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

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

Issue 2259353002: Update Flaky ToolbarActionViewInteractiveUITests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits Created 4 years, 3 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 "base/bind.h" 10 #include "base/bind.h"
(...skipping 25 matching lines...) Expand all
36 36
37 using views::LabelButtonBorder; 37 using views::LabelButtonBorder;
38 38
39 namespace { 39 namespace {
40 40
41 // Toolbar action buttons have no insets because the badges are drawn right at 41 // Toolbar action buttons have no insets because the badges are drawn right at
42 // the edge of the view's area. Other badding (such as centering the icon) is 42 // the edge of the view's area. Other badding (such as centering the icon) is
43 // handled directly by the Image. 43 // handled directly by the Image.
44 const int kBorderInset = 0; 44 const int kBorderInset = 0;
45 45
46 // The callback to call directly before showing the context menu.
47 ToolbarActionView::ContextMenuCallback* context_menu_callback_for_test =
48 nullptr;
49
50 } // namespace 46 } // namespace
51 47
52 //////////////////////////////////////////////////////////////////////////////// 48 ////////////////////////////////////////////////////////////////////////////////
53 // ToolbarActionView 49 // ToolbarActionView
54 50
55 ToolbarActionView::ToolbarActionView( 51 ToolbarActionView::ToolbarActionView(
56 ToolbarActionViewController* view_controller, 52 ToolbarActionViewController* view_controller,
57 ToolbarActionView::Delegate* delegate) 53 ToolbarActionView::Delegate* delegate)
58 : MenuButton(base::string16(), this, false), 54 : MenuButton(base::string16(), this, false),
59 view_controller_(view_controller), 55 view_controller_(view_controller),
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 // We should only get a button pressed event with a non-enabled action if 156 // We should only get a button pressed event with a non-enabled action if
161 // the left-click behavior should open the menu. 157 // the left-click behavior should open the menu.
162 DCHECK(view_controller_->DisabledClickOpensMenu()); 158 DCHECK(view_controller_->DisabledClickOpensMenu());
163 context_menu_controller()->ShowContextMenuForView(this, point, 159 context_menu_controller()->ShowContextMenuForView(this, point,
164 ui::MENU_SOURCE_NONE); 160 ui::MENU_SOURCE_NONE);
165 } else { 161 } else {
166 view_controller_->ExecuteAction(true); 162 view_controller_->ExecuteAction(true);
167 } 163 }
168 } 164 }
169 165
166 bool ToolbarActionView::IsMenuRunningForTesting() const {
167 return IsMenuRunning();
168 }
169
170 void ToolbarActionView::OnMenuClosed() { 170 void ToolbarActionView::OnMenuClosed() {
171 menu_runner_.reset(); 171 menu_runner_.reset();
172 menu_ = nullptr; 172 menu_ = nullptr;
173 view_controller_->OnContextMenuClosed(); 173 view_controller_->OnContextMenuClosed();
174 menu_adapter_.reset(); 174 menu_adapter_.reset();
175 } 175 }
176 176
177 gfx::ImageSkia ToolbarActionView::GetIconForTest() { 177 gfx::ImageSkia ToolbarActionView::GetIconForTest() {
178 return GetImage(views::Button::STATE_NORMAL); 178 return GetImage(views::Button::STATE_NORMAL);
179 } 179 }
180 180
181 void ToolbarActionView::set_context_menu_callback_for_testing(
182 base::Callback<void(ToolbarActionView*)>* callback) {
183 context_menu_callback_for_test = callback;
184 }
185
186 gfx::Size ToolbarActionView::GetPreferredSize() const { 181 gfx::Size ToolbarActionView::GetPreferredSize() const {
187 return gfx::Size(ToolbarActionsBar::IconWidth(false), 182 return gfx::Size(ToolbarActionsBar::IconWidth(false),
188 ToolbarActionsBar::IconHeight()); 183 ToolbarActionsBar::IconHeight());
189 } 184 }
190 185
191 bool ToolbarActionView::OnMousePressed(const ui::MouseEvent& event) { 186 bool ToolbarActionView::OnMousePressed(const ui::MouseEvent& event) {
192 // views::MenuButton actions are only triggered by left mouse clicks. 187 // views::MenuButton actions are only triggered by left mouse clicks.
193 if (event.IsOnlyLeftMouseButton() && !pressed_lock_) { 188 if (event.IsOnlyLeftMouseButton() && !pressed_lock_) {
194 // TODO(bruthig): The ACTION_PENDING triggering logic should be in 189 // TODO(bruthig): The ACTION_PENDING triggering logic should be in
195 // MenuButton::OnPressed() however there is a bug with the pressed state 190 // MenuButton::OnPressed() however there is a bug with the pressed state
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 290
296 // Unretained() is safe here as ToolbarActionView will always outlive the 291 // Unretained() is safe here as ToolbarActionView will always outlive the
297 // menu. Any action that would lead to the deletion of |this| first triggers 292 // menu. Any action that would lead to the deletion of |this| first triggers
298 // the closing of the menu through lost capture. 293 // the closing of the menu through lost capture.
299 menu_adapter_.reset(new views::MenuModelAdapter( 294 menu_adapter_.reset(new views::MenuModelAdapter(
300 context_menu_model, 295 context_menu_model,
301 base::Bind(&ToolbarActionView::OnMenuClosed, base::Unretained(this)))); 296 base::Bind(&ToolbarActionView::OnMenuClosed, base::Unretained(this))));
302 menu_ = menu_adapter_->CreateMenu(); 297 menu_ = menu_adapter_->CreateMenu();
303 menu_runner_.reset(new views::MenuRunner(menu_, run_types)); 298 menu_runner_.reset(new views::MenuRunner(menu_, run_types));
304 299
305 if (context_menu_callback_for_test)
306 context_menu_callback_for_test->Run(this);
307 ignore_result( 300 ignore_result(
308 menu_runner_->RunMenuAt(parent, this, gfx::Rect(screen_loc, size()), 301 menu_runner_->RunMenuAt(parent, this, gfx::Rect(screen_loc, size()),
309 views::MENU_ANCHOR_TOPLEFT, source_type)); 302 views::MENU_ANCHOR_TOPLEFT, source_type));
310 } 303 }
311 304
312 bool ToolbarActionView::CloseActiveMenuIfNeeded() { 305 bool ToolbarActionView::CloseActiveMenuIfNeeded() {
313 // If this view is shown inside another menu, there's a possibility that there 306 // If this view is shown inside another menu, there's a possibility that there
314 // is another context menu showing that we have to close before we can 307 // is another context menu showing that we have to close before we can
315 // activate a different menu. 308 // activate a different menu.
316 if (delegate_->ShownInsideMenu()) { 309 if (delegate_->ShownInsideMenu()) {
317 views::MenuController* menu_controller = 310 views::MenuController* menu_controller =
318 views::MenuController::GetActiveInstance(); 311 views::MenuController::GetActiveInstance();
319 // If this is shown inside a menu, then there should always be an active 312 // If this is shown inside a menu, then there should always be an active
320 // menu controller. 313 // menu controller.
321 DCHECK(menu_controller); 314 DCHECK(menu_controller);
322 if (menu_controller->in_nested_run()) { 315 if (menu_controller->in_nested_run()) {
323 // There is another menu showing. Close the outermost menu (since we are 316 // There is another menu showing. Close the outermost menu (since we are
324 // shown in the same menu, we don't want to close the whole thing). 317 // shown in the same menu, we don't want to close the whole thing).
325 menu_controller->Cancel(views::MenuController::EXIT_OUTERMOST); 318 menu_controller->Cancel(views::MenuController::EXIT_OUTERMOST);
326 return true; 319 return true;
327 } 320 }
328 } 321 }
329 322
330 return false; 323 return false;
331 } 324 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698