Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: chrome/browser/ui/views/toolbar/app_menu_button.cc

Issue 2858313002: Refactored AppMenuAnimation (Closed)
Patch Set: Add comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "chrome/browser/ui/views/toolbar/app_menu_button.h" 5 #include "chrome/browser/ui/views/toolbar/app_menu_button.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
11 #include "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.h"
12 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "cc/paint/paint_flags.h" 14 #include "cc/paint/paint_flags.h"
15 #include "chrome/app/vector_icons/vector_icons.h" 15 #include "chrome/app/vector_icons/vector_icons.h"
16 #include "chrome/browser/themes/theme_properties.h" 16 #include "chrome/browser/themes/theme_properties.h"
17 #include "chrome/browser/ui/browser.h" 17 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/browser_otr_state.h" 18 #include "chrome/browser/ui/browser_otr_state.h"
19 #include "chrome/browser/ui/layout_constants.h" 19 #include "chrome/browser/ui/layout_constants.h"
20 #include "chrome/browser/ui/tabs/tab_strip_model.h" 20 #include "chrome/browser/ui/tabs/tab_strip_model.h"
21 #include "chrome/browser/ui/toolbar/app_menu_animation.h"
21 #include "chrome/browser/ui/toolbar/app_menu_model.h" 22 #include "chrome/browser/ui/toolbar/app_menu_model.h"
22 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" 23 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h"
23 #include "chrome/browser/ui/views/toolbar/app_menu.h" 24 #include "chrome/browser/ui/views/toolbar/app_menu.h"
24 #include "chrome/browser/ui/views/toolbar/app_menu_animation.h"
25 #include "chrome/browser/ui/views/toolbar/toolbar_button.h" 25 #include "chrome/browser/ui/views/toolbar/toolbar_button.h"
26 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" 26 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
27 #include "chrome/common/chrome_switches.h" 27 #include "chrome/common/chrome_switches.h"
28 #include "chrome/grit/theme_resources.h" 28 #include "chrome/grit/theme_resources.h"
29 #include "ui/base/resource/resource_bundle.h" 29 #include "ui/base/resource/resource_bundle.h"
30 #include "ui/base/theme_provider.h" 30 #include "ui/base/theme_provider.h"
31 #include "ui/gfx/canvas.h"
31 #include "ui/gfx/color_palette.h" 32 #include "ui/gfx/color_palette.h"
32 #include "ui/gfx/paint_vector_icon.h" 33 #include "ui/gfx/paint_vector_icon.h"
33 #include "ui/keyboard/keyboard_controller.h" 34 #include "ui/keyboard/keyboard_controller.h"
34 #include "ui/views/controls/button/label_button_border.h" 35 #include "ui/views/controls/button/label_button_border.h"
35 #include "ui/views/controls/menu/menu_listener.h" 36 #include "ui/views/controls/menu/menu_listener.h"
36 #include "ui/views/metrics.h" 37 #include "ui/views/metrics.h"
37 38
38 namespace { 39 namespace {
39 const float kIconSize = 16; 40
41 constexpr float kIconSize = 16;
42
43 // The radius of each dot in the icon.
44 constexpr float kDotRadius = 2.0f;
msw 2017/05/05 18:47:38 nit: maybe this should be owned by app_menu_animat
spqchan 2017/05/05 21:20:53 Removed the delegate's PaintDot function so this i
45
40 } // namespace 46 } // namespace
41 47
42 // static 48 // static
43 bool AppMenuButton::g_open_app_immediately_for_testing = false; 49 bool AppMenuButton::g_open_app_immediately_for_testing = false;
44 50
45 AppMenuButton::AppMenuButton(ToolbarView* toolbar_view) 51 AppMenuButton::AppMenuButton(ToolbarView* toolbar_view)
46 : views::MenuButton(base::string16(), toolbar_view, false), 52 : views::MenuButton(base::string16(), toolbar_view, false),
47 severity_(AppMenuIconController::Severity::NONE), 53 severity_(AppMenuIconController::Severity::NONE),
48 type_(AppMenuIconController::IconType::NONE), 54 type_(AppMenuIconController::IconType::NONE),
49 toolbar_view_(toolbar_view), 55 toolbar_view_(toolbar_view),
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 animation_->PaintAppMenu(canvas, bounds); 157 animation_->PaintAppMenu(canvas, bounds);
152 } 158 }
153 159
154 void AppMenuButton::TabInsertedAt(TabStripModel* tab_strip_model, 160 void AppMenuButton::TabInsertedAt(TabStripModel* tab_strip_model,
155 content::WebContents* contents, 161 content::WebContents* contents,
156 int index, 162 int index,
157 bool foreground) { 163 bool foreground) {
158 AnimateIconIfPossible(); 164 AnimateIconIfPossible();
159 } 165 }
160 166
167 void AppMenuButton::PaintDot(const gfx::PointF point,
168 SkColor color,
169 gfx::SizeF size,
170 gfx::Canvas* canvas) {
171 cc::PaintFlags flags;
172 flags.setColor(color);
173 flags.setStrokeWidth(size.height());
174 flags.setStrokeCap(cc::PaintFlags::kRound_Cap);
175 flags.setStyle(cc::PaintFlags::kFill_Style);
176 flags.setAntiAlias(true);
msw 2017/05/05 18:47:38 aside: would avoiding anti aliasing avoid the blur
spqchan 2017/05/05 21:20:53 That's a really good point. I tried to remove it a
177 canvas->DrawRoundRect(gfx::RectF(point, size), kDotRadius, flags);
178 }
179
180 void AppMenuButton::AppMenuAnimationStarted() {
181 SetPaintToLayer();
182 layer()->SetFillsBoundsOpaquely(false);
183 }
184
185 void AppMenuButton::AppMenuAnimationEnded() {
186 DestroyLayer();
187 }
188
189 void AppMenuButton::InvalidateIcon() {
190 SchedulePaint();
191 }
192
161 void AppMenuButton::UpdateIcon(bool should_animate) { 193 void AppMenuButton::UpdateIcon(bool should_animate) {
162 SkColor severity_color = gfx::kPlaceholderColor; 194 SkColor severity_color = gfx::kPlaceholderColor;
163 SkColor toolbar_icon_color = 195 SkColor toolbar_icon_color =
164 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON); 196 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON);
165 const ui::NativeTheme* native_theme = GetNativeTheme(); 197 const ui::NativeTheme* native_theme = GetNativeTheme();
166 switch (severity_) { 198 switch (severity_) {
167 case AppMenuIconController::Severity::NONE: 199 case AppMenuIconController::Severity::NONE:
168 severity_color = toolbar_icon_color; 200 severity_color = toolbar_icon_color;
169 break; 201 break;
170 case AppMenuIconController::Severity::LOW: 202 case AppMenuIconController::Severity::LOW:
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 251
220 void AppMenuButton::AnimateIconIfPossible() { 252 void AppMenuButton::AnimateIconIfPossible() {
221 if (!animation_ || !should_use_new_icon_ || 253 if (!animation_ || !should_use_new_icon_ ||
222 severity_ == AppMenuIconController::Severity::NONE) { 254 severity_ == AppMenuIconController::Severity::NONE) {
223 return; 255 return;
224 } 256 }
225 257
226 animation_->StartAnimation(); 258 animation_->StartAnimation();
227 } 259 }
228 260
229 void AppMenuButton::AppMenuAnimationStarted() {
230 SetPaintToLayer();
231 layer()->SetFillsBoundsOpaquely(false);
232 }
233
234 void AppMenuButton::AppMenuAnimationEnded() {
235 DestroyLayer();
236 }
237
238 const char* AppMenuButton::GetClassName() const { 261 const char* AppMenuButton::GetClassName() const {
239 return "AppMenuButton"; 262 return "AppMenuButton";
240 } 263 }
241 264
242 std::unique_ptr<views::LabelButtonBorder> AppMenuButton::CreateDefaultBorder() 265 std::unique_ptr<views::LabelButtonBorder> AppMenuButton::CreateDefaultBorder()
243 const { 266 const {
244 std::unique_ptr<views::LabelButtonBorder> border = 267 std::unique_ptr<views::LabelButtonBorder> border =
245 MenuButton::CreateDefaultBorder(); 268 MenuButton::CreateDefaultBorder();
246 269
247 // Adjust border insets to follow the margin change, 270 // Adjust border insets to follow the margin change,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 return ui::DragDropTypes::DRAG_MOVE; 315 return ui::DragDropTypes::DRAG_MOVE;
293 } 316 }
294 317
295 void AppMenuButton::OnDragExited() { 318 void AppMenuButton::OnDragExited() {
296 weak_factory_.InvalidateWeakPtrs(); 319 weak_factory_.InvalidateWeakPtrs();
297 } 320 }
298 321
299 int AppMenuButton::OnPerformDrop(const ui::DropTargetEvent& event) { 322 int AppMenuButton::OnPerformDrop(const ui::DropTargetEvent& event) {
300 return ui::DragDropTypes::DRAG_MOVE; 323 return ui::DragDropTypes::DRAG_MOVE;
301 } 324 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698