OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/frame/browser_desktop_window_tree_host_win.h" | 5 #include "chrome/browser/ui/views/frame/browser_desktop_window_tree_host_win.h" |
6 | 6 |
7 #include <dwmapi.h> | 7 #include <dwmapi.h> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/process/process_handle.h" | 10 #include "base/process/process_handle.h" |
11 #include "base/win/windows_version.h" | 11 #include "base/win/windows_version.h" |
12 #include "chrome/browser/lifetime/application_lifetime.h" | 12 #include "chrome/browser/lifetime/application_lifetime.h" |
13 #include "chrome/browser/themes/theme_service.h" | 13 #include "chrome/browser/themes/theme_service.h" |
14 #include "chrome/browser/themes/theme_service_factory.h" | 14 #include "chrome/browser/themes/theme_service_factory.h" |
15 #include "chrome/browser/ui/views/frame/browser_frame.h" | 15 #include "chrome/browser/ui/views/frame/browser_frame.h" |
16 #include "chrome/browser/ui/views/frame/browser_frame_common_win.h" | |
17 #include "chrome/browser/ui/views/frame/browser_view.h" | 16 #include "chrome/browser/ui/views/frame/browser_view.h" |
18 #include "chrome/browser/ui/views/frame/browser_window_property_manager_win.h" | 17 #include "chrome/browser/ui/views/frame/browser_window_property_manager_win.h" |
19 #include "chrome/browser/ui/views/frame/system_menu_insertion_delegate_win.h" | 18 #include "chrome/browser/ui/views/frame/system_menu_insertion_delegate_win.h" |
20 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 19 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
21 #include "chrome/common/chrome_constants.h" | 20 #include "chrome/common/chrome_constants.h" |
21 #include "ui/base/material_design/material_design_controller.h" | |
22 #include "ui/base/theme_provider.h" | 22 #include "ui/base/theme_provider.h" |
23 #include "ui/gfx/geometry/point.h" | |
23 #include "ui/gfx/win/dpi.h" | 24 #include "ui/gfx/win/dpi.h" |
24 #include "ui/views/controls/menu/native_menu_win.h" | 25 #include "ui/views/controls/menu/native_menu_win.h" |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
28 const int kClientEdgeThickness = 3; | 29 // The amount of additional non-client area to draw beyond what we have Windows |
30 // draw, in DIPs. Only used pre-Win 10. | |
31 const int kDWMFrameBorderExtensionDips = 3; | |
29 | 32 |
30 } // namespace | 33 } // namespace |
31 | 34 |
32 //////////////////////////////////////////////////////////////////////////////// | 35 //////////////////////////////////////////////////////////////////////////////// |
33 // BrowserDesktopWindowTreeHostWin, public: | 36 // BrowserDesktopWindowTreeHostWin, public: |
34 | 37 |
35 BrowserDesktopWindowTreeHostWin::BrowserDesktopWindowTreeHostWin( | 38 BrowserDesktopWindowTreeHostWin::BrowserDesktopWindowTreeHostWin( |
36 views::internal::NativeWidgetDelegate* native_widget_delegate, | 39 views::internal::NativeWidgetDelegate* native_widget_delegate, |
37 views::DesktopNativeWidgetAura* desktop_native_widget_aura, | 40 views::DesktopNativeWidgetAura* desktop_native_widget_aura, |
38 BrowserView* browser_view, | 41 BrowserView* browser_view, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 bool BrowserDesktopWindowTreeHostWin::GetClientAreaInsets( | 91 bool BrowserDesktopWindowTreeHostWin::GetClientAreaInsets( |
89 gfx::Insets* insets) const { | 92 gfx::Insets* insets) const { |
90 // Use the default client insets for an opaque frame or a glass popup/app | 93 // Use the default client insets for an opaque frame or a glass popup/app |
91 // frame. | 94 // frame. |
92 if (!GetWidget()->ShouldUseNativeFrame() || | 95 if (!GetWidget()->ShouldUseNativeFrame() || |
93 !browser_view_->IsBrowserTypeNormal()) { | 96 !browser_view_->IsBrowserTypeNormal()) { |
94 return false; | 97 return false; |
95 } | 98 } |
96 | 99 |
97 int border_thickness = GetSystemMetrics(SM_CXSIZEFRAME); | 100 int border_thickness = GetSystemMetrics(SM_CXSIZEFRAME); |
98 // In fullscreen mode, we have no frame. In restored mode, we draw our own | 101 if (GetWidget()->IsFullscreen()) { |
99 // client edge over part of the default frame. | 102 // In fullscreen mode there is no frame. |
100 if (GetWidget()->IsFullscreen()) | |
101 border_thickness = 0; | 103 border_thickness = 0; |
102 else if (!IsMaximized() && base::win::GetVersion() < base::win::VERSION_WIN10) | 104 } else if (!IsMaximized() && |
103 border_thickness -= kClientEdgeThickness; | 105 base::win::GetVersion() < base::win::VERSION_WIN10) { |
106 // Reduce the Windows non-client border size because we extended the border | |
107 // into our client area in UpdateDWMFrame(). | |
108 border_thickness -= kDWMFrameBorderExtensionDips; | |
109 } | |
104 insets->Set(0, border_thickness, border_thickness, border_thickness); | 110 insets->Set(0, border_thickness, border_thickness, border_thickness); |
105 return true; | 111 return true; |
106 } | 112 } |
107 | 113 |
108 void BrowserDesktopWindowTreeHostWin::HandleCreate() { | 114 void BrowserDesktopWindowTreeHostWin::HandleCreate() { |
109 DesktopWindowTreeHostWin::HandleCreate(); | 115 DesktopWindowTreeHostWin::HandleCreate(); |
110 browser_window_property_manager_ = | 116 browser_window_property_manager_ = |
111 BrowserWindowPropertyManager::CreateBrowserWindowPropertyManager( | 117 BrowserWindowPropertyManager::CreateBrowserWindowPropertyManager( |
112 browser_view_, GetHWND()); | 118 browser_view_, GetHWND()); |
113 } | 119 } |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 : views::FrameMode::CUSTOM_DRAWN; | 225 : views::FrameMode::CUSTOM_DRAWN; |
220 } | 226 } |
221 | 227 |
222 bool BrowserDesktopWindowTreeHostWin::ShouldUseNativeFrame() const { | 228 bool BrowserDesktopWindowTreeHostWin::ShouldUseNativeFrame() const { |
223 if (!views::DesktopWindowTreeHostWin::ShouldUseNativeFrame()) | 229 if (!views::DesktopWindowTreeHostWin::ShouldUseNativeFrame()) |
224 return false; | 230 return false; |
225 // This function can get called when the Browser window is closed i.e. in the | 231 // This function can get called when the Browser window is closed i.e. in the |
226 // context of the BrowserView destructor. | 232 // context of the BrowserView destructor. |
227 if (!browser_view_->browser()) | 233 if (!browser_view_->browser()) |
228 return false; | 234 return false; |
229 return chrome::ShouldUseNativeFrame(browser_view_, | 235 // We don't theme popup or app windows, so regardless of whether or not a |
230 GetWidget()->GetThemeProvider()); | 236 // theme is active for normal browser windows, we don't want to use the custom |
237 // frame for popups/apps. | |
238 if (!browser_view_->IsBrowserTypeNormal()) | |
239 return true; | |
240 // Otherwise, we use the native frame when we're told we should by the theme | |
241 // provider (e.g. no custom theme is active). | |
242 return GetWidget()->GetThemeProvider()->ShouldUseNativeFrame(); | |
231 } | 243 } |
232 | 244 |
233 void BrowserDesktopWindowTreeHostWin::FrameTypeChanged() { | 245 void BrowserDesktopWindowTreeHostWin::FrameTypeChanged() { |
234 views::DesktopWindowTreeHostWin::FrameTypeChanged(); | 246 views::DesktopWindowTreeHostWin::FrameTypeChanged(); |
235 did_gdi_clear_ = false; | 247 did_gdi_clear_ = false; |
236 } | 248 } |
237 | 249 |
238 //////////////////////////////////////////////////////////////////////////////// | 250 //////////////////////////////////////////////////////////////////////////////// |
239 // BrowserDesktopWindowTreeHostWin, private: | 251 // BrowserDesktopWindowTreeHostWin, private: |
240 | 252 |
(...skipping 11 matching lines...) Expand all Loading... | |
252 return; | 264 return; |
253 | 265 |
254 MARGINS margins = GetDWMFrameMargins(); | 266 MARGINS margins = GetDWMFrameMargins(); |
255 | 267 |
256 DwmExtendFrameIntoClientArea(GetHWND(), &margins); | 268 DwmExtendFrameIntoClientArea(GetHWND(), &margins); |
257 } | 269 } |
258 | 270 |
259 MARGINS BrowserDesktopWindowTreeHostWin::GetDWMFrameMargins() const { | 271 MARGINS BrowserDesktopWindowTreeHostWin::GetDWMFrameMargins() const { |
260 MARGINS margins = { 0 }; | 272 MARGINS margins = { 0 }; |
261 | 273 |
262 // If the opaque frame is visible, we use the default (zero) margins. | 274 // If the opaque frame is visible or we're fullscreen, we don't extend the |
Peter Kasting
2016/04/15 00:20:51
Nit: the opaque frame is visible -> we're using th
Bret
2016/04/15 23:07:08
Done.
| |
263 // Otherwise, we need to figure out how to extend the glass in. | 275 // glass in at all because it won't be visible. |
264 if (GetWidget()->ShouldUseNativeFrame()) { | 276 if (!GetWidget()->ShouldUseNativeFrame() || GetWidget()->IsFullscreen()) |
265 // In fullscreen mode, we don't extend glass into the client area at all, | 277 return margins; |
266 // because the GDI-drawn text in the web content composited over it will | 278 |
267 // become semi-transparent over any glass area. | 279 if (!IsMaximized()) { |
268 if (!IsMaximized() && !GetWidget()->IsFullscreen()) { | 280 if (base::win::GetVersion() < base::win::VERSION_WIN10) { |
269 margins.cyTopHeight = kClientEdgeThickness + 1; | 281 gfx::Point dip_margin(kDWMFrameBorderExtensionDips, |
270 // On Windows 10, we don't draw our own window border, so don't extend the | 282 kDWMFrameBorderExtensionDips); |
271 // nonclient area in for it. The top is extended so that the MARGINS isn't | 283 gfx::Point pixel_margin = gfx::win::DIPToScreenPoint(dip_margin); |
272 // treated as an empty (ignored) extension. | 284 margins.cxLeftWidth = pixel_margin.x(); |
273 if (base::win::GetVersion() >= base::win::VERSION_WIN10) { | 285 margins.cxRightWidth = pixel_margin.x(); |
274 margins.cxLeftWidth = 0; | 286 margins.cyBottomHeight = pixel_margin.y(); |
275 margins.cxRightWidth = 0; | 287 |
276 margins.cyBottomHeight = 0; | 288 const bool md = ui::MaterialDesignController::IsModeMaterial(); |
277 } else { | 289 if (!md) { |
278 margins.cxLeftWidth = kClientEdgeThickness + 1; | 290 // Since the toolbar in non-md has rounded corners that show the glass |
279 margins.cxRightWidth = kClientEdgeThickness + 1; | 291 // frame behind, the extension of the glass area to the bottom of the |
280 margins.cyBottomHeight = kClientEdgeThickness + 1; | 292 // tabstrip below isn't sufficient. We need to go down further to the |
293 // bottom of the rounded corner region. | |
294 margins.cyTopHeight = pixel_margin.y(); | |
281 } | 295 } |
282 } | 296 } |
283 // In maximized mode, we only have a titlebar strip of glass, no side/bottom | 297 // Else, on Windows 10, we don't need extra border thickness because we draw |
284 // borders. | 298 // right up to the edge of the client area and there are no rounded corners |
285 if (!browser_view_->IsFullscreen()) { | 299 // anywhere that we need to make sure are covered. |
286 gfx::Rect tabstrip_bounds( | 300 } |
287 browser_frame_->GetBoundsForTabStrip(browser_view_->tabstrip())); | |
288 tabstrip_bounds = gfx::win::DIPToScreenRect(tabstrip_bounds); | |
289 margins.cyTopHeight = tabstrip_bounds.bottom(); | |
290 | 301 |
291 // On pre-Win 10, we need to offset the DWM frame into the toolbar so that | 302 // Extend top for the tabstrip background. |
292 // the blackness doesn't show up on our rounded toolbar corners. In Win | 303 gfx::Rect tabstrip_bounds( |
293 // 10 and above there are no rounded corners, so this is unnecessary. | 304 browser_frame_->GetBoundsForTabStrip(browser_view_->tabstrip())); |
294 const int kDWMFrameTopOffset = 3; | 305 tabstrip_bounds = gfx::win::DIPToScreenRect(tabstrip_bounds); |
295 if (base::win::GetVersion() < base::win::VERSION_WIN10) | 306 margins.cyTopHeight += tabstrip_bounds.bottom(); |
296 margins.cyTopHeight += kDWMFrameTopOffset; | 307 |
297 } | |
298 } | |
299 return margins; | 308 return margins; |
300 } | 309 } |
301 | 310 |
302 //////////////////////////////////////////////////////////////////////////////// | 311 //////////////////////////////////////////////////////////////////////////////// |
303 // BrowserDesktopWindowTreeHost, public: | 312 // BrowserDesktopWindowTreeHost, public: |
304 | 313 |
305 // static | 314 // static |
306 BrowserDesktopWindowTreeHost* | 315 BrowserDesktopWindowTreeHost* |
307 BrowserDesktopWindowTreeHost::CreateBrowserDesktopWindowTreeHost( | 316 BrowserDesktopWindowTreeHost::CreateBrowserDesktopWindowTreeHost( |
308 views::internal::NativeWidgetDelegate* native_widget_delegate, | 317 views::internal::NativeWidgetDelegate* native_widget_delegate, |
309 views::DesktopNativeWidgetAura* desktop_native_widget_aura, | 318 views::DesktopNativeWidgetAura* desktop_native_widget_aura, |
310 BrowserView* browser_view, | 319 BrowserView* browser_view, |
311 BrowserFrame* browser_frame) { | 320 BrowserFrame* browser_frame) { |
312 return new BrowserDesktopWindowTreeHostWin(native_widget_delegate, | 321 return new BrowserDesktopWindowTreeHostWin(native_widget_delegate, |
313 desktop_native_widget_aura, | 322 desktop_native_widget_aura, |
314 browser_view, | 323 browser_view, |
315 browser_frame); | 324 browser_frame); |
316 } | 325 } |
OLD | NEW |