Chromium Code Reviews| 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 { | |
|
James Cook
2013/10/11 23:05:06
I just moved it to match the header order.
| |
| 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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 528 } | 560 } |
| 529 if (web_contents()->GetRenderViewHost()->GetView()) | 561 if (web_contents()->GetRenderViewHost()->GetView()) |
| 530 web_contents()->GetRenderViewHost()->GetView()->SetClickthroughRegion(rgn); | 562 web_contents()->GetRenderViewHost()->GetView()->SetClickthroughRegion(rgn); |
| 531 #endif | 563 #endif |
| 532 | 564 |
| 533 FOR_EACH_OBSERVER(web_modal::ModalDialogHostObserver, | 565 FOR_EACH_OBSERVER(web_modal::ModalDialogHostObserver, |
| 534 observer_list_, | 566 observer_list_, |
| 535 OnPositionRequiresUpdate()); | 567 OnPositionRequiresUpdate()); |
| 536 } | 568 } |
| 537 | 569 |
| 538 bool NativeAppWindowViews::ShouldUseChromeStyleFrame() const { | |
| 539 return !CommandLine::ForCurrentProcess()->HasSwitch( | |
| 540 switches::kAppsUseNativeFrame) || frameless_; | |
| 541 } | |
| 542 | |
| 543 // WidgetDelegate implementation. | 570 // WidgetDelegate implementation. |
| 544 | 571 |
| 545 void NativeAppWindowViews::OnWidgetMove() { | 572 void NativeAppWindowViews::OnWidgetMove() { |
| 546 shell_window_->OnNativeWindowChanged(); | 573 shell_window_->OnNativeWindowChanged(); |
| 547 } | 574 } |
| 548 | 575 |
| 549 views::View* NativeAppWindowViews::GetInitiallyFocusedView() { | 576 views::View* NativeAppWindowViews::GetInitiallyFocusedView() { |
| 550 return web_view_; | 577 return web_view_; |
| 551 } | 578 } |
| 552 | 579 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 620 ash::PanelFrameView::FRAME_NONE : ash::PanelFrameView::FRAME_ASH; | 647 ash::PanelFrameView::FRAME_NONE : ash::PanelFrameView::FRAME_ASH; |
| 621 return new ash::PanelFrameView(widget, frame_type); | 648 return new ash::PanelFrameView(widget, frame_type); |
| 622 } | 649 } |
| 623 if (!frameless_) { | 650 if (!frameless_) { |
| 624 ash::CustomFrameViewAsh* frame = new ash::CustomFrameViewAsh(); | 651 ash::CustomFrameViewAsh* frame = new ash::CustomFrameViewAsh(); |
| 625 frame->Init(widget); | 652 frame->Init(widget); |
| 626 return frame; | 653 return frame; |
| 627 } | 654 } |
| 628 } | 655 } |
| 629 #endif | 656 #endif |
| 630 if (ShouldUseChromeStyleFrame()) { | 657 if (ShouldUseChromeStyleFrame()) |
| 631 ShellWindowFrameView* frame_view = new ShellWindowFrameView(this); | 658 return CreateShellWindowFrameView(); |
| 632 frame_view->Init(window_); | |
| 633 return frame_view; | |
| 634 } | |
| 635 return views::WidgetDelegateView::CreateNonClientFrameView(widget); | 659 return views::WidgetDelegateView::CreateNonClientFrameView(widget); |
| 636 } | 660 } |
| 637 | 661 |
| 638 bool NativeAppWindowViews::WidgetHasHitTestMask() const { | 662 bool NativeAppWindowViews::WidgetHasHitTestMask() const { |
| 639 return input_region_ != NULL; | 663 return input_region_ != NULL; |
| 640 } | 664 } |
| 641 | 665 |
| 642 void NativeAppWindowViews::GetWidgetHitTestMask(gfx::Path* mask) const { | 666 void NativeAppWindowViews::GetWidgetHitTestMask(gfx::Path* mask) const { |
| 643 input_region_->getBoundaryPath(mask); | 667 input_region_->getBoundaryPath(mask); |
| 644 } | 668 } |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 799 const content::NativeWebKeyboardEvent& event) { | 823 const content::NativeWebKeyboardEvent& event) { |
| 800 unhandled_keyboard_event_handler_.HandleKeyboardEvent(event, | 824 unhandled_keyboard_event_handler_.HandleKeyboardEvent(event, |
| 801 GetFocusManager()); | 825 GetFocusManager()); |
| 802 } | 826 } |
| 803 | 827 |
| 804 void NativeAppWindowViews::RenderViewHostChanged( | 828 void NativeAppWindowViews::RenderViewHostChanged( |
| 805 content::RenderViewHost* old_host, | 829 content::RenderViewHost* old_host, |
| 806 content::RenderViewHost* new_host) { | 830 content::RenderViewHost* new_host) { |
| 807 OnViewWasResized(); | 831 OnViewWasResized(); |
| 808 } | 832 } |
| OLD | NEW |