Index: chrome/browser/ui/views/frame/glass_browser_frame_view.cc |
diff --git a/chrome/browser/ui/views/frame/glass_browser_frame_view.cc b/chrome/browser/ui/views/frame/glass_browser_frame_view.cc |
index 8f049ca733af21bec5a84a35c0459c14150e997d..0eae2fb5b2d47442c7321e5655684f8a11dba004 100644 |
--- a/chrome/browser/ui/views/frame/glass_browser_frame_view.cc |
+++ b/chrome/browser/ui/views/frame/glass_browser_frame_view.cc |
@@ -49,7 +49,7 @@ const int kNonClientRestoredExtraThickness = 11; |
// pixels at the end of the top and bottom edges trigger diagonal resizing. |
const int kResizeCornerWidth = 16; |
// How far the profile switcher button is from the left of the minimize button. |
-const int kProfileSwitcherButtonOffset = 5; |
+const int kProfileSwitcherButtonOffset = 1; |
// The content edge images have a shadow built into them. |
const int kContentEdgeShadowThickness = 2; |
// In restored mode, the New Tab button isn't at the same height as the caption |
@@ -60,11 +60,6 @@ const int kNewTabCaptionRestoredSpacing = 5; |
// similar vertical coordinates, we need to reserve a larger, 16 px gap to avoid |
// looking too cluttered. |
const int kNewTabCaptionMaximizedSpacing = 16; |
-// Height of the profile switcher button. Same as the height of the Windows 7/8 |
-// caption buttons. |
-// TODO(bsep): Windows 10 caption buttons look very different and we would like |
-// the profile switcher button to match on that platform. |
-const int kProfileSwitcherButtonHeight = 20; |
// There is a small one-pixel strip right above the caption buttons in which the |
// resize border "peeks" through. |
const int kCaptionButtonTopInset = 1; |
@@ -99,7 +94,8 @@ GlassBrowserFrameView::GlassBrowserFrameView(BrowserFrame* frame, |
restore_button_(nullptr), |
close_button_(nullptr), |
throbber_running_(false), |
- throbber_frame_(0) { |
+ throbber_frame_(0), |
+ tab_strip_(nullptr) { |
// We initialize all fields despite some of them being unused in some modes, |
// since it's possible for modes to flip dynamically (e.g. if the user enables |
// a high-contrast theme). Throbber icons are only used when ShowSystemIcon() |
@@ -132,6 +128,10 @@ GlassBrowserFrameView::GlassBrowserFrameView(BrowserFrame* frame, |
} |
GlassBrowserFrameView::~GlassBrowserFrameView() { |
+ if (tab_strip_) { |
+ tab_strip_->RemoveObserver(this); |
+ tab_strip_ = nullptr; |
+ } |
} |
/////////////////////////////////////////////////////////////////////////////// |
@@ -148,12 +148,14 @@ gfx::Rect GlassBrowserFrameView::GetBoundsForTabStrip( |
// The profile switcher button is optionally displayed to the left of the |
// minimize button. |
- if (profile_switcher_.view()) { |
+ views::View* button_view = GetProfileSwitcherView(); |
+ if (button_view) { |
const int old_end_x = end_x; |
- end_x -= profile_switcher_.view()->width() + kProfileSwitcherButtonOffset; |
+ end_x -= button_view->width() + kProfileSwitcherButtonOffset; |
// In non-maximized mode, allow the new tab button to slide completely |
// under the profile switcher button. |
+ // Note that the button should be "cozy" then, even if it's an MD button. |
if (!IsMaximized()) { |
end_x = std::min(end_x + GetLayoutSize(NEW_TAB_BUTTON).width() + |
kNewTabCaptionRestoredSpacing, |
@@ -214,7 +216,14 @@ gfx::Size GlassBrowserFrameView::GetMinimumSize() const { |
} |
views::View* GlassBrowserFrameView::GetProfileSwitcherView() const { |
- return profile_switcher_.view(); |
+ return profile_switcher_.button(); |
+} |
+ |
+void GlassBrowserFrameView::OnBrowserViewInitViewsComplete() { |
+ DCHECK(browser_view()->tabstrip()); |
+ DCHECK(!tab_strip_); |
+ tab_strip_ = browser_view()->tabstrip(); |
+ tab_strip_->AddObserver(this); |
} |
/////////////////////////////////////////////////////////////////////////////// |
@@ -270,8 +279,8 @@ int GlassBrowserFrameView::NonClientHitTest(const gfx::Point& point) { |
// See if the point is within the incognito icon or the profile switcher menu. |
if ((profile_indicator_icon() && |
profile_indicator_icon()->GetMirroredBounds().Contains(point)) || |
- (profile_switcher_.view() && |
- profile_switcher_.view()->GetMirroredBounds().Contains(point))) |
+ (GetProfileSwitcherView() && |
+ GetProfileSwitcherView()->GetMirroredBounds().Contains(point))) |
return HTCLIENT; |
int frame_component = frame()->client_view()->NonClientHitTest(point); |
@@ -406,6 +415,15 @@ void GlassBrowserFrameView::Layout() { |
LayoutClientView(); |
} |
+void GlassBrowserFrameView::ChildPreferredSizeChanged(views::View* child) { |
+ if (child == profile_switcher_.button()) { |
+ // Need to layout the root view here so that the line below the tabstrip |
+ // is re-drawn properly when a profile is added or removed and the avatar |
+ // button changes between tall and cozy as a result. |
+ frame()->GetRootView()->Layout(); |
+ } |
+} |
+ |
/////////////////////////////////////////////////////////////////////////////// |
// GlassBrowserFrameView, protected: |
@@ -434,8 +452,8 @@ bool GlassBrowserFrameView::DoesIntersectRect(const views::View* target, |
profile_indicator_icon() && |
profile_indicator_icon()->GetMirroredBounds().Intersects(rect); |
bool hit_profile_switcher_button = |
- profile_switcher_.view() && |
- profile_switcher_.view()->GetMirroredBounds().Intersects(rect); |
+ GetProfileSwitcherView() && |
+ GetProfileSwitcherView()->GetMirroredBounds().Intersects(rect); |
return hit_incognito_icon || hit_profile_switcher_button || |
!frame()->client_view()->bounds().Intersects(rect); |
} |
@@ -715,20 +733,44 @@ void GlassBrowserFrameView::FillClientEdgeRects(int x, |
canvas->FillRect(side, color); |
} |
+void GlassBrowserFrameView::TabStripMaxXChanged(TabStrip* tab_strip) { |
+ // May switch between cozy and tall MD avatar button here. |
+ DCHECK_EQ(tab_strip, tab_strip_); |
+ ChildPreferredSizeChanged(profile_switcher_.button()); |
+} |
+ |
+void GlassBrowserFrameView::TabStripRemovedTabAt(TabStrip* tab_strip, |
+ int index) { |
+ // May switch between cozy and tall button here, too. TabStripMaxXChanged |
+ // is not enough when a tab other than the last tab is closed. |
+ DCHECK_EQ(tab_strip, tab_strip_); |
+ ChildPreferredSizeChanged(profile_switcher_.button()); |
+} |
+ |
+void GlassBrowserFrameView::TabStripDeleted(TabStrip* tab_strip) { |
+ DCHECK_EQ(tab_strip, tab_strip_); |
+ DCHECK(tab_strip_); |
+ tab_strip_->RemoveObserver(this); |
+ tab_strip_ = nullptr; |
+} |
+ |
void GlassBrowserFrameView::LayoutProfileSwitcher() { |
DCHECK(browser_view()->IsRegularOrGuestSession()); |
- if (!profile_switcher_.view()) |
+ |
+ AvatarButton* avatar_button = profile_switcher_.button(); |
+ if (!avatar_button) |
return; |
- gfx::Size label_size = profile_switcher_.view()->GetPreferredSize(); |
+ gfx::Size button_size = avatar_button->GetPreferredSize(); |
+ int button_width = button_size.width(); |
+ int button_height = button_size.height(); |
int button_x; |
if (CaptionButtonsOnLeadingEdge()) { |
button_x = width() - frame()->GetMinimizeButtonOffset() + |
kProfileSwitcherButtonOffset; |
} else { |
- button_x = |
- MinimizeButtonX() - kProfileSwitcherButtonOffset - label_size.width(); |
+ button_x = MinimizeButtonX() - kProfileSwitcherButtonOffset - button_width; |
} |
int button_y = WindowTopY(); |
@@ -739,8 +781,9 @@ void GlassBrowserFrameView::LayoutProfileSwitcher() { |
// button the same way to match. |
button_y -= 1; |
} |
- profile_switcher_.view()->SetBounds(button_x, button_y, label_size.width(), |
- kProfileSwitcherButtonHeight); |
+ |
+ avatar_button->UpdateButtonHeightForPosition(button_x, &button_height); |
Evan Stade
2017/04/28 18:38:29
I would rearrange these calculations slightly. You
emx
2017/05/02 15:17:11
Yes, that simplifies things a lot and now I don't
|
+ avatar_button->SetBounds(button_x, button_y, button_width, button_height); |
} |
void GlassBrowserFrameView::LayoutIncognitoIcon() { |
@@ -749,7 +792,7 @@ void GlassBrowserFrameView::LayoutIncognitoIcon() { |
// In RTL, the icon needs to start after the caption buttons. |
if (CaptionButtonsOnLeadingEdge()) { |
x = width() - frame()->GetMinimizeButtonOffset() + |
- (profile_switcher_.view() ? (profile_switcher_.view()->width() + |
+ (GetProfileSwitcherView() ? (GetProfileSwitcherView()->width() + |
kProfileSwitcherButtonOffset) |
: 0); |
} |