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

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

Issue 1798523003: Moved AppMenu ACTIVATED/DEACTIVATED ink drop handling in to MenuButton. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2661
Patch Set: Created 4 years, 9 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/location.h" 7 #include "base/location.h"
8 #include "base/metrics/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
(...skipping 22 matching lines...) Expand all
33 33
34 // static 34 // static
35 bool AppMenuButton::g_open_app_immediately_for_testing = false; 35 bool AppMenuButton::g_open_app_immediately_for_testing = false;
36 36
37 AppMenuButton::AppMenuButton(ToolbarView* toolbar_view) 37 AppMenuButton::AppMenuButton(ToolbarView* toolbar_view)
38 : views::MenuButton(base::string16(), toolbar_view, false), 38 : views::MenuButton(base::string16(), toolbar_view, false),
39 severity_(AppMenuIconPainter::SEVERITY_NONE), 39 severity_(AppMenuIconPainter::SEVERITY_NONE),
40 toolbar_view_(toolbar_view), 40 toolbar_view_(toolbar_view),
41 allow_extension_dragging_( 41 allow_extension_dragging_(
42 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()), 42 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()),
43 destroyed_(nullptr),
44 margin_trailing_(0), 43 margin_trailing_(0),
45 ink_drop_delegate_(new views::ButtonInkDropDelegate(this, this)), 44 ink_drop_delegate_(new views::ButtonInkDropDelegate(this, this)),
46 weak_factory_(this) { 45 weak_factory_(this) {
47 set_ink_drop_delegate(ink_drop_delegate_.get()); 46 set_ink_drop_delegate(ink_drop_delegate_.get());
48 if (!ui::MaterialDesignController::IsModeMaterial()) 47 if (!ui::MaterialDesignController::IsModeMaterial())
49 icon_painter_.reset(new AppMenuIconPainter(this)); 48 icon_painter_.reset(new AppMenuIconPainter(this));
50 } 49 }
51 50
52 AppMenuButton::~AppMenuButton() { 51 AppMenuButton::~AppMenuButton() {}
53 if (destroyed_)
54 *destroyed_ = true;
55 }
56 52
57 void AppMenuButton::SetSeverity(AppMenuIconPainter::Severity severity, 53 void AppMenuButton::SetSeverity(AppMenuIconPainter::Severity severity,
58 bool animate) { 54 bool animate) {
59 if (ui::MaterialDesignController::IsModeMaterial()) { 55 if (ui::MaterialDesignController::IsModeMaterial()) {
60 severity_ = severity; 56 severity_ = severity;
61 UpdateIcon(); 57 UpdateIcon();
62 return; 58 return;
63 } 59 }
64 60
65 icon_painter_->SetSeverity(severity, animate); 61 icon_painter_->SetSeverity(severity, animate);
(...skipping 14 matching lines...) Expand all
80 #endif 76 #endif
81 77
82 Browser* browser = toolbar_view_->browser(); 78 Browser* browser = toolbar_view_->browser();
83 79
84 menu_.reset(new AppMenu(browser, for_drop ? AppMenu::FOR_DROP : 0)); 80 menu_.reset(new AppMenu(browser, for_drop ? AppMenu::FOR_DROP : 0));
85 menu_model_.reset(new AppMenuModel(toolbar_view_, browser)); 81 menu_model_.reset(new AppMenuModel(toolbar_view_, browser));
86 menu_->Init(menu_model_.get()); 82 menu_->Init(menu_model_.get());
87 83
88 FOR_EACH_OBSERVER(views::MenuListener, menu_listeners_, OnMenuOpened()); 84 FOR_EACH_OBSERVER(views::MenuListener, menu_listeners_, OnMenuOpened());
89 85
90 // Because running the menu below spins a nested message loop, |this| can be
91 // deleted by the time RunMenu() returns. To detect this, we set |destroyed_|
92 // (which is normally null) to point to a local. If our destructor runs during
93 // RunMenu(), then this local will be set to true on return, and we'll know
94 // it's not safe to access any member variables.
95 bool destroyed = false;
96 destroyed_ = &destroyed;
97
98 ink_drop_delegate()->OnAction(views::InkDropState::ACTIVATED);
99
100 base::TimeTicks menu_open_time = base::TimeTicks::Now(); 86 base::TimeTicks menu_open_time = base::TimeTicks::Now();
101 menu_->RunMenu(this); 87 menu_->RunMenu(this);
102 88
103 if (!for_drop) { 89 if (!for_drop) {
104 // Record the time-to-action for the menu. We don't record in the case of a 90 // Record the time-to-action for the menu. We don't record in the case of a
105 // drag-and-drop command because menus opened for drag-and-drop don't block 91 // drag-and-drop command because menus opened for drag-and-drop don't block
106 // the message loop. 92 // the message loop.
107 UMA_HISTOGRAM_TIMES("Toolbar.AppMenuTimeToAction", 93 UMA_HISTOGRAM_TIMES("Toolbar.AppMenuTimeToAction",
108 base::TimeTicks::Now() - menu_open_time); 94 base::TimeTicks::Now() - menu_open_time);
109 } 95 }
110
111 if (!destroyed) {
112 ink_drop_delegate()->OnAction(views::InkDropState::DEACTIVATED);
113 destroyed_ = nullptr;
114 }
115 } 96 }
116 97
117 void AppMenuButton::CloseMenu() { 98 void AppMenuButton::CloseMenu() {
118 if (menu_) 99 if (menu_)
119 menu_->CloseMenu(); 100 menu_->CloseMenu();
120 menu_.reset(); 101 menu_.reset();
121 } 102 }
122 103
123 bool AppMenuButton::IsMenuShowing() const { 104 bool AppMenuButton::IsMenuShowing() const {
124 return menu_ && menu_->IsShowing(); 105 return menu_ && menu_->IsShowing();
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 views::MenuButton::OnPaint(canvas); 258 views::MenuButton::OnPaint(canvas);
278 if (ui::MaterialDesignController::IsModeMaterial()) 259 if (ui::MaterialDesignController::IsModeMaterial())
279 return; 260 return;
280 // Use GetPreferredSize() to center the icon inside the visible bounds rather 261 // Use GetPreferredSize() to center the icon inside the visible bounds rather
281 // than the whole size() (which may refer to hit test region extended to the 262 // than the whole size() (which may refer to hit test region extended to the
282 // end of the toolbar in maximized mode). 263 // end of the toolbar in maximized mode).
283 icon_painter_->Paint(canvas, GetThemeProvider(), 264 icon_painter_->Paint(canvas, GetThemeProvider(),
284 gfx::Rect(GetPreferredSize()), 265 gfx::Rect(GetPreferredSize()),
285 AppMenuIconPainter::BEZEL_NONE); 266 AppMenuIconPainter::BEZEL_NONE);
286 } 267 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/toolbar/app_menu_button.h ('k') | chrome/browser/ui/views/toolbar/toolbar_action_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698