1// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "extensions/shell/browser/shell_native_app_window.h"
6
7#include "content/public/browser/web_contents.h"
8#include "extensions/shell/browser/desktop_controller.h"
9#include "ui/aura/window.h"
10#include "ui/aura/window_tree_host.h"
11#include "ui/gfx/geometry/insets.h"
12#include "ui/gfx/geometry/point.h"
13#include "ui/gfx/geometry/rect.h"
14#include "ui/gfx/geometry/size.h"
15#include "ui/wm/core/window_util.h"
16
17namespace extensions {
18namespace {
19
20gfx::Size GetDesktopWindowSize() {
21  return DesktopController::instance()->GetHost()->window()->bounds().size();
22}
23
24}  // namespace
25
26ShellNativeAppWindow::ShellNativeAppWindow(
27    AppWindow* app_window,
28    const AppWindow::CreateParams& params)
29    : app_window_(app_window) {
30  gfx::Rect bounds = params.GetInitialWindowBounds(GetFrameInsets());
31  bool position_specified =
32      bounds.x() != AppWindow::BoundsSpecification::kUnspecifiedPosition &&
33      bounds.y() != AppWindow::BoundsSpecification::kUnspecifiedPosition;
34  if (!position_specified)
35    bounds.set_origin(GetBounds().origin());
36  SetBounds(bounds);
37}
38
39ShellNativeAppWindow::~ShellNativeAppWindow() {
40}
41
42bool ShellNativeAppWindow::IsActive() const {
43  // Even though app_shell only supports a single app window, there might be
44  // some sort of system-level dialog open and active.
45  aura::Window* window = GetWindow();
46  return window && wm::IsActiveWindow(window);
47}
48
49bool ShellNativeAppWindow::IsMaximized() const {
50  return false;
51}
52
53bool ShellNativeAppWindow::IsMinimized() const {
54  return false;
55}
56
57bool ShellNativeAppWindow::IsFullscreen() const {
58  // The window in app_shell is considered a "restored" window that happens to
59  // fill the display. This avoids special handling of fullscreen or maximized
60  // windows that app_shell doesn't need.
61  return false;
62}
63
64gfx::NativeWindow ShellNativeAppWindow::GetNativeWindow() {
65  return GetWindow();
66}
67
68gfx::Rect ShellNativeAppWindow::GetRestoredBounds() const {
69  // app_shell windows cannot be maximized, so the current bounds are the
70  // restored bounds.
71  return GetBounds();
72}
73
74ui::WindowShowState ShellNativeAppWindow::GetRestoredState() const {
75  return ui::SHOW_STATE_NORMAL;
76}
77
78gfx::Rect ShellNativeAppWindow::GetBounds() const {
79  return GetWindow()->GetBoundsInScreen();
80}
81
82void ShellNativeAppWindow::Show() {
83  GetWindow()->Show();
84}
85
86void ShellNativeAppWindow::Hide() {
87  GetWindow()->Hide();
88}
89
90void ShellNativeAppWindow::ShowInactive() {
91  NOTIMPLEMENTED();
92}
93
94void ShellNativeAppWindow::Close() {
95  app_window_->OnNativeClose();
96}
97
98void ShellNativeAppWindow::Activate() {
99  aura::Window* window = GetWindow();
100  if (window)
101    wm::ActivateWindow(window);
102}
103
104void ShellNativeAppWindow::Deactivate() {
105  aura::Window* window = GetWindow();
106  if (window)
107    wm::DeactivateWindow(window);
108}
109
110void ShellNativeAppWindow::Maximize() {
111  NOTIMPLEMENTED();
112}
113
114void ShellNativeAppWindow::Minimize() {
115  NOTIMPLEMENTED();
116}
117
118void ShellNativeAppWindow::Restore() {
119  NOTIMPLEMENTED();
120}
121
122void ShellNativeAppWindow::SetBounds(const gfx::Rect& bounds) {
123  GetWindow()->SetBounds(bounds);
124}
125
126void ShellNativeAppWindow::FlashFrame(bool flash) {
127  NOTIMPLEMENTED();
128}
129
130bool ShellNativeAppWindow::IsAlwaysOnTop() const {
131  return false;
132}
133
134void ShellNativeAppWindow::SetAlwaysOnTop(bool always_on_top) {
135  NOTIMPLEMENTED();
136}
137
138gfx::NativeView ShellNativeAppWindow::GetHostView() const {
139  NOTIMPLEMENTED();
140  return NULL;
141}
142
143gfx::Point ShellNativeAppWindow::GetDialogPosition(const gfx::Size& size) {
144  NOTIMPLEMENTED();
145  return gfx::Point();
146}
147
148void ShellNativeAppWindow::AddObserver(
149      web_modal::ModalDialogHostObserver* observer) {
150  NOTIMPLEMENTED();
151}
152
153void ShellNativeAppWindow::RemoveObserver(
154      web_modal::ModalDialogHostObserver* observer) {
155  NOTIMPLEMENTED();
156}
157
158gfx::Size ShellNativeAppWindow::GetMaximumDialogSize() {
159  NOTIMPLEMENTED();
160  return gfx::Size();
161}
162
163void ShellNativeAppWindow::SetFullscreen(int fullscreen_types) {
164  NOTIMPLEMENTED();
165}
166
167bool ShellNativeAppWindow::IsFullscreenOrPending() const {
168  // See comment in IsFullscreen().
169  return false;
170}
171
172void ShellNativeAppWindow::UpdateWindowIcon() {
173  // No icon to update.
174}
175
176void ShellNativeAppWindow::UpdateWindowTitle() {
177  // No window title to update.
178}
179
180void ShellNativeAppWindow::UpdateBadgeIcon() {
181  // No badge to update.
182}
183
184void ShellNativeAppWindow::UpdateDraggableRegions(
185    const std::vector<DraggableRegion>& regions) {
186  NOTIMPLEMENTED();
187}
188
189SkRegion* ShellNativeAppWindow::GetDraggableRegion() {
190  NOTIMPLEMENTED();
191  return NULL;
192}
193
194void ShellNativeAppWindow::UpdateShape(scoped_ptr<SkRegion> region) {
195  NOTIMPLEMENTED();
196}
197
198void ShellNativeAppWindow::HandleKeyboardEvent(
199      const content::NativeWebKeyboardEvent& event) {
200  // No special handling. The WebContents will handle it.
201}
202
203bool ShellNativeAppWindow::IsFrameless() const {
204  NOTIMPLEMENTED();
205  return false;
206}
207
208bool ShellNativeAppWindow::HasFrameColor() const {
209  return false;
210}
211
212SkColor ShellNativeAppWindow::ActiveFrameColor() const {
213  return SkColor();
214}
215
216SkColor ShellNativeAppWindow::InactiveFrameColor() const {
217  return SkColor();
218}
219
220gfx::Insets ShellNativeAppWindow::GetFrameInsets() const {
221  return gfx::Insets();
222}
223
224void ShellNativeAppWindow::ShowWithApp() {
225  NOTIMPLEMENTED();
226}
227
228void ShellNativeAppWindow::HideWithApp() {
229  NOTIMPLEMENTED();
230}
231
232void ShellNativeAppWindow::UpdateShelfMenu() {
233  // app_shell has no shelf, dock, or system-tray to update.
234}
235
236gfx::Size ShellNativeAppWindow::GetContentMinimumSize() const {
237  // Content fills the desktop and cannot be resized.
238  return GetDesktopWindowSize();
239}
240
241gfx::Size ShellNativeAppWindow::GetContentMaximumSize() const {
242  // Content fills the desktop and cannot be resized.
243  return GetDesktopWindowSize();
244}
245
246void ShellNativeAppWindow::SetContentSizeConstraints(
247    const gfx::Size& min_size,
248    const gfx::Size& max_size) {
249  NOTIMPLEMENTED();
250}
251
252void ShellNativeAppWindow::SetVisibleOnAllWorkspaces(bool always_visible) {
253  NOTIMPLEMENTED();
254}
255
256bool ShellNativeAppWindow::CanHaveAlphaEnabled() const {
257  // No background to display if the window was transparent.
258  return false;
259}
260
261aura::Window* ShellNativeAppWindow::GetWindow() const {
262  return app_window_->web_contents()->GetNativeView();
263}
264
265}  // namespace extensions
266