| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 : MenuButton(nullptr, base::string16(), this, false), | 61 : MenuButton(nullptr, base::string16(), this, false), |
| 62 view_controller_(view_controller), | 62 view_controller_(view_controller), |
| 63 profile_(profile), | 63 profile_(profile), |
| 64 delegate_(delegate), | 64 delegate_(delegate), |
| 65 called_register_command_(false), | 65 called_register_command_(false), |
| 66 wants_to_run_(false), | 66 wants_to_run_(false), |
| 67 menu_(nullptr), | 67 menu_(nullptr), |
| 68 ink_drop_delegate_(new views::ButtonInkDropDelegate(this, this)), | 68 ink_drop_delegate_(new views::ButtonInkDropDelegate(this, this)), |
| 69 weak_factory_(this) { | 69 weak_factory_(this) { |
| 70 set_ink_drop_delegate(ink_drop_delegate_.get()); | 70 set_ink_drop_delegate(ink_drop_delegate_.get()); |
| 71 set_has_ink_drop_action_on_click(true); |
| 71 set_id(VIEW_ID_BROWSER_ACTION); | 72 set_id(VIEW_ID_BROWSER_ACTION); |
| 72 view_controller_->SetDelegate(this); | 73 view_controller_->SetDelegate(this); |
| 73 SetHorizontalAlignment(gfx::ALIGN_CENTER); | 74 SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 74 set_drag_controller(delegate_); | 75 set_drag_controller(delegate_); |
| 75 | 76 |
| 76 set_context_menu_controller(this); | 77 set_context_menu_controller(this); |
| 77 | 78 |
| 78 const int kInkDropLargeSize = 32; | 79 const int kInkDropLargeSize = 32; |
| 79 const int kInkDropLargeCornerRadius = 5; | 80 const int kInkDropLargeCornerRadius = 5; |
| 80 const int kInkDropSmallSize = 24; | 81 const int kInkDropSmallSize = 24; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 91 SetFocusable(true); | 92 SetFocusable(true); |
| 92 } | 93 } |
| 93 | 94 |
| 94 UpdateState(); | 95 UpdateState(); |
| 95 } | 96 } |
| 96 | 97 |
| 97 ToolbarActionView::~ToolbarActionView() { | 98 ToolbarActionView::~ToolbarActionView() { |
| 98 if (context_menu_owner == this) | 99 if (context_menu_owner == this) |
| 99 context_menu_owner = nullptr; | 100 context_menu_owner = nullptr; |
| 100 view_controller_->SetDelegate(nullptr); | 101 view_controller_->SetDelegate(nullptr); |
| 101 ink_drop_delegate_.reset(); | |
| 102 set_ink_drop_delegate(nullptr); | |
| 103 } | 102 } |
| 104 | 103 |
| 105 void ToolbarActionView::GetAccessibleState(ui::AXViewState* state) { | 104 void ToolbarActionView::GetAccessibleState(ui::AXViewState* state) { |
| 106 views::MenuButton::GetAccessibleState(state); | 105 views::MenuButton::GetAccessibleState(state); |
| 107 state->role = ui::AX_ROLE_BUTTON; | 106 state->role = ui::AX_ROLE_BUTTON; |
| 108 } | 107 } |
| 109 | 108 |
| 110 scoped_ptr<LabelButtonBorder> ToolbarActionView::CreateDefaultBorder() const { | 109 scoped_ptr<LabelButtonBorder> ToolbarActionView::CreateDefaultBorder() const { |
| 111 scoped_ptr<LabelButtonBorder> border = LabelButton::CreateDefaultBorder(); | 110 scoped_ptr<LabelButtonBorder> border = LabelButton::CreateDefaultBorder(); |
| 112 border->set_insets(gfx::Insets(kBorderInset, kBorderInset, | 111 border->set_insets(gfx::Insets(kBorderInset, kBorderInset, |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 context_menu_callback = callback; | 200 context_menu_callback = callback; |
| 202 } | 201 } |
| 203 | 202 |
| 204 gfx::Size ToolbarActionView::GetPreferredSize() const { | 203 gfx::Size ToolbarActionView::GetPreferredSize() const { |
| 205 return gfx::Size(ToolbarActionsBar::IconWidth(false), | 204 return gfx::Size(ToolbarActionsBar::IconWidth(false), |
| 206 ToolbarActionsBar::IconHeight()); | 205 ToolbarActionsBar::IconHeight()); |
| 207 } | 206 } |
| 208 | 207 |
| 209 bool ToolbarActionView::OnMousePressed(const ui::MouseEvent& event) { | 208 bool ToolbarActionView::OnMousePressed(const ui::MouseEvent& event) { |
| 210 // views::MenuButton actions are only triggered by left mouse clicks. | 209 // views::MenuButton actions are only triggered by left mouse clicks. |
| 211 if (event.IsOnlyLeftMouseButton()) | 210 if (event.IsOnlyLeftMouseButton()) { |
| 211 // TODO(bruthig): The ACTION_PENDING triggering logic should be in |
| 212 // MenuButton::OnPressed() however there is a bug with the pressed state |
| 213 // logic in MenuButton. See http://crbug.com/567252. |
| 212 ink_drop_delegate()->OnAction(views::InkDropState::ACTION_PENDING); | 214 ink_drop_delegate()->OnAction(views::InkDropState::ACTION_PENDING); |
| 215 } |
| 213 return MenuButton::OnMousePressed(event); | 216 return MenuButton::OnMousePressed(event); |
| 214 } | 217 } |
| 215 | 218 |
| 216 void ToolbarActionView::OnGestureEvent(ui::GestureEvent* event) { | 219 void ToolbarActionView::OnGestureEvent(ui::GestureEvent* event) { |
| 217 // While the dropdown menu is showing, the button should not handle gestures. | 220 // While the dropdown menu is showing, the button should not handle gestures. |
| 218 if (menu_) | 221 if (menu_) |
| 219 event->StopPropagation(); | 222 event->StopPropagation(); |
| 220 else | 223 else |
| 221 MenuButton::OnGestureEvent(event); | 224 MenuButton::OnGestureEvent(event); |
| 222 } | 225 } |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 if (menu_controller->in_nested_run()) { | 371 if (menu_controller->in_nested_run()) { |
| 369 // There is another menu showing. Close the outermost menu (since we are | 372 // There is another menu showing. Close the outermost menu (since we are |
| 370 // shown in the same menu, we don't want to close the whole thing). | 373 // shown in the same menu, we don't want to close the whole thing). |
| 371 menu_controller->Cancel(views::MenuController::EXIT_OUTERMOST); | 374 menu_controller->Cancel(views::MenuController::EXIT_OUTERMOST); |
| 372 return true; | 375 return true; |
| 373 } | 376 } |
| 374 } | 377 } |
| 375 | 378 |
| 376 return false; | 379 return false; |
| 377 } | 380 } |
| OLD | NEW |