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/glass_browser_frame_view.h" | 5 #include "chrome/browser/ui/views/frame/glass_browser_frame_view.h" |
6 | 6 |
| 7 #include <dwmapi.h> |
7 #include <utility> | 8 #include <utility> |
8 | 9 |
9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
10 #include "base/win/windows_version.h" | 11 #include "base/win/windows_version.h" |
11 #include "chrome/app/chrome_command_ids.h" | 12 #include "chrome/app/chrome_command_ids.h" |
12 #include "chrome/app/chrome_dll_resource.h" | 13 #include "chrome/app/chrome_dll_resource.h" |
13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/themes/theme_properties.h" | 15 #include "chrome/browser/themes/theme_properties.h" |
15 #include "chrome/browser/ui/layout_constants.h" | 16 #include "chrome/browser/ui/layout_constants.h" |
16 #include "chrome/browser/ui/views/frame/browser_view.h" | 17 #include "chrome/browser/ui/views/frame/browser_view.h" |
17 #include "chrome/browser/ui/views/profiles/profile_indicator_icon.h" | 18 #include "chrome/browser/ui/views/profiles/profile_indicator_icon.h" |
18 #include "chrome/browser/ui/views/tabs/tab.h" | 19 #include "chrome/browser/ui/views/tabs/tab.h" |
19 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 20 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
20 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 21 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
21 #include "components/prefs/pref_service.h" | 22 #include "components/prefs/pref_service.h" |
22 #include "components/signin/core/browser/signin_header_helper.h" | 23 #include "components/signin/core/browser/signin_header_helper.h" |
23 #include "components/signin/core/common/profile_management_switches.h" | 24 #include "components/signin/core/common/profile_management_switches.h" |
24 #include "grit/theme_resources.h" | 25 #include "grit/theme_resources.h" |
25 #include "skia/ext/image_operations.h" | 26 #include "skia/ext/image_operations.h" |
26 #include "ui/base/material_design/material_design_controller.h" | 27 #include "ui/base/material_design/material_design_controller.h" |
27 #include "ui/base/resource/resource_bundle_win.h" | 28 #include "ui/base/resource/resource_bundle_win.h" |
28 #include "ui/base/theme_provider.h" | 29 #include "ui/base/theme_provider.h" |
29 #include "ui/display/win/dpi.h" | 30 #include "ui/display/win/dpi.h" |
30 #include "ui/gfx/canvas.h" | 31 #include "ui/gfx/canvas.h" |
| 32 #include "ui/gfx/geometry/dip_util.h" |
31 #include "ui/gfx/icon_util.h" | 33 #include "ui/gfx/icon_util.h" |
32 #include "ui/gfx/image/image.h" | 34 #include "ui/gfx/image/image.h" |
33 #include "ui/gfx/scoped_canvas.h" | 35 #include "ui/gfx/scoped_canvas.h" |
34 #include "ui/resources/grit/ui_resources.h" | 36 #include "ui/resources/grit/ui_resources.h" |
35 #include "ui/views/controls/label.h" | 37 #include "ui/views/controls/label.h" |
36 #include "ui/views/layout/layout_constants.h" | 38 #include "ui/views/layout/layout_constants.h" |
37 #include "ui/views/resources/grit/views_resources.h" | 39 #include "ui/views/resources/grit/views_resources.h" |
38 #include "ui/views/win/hwnd_util.h" | 40 #include "ui/views/win/hwnd_util.h" |
39 #include "ui/views/window/client_view.h" | 41 #include "ui/views/window/client_view.h" |
40 | 42 |
(...skipping 22 matching lines...) Expand all Loading... |
63 const int kNewTabCaptionRestoredSpacing = 5; | 65 const int kNewTabCaptionRestoredSpacing = 5; |
64 // In maximized mode, where the New Tab button and the caption buttons are at | 66 // In maximized mode, where the New Tab button and the caption buttons are at |
65 // similar vertical coordinates, we need to reserve a larger, 16 px gap to avoid | 67 // similar vertical coordinates, we need to reserve a larger, 16 px gap to avoid |
66 // looking too cluttered. | 68 // looking too cluttered. |
67 const int kNewTabCaptionMaximizedSpacing = 16; | 69 const int kNewTabCaptionMaximizedSpacing = 16; |
68 // Height of the profile switcher button. Same as the height of the Windows 7/8 | 70 // Height of the profile switcher button. Same as the height of the Windows 7/8 |
69 // caption buttons. | 71 // caption buttons. |
70 // TODO(bsep): Windows 10 caption buttons look very different and we would like | 72 // TODO(bsep): Windows 10 caption buttons look very different and we would like |
71 // the profile switcher button to match on that platform. | 73 // the profile switcher button to match on that platform. |
72 const int kProfileSwitcherButtonHeight = 20; | 74 const int kProfileSwitcherButtonHeight = 20; |
| 75 // There is a small one-pixel strip right above the caption buttons in which the |
| 76 // resize border "peeks" through. |
| 77 const int kCaptionButtonTopInset = 1; |
73 | 78 |
74 // Converts the |image| to a Windows icon and returns the corresponding HICON | 79 // Converts the |image| to a Windows icon and returns the corresponding HICON |
75 // handle. |image| is resized to desired |width| and |height| if needed. | 80 // handle. |image| is resized to desired |width| and |height| if needed. |
76 base::win::ScopedHICON CreateHICONFromSkBitmapSizedTo( | 81 base::win::ScopedHICON CreateHICONFromSkBitmapSizedTo( |
77 const gfx::ImageSkia& image, | 82 const gfx::ImageSkia& image, |
78 int width, | 83 int width, |
79 int height) { | 84 int height) { |
80 return IconUtil::CreateHICONFromSkBitmap( | 85 return IconUtil::CreateHICONFromSkBitmap( |
81 width == image.width() && height == image.height() | 86 width == image.width() && height == image.height() |
82 ? *image.bitmap() | 87 ? *image.bitmap() |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 gfx::Rect sys_menu_region(client_border_thickness, | 243 gfx::Rect sys_menu_region(client_border_thickness, |
239 display::win::GetSystemMetricsInDIP(SM_CYSIZEFRAME), | 244 display::win::GetSystemMetricsInDIP(SM_CYSIZEFRAME), |
240 display::win::GetSystemMetricsInDIP(SM_CXSMICON), | 245 display::win::GetSystemMetricsInDIP(SM_CXSMICON), |
241 display::win::GetSystemMetricsInDIP(SM_CYSMICON)); | 246 display::win::GetSystemMetricsInDIP(SM_CYSMICON)); |
242 if (sys_menu_region.Contains(point)) | 247 if (sys_menu_region.Contains(point)) |
243 return (frame_component == HTCLIENT) ? HTCLIENT : HTSYSMENU; | 248 return (frame_component == HTCLIENT) ? HTCLIENT : HTSYSMENU; |
244 | 249 |
245 if (frame_component != HTNOWHERE) | 250 if (frame_component != HTNOWHERE) |
246 return frame_component; | 251 return frame_component; |
247 | 252 |
| 253 // On Windows 8+, the caption buttons are almost butted up to the top right |
| 254 // corner of the window. This code ensures the mouse isn't set to a size |
| 255 // cursor while hovering over the caption buttons, thus giving the incorrect |
| 256 // impression that the user can resize the window. |
| 257 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { |
| 258 RECT button_bounds = {0}; |
| 259 if (SUCCEEDED(DwmGetWindowAttribute(views::HWNDForWidget(frame()), |
| 260 DWMWA_CAPTION_BUTTON_BOUNDS, |
| 261 &button_bounds, |
| 262 sizeof(button_bounds)))) { |
| 263 gfx::Rect buttons = gfx::ConvertRectToDIP(display::win::GetDPIScale(), |
| 264 gfx::Rect(button_bounds)); |
| 265 // The sizing region at the window edge above the caption buttons is |
| 266 // 1 px regardless of scale factor. If we inset by 1 before converting |
| 267 // to DIPs, the precision loss might eliminate this region entirely. The |
| 268 // best we can do is to inset after conversion. This guarantees we'll |
| 269 // show the resize cursor when resizing is possible. The cost of which |
| 270 // is also maybe showing it over the portion of the DIP that isn't the |
| 271 // outermost pixel. |
| 272 buttons.Inset(0, kCaptionButtonTopInset, 0, 0); |
| 273 if (buttons.Contains(point)) |
| 274 return HTNOWHERE; |
| 275 } |
| 276 } |
| 277 |
248 int top_border_thickness = FrameTopBorderThickness(false); | 278 int top_border_thickness = FrameTopBorderThickness(false); |
249 // We want the resize corner behavior to apply to the kResizeCornerWidth | 279 // We want the resize corner behavior to apply to the kResizeCornerWidth |
250 // pixels at each end of the top and bottom edges. Because |point|'s x | 280 // pixels at each end of the top and bottom edges. Because |point|'s x |
251 // coordinate is based on the DWM-inset portion of the window (so, it's 0 at | 281 // coordinate is based on the DWM-inset portion of the window (so, it's 0 at |
252 // the first pixel inside the left DWM margin), we need to subtract the DWM | 282 // the first pixel inside the left DWM margin), we need to subtract the DWM |
253 // margin thickness, which we calculate as the total frame border thickness | 283 // margin thickness, which we calculate as the total frame border thickness |
254 // minus the nonclient border thickness. | 284 // minus the nonclient border thickness. |
255 const int dwm_margin = FrameBorderThickness() - client_border_thickness; | 285 const int dwm_margin = FrameBorderThickness() - client_border_thickness; |
256 int window_component = GetHTComponentForFrame( | 286 int window_component = GetHTComponentForFrame( |
257 point, top_border_thickness, client_border_thickness, | 287 point, top_border_thickness, client_border_thickness, |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 static bool initialized = false; | 707 static bool initialized = false; |
678 if (!initialized) { | 708 if (!initialized) { |
679 for (int i = 0; i < kThrobberIconCount; ++i) { | 709 for (int i = 0; i < kThrobberIconCount; ++i) { |
680 throbber_icons_[i] = | 710 throbber_icons_[i] = |
681 ui::LoadThemeIconFromResourcesDataDLL(IDI_THROBBER_01 + i); | 711 ui::LoadThemeIconFromResourcesDataDLL(IDI_THROBBER_01 + i); |
682 DCHECK(throbber_icons_[i]); | 712 DCHECK(throbber_icons_[i]); |
683 } | 713 } |
684 initialized = true; | 714 initialized = true; |
685 } | 715 } |
686 } | 716 } |
OLD | NEW |