OLD | NEW |
(Empty) | |
| 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 "apps/shell/browser/shell_native_app_window.h" |
| 6 |
| 7 #include "apps/app_window.h" |
| 8 #include "apps/ui/views/app_window_frame_view.h" |
| 9 #include "ui/gfx/image/image_skia.h" |
| 10 #include "ui/gfx/rect.h" |
| 11 #include "ui/views/controls/webview/webview.h" |
| 12 #include "ui/views/widget/widget.h" |
| 13 |
| 14 namespace apps { |
| 15 |
| 16 ShellNativeAppWindow::ShellNativeAppWindow() |
| 17 : shell_window_(NULL), |
| 18 web_view_(NULL), |
| 19 window_(NULL) { |
| 20 } |
| 21 |
| 22 void ShellNativeAppWindow::Init(AppWindow* shell_window, |
| 23 const gfx::Rect& window_bounds) { |
| 24 shell_window_ = shell_window; |
| 25 |
| 26 window_ = new views::Widget; |
| 27 InitializeWindow(window_bounds); |
| 28 |
| 29 OnViewWasResized(); |
| 30 window_->AddObserver(this); |
| 31 } |
| 32 |
| 33 ShellNativeAppWindow::~ShellNativeAppWindow() { |
| 34 web_view_->SetWebContents(NULL); |
| 35 } |
| 36 |
| 37 void ShellNativeAppWindow::InitializeWindow(const gfx::Rect& window_bounds) { |
| 38 views::Widget::InitParams init_params(views::Widget::InitParams::TYPE_WINDOW); |
| 39 init_params.delegate = this; |
| 40 init_params.top_level = true; |
| 41 window_->Init(init_params); |
| 42 window_->CenterWindow(window_bounds.size()); |
| 43 } |
| 44 |
| 45 void ShellNativeAppWindow::OnViewWasResized() { |
| 46 FOR_EACH_OBSERVER(web_modal::ModalDialogHostObserver, |
| 47 observer_list_, |
| 48 OnPositionRequiresUpdate()); |
| 49 } |
| 50 |
| 51 const extensions::Extension* ShellNativeAppWindow::GetExtension() { |
| 52 return shell_window_->extension(); |
| 53 } |
| 54 |
| 55 content::WebContents* ShellNativeAppWindow::GetWebContents() { |
| 56 return shell_window_->web_contents(); |
| 57 } |
| 58 |
| 59 // ui::BaseWindow implementation. |
| 60 |
| 61 bool ShellNativeAppWindow::IsActive() const { |
| 62 return window_->IsActive(); |
| 63 } |
| 64 |
| 65 bool ShellNativeAppWindow::IsMaximized() const { |
| 66 return false; |
| 67 } |
| 68 |
| 69 bool ShellNativeAppWindow::IsMinimized() const { |
| 70 return false; |
| 71 } |
| 72 |
| 73 bool ShellNativeAppWindow::IsFullscreen() const { |
| 74 return false; |
| 75 } |
| 76 |
| 77 gfx::NativeWindow ShellNativeAppWindow::GetNativeWindow() { |
| 78 return window_->GetNativeWindow(); |
| 79 } |
| 80 |
| 81 gfx::Rect ShellNativeAppWindow::GetRestoredBounds() const { |
| 82 return window_->GetRestoredBounds(); |
| 83 } |
| 84 |
| 85 ui::WindowShowState ShellNativeAppWindow::GetRestoredState() const { |
| 86 return ui::SHOW_STATE_NORMAL; |
| 87 } |
| 88 |
| 89 gfx::Rect ShellNativeAppWindow::GetBounds() const { |
| 90 return window_->GetWindowBoundsInScreen(); |
| 91 } |
| 92 |
| 93 void ShellNativeAppWindow::Show() { |
| 94 if (window_->IsVisible()) { |
| 95 window_->Activate(); |
| 96 return; |
| 97 } |
| 98 window_->Show(); |
| 99 } |
| 100 |
| 101 void ShellNativeAppWindow::ShowInactive() { |
| 102 if (window_->IsVisible()) |
| 103 return; |
| 104 window_->ShowInactive(); |
| 105 } |
| 106 |
| 107 void ShellNativeAppWindow::Hide() { |
| 108 window_->Hide(); |
| 109 } |
| 110 |
| 111 void ShellNativeAppWindow::Close() { |
| 112 window_->Close(); |
| 113 } |
| 114 |
| 115 void ShellNativeAppWindow::Activate() { |
| 116 window_->Activate(); |
| 117 } |
| 118 |
| 119 void ShellNativeAppWindow::Deactivate() { |
| 120 window_->Deactivate(); |
| 121 } |
| 122 |
| 123 void ShellNativeAppWindow::Maximize() {} |
| 124 |
| 125 void ShellNativeAppWindow::Minimize() {} |
| 126 |
| 127 void ShellNativeAppWindow::Restore() {} |
| 128 |
| 129 void ShellNativeAppWindow::SetBounds(const gfx::Rect& bounds) { |
| 130 window_->SetBounds(bounds); |
| 131 } |
| 132 |
| 133 void ShellNativeAppWindow::FlashFrame(bool flash) {} |
| 134 |
| 135 bool ShellNativeAppWindow::IsAlwaysOnTop() const { |
| 136 return window_->IsAlwaysOnTop(); |
| 137 } |
| 138 |
| 139 void ShellNativeAppWindow::SetAlwaysOnTop(bool always_on_top) { |
| 140 window_->SetAlwaysOnTop(always_on_top); |
| 141 } |
| 142 |
| 143 gfx::NativeView ShellNativeAppWindow::GetHostView() const { |
| 144 return window_->GetNativeView(); |
| 145 } |
| 146 |
| 147 gfx::Point ShellNativeAppWindow::GetDialogPosition(const gfx::Size& size) { |
| 148 gfx::Size shell_window_size = window_->GetWindowBoundsInScreen().size(); |
| 149 return gfx::Point(shell_window_size.width() / 2 - size.width() / 2, |
| 150 shell_window_size.height() / 2 - size.height() / 2); |
| 151 } |
| 152 |
| 153 gfx::Size ShellNativeAppWindow::GetMaximumDialogSize() { |
| 154 return window_->GetWindowBoundsInScreen().size(); |
| 155 } |
| 156 |
| 157 void ShellNativeAppWindow::AddObserver( |
| 158 web_modal::ModalDialogHostObserver* observer) { |
| 159 observer_list_.AddObserver(observer); |
| 160 } |
| 161 |
| 162 void ShellNativeAppWindow::RemoveObserver( |
| 163 web_modal::ModalDialogHostObserver* observer) { |
| 164 observer_list_.RemoveObserver(observer); |
| 165 } |
| 166 |
| 167 // WidgetDelegate implementation. |
| 168 |
| 169 void ShellNativeAppWindow::OnWidgetMove() { |
| 170 shell_window_->OnNativeWindowChanged(); |
| 171 } |
| 172 |
| 173 views::View* ShellNativeAppWindow::GetInitiallyFocusedView() { |
| 174 return web_view_; |
| 175 } |
| 176 |
| 177 bool ShellNativeAppWindow::CanResize() const { |
| 178 return false; |
| 179 } |
| 180 |
| 181 bool ShellNativeAppWindow::CanMaximize() const { |
| 182 return false; |
| 183 } |
| 184 |
| 185 base::string16 ShellNativeAppWindow::GetWindowTitle() const { |
| 186 return base::string16(); |
| 187 } |
| 188 |
| 189 bool ShellNativeAppWindow::ShouldShowWindowTitle() const { |
| 190 return false; |
| 191 } |
| 192 |
| 193 gfx::ImageSkia ShellNativeAppWindow::GetWindowAppIcon() { |
| 194 return gfx::ImageSkia(); |
| 195 } |
| 196 |
| 197 gfx::ImageSkia ShellNativeAppWindow::GetWindowIcon() { |
| 198 return gfx::ImageSkia(); |
| 199 } |
| 200 |
| 201 bool ShellNativeAppWindow::ShouldShowWindowIcon() const { |
| 202 return false; |
| 203 } |
| 204 |
| 205 void ShellNativeAppWindow::SaveWindowPlacement(const gfx::Rect& bounds, |
| 206 ui::WindowShowState show_state) { |
| 207 views::WidgetDelegate::SaveWindowPlacement(bounds, show_state); |
| 208 shell_window_->OnNativeWindowChanged(); |
| 209 } |
| 210 |
| 211 void ShellNativeAppWindow::DeleteDelegate() { |
| 212 window_->RemoveObserver(this); |
| 213 shell_window_->OnNativeClose(); |
| 214 } |
| 215 |
| 216 views::Widget* ShellNativeAppWindow::GetWidget() { |
| 217 return window_; |
| 218 } |
| 219 |
| 220 const views::Widget* ShellNativeAppWindow::GetWidget() const { |
| 221 return window_; |
| 222 } |
| 223 |
| 224 views::View* ShellNativeAppWindow::GetContentsView() { |
| 225 return this; |
| 226 } |
| 227 |
| 228 views::NonClientFrameView* ShellNativeAppWindow::CreateNonClientFrameView( |
| 229 views::Widget* widget) { |
| 230 AppWindowFrameView* frame_view = new AppWindowFrameView(this); |
| 231 // Window is not resizable, so no bounds inset or corner resize area. |
| 232 frame_view->Init(window_, 0, 0, 1, 0); |
| 233 return frame_view; |
| 234 } |
| 235 |
| 236 bool ShellNativeAppWindow::WidgetHasHitTestMask() const { |
| 237 return false; |
| 238 } |
| 239 |
| 240 void ShellNativeAppWindow::GetWidgetHitTestMask(gfx::Path* mask) const { |
| 241 } |
| 242 |
| 243 bool ShellNativeAppWindow::ShouldDescendIntoChildForEventHandling( |
| 244 gfx::NativeView child, |
| 245 const gfx::Point& location) { |
| 246 return true; |
| 247 } |
| 248 |
| 249 // WidgetObserver implementation. |
| 250 |
| 251 void ShellNativeAppWindow::OnWidgetVisibilityChanged(views::Widget* widget, |
| 252 bool visible) { |
| 253 shell_window_->OnNativeWindowChanged(); |
| 254 } |
| 255 |
| 256 void ShellNativeAppWindow::OnWidgetActivationChanged(views::Widget* widget, |
| 257 bool active) { |
| 258 shell_window_->OnNativeWindowChanged(); |
| 259 if (active) |
| 260 shell_window_->OnNativeWindowActivated(); |
| 261 } |
| 262 |
| 263 // views::View implementation. |
| 264 |
| 265 void ShellNativeAppWindow::Layout() { |
| 266 DCHECK(web_view_); |
| 267 web_view_->SetBounds(0, 0, width(), height()); |
| 268 OnViewWasResized(); |
| 269 } |
| 270 |
| 271 void ShellNativeAppWindow::ViewHierarchyChanged( |
| 272 const ViewHierarchyChangedDetails& details) { |
| 273 if (details.is_add && details.child == this) { |
| 274 web_view_ = new views::WebView(NULL); |
| 275 AddChildView(web_view_); |
| 276 web_view_->SetWebContents(GetWebContents()); |
| 277 } |
| 278 } |
| 279 |
| 280 gfx::Size ShellNativeAppWindow::GetMinimumSize() { |
| 281 return shell_window_->size_constraints().GetMinimumSize(); |
| 282 } |
| 283 |
| 284 gfx::Size ShellNativeAppWindow::GetMaximumSize() { |
| 285 return shell_window_->size_constraints().GetMaximumSize(); |
| 286 } |
| 287 |
| 288 void ShellNativeAppWindow::OnFocus() { |
| 289 web_view_->RequestFocus(); |
| 290 } |
| 291 |
| 292 bool ShellNativeAppWindow::AcceleratorPressed( |
| 293 const ui::Accelerator& accelerator) { |
| 294 return false; |
| 295 } |
| 296 |
| 297 // NativeAppWindow implementation. |
| 298 |
| 299 void ShellNativeAppWindow::SetFullscreen(int fullscreen_types) {} |
| 300 |
| 301 bool ShellNativeAppWindow::IsFullscreenOrPending() const { |
| 302 return false; |
| 303 } |
| 304 |
| 305 bool ShellNativeAppWindow::IsDetached() const { |
| 306 return false; |
| 307 } |
| 308 |
| 309 void ShellNativeAppWindow::UpdateWindowIcon() {} |
| 310 |
| 311 void ShellNativeAppWindow::UpdateWindowTitle() {} |
| 312 |
| 313 void ShellNativeAppWindow::UpdateBadgeIcon() {} |
| 314 |
| 315 void ShellNativeAppWindow::UpdateDraggableRegions( |
| 316 const std::vector<extensions::DraggableRegion>& regions) {} |
| 317 |
| 318 SkRegion* ShellNativeAppWindow::GetDraggableRegion() { |
| 319 return NULL; |
| 320 } |
| 321 |
| 322 void ShellNativeAppWindow::UpdateShape(scoped_ptr<SkRegion> region) {} |
| 323 |
| 324 void ShellNativeAppWindow::HandleKeyboardEvent( |
| 325 const content::NativeWebKeyboardEvent& event) {} |
| 326 |
| 327 bool ShellNativeAppWindow::IsFrameless() const { |
| 328 return true; |
| 329 } |
| 330 |
| 331 gfx::Insets ShellNativeAppWindow::GetFrameInsets() const { |
| 332 return gfx::Insets(); |
| 333 } |
| 334 |
| 335 void ShellNativeAppWindow::HideWithApp() {} |
| 336 |
| 337 void ShellNativeAppWindow::ShowWithApp() {} |
| 338 |
| 339 void ShellNativeAppWindow::UpdateWindowMinMaxSize() {} |
| 340 |
| 341 } // namespace apps |
OLD | NEW |