| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/ui/views/apps/native_app_window_views.h" | 5 #include "chrome/browser/ui/views/apps/native_app_window_views.h" |
| 6 | 6 |
| 7 #include "apps/ui/views/shell_window_frame_view.h" |
| 7 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 8 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 9 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 10 #include "base/threading/sequenced_worker_pool.h" | 11 #include "base/threading/sequenced_worker_pool.h" |
| 11 #include "chrome/app/chrome_command_ids.h" | 12 #include "chrome/app/chrome_command_ids.h" |
| 12 #include "chrome/browser/extensions/extension_host.h" | 13 #include "chrome/browser/extensions/extension_host.h" |
| 13 #include "chrome/browser/favicon/favicon_tab_helper.h" | 14 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views
.h" | 16 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views
.h" |
| 16 #include "chrome/browser/ui/views/extensions/shell_window_frame_view.h" | |
| 17 #include "chrome/browser/web_applications/web_app.h" | 17 #include "chrome/browser/web_applications/web_app.h" |
| 18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/common/extensions/extension.h" | 19 #include "chrome/common/extensions/extension.h" |
| 20 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/render_view_host.h" | 21 #include "content/public/browser/render_view_host.h" |
| 22 #include "content/public/browser/render_widget_host_view.h" | 22 #include "content/public/browser/render_widget_host_view.h" |
| 23 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 24 #include "content/public/browser/web_contents_view.h" | 24 #include "content/public/browser/web_contents_view.h" |
| 25 #include "extensions/common/draggable_region.h" | 25 #include "extensions/common/draggable_region.h" |
| 26 #include "ui/views/controls/webview/webview.h" | 26 #include "ui/views/controls/webview/webview.h" |
| 27 #include "ui/views/widget/widget.h" | 27 #include "ui/views/widget/widget.h" |
| 28 #include "ui/views/window/non_client_view.h" | 28 #include "ui/views/window/non_client_view.h" |
| 29 | 29 |
| 30 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
| 31 #include "base/strings/utf_string_conversions.h" | 31 #include "base/strings/utf_string_conversions.h" |
| 32 #include "chrome/browser/ui/web_applications/web_app_ui.h" | 32 #include "chrome/browser/ui/web_applications/web_app_ui.h" |
| 33 #include "chrome/browser/web_applications/web_app_win.h" | 33 #include "chrome/browser/web_applications/web_app_win.h" |
| 34 #include "ui/base/win/shell.h" | 34 #include "ui/base/win/shell.h" |
| 35 #include "ui/views/win/hwnd_util.h" | 35 #include "ui/views/win/hwnd_util.h" |
| 36 #endif | 36 #endif |
| 37 | 37 |
| 38 #if defined(OS_LINUX) | 38 #if defined(OS_LINUX) |
| 39 #include "chrome/browser/shell_integration_linux.h" | 39 #include "chrome/browser/shell_integration_linux.h" |
| 40 #endif | 40 #endif |
| 41 | 41 |
| 42 #if defined(USE_ASH) | 42 #if defined(USE_ASH) |
| 43 #include "ash/ash_constants.h" |
| 43 #include "ash/screen_ash.h" | 44 #include "ash/screen_ash.h" |
| 44 #include "ash/shell.h" | 45 #include "ash/shell.h" |
| 45 #include "ash/wm/custom_frame_view_ash.h" | 46 #include "ash/wm/custom_frame_view_ash.h" |
| 46 #include "ash/wm/panels/panel_frame_view.h" | 47 #include "ash/wm/panels/panel_frame_view.h" |
| 47 #include "ash/wm/window_state.h" | 48 #include "ash/wm/window_state.h" |
| 48 #include "chrome/browser/ui/ash/ash_util.h" | 49 #include "chrome/browser/ui/ash/ash_util.h" |
| 49 #include "ui/aura/client/aura_constants.h" | 50 #include "ui/aura/client/aura_constants.h" |
| 50 #include "ui/aura/root_window.h" | 51 #include "ui/aura/root_window.h" |
| 51 #include "ui/aura/window.h" | 52 #include "ui/aura/window.h" |
| 52 #endif | 53 #endif |
| 53 | 54 |
| 54 using apps::ShellWindow; | 55 using apps::ShellWindow; |
| 55 | 56 |
| 56 namespace { | 57 namespace { |
| 57 | 58 |
| 58 const int kMinPanelWidth = 100; | 59 const int kMinPanelWidth = 100; |
| 59 const int kMinPanelHeight = 100; | 60 const int kMinPanelHeight = 100; |
| 60 const int kDefaultPanelWidth = 200; | 61 const int kDefaultPanelWidth = 200; |
| 61 const int kDefaultPanelHeight = 300; | 62 const int kDefaultPanelHeight = 300; |
| 62 const int kResizeInsideBoundsSize = 5; | 63 const int kResizeInsideBoundsSize = 5; |
| 64 const int kResizeAreaCornerSize = 16; |
| 63 | 65 |
| 64 struct AcceleratorMapping { | 66 struct AcceleratorMapping { |
| 65 ui::KeyboardCode keycode; | 67 ui::KeyboardCode keycode; |
| 66 int modifiers; | 68 int modifiers; |
| 67 int command_id; | 69 int command_id; |
| 68 }; | 70 }; |
| 69 const AcceleratorMapping kAppWindowAcceleratorMap[] = { | 71 const AcceleratorMapping kAppWindowAcceleratorMap[] = { |
| 70 { ui::VKEY_W, ui::EF_CONTROL_DOWN, IDC_CLOSE_WINDOW }, | 72 { ui::VKEY_W, ui::EF_CONTROL_DOWN, IDC_CLOSE_WINDOW }, |
| 71 { ui::VKEY_W, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN, IDC_CLOSE_WINDOW }, | 73 { ui::VKEY_W, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN, IDC_CLOSE_WINDOW }, |
| 72 { ui::VKEY_F4, ui::EF_ALT_DOWN, IDC_CLOSE_WINDOW }, | 74 { ui::VKEY_F4, ui::EF_ALT_DOWN, IDC_CLOSE_WINDOW }, |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 native_window->SetDefaultParentByRootWindow( | 292 native_window->SetDefaultParentByRootWindow( |
| 291 native_window->GetRootWindow(), native_window->GetBoundsInScreen()); | 293 native_window->GetRootWindow(), native_window->GetBoundsInScreen()); |
| 292 window_->SetBounds(window_bounds); | 294 window_->SetBounds(window_bounds); |
| 293 } | 295 } |
| 294 #else | 296 #else |
| 295 // TODO(stevenjb): NativeAppWindow panels need to be implemented for other | 297 // TODO(stevenjb): NativeAppWindow panels need to be implemented for other |
| 296 // platforms. | 298 // platforms. |
| 297 #endif | 299 #endif |
| 298 } | 300 } |
| 299 | 301 |
| 302 bool NativeAppWindowViews::ShouldUseChromeStyleFrame() const { |
| 303 return !CommandLine::ForCurrentProcess()->HasSwitch( |
| 304 switches::kAppsUseNativeFrame) || frameless_; |
| 305 } |
| 306 |
| 307 apps::ShellWindowFrameView* NativeAppWindowViews::CreateShellWindowFrameView() { |
| 308 // By default the user can resize the window from slightly inside the bounds. |
| 309 int resize_inside_bounds_size = kResizeInsideBoundsSize; |
| 310 int resize_outside_bounds_size = 0; |
| 311 int resize_outside_scale_for_touch = 1; |
| 312 int resize_area_corner_size = kResizeAreaCornerSize; |
| 313 #if defined(USE_ASH) |
| 314 // For Aura windows on the Ash desktop the sizes are different and the user |
| 315 // can resize the window from slightly outside the bounds as well. |
| 316 if (chrome::IsNativeWindowInAsh(window_->GetNativeWindow())) { |
| 317 resize_inside_bounds_size = ash::kResizeInsideBoundsSize; |
| 318 resize_outside_bounds_size = ash::kResizeOutsideBoundsSize; |
| 319 resize_outside_scale_for_touch = ash::kResizeOutsideBoundsScaleForTouch; |
| 320 resize_area_corner_size = ash::kResizeAreaCornerSize; |
| 321 } |
| 322 #endif |
| 323 apps::ShellWindowFrameView* frame_view = new apps::ShellWindowFrameView(this); |
| 324 frame_view->Init(window_, |
| 325 resize_inside_bounds_size, |
| 326 resize_outside_bounds_size, |
| 327 resize_outside_scale_for_touch, |
| 328 resize_area_corner_size); |
| 329 return frame_view; |
| 330 } |
| 331 |
| 300 // ui::BaseWindow implementation. | 332 // ui::BaseWindow implementation. |
| 301 | 333 |
| 302 bool NativeAppWindowViews::IsActive() const { | 334 bool NativeAppWindowViews::IsActive() const { |
| 303 return window_->IsActive(); | 335 return window_->IsActive(); |
| 304 } | 336 } |
| 305 | 337 |
| 306 bool NativeAppWindowViews::IsMaximized() const { | 338 bool NativeAppWindowViews::IsMaximized() const { |
| 307 return window_->IsMaximized(); | 339 return window_->IsMaximized(); |
| 308 } | 340 } |
| 309 | 341 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 return ash::wm::GetWindowState(window_->GetNativeWindow())-> | 448 return ash::wm::GetWindowState(window_->GetNativeWindow())-> |
| 417 panel_attached(); | 449 panel_attached(); |
| 418 #else | 450 #else |
| 419 return true; | 451 return true; |
| 420 #endif | 452 #endif |
| 421 } else { | 453 } else { |
| 422 return window_->IsAlwaysOnTop(); | 454 return window_->IsAlwaysOnTop(); |
| 423 } | 455 } |
| 424 } | 456 } |
| 425 | 457 |
| 458 bool NativeAppWindowViews::IsFrameless() const { |
| 459 return frameless_; |
| 460 } |
| 461 |
| 426 gfx::Insets NativeAppWindowViews::GetFrameInsets() const { | 462 gfx::Insets NativeAppWindowViews::GetFrameInsets() const { |
| 427 if (frameless()) | 463 if (frameless_) |
| 428 return gfx::Insets(); | 464 return gfx::Insets(); |
| 429 | 465 |
| 430 // The pretend client_bounds passed in need to be large enough to ensure that | 466 // The pretend client_bounds passed in need to be large enough to ensure that |
| 431 // GetWindowBoundsForClientBounds() doesn't decide that it needs more than | 467 // GetWindowBoundsForClientBounds() doesn't decide that it needs more than |
| 432 // the specified amount of space to fit the window controls in, and return a | 468 // the specified amount of space to fit the window controls in, and return a |
| 433 // number larger than the real frame insets. Most window controls are smaller | 469 // number larger than the real frame insets. Most window controls are smaller |
| 434 // than 1000x1000px, so this should be big enough. | 470 // than 1000x1000px, so this should be big enough. |
| 435 gfx::Rect client_bounds = gfx::Rect(1000, 1000); | 471 gfx::Rect client_bounds = gfx::Rect(1000, 1000); |
| 436 gfx::Rect window_bounds = | 472 gfx::Rect window_bounds = |
| 437 window_->non_client_view()->GetWindowBoundsForClientBounds( | 473 window_->non_client_view()->GetWindowBoundsForClientBounds( |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 } | 564 } |
| 529 if (web_contents()->GetRenderViewHost()->GetView()) | 565 if (web_contents()->GetRenderViewHost()->GetView()) |
| 530 web_contents()->GetRenderViewHost()->GetView()->SetClickthroughRegion(rgn); | 566 web_contents()->GetRenderViewHost()->GetView()->SetClickthroughRegion(rgn); |
| 531 #endif | 567 #endif |
| 532 | 568 |
| 533 FOR_EACH_OBSERVER(web_modal::ModalDialogHostObserver, | 569 FOR_EACH_OBSERVER(web_modal::ModalDialogHostObserver, |
| 534 observer_list_, | 570 observer_list_, |
| 535 OnPositionRequiresUpdate()); | 571 OnPositionRequiresUpdate()); |
| 536 } | 572 } |
| 537 | 573 |
| 538 bool NativeAppWindowViews::ShouldUseChromeStyleFrame() const { | |
| 539 return !CommandLine::ForCurrentProcess()->HasSwitch( | |
| 540 switches::kAppsUseNativeFrame) || frameless_; | |
| 541 } | |
| 542 | |
| 543 // WidgetDelegate implementation. | 574 // WidgetDelegate implementation. |
| 544 | 575 |
| 545 void NativeAppWindowViews::OnWidgetMove() { | 576 void NativeAppWindowViews::OnWidgetMove() { |
| 546 shell_window_->OnNativeWindowChanged(); | 577 shell_window_->OnNativeWindowChanged(); |
| 547 } | 578 } |
| 548 | 579 |
| 549 views::View* NativeAppWindowViews::GetInitiallyFocusedView() { | 580 views::View* NativeAppWindowViews::GetInitiallyFocusedView() { |
| 550 return web_view_; | 581 return web_view_; |
| 551 } | 582 } |
| 552 | 583 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 ash::PanelFrameView::FRAME_NONE : ash::PanelFrameView::FRAME_ASH; | 651 ash::PanelFrameView::FRAME_NONE : ash::PanelFrameView::FRAME_ASH; |
| 621 return new ash::PanelFrameView(widget, frame_type); | 652 return new ash::PanelFrameView(widget, frame_type); |
| 622 } | 653 } |
| 623 if (!frameless_) { | 654 if (!frameless_) { |
| 624 ash::CustomFrameViewAsh* frame = new ash::CustomFrameViewAsh(); | 655 ash::CustomFrameViewAsh* frame = new ash::CustomFrameViewAsh(); |
| 625 frame->Init(widget); | 656 frame->Init(widget); |
| 626 return frame; | 657 return frame; |
| 627 } | 658 } |
| 628 } | 659 } |
| 629 #endif | 660 #endif |
| 630 if (ShouldUseChromeStyleFrame()) { | 661 if (ShouldUseChromeStyleFrame()) |
| 631 ShellWindowFrameView* frame_view = new ShellWindowFrameView(this); | 662 return CreateShellWindowFrameView(); |
| 632 frame_view->Init(window_); | |
| 633 return frame_view; | |
| 634 } | |
| 635 return views::WidgetDelegateView::CreateNonClientFrameView(widget); | 663 return views::WidgetDelegateView::CreateNonClientFrameView(widget); |
| 636 } | 664 } |
| 637 | 665 |
| 638 bool NativeAppWindowViews::WidgetHasHitTestMask() const { | 666 bool NativeAppWindowViews::WidgetHasHitTestMask() const { |
| 639 return input_region_ != NULL; | 667 return input_region_ != NULL; |
| 640 } | 668 } |
| 641 | 669 |
| 642 void NativeAppWindowViews::GetWidgetHitTestMask(gfx::Path* mask) const { | 670 void NativeAppWindowViews::GetWidgetHitTestMask(gfx::Path* mask) const { |
| 643 input_region_->getBoundaryPath(mask); | 671 input_region_->getBoundaryPath(mask); |
| 644 } | 672 } |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 void NativeAppWindowViews::UpdateDraggableRegions( | 816 void NativeAppWindowViews::UpdateDraggableRegions( |
| 789 const std::vector<extensions::DraggableRegion>& regions) { | 817 const std::vector<extensions::DraggableRegion>& regions) { |
| 790 // Draggable region is not supported for non-frameless window. | 818 // Draggable region is not supported for non-frameless window. |
| 791 if (!frameless_) | 819 if (!frameless_) |
| 792 return; | 820 return; |
| 793 | 821 |
| 794 draggable_region_.reset(ShellWindow::RawDraggableRegionsToSkRegion(regions)); | 822 draggable_region_.reset(ShellWindow::RawDraggableRegionsToSkRegion(regions)); |
| 795 OnViewWasResized(); | 823 OnViewWasResized(); |
| 796 } | 824 } |
| 797 | 825 |
| 826 SkRegion* NativeAppWindowViews::GetDraggableRegion() const { |
| 827 return draggable_region_.get(); |
| 828 } |
| 829 |
| 798 void NativeAppWindowViews::HandleKeyboardEvent( | 830 void NativeAppWindowViews::HandleKeyboardEvent( |
| 799 const content::NativeWebKeyboardEvent& event) { | 831 const content::NativeWebKeyboardEvent& event) { |
| 800 unhandled_keyboard_event_handler_.HandleKeyboardEvent(event, | 832 unhandled_keyboard_event_handler_.HandleKeyboardEvent(event, |
| 801 GetFocusManager()); | 833 GetFocusManager()); |
| 802 } | 834 } |
| 803 | 835 |
| 804 void NativeAppWindowViews::RenderViewHostChanged( | 836 void NativeAppWindowViews::RenderViewHostChanged( |
| 805 content::RenderViewHost* old_host, | 837 content::RenderViewHost* old_host, |
| 806 content::RenderViewHost* new_host) { | 838 content::RenderViewHost* new_host) { |
| 807 OnViewWasResized(); | 839 OnViewWasResized(); |
| 808 } | 840 } |
| OLD | NEW |