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; | |
|
Evan Stade
2017/05/03 16:39:36
nit: unnamed namespace for these constants
emx
2017/05/03 17:10:59
Done.
| |
| 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 = SkColorSetA(SK_ColorBLACK, 0.54 * 0xFF); | |
| 22 // Opacity of the ink drop on hover | |
| 23 const float kInkDropHighlightOpacity = 0.08f; | |
| 24 // Opacity of the ink drop on click, which is added to kInkDropHighlightOpacity | |
| 25 const float kInkDropRippleOpacity = 0.04f; | |
| 26 | |
| 27 Win10NativeAvatarButton::Win10NativeAvatarButton( | |
| 28 views::MenuButtonListener* listener, | |
| 29 Profile* profile) | |
| 30 : AvatarButton(listener, profile) { | |
| 31 set_generic_avatar(gfx::CreateVectorIcon( | |
| 32 kAccountCircleIcon, kButtonIconHeight, kButtonIconColor)); | |
| 33 SetBorder(CreateBorder()); | |
| 34 | |
| 35 Update(); | |
| 36 SchedulePaint(); | |
| 37 | |
| 38 SetInkDropMode(InkDropMode::ON); | |
| 39 set_has_ink_drop_action_on_click(true); | |
| 40 SetFocusPainter(nullptr); | |
| 41 set_ink_drop_base_color(SK_ColorBLACK); | |
| 42 set_ink_drop_visible_opacity(kInkDropRippleOpacity); | |
| 43 } | |
| 44 | |
| 45 Win10NativeAvatarButton::~Win10NativeAvatarButton() {} | |
| 46 | |
| 47 gfx::Size Win10NativeAvatarButton::GetMinimumSize() const { | |
| 48 // Returns the "cozy" size of the button. Called by | |
| 49 // GlassBrowserFrameView::LayoutProfileSwitcher() when it calculates that the | |
| 50 // button needs to slide over the tabstrip. | |
| 51 return gfx::Size(kButtonMinWidth, kButtonCozyHeight); | |
| 52 } | |
| 53 | |
| 54 gfx::Size Win10NativeAvatarButton::GetPreferredSize() const { | |
| 55 // Returns the "tall" (normal) size of the button. Its height should match | |
| 56 // the caption button height. | |
| 57 gfx::Size size = views::MenuButton::GetPreferredSize(); | |
| 58 size.set_width( | |
| 59 std::min(std::max(size.width(), kButtonMinWidth), kButtonMaxWidth)); | |
| 60 // TODO(emx): get the proper height here - see http://crrev/2833363002 | |
| 61 size.set_height(30); | |
| 62 return size; | |
| 63 } | |
| 64 | |
| 65 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.
| |
| 66 // These insets look OK at 100%, 125%, 150%, 175% and 200% scaling. | |
| 67 const int kLeftRightInset = 8; | |
| 68 const int kTopInset = 1; | |
| 69 const int kBottomInset = 3; | |
| 70 return views::CreateEmptyBorder(kTopInset, kLeftRightInset, kBottomInset, | |
| 71 kLeftRightInset); | |
| 72 } | |
| 73 | |
| 74 bool Win10NativeAvatarButton::UseFloodFillInkDrop() const { | |
| 75 return true; | |
| 76 } | |
| 77 | |
| 78 std::unique_ptr<views::InkDropHighlight> | |
| 79 Win10NativeAvatarButton::CreateInkDropHighlight() const { | |
| 80 auto center = gfx::RectF(GetLocalBounds()).CenterPoint(); | |
| 81 auto ink_drop_highlight = base::MakeUnique<views::InkDropHighlight>( | |
| 82 size(), 0, center, GetInkDropBaseColor()); | |
| 83 ink_drop_highlight->set_visible_opacity(kInkDropHighlightOpacity); | |
| 84 return ink_drop_highlight; | |
| 85 } | |
| OLD | NEW |