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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/threading/sequenced_worker_pool.h" | 10 #include "base/threading/sequenced_worker_pool.h" |
| 11 #include "chrome/app/chrome_command_ids.h" | 11 #include "chrome/app/chrome_command_ids.h" |
| 12 #include "chrome/browser/extensions/extension_host.h" | 12 #include "chrome/browser/extensions/extension_host.h" |
| 13 #include "chrome/browser/favicon/favicon_tab_helper.h" | 13 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/host_desktop.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/ui/views/extensions/shell_window_frame_view.h" |
| 17 #include "chrome/browser/web_applications/web_app.h" | 18 #include "chrome/browser/web_applications/web_app.h" |
| 18 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
| 20 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/render_view_host.h" | 22 #include "content/public/browser/render_view_host.h" |
| 22 #include "content/public/browser/render_widget_host_view.h" | 23 #include "content/public/browser/render_widget_host_view.h" |
| 23 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 24 #include "content/public/browser/web_contents_view.h" | 25 #include "content/public/browser/web_contents_view.h" |
| 25 #include "extensions/common/draggable_region.h" | 26 #include "extensions/common/draggable_region.h" |
| 26 #include "ui/views/controls/webview/webview.h" | 27 #include "ui/views/controls/webview/webview.h" |
| 27 #include "ui/views/widget/widget.h" | 28 #include "ui/views/widget/widget.h" |
| 28 #include "ui/views/window/non_client_view.h" | 29 #include "ui/views/window/non_client_view.h" |
| 29 | 30 |
| 30 #if defined(OS_WIN) | 31 #if defined(OS_WIN) |
| 31 #include "base/strings/utf_string_conversions.h" | 32 #include "base/strings/utf_string_conversions.h" |
| 32 #include "chrome/browser/ui/web_applications/web_app_ui.h" | 33 #include "chrome/browser/ui/web_applications/web_app_ui.h" |
| 33 #include "chrome/browser/web_applications/web_app_win.h" | 34 #include "chrome/browser/web_applications/web_app_win.h" |
| 34 #include "ui/base/win/shell.h" | 35 #include "ui/base/win/shell.h" |
| 35 #include "ui/views/win/hwnd_util.h" | 36 #include "ui/views/win/hwnd_util.h" |
| 36 #endif | 37 #endif |
| 37 | 38 |
| 38 #if defined(OS_LINUX) | 39 #if defined(OS_LINUX) |
| 39 #include "chrome/browser/shell_integration_linux.h" | 40 #include "chrome/browser/shell_integration_linux.h" |
| 40 #endif | 41 #endif |
| 41 | 42 |
| 42 #if defined(USE_ASH) | 43 #if defined(USE_ASH) |
| 44 #include "ash/ash_switches.h" | |
| 43 #include "ash/screen_ash.h" | 45 #include "ash/screen_ash.h" |
| 44 #include "ash/shell.h" | 46 #include "ash/shell.h" |
| 45 #include "ash/wm/custom_frame_view_ash.h" | 47 #include "ash/wm/custom_frame_view_ash.h" |
| 46 #include "ash/wm/panels/panel_frame_view.h" | 48 #include "ash/wm/panels/panel_frame_view.h" |
| 47 #include "ash/wm/window_state.h" | 49 #include "ash/wm/window_state.h" |
| 48 #include "chrome/browser/ui/ash/ash_util.h" | 50 #include "chrome/browser/ui/ash/ash_util.h" |
| 51 #include "chrome/browser/ui/views/frame/app_non_client_frame_view_ash.h" | |
| 52 #include "chrome/browser/ui/views/frame/non_client_frame_view_switcher_ash.h" | |
| 49 #include "ui/aura/client/aura_constants.h" | 53 #include "ui/aura/client/aura_constants.h" |
| 50 #include "ui/aura/root_window.h" | 54 #include "ui/aura/root_window.h" |
| 51 #include "ui/aura/window.h" | 55 #include "ui/aura/window.h" |
| 56 #include "ui/views/widget/native_widget_aura.h" | |
| 52 #endif | 57 #endif |
| 53 | 58 |
| 54 using apps::ShellWindow; | 59 using apps::ShellWindow; |
| 55 | 60 |
| 56 namespace { | 61 namespace { |
| 57 | 62 |
| 58 const int kMinPanelWidth = 100; | 63 const int kMinPanelWidth = 100; |
| 59 const int kMinPanelHeight = 100; | 64 const int kMinPanelHeight = 100; |
| 60 const int kDefaultPanelWidth = 200; | 65 const int kDefaultPanelWidth = 200; |
| 61 const int kDefaultPanelHeight = 300; | 66 const int kDefaultPanelHeight = 300; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 if (position_specified && !window_bounds.IsEmpty()) | 180 if (position_specified && !window_bounds.IsEmpty()) |
| 176 init_params.bounds = window_bounds; | 181 init_params.bounds = window_bounds; |
| 177 | 182 |
| 178 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 183 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 179 // Set up a custom WM_CLASS for app windows. This allows task switchers in | 184 // Set up a custom WM_CLASS for app windows. This allows task switchers in |
| 180 // X11 environments to distinguish them from main browser windows. | 185 // X11 environments to distinguish them from main browser windows. |
| 181 init_params.wm_class_name = web_app::GetWMClassFromAppName(app_name); | 186 init_params.wm_class_name = web_app::GetWMClassFromAppName(app_name); |
| 182 init_params.wm_class_class = ShellIntegrationLinux::GetProgramClassName(); | 187 init_params.wm_class_class = ShellIntegrationLinux::GetProgramClassName(); |
| 183 #endif | 188 #endif |
| 184 | 189 |
| 190 #if defined(USE_ASH) | |
| 191 if (!frameless_ && | |
| 192 ash::switches::UseSameFrameForV1AndV2Apps() && | |
| 193 chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH) { | |
| 194 // Initialize |frame_switcher_| to switch the non client frame view when | |
| 195 // |window_| is maximized. |frame_switcher_| must be initialized before | |
| 196 // |window_| is inited because it must be notified of changes in | |
| 197 // ash::wm::WindowShowState before WorkspaceLayoutManager. This | |
| 198 // notification order avoids an extra layout whenever |window_| is | |
| 199 // maximized. | |
| 200 views::NativeWidgetAura* native_widget = | |
|
James Cook
2013/10/02 21:07:55
Why do you need to introduce a new native widget h
pkotwicz
2013/10/03 20:45:35
I have added a better comment.
The reason is that
| |
| 201 new views::NativeWidgetAura(window_); | |
| 202 frame_switcher_.reset(new NonClientFrameViewSwitcherAsh( | |
| 203 window_, native_widget->GetNativeView())); | |
| 204 | |
| 205 init_params.native_widget = native_widget; | |
| 206 init_params.context = ash::Shell::GetPrimaryRootWindow(); | |
| 207 } | |
| 208 #endif | |
| 209 | |
| 185 window_->Init(init_params); | 210 window_->Init(init_params); |
| 186 | 211 |
| 187 gfx::Rect adjusted_bounds = window_bounds; | 212 gfx::Rect adjusted_bounds = window_bounds; |
| 188 adjusted_bounds.Inset(-GetFrameInsets()); | 213 adjusted_bounds.Inset(-GetFrameInsets()); |
| 189 // Center window if no position was specified. | 214 // Center window if no position was specified. |
| 190 if (!position_specified) | 215 if (!position_specified) |
| 191 window_->CenterWindow(adjusted_bounds.size()); | 216 window_->CenterWindow(adjusted_bounds.size()); |
| 192 else if (!adjusted_bounds.IsEmpty() && adjusted_bounds != window_bounds) | 217 else if (!adjusted_bounds.IsEmpty() && adjusted_bounds != window_bounds) |
| 193 window_->SetBounds(adjusted_bounds); | 218 window_->SetBounds(adjusted_bounds); |
| 194 | 219 |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 599 views::NonClientFrameView* NativeAppWindowViews::CreateNonClientFrameView( | 624 views::NonClientFrameView* NativeAppWindowViews::CreateNonClientFrameView( |
| 600 views::Widget* widget) { | 625 views::Widget* widget) { |
| 601 #if defined(USE_ASH) | 626 #if defined(USE_ASH) |
| 602 if (chrome::IsNativeViewInAsh(widget->GetNativeView())) { | 627 if (chrome::IsNativeViewInAsh(widget->GetNativeView())) { |
| 603 if (shell_window_->window_type_is_panel()) { | 628 if (shell_window_->window_type_is_panel()) { |
| 604 ash::PanelFrameView::FrameType frame_type = frameless_ ? | 629 ash::PanelFrameView::FrameType frame_type = frameless_ ? |
| 605 ash::PanelFrameView::FRAME_NONE : ash::PanelFrameView::FRAME_ASH; | 630 ash::PanelFrameView::FRAME_NONE : ash::PanelFrameView::FRAME_ASH; |
| 606 return new ash::PanelFrameView(widget, frame_type); | 631 return new ash::PanelFrameView(widget, frame_type); |
| 607 } | 632 } |
| 608 if (!frameless_) { | 633 if (!frameless_) { |
| 609 ash::CustomFrameViewAsh* frame = new ash::CustomFrameViewAsh(); | 634 if (ash::switches::UseSameFrameForV1AndV2Apps() && |
| 610 frame->Init(widget); | 635 IsMaximized()) { |
| 611 return frame; | 636 return new AppNonClientFrameViewAsh(widget); |
| 637 } else { | |
| 638 ash::CustomFrameViewAsh* frame = new ash::CustomFrameViewAsh(); | |
| 639 frame->Init(widget); | |
| 640 return frame; | |
| 641 } | |
| 612 } | 642 } |
| 613 } | 643 } |
| 614 #endif | 644 #endif |
| 615 if (ShouldUseChromeStyleFrame()) { | 645 if (ShouldUseChromeStyleFrame()) { |
| 616 ShellWindowFrameView* frame_view = new ShellWindowFrameView(this); | 646 ShellWindowFrameView* frame_view = new ShellWindowFrameView(this); |
| 617 frame_view->Init(window_); | 647 frame_view->Init(window_); |
| 618 return frame_view; | 648 return frame_view; |
| 619 } | 649 } |
| 620 return views::WidgetDelegateView::CreateNonClientFrameView(widget); | 650 return views::WidgetDelegateView::CreateNonClientFrameView(widget); |
| 621 } | 651 } |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 782 | 812 |
| 783 void NativeAppWindowViews::HandleKeyboardEvent( | 813 void NativeAppWindowViews::HandleKeyboardEvent( |
| 784 const content::NativeWebKeyboardEvent& event) { | 814 const content::NativeWebKeyboardEvent& event) { |
| 785 unhandled_keyboard_event_handler_.HandleKeyboardEvent(event, | 815 unhandled_keyboard_event_handler_.HandleKeyboardEvent(event, |
| 786 GetFocusManager()); | 816 GetFocusManager()); |
| 787 } | 817 } |
| 788 | 818 |
| 789 void NativeAppWindowViews::RenderViewHostChanged() { | 819 void NativeAppWindowViews::RenderViewHostChanged() { |
| 790 OnViewWasResized(); | 820 OnViewWasResized(); |
| 791 } | 821 } |
| OLD | NEW |