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