| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "apps/ui/views/native_app_window_views.h" | 5 #include "components/native_app_window/native_app_window_views.h" |
| 6 | 6 |
| 7 #include "base/threading/sequenced_worker_pool.h" | 7 #include "base/threading/sequenced_worker_pool.h" |
| 8 #include "content/public/browser/render_view_host.h" | 8 #include "content/public/browser/render_view_host.h" |
| 9 #include "content/public/browser/render_widget_host_view.h" | 9 #include "content/public/browser/render_widget_host_view.h" |
| 10 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
| 11 #include "extensions/browser/app_window/app_window.h" | 11 #include "extensions/browser/app_window/app_window.h" |
| 12 #include "extensions/common/draggable_region.h" | 12 #include "extensions/common/draggable_region.h" |
| 13 #include "third_party/skia/include/core/SkRegion.h" | 13 #include "third_party/skia/include/core/SkRegion.h" |
| 14 #include "ui/gfx/path.h" | 14 #include "ui/gfx/path.h" |
| 15 #include "ui/views/controls/webview/webview.h" | 15 #include "ui/views/controls/webview/webview.h" |
| 16 #include "ui/views/widget/widget.h" | 16 #include "ui/views/widget/widget.h" |
| 17 #include "ui/views/window/non_client_view.h" | 17 #include "ui/views/window/non_client_view.h" |
| 18 | 18 |
| 19 #if defined(USE_AURA) | 19 #if defined(USE_AURA) |
| 20 #include "ui/aura/window.h" | 20 #include "ui/aura/window.h" |
| 21 #endif | 21 #endif |
| 22 | 22 |
| 23 using extensions::AppWindow; | 23 using extensions::AppWindow; |
| 24 | 24 |
| 25 namespace apps { | 25 namespace native_app_window { |
| 26 | 26 |
| 27 NativeAppWindowViews::NativeAppWindowViews() | 27 NativeAppWindowViews::NativeAppWindowViews() |
| 28 : app_window_(NULL), | 28 : app_window_(NULL), |
| 29 web_view_(NULL), | 29 web_view_(NULL), |
| 30 widget_(NULL), | 30 widget_(NULL), |
| 31 frameless_(false), | 31 frameless_(false), |
| 32 resizable_(false) {} | 32 resizable_(false) { |
| 33 } |
| 33 | 34 |
| 34 void NativeAppWindowViews::Init(AppWindow* app_window, | 35 void NativeAppWindowViews::Init(AppWindow* app_window, |
| 35 const AppWindow::CreateParams& create_params) { | 36 const AppWindow::CreateParams& create_params) { |
| 36 app_window_ = app_window; | 37 app_window_ = app_window; |
| 37 frameless_ = create_params.frame == AppWindow::FRAME_NONE; | 38 frameless_ = create_params.frame == AppWindow::FRAME_NONE; |
| 38 resizable_ = create_params.resizable; | 39 resizable_ = create_params.resizable; |
| 39 size_constraints_.set_minimum_size( | 40 size_constraints_.set_minimum_size( |
| 40 create_params.GetContentMinimumSize(gfx::Insets())); | 41 create_params.GetContentMinimumSize(gfx::Insets())); |
| 41 size_constraints_.set_maximum_size( | 42 size_constraints_.set_maximum_size( |
| 42 create_params.GetContentMaximumSize(gfx::Insets())); | 43 create_params.GetContentMaximumSize(gfx::Insets())); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 64 views::Widget::InitParams init_params(views::Widget::InitParams::TYPE_WINDOW); | 65 views::Widget::InitParams init_params(views::Widget::InitParams::TYPE_WINDOW); |
| 65 init_params.delegate = this; | 66 init_params.delegate = this; |
| 66 init_params.keep_on_top = create_params.always_on_top; | 67 init_params.keep_on_top = create_params.always_on_top; |
| 67 widget_->Init(init_params); | 68 widget_->Init(init_params); |
| 68 widget_->CenterWindow( | 69 widget_->CenterWindow( |
| 69 create_params.GetInitialWindowBounds(gfx::Insets()).size()); | 70 create_params.GetInitialWindowBounds(gfx::Insets()).size()); |
| 70 } | 71 } |
| 71 | 72 |
| 72 // ui::BaseWindow implementation. | 73 // ui::BaseWindow implementation. |
| 73 | 74 |
| 74 bool NativeAppWindowViews::IsActive() const { return widget_->IsActive(); } | 75 bool NativeAppWindowViews::IsActive() const { |
| 76 return widget_->IsActive(); |
| 77 } |
| 75 | 78 |
| 76 bool NativeAppWindowViews::IsMaximized() const { | 79 bool NativeAppWindowViews::IsMaximized() const { |
| 77 return widget_->IsMaximized(); | 80 return widget_->IsMaximized(); |
| 78 } | 81 } |
| 79 | 82 |
| 80 bool NativeAppWindowViews::IsMinimized() const { | 83 bool NativeAppWindowViews::IsMinimized() const { |
| 81 return widget_->IsMinimized(); | 84 return widget_->IsMinimized(); |
| 82 } | 85 } |
| 83 | 86 |
| 84 bool NativeAppWindowViews::IsFullscreen() const { | 87 bool NativeAppWindowViews::IsFullscreen() const { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 114 widget_->Show(); | 117 widget_->Show(); |
| 115 } | 118 } |
| 116 | 119 |
| 117 void NativeAppWindowViews::ShowInactive() { | 120 void NativeAppWindowViews::ShowInactive() { |
| 118 if (widget_->IsVisible()) | 121 if (widget_->IsVisible()) |
| 119 return; | 122 return; |
| 120 | 123 |
| 121 widget_->ShowInactive(); | 124 widget_->ShowInactive(); |
| 122 } | 125 } |
| 123 | 126 |
| 124 void NativeAppWindowViews::Hide() { widget_->Hide(); } | 127 void NativeAppWindowViews::Hide() { |
| 128 widget_->Hide(); |
| 129 } |
| 125 | 130 |
| 126 void NativeAppWindowViews::Close() { widget_->Close(); } | 131 void NativeAppWindowViews::Close() { |
| 132 widget_->Close(); |
| 133 } |
| 127 | 134 |
| 128 void NativeAppWindowViews::Activate() { widget_->Activate(); } | 135 void NativeAppWindowViews::Activate() { |
| 136 widget_->Activate(); |
| 137 } |
| 129 | 138 |
| 130 void NativeAppWindowViews::Deactivate() { widget_->Deactivate(); } | 139 void NativeAppWindowViews::Deactivate() { |
| 140 widget_->Deactivate(); |
| 141 } |
| 131 | 142 |
| 132 void NativeAppWindowViews::Maximize() { widget_->Maximize(); } | 143 void NativeAppWindowViews::Maximize() { |
| 144 widget_->Maximize(); |
| 145 } |
| 133 | 146 |
| 134 void NativeAppWindowViews::Minimize() { widget_->Minimize(); } | 147 void NativeAppWindowViews::Minimize() { |
| 148 widget_->Minimize(); |
| 149 } |
| 135 | 150 |
| 136 void NativeAppWindowViews::Restore() { widget_->Restore(); } | 151 void NativeAppWindowViews::Restore() { |
| 152 widget_->Restore(); |
| 153 } |
| 137 | 154 |
| 138 void NativeAppWindowViews::SetBounds(const gfx::Rect& bounds) { | 155 void NativeAppWindowViews::SetBounds(const gfx::Rect& bounds) { |
| 139 widget_->SetBounds(bounds); | 156 widget_->SetBounds(bounds); |
| 140 } | 157 } |
| 141 | 158 |
| 142 void NativeAppWindowViews::FlashFrame(bool flash) { | 159 void NativeAppWindowViews::FlashFrame(bool flash) { |
| 143 widget_->FlashFrame(flash); | 160 widget_->FlashFrame(flash); |
| 144 } | 161 } |
| 145 | 162 |
| 146 bool NativeAppWindowViews::IsAlwaysOnTop() const { | 163 bool NativeAppWindowViews::IsAlwaysOnTop() const { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 ui::WindowShowState show_state) { | 234 ui::WindowShowState show_state) { |
| 218 views::WidgetDelegate::SaveWindowPlacement(bounds, show_state); | 235 views::WidgetDelegate::SaveWindowPlacement(bounds, show_state); |
| 219 app_window_->OnNativeWindowChanged(); | 236 app_window_->OnNativeWindowChanged(); |
| 220 } | 237 } |
| 221 | 238 |
| 222 void NativeAppWindowViews::DeleteDelegate() { | 239 void NativeAppWindowViews::DeleteDelegate() { |
| 223 widget_->RemoveObserver(this); | 240 widget_->RemoveObserver(this); |
| 224 app_window_->OnNativeClose(); | 241 app_window_->OnNativeClose(); |
| 225 } | 242 } |
| 226 | 243 |
| 227 views::Widget* NativeAppWindowViews::GetWidget() { return widget_; } | 244 views::Widget* NativeAppWindowViews::GetWidget() { |
| 245 return widget_; |
| 246 } |
| 228 | 247 |
| 229 const views::Widget* NativeAppWindowViews::GetWidget() const { return widget_; } | 248 const views::Widget* NativeAppWindowViews::GetWidget() const { |
| 249 return widget_; |
| 250 } |
| 230 | 251 |
| 231 views::View* NativeAppWindowViews::GetContentsView() { | 252 views::View* NativeAppWindowViews::GetContentsView() { |
| 232 return this; | 253 return this; |
| 233 } | 254 } |
| 234 | 255 |
| 235 bool NativeAppWindowViews::ShouldDescendIntoChildForEventHandling( | 256 bool NativeAppWindowViews::ShouldDescendIntoChildForEventHandling( |
| 236 gfx::NativeView child, | 257 gfx::NativeView child, |
| 237 const gfx::Point& location) { | 258 const gfx::Point& location) { |
| 238 #if defined(USE_AURA) | 259 #if defined(USE_AURA) |
| 239 if (child->Contains(web_view_->web_contents()->GetNativeView())) { | 260 if (child->Contains(web_view_->web_contents()->GetNativeView())) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 void NativeAppWindowViews::SetFullscreen(int fullscreen_types) { | 333 void NativeAppWindowViews::SetFullscreen(int fullscreen_types) { |
| 313 // Stub implementation. See also ChromeNativeAppWindowViews. | 334 // Stub implementation. See also ChromeNativeAppWindowViews. |
| 314 widget_->SetFullscreen(fullscreen_types != AppWindow::FULLSCREEN_TYPE_NONE); | 335 widget_->SetFullscreen(fullscreen_types != AppWindow::FULLSCREEN_TYPE_NONE); |
| 315 } | 336 } |
| 316 | 337 |
| 317 bool NativeAppWindowViews::IsFullscreenOrPending() const { | 338 bool NativeAppWindowViews::IsFullscreenOrPending() const { |
| 318 // Stub implementation. See also ChromeNativeAppWindowViews. | 339 // Stub implementation. See also ChromeNativeAppWindowViews. |
| 319 return widget_->IsFullscreen(); | 340 return widget_->IsFullscreen(); |
| 320 } | 341 } |
| 321 | 342 |
| 322 void NativeAppWindowViews::UpdateWindowIcon() { widget_->UpdateWindowIcon(); } | 343 void NativeAppWindowViews::UpdateWindowIcon() { |
| 344 widget_->UpdateWindowIcon(); |
| 345 } |
| 323 | 346 |
| 324 void NativeAppWindowViews::UpdateWindowTitle() { widget_->UpdateWindowTitle(); } | 347 void NativeAppWindowViews::UpdateWindowTitle() { |
| 348 widget_->UpdateWindowTitle(); |
| 349 } |
| 325 | 350 |
| 326 void NativeAppWindowViews::UpdateBadgeIcon() { | 351 void NativeAppWindowViews::UpdateBadgeIcon() { |
| 327 // Stub implementation. See also ChromeNativeAppWindowViews. | 352 // Stub implementation. See also ChromeNativeAppWindowViews. |
| 328 } | 353 } |
| 329 | 354 |
| 330 void NativeAppWindowViews::UpdateDraggableRegions( | 355 void NativeAppWindowViews::UpdateDraggableRegions( |
| 331 const std::vector<extensions::DraggableRegion>& regions) { | 356 const std::vector<extensions::DraggableRegion>& regions) { |
| 332 // Draggable region is not supported for non-frameless window. | 357 // Draggable region is not supported for non-frameless window. |
| 333 if (!frameless_) | 358 if (!frameless_) |
| 334 return; | 359 return; |
| 335 | 360 |
| 336 draggable_region_.reset(AppWindow::RawDraggableRegionsToSkRegion(regions)); | 361 draggable_region_.reset(AppWindow::RawDraggableRegionsToSkRegion(regions)); |
| 337 OnViewWasResized(); | 362 OnViewWasResized(); |
| 338 } | 363 } |
| 339 | 364 |
| 340 SkRegion* NativeAppWindowViews::GetDraggableRegion() { | 365 SkRegion* NativeAppWindowViews::GetDraggableRegion() { |
| 341 return draggable_region_.get(); | 366 return draggable_region_.get(); |
| 342 } | 367 } |
| 343 | 368 |
| 344 void NativeAppWindowViews::UpdateShape(scoped_ptr<SkRegion> region) { | 369 void NativeAppWindowViews::UpdateShape(scoped_ptr<SkRegion> region) { |
| 345 // Stub implementation. See also ChromeNativeAppWindowViews. | 370 // Stub implementation. See also ChromeNativeAppWindowViews. |
| 346 } | 371 } |
| 347 | 372 |
| 348 void NativeAppWindowViews::HandleKeyboardEvent( | 373 void NativeAppWindowViews::HandleKeyboardEvent( |
| 349 const content::NativeWebKeyboardEvent& event) { | 374 const content::NativeWebKeyboardEvent& event) { |
| 350 unhandled_keyboard_event_handler_.HandleKeyboardEvent(event, | 375 unhandled_keyboard_event_handler_.HandleKeyboardEvent(event, |
| 351 GetFocusManager()); | 376 GetFocusManager()); |
| 352 } | 377 } |
| 353 | 378 |
| 354 bool NativeAppWindowViews::IsFrameless() const { return frameless_; } | 379 bool NativeAppWindowViews::IsFrameless() const { |
| 380 return frameless_; |
| 381 } |
| 355 | 382 |
| 356 bool NativeAppWindowViews::HasFrameColor() const { return false; } | 383 bool NativeAppWindowViews::HasFrameColor() const { |
| 384 return false; |
| 385 } |
| 357 | 386 |
| 358 SkColor NativeAppWindowViews::ActiveFrameColor() const { | 387 SkColor NativeAppWindowViews::ActiveFrameColor() const { |
| 359 return SK_ColorBLACK; | 388 return SK_ColorBLACK; |
| 360 } | 389 } |
| 361 | 390 |
| 362 SkColor NativeAppWindowViews::InactiveFrameColor() const { | 391 SkColor NativeAppWindowViews::InactiveFrameColor() const { |
| 363 return SK_ColorBLACK; | 392 return SK_ColorBLACK; |
| 364 } | 393 } |
| 365 | 394 |
| 366 gfx::Insets NativeAppWindowViews::GetFrameInsets() const { | 395 gfx::Insets NativeAppWindowViews::GetFrameInsets() const { |
| 367 if (frameless_) | 396 if (frameless_) |
| 368 return gfx::Insets(); | 397 return gfx::Insets(); |
| 369 | 398 |
| 370 // The pretend client_bounds passed in need to be large enough to ensure that | 399 // The pretend client_bounds passed in need to be large enough to ensure that |
| 371 // GetWindowBoundsForClientBounds() doesn't decide that it needs more than | 400 // GetWindowBoundsForClientBounds() doesn't decide that it needs more than |
| 372 // the specified amount of space to fit the window controls in, and return a | 401 // the specified amount of space to fit the window controls in, and return a |
| 373 // number larger than the real frame insets. Most window controls are smaller | 402 // number larger than the real frame insets. Most window controls are smaller |
| 374 // than 1000x1000px, so this should be big enough. | 403 // than 1000x1000px, so this should be big enough. |
| 375 gfx::Rect client_bounds = gfx::Rect(1000, 1000); | 404 gfx::Rect client_bounds = gfx::Rect(1000, 1000); |
| 376 gfx::Rect window_bounds = | 405 gfx::Rect window_bounds = |
| 377 widget_->non_client_view()->GetWindowBoundsForClientBounds(client_bounds); | 406 widget_->non_client_view()->GetWindowBoundsForClientBounds(client_bounds); |
| 378 return window_bounds.InsetsFrom(client_bounds); | 407 return window_bounds.InsetsFrom(client_bounds); |
| 379 } | 408 } |
| 380 | 409 |
| 381 void NativeAppWindowViews::HideWithApp() {} | 410 void NativeAppWindowViews::HideWithApp() { |
| 411 } |
| 382 | 412 |
| 383 void NativeAppWindowViews::ShowWithApp() {} | 413 void NativeAppWindowViews::ShowWithApp() { |
| 414 } |
| 384 | 415 |
| 385 void NativeAppWindowViews::UpdateShelfMenu() {} | 416 void NativeAppWindowViews::UpdateShelfMenu() { |
| 417 } |
| 386 | 418 |
| 387 gfx::Size NativeAppWindowViews::GetContentMinimumSize() const { | 419 gfx::Size NativeAppWindowViews::GetContentMinimumSize() const { |
| 388 return size_constraints_.GetMinimumSize(); | 420 return size_constraints_.GetMinimumSize(); |
| 389 } | 421 } |
| 390 | 422 |
| 391 gfx::Size NativeAppWindowViews::GetContentMaximumSize() const { | 423 gfx::Size NativeAppWindowViews::GetContentMaximumSize() const { |
| 392 return size_constraints_.GetMaximumSize(); | 424 return size_constraints_.GetMaximumSize(); |
| 393 } | 425 } |
| 394 | 426 |
| 395 void NativeAppWindowViews::SetContentSizeConstraints( | 427 void NativeAppWindowViews::SetContentSizeConstraints( |
| 396 const gfx::Size& min_size, const gfx::Size& max_size) { | 428 const gfx::Size& min_size, |
| 429 const gfx::Size& max_size) { |
| 397 size_constraints_.set_minimum_size(min_size); | 430 size_constraints_.set_minimum_size(min_size); |
| 398 size_constraints_.set_maximum_size(max_size); | 431 size_constraints_.set_maximum_size(max_size); |
| 399 widget_->OnSizeConstraintsChanged(); | 432 widget_->OnSizeConstraintsChanged(); |
| 400 } | 433 } |
| 401 | 434 |
| 402 bool NativeAppWindowViews::CanHaveAlphaEnabled() const { | 435 bool NativeAppWindowViews::CanHaveAlphaEnabled() const { |
| 403 return widget_->IsTranslucentWindowOpacitySupported(); | 436 return widget_->IsTranslucentWindowOpacitySupported(); |
| 404 } | 437 } |
| 405 | 438 |
| 406 void NativeAppWindowViews::SetVisibleOnAllWorkspaces(bool always_visible) { | 439 void NativeAppWindowViews::SetVisibleOnAllWorkspaces(bool always_visible) { |
| 407 widget_->SetVisibleOnAllWorkspaces(always_visible); | 440 widget_->SetVisibleOnAllWorkspaces(always_visible); |
| 408 } | 441 } |
| 409 | 442 |
| 410 } // namespace apps | 443 } // namespace extensions |
| OLD | NEW |