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 17 namespace extensions { 18 namespace { 19 20 gfx::Size GetDesktopWindowSize() { 21 return DesktopController::instance()->GetHost()->window()->bounds().size(); 22 } 23 24 } // namespace 25 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()); 36 SetBounds(bounds); 37 } 38 39 ShellNativeAppWindow::~ShellNativeAppWindow() { 40 } 41 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); 47 } 48 49 bool ShellNativeAppWindow::IsMaximized() const { 50 return false; 51 } 52 53 bool ShellNativeAppWindow::IsMinimized() const { 54 return false; 55 } 56 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. 61 return false; 62 } 63 64 gfx::NativeWindow ShellNativeAppWindow::GetNativeWindow() { 65 return GetWindow(); 66 } 67 68 gfx::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 74 ui::WindowShowState ShellNativeAppWindow::GetRestoredState() const { 75 return ui::SHOW_STATE_NORMAL; 76 } 77 78 gfx::Rect ShellNativeAppWindow::GetBounds() const { 79 return GetWindow()->GetBoundsInScreen(); 80 } 81 82 void ShellNativeAppWindow::Show() { 83 GetWindow()->Show(); 84 } 85 86 void ShellNativeAppWindow::Hide() { 87 GetWindow()->Hide(); 88 } 89 90 void ShellNativeAppWindow::ShowInactive() { 91 NOTIMPLEMENTED(); 92 } 93 94 void ShellNativeAppWindow::Close() { 95 app_window_->OnNativeClose(); 96 } 97 98 void ShellNativeAppWindow::Activate() { 99 aura::Window* window = GetWindow(); 100 if (window) 101 wm::ActivateWindow(window); 102 } 103 104 void ShellNativeAppWindow::Deactivate() { 105 aura::Window* window = GetWindow(); 106 if (window) 107 wm::DeactivateWindow(window); 108 } 109 110 void ShellNativeAppWindow::Maximize() { 111 NOTIMPLEMENTED(); 112 } 113 114 void ShellNativeAppWindow::Minimize() { 115 NOTIMPLEMENTED(); 116 } 117 118 void ShellNativeAppWindow::Restore() { 119 NOTIMPLEMENTED(); 120 } 121 122 void ShellNativeAppWindow::SetBounds(const gfx::Rect& bounds) { 123 GetWindow()->SetBounds(bounds); 124 } 125 126 void ShellNativeAppWindow::FlashFrame(bool flash) { 127 NOTIMPLEMENTED(); 128 } 129 130 bool ShellNativeAppWindow::IsAlwaysOnTop() const { 131 return false; 132 } 133 134 void ShellNativeAppWindow::SetAlwaysOnTop(bool always_on_top) { 135 NOTIMPLEMENTED(); 136 } 137 138 gfx::NativeView ShellNativeAppWindow::GetHostView() const { 139 NOTIMPLEMENTED(); 140 return NULL; 141 } 142 143 gfx::Point ShellNativeAppWindow::GetDialogPosition(const gfx::Size& size) { 144 NOTIMPLEMENTED(); 145 return gfx::Point(); 146 } 147 148 void ShellNativeAppWindow::AddObserver( 149 web_modal::ModalDialogHostObserver* observer) { 150 NOTIMPLEMENTED(); 151 } 152 153 void ShellNativeAppWindow::RemoveObserver( 154 web_modal::ModalDialogHostObserver* observer) { 155 NOTIMPLEMENTED(); 156 } 157 158 gfx::Size ShellNativeAppWindow::GetMaximumDialogSize() { 159 NOTIMPLEMENTED(); 160 return gfx::Size(); 161 } 162 163 void ShellNativeAppWindow::SetFullscreen(int fullscreen_types) { 164 NOTIMPLEMENTED(); 165 } 166 167 bool ShellNativeAppWindow::IsFullscreenOrPending() const { 168 // See comment in IsFullscreen(). 169 return false; 170 } 171 172 void ShellNativeAppWindow::UpdateWindowIcon() { 173 // No icon to update. 174 } 175 176 void ShellNativeAppWindow::UpdateWindowTitle() { 177 // No window title to update. 178 } 179 180 void ShellNativeAppWindow::UpdateBadgeIcon() { 181 // No badge to update. 182 } 183 184 void ShellNativeAppWindow::UpdateDraggableRegions( 185 const std::vector<DraggableRegion>& regions) { 186 NOTIMPLEMENTED(); 187 } 188 189 SkRegion* ShellNativeAppWindow::GetDraggableRegion() { 190 NOTIMPLEMENTED(); 191 return NULL; 192 } 193 194 void ShellNativeAppWindow::UpdateShape(scoped_ptr<SkRegion> region) { 195 NOTIMPLEMENTED(); 196 } 197 198 void ShellNativeAppWindow::HandleKeyboardEvent( 199 const content::NativeWebKeyboardEvent& event) { 200 // No special handling. The WebContents will handle it. 201 } 202 203 bool ShellNativeAppWindow::IsFrameless() const { 204 NOTIMPLEMENTED(); 205 return false; 206 } 207 208 bool ShellNativeAppWindow::HasFrameColor() const { 209 return false; 210 } 211 212 SkColor ShellNativeAppWindow::ActiveFrameColor() const { 213 return SkColor(); 214 } 215 216 SkColor ShellNativeAppWindow::InactiveFrameColor() const { 217 return SkColor(); 218 } 219 220 gfx::Insets ShellNativeAppWindow::GetFrameInsets() const { 221 return gfx::Insets(); 222 } 223 224 void ShellNativeAppWindow::ShowWithApp() { 225 NOTIMPLEMENTED(); 226 } 227 228 void ShellNativeAppWindow::HideWithApp() { 229 NOTIMPLEMENTED(); 230 } 231 232 void ShellNativeAppWindow::UpdateShelfMenu() { 233 // app_shell has no shelf, dock, or system-tray to update. 234 } 235 236 gfx::Size ShellNativeAppWindow::GetContentMinimumSize() const { 237 // Content fills the desktop and cannot be resized. 238 return GetDesktopWindowSize(); 239 } 240 241 gfx::Size ShellNativeAppWindow::GetContentMaximumSize() const { 242 // Content fills the desktop and cannot be resized. 243 return GetDesktopWindowSize(); 244 } 245 246 void ShellNativeAppWindow::SetContentSizeConstraints( 247 const gfx::Size& min_size, 248 const gfx::Size& max_size) { 249 NOTIMPLEMENTED(); 250 } 251 252 void ShellNativeAppWindow::SetVisibleOnAllWorkspaces(bool always_visible) { 253 NOTIMPLEMENTED(); 254 } 255 256 bool ShellNativeAppWindow::CanHaveAlphaEnabled() const { 257 // No background to display if the window was transparent. 258 return false; 259 } 260 261 aura::Window* ShellNativeAppWindow::GetWindow() const { 262 return app_window_->web_contents()->GetNativeView(); 263 } 264 265 } // namespace extensions 266