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

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

Issue 1550443002: Pushed InkDropHost inheritence up to CustomButton. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed whitespace in toolbar_action_view.h Created 4 years, 11 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/toolbar_action_view.h" 5 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 delegate_->OnMouseEnteredToolbarActionView(); 117 delegate_->OnMouseEnteredToolbarActionView();
118 views::MenuButton::OnMouseEntered(event); 118 views::MenuButton::OnMouseEntered(event);
119 } 119 }
120 120
121 bool ToolbarActionView::ShouldEnterPushedState(const ui::Event& event) { 121 bool ToolbarActionView::ShouldEnterPushedState(const ui::Event& event) {
122 return views::MenuButton::ShouldEnterPushedState(event) && 122 return views::MenuButton::ShouldEnterPushedState(event) &&
123 (base::TimeTicks::Now() - popup_closed_time_).InMilliseconds() > 123 (base::TimeTicks::Now() - popup_closed_time_).InMilliseconds() >
124 views::kMinimumMsBetweenButtonClicks; 124 views::kMinimumMsBetweenButtonClicks;
125 } 125 }
126 126
127 void ToolbarActionView::AddInkDropLayer(ui::Layer* ink_drop_layer) {
128 image()->SetPaintToLayer(true);
129 image()->SetFillsBoundsOpaquely(false);
130 views::MenuButton::AddInkDropLayer(ink_drop_layer);
131 }
132
133 void ToolbarActionView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) {
134 views::MenuButton::RemoveInkDropLayer(ink_drop_layer);
135 image()->SetFillsBoundsOpaquely(true);
136 image()->SetPaintToLayer(false);
137 }
138
127 content::WebContents* ToolbarActionView::GetCurrentWebContents() const { 139 content::WebContents* ToolbarActionView::GetCurrentWebContents() const {
128 return delegate_->GetCurrentWebContents(); 140 return delegate_->GetCurrentWebContents();
129 } 141 }
130 142
131 void ToolbarActionView::UpdateState() { 143 void ToolbarActionView::UpdateState() {
132 content::WebContents* web_contents = GetCurrentWebContents(); 144 content::WebContents* web_contents = GetCurrentWebContents();
133 if (SessionTabHelper::IdForTab(web_contents) < 0) 145 if (SessionTabHelper::IdForTab(web_contents) < 0)
134 return; 146 return;
135 147
136 if (!view_controller_->IsEnabled(web_contents) && 148 if (!view_controller_->IsEnabled(web_contents) &&
(...skipping 29 matching lines...) Expand all
166 // We should only get a button pressed event with a non-enabled action if 178 // We should only get a button pressed event with a non-enabled action if
167 // the left-click behavior should open the menu. 179 // the left-click behavior should open the menu.
168 DCHECK(view_controller_->DisabledClickOpensMenu()); 180 DCHECK(view_controller_->DisabledClickOpensMenu());
169 context_menu_controller()->ShowContextMenuForView(this, point, 181 context_menu_controller()->ShowContextMenuForView(this, point,
170 ui::MENU_SOURCE_NONE); 182 ui::MENU_SOURCE_NONE);
171 } else { 183 } else {
172 view_controller_->ExecuteAction(true); 184 view_controller_->ExecuteAction(true);
173 } 185 }
174 } 186 }
175 187
176 void ToolbarActionView::AddInkDropLayer(ui::Layer* ink_drop_layer) {
177 SetPaintToLayer(true);
178 SetFillsBoundsOpaquely(false);
179 image()->SetPaintToLayer(true);
180 image()->SetFillsBoundsOpaquely(false);
181
182 layer()->Add(ink_drop_layer);
183 layer()->StackAtBottom(ink_drop_layer);
184 }
185
186 void ToolbarActionView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) {
187 layer()->Remove(ink_drop_layer);
188
189 image()->SetFillsBoundsOpaquely(true);
190 image()->SetPaintToLayer(false);
191 SetPaintToLayer(false);
192 }
193
194 gfx::ImageSkia ToolbarActionView::GetIconForTest() { 188 gfx::ImageSkia ToolbarActionView::GetIconForTest() {
195 return GetImage(views::Button::STATE_NORMAL); 189 return GetImage(views::Button::STATE_NORMAL);
196 } 190 }
197 191
198 void ToolbarActionView::set_context_menu_callback_for_testing( 192 void ToolbarActionView::set_context_menu_callback_for_testing(
199 base::Callback<void(ToolbarActionView*)>* callback) { 193 base::Callback<void(ToolbarActionView*)>* callback) {
200 context_menu_callback = callback; 194 context_menu_callback = callback;
201 } 195 }
202 196
203 gfx::Size ToolbarActionView::GetPreferredSize() const { 197 gfx::Size ToolbarActionView::GetPreferredSize() const {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 weak_factory_.GetWeakPtr(), 289 weak_factory_.GetWeakPtr(),
296 source_type); 290 source_type);
297 } 291 }
298 if (CloseActiveMenuIfNeeded()) 292 if (CloseActiveMenuIfNeeded())
299 return; 293 return;
300 294
301 // Otherwise, no other menu is showing, and we can proceed normally. 295 // Otherwise, no other menu is showing, and we can proceed normally.
302 DoShowContextMenu(source_type); 296 DoShowContextMenu(source_type);
303 } 297 }
304 298
305 gfx::Point ToolbarActionView::CalculateInkDropCenter() const {
306 return GetLocalBounds().CenterPoint();
307 }
308
309 void ToolbarActionView::DoShowContextMenu( 299 void ToolbarActionView::DoShowContextMenu(
310 ui::MenuSourceType source_type) { 300 ui::MenuSourceType source_type) {
311 ui::MenuModel* context_menu_model = view_controller_->GetContextMenu(); 301 ui::MenuModel* context_menu_model = view_controller_->GetContextMenu();
312 // It's possible the action doesn't have a context menu. 302 // It's possible the action doesn't have a context menu.
313 if (!context_menu_model) 303 if (!context_menu_model)
314 return; 304 return;
315 305
316 DCHECK(visible()); // We should never show a context menu for a hidden item. 306 DCHECK(visible()); // We should never show a context menu for a hidden item.
317 DCHECK(!context_menu_owner); 307 DCHECK(!context_menu_owner);
318 308
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 if (menu_controller->in_nested_run()) { 361 if (menu_controller->in_nested_run()) {
372 // There is another menu showing. Close the outermost menu (since we are 362 // There is another menu showing. Close the outermost menu (since we are
373 // shown in the same menu, we don't want to close the whole thing). 363 // shown in the same menu, we don't want to close the whole thing).
374 menu_controller->Cancel(views::MenuController::EXIT_OUTERMOST); 364 menu_controller->Cancel(views::MenuController::EXIT_OUTERMOST);
375 return true; 365 return true;
376 } 366 }
377 } 367 }
378 368
379 return false; 369 return false;
380 } 370 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698