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

Unified Diff: chrome/browser/ui/views/profiles/win10_native_avatar_button.cc

Issue 2851543002: Update avatar button to MD (part 1) (Closed)
Patch Set: Renamed NewAvatarButton->ThemedAvatarButton and MaterialDesignAvatarButton->Win10NativeAvatarButton… Created 3 years, 8 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/profiles/win10_native_avatar_button.cc
diff --git a/chrome/browser/ui/views/profiles/win10_native_avatar_button.cc b/chrome/browser/ui/views/profiles/win10_native_avatar_button.cc
new file mode 100644
index 0000000000000000000000000000000000000000..94fe951eee170f5a24094fd6012d7bc9c36650a8
--- /dev/null
+++ b/chrome/browser/ui/views/profiles/win10_native_avatar_button.cc
@@ -0,0 +1,104 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/views/profiles/win10_native_avatar_button.h"
+
+#include "chrome/app/vector_icons/vector_icons.h"
+#include "chrome/browser/ui/views/tabs/tab_strip.h"
+#include "ui/gfx/paint_vector_icon.h"
+#include "ui/views/animation/flood_fill_ink_drop_ripple.h"
+#include "ui/views/animation/ink_drop_impl.h"
+#include "ui/views/border.h"
+#include "ui/views/painter.h"
+
+const int kButtonMinWidth = 48;
+const int kButtonMaxWidth = 96;
+// Height of the "cozy" MD button that slides over the tabstrip
+// ("tall" MD button height is computed)
+const int kButtonCozyHeight = 20;
+const int kButtonIconHeight = 16;
+const SkColor kButtonIconColor = SkColorSetARGB(138, 0, 0, 0); // Alpha 54%
Evan Stade 2017/04/28 18:38:29 I believe this is more or less equivalent to gfx::
emx 2017/05/02 15:17:11 It's noticeably lighter than kChromeIconGrey. As A
+// Opacity of the ink drop on hover
+const float kHighlightInkDropOpacity = 0.08f;
Evan Stade 2017/04/28 18:38:29 nit: InkDropHighlight, InkDropRipple
emx 2017/05/02 15:17:11 Done.
+// Opacity of the ink drop on click, which is added to kHighlightInkDropOpacity
+const float kRippleInkDropOpacity = 0.04f;
+
+Win10NativeAvatarButton::Win10NativeAvatarButton(
+ views::MenuButtonListener* listener,
+ Profile* profile,
+ BrowserView* browser_view)
+ : AvatarButton(listener, profile), browser_view_(browser_view) {
+ DCHECK(browser_view);
+
+ set_generic_avatar(gfx::CreateVectorIcon(
+ kAccountCircleIcon, kButtonIconHeight, kButtonIconColor));
+ SetBorder(CreateBorder());
+
+ Update();
+ SchedulePaint();
+
+ SetInkDropMode(InkDropMode::ON);
+ set_has_ink_drop_action_on_click(true);
+ SetFocusPainter(nullptr);
+ set_ink_drop_base_color(SK_ColorBLACK);
+ set_ink_drop_visible_opacity(kRippleInkDropOpacity);
+}
+
+Win10NativeAvatarButton::~Win10NativeAvatarButton() {}
+
+gfx::Size Win10NativeAvatarButton::GetPreferredSize() const {
+ gfx::Size ps = views::MenuButton::GetPreferredSize();
+ ps.set_width(
+ std::min(std::max(ps.width(), kButtonMinWidth), kButtonMaxWidth));
+ // TODO(emx): get the proper height here - see http://crrev/2833363002
+ ps.set_height(30);
+ return ps;
+}
+
+std::unique_ptr<views::Border> Win10NativeAvatarButton::CreateBorder() const {
+ // These insets look OK at 100%, 125%, 150%, 175% and 200% scaling.
+ const int kLeftRightInset = 8;
+ const int kTopInset = 1;
+ const int kBottomInset = 3;
+ return views::CreateEmptyBorder(kTopInset, kLeftRightInset, kBottomInset,
+ kLeftRightInset);
+}
+
+std::unique_ptr<views::InkDrop> Win10NativeAvatarButton::CreateInkDrop() {
+ return CreateDefaultFloodFillInkDropImpl();
+}
+
+std::unique_ptr<views::InkDropHighlight>
+Win10NativeAvatarButton::CreateInkDropHighlight() const {
+ auto center = gfx::RectF(gfx::Rect(size())).CenterPoint();
Evan Stade 2017/04/28 18:38:29 nit: s/gfx::Rect(size())/GetLocalBounds()
emx 2017/05/02 15:17:11 Done.
+ auto ink_drop_highlight = base::MakeUnique<views::InkDropHighlight>(
+ size(), 0, center, GetInkDropBaseColor());
+ ink_drop_highlight->set_visible_opacity(kHighlightInkDropOpacity);
+ return ink_drop_highlight;
+}
+
+std::unique_ptr<views::InkDropRipple>
+Win10NativeAvatarButton::CreateInkDropRipple() const {
Evan Stade 2017/04/28 18:38:30 this looks like it's copied pretty much verbatim f
emx 2017/05/02 15:17:11 Done.
+ return base::MakeUnique<views::FloodFillInkDropRipple>(
+ size(), GetInkDropCenterBasedOnLastEvent(), GetInkDropBaseColor(),
+ ink_drop_visible_opacity());
+}
+
+void Win10NativeAvatarButton::UpdateButtonHeightForPosition(
+ const int button_x,
+ int* button_height) const {
+ TabStrip* tab_strip = browser_view_->tabstrip();
+ if (!tab_strip)
+ return;
+
+ // In RTL the new tab button is on the left, so it can never slide under the
+ // avatar button (which is still on the right). May as well use the space.
+ if (base::i18n::IsRTL())
+ return;
+
+ // Use the "cozy" button if the tabstrip can slide under it
+ if (tab_strip->max_x() >= button_x) {
+ *button_height = kButtonCozyHeight;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698