| 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_win.h" | 5 #include "chrome/browser/ui/views/apps/chrome_native_app_window_views_win.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 "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 } | 37 } |
| 38 | 38 |
| 39 ChromeNativeAppWindowViewsWin::~ChromeNativeAppWindowViewsWin() { | 39 ChromeNativeAppWindowViewsWin::~ChromeNativeAppWindowViewsWin() { |
| 40 } | 40 } |
| 41 | 41 |
| 42 void ChromeNativeAppWindowViewsWin::ActivateParentDesktopIfNecessary() { | 42 void ChromeNativeAppWindowViewsWin::ActivateParentDesktopIfNecessary() { |
| 43 // Only switching into Ash from Native is supported. Tearing the user out of | 43 // Only switching into Ash from Native is supported. Tearing the user out of |
| 44 // Metro mode can only be done by launching a process from Metro mode itself. | 44 // Metro mode can only be done by launching a process from Metro mode itself. |
| 45 // This is done for launching apps, but not regular activations. | 45 // This is done for launching apps, but not regular activations. |
| 46 if (IsRunningInAsh() && | 46 if (IsRunningInAsh() && |
| 47 chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_NATIVE) { | 47 chrome::GetActiveDesktop() == ui::HOST_DESKTOP_TYPE_NATIVE) { |
| 48 chrome::ActivateMetroChrome(); | 48 chrome::ActivateMetroChrome(); |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 | 51 |
| 52 HWND ChromeNativeAppWindowViewsWin::GetNativeAppWindowHWND() const { | 52 HWND ChromeNativeAppWindowViewsWin::GetNativeAppWindowHWND() const { |
| 53 return views::HWNDForWidget(widget()->GetTopLevelWidget()); | 53 return views::HWNDForWidget(widget()->GetTopLevelWidget()); |
| 54 } | 54 } |
| 55 | 55 |
| 56 bool ChromeNativeAppWindowViewsWin::IsRunningInAsh() { | 56 bool ChromeNativeAppWindowViewsWin::IsRunningInAsh() { |
| 57 if (!ash::Shell::HasInstance()) | 57 if (!ash::Shell::HasInstance()) |
| 58 return false; | 58 return false; |
| 59 | 59 |
| 60 views::Widget* widget = | 60 views::Widget* widget = |
| 61 implicit_cast<views::WidgetDelegate*>(this)->GetWidget(); | 61 implicit_cast<views::WidgetDelegate*>(this)->GetWidget(); |
| 62 chrome::HostDesktopType host_desktop_type = | 62 ui::HostDesktopType host_desktop_type = |
| 63 chrome::GetHostDesktopTypeForNativeWindow(widget->GetNativeWindow()); | 63 chrome::GetHostDesktopTypeForNativeWindow(widget->GetNativeWindow()); |
| 64 return host_desktop_type == chrome::HOST_DESKTOP_TYPE_ASH; | 64 return host_desktop_type == ui::HOST_DESKTOP_TYPE_ASH; |
| 65 } | 65 } |
| 66 | 66 |
| 67 void ChromeNativeAppWindowViewsWin::EnsureCaptionStyleSet() { | 67 void ChromeNativeAppWindowViewsWin::EnsureCaptionStyleSet() { |
| 68 // Windows seems to have issues maximizing windows without WS_CAPTION. | 68 // Windows seems to have issues maximizing windows without WS_CAPTION. |
| 69 // The default views / Aura implementation will remove this if we are using | 69 // The default views / Aura implementation will remove this if we are using |
| 70 // frameless or colored windows, so we put it back here. | 70 // frameless or colored windows, so we put it back here. |
| 71 HWND hwnd = GetNativeAppWindowHWND(); | 71 HWND hwnd = GetNativeAppWindowHWND(); |
| 72 int current_style = ::GetWindowLong(hwnd, GWL_STYLE); | 72 int current_style = ::GetWindowLong(hwnd, GWL_STYLE); |
| 73 ::SetWindowLong(hwnd, GWL_STYLE, current_style | WS_CAPTION); | 73 ::SetWindowLong(hwnd, GWL_STYLE, current_style | WS_CAPTION); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void ChromeNativeAppWindowViewsWin::OnBeforeWidgetInit( | 76 void ChromeNativeAppWindowViewsWin::OnBeforeWidgetInit( |
| 77 const extensions::AppWindow::CreateParams& create_params, | 77 const extensions::AppWindow::CreateParams& create_params, |
| 78 views::Widget::InitParams* init_params, | 78 views::Widget::InitParams* init_params, |
| 79 views::Widget* widget) { | 79 views::Widget* widget) { |
| 80 ChromeNativeAppWindowViewsAura::OnBeforeWidgetInit(create_params, init_params, | 80 ChromeNativeAppWindowViewsAura::OnBeforeWidgetInit(create_params, init_params, |
| 81 widget); | 81 widget); |
| 82 | 82 |
| 83 content::BrowserContext* browser_context = app_window()->browser_context(); | 83 content::BrowserContext* browser_context = app_window()->browser_context(); |
| 84 std::string extension_id = app_window()->extension_id(); | 84 std::string extension_id = app_window()->extension_id(); |
| 85 // If an app has any existing windows, ensure new ones are created on the | 85 // If an app has any existing windows, ensure new ones are created on the |
| 86 // same desktop. | 86 // same desktop. |
| 87 extensions::AppWindow* any_existing_window = | 87 extensions::AppWindow* any_existing_window = |
| 88 extensions::AppWindowRegistry::Get(browser_context) | 88 extensions::AppWindowRegistry::Get(browser_context) |
| 89 ->GetCurrentAppWindowForApp(extension_id); | 89 ->GetCurrentAppWindowForApp(extension_id); |
| 90 chrome::HostDesktopType desktop_type; | 90 ui::HostDesktopType desktop_type; |
| 91 if (any_existing_window) { | 91 if (any_existing_window) { |
| 92 desktop_type = chrome::GetHostDesktopTypeForNativeWindow( | 92 desktop_type = chrome::GetHostDesktopTypeForNativeWindow( |
| 93 any_existing_window->GetNativeWindow()); | 93 any_existing_window->GetNativeWindow()); |
| 94 } else { | 94 } else { |
| 95 PerAppSettingsService* settings = | 95 PerAppSettingsService* settings = |
| 96 PerAppSettingsServiceFactory::GetForBrowserContext(browser_context); | 96 PerAppSettingsServiceFactory::GetForBrowserContext(browser_context); |
| 97 if (settings->HasDesktopLastLaunchedFrom(extension_id)) { | 97 if (settings->HasDesktopLastLaunchedFrom(extension_id)) { |
| 98 desktop_type = settings->GetDesktopLastLaunchedFrom(extension_id); | 98 desktop_type = settings->GetDesktopLastLaunchedFrom(extension_id); |
| 99 } else { | 99 } else { |
| 100 // We don't know what desktop this app was last launched from, so take our | 100 // We don't know what desktop this app was last launched from, so take our |
| 101 // best guess as to what desktop the user is on. | 101 // best guess as to what desktop the user is on. |
| 102 desktop_type = chrome::GetActiveDesktop(); | 102 desktop_type = chrome::GetActiveDesktop(); |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 if (desktop_type == chrome::HOST_DESKTOP_TYPE_ASH) | 105 if (desktop_type == ui::HOST_DESKTOP_TYPE_ASH) |
| 106 init_params->context = ash::Shell::GetPrimaryRootWindow(); | 106 init_params->context = ash::Shell::GetPrimaryRootWindow(); |
| 107 else | 107 else |
| 108 init_params->native_widget = new AppWindowDesktopNativeWidgetAuraWin(this); | 108 init_params->native_widget = new AppWindowDesktopNativeWidgetAuraWin(this); |
| 109 | 109 |
| 110 is_translucent_ = | 110 is_translucent_ = |
| 111 init_params->opacity == views::Widget::InitParams::TRANSLUCENT_WINDOW; | 111 init_params->opacity == views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 112 } | 112 } |
| 113 | 113 |
| 114 void ChromeNativeAppWindowViewsWin::InitializeDefaultWindow( | 114 void ChromeNativeAppWindowViewsWin::InitializeDefaultWindow( |
| 115 const extensions::AppWindow::CreateParams& create_params) { | 115 const extensions::AppWindow::CreateParams& create_params) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 ActivateParentDesktopIfNecessary(); | 159 ActivateParentDesktopIfNecessary(); |
| 160 ChromeNativeAppWindowViewsAura::Activate(); | 160 ChromeNativeAppWindowViewsAura::Activate(); |
| 161 } | 161 } |
| 162 | 162 |
| 163 bool ChromeNativeAppWindowViewsWin::CanMinimize() const { | 163 bool ChromeNativeAppWindowViewsWin::CanMinimize() const { |
| 164 // Resizing on Windows breaks translucency if the window also has shape. | 164 // Resizing on Windows breaks translucency if the window also has shape. |
| 165 // See http://crbug.com/417947. | 165 // See http://crbug.com/417947. |
| 166 return ChromeNativeAppWindowViewsAura::CanMinimize() && | 166 return ChromeNativeAppWindowViewsAura::CanMinimize() && |
| 167 !(WidgetHasHitTestMask() && is_translucent_); | 167 !(WidgetHasHitTestMask() && is_translucent_); |
| 168 } | 168 } |
| OLD | NEW |