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

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

Issue 1478303003: Converted all Views to use an InkDropDelegate instead of a InkDropAnimationController. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merged with master / https://codereview.chromium.org/1494433003. Created 5 years 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/location.h" 7 #include "base/location.h"
8 #include "base/single_thread_task_runner.h" 8 #include "base/single_thread_task_runner.h"
9 #include "base/thread_task_runner_handle.h" 9 #include "base/thread_task_runner_handle.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "chrome/browser/themes/theme_properties.h" 11 #include "chrome/browser/themes/theme_properties.h"
12 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/layout_constants.h" 13 #include "chrome/browser/ui/layout_constants.h"
14 #include "chrome/browser/ui/toolbar/app_menu_model.h" 14 #include "chrome/browser/ui/toolbar/app_menu_model.h"
15 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" 15 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h"
16 #include "chrome/browser/ui/views/toolbar/app_menu.h" 16 #include "chrome/browser/ui/views/toolbar/app_menu.h"
17 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" 17 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
18 #include "extensions/common/feature_switch.h" 18 #include "extensions/common/feature_switch.h"
19 #include "grit/theme_resources.h" 19 #include "grit/theme_resources.h"
20 #include "ui/base/resource/material_design/material_design_controller.h" 20 #include "ui/base/resource/material_design/material_design_controller.h"
21 #include "ui/base/resource/resource_bundle.h" 21 #include "ui/base/resource/resource_bundle.h"
22 #include "ui/base/theme_provider.h" 22 #include "ui/base/theme_provider.h"
23 #include "ui/gfx/color_palette.h" 23 #include "ui/gfx/color_palette.h"
24 #include "ui/gfx/paint_vector_icon.h" 24 #include "ui/gfx/paint_vector_icon.h"
25 #include "ui/gfx/vector_icons_public.h" 25 #include "ui/gfx/vector_icons_public.h"
26 #include "ui/keyboard/keyboard_controller.h" 26 #include "ui/keyboard/keyboard_controller.h"
27 #include "ui/views/animation/ink_drop_animation_controller.h" 27 #include "ui/views/animation/button_ink_drop_delegate.h"
28 #include "ui/views/animation/ink_drop_animation_controller_factory.h"
29 #include "ui/views/controls/button/label_button_border.h" 28 #include "ui/views/controls/button/label_button_border.h"
30 #include "ui/views/controls/menu/menu_listener.h" 29 #include "ui/views/controls/menu/menu_listener.h"
31 #include "ui/views/metrics.h" 30 #include "ui/views/metrics.h"
32 #include "ui/views/painter.h" 31 #include "ui/views/painter.h"
33 32
34 // static 33 // static
35 bool AppMenuButton::g_open_app_immediately_for_testing = false; 34 bool AppMenuButton::g_open_app_immediately_for_testing = false;
36 35
37 AppMenuButton::AppMenuButton(ToolbarView* toolbar_view) 36 AppMenuButton::AppMenuButton(ToolbarView* toolbar_view)
38 : views::MenuButton(NULL, base::string16(), toolbar_view, false), 37 : views::MenuButton(NULL, base::string16(), toolbar_view, false),
39 severity_(AppMenuIconPainter::SEVERITY_NONE), 38 severity_(AppMenuIconPainter::SEVERITY_NONE),
40 ink_drop_animation_controller_(
41 views::InkDropAnimationControllerFactory::
42 CreateInkDropAnimationController(this)),
43 toolbar_view_(toolbar_view), 39 toolbar_view_(toolbar_view),
44 allow_extension_dragging_( 40 allow_extension_dragging_(
45 extensions::FeatureSwitch::extension_action_redesign() 41 extensions::FeatureSwitch::extension_action_redesign()
46 ->IsEnabled()), 42 ->IsEnabled()),
47 destroyed_(nullptr), 43 destroyed_(nullptr),
48 margin_trailing_(0), 44 margin_trailing_(0),
45 ink_drop_delegate_(new views::ButtonInkDropDelegate(this, this)),
49 weak_factory_(this) { 46 weak_factory_(this) {
47 set_ink_drop_delegate(ink_drop_delegate_.get());
50 if (!ui::MaterialDesignController::IsModeMaterial()) 48 if (!ui::MaterialDesignController::IsModeMaterial())
51 icon_painter_.reset(new AppMenuIconPainter(this)); 49 icon_painter_.reset(new AppMenuIconPainter(this));
52 50
53 const int kInkDropLargeSize = 32; 51 const int kInkDropLargeSize = 32;
54 const int kInkDropLargeCornerRadius = 5; 52 const int kInkDropLargeCornerRadius = 5;
55 const int kInkDropSmallSize = 24; 53 const int kInkDropSmallSize = 24;
56 const int kInkDropSmallCornerRadius = 2; 54 const int kInkDropSmallCornerRadius = 2;
57 55
58 ink_drop_animation_controller_->SetInkDropSize( 56 ink_drop_delegate()->SetInkDropSize(
59 gfx::Size(kInkDropLargeSize, kInkDropLargeSize), 57 kInkDropLargeSize, kInkDropLargeCornerRadius, kInkDropSmallSize,
60 kInkDropLargeCornerRadius,
61 gfx::Size(kInkDropSmallSize, kInkDropSmallSize),
62 kInkDropSmallCornerRadius); 58 kInkDropSmallCornerRadius);
63 } 59 }
64 60
65 AppMenuButton::~AppMenuButton() { 61 AppMenuButton::~AppMenuButton() {
66 if (destroyed_) 62 if (destroyed_)
67 *destroyed_ = true; 63 *destroyed_ = true;
64 set_ink_drop_delegate(nullptr);
65 ink_drop_delegate_.reset();
68 } 66 }
69 67
70 void AppMenuButton::SetSeverity(AppMenuIconPainter::Severity severity, 68 void AppMenuButton::SetSeverity(AppMenuIconPainter::Severity severity,
71 bool animate) { 69 bool animate) {
72 if (ui::MaterialDesignController::IsModeMaterial()) { 70 if (ui::MaterialDesignController::IsModeMaterial()) {
73 severity_ = severity; 71 severity_ = severity;
74 UpdateIcon(); 72 UpdateIcon();
75 return; 73 return;
76 } 74 }
77 75
(...skipping 23 matching lines...) Expand all
101 FOR_EACH_OBSERVER(views::MenuListener, menu_listeners_, OnMenuOpened()); 99 FOR_EACH_OBSERVER(views::MenuListener, menu_listeners_, OnMenuOpened());
102 100
103 // Because running the menu below spins a nested message loop, |this| can be 101 // Because running the menu below spins a nested message loop, |this| can be
104 // deleted by the time RunMenu() returns. To detect this, we set |destroyed_| 102 // deleted by the time RunMenu() returns. To detect this, we set |destroyed_|
105 // (which is normally null) to point to a local. If our destructor runs during 103 // (which is normally null) to point to a local. If our destructor runs during
106 // RunMenu(), then this local will be set to true on return, and we'll know 104 // RunMenu(), then this local will be set to true on return, and we'll know
107 // it's not safe to access any member variables. 105 // it's not safe to access any member variables.
108 bool destroyed = false; 106 bool destroyed = false;
109 destroyed_ = &destroyed; 107 destroyed_ = &destroyed;
110 108
111 ink_drop_animation_controller_->AnimateToState( 109 ink_drop_delegate()->OnAction(views::InkDropState::ACTIVATED);
112 views::InkDropState::ACTIVATED);
113 menu_->RunMenu(this); 110 menu_->RunMenu(this);
114 111
115 if (!destroyed) { 112 if (!destroyed) {
116 ink_drop_animation_controller_->AnimateToState( 113 ink_drop_delegate()->OnAction(views::InkDropState::DEACTIVATED);
117 views::InkDropState::DEACTIVATED);
118 destroyed_ = nullptr; 114 destroyed_ = nullptr;
119 } 115 }
120 } 116 }
121 117
122 void AppMenuButton::CloseMenu() { 118 void AppMenuButton::CloseMenu() {
123 if (menu_) 119 if (menu_)
124 menu_->CloseMenu(); 120 menu_->CloseMenu();
125 menu_.reset(); 121 menu_.reset();
126 } 122 }
127 123
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 views::View::AreDropTypesRequired(); 257 views::View::AreDropTypesRequired();
262 } 258 }
263 259
264 bool AppMenuButton::CanDrop(const ui::OSExchangeData& data) { 260 bool AppMenuButton::CanDrop(const ui::OSExchangeData& data) {
265 return allow_extension_dragging_ ? 261 return allow_extension_dragging_ ?
266 BrowserActionDragData::CanDrop(data, 262 BrowserActionDragData::CanDrop(data,
267 toolbar_view_->browser()->profile()) : 263 toolbar_view_->browser()->profile()) :
268 views::View::CanDrop(data); 264 views::View::CanDrop(data);
269 } 265 }
270 266
271 void AppMenuButton::Layout() {
272 MenuButton::Layout();
273 ink_drop_animation_controller_->SetInkDropCenter(CalculateInkDropCenter());
274 }
275
276 void AppMenuButton::OnDragEntered(const ui::DropTargetEvent& event) { 267 void AppMenuButton::OnDragEntered(const ui::DropTargetEvent& event) {
277 DCHECK(allow_extension_dragging_); 268 DCHECK(allow_extension_dragging_);
278 DCHECK(!weak_factory_.HasWeakPtrs()); 269 DCHECK(!weak_factory_.HasWeakPtrs());
279 if (!g_open_app_immediately_for_testing) { 270 if (!g_open_app_immediately_for_testing) {
280 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 271 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
281 FROM_HERE, 272 FROM_HERE,
282 base::Bind(&AppMenuButton::ShowMenu, weak_factory_.GetWeakPtr(), true), 273 base::Bind(&AppMenuButton::ShowMenu, weak_factory_.GetWeakPtr(), true),
283 base::TimeDelta::FromMilliseconds(views::GetMenuShowDelay())); 274 base::TimeDelta::FromMilliseconds(views::GetMenuShowDelay()));
284 } else { 275 } else {
285 ShowMenu(true); 276 ShowMenu(true);
(...skipping 19 matching lines...) Expand all
305 views::MenuButton::OnPaint(canvas); 296 views::MenuButton::OnPaint(canvas);
306 if (ui::MaterialDesignController::IsModeMaterial()) 297 if (ui::MaterialDesignController::IsModeMaterial())
307 return; 298 return;
308 // Use GetPreferredSize() to center the icon inside the visible bounds rather 299 // Use GetPreferredSize() to center the icon inside the visible bounds rather
309 // than the whole size() (which may refer to hit test region extended to the 300 // than the whole size() (which may refer to hit test region extended to the
310 // end of the toolbar in maximized mode). 301 // end of the toolbar in maximized mode).
311 icon_painter_->Paint(canvas, GetThemeProvider(), 302 icon_painter_->Paint(canvas, GetThemeProvider(),
312 gfx::Rect(GetPreferredSize()), 303 gfx::Rect(GetPreferredSize()),
313 AppMenuIconPainter::BEZEL_NONE); 304 AppMenuIconPainter::BEZEL_NONE);
314 } 305 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698