OLD | NEW |
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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 : MenuButton(nullptr, base::string16(), this, false), | 63 : MenuButton(nullptr, base::string16(), this, false), |
64 view_controller_(view_controller), | 64 view_controller_(view_controller), |
65 profile_(profile), | 65 profile_(profile), |
66 delegate_(delegate), | 66 delegate_(delegate), |
67 called_register_command_(false), | 67 called_register_command_(false), |
68 wants_to_run_(false), | 68 wants_to_run_(false), |
69 menu_(nullptr), | 69 menu_(nullptr), |
70 ink_drop_delegate_(new views::ButtonInkDropDelegate(this, this)), | 70 ink_drop_delegate_(new views::ButtonInkDropDelegate(this, this)), |
71 weak_factory_(this) { | 71 weak_factory_(this) { |
72 set_ink_drop_delegate(ink_drop_delegate_.get()); | 72 set_ink_drop_delegate(ink_drop_delegate_.get()); |
| 73 set_has_ink_drop_action_on_click(true); |
73 set_id(VIEW_ID_BROWSER_ACTION); | 74 set_id(VIEW_ID_BROWSER_ACTION); |
74 view_controller_->SetDelegate(this); | 75 view_controller_->SetDelegate(this); |
75 SetHorizontalAlignment(gfx::ALIGN_CENTER); | 76 SetHorizontalAlignment(gfx::ALIGN_CENTER); |
76 set_drag_controller(delegate_); | 77 set_drag_controller(delegate_); |
77 | 78 |
78 set_context_menu_controller(this); | 79 set_context_menu_controller(this); |
79 | 80 |
80 const int kInkDropLargeSize = 32; | 81 const int kInkDropLargeSize = 32; |
81 const int kInkDropLargeCornerRadius = 5; | 82 const int kInkDropLargeCornerRadius = 5; |
82 const int kInkDropSmallSize = 24; | 83 const int kInkDropSmallSize = 24; |
(...skipping 18 matching lines...) Expand all Loading... |
101 SetFocusable(true); | 102 SetFocusable(true); |
102 } | 103 } |
103 | 104 |
104 UpdateState(); | 105 UpdateState(); |
105 } | 106 } |
106 | 107 |
107 ToolbarActionView::~ToolbarActionView() { | 108 ToolbarActionView::~ToolbarActionView() { |
108 if (context_menu_owner == this) | 109 if (context_menu_owner == this) |
109 context_menu_owner = nullptr; | 110 context_menu_owner = nullptr; |
110 view_controller_->SetDelegate(nullptr); | 111 view_controller_->SetDelegate(nullptr); |
| 112 set_ink_drop_delegate(nullptr); |
111 ink_drop_delegate_.reset(); | 113 ink_drop_delegate_.reset(); |
112 set_ink_drop_delegate(nullptr); | |
113 } | 114 } |
114 | 115 |
115 void ToolbarActionView::GetAccessibleState(ui::AXViewState* state) { | 116 void ToolbarActionView::GetAccessibleState(ui::AXViewState* state) { |
116 views::MenuButton::GetAccessibleState(state); | 117 views::MenuButton::GetAccessibleState(state); |
117 state->role = ui::AX_ROLE_BUTTON; | 118 state->role = ui::AX_ROLE_BUTTON; |
118 } | 119 } |
119 | 120 |
120 scoped_ptr<LabelButtonBorder> ToolbarActionView::CreateDefaultBorder() const { | 121 scoped_ptr<LabelButtonBorder> ToolbarActionView::CreateDefaultBorder() const { |
121 scoped_ptr<LabelButtonBorder> border = LabelButton::CreateDefaultBorder(); | 122 scoped_ptr<LabelButtonBorder> border = LabelButton::CreateDefaultBorder(); |
122 border->set_insets(gfx::Insets(kBorderInset, kBorderInset, | 123 border->set_insets(gfx::Insets(kBorderInset, kBorderInset, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 context_menu_callback = callback; | 220 context_menu_callback = callback; |
220 } | 221 } |
221 | 222 |
222 gfx::Size ToolbarActionView::GetPreferredSize() const { | 223 gfx::Size ToolbarActionView::GetPreferredSize() const { |
223 return gfx::Size(ToolbarActionsBar::IconWidth(false), | 224 return gfx::Size(ToolbarActionsBar::IconWidth(false), |
224 ToolbarActionsBar::IconHeight()); | 225 ToolbarActionsBar::IconHeight()); |
225 } | 226 } |
226 | 227 |
227 bool ToolbarActionView::OnMousePressed(const ui::MouseEvent& event) { | 228 bool ToolbarActionView::OnMousePressed(const ui::MouseEvent& event) { |
228 // views::MenuButton actions are only triggered by left mouse clicks. | 229 // views::MenuButton actions are only triggered by left mouse clicks. |
229 if (event.IsOnlyLeftMouseButton()) | 230 if (event.IsOnlyLeftMouseButton()) { |
| 231 // TODO(bruthig): The ACTION_PENDING triggering logic should be in |
| 232 // MenuButton::OnPressed() however there is a bug with the pressed state |
| 233 // logic in MenuButton. See http://crbug.com/567252. |
230 ink_drop_delegate()->OnAction(views::InkDropState::ACTION_PENDING); | 234 ink_drop_delegate()->OnAction(views::InkDropState::ACTION_PENDING); |
| 235 } |
231 return MenuButton::OnMousePressed(event); | 236 return MenuButton::OnMousePressed(event); |
232 } | 237 } |
233 | 238 |
234 void ToolbarActionView::OnGestureEvent(ui::GestureEvent* event) { | 239 void ToolbarActionView::OnGestureEvent(ui::GestureEvent* event) { |
235 // While the dropdown menu is showing, the button should not handle gestures. | 240 // While the dropdown menu is showing, the button should not handle gestures. |
236 if (menu_) | 241 if (menu_) |
237 event->StopPropagation(); | 242 event->StopPropagation(); |
238 else | 243 else |
239 MenuButton::OnGestureEvent(event); | 244 MenuButton::OnGestureEvent(event); |
240 } | 245 } |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 if (menu_controller->in_nested_run()) { | 391 if (menu_controller->in_nested_run()) { |
387 // There is another menu showing. Close the outermost menu (since we are | 392 // There is another menu showing. Close the outermost menu (since we are |
388 // shown in the same menu, we don't want to close the whole thing). | 393 // shown in the same menu, we don't want to close the whole thing). |
389 menu_controller->Cancel(views::MenuController::EXIT_OUTERMOST); | 394 menu_controller->Cancel(views::MenuController::EXIT_OUTERMOST); |
390 return true; | 395 return true; |
391 } | 396 } |
392 } | 397 } |
393 | 398 |
394 return false; | 399 return false; |
395 } | 400 } |
OLD | NEW |