| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/win/windows_version.h" | 10 #include "base/win/windows_version.h" |
| 11 #include "chrome/app/chrome_command_ids.h" | 11 #include "chrome/app/chrome_command_ids.h" |
| 12 #include "chrome/app/chrome_dll_resource.h" | 12 #include "chrome/app/chrome_dll_resource.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/themes/theme_properties.h" | 14 #include "chrome/browser/themes/theme_properties.h" |
| 15 #include "chrome/browser/ui/layout_constants.h" | 15 #include "chrome/browser/ui/layout_constants.h" |
| 16 #include "chrome/browser/ui/views/frame/browser_view.h" | 16 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 17 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" | 17 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" |
| 18 #include "chrome/browser/ui/views/tabs/tab.h" | 18 #include "chrome/browser/ui/views/tabs/tab.h" |
| 19 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 19 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
| 20 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 20 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| 21 #include "components/prefs/pref_service.h" | 21 #include "components/prefs/pref_service.h" |
| 22 #include "components/signin/core/browser/signin_header_helper.h" | 22 #include "components/signin/core/browser/signin_header_helper.h" |
| 23 #include "components/signin/core/common/profile_management_switches.h" | 23 #include "components/signin/core/common/profile_management_switches.h" |
| 24 #include "grit/theme_resources.h" | 24 #include "grit/theme_resources.h" |
| 25 #include "skia/ext/image_operations.h" | 25 #include "skia/ext/image_operations.h" |
| 26 #include "ui/base/material_design/material_design_controller.h" | 26 #include "ui/base/material_design/material_design_controller.h" |
| 27 #include "ui/base/resource/resource_bundle_win.h" | 27 #include "ui/base/resource/resource_bundle_win.h" |
| 28 #include "ui/base/theme_provider.h" | 28 #include "ui/base/theme_provider.h" |
| 29 #include "ui/display/win/dpi.h" |
| 29 #include "ui/gfx/canvas.h" | 30 #include "ui/gfx/canvas.h" |
| 30 #include "ui/gfx/icon_util.h" | 31 #include "ui/gfx/icon_util.h" |
| 31 #include "ui/gfx/image/image.h" | 32 #include "ui/gfx/image/image.h" |
| 32 #include "ui/gfx/scoped_canvas.h" | 33 #include "ui/gfx/scoped_canvas.h" |
| 33 #include "ui/gfx/win/dpi.h" | |
| 34 #include "ui/resources/grit/ui_resources.h" | 34 #include "ui/resources/grit/ui_resources.h" |
| 35 #include "ui/views/controls/label.h" | 35 #include "ui/views/controls/label.h" |
| 36 #include "ui/views/layout/layout_constants.h" | 36 #include "ui/views/layout/layout_constants.h" |
| 37 #include "ui/views/resources/grit/views_resources.h" | 37 #include "ui/views/resources/grit/views_resources.h" |
| 38 #include "ui/views/win/hwnd_util.h" | 38 #include "ui/views/win/hwnd_util.h" |
| 39 #include "ui/views/window/client_view.h" | 39 #include "ui/views/window/client_view.h" |
| 40 | 40 |
| 41 HICON GlassBrowserFrameView::throbber_icons_[ | 41 HICON GlassBrowserFrameView::throbber_icons_[ |
| 42 GlassBrowserFrameView::kThrobberIconCount]; | 42 GlassBrowserFrameView::kThrobberIconCount]; |
| 43 | 43 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 avatar_button()->GetMirroredBounds().Contains(point)) || | 221 avatar_button()->GetMirroredBounds().Contains(point)) || |
| 222 (profile_switcher_.view() && | 222 (profile_switcher_.view() && |
| 223 profile_switcher_.view()->GetMirroredBounds().Contains(point))) | 223 profile_switcher_.view()->GetMirroredBounds().Contains(point))) |
| 224 return HTCLIENT; | 224 return HTCLIENT; |
| 225 | 225 |
| 226 int frame_component = frame()->client_view()->NonClientHitTest(point); | 226 int frame_component = frame()->client_view()->NonClientHitTest(point); |
| 227 | 227 |
| 228 // See if we're in the sysmenu region. We still have to check the tabstrip | 228 // See if we're in the sysmenu region. We still have to check the tabstrip |
| 229 // first so that clicks in a tab don't get treated as sysmenu clicks. | 229 // first so that clicks in a tab don't get treated as sysmenu clicks. |
| 230 int nonclient_border_thickness = NonClientBorderThickness(false); | 230 int nonclient_border_thickness = NonClientBorderThickness(false); |
| 231 if (gfx::Rect(nonclient_border_thickness, | 231 gfx::Rect sys_menu_region(nonclient_border_thickness, |
| 232 gfx::win::GetSystemMetricsInDIP(SM_CYSIZEFRAME), | 232 display::win::GetSystemMetricsInDIP(SM_CYSIZEFRAME), |
| 233 gfx::win::GetSystemMetricsInDIP(SM_CXSMICON), | 233 display::win::GetSystemMetricsInDIP(SM_CXSMICON), |
| 234 gfx::win::GetSystemMetricsInDIP(SM_CYSMICON)).Contains(point)) | 234 display::win::GetSystemMetricsInDIP(SM_CYSMICON)); |
| 235 if (sys_menu_region.Contains(point)) |
| 235 return (frame_component == HTCLIENT) ? HTCLIENT : HTSYSMENU; | 236 return (frame_component == HTCLIENT) ? HTCLIENT : HTSYSMENU; |
| 236 | 237 |
| 237 if (frame_component != HTNOWHERE) | 238 if (frame_component != HTNOWHERE) |
| 238 return frame_component; | 239 return frame_component; |
| 239 | 240 |
| 240 int frame_top_border_height = FrameTopBorderHeight(false); | 241 int frame_top_border_height = FrameTopBorderHeight(false); |
| 241 // We want the resize corner behavior to apply to the kResizeCornerWidth | 242 // We want the resize corner behavior to apply to the kResizeCornerWidth |
| 242 // pixels at each end of the top and bottom edges. Because |point|'s x | 243 // pixels at each end of the top and bottom edges. Because |point|'s x |
| 243 // coordinate is based on the DWM-inset portion of the window (so, it's 0 at | 244 // coordinate is based on the DWM-inset portion of the window (so, it's 0 at |
| 244 // the first pixel inside the left DWM margin), we need to subtract the DWM | 245 // the first pixel inside the left DWM margin), we need to subtract the DWM |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 avatar_button()->GetMirroredBounds().Intersects(rect); | 294 avatar_button()->GetMirroredBounds().Intersects(rect); |
| 294 bool hit_new_avatar_button = | 295 bool hit_new_avatar_button = |
| 295 profile_switcher_.view() && | 296 profile_switcher_.view() && |
| 296 profile_switcher_.view()->GetMirroredBounds().Intersects(rect); | 297 profile_switcher_.view()->GetMirroredBounds().Intersects(rect); |
| 297 return hit_incognito_icon || hit_new_avatar_button || | 298 return hit_incognito_icon || hit_new_avatar_button || |
| 298 !frame()->client_view()->bounds().Intersects(rect); | 299 !frame()->client_view()->bounds().Intersects(rect); |
| 299 } | 300 } |
| 300 | 301 |
| 301 int GlassBrowserFrameView::FrameBorderThickness() const { | 302 int GlassBrowserFrameView::FrameBorderThickness() const { |
| 302 return (frame()->IsMaximized() || frame()->IsFullscreen()) ? | 303 return (frame()->IsMaximized() || frame()->IsFullscreen()) ? |
| 303 0 : gfx::win::GetSystemMetricsInDIP(SM_CXSIZEFRAME); | 304 0 : display::win::GetSystemMetricsInDIP(SM_CXSIZEFRAME); |
| 304 } | 305 } |
| 305 | 306 |
| 306 int GlassBrowserFrameView::FrameTopBorderHeight(bool restored) const { | 307 int GlassBrowserFrameView::FrameTopBorderHeight(bool restored) const { |
| 307 // We'd like to use FrameBorderThickness() here, but the maximized Aero glass | 308 // We'd like to use FrameBorderThickness() here, but the maximized Aero glass |
| 308 // frame has a 0 frame border around most edges and a CYSIZEFRAME-thick border | 309 // frame has a 0 frame border around most edges and a CYSIZEFRAME-thick border |
| 309 // at the top (see AeroGlassFrame::OnGetMinMaxInfo()). | 310 // at the top (see AeroGlassFrame::OnGetMinMaxInfo()). |
| 310 return (frame()->IsFullscreen() && !restored) ? | 311 return (frame()->IsFullscreen() && !restored) ? |
| 311 0 : gfx::win::GetSystemMetricsInDIP(SM_CYSIZEFRAME); | 312 0 : display::win::GetSystemMetricsInDIP(SM_CYSIZEFRAME); |
| 312 } | 313 } |
| 313 | 314 |
| 314 int GlassBrowserFrameView::NonClientBorderThickness(bool restored) const { | 315 int GlassBrowserFrameView::NonClientBorderThickness(bool restored) const { |
| 315 if ((frame()->IsMaximized() || frame()->IsFullscreen()) && !restored) | 316 if ((frame()->IsMaximized() || frame()->IsFullscreen()) && !restored) |
| 316 return 0; | 317 return 0; |
| 317 | 318 |
| 318 return (base::win::GetVersion() < base::win::VERSION_WIN10) | 319 return (base::win::GetVersion() < base::win::VERSION_WIN10) |
| 319 ? kNonClientBorderThicknessPreWin10 | 320 ? kNonClientBorderThicknessPreWin10 |
| 320 : kNonClientBorderThicknessWin10; | 321 : kNonClientBorderThicknessWin10; |
| 321 } | 322 } |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 // placed just below a 2 px border at the top of the window (which is the | 514 // placed just below a 2 px border at the top of the window (which is the |
| 514 // first two pixels' worth of FrameTopBorderHeight()), then extended upwards | 515 // first two pixels' worth of FrameTopBorderHeight()), then extended upwards |
| 515 // one extra pixel to overlap part of this border. | 516 // one extra pixel to overlap part of this border. |
| 516 // | 517 // |
| 517 // To match both of these, we size the button as if it's always the extra one | 518 // To match both of these, we size the button as if it's always the extra one |
| 518 // pixel in height, then we place it at the correct position in restored mode, | 519 // pixel in height, then we place it at the correct position in restored mode, |
| 519 // or one pixel above the top of the screen in maximized mode. | 520 // or one pixel above the top of the screen in maximized mode. |
| 520 int button_y = frame()->IsMaximized() ? (FrameTopBorderHeight(false) - 1) : 1; | 521 int button_y = frame()->IsMaximized() ? (FrameTopBorderHeight(false) - 1) : 1; |
| 521 profile_switcher_.view()->SetBounds( | 522 profile_switcher_.view()->SetBounds( |
| 522 button_x, button_y, label_size.width(), | 523 button_x, button_y, label_size.width(), |
| 523 gfx::win::GetSystemMetricsInDIP(SM_CYMENUSIZE) + 1); | 524 display::win::GetSystemMetricsInDIP(SM_CYMENUSIZE) + 1); |
| 524 } | 525 } |
| 525 | 526 |
| 526 void GlassBrowserFrameView::LayoutIncognitoIcon() { | 527 void GlassBrowserFrameView::LayoutIncognitoIcon() { |
| 527 const bool md = ui::MaterialDesignController::IsModeMaterial(); | 528 const bool md = ui::MaterialDesignController::IsModeMaterial(); |
| 528 const gfx::Insets insets(GetLayoutInsets(AVATAR_ICON)); | 529 const gfx::Insets insets(GetLayoutInsets(AVATAR_ICON)); |
| 529 const gfx::Size size(GetOTRAvatarIcon().size()); | 530 const gfx::Size size(GetOTRAvatarIcon().size()); |
| 530 int x = NonClientBorderThickness(false); | 531 int x = NonClientBorderThickness(false); |
| 531 // In RTL, the icon needs to start after the caption buttons. | 532 // In RTL, the icon needs to start after the caption buttons. |
| 532 if (base::i18n::IsRTL()) { | 533 if (base::i18n::IsRTL()) { |
| 533 x = width() - frame()->GetMinimizeButtonOffset() + | 534 x = width() - frame()->GetMinimizeButtonOffset() + |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 static bool initialized = false; | 649 static bool initialized = false; |
| 649 if (!initialized) { | 650 if (!initialized) { |
| 650 for (int i = 0; i < kThrobberIconCount; ++i) { | 651 for (int i = 0; i < kThrobberIconCount; ++i) { |
| 651 throbber_icons_[i] = | 652 throbber_icons_[i] = |
| 652 ui::LoadThemeIconFromResourcesDataDLL(IDI_THROBBER_01 + i); | 653 ui::LoadThemeIconFromResourcesDataDLL(IDI_THROBBER_01 + i); |
| 653 DCHECK(throbber_icons_[i]); | 654 DCHECK(throbber_icons_[i]); |
| 654 } | 655 } |
| 655 initialized = true; | 656 initialized = true; |
| 656 } | 657 } |
| 657 } | 658 } |
| OLD | NEW |