| 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 "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 // (because that would close the menu). | 77 // (because that would close the menu). |
| 78 if (delegate_->ShownInsideMenu()) { | 78 if (delegate_->ShownInsideMenu()) { |
| 79 set_request_focus_on_press(false); | 79 set_request_focus_on_press(false); |
| 80 SetFocusable(true); | 80 SetFocusable(true); |
| 81 } | 81 } |
| 82 | 82 |
| 83 UpdateState(); | 83 UpdateState(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 ToolbarActionView::~ToolbarActionView() { | 86 ToolbarActionView::~ToolbarActionView() { |
| 87 // Avoid access to a destroyed InkDropDelegate when the |pressed_lock_| is |
| 88 // destroyed. |
| 89 set_ink_drop_delegate(nullptr); |
| 87 view_controller_->SetDelegate(nullptr); | 90 view_controller_->SetDelegate(nullptr); |
| 88 } | 91 } |
| 89 | 92 |
| 90 void ToolbarActionView::GetAccessibleState(ui::AXViewState* state) { | 93 void ToolbarActionView::GetAccessibleState(ui::AXViewState* state) { |
| 91 views::MenuButton::GetAccessibleState(state); | 94 views::MenuButton::GetAccessibleState(state); |
| 92 state->role = ui::AX_ROLE_BUTTON; | 95 state->role = ui::AX_ROLE_BUTTON; |
| 93 } | 96 } |
| 94 | 97 |
| 95 scoped_ptr<LabelButtonBorder> ToolbarActionView::CreateDefaultBorder() const { | 98 scoped_ptr<LabelButtonBorder> ToolbarActionView::CreateDefaultBorder() const { |
| 96 scoped_ptr<LabelButtonBorder> border = LabelButton::CreateDefaultBorder(); | 99 scoped_ptr<LabelButtonBorder> border = LabelButton::CreateDefaultBorder(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 109 (base::TimeTicks::Now() - popup_closed_time_).InMilliseconds() > | 112 (base::TimeTicks::Now() - popup_closed_time_).InMilliseconds() > |
| 110 views::kMinimumMsBetweenButtonClicks; | 113 views::kMinimumMsBetweenButtonClicks; |
| 111 } | 114 } |
| 112 | 115 |
| 113 SkColor ToolbarActionView::GetInkDropBaseColor() const { | 116 SkColor ToolbarActionView::GetInkDropBaseColor() const { |
| 114 if (delegate_->ShownInsideMenu()) { | 117 if (delegate_->ShownInsideMenu()) { |
| 115 return GetNativeTheme()->GetSystemColor( | 118 return GetNativeTheme()->GetSystemColor( |
| 116 ui::NativeTheme::kColorId_HoverMenuItemBackgroundColor); | 119 ui::NativeTheme::kColorId_HoverMenuItemBackgroundColor); |
| 117 } | 120 } |
| 118 | 121 |
| 119 return GetThemeProvider()->GetColor( | 122 return GetThemeProvider() |
| 120 ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON); | 123 ? GetThemeProvider()->GetColor( |
| 124 ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON) |
| 125 : CustomButton::GetInkDropBaseColor(); |
| 121 } | 126 } |
| 122 | 127 |
| 123 bool ToolbarActionView::ShouldShowInkDropHover() const { | 128 bool ToolbarActionView::ShouldShowInkDropHover() const { |
| 124 return !delegate_->ShownInsideMenu() && | 129 return !delegate_->ShownInsideMenu() && |
| 125 views::MenuButton::ShouldShowInkDropHover(); | 130 views::MenuButton::ShouldShowInkDropHover(); |
| 126 } | 131 } |
| 127 | 132 |
| 128 content::WebContents* ToolbarActionView::GetCurrentWebContents() const { | 133 content::WebContents* ToolbarActionView::GetCurrentWebContents() const { |
| 129 return delegate_->GetCurrentWebContents(); | 134 return delegate_->GetCurrentWebContents(); |
| 130 } | 135 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 } else { | 174 } else { |
| 170 view_controller_->ExecuteAction(true); | 175 view_controller_->ExecuteAction(true); |
| 171 } | 176 } |
| 172 } | 177 } |
| 173 | 178 |
| 174 void ToolbarActionView::OnMenuClosed() { | 179 void ToolbarActionView::OnMenuClosed() { |
| 175 menu_runner_.reset(); | 180 menu_runner_.reset(); |
| 176 menu_ = nullptr; | 181 menu_ = nullptr; |
| 177 view_controller_->OnContextMenuClosed(); | 182 view_controller_->OnContextMenuClosed(); |
| 178 menu_adapter_.reset(); | 183 menu_adapter_.reset(); |
| 179 ink_drop_delegate()->OnAction(views::InkDropState::DEACTIVATED); | |
| 180 } | 184 } |
| 181 | 185 |
| 182 gfx::ImageSkia ToolbarActionView::GetIconForTest() { | 186 gfx::ImageSkia ToolbarActionView::GetIconForTest() { |
| 183 return GetImage(views::Button::STATE_NORMAL); | 187 return GetImage(views::Button::STATE_NORMAL); |
| 184 } | 188 } |
| 185 | 189 |
| 186 void ToolbarActionView::set_context_menu_callback_for_testing( | 190 void ToolbarActionView::set_context_menu_callback_for_testing( |
| 187 base::Callback<void(ToolbarActionView*)>* callback) { | 191 base::Callback<void(ToolbarActionView*)>* callback) { |
| 188 context_menu_callback_for_test = callback; | 192 context_menu_callback_for_test = callback; |
| 189 } | 193 } |
| 190 | 194 |
| 191 gfx::Size ToolbarActionView::GetPreferredSize() const { | 195 gfx::Size ToolbarActionView::GetPreferredSize() const { |
| 192 return gfx::Size(ToolbarActionsBar::IconWidth(false), | 196 return gfx::Size(ToolbarActionsBar::IconWidth(false), |
| 193 ToolbarActionsBar::IconHeight()); | 197 ToolbarActionsBar::IconHeight()); |
| 194 } | 198 } |
| 195 | 199 |
| 196 bool ToolbarActionView::OnMousePressed(const ui::MouseEvent& event) { | 200 bool ToolbarActionView::OnMousePressed(const ui::MouseEvent& event) { |
| 197 // views::MenuButton actions are only triggered by left mouse clicks. | 201 // views::MenuButton actions are only triggered by left mouse clicks. |
| 198 if (event.IsOnlyLeftMouseButton()) { | 202 if (event.IsOnlyLeftMouseButton() && !pressed_lock_) { |
| 199 // TODO(bruthig): The ACTION_PENDING triggering logic should be in | 203 // TODO(bruthig): The ACTION_PENDING triggering logic should be in |
| 200 // MenuButton::OnPressed() however there is a bug with the pressed state | 204 // MenuButton::OnPressed() however there is a bug with the pressed state |
| 201 // logic in MenuButton. See http://crbug.com/567252. | 205 // logic in MenuButton. See http://crbug.com/567252. |
| 202 ink_drop_delegate()->OnAction(views::InkDropState::ACTION_PENDING); | 206 ink_drop_delegate()->OnAction(views::InkDropState::ACTION_PENDING); |
| 203 } | 207 } |
| 204 return MenuButton::OnMousePressed(event); | 208 return MenuButton::OnMousePressed(event); |
| 205 } | 209 } |
| 206 | 210 |
| 207 void ToolbarActionView::OnGestureEvent(ui::GestureEvent* event) { | 211 void ToolbarActionView::OnGestureEvent(ui::GestureEvent* event) { |
| 208 // While the dropdown menu is showing, the button should not handle gestures. | 212 // While the dropdown menu is showing, the button should not handle gestures. |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 views::MenuRunner::CONTEXT_MENU | views::MenuRunner::ASYNC; | 295 views::MenuRunner::CONTEXT_MENU | views::MenuRunner::ASYNC; |
| 292 if (delegate_->ShownInsideMenu()) | 296 if (delegate_->ShownInsideMenu()) |
| 293 run_types |= views::MenuRunner::IS_NESTED; | 297 run_types |= views::MenuRunner::IS_NESTED; |
| 294 | 298 |
| 295 // RunMenuAt expects a nested menu to be parented by the same widget as the | 299 // RunMenuAt expects a nested menu to be parented by the same widget as the |
| 296 // already visible menu, in this case the Chrome menu. | 300 // already visible menu, in this case the Chrome menu. |
| 297 views::Widget* parent = delegate_->ShownInsideMenu() ? | 301 views::Widget* parent = delegate_->ShownInsideMenu() ? |
| 298 delegate_->GetOverflowReferenceView()->GetWidget() : | 302 delegate_->GetOverflowReferenceView()->GetWidget() : |
| 299 GetWidget(); | 303 GetWidget(); |
| 300 | 304 |
| 301 ink_drop_delegate()->OnAction(views::InkDropState::ACTIVATED); | |
| 302 // Unretained() is safe here as ToolbarActionView will always outlive the | 305 // Unretained() is safe here as ToolbarActionView will always outlive the |
| 303 // menu. Any action that would lead to the deletion of |this| first triggers | 306 // menu. Any action that would lead to the deletion of |this| first triggers |
| 304 // the closing of the menu through lost capture. | 307 // the closing of the menu through lost capture. |
| 305 menu_adapter_.reset(new views::MenuModelAdapter( | 308 menu_adapter_.reset(new views::MenuModelAdapter( |
| 306 context_menu_model, | 309 context_menu_model, |
| 307 base::Bind(&ToolbarActionView::OnMenuClosed, base::Unretained(this)))); | 310 base::Bind(&ToolbarActionView::OnMenuClosed, base::Unretained(this)))); |
| 308 menu_ = menu_adapter_->CreateMenu(); | 311 menu_ = menu_adapter_->CreateMenu(); |
| 309 menu_runner_.reset(new views::MenuRunner(menu_, run_types)); | 312 menu_runner_.reset(new views::MenuRunner(menu_, run_types)); |
| 310 | 313 |
| 311 if (context_menu_callback_for_test) | 314 if (context_menu_callback_for_test) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 328 if (menu_controller->in_nested_run()) { | 331 if (menu_controller->in_nested_run()) { |
| 329 // There is another menu showing. Close the outermost menu (since we are | 332 // There is another menu showing. Close the outermost menu (since we are |
| 330 // shown in the same menu, we don't want to close the whole thing). | 333 // shown in the same menu, we don't want to close the whole thing). |
| 331 menu_controller->Cancel(views::MenuController::EXIT_OUTERMOST); | 334 menu_controller->Cancel(views::MenuController::EXIT_OUTERMOST); |
| 332 return true; | 335 return true; |
| 333 } | 336 } |
| 334 } | 337 } |
| 335 | 338 |
| 336 return false; | 339 return false; |
| 337 } | 340 } |
| OLD | NEW |