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..5c89975bc411fca5cada02e994590a4d94722b28 |
--- /dev/null |
+++ b/chrome/browser/ui/views/profiles/win10_native_avatar_button.cc |
@@ -0,0 +1,85 @@ |
+// 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; |
Evan Stade
2017/05/03 16:39:36
nit: unnamed namespace for these constants
emx
2017/05/03 17:10:59
Done.
|
+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 = SkColorSetA(SK_ColorBLACK, 0.54 * 0xFF); |
+// Opacity of the ink drop on hover |
+const float kInkDropHighlightOpacity = 0.08f; |
+// Opacity of the ink drop on click, which is added to kInkDropHighlightOpacity |
+const float kInkDropRippleOpacity = 0.04f; |
+ |
+Win10NativeAvatarButton::Win10NativeAvatarButton( |
+ views::MenuButtonListener* listener, |
+ Profile* profile) |
+ : AvatarButton(listener, profile) { |
+ 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(kInkDropRippleOpacity); |
+} |
+ |
+Win10NativeAvatarButton::~Win10NativeAvatarButton() {} |
+ |
+gfx::Size Win10NativeAvatarButton::GetMinimumSize() const { |
+ // Returns the "cozy" size of the button. Called by |
+ // GlassBrowserFrameView::LayoutProfileSwitcher() when it calculates that the |
+ // button needs to slide over the tabstrip. |
+ return gfx::Size(kButtonMinWidth, kButtonCozyHeight); |
+} |
+ |
+gfx::Size Win10NativeAvatarButton::GetPreferredSize() const { |
+ // Returns the "tall" (normal) size of the button. Its height should match |
+ // the caption button height. |
+ gfx::Size size = views::MenuButton::GetPreferredSize(); |
+ size.set_width( |
+ std::min(std::max(size.width(), kButtonMinWidth), kButtonMaxWidth)); |
+ // TODO(emx): get the proper height here - see http://crrev/2833363002 |
+ size.set_height(30); |
+ return size; |
+} |
+ |
+std::unique_ptr<views::Border> Win10NativeAvatarButton::CreateBorder() const { |
Evan Stade
2017/05/02 15:49:20
file local static?
emx
2017/05/03 17:10:59
Done.
|
+ // 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); |
+} |
+ |
+bool Win10NativeAvatarButton::UseFloodFillInkDrop() const { |
+ return true; |
+} |
+ |
+std::unique_ptr<views::InkDropHighlight> |
+Win10NativeAvatarButton::CreateInkDropHighlight() const { |
+ auto center = gfx::RectF(GetLocalBounds()).CenterPoint(); |
+ auto ink_drop_highlight = base::MakeUnique<views::InkDropHighlight>( |
+ size(), 0, center, GetInkDropBaseColor()); |
+ ink_drop_highlight->set_visible_opacity(kInkDropHighlightOpacity); |
+ return ink_drop_highlight; |
+} |