Chromium Code Reviews| 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 // Even though the tiny area above the caption buttons is very difficult | |
| 266 // to hit, this ensures behavioral consistency with other top-level | |
| 267 // windows. It is worth noting that this area is the same size (1px) | |
| 268 // regardless of the current scale factor. For that reason the rect is | |
| 269 // inset after it is adjusted for the device scale. Even so, this is less | |
| 270 // than ideal since conversion to DIPs may lose some precision. Given | |
| 271 // that the API doesn't take that into account, at this point this is the | |
| 272 // best we can do. | |
|
Peter Kasting
2016/07/20 18:47:44
Nit: This still reads pretty confusingly to me. W
| |
| 273 buttons.Inset(0, kCaptionButtonTopInset, 0, 0); | |
| 274 if (buttons.Contains(point)) | |
| 275 return HTNOWHERE; | |
| 276 } | |
| 277 } | |
| 278 | |
| 248 int top_border_thickness = FrameTopBorderThickness(false); | 279 int top_border_thickness = FrameTopBorderThickness(false); |
| 249 // We want the resize corner behavior to apply to the kResizeCornerWidth | 280 // 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 | 281 // 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 | 282 // 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 | 283 // 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 | 284 // margin thickness, which we calculate as the total frame border thickness |
| 254 // minus the nonclient border thickness. | 285 // minus the nonclient border thickness. |
| 255 const int dwm_margin = FrameBorderThickness() - client_border_thickness; | 286 const int dwm_margin = FrameBorderThickness() - client_border_thickness; |
| 256 int window_component = GetHTComponentForFrame( | 287 int window_component = GetHTComponentForFrame( |
| 257 point, top_border_thickness, client_border_thickness, | 288 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; | 708 static bool initialized = false; |
| 678 if (!initialized) { | 709 if (!initialized) { |
| 679 for (int i = 0; i < kThrobberIconCount; ++i) { | 710 for (int i = 0; i < kThrobberIconCount; ++i) { |
| 680 throbber_icons_[i] = | 711 throbber_icons_[i] = |
| 681 ui::LoadThemeIconFromResourcesDataDLL(IDI_THROBBER_01 + i); | 712 ui::LoadThemeIconFromResourcesDataDLL(IDI_THROBBER_01 + i); |
| 682 DCHECK(throbber_icons_[i]); | 713 DCHECK(throbber_icons_[i]); |
| 683 } | 714 } |
| 684 initialized = true; | 715 initialized = true; |
| 685 } | 716 } |
| 686 } | 717 } |
| OLD | NEW |