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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 // GlassBrowserFrameView, BrowserNonClientFrameView implementation: | 107 // GlassBrowserFrameView, BrowserNonClientFrameView implementation: |
108 | 108 |
109 gfx::Rect GlassBrowserFrameView::GetBoundsForTabStrip( | 109 gfx::Rect GlassBrowserFrameView::GetBoundsForTabStrip( |
110 views::View* tabstrip) const { | 110 views::View* tabstrip) const { |
111 int minimize_button_offset = | 111 int minimize_button_offset = |
112 std::min(frame()->GetMinimizeButtonOffset(), width()); | 112 std::min(frame()->GetMinimizeButtonOffset(), width()); |
113 | 113 |
114 // 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 |
115 // minimize button. | 115 // minimize button. |
116 if (new_avatar_button()) { | 116 if (new_avatar_button()) { |
117 DCHECK(switches::IsNewAvatarMenu()); | |
118 minimize_button_offset -= | 117 minimize_button_offset -= |
119 new_avatar_button()->width() + kNewAvatarButtonOffset; | 118 new_avatar_button()->width() + kNewAvatarButtonOffset; |
120 | 119 |
121 // In non-maximized mode, allow the new tab button to completely slide under | 120 // In non-maximized mode, allow the new tab button to completely slide under |
122 // the avatar button. | 121 // the avatar button. |
123 if (!frame()->IsMaximized() && !base::i18n::IsRTL()) { | 122 if (!frame()->IsMaximized() && !base::i18n::IsRTL()) { |
124 minimize_button_offset += | 123 minimize_button_offset += |
125 TabStrip::kNewTabButtonAssetWidth + kNewTabCaptionRestoredSpacing; | 124 TabStrip::kNewTabButtonAssetWidth + kNewTabCaptionRestoredSpacing; |
126 } | 125 } |
127 } | 126 } |
128 | 127 |
129 int tabstrip_x = browser_view()->ShouldShowAvatar() ? | 128 int tabstrip_x = browser_view()->ShouldShowAvatar() ? |
130 (avatar_bounds_.right() + kAvatarRightSpacing) : | 129 (avatar_bounds_.right() + kAvatarRightSpacing) : |
131 NonClientBorderThickness() + kTabStripIndent; | 130 NonClientBorderThickness() + kTabStripIndent; |
132 // In RTL languages, we have moved an avatar icon left by the size of window | 131 // In RTL languages, we have moved an avatar icon left by the size of window |
133 // controls to prevent it from being rendered over them. So, we use its x | 132 // controls to prevent it from being rendered over them. So, we use its x |
134 // position to move this tab strip left when maximized. Also, we can render | 133 // position to move this tab strip left when maximized. Also, we can render |
135 // a tab strip until the left end of this window without considering the size | 134 // a tab strip until the left end of this window without considering the size |
136 // of window controls in RTL languages. | 135 // of window controls in RTL languages. |
137 if (base::i18n::IsRTL()) { | 136 if (base::i18n::IsRTL()) { |
138 if (!browser_view()->ShouldShowAvatar() && frame()->IsMaximized()) { | 137 if (!browser_view()->ShouldShowAvatar() && frame()->IsMaximized()) { |
139 tabstrip_x += avatar_bounds_.x(); | 138 tabstrip_x += avatar_bounds_.x(); |
140 } else if (browser_view()->IsRegularOrGuestSession() && | 139 } else if (browser_view()->IsRegularOrGuestSession()) { |
141 switches::IsNewAvatarMenu()) { | |
142 tabstrip_x = width() - minimize_button_offset; | 140 tabstrip_x = width() - minimize_button_offset; |
143 } | 141 } |
144 | 142 |
145 minimize_button_offset = width(); | 143 minimize_button_offset = width(); |
146 } | 144 } |
147 int tabstrip_width = minimize_button_offset - tabstrip_x - | 145 int tabstrip_width = minimize_button_offset - tabstrip_x - |
148 (frame()->IsMaximized() ? | 146 (frame()->IsMaximized() ? |
149 kNewTabCaptionMaximizedSpacing : kNewTabCaptionRestoredSpacing); | 147 kNewTabCaptionMaximizedSpacing : kNewTabCaptionRestoredSpacing); |
150 return gfx::Rect(tabstrip_x, NonClientTopBorderHeight(), | 148 return gfx::Rect(tabstrip_x, NonClientTopBorderHeight(), |
151 std::max(0, tabstrip_width), | 149 std::max(0, tabstrip_width), |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 | 265 |
268 void GlassBrowserFrameView::OnPaint(gfx::Canvas* canvas) { | 266 void GlassBrowserFrameView::OnPaint(gfx::Canvas* canvas) { |
269 if (browser_view()->IsToolbarVisible() && | 267 if (browser_view()->IsToolbarVisible() && |
270 browser_view()->toolbar()->ShouldPaintBackground()) | 268 browser_view()->toolbar()->ShouldPaintBackground()) |
271 PaintToolbarBackground(canvas); | 269 PaintToolbarBackground(canvas); |
272 if (!frame()->IsMaximized()) | 270 if (!frame()->IsMaximized()) |
273 PaintRestoredClientEdge(canvas); | 271 PaintRestoredClientEdge(canvas); |
274 } | 272 } |
275 | 273 |
276 void GlassBrowserFrameView::Layout() { | 274 void GlassBrowserFrameView::Layout() { |
277 if (browser_view()->IsRegularOrGuestSession() && switches::IsNewAvatarMenu()) | 275 if (browser_view()->IsRegularOrGuestSession()) |
278 LayoutNewStyleAvatar(); | 276 LayoutNewStyleAvatar(); |
279 else | 277 else |
280 LayoutAvatar(); | 278 LayoutAvatar(); |
281 | 279 |
282 LayoutClientView(); | 280 LayoutClientView(); |
283 } | 281 } |
284 | 282 |
285 /////////////////////////////////////////////////////////////////////////////// | 283 /////////////////////////////////////////////////////////////////////////////// |
286 // GlassBrowserFrameView, protected: | 284 // GlassBrowserFrameView, protected: |
287 | 285 |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 canvas->FillRect(gfx::Rect(client_area_bounds.x(), client_area_bottom, | 478 canvas->FillRect(gfx::Rect(client_area_bounds.x(), client_area_bottom, |
481 client_area_bounds.width(), kClientEdgeThickness), | 479 client_area_bounds.width(), kClientEdgeThickness), |
482 toolbar_color); | 480 toolbar_color); |
483 canvas->FillRect(gfx::Rect(client_area_bounds.right(), client_area_top, | 481 canvas->FillRect(gfx::Rect(client_area_bounds.right(), client_area_top, |
484 kClientEdgeThickness, | 482 kClientEdgeThickness, |
485 client_area_bottom + kClientEdgeThickness - client_area_top), | 483 client_area_bottom + kClientEdgeThickness - client_area_top), |
486 toolbar_color); | 484 toolbar_color); |
487 } | 485 } |
488 | 486 |
489 void GlassBrowserFrameView::LayoutNewStyleAvatar() { | 487 void GlassBrowserFrameView::LayoutNewStyleAvatar() { |
490 DCHECK(switches::IsNewAvatarMenu()); | 488 DCHECK(browser_view()->IsRegularOrGuestSession()); |
491 if (!new_avatar_button()) | 489 if (!new_avatar_button()) |
492 return; | 490 return; |
493 | 491 |
494 gfx::Size label_size = new_avatar_button()->GetPreferredSize(); | 492 gfx::Size label_size = new_avatar_button()->GetPreferredSize(); |
495 | 493 |
496 int button_x = frame()->GetMinimizeButtonOffset() - | 494 int button_x = frame()->GetMinimizeButtonOffset() - |
497 kNewAvatarButtonOffset - label_size.width(); | 495 kNewAvatarButtonOffset - label_size.width(); |
498 if (base::i18n::IsRTL()) | 496 if (base::i18n::IsRTL()) |
499 button_x = width() - frame()->GetMinimizeButtonOffset() + | 497 button_x = width() - frame()->GetMinimizeButtonOffset() + |
500 kNewAvatarButtonOffset; | 498 kNewAvatarButtonOffset; |
501 | 499 |
502 // We need to offset the button correctly in maximized mode, so that the | 500 // We need to offset the button correctly in maximized mode, so that the |
503 // custom glass style aligns with the native control glass style. The | 501 // custom glass style aligns with the native control glass style. The |
504 // glass shadow is off by 1px, which was determined by visual inspection. | 502 // glass shadow is off by 1px, which was determined by visual inspection. |
505 const int shadow_height = GetLayoutConstant(TABSTRIP_TOP_SHADOW_HEIGHT); | 503 const int shadow_height = GetLayoutConstant(TABSTRIP_TOP_SHADOW_HEIGHT); |
506 int button_y = frame()->IsMaximized() ? | 504 int button_y = frame()->IsMaximized() ? |
507 (NonClientTopBorderHeight() + shadow_height - 1) : 1; | 505 (NonClientTopBorderHeight() + shadow_height - 1) : 1; |
508 | 506 |
509 new_avatar_button()->SetBounds( | 507 new_avatar_button()->SetBounds( |
510 button_x, | 508 button_x, |
511 button_y, | 509 button_y, |
512 label_size.width(), | 510 label_size.width(), |
513 gfx::win::GetSystemMetricsInDIP(SM_CYMENUSIZE) + 1); | 511 gfx::win::GetSystemMetricsInDIP(SM_CYMENUSIZE) + 1); |
514 } | 512 } |
515 | 513 |
516 void GlassBrowserFrameView::LayoutAvatar() { | 514 void GlassBrowserFrameView::LayoutAvatar() { |
517 // Even though the avatar is used for both incognito and profiles we always | |
518 // use the incognito icon to layout the avatar button. The profile icon | |
519 // can be customized so we can't depend on its size to perform layout. | |
520 gfx::ImageSkia incognito_icon = browser_view()->GetOTRAvatarIcon(); | 515 gfx::ImageSkia incognito_icon = browser_view()->GetOTRAvatarIcon(); |
521 | 516 |
522 int avatar_x = NonClientBorderThickness() + kAvatarLeftSpacing; | 517 int avatar_x = NonClientBorderThickness() + kAvatarLeftSpacing; |
523 // Move this avatar icon by the size of window controls to prevent it from | 518 // Move this avatar icon by the size of window controls to prevent it from |
524 // being rendered over them in RTL languages. This code also needs to adjust | 519 // being rendered over them in RTL languages. This code also needs to adjust |
525 // the width of a tab strip to avoid decreasing this size twice. (See the | 520 // the width of a tab strip to avoid decreasing this size twice. (See the |
526 // comment in GetBoundsForTabStrip().) | 521 // comment in GetBoundsForTabStrip().) |
527 if (base::i18n::IsRTL()) | 522 if (base::i18n::IsRTL()) |
528 avatar_x += width() - frame()->GetMinimizeButtonOffset(); | 523 avatar_x += width() - frame()->GetMinimizeButtonOffset(); |
529 | 524 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 static bool initialized = false; | 629 static bool initialized = false; |
635 if (!initialized) { | 630 if (!initialized) { |
636 for (int i = 0; i < kThrobberIconCount; ++i) { | 631 for (int i = 0; i < kThrobberIconCount; ++i) { |
637 throbber_icons_[i] = | 632 throbber_icons_[i] = |
638 ui::LoadThemeIconFromResourcesDataDLL(IDI_THROBBER_01 + i); | 633 ui::LoadThemeIconFromResourcesDataDLL(IDI_THROBBER_01 + i); |
639 DCHECK(throbber_icons_[i]); | 634 DCHECK(throbber_icons_[i]); |
640 } | 635 } |
641 initialized = true; | 636 initialized = true; |
642 } | 637 } |
643 } | 638 } |
OLD | NEW |