OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/common/system/tray/system_menu_button.h" | 5 #include "ash/common/system/tray/system_menu_button.h" |
6 | 6 |
7 #include "ash/common/ash_constants.h" | 7 #include "ash/common/ash_constants.h" |
8 #include "ash/common/system/tray/system_tray.h" | 8 #include "ash/common/system/tray/system_tray.h" |
9 #include "ash/common/system/tray/tray_constants.h" | 9 #include "ash/common/system/tray/tray_constants.h" |
10 #include "ui/base/l10n/l10n_util.h" | 10 #include "ui/base/l10n/l10n_util.h" |
11 #include "ui/gfx/paint_vector_icon.h" | 11 #include "ui/gfx/paint_vector_icon.h" |
12 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" | 12 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" |
13 #include "ui/views/animation/ink_drop_highlight.h" | 13 #include "ui/views/animation/ink_drop_highlight.h" |
14 #include "ui/views/animation/square_ink_drop_ripple.h" | |
14 #include "ui/views/border.h" | 15 #include "ui/views/border.h" |
15 #include "ui/views/painter.h" | 16 #include "ui/views/painter.h" |
16 | 17 |
17 namespace ash { | 18 namespace ash { |
18 | 19 |
19 SystemMenuButton::SystemMenuButton(views::ButtonListener* listener, | 20 SystemMenuButton::SystemMenuButton(views::ButtonListener* listener, |
21 InkDropStyle ink_drop_style, | |
20 const gfx::VectorIcon& icon, | 22 const gfx::VectorIcon& icon, |
21 int accessible_name_id) | 23 int accessible_name_id) |
22 : views::ImageButton(listener) { | 24 : views::ImageButton(listener), ink_drop_style_(ink_drop_style) { |
23 gfx::ImageSkia image = gfx::CreateVectorIcon(icon, kMenuIconColor); | 25 gfx::ImageSkia image = gfx::CreateVectorIcon(icon, kMenuIconColor); |
24 SetImage(views::Button::STATE_NORMAL, &image); | 26 SetImage(views::Button::STATE_NORMAL, &image); |
25 gfx::ImageSkia disabled_image = | 27 gfx::ImageSkia disabled_image = |
26 gfx::CreateVectorIcon(icon, kMenuIconColorDisabled); | 28 gfx::CreateVectorIcon(icon, kMenuIconColorDisabled); |
27 SetImage(views::Button::STATE_DISABLED, &disabled_image); | 29 SetImage(views::Button::STATE_DISABLED, &disabled_image); |
28 | 30 |
29 const int horizontal_padding = (kMenuButtonSize - image.width()) / 2; | 31 const int horizontal_padding = (kMenuButtonSize - image.width()) / 2; |
30 const int vertical_padding = (kMenuButtonSize - image.height()) / 2; | 32 const int vertical_padding = (kMenuButtonSize - image.height()) / 2; |
31 SetBorder( | 33 SetBorder( |
32 views::Border::CreateEmptyBorder(vertical_padding, horizontal_padding, | 34 views::Border::CreateEmptyBorder(vertical_padding, horizontal_padding, |
33 vertical_padding, horizontal_padding)); | 35 vertical_padding, horizontal_padding)); |
34 | 36 |
35 SetTooltipText(l10n_util::GetStringUTF16(accessible_name_id)); | 37 SetTooltipText(l10n_util::GetStringUTF16(accessible_name_id)); |
36 | 38 |
37 // TODO(tdanderson): Update the focus rect color, border thickness, and | 39 // TODO(tdanderson): Update the focus rect color, border thickness, and |
38 // location for material design. | 40 // location for material design. |
39 SetFocusForPlatform(); | 41 SetFocusForPlatform(); |
40 SetFocusPainter(views::Painter::CreateSolidFocusPainter( | 42 SetFocusPainter(views::Painter::CreateSolidFocusPainter( |
41 kFocusBorderColor, gfx::Insets(1, 1, 1, 1))); | 43 kFocusBorderColor, gfx::Insets(1, 1, 1, 1))); |
42 | 44 |
43 SetInkDropMode(InkDropMode::ON_NO_GESTURE_HANDLER); | 45 SetInkDropMode(InkDropMode::ON); |
44 set_has_ink_drop_action_on_click(true); | 46 set_has_ink_drop_action_on_click(true); |
45 set_ink_drop_base_color(SK_ColorBLACK); | 47 set_ink_drop_base_color(kTrayPopupInkDropBaseColor); |
48 set_ink_drop_visible_opacity(kTrayPopupInkDropRippleOpacity); | |
46 } | 49 } |
47 | 50 |
48 SystemMenuButton::~SystemMenuButton() {} | 51 SystemMenuButton::~SystemMenuButton() {} |
49 | 52 |
50 std::unique_ptr<views::InkDropRipple> SystemMenuButton::CreateInkDropRipple() | 53 std::unique_ptr<views::InkDropRipple> SystemMenuButton::CreateInkDropRipple() |
51 const { | 54 const { |
52 return base::MakeUnique<views::FloodFillInkDropRipple>( | 55 const gfx::Size size = GetInkDropSize(); |
53 GetLocalBounds(), GetInkDropCenterBasedOnLastEvent(), | 56 switch (ink_drop_style_) { |
54 GetInkDropBaseColor(), ink_drop_visible_opacity()); | 57 case InkDropStyle::SQUARE: |
58 return base::MakeUnique<views::SquareInkDropRipple>( | |
59 size, size.width() / 2, size, size.width() / 2, | |
60 GetInkDropCenterBasedOnLastEvent(), GetLocalBounds().CenterPoint(), | |
61 GetInkDropBaseColor(), ink_drop_visible_opacity()); | |
62 case InkDropStyle::FLOOD_FILL: | |
63 gfx::Rect bounds = GetLocalBounds(); | |
64 bounds.Inset(kTrayPopupInkDropInset, kTrayPopupInkDropInset); | |
65 return base::MakeUnique<views::FloodFillInkDropRipple>( | |
66 bounds, GetInkDropCenterBasedOnLastEvent(), GetInkDropBaseColor(), | |
67 ink_drop_visible_opacity()); | |
68 } | |
69 // Required for some compilers. | |
70 NOTREACHED(); | |
71 return nullptr; | |
55 } | 72 } |
56 | 73 |
57 std::unique_ptr<views::InkDropHighlight> | 74 std::unique_ptr<views::InkDropHighlight> |
58 SystemMenuButton::CreateInkDropHighlight() const { | 75 SystemMenuButton::CreateInkDropHighlight() const { |
59 return nullptr; | 76 // TODO(bruthig): Show the highlight when the ink drop is active. (See |
77 // crbug.com/649734) | |
78 if (!ShouldShowInkDropHighlight()) | |
79 return nullptr; | |
80 | |
81 int highlight_radius = 0; | |
82 switch (ink_drop_style_) { | |
tdanderson
2016/10/27 21:21:40
optional: Consider replacing 81-89 with just:
int
bruthig
2016/10/27 21:34:30
You're right ;) I prefer switch cases when enumera
| |
83 case InkDropStyle::SQUARE: | |
84 highlight_radius = GetInkDropSize().width() / 2; | |
85 break; | |
86 case InkDropStyle::FLOOD_FILL: | |
87 highlight_radius = 0; | |
88 break; | |
89 } | |
90 | |
91 std::unique_ptr<views::InkDropHighlight> highlight( | |
92 new views::InkDropHighlight(GetInkDropSize(), highlight_radius, | |
93 gfx::RectF(GetLocalBounds()).CenterPoint(), | |
94 GetInkDropBaseColor())); | |
95 highlight->set_visible_opacity(kTrayPopupInkDropHighlightOpacity); | |
96 return highlight; | |
60 } | 97 } |
61 | 98 |
62 bool SystemMenuButton::ShouldShowInkDropForFocus() const { | 99 bool SystemMenuButton::ShouldShowInkDropHighlight() const { |
63 return false; | 100 return false; |
64 } | 101 } |
65 | 102 |
103 gfx::Size SystemMenuButton::GetInkDropSize() const { | |
104 gfx::Rect bounds = GetLocalBounds(); | |
105 bounds.Inset(kTrayPopupInkDropInset, kTrayPopupInkDropInset); | |
106 return bounds.size(); | |
107 } | |
108 | |
66 } // namespace ash | 109 } // namespace ash |
OLD | NEW |