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

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

Issue 2041033002: Moved ButtonInkDropDelegate logic into InkDropHostView and deleted InkDropDelegates. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed merge conflict in custom_button.cc Created 4 years, 6 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"
11 #include "chrome/browser/chrome_notification_types.h" 11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/sessions/session_tab_helper.h" 12 #include "chrome/browser/sessions/session_tab_helper.h"
13 #include "chrome/browser/themes/theme_properties.h" 13 #include "chrome/browser/themes/theme_properties.h"
14 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" 14 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h"
15 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" 15 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h"
16 #include "chrome/browser/ui/view_ids.h" 16 #include "chrome/browser/ui/view_ids.h"
17 #include "chrome/grit/generated_resources.h" 17 #include "chrome/grit/generated_resources.h"
18 #include "content/public/browser/notification_source.h" 18 #include "content/public/browser/notification_source.h"
19 #include "grit/theme_resources.h" 19 #include "grit/theme_resources.h"
20 #include "ui/accessibility/ax_view_state.h" 20 #include "ui/accessibility/ax_view_state.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/compositor/paint_recorder.h" 23 #include "ui/compositor/paint_recorder.h"
24 #include "ui/events/event.h" 24 #include "ui/events/event.h"
25 #include "ui/gfx/image/image_skia.h" 25 #include "ui/gfx/image/image_skia.h"
26 #include "ui/gfx/image/image_skia_operations.h" 26 #include "ui/gfx/image/image_skia_operations.h"
27 #include "ui/gfx/image/image_skia_source.h" 27 #include "ui/gfx/image/image_skia_source.h"
28 #include "ui/resources/grit/ui_resources.h" 28 #include "ui/resources/grit/ui_resources.h"
29 #include "ui/views/animation/button_ink_drop_delegate.h"
30 #include "ui/views/controls/button/label_button_border.h" 29 #include "ui/views/controls/button/label_button_border.h"
31 #include "ui/views/controls/menu/menu_controller.h" 30 #include "ui/views/controls/menu/menu_controller.h"
32 #include "ui/views/controls/menu/menu_model_adapter.h" 31 #include "ui/views/controls/menu/menu_model_adapter.h"
33 #include "ui/views/controls/menu/menu_runner.h" 32 #include "ui/views/controls/menu/menu_runner.h"
34 #include "ui/views/mouse_constants.h" 33 #include "ui/views/mouse_constants.h"
35 #include "ui/views/resources/grit/views_resources.h" 34 #include "ui/views/resources/grit/views_resources.h"
36 35
37 using views::LabelButtonBorder; 36 using views::LabelButtonBorder;
38 37
39 namespace { 38 namespace {
(...skipping 15 matching lines...) Expand all
55 ToolbarActionView::ToolbarActionView( 54 ToolbarActionView::ToolbarActionView(
56 ToolbarActionViewController* view_controller, 55 ToolbarActionViewController* view_controller,
57 ToolbarActionView::Delegate* delegate) 56 ToolbarActionView::Delegate* delegate)
58 : MenuButton(base::string16(), this, false), 57 : MenuButton(base::string16(), this, false),
59 view_controller_(view_controller), 58 view_controller_(view_controller),
60 delegate_(delegate), 59 delegate_(delegate),
61 called_register_command_(false), 60 called_register_command_(false),
62 wants_to_run_(false), 61 wants_to_run_(false),
63 menu_(nullptr), 62 menu_(nullptr),
64 weak_factory_(this) { 63 weak_factory_(this) {
65 set_ink_drop_delegate( 64 SetHasInkDrop(true);
66 base::WrapUnique(new views::ButtonInkDropDelegate(this, this)));
67 set_has_ink_drop_action_on_click(true); 65 set_has_ink_drop_action_on_click(true);
68 set_id(VIEW_ID_BROWSER_ACTION); 66 set_id(VIEW_ID_BROWSER_ACTION);
69 view_controller_->SetDelegate(this); 67 view_controller_->SetDelegate(this);
70 SetHorizontalAlignment(gfx::ALIGN_CENTER); 68 SetHorizontalAlignment(gfx::ALIGN_CENTER);
71 set_drag_controller(delegate_); 69 set_drag_controller(delegate_);
72 70
73 set_context_menu_controller(this); 71 set_context_menu_controller(this);
74 72
75 // If the button is within a menu, we need to make it focusable in order to 73 // If the button is within a menu, we need to make it focusable in order to
76 // have it accessible via keyboard navigation. 74 // have it accessible via keyboard navigation.
77 if (delegate_->ShownInsideMenu()) 75 if (delegate_->ShownInsideMenu())
78 SetFocusBehavior(FocusBehavior::ALWAYS); 76 SetFocusBehavior(FocusBehavior::ALWAYS);
79 77
80 UpdateState(); 78 UpdateState();
81 } 79 }
82 80
83 ToolbarActionView::~ToolbarActionView() { 81 ToolbarActionView::~ToolbarActionView() {
84 // Avoid access to a destroyed InkDropDelegate when the |pressed_lock_| is
85 // destroyed.
86 set_ink_drop_delegate(nullptr);
87 view_controller_->SetDelegate(nullptr); 82 view_controller_->SetDelegate(nullptr);
88 } 83 }
89 84
90 void ToolbarActionView::GetAccessibleState(ui::AXViewState* state) { 85 void ToolbarActionView::GetAccessibleState(ui::AXViewState* state) {
91 views::MenuButton::GetAccessibleState(state); 86 views::MenuButton::GetAccessibleState(state);
92 state->role = ui::AX_ROLE_BUTTON; 87 state->role = ui::AX_ROLE_BUTTON;
93 } 88 }
94 89
95 std::unique_ptr<LabelButtonBorder> ToolbarActionView::CreateDefaultBorder() 90 std::unique_ptr<LabelButtonBorder> ToolbarActionView::CreateDefaultBorder()
96 const { 91 const {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 return gfx::Size(ToolbarActionsBar::IconWidth(false), 183 return gfx::Size(ToolbarActionsBar::IconWidth(false),
189 ToolbarActionsBar::IconHeight()); 184 ToolbarActionsBar::IconHeight());
190 } 185 }
191 186
192 bool ToolbarActionView::OnMousePressed(const ui::MouseEvent& event) { 187 bool ToolbarActionView::OnMousePressed(const ui::MouseEvent& event) {
193 // views::MenuButton actions are only triggered by left mouse clicks. 188 // views::MenuButton actions are only triggered by left mouse clicks.
194 if (event.IsOnlyLeftMouseButton() && !pressed_lock_) { 189 if (event.IsOnlyLeftMouseButton() && !pressed_lock_) {
195 // TODO(bruthig): The ACTION_PENDING triggering logic should be in 190 // TODO(bruthig): The ACTION_PENDING triggering logic should be in
196 // MenuButton::OnPressed() however there is a bug with the pressed state 191 // MenuButton::OnPressed() however there is a bug with the pressed state
197 // logic in MenuButton. See http://crbug.com/567252. 192 // logic in MenuButton. See http://crbug.com/567252.
198 ink_drop_delegate()->OnAction(views::InkDropState::ACTION_PENDING); 193 AnimateInkDrop(views::InkDropState::ACTION_PENDING);
199 } 194 }
200 return MenuButton::OnMousePressed(event); 195 return MenuButton::OnMousePressed(event);
201 } 196 }
202 197
203 void ToolbarActionView::OnGestureEvent(ui::GestureEvent* event) { 198 void ToolbarActionView::OnGestureEvent(ui::GestureEvent* event) {
204 // While the dropdown menu is showing, the button should not handle gestures. 199 // While the dropdown menu is showing, the button should not handle gestures.
205 if (menu_) 200 if (menu_)
206 event->StopPropagation(); 201 event->StopPropagation();
207 else 202 else
208 MenuButton::OnGestureEvent(event); 203 MenuButton::OnGestureEvent(event);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 if (menu_controller->in_nested_run()) { 318 if (menu_controller->in_nested_run()) {
324 // There is another menu showing. Close the outermost menu (since we are 319 // There is another menu showing. Close the outermost menu (since we are
325 // shown in the same menu, we don't want to close the whole thing). 320 // shown in the same menu, we don't want to close the whole thing).
326 menu_controller->Cancel(views::MenuController::EXIT_OUTERMOST); 321 menu_controller->Cancel(views::MenuController::EXIT_OUTERMOST);
327 return true; 322 return true;
328 } 323 }
329 } 324 }
330 325
331 return false; 326 return false;
332 } 327 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/toolbar/app_menu_button.cc ('k') | chrome/browser/ui/views/toolbar/toolbar_action_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698