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.
5 #include "extensions/shell/browser/shell_native_app_window.h"
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"
17 namespace extensions {
20 gfx::Size GetDesktopWindowSize() {
21 return DesktopController::instance()->GetHost()->window()->bounds().size();
26 ShellNativeAppWindow::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());
39 ShellNativeAppWindow::~ShellNativeAppWindow() {
42 bool 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);
49 bool ShellNativeAppWindow::IsMaximized() const {
53 bool ShellNativeAppWindow::IsMinimized() const {
57 bool 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.
64 gfx::NativeWindow ShellNativeAppWindow::GetNativeWindow() {
68 gfx::Rect ShellNativeAppWindow::GetRestoredBounds() const {
69 // app_shell windows cannot be maximized, so the current bounds are the
74 ui::WindowShowState ShellNativeAppWindow::GetRestoredState() const {
75 return ui::SHOW_STATE_NORMAL;
78 gfx::Rect ShellNativeAppWindow::GetBounds() const {
79 return GetWindow()->GetBoundsInScreen();
82 void ShellNativeAppWindow::Show() {
86 void ShellNativeAppWindow::Hide() {
90 void ShellNativeAppWindow::ShowInactive() {
94 void ShellNativeAppWindow::Close() {
95 app_window_->OnNativeClose();
98 void ShellNativeAppWindow::Activate() {
99 aura::Window* window = GetWindow();
101 wm::ActivateWindow(window);
104 void ShellNativeAppWindow::Deactivate() {
105 aura::Window* window = GetWindow();
107 wm::DeactivateWindow(window);
110 void ShellNativeAppWindow::Maximize() {
114 void ShellNativeAppWindow::Minimize() {
118 void ShellNativeAppWindow::Restore() {
122 void ShellNativeAppWindow::SetBounds(const gfx::Rect& bounds) {
123 GetWindow()->SetBounds(bounds);
126 void ShellNativeAppWindow::FlashFrame(bool flash) {
130 bool ShellNativeAppWindow::IsAlwaysOnTop() const {
134 void ShellNativeAppWindow::SetAlwaysOnTop(bool always_on_top) {
138 gfx::NativeView ShellNativeAppWindow::GetHostView() const {
143 gfx::Point ShellNativeAppWindow::GetDialogPosition(const gfx::Size& size) {
148 void ShellNativeAppWindow::AddObserver(
149 web_modal::ModalDialogHostObserver* observer) {
153 void ShellNativeAppWindow::RemoveObserver(
154 web_modal::ModalDialogHostObserver* observer) {
158 gfx::Size ShellNativeAppWindow::GetMaximumDialogSize() {
163 void ShellNativeAppWindow::SetFullscreen(int fullscreen_types) {
167 bool ShellNativeAppWindow::IsFullscreenOrPending() const {
168 // See comment in IsFullscreen().
172 void ShellNativeAppWindow::UpdateWindowIcon() {
173 // No icon to update.
176 void ShellNativeAppWindow::UpdateWindowTitle() {
177 // No window title to update.
180 void ShellNativeAppWindow::UpdateBadgeIcon() {
181 // No badge to update.
184 void ShellNativeAppWindow::UpdateDraggableRegions(
185 const std::vector<DraggableRegion>& regions) {
189 SkRegion* ShellNativeAppWindow::GetDraggableRegion() {
194 void ShellNativeAppWindow::UpdateShape(scoped_ptr<SkRegion> region) {
198 void ShellNativeAppWindow::HandleKeyboardEvent(
199 const content::NativeWebKeyboardEvent& event) {
200 // No special handling. The WebContents will handle it.
203 bool ShellNativeAppWindow::IsFrameless() const {
208 bool ShellNativeAppWindow::HasFrameColor() const {
212 SkColor ShellNativeAppWindow::ActiveFrameColor() const {
216 SkColor ShellNativeAppWindow::InactiveFrameColor() const {
220 gfx::Insets ShellNativeAppWindow::GetFrameInsets() const {
221 return gfx::Insets();
224 void ShellNativeAppWindow::ShowWithApp() {
228 void ShellNativeAppWindow::HideWithApp() {
232 void ShellNativeAppWindow::UpdateShelfMenu() {
233 // app_shell has no shelf, dock, or system-tray to update.
236 gfx::Size ShellNativeAppWindow::GetContentMinimumSize() const {
237 // Content fills the desktop and cannot be resized.
238 return GetDesktopWindowSize();
241 gfx::Size ShellNativeAppWindow::GetContentMaximumSize() const {
242 // Content fills the desktop and cannot be resized.
243 return GetDesktopWindowSize();
246 void ShellNativeAppWindow::SetContentSizeConstraints(
247 const gfx::Size& min_size,
248 const gfx::Size& max_size) {
252 void ShellNativeAppWindow::SetVisibleOnAllWorkspaces(bool always_visible) {
256 bool ShellNativeAppWindow::CanHaveAlphaEnabled() const {
257 // No background to display if the window was transparent.
261 aura::Window* ShellNativeAppWindow::GetWindow() const {
262 return app_window_->web_contents()->GetNativeView();
265 } // namespace extensions