Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/views/profiles/win10_native_avatar_button.h" | |
| 6 | |
| 7 #include "chrome/app/vector_icons/vector_icons.h" | |
| 8 #include "chrome/browser/ui/views/tabs/tab_strip.h" | |
| 9 #include "ui/gfx/paint_vector_icon.h" | |
| 10 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" | |
| 11 #include "ui/views/animation/ink_drop_impl.h" | |
| 12 #include "ui/views/border.h" | |
| 13 #include "ui/views/painter.h" | |
| 14 | |
| 15 const int kButtonMinWidth = 48; | |
| 16 const int kButtonMaxWidth = 96; | |
| 17 // Height of the "cozy" MD button that slides over the tabstrip | |
| 18 // ("tall" MD button height is computed) | |
| 19 const int kButtonCozyHeight = 20; | |
| 20 const int kButtonIconHeight = 16; | |
| 21 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
| |
| 22 // Opacity of the ink drop on hover | |
| 23 const float kHighlightInkDropOpacity = 0.08f; | |
|
Evan Stade
2017/04/28 18:38:29
nit: InkDropHighlight, InkDropRipple
emx
2017/05/02 15:17:11
Done.
| |
| 24 // Opacity of the ink drop on click, which is added to kHighlightInkDropOpacity | |
| 25 const float kRippleInkDropOpacity = 0.04f; | |
| 26 | |
| 27 Win10NativeAvatarButton::Win10NativeAvatarButton( | |
| 28 views::MenuButtonListener* listener, | |
| 29 Profile* profile, | |
| 30 BrowserView* browser_view) | |
| 31 : AvatarButton(listener, profile), browser_view_(browser_view) { | |
| 32 DCHECK(browser_view); | |
| 33 | |
| 34 set_generic_avatar(gfx::CreateVectorIcon( | |
| 35 kAccountCircleIcon, kButtonIconHeight, kButtonIconColor)); | |
| 36 SetBorder(CreateBorder()); | |
| 37 | |
| 38 Update(); | |
| 39 SchedulePaint(); | |
| 40 | |
| 41 SetInkDropMode(InkDropMode::ON); | |
| 42 set_has_ink_drop_action_on_click(true); | |
| 43 SetFocusPainter(nullptr); | |
| 44 set_ink_drop_base_color(SK_ColorBLACK); | |
| 45 set_ink_drop_visible_opacity(kRippleInkDropOpacity); | |
| 46 } | |
| 47 | |
| 48 Win10NativeAvatarButton::~Win10NativeAvatarButton() {} | |
| 49 | |
| 50 gfx::Size Win10NativeAvatarButton::GetPreferredSize() const { | |
| 51 gfx::Size ps = views::MenuButton::GetPreferredSize(); | |
| 52 ps.set_width( | |
| 53 std::min(std::max(ps.width(), kButtonMinWidth), kButtonMaxWidth)); | |
| 54 // TODO(emx): get the proper height here - see http://crrev/2833363002 | |
| 55 ps.set_height(30); | |
| 56 return ps; | |
| 57 } | |
| 58 | |
| 59 std::unique_ptr<views::Border> Win10NativeAvatarButton::CreateBorder() const { | |
| 60 // These insets look OK at 100%, 125%, 150%, 175% and 200% scaling. | |
| 61 const int kLeftRightInset = 8; | |
| 62 const int kTopInset = 1; | |
| 63 const int kBottomInset = 3; | |
| 64 return views::CreateEmptyBorder(kTopInset, kLeftRightInset, kBottomInset, | |
| 65 kLeftRightInset); | |
| 66 } | |
| 67 | |
| 68 std::unique_ptr<views::InkDrop> Win10NativeAvatarButton::CreateInkDrop() { | |
| 69 return CreateDefaultFloodFillInkDropImpl(); | |
| 70 } | |
| 71 | |
| 72 std::unique_ptr<views::InkDropHighlight> | |
| 73 Win10NativeAvatarButton::CreateInkDropHighlight() const { | |
| 74 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.
| |
| 75 auto ink_drop_highlight = base::MakeUnique<views::InkDropHighlight>( | |
| 76 size(), 0, center, GetInkDropBaseColor()); | |
| 77 ink_drop_highlight->set_visible_opacity(kHighlightInkDropOpacity); | |
| 78 return ink_drop_highlight; | |
| 79 } | |
| 80 | |
| 81 std::unique_ptr<views::InkDropRipple> | |
| 82 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.
| |
| 83 return base::MakeUnique<views::FloodFillInkDropRipple>( | |
| 84 size(), GetInkDropCenterBasedOnLastEvent(), GetInkDropBaseColor(), | |
| 85 ink_drop_visible_opacity()); | |
| 86 } | |
| 87 | |
| 88 void Win10NativeAvatarButton::UpdateButtonHeightForPosition( | |
| 89 const int button_x, | |
| 90 int* button_height) const { | |
| 91 TabStrip* tab_strip = browser_view_->tabstrip(); | |
| 92 if (!tab_strip) | |
| 93 return; | |
| 94 | |
| 95 // In RTL the new tab button is on the left, so it can never slide under the | |
| 96 // avatar button (which is still on the right). May as well use the space. | |
| 97 if (base::i18n::IsRTL()) | |
| 98 return; | |
| 99 | |
| 100 // Use the "cozy" button if the tabstrip can slide under it | |
| 101 if (tab_strip->max_x() >= button_x) { | |
| 102 *button_height = kButtonCozyHeight; | |
| 103 } | |
| 104 } | |
| OLD | NEW |