OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/shelf/overflow_button.h" | 5 #include "ash/common/shelf/overflow_button.h" |
6 | 6 |
7 #include "ash/common/ash_constants.h" | 7 #include "ash/common/ash_constants.h" |
8 #include "ash/common/material_design/material_design_controller.h" | 8 #include "ash/common/material_design/material_design_controller.h" |
9 #include "ash/common/shelf/ink_drop_button_listener.h" | 9 #include "ash/common/shelf/ink_drop_button_listener.h" |
10 #include "ash/common/shelf/shelf_constants.h" | 10 #include "ash/common/shelf/shelf_constants.h" |
11 #include "ash/common/shelf/shelf_view.h" | 11 #include "ash/common/shelf/shelf_view.h" |
12 #include "ash/common/shelf/wm_shelf.h" | 12 #include "ash/common/shelf/wm_shelf.h" |
13 #include "ash/common/shelf/wm_shelf_util.h" | 13 #include "ash/common/shelf/wm_shelf_util.h" |
14 #include "grit/ash_resources.h" | 14 #include "grit/ash_resources.h" |
15 #include "grit/ash_strings.h" | 15 #include "grit/ash_strings.h" |
16 #include "third_party/skia/include/core/SkPaint.h" | 16 #include "third_party/skia/include/core/SkPaint.h" |
17 #include "third_party/skia/include/core/SkPath.h" | 17 #include "third_party/skia/include/core/SkPath.h" |
18 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
19 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
20 #include "ui/gfx/canvas.h" | 20 #include "ui/gfx/canvas.h" |
21 #include "ui/gfx/image/image_skia_operations.h" | 21 #include "ui/gfx/image/image_skia_operations.h" |
22 #include "ui/gfx/paint_vector_icon.h" | 22 #include "ui/gfx/paint_vector_icon.h" |
23 #include "ui/gfx/skbitmap_operations.h" | 23 #include "ui/gfx/skbitmap_operations.h" |
24 #include "ui/gfx/skia_util.h" | 24 #include "ui/gfx/skia_util.h" |
25 #include "ui/gfx/transform.h" | 25 #include "ui/gfx/transform.h" |
26 #include "ui/gfx/vector_icons_public.h" | 26 #include "ui/gfx/vector_icons_public.h" |
| 27 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" |
27 | 28 |
28 namespace ash { | 29 namespace ash { |
29 | 30 |
30 OverflowButton::OverflowButton(ShelfView* shelf_view, WmShelf* wm_shelf) | 31 OverflowButton::OverflowButton(ShelfView* shelf_view, WmShelf* wm_shelf) |
31 : CustomButton(nullptr), | 32 : CustomButton(nullptr), |
32 bottom_image_(nullptr), | 33 bottom_image_(nullptr), |
33 shelf_view_(shelf_view), | 34 shelf_view_(shelf_view), |
34 wm_shelf_(wm_shelf), | 35 wm_shelf_(wm_shelf), |
35 background_alpha_(0) { | 36 background_alpha_(0) { |
36 DCHECK(shelf_view_); | 37 DCHECK(shelf_view_); |
37 if (MaterialDesignController::IsShelfMaterial()) { | 38 if (MaterialDesignController::IsShelfMaterial()) { |
| 39 SetInkDropMode(InkDropMode::ON); |
| 40 set_ink_drop_base_color(kShelfInkDropBaseColor); |
| 41 set_ink_drop_visible_opacity(kShelfInkDropVisibleOpacity); |
| 42 set_hide_ink_drop_when_showing_context_menu(false); |
38 bottom_image_md_ = | 43 bottom_image_md_ = |
39 CreateVectorIcon(gfx::VectorIconId::SHELF_OVERFLOW, kShelfIconColor); | 44 CreateVectorIcon(gfx::VectorIconId::SHELF_OVERFLOW, kShelfIconColor); |
40 bottom_image_ = &bottom_image_md_; | 45 bottom_image_ = &bottom_image_md_; |
41 } else { | 46 } else { |
42 bottom_image_ = ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 47 bottom_image_ = ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
43 IDR_ASH_SHELF_OVERFLOW); | 48 IDR_ASH_SHELF_OVERFLOW); |
44 } | 49 } |
45 | 50 |
46 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); | 51 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); |
47 SetAccessibleName(l10n_util::GetStringUTF16(IDS_ASH_SHELF_OVERFLOW_NAME)); | 52 SetAccessibleName(l10n_util::GetStringUTF16(IDS_ASH_SHELF_OVERFLOW_NAME)); |
48 } | 53 } |
49 | 54 |
50 OverflowButton::~OverflowButton() {} | 55 OverflowButton::~OverflowButton() {} |
51 | 56 |
52 void OverflowButton::OnShelfAlignmentChanged() { | 57 void OverflowButton::OnShelfAlignmentChanged() { |
53 SchedulePaint(); | 58 SchedulePaint(); |
54 } | 59 } |
55 | 60 |
| 61 void OverflowButton::OnOverflowBubbleShown() { |
| 62 AnimateInkDrop(views::InkDropState::ACTIVATED, nullptr); |
| 63 if (!ash::MaterialDesignController::IsShelfMaterial()) |
| 64 SchedulePaint(); |
| 65 } |
| 66 |
| 67 void OverflowButton::OnOverflowBubbleHidden() { |
| 68 AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr); |
| 69 if (!ash::MaterialDesignController::IsShelfMaterial()) |
| 70 SchedulePaint(); |
| 71 } |
| 72 |
56 void OverflowButton::SetBackgroundAlpha(int alpha) { | 73 void OverflowButton::SetBackgroundAlpha(int alpha) { |
57 background_alpha_ = alpha; | 74 background_alpha_ = alpha; |
58 SchedulePaint(); | 75 SchedulePaint(); |
59 } | 76 } |
60 | 77 |
61 void OverflowButton::OnPaint(gfx::Canvas* canvas) { | 78 void OverflowButton::OnPaint(gfx::Canvas* canvas) { |
62 gfx::Rect bounds = CalculateButtonBounds(); | 79 gfx::Rect bounds = CalculateButtonBounds(); |
63 PaintBackground(canvas, bounds); | 80 PaintBackground(canvas, bounds); |
64 PaintForeground(canvas, bounds); | 81 PaintForeground(canvas, bounds); |
65 } | 82 } |
66 | 83 |
| 84 std::unique_ptr<views::InkDropRipple> OverflowButton::CreateInkDropRipple() |
| 85 const { |
| 86 return base::WrapUnique(new views::FloodFillInkDropRipple( |
| 87 CalculateButtonBounds(), GetInkDropCenterBasedOnLastEvent(), |
| 88 GetInkDropBaseColor(), ink_drop_visible_opacity())); |
| 89 } |
| 90 |
| 91 bool OverflowButton::ShouldEnterPushedState(const ui::Event& event) { |
| 92 if (shelf_view_->IsShowingOverflowBubble()) |
| 93 return false; |
| 94 |
| 95 return CustomButton::ShouldEnterPushedState(event); |
| 96 } |
| 97 |
| 98 bool OverflowButton::ShouldShowInkDropHighlight() const { |
| 99 return false; |
| 100 } |
| 101 |
67 void OverflowButton::NotifyClick(const ui::Event& event) { | 102 void OverflowButton::NotifyClick(const ui::Event& event) { |
68 CustomButton::NotifyClick(event); | 103 CustomButton::NotifyClick(event); |
69 shelf_view_->ButtonPressed(this, event, ink_drop()); | 104 shelf_view_->ButtonPressed(this, event, ink_drop()); |
70 } | 105 } |
71 | 106 |
72 void OverflowButton::PaintBackground(gfx::Canvas* canvas, | 107 void OverflowButton::PaintBackground(gfx::Canvas* canvas, |
73 const gfx::Rect& bounds) { | 108 const gfx::Rect& bounds) { |
74 if (MaterialDesignController::IsShelfMaterial()) { | 109 if (MaterialDesignController::IsShelfMaterial()) { |
75 SkPaint background_paint; | 110 SkPaint background_paint; |
76 background_paint.setFlags(SkPaint::kAntiAlias_Flag); | 111 background_paint.setFlags(SkPaint::kAntiAlias_Flag); |
77 background_paint.setColor(SkColorSetA(kShelfBaseColor, background_alpha_)); | 112 background_paint.setColor(SkColorSetA(kShelfBaseColor, background_alpha_)); |
78 canvas->DrawRoundRect(bounds, kOverflowButtonCornerRadius, | 113 canvas->DrawRoundRect(bounds, kOverflowButtonCornerRadius, |
79 background_paint); | 114 background_paint); |
80 | |
81 if (shelf_view_->IsShowingOverflowBubble()) { | |
82 SkPaint highlight_paint; | |
83 highlight_paint.setFlags(SkPaint::kAntiAlias_Flag); | |
84 highlight_paint.setColor(kShelfButtonActivatedHighlightColor); | |
85 canvas->DrawRoundRect(bounds, kOverflowButtonCornerRadius, | |
86 highlight_paint); | |
87 } | |
88 } else { | 115 } else { |
89 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 116 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
90 const gfx::ImageSkia* background = | 117 const gfx::ImageSkia* background = |
91 rb.GetImageNamed(NonMaterialBackgroundImageId()).ToImageSkia(); | 118 rb.GetImageNamed(NonMaterialBackgroundImageId()).ToImageSkia(); |
92 canvas->DrawImageInt(*background, bounds.x(), bounds.y()); | 119 canvas->DrawImageInt(*background, bounds.x(), bounds.y()); |
93 } | 120 } |
94 } | 121 } |
95 | 122 |
96 void OverflowButton::PaintForeground(gfx::Canvas* canvas, | 123 void OverflowButton::PaintForeground(gfx::Canvas* canvas, |
97 const gfx::Rect& bounds) { | 124 const gfx::Rect& bounds) { |
(...skipping 17 matching lines...) Expand all Loading... |
115 default: | 142 default: |
116 image = bottom_image_; | 143 image = bottom_image_; |
117 break; | 144 break; |
118 } | 145 } |
119 | 146 |
120 canvas->DrawImageInt(*image, | 147 canvas->DrawImageInt(*image, |
121 bounds.x() + ((bounds.width() - image->width()) / 2), | 148 bounds.x() + ((bounds.width() - image->width()) / 2), |
122 bounds.y() + ((bounds.height() - image->height()) / 2)); | 149 bounds.y() + ((bounds.height() - image->height()) / 2)); |
123 } | 150 } |
124 | 151 |
125 int OverflowButton::NonMaterialBackgroundImageId() { | 152 int OverflowButton::NonMaterialBackgroundImageId() const { |
126 if (shelf_view_->IsShowingOverflowBubble()) | 153 if (shelf_view_->IsShowingOverflowBubble()) |
127 return IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED; | 154 return IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED; |
128 else if (wm_shelf_->IsDimmed()) | 155 else if (wm_shelf_->IsDimmed()) |
129 return IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK; | 156 return IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK; |
130 return IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL; | 157 return IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL; |
131 } | 158 } |
132 | 159 |
133 gfx::Rect OverflowButton::CalculateButtonBounds() { | 160 gfx::Rect OverflowButton::CalculateButtonBounds() const { |
134 ShelfAlignment alignment = wm_shelf_->GetAlignment(); | 161 ShelfAlignment alignment = wm_shelf_->GetAlignment(); |
135 gfx::Rect bounds(GetContentsBounds()); | 162 gfx::Rect bounds(GetContentsBounds()); |
136 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 163 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
137 if (MaterialDesignController::IsShelfMaterial()) { | 164 if (MaterialDesignController::IsShelfMaterial()) { |
138 const int width_offset = (bounds.width() - kOverflowButtonSize) / 2; | 165 const int width_offset = (bounds.width() - kOverflowButtonSize) / 2; |
139 const int height_offset = (bounds.height() - kOverflowButtonSize) / 2; | 166 const int height_offset = (bounds.height() - kOverflowButtonSize) / 2; |
140 if (IsHorizontalAlignment(alignment)) { | 167 if (IsHorizontalAlignment(alignment)) { |
141 bounds = gfx::Rect(bounds.x() + width_offset, bounds.y() + height_offset, | 168 bounds = gfx::Rect(bounds.x() + width_offset, bounds.y() + height_offset, |
142 kOverflowButtonSize, kOverflowButtonSize); | 169 kOverflowButtonSize, kOverflowButtonSize); |
143 } else { | 170 } else { |
(...skipping 17 matching lines...) Expand all Loading... |
161 bounds = | 188 bounds = |
162 gfx::Rect(bounds.x() + (bounds.width() - background->width()) / 2, | 189 gfx::Rect(bounds.x() + (bounds.width() - background->width()) / 2, |
163 bounds.y() + kShelfItemInset, background->width(), | 190 bounds.y() + kShelfItemInset, background->width(), |
164 background->height()); | 191 background->height()); |
165 } | 192 } |
166 } | 193 } |
167 return bounds; | 194 return bounds; |
168 } | 195 } |
169 | 196 |
170 } // namespace ash | 197 } // namespace ash |
OLD | NEW |