Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(534)

Unified Diff: chrome/browser/ui/views/frame/browser_non_client_frame_view_mac.mm

Issue 1529703003: [EXPERIMENT] [MacViews] Enable and handle the profile switcher. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/frame/browser_non_client_frame_view_mac.mm
diff --git a/chrome/browser/ui/views/frame/browser_non_client_frame_view_mac.mm b/chrome/browser/ui/views/frame/browser_non_client_frame_view_mac.mm
index 848a2d538b3d68d7963332b2341736e7f65932df..53f2fc4833bc00e030f1d3a161424bf5321f302d 100644
--- a/chrome/browser/ui/views/frame/browser_non_client_frame_view_mac.mm
+++ b/chrome/browser/ui/views/frame/browser_non_client_frame_view_mac.mm
@@ -9,6 +9,7 @@
#include "chrome/browser/ui/views/frame/browser_frame.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/browser_view_layout.h"
+#include "chrome/browser/ui/views/profiles/profile_indicator_icon.h"
#include "grit/theme_resources.h"
#include "ui/base/hit_test.h"
#include "ui/base/theme_provider.h"
@@ -19,7 +20,9 @@ namespace {
// How far to inset the tabstrip from the sides of the window.
const int kTabstripTopInset = 8;
const int kTabstripLeftInset = 70; // Make room for window control buttons.
-const int kTabstripRightInset = 0;
+
+// Padding on each side of either the incognito icon, or the profile switcher.
+const int kAvatarButtonPadding = 3;
} // namespace
@@ -27,9 +30,9 @@ const int kTabstripRightInset = 0;
// BrowserNonClientFrameViewMac, public:
BrowserNonClientFrameViewMac::BrowserNonClientFrameViewMac(
- BrowserFrame* frame, BrowserView* browser_view)
- : BrowserNonClientFrameView(frame, browser_view) {
-}
+ BrowserFrame* frame,
+ BrowserView* browser_view)
+ : BrowserNonClientFrameView(frame, browser_view), profile_switcher_(this) {}
BrowserNonClientFrameViewMac::~BrowserNonClientFrameViewMac() {
}
@@ -37,12 +40,18 @@ BrowserNonClientFrameViewMac::~BrowserNonClientFrameViewMac() {
///////////////////////////////////////////////////////////////////////////////
// BrowserNonClientFrameViewMac, BrowserNonClientFrameView implementation:
+void BrowserNonClientFrameViewMac::OnBrowserViewInitViewsComplete() {
+ // Update avatars here rather than the constructor to avoid triggering a call
+ // to Widget::OnRootViewLayout() before the NonClientView is initialized.
+ UpdateProfileIcons();
+}
+
gfx::Rect BrowserNonClientFrameViewMac::GetBoundsForTabStrip(
views::View* tabstrip) const {
DCHECK(tabstrip);
- gfx::Rect bounds = gfx::Rect(0, kTabstripTopInset,
- width(), tabstrip->GetPreferredSize().height());
- bounds.Inset(kTabstripLeftInset, 0, kTabstripRightInset, 0);
+ gfx::Rect bounds(0, kTabstripTopInset, width(),
+ tabstrip->GetPreferredSize().height());
+ bounds.Inset(kTabstripLeftInset, 0, GetTabStripRightInset(), 0);
return bounds;
}
@@ -57,6 +66,10 @@ int BrowserNonClientFrameViewMac::GetThemeBackgroundXInset() const {
void BrowserNonClientFrameViewMac::UpdateThrobber(bool running) {
}
+views::View* BrowserNonClientFrameViewMac::GetProfileSwitcherView() const {
+ return profile_switcher_.view();
+}
+
///////////////////////////////////////////////////////////////////////////////
// BrowserNonClientFrameViewMac, views::NonClientFrameView implementation:
@@ -70,6 +83,9 @@ gfx::Rect BrowserNonClientFrameViewMac::GetWindowBoundsForClientBounds(
}
int BrowserNonClientFrameViewMac::NonClientHitTest(const gfx::Point& point) {
+ if (profile_switcher_.HitTest(point))
+ return HTCLIENT;
+
int component = frame()->client_view()->NonClientHitTest(point);
// BrowserView::NonClientHitTest will return HTNOWHERE for points that hit
@@ -121,14 +137,59 @@ void BrowserNonClientFrameViewMac::OnPaint(gfx::Canvas* canvas) {
PaintToolbarBackground(canvas);
}
+void BrowserNonClientFrameViewMac::Layout() {
+ views::View* switcher_button = profile_switcher_.view();
+ if (switcher_button) {
+ const gfx::Size button_size = switcher_button->GetPreferredSize();
+ switcher_button->SetBounds(
+ width() - GetTabStripRightInset() + kAvatarButtonPadding,
+ kAvatarButtonPadding, button_size.width(), button_size.height());
+ }
+ if (profile_indicator_icon()) {
+ DCHECK(!switcher_button);
+ const gfx::Size button_size = GetOTRAvatarIcon().size();
+
+ // The incognito icon needs to hug the base of the tab strip.
+ const gfx::Insets insets(GetLayoutInsets(AVATAR_ICON));
+ const int bottom = GetTopInset(false) +
+ browser_view()->GetTabStripHeight() - insets.bottom();
+
+ profile_indicator_icon()->SetBounds(
+ width() - GetTabStripRightInset() + kAvatarButtonPadding,
+ bottom - button_size.height(), button_size.width(),
+ button_size.height());
+ }
+}
+
+bool BrowserNonClientFrameViewMac::DoesIntersectRect(
+ const View* target,
+ const gfx::Rect& rect) const {
+ DCHECK_EQ(target, this);
+ // Note this doesn't check the incognito icon, since that is non-interactive.
+ return profile_switcher_.Intersects(rect) ||
+ NonClientFrameView::DoesIntersectRect(target, rect);
+}
+
// BrowserNonClientFrameView:
void BrowserNonClientFrameViewMac::UpdateProfileIcons() {
- NOTIMPLEMENTED();
+ if (browser_view()->IsRegularOrGuestSession())
+ profile_switcher_.Update(AvatarButtonStyle::NATIVE);
+ else
+ UpdateProfileIndicatorIcon();
}
///////////////////////////////////////////////////////////////////////////////
// BrowserNonClientFrameViewMac, private:
+int BrowserNonClientFrameViewMac::GetTabStripRightInset() const {
+ int inset = kAvatarButtonPadding * 2;
+ if (profile_indicator_icon())
+ inset += profile_indicator_icon()->width();
+ if (profile_switcher_.view())
+ inset += profile_switcher_.view()->width();
+ return inset;
+}
+
void BrowserNonClientFrameViewMac::PaintThemedFrame(gfx::Canvas* canvas) {
gfx::ImageSkia image = GetFrameImage();
canvas->TileImageInt(image, 0, 0, width(), image.height());

Powered by Google App Engine
This is Rietveld 408576698