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 "chrome/browser/ui/views/apps/chrome_native_app_window_views.h" | 5 #include "chrome/browser/ui/views/apps/chrome_native_app_window_views.h" |
6 | 6 |
7 #include "apps/ui/views/app_window_frame_view.h" | 7 #include "apps/ui/views/app_window_frame_view.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
10 #include "chrome/browser/app_mode/app_mode_utils.h" | 10 #include "chrome/browser/app_mode/app_mode_utils.h" |
11 #include "chrome/browser/chrome_page_zoom.h" | 11 #include "chrome/browser/chrome_page_zoom.h" |
12 #include "chrome/browser/favicon/favicon_tab_helper.h" | 12 #include "chrome/browser/favicon/favicon_tab_helper.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/ui/host_desktop.h" | 14 #include "chrome/browser/ui/host_desktop.h" |
15 #include "chrome/browser/ui/views/apps/shaped_app_window_targeter.h" | 15 #include "chrome/browser/ui/views/apps/shaped_app_window_targeter.h" |
16 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views
.h" | 16 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views
.h" |
17 #include "chrome/browser/ui/views/frame/taskbar_decorator.h" | 17 #include "chrome/browser/ui/views/frame/taskbar_decorator.h" |
18 #include "chrome/browser/web_applications/web_app.h" | 18 #include "chrome/browser/web_applications/web_app.h" |
19 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
20 #include "extensions/common/extension.h" | 20 #include "extensions/common/extension.h" |
| 21 #include "ui/aura/window.h" |
21 #include "ui/base/hit_test.h" | 22 #include "ui/base/hit_test.h" |
22 #include "ui/base/models/simple_menu_model.h" | 23 #include "ui/base/models/simple_menu_model.h" |
23 #include "ui/gfx/image/image_skia.h" | 24 #include "ui/gfx/image/image_skia.h" |
24 #include "ui/views/controls/menu/menu_runner.h" | 25 #include "ui/views/controls/menu/menu_runner.h" |
25 #include "ui/views/controls/webview/webview.h" | 26 #include "ui/views/controls/webview/webview.h" |
26 #include "ui/views/widget/widget.h" | 27 #include "ui/views/widget/widget.h" |
27 #include "ui/wm/core/easy_resize_window_targeter.h" | |
28 | 28 |
29 #if defined(OS_LINUX) | 29 #if defined(OS_LINUX) |
30 #include "chrome/browser/shell_integration_linux.h" | 30 #include "chrome/browser/shell_integration_linux.h" |
31 #endif | 31 #endif |
32 | 32 |
33 #if defined(USE_ASH) | 33 #if defined(USE_ASH) |
34 #include "ash/ash_constants.h" | 34 #include "ash/ash_constants.h" |
35 #include "ash/ash_switches.h" | 35 #include "ash/ash_switches.h" |
36 #include "ash/frame/custom_frame_view_ash.h" | 36 #include "ash/frame/custom_frame_view_ash.h" |
37 #include "ash/screen_util.h" | 37 #include "ash/screen_util.h" |
38 #include "ash/shell.h" | 38 #include "ash/shell.h" |
39 #include "ash/wm/immersive_fullscreen_controller.h" | 39 #include "ash/wm/immersive_fullscreen_controller.h" |
40 #include "ash/wm/panels/panel_frame_view.h" | 40 #include "ash/wm/panels/panel_frame_view.h" |
41 #include "ash/wm/window_state.h" | 41 #include "ash/wm/window_state.h" |
42 #include "ash/wm/window_state_delegate.h" | 42 #include "ash/wm/window_state_delegate.h" |
43 #include "ash/wm/window_state_observer.h" | 43 #include "ash/wm/window_state_observer.h" |
44 #include "chrome/browser/ui/ash/ash_util.h" | 44 #include "chrome/browser/ui/ash/ash_util.h" |
45 #include "chrome/browser/ui/ash/multi_user/multi_user_context_menu.h" | 45 #include "chrome/browser/ui/ash/multi_user/multi_user_context_menu.h" |
46 #include "ui/aura/client/aura_constants.h" | 46 #include "ui/aura/client/aura_constants.h" |
47 #include "ui/aura/client/window_tree_client.h" | 47 #include "ui/aura/client/window_tree_client.h" |
48 #include "ui/aura/window.h" | |
49 #include "ui/aura/window_observer.h" | 48 #include "ui/aura/window_observer.h" |
50 #endif | 49 #endif |
51 | 50 |
52 #if defined(USE_AURA) | |
53 #include "ui/aura/window.h" | |
54 #endif | |
55 | |
56 using apps::AppWindow; | 51 using apps::AppWindow; |
57 | 52 |
58 namespace { | 53 namespace { |
59 | 54 |
60 const int kMinPanelWidth = 100; | 55 const int kMinPanelWidth = 100; |
61 const int kMinPanelHeight = 100; | 56 const int kMinPanelHeight = 100; |
62 const int kDefaultPanelWidth = 200; | 57 const int kDefaultPanelWidth = 200; |
63 const int kDefaultPanelHeight = 300; | 58 const int kDefaultPanelHeight = 300; |
64 const int kResizeInsideBoundsSize = 5; | |
65 const int kResizeAreaCornerSize = 16; | |
66 | 59 |
67 struct AcceleratorMapping { | 60 struct AcceleratorMapping { |
68 ui::KeyboardCode keycode; | 61 ui::KeyboardCode keycode; |
69 int modifiers; | 62 int modifiers; |
70 int command_id; | 63 int command_id; |
71 }; | 64 }; |
72 | 65 |
73 const AcceleratorMapping kAppWindowAcceleratorMap[] = { | 66 const AcceleratorMapping kAppWindowAcceleratorMap[] = { |
74 { ui::VKEY_W, ui::EF_CONTROL_DOWN, IDC_CLOSE_WINDOW }, | 67 { ui::VKEY_W, ui::EF_CONTROL_DOWN, IDC_CLOSE_WINDOW }, |
75 { ui::VKEY_W, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN, IDC_CLOSE_WINDOW }, | 68 { ui::VKEY_W, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN, IDC_CLOSE_WINDOW }, |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 native_window->GetRootWindow(), | 317 native_window->GetRootWindow(), |
325 native_window->GetBoundsInScreen()); | 318 native_window->GetBoundsInScreen()); |
326 widget()->SetBounds(window_bounds); | 319 widget()->SetBounds(window_bounds); |
327 } | 320 } |
328 #else | 321 #else |
329 // TODO(stevenjb): NativeAppWindow panels need to be implemented for other | 322 // TODO(stevenjb): NativeAppWindow panels need to be implemented for other |
330 // platforms. | 323 // platforms. |
331 #endif | 324 #endif |
332 } | 325 } |
333 | 326 |
334 void ChromeNativeAppWindowViews::InstallEasyResizeTargeterOnContainer() const { | 327 views::NonClientFrameView* |
335 aura::Window* root_window = widget()->GetNativeWindow()->GetRootWindow(); | 328 ChromeNativeAppWindowViews::CreateStandardAppWindowFrame() { |
336 gfx::Insets inset(kResizeInsideBoundsSize, kResizeInsideBoundsSize, | 329 return views::WidgetDelegateView::CreateNonClientFrameView(widget()); |
337 kResizeInsideBoundsSize, kResizeInsideBoundsSize); | |
338 root_window->SetEventTargeter(scoped_ptr<ui::EventTargeter>( | |
339 new wm::EasyResizeWindowTargeter(root_window, inset, inset))); | |
340 } | 330 } |
341 | 331 |
342 apps::AppWindowFrameView* | 332 apps::AppWindowFrameView* |
343 ChromeNativeAppWindowViews::CreateAppWindowFrameView() { | 333 ChromeNativeAppWindowViews::CreateNonStandardAppWindowFrame() { |
344 // By default the user can resize the window from slightly inside the bounds. | 334 apps::AppWindowFrameView* frame = new apps::AppWindowFrameView( |
345 int resize_inside_bounds_size = kResizeInsideBoundsSize; | 335 widget(), this, has_frame_color_, frame_color_); |
346 int resize_outside_bounds_size = 0; | |
347 int resize_outside_scale_for_touch = 1; | |
348 int resize_area_corner_size = kResizeAreaCornerSize; | |
349 #if defined(USE_ASH) | 336 #if defined(USE_ASH) |
350 // For Aura windows on the Ash desktop the sizes are different and the user | 337 // For Aura windows on the Ash desktop the sizes are different and the user |
351 // can resize the window from slightly outside the bounds as well. | 338 // can resize the window from slightly outside the bounds as well. |
352 if (chrome::IsNativeWindowInAsh(widget()->GetNativeWindow())) { | 339 if (chrome::IsNativeWindowInAsh(widget()->GetNativeWindow())) { |
353 resize_inside_bounds_size = ash::kResizeInsideBoundsSize; | 340 frame->SetResizeSizes(ash::kResizeInsideBoundsSize, |
354 resize_outside_bounds_size = ash::kResizeOutsideBoundsSize; | 341 ash::kResizeOutsideBoundsSize, |
355 resize_outside_scale_for_touch = ash::kResizeOutsideBoundsScaleForTouch; | 342 ash::kResizeAreaCornerSize); |
356 resize_area_corner_size = ash::kResizeAreaCornerSize; | |
357 } | 343 } |
358 #endif | 344 #endif |
359 apps::AppWindowFrameView* frame_view = new apps::AppWindowFrameView(); | 345 return frame; |
360 frame_view->Init(widget(), | |
361 this, | |
362 has_frame_color_, | |
363 frame_color_, | |
364 resize_inside_bounds_size, | |
365 resize_outside_bounds_size, | |
366 resize_outside_scale_for_touch, | |
367 resize_area_corner_size); | |
368 return frame_view; | |
369 } | 346 } |
370 | 347 |
371 // ui::BaseWindow implementation. | 348 // ui::BaseWindow implementation. |
372 | 349 |
373 ui::WindowShowState ChromeNativeAppWindowViews::GetRestoredState() const { | 350 ui::WindowShowState ChromeNativeAppWindowViews::GetRestoredState() const { |
374 if (IsMaximized()) | 351 if (IsMaximized()) |
375 return ui::SHOW_STATE_MAXIMIZED; | 352 return ui::SHOW_STATE_MAXIMIZED; |
376 if (IsFullscreen()) { | 353 if (IsFullscreen()) { |
377 #if defined(USE_ASH) | 354 #if defined(USE_ASH) |
378 if (immersive_fullscreen_controller_.get() && | 355 if (immersive_fullscreen_controller_.get() && |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 | 462 |
486 if (app_window()->window_type_is_panel()) { | 463 if (app_window()->window_type_is_panel()) { |
487 ash::PanelFrameView::FrameType frame_type = IsFrameless() ? | 464 ash::PanelFrameView::FrameType frame_type = IsFrameless() ? |
488 ash::PanelFrameView::FRAME_NONE : ash::PanelFrameView::FRAME_ASH; | 465 ash::PanelFrameView::FRAME_NONE : ash::PanelFrameView::FRAME_ASH; |
489 views::NonClientFrameView* frame_view = | 466 views::NonClientFrameView* frame_view = |
490 new ash::PanelFrameView(widget, frame_type); | 467 new ash::PanelFrameView(widget, frame_type); |
491 frame_view->set_context_menu_controller(this); | 468 frame_view->set_context_menu_controller(this); |
492 return frame_view; | 469 return frame_view; |
493 } | 470 } |
494 | 471 |
495 if (!IsFrameless()) { | 472 if (IsFrameless()) |
496 ash::CustomFrameViewAsh* custom_frame_view = | 473 return CreateNonStandardAppWindowFrame(); |
497 new ash::CustomFrameViewAsh(widget); | 474 |
| 475 ash::CustomFrameViewAsh* custom_frame_view = |
| 476 new ash::CustomFrameViewAsh(widget); |
498 #if defined(OS_CHROMEOS) | 477 #if defined(OS_CHROMEOS) |
499 // Non-frameless app windows can be put into immersive fullscreen. | 478 // Non-frameless app windows can be put into immersive fullscreen. |
500 // TODO(pkotwicz): Investigate if immersive fullscreen can be enabled for | 479 // TODO(pkotwicz): Investigate if immersive fullscreen can be enabled for |
501 // Windows Ash. | 480 // Windows Ash. |
502 immersive_fullscreen_controller_.reset( | 481 immersive_fullscreen_controller_.reset( |
503 new ash::ImmersiveFullscreenController()); | 482 new ash::ImmersiveFullscreenController()); |
504 custom_frame_view->InitImmersiveFullscreenControllerForView( | 483 custom_frame_view->InitImmersiveFullscreenControllerForView( |
505 immersive_fullscreen_controller_.get()); | 484 immersive_fullscreen_controller_.get()); |
506 #endif | 485 #endif |
507 custom_frame_view->GetHeaderView()->set_context_menu_controller(this); | 486 custom_frame_view->GetHeaderView()->set_context_menu_controller(this); |
508 return custom_frame_view; | 487 return custom_frame_view; |
509 } | |
510 } | 488 } |
511 #endif | 489 #endif |
512 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 490 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
513 return CreateAppWindowFrameView(); | 491 // Linux always uses the non standard frame view because the OS draws the |
| 492 // frame (if a frame is needed). |
| 493 return CreateNonStandardAppWindowFrame(); |
514 #else | 494 #else |
515 if (IsFrameless() || has_frame_color_) | 495 if (IsFrameless() || has_frame_color_) |
516 return CreateAppWindowFrameView(); | 496 return CreateNonStandardAppWindowFrame(); |
517 #endif | 497 #endif |
518 return views::WidgetDelegateView::CreateNonClientFrameView(widget); | 498 return CreateStandardAppWindowFrame(); |
519 } | 499 } |
520 | 500 |
521 bool ChromeNativeAppWindowViews::WidgetHasHitTestMask() const { | 501 bool ChromeNativeAppWindowViews::WidgetHasHitTestMask() const { |
522 return shape_ != NULL; | 502 return shape_ != NULL; |
523 } | 503 } |
524 | 504 |
525 void ChromeNativeAppWindowViews::GetWidgetHitTestMask(gfx::Path* mask) const { | 505 void ChromeNativeAppWindowViews::GetWidgetHitTestMask(gfx::Path* mask) const { |
526 shape_->getBoundaryPath(mask); | 506 shape_->getBoundaryPath(mask); |
527 } | 507 } |
528 | 508 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 create_params.window_type == AppWindow::WINDOW_TYPE_V1_PANEL) { | 643 create_params.window_type == AppWindow::WINDOW_TYPE_V1_PANEL) { |
664 InitializePanelWindow(create_params); | 644 InitializePanelWindow(create_params); |
665 } else { | 645 } else { |
666 InitializeDefaultWindow(create_params); | 646 InitializeDefaultWindow(create_params); |
667 } | 647 } |
668 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews( | 648 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews( |
669 Profile::FromBrowserContext(app_window->browser_context()), | 649 Profile::FromBrowserContext(app_window->browser_context()), |
670 widget()->GetFocusManager(), | 650 widget()->GetFocusManager(), |
671 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, | 651 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, |
672 NULL)); | 652 NULL)); |
673 | |
674 #if defined(OS_WIN) | |
675 if ((IsFrameless() || has_frame_color_) && | |
676 chrome::GetHostDesktopTypeForNativeWindow(widget()->GetNativeWindow()) != | |
677 chrome::HOST_DESKTOP_TYPE_ASH) { | |
678 InstallEasyResizeTargeterOnContainer(); | |
679 } | |
680 #endif | |
681 } | 653 } |
OLD | NEW |