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 "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "base/win/windows_version.h" | 9 #include "base/win/windows_version.h" |
10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 namespace { | 42 namespace { |
43 // Size of client edge drawn inside the outer frame borders. | 43 // Size of client edge drawn inside the outer frame borders. |
44 const int kNonClientBorderThicknessPreWin10 = 3; | 44 const int kNonClientBorderThicknessPreWin10 = 3; |
45 const int kNonClientBorderThicknessWin10 = 1; | 45 const int kNonClientBorderThicknessWin10 = 1; |
46 // Besides the frame border, there's another 9 px of empty space atop the | 46 // Besides the frame border, there's another 9 px of empty space atop the |
47 // window in restored mode, to use to drag the window around. | 47 // window in restored mode, to use to drag the window around. |
48 const int kNonClientRestoredExtraThickness = 9; | 48 const int kNonClientRestoredExtraThickness = 9; |
49 // In the window corners, the resize areas don't actually expand bigger, but the | 49 // In the window corners, the resize areas don't actually expand bigger, but the |
50 // 16 px at the end of the top and bottom edges triggers diagonal resizing. | 50 // 16 px at the end of the top and bottom edges triggers diagonal resizing. |
51 const int kResizeCornerWidth = 16; | 51 const int kResizeCornerWidth = 16; |
52 // Space between the right edge of the incognito icon and the tabstrip. | |
53 const int kIncognitoRightSpacing = -2; | |
54 // How far the new avatar button is from the left of the minimize button. | 52 // How far the new avatar button is from the left of the minimize button. |
55 const int kNewAvatarButtonOffset = 5; | 53 const int kNewAvatarButtonOffset = 5; |
56 // The content left/right images have a shadow built into them. | 54 // The content left/right images have a shadow built into them. |
57 const int kContentEdgeShadowThickness = 2; | 55 const int kContentEdgeShadowThickness = 2; |
58 // In restored mode, the New Tab button isn't at the same height as the caption | 56 // In restored mode, the New Tab button isn't at the same height as the caption |
59 // buttons, but the space will look cluttered if it actually slides under them, | 57 // buttons, but the space will look cluttered if it actually slides under them, |
60 // so we stop it when the gap between the two is down to 5 px. | 58 // so we stop it when the gap between the two is down to 5 px. |
61 const int kNewTabCaptionRestoredSpacing = 5; | 59 const int kNewTabCaptionRestoredSpacing = 5; |
62 // In maximized mode, where the New Tab button and the caption buttons are at | 60 // In maximized mode, where the New Tab button and the caption buttons are at |
63 // similar vertical coordinates, we need to reserve a larger, 16 px gap to avoid | 61 // similar vertical coordinates, we need to reserve a larger, 16 px gap to avoid |
64 // looking too cluttered. | 62 // looking too cluttered. |
65 const int kNewTabCaptionMaximizedSpacing = 16; | 63 const int kNewTabCaptionMaximizedSpacing = 16; |
66 // How far to indent the tabstrip from the left side of the screen when there | |
67 // is no incognito icon. | |
68 const int kTabStripIndent = -6; | |
69 | 64 |
70 // Converts the |image| to a Windows icon and returns the corresponding HICON | 65 // Converts the |image| to a Windows icon and returns the corresponding HICON |
71 // handle. |image| is resized to desired |width| and |height| if needed. | 66 // handle. |image| is resized to desired |width| and |height| if needed. |
72 HICON CreateHICONFromSkBitmapSizedTo(const gfx::ImageSkia& image, | 67 HICON CreateHICONFromSkBitmapSizedTo(const gfx::ImageSkia& image, |
73 int width, | 68 int width, |
74 int height) { | 69 int height) { |
75 if (width == image.width() && height == image.height()) | 70 if (width == image.width() && height == image.height()) |
76 return IconUtil::CreateHICONFromSkBitmap(*image.bitmap()); | 71 return IconUtil::CreateHICONFromSkBitmap(*image.bitmap()); |
77 return IconUtil::CreateHICONFromSkBitmap(skia::ImageOperations::Resize( | 72 return IconUtil::CreateHICONFromSkBitmap(skia::ImageOperations::Resize( |
78 *image.bitmap(), skia::ImageOperations::RESIZE_BEST, width, height)); | 73 *image.bitmap(), skia::ImageOperations::RESIZE_BEST, width, height)); |
(...skipping 16 matching lines...) Expand all Loading... |
95 } | 90 } |
96 | 91 |
97 GlassBrowserFrameView::~GlassBrowserFrameView() { | 92 GlassBrowserFrameView::~GlassBrowserFrameView() { |
98 } | 93 } |
99 | 94 |
100 /////////////////////////////////////////////////////////////////////////////// | 95 /////////////////////////////////////////////////////////////////////////////// |
101 // GlassBrowserFrameView, BrowserNonClientFrameView implementation: | 96 // GlassBrowserFrameView, BrowserNonClientFrameView implementation: |
102 | 97 |
103 gfx::Rect GlassBrowserFrameView::GetBoundsForTabStrip( | 98 gfx::Rect GlassBrowserFrameView::GetBoundsForTabStrip( |
104 views::View* tabstrip) const { | 99 views::View* tabstrip) const { |
105 int end_x = std::min(frame()->GetMinimizeButtonOffset(), width()); | 100 // In maximized RTL windows, don't let the tabstrip overlap the caption area, |
| 101 // or the alpha-blending it does will make things like the new avatar button |
| 102 // look glitchy. |
| 103 const int offset = |
| 104 (ui::MaterialDesignController::IsModeMaterial() || !base::i18n::IsRTL() || |
| 105 !frame()->IsMaximized()) ? |
| 106 GetLayoutInsets(AVATAR_ICON).right() : 0; |
| 107 const int x = incognito_bounds_.right() + offset; |
| 108 int end_x = width() - NonClientBorderThickness(); |
| 109 if (!base::i18n::IsRTL()) { |
| 110 end_x = std::min(frame()->GetMinimizeButtonOffset(), end_x) - |
| 111 (frame()->IsMaximized() ? |
| 112 kNewTabCaptionMaximizedSpacing : kNewTabCaptionRestoredSpacing); |
106 | 113 |
107 // The new avatar button is optionally displayed to the left of the | 114 // The new avatar button is optionally displayed to the left of the |
108 // minimize button. | 115 // minimize button. |
109 if (new_avatar_button()) { | 116 if (new_avatar_button()) { |
110 end_x -= new_avatar_button()->width() + kNewAvatarButtonOffset; | 117 const int old_end_x = end_x; |
| 118 end_x -= new_avatar_button()->width() + kNewAvatarButtonOffset; |
111 | 119 |
112 // In non-maximized mode, allow the new tab button to slide completely under | 120 // In non-maximized mode, allow the new tab button to slide completely |
113 // the avatar button. | 121 // under the avatar button. |
114 if (!frame()->IsMaximized() && !base::i18n::IsRTL()) { | 122 if (!frame()->IsMaximized()) { |
115 end_x += GetLayoutConstant(NEW_TAB_BUTTON_WIDTH) + | 123 end_x = std::min(end_x + GetLayoutConstant(NEW_TAB_BUTTON_WIDTH) + |
116 kNewTabCaptionRestoredSpacing; | 124 kNewTabCaptionRestoredSpacing, |
| 125 old_end_x); |
| 126 } |
117 } | 127 } |
118 } | 128 } |
119 | 129 return gfx::Rect(x, NonClientTopBorderHeight(), std::max(0, end_x - x), |
120 int x = browser_view()->ShouldShowAvatar() ? | |
121 (incognito_bounds_.right() + kIncognitoRightSpacing) : | |
122 NonClientBorderThickness() + kTabStripIndent; | |
123 // In RTL languages, we have moved an avatar icon left by the size of window | |
124 // controls to prevent it from being rendered over them. So, we use its x | |
125 // position to move this tab strip left when maximized. Also, we can render | |
126 // a tab strip until the left end of this window without considering the size | |
127 // of window controls in RTL languages. | |
128 if (base::i18n::IsRTL()) { | |
129 if (!browser_view()->ShouldShowAvatar() && frame()->IsMaximized()) { | |
130 x += incognito_bounds_.x(); | |
131 } else if (browser_view()->IsRegularOrGuestSession()) { | |
132 x = width() - end_x; | |
133 } | |
134 | |
135 end_x = width(); | |
136 } | |
137 int tabstrip_width = end_x - x - | |
138 (frame()->IsMaximized() ? | |
139 kNewTabCaptionMaximizedSpacing : kNewTabCaptionRestoredSpacing); | |
140 return gfx::Rect(x, NonClientTopBorderHeight(), std::max(0, tabstrip_width), | |
141 tabstrip->GetPreferredSize().height()); | 130 tabstrip->GetPreferredSize().height()); |
142 } | 131 } |
143 | 132 |
144 int GlassBrowserFrameView::GetTopInset() const { | 133 int GlassBrowserFrameView::GetTopInset() const { |
145 return GetClientAreaInsets().top(); | 134 return GetClientAreaInsets().top(); |
146 } | 135 } |
147 | 136 |
148 int GlassBrowserFrameView::GetThemeBackgroundXInset() const { | 137 int GlassBrowserFrameView::GetThemeBackgroundXInset() const { |
149 return 0; | 138 return 0; |
150 } | 139 } |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 if (browser_view()->IsToolbarVisible() && | 251 if (browser_view()->IsToolbarVisible() && |
263 browser_view()->toolbar()->ShouldPaintBackground()) | 252 browser_view()->toolbar()->ShouldPaintBackground()) |
264 PaintToolbarBackground(canvas); | 253 PaintToolbarBackground(canvas); |
265 if (!frame()->IsMaximized()) | 254 if (!frame()->IsMaximized()) |
266 PaintRestoredClientEdge(canvas); | 255 PaintRestoredClientEdge(canvas); |
267 } | 256 } |
268 | 257 |
269 void GlassBrowserFrameView::Layout() { | 258 void GlassBrowserFrameView::Layout() { |
270 if (browser_view()->IsRegularOrGuestSession()) | 259 if (browser_view()->IsRegularOrGuestSession()) |
271 LayoutNewStyleAvatar(); | 260 LayoutNewStyleAvatar(); |
272 else | 261 LayoutIncognitoIcon(); |
273 LayoutIncognitoIcon(); | |
274 | |
275 LayoutClientView(); | 262 LayoutClientView(); |
276 } | 263 } |
277 | 264 |
278 /////////////////////////////////////////////////////////////////////////////// | 265 /////////////////////////////////////////////////////////////////////////////// |
279 // GlassBrowserFrameView, protected: | 266 // GlassBrowserFrameView, protected: |
280 | 267 |
281 // views::ButtonListener: | 268 // views::ButtonListener: |
282 void GlassBrowserFrameView::ButtonPressed(views::Button* sender, | 269 void GlassBrowserFrameView::ButtonPressed(views::Button* sender, |
283 const ui::Event& event) { | 270 const ui::Event& event) { |
284 if (sender == new_avatar_button()) { | 271 if (sender == new_avatar_button()) { |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 button_y, | 505 button_y, |
519 label_size.width(), | 506 label_size.width(), |
520 gfx::win::GetSystemMetricsInDIP(SM_CYMENUSIZE) + 1); | 507 gfx::win::GetSystemMetricsInDIP(SM_CYMENUSIZE) + 1); |
521 } | 508 } |
522 | 509 |
523 void GlassBrowserFrameView::LayoutIncognitoIcon() { | 510 void GlassBrowserFrameView::LayoutIncognitoIcon() { |
524 const gfx::Insets insets(GetLayoutInsets(AVATAR_ICON)); | 511 const gfx::Insets insets(GetLayoutInsets(AVATAR_ICON)); |
525 const gfx::Size size(browser_view()->GetOTRAvatarIcon().size()); | 512 const gfx::Size size(browser_view()->GetOTRAvatarIcon().size()); |
526 int x = NonClientBorderThickness(); | 513 int x = NonClientBorderThickness(); |
527 // In RTL, the icon needs to start after the caption buttons. | 514 // In RTL, the icon needs to start after the caption buttons. |
528 if (base::i18n::IsRTL()) | 515 if (base::i18n::IsRTL()) { |
529 x += width() - frame()->GetMinimizeButtonOffset(); | 516 x = width() - frame()->GetMinimizeButtonOffset() + |
| 517 (new_avatar_button() ? |
| 518 (new_avatar_button()->width() + kNewAvatarButtonOffset) : 0); |
| 519 } |
530 const int bottom = | 520 const int bottom = |
531 GetTopInset() + browser_view()->GetTabStripHeight() - insets.bottom(); | 521 GetTopInset() + browser_view()->GetTabStripHeight() - insets.bottom(); |
532 const int y = frame()->IsMaximized() ? | 522 const int y = (ui::MaterialDesignController::IsModeMaterial() || |
533 FrameTopBorderHeight() : (bottom - size.height()); | 523 !frame()->IsMaximized()) ? |
534 incognito_bounds_.SetRect(x + insets.left(), y, size.width(), | 524 (bottom - size.height()) : FrameTopBorderHeight(); |
535 browser_view()->ShouldShowAvatar() ? (bottom - y) : 0); | 525 incognito_bounds_.SetRect(x + (avatar_button() ? insets.left() : 0), y, |
| 526 avatar_button() ? size.width() : 0, bottom - y); |
536 if (avatar_button()) | 527 if (avatar_button()) |
537 avatar_button()->SetBoundsRect(incognito_bounds_); | 528 avatar_button()->SetBoundsRect(incognito_bounds_); |
538 } | 529 } |
539 | 530 |
540 void GlassBrowserFrameView::LayoutClientView() { | 531 void GlassBrowserFrameView::LayoutClientView() { |
541 client_view_bounds_ = CalculateClientAreaBounds(width(), height()); | 532 client_view_bounds_ = CalculateClientAreaBounds(width(), height()); |
542 } | 533 } |
543 | 534 |
544 gfx::Insets GlassBrowserFrameView::GetClientAreaInsets() const { | 535 gfx::Insets GlassBrowserFrameView::GetClientAreaInsets() const { |
545 if (!browser_view()->IsTabStripVisible()) | 536 if (!browser_view()->IsTabStripVisible()) |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 static bool initialized = false; | 623 static bool initialized = false; |
633 if (!initialized) { | 624 if (!initialized) { |
634 for (int i = 0; i < kThrobberIconCount; ++i) { | 625 for (int i = 0; i < kThrobberIconCount; ++i) { |
635 throbber_icons_[i] = | 626 throbber_icons_[i] = |
636 ui::LoadThemeIconFromResourcesDataDLL(IDI_THROBBER_01 + i); | 627 ui::LoadThemeIconFromResourcesDataDLL(IDI_THROBBER_01 + i); |
637 DCHECK(throbber_icons_[i]); | 628 DCHECK(throbber_icons_[i]); |
638 } | 629 } |
639 initialized = true; | 630 initialized = true; |
640 } | 631 } |
641 } | 632 } |
OLD | NEW |