| 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" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.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_service.h" | 13 #include "chrome/browser/themes/theme_service.h" |
| 14 #include "chrome/browser/themes/theme_service_factory.h" | 14 #include "chrome/browser/themes/theme_service_factory.h" |
| 15 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" | 15 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
| 16 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" | 16 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" |
| 17 #include "chrome/browser/ui/view_ids.h" | 17 #include "chrome/browser/ui/view_ids.h" |
| 18 #include "chrome/grit/generated_resources.h" | 18 #include "chrome/grit/generated_resources.h" |
| 19 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
| 20 #include "grit/theme_resources.h" | 20 #include "grit/theme_resources.h" |
| 21 #include "ui/accessibility/ax_view_state.h" | 21 #include "ui/accessibility/ax_view_state.h" |
| 22 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.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" |
| 29 #include "ui/views/controls/button/label_button_border.h" | 30 #include "ui/views/controls/button/label_button_border.h" |
| 30 #include "ui/views/controls/menu/menu_controller.h" | 31 #include "ui/views/controls/menu/menu_controller.h" |
| 31 #include "ui/views/controls/menu/menu_model_adapter.h" | 32 #include "ui/views/controls/menu/menu_model_adapter.h" |
| 32 #include "ui/views/controls/menu/menu_runner.h" | 33 #include "ui/views/controls/menu/menu_runner.h" |
| 33 #include "ui/views/mouse_constants.h" | 34 #include "ui/views/mouse_constants.h" |
| 34 #include "ui/views/resources/grit/views_resources.h" | 35 #include "ui/views/resources/grit/views_resources.h" |
| 35 | 36 |
| 36 using views::LabelButtonBorder; | 37 using views::LabelButtonBorder; |
| 37 | 38 |
| 38 namespace { | 39 namespace { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 60 Profile* profile, | 61 Profile* profile, |
| 61 ToolbarActionView::Delegate* delegate) | 62 ToolbarActionView::Delegate* delegate) |
| 62 : MenuButton(nullptr, base::string16(), this, false), | 63 : MenuButton(nullptr, base::string16(), this, false), |
| 63 view_controller_(view_controller), | 64 view_controller_(view_controller), |
| 64 profile_(profile), | 65 profile_(profile), |
| 65 delegate_(delegate), | 66 delegate_(delegate), |
| 66 called_register_command_(false), | 67 called_register_command_(false), |
| 67 wants_to_run_(false), | 68 wants_to_run_(false), |
| 68 menu_(nullptr), | 69 menu_(nullptr), |
| 69 weak_factory_(this) { | 70 weak_factory_(this) { |
| 71 scoped_ptr<views::InkDropDelegate> new_ink_drop_delegate( |
| 72 new views::ButtonInkDropDelegate(this, this)); |
| 73 SetInkDropDelegate(new_ink_drop_delegate.Pass()); |
| 70 set_id(VIEW_ID_BROWSER_ACTION); | 74 set_id(VIEW_ID_BROWSER_ACTION); |
| 71 view_controller_->SetDelegate(this); | 75 view_controller_->SetDelegate(this); |
| 72 SetHorizontalAlignment(gfx::ALIGN_CENTER); | 76 SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 73 set_drag_controller(delegate_); | 77 set_drag_controller(delegate_); |
| 74 | 78 |
| 75 set_context_menu_controller(this); | 79 set_context_menu_controller(this); |
| 76 | 80 |
| 81 const int kInkDropLargeSize = 32; |
| 82 const int kInkDropLargeCornerRadius = 5; |
| 83 const int kInkDropSmallSize = 24; |
| 84 const int kInkDropSmallCornerRadius = 2; |
| 85 ink_drop_delegate()->SetInkDropSize( |
| 86 kInkDropLargeSize, kInkDropLargeCornerRadius, kInkDropSmallSize, |
| 87 kInkDropSmallCornerRadius); |
| 88 |
| 77 // We also listen for browser theme changes on linux because a switch from or | 89 // We also listen for browser theme changes on linux because a switch from or |
| 78 // to GTK requires that we regrab our browser action images. | 90 // to GTK requires that we regrab our browser action images. |
| 79 registrar_.Add( | 91 registrar_.Add( |
| 80 this, | 92 this, |
| 81 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 93 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
| 82 content::Source<ThemeService>( | 94 content::Source<ThemeService>( |
| 83 ThemeServiceFactory::GetForProfile(profile_))); | 95 ThemeServiceFactory::GetForProfile(profile_))); |
| 84 | 96 |
| 85 // If the button is within a menu, we need to make it focusable in order to | 97 // If the button is within a menu, we need to make it focusable in order to |
| 86 // have it accessible via keyboard navigation, but it shouldn't request focus | 98 // have it accessible via keyboard navigation, but it shouldn't request focus |
| 87 // (because that would close the menu). | 99 // (because that would close the menu). |
| 88 if (delegate_->ShownInsideMenu()) { | 100 if (delegate_->ShownInsideMenu()) { |
| 89 set_request_focus_on_press(false); | 101 set_request_focus_on_press(false); |
| 90 SetFocusable(true); | 102 SetFocusable(true); |
| 91 } | 103 } |
| 92 | 104 |
| 93 UpdateState(); | 105 UpdateState(); |
| 94 } | 106 } |
| 95 | 107 |
| 96 ToolbarActionView::~ToolbarActionView() { | 108 ToolbarActionView::~ToolbarActionView() { |
| 97 if (context_menu_owner == this) | 109 if (context_menu_owner == this) |
| 98 context_menu_owner = nullptr; | 110 context_menu_owner = nullptr; |
| 99 view_controller_->SetDelegate(nullptr); | 111 view_controller_->SetDelegate(nullptr); |
| 100 } | 112 } |
| 101 | 113 |
| 102 gfx::Size ToolbarActionView::GetPreferredSize() const { | |
| 103 return gfx::Size(ToolbarActionsBar::IconWidth(false), | |
| 104 ToolbarActionsBar::IconHeight()); | |
| 105 } | |
| 106 | |
| 107 void ToolbarActionView::OnDragDone() { | |
| 108 views::MenuButton::OnDragDone(); | |
| 109 delegate_->OnToolbarActionViewDragDone(); | |
| 110 } | |
| 111 | |
| 112 void ToolbarActionView::ViewHierarchyChanged( | |
| 113 const ViewHierarchyChangedDetails& details) { | |
| 114 if (details.is_add && !called_register_command_ && GetFocusManager()) { | |
| 115 view_controller_->RegisterCommand(); | |
| 116 called_register_command_ = true; | |
| 117 } | |
| 118 | |
| 119 MenuButton::ViewHierarchyChanged(details); | |
| 120 } | |
| 121 | |
| 122 void ToolbarActionView::GetAccessibleState(ui::AXViewState* state) { | 114 void ToolbarActionView::GetAccessibleState(ui::AXViewState* state) { |
| 123 views::MenuButton::GetAccessibleState(state); | 115 views::MenuButton::GetAccessibleState(state); |
| 124 state->role = ui::AX_ROLE_BUTTON; | 116 state->role = ui::AX_ROLE_BUTTON; |
| 125 } | 117 } |
| 126 | 118 |
| 127 void ToolbarActionView::OnMenuButtonClicked(views::View* sender, | 119 scoped_ptr<LabelButtonBorder> ToolbarActionView::CreateDefaultBorder() const { |
| 128 const gfx::Point& point) { | 120 scoped_ptr<LabelButtonBorder> border = LabelButton::CreateDefaultBorder(); |
| 129 if (!view_controller_->IsEnabled(GetCurrentWebContents())) { | 121 border->set_insets(gfx::Insets(kBorderInset, kBorderInset, |
| 130 // We should only get a button pressed event with a non-enabled action if | 122 kBorderInset, kBorderInset)); |
| 131 // the left-click behavior should open the menu. | 123 return border.Pass(); |
| 132 DCHECK(view_controller_->DisabledClickOpensMenu()); | 124 } |
| 133 context_menu_controller()->ShowContextMenuForView(this, point, | 125 |
| 134 ui::MENU_SOURCE_NONE); | 126 void ToolbarActionView::OnMouseEntered(const ui::MouseEvent& event) { |
| 135 } else { | 127 delegate_->OnMouseEnteredToolbarActionView(); |
| 136 view_controller_->ExecuteAction(true); | 128 views::MenuButton::OnMouseEntered(event); |
| 137 } | 129 } |
| 130 |
| 131 bool ToolbarActionView::ShouldEnterPushedState(const ui::Event& event) { |
| 132 return views::MenuButton::ShouldEnterPushedState(event) && |
| 133 (base::TimeTicks::Now() - popup_closed_time_).InMilliseconds() > |
| 134 views::kMinimumMsBetweenButtonClicks; |
| 135 } |
| 136 |
| 137 content::WebContents* ToolbarActionView::GetCurrentWebContents() const { |
| 138 return delegate_->GetCurrentWebContents(); |
| 138 } | 139 } |
| 139 | 140 |
| 140 void ToolbarActionView::UpdateState() { | 141 void ToolbarActionView::UpdateState() { |
| 141 content::WebContents* web_contents = GetCurrentWebContents(); | 142 content::WebContents* web_contents = GetCurrentWebContents(); |
| 142 if (SessionTabHelper::IdForTab(web_contents) < 0) | 143 if (SessionTabHelper::IdForTab(web_contents) < 0) |
| 143 return; | 144 return; |
| 144 | 145 |
| 145 if (!view_controller_->IsEnabled(web_contents) && | 146 if (!view_controller_->IsEnabled(web_contents) && |
| 146 !view_controller_->DisabledClickOpensMenu()) { | 147 !view_controller_->DisabledClickOpensMenu()) { |
| 147 SetState(views::CustomButton::STATE_DISABLED); | 148 SetState(views::CustomButton::STATE_DISABLED); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 163 gfx::ImageSkiaOperations::CreateSuperimposedImage(bg, icon)); | 164 gfx::ImageSkiaOperations::CreateSuperimposedImage(bg, icon)); |
| 164 } | 165 } |
| 165 | 166 |
| 166 SetTooltipText(view_controller_->GetTooltip(web_contents)); | 167 SetTooltipText(view_controller_->GetTooltip(web_contents)); |
| 167 SetAccessibleName(view_controller_->GetAccessibleName(web_contents)); | 168 SetAccessibleName(view_controller_->GetAccessibleName(web_contents)); |
| 168 | 169 |
| 169 Layout(); // We need to layout since we may have added an icon as a result. | 170 Layout(); // We need to layout since we may have added an icon as a result. |
| 170 SchedulePaint(); | 171 SchedulePaint(); |
| 171 } | 172 } |
| 172 | 173 |
| 174 void ToolbarActionView::OnMenuButtonClicked(views::View* sender, |
| 175 const gfx::Point& point) { |
| 176 if (!view_controller_->IsEnabled(GetCurrentWebContents())) { |
| 177 // We should only get a button pressed event with a non-enabled action if |
| 178 // the left-click behavior should open the menu. |
| 179 DCHECK(view_controller_->DisabledClickOpensMenu()); |
| 180 context_menu_controller()->ShowContextMenuForView(this, point, |
| 181 ui::MENU_SOURCE_NONE); |
| 182 } else { |
| 183 view_controller_->ExecuteAction(true); |
| 184 } |
| 185 } |
| 186 |
| 173 void ToolbarActionView::Observe(int type, | 187 void ToolbarActionView::Observe(int type, |
| 174 const content::NotificationSource& source, | 188 const content::NotificationSource& source, |
| 175 const content::NotificationDetails& details) { | 189 const content::NotificationDetails& details) { |
| 176 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, type); | 190 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, type); |
| 177 UpdateState(); | 191 UpdateState(); |
| 178 } | 192 } |
| 179 | 193 |
| 180 void ToolbarActionView::OnMouseEntered(const ui::MouseEvent& event) { | 194 void ToolbarActionView::AddInkDropLayer(ui::Layer* ink_drop_layer) { |
| 181 delegate_->OnMouseEnteredToolbarActionView(); | 195 SetPaintToLayer(true); |
| 182 views::MenuButton::OnMouseEntered(event); | 196 SetFillsBoundsOpaquely(false); |
| 197 image()->SetPaintToLayer(true); |
| 198 image()->SetFillsBoundsOpaquely(false); |
| 199 |
| 200 layer()->Add(ink_drop_layer); |
| 201 layer()->StackAtBottom(ink_drop_layer); |
| 183 } | 202 } |
| 184 | 203 |
| 185 bool ToolbarActionView::ShouldEnterPushedState(const ui::Event& event) { | 204 void ToolbarActionView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { |
| 186 return views::MenuButton::ShouldEnterPushedState(event) && | 205 layer()->Remove(ink_drop_layer); |
| 187 (base::TimeTicks::Now() - popup_closed_time_).InMilliseconds() > | |
| 188 views::kMinimumMsBetweenButtonClicks; | |
| 189 } | |
| 190 | 206 |
| 191 scoped_ptr<LabelButtonBorder> ToolbarActionView::CreateDefaultBorder() const { | 207 image()->SetFillsBoundsOpaquely(true); |
| 192 scoped_ptr<LabelButtonBorder> border = LabelButton::CreateDefaultBorder(); | 208 image()->SetPaintToLayer(false); |
| 193 border->set_insets(gfx::Insets(kBorderInset, kBorderInset, | 209 SetPaintToLayer(false); |
| 194 kBorderInset, kBorderInset)); | |
| 195 return border.Pass(); | |
| 196 } | 210 } |
| 197 | 211 |
| 198 gfx::ImageSkia ToolbarActionView::GetIconForTest() { | 212 gfx::ImageSkia ToolbarActionView::GetIconForTest() { |
| 199 return GetImage(views::Button::STATE_NORMAL); | 213 return GetImage(views::Button::STATE_NORMAL); |
| 200 } | 214 } |
| 201 | 215 |
| 202 void ToolbarActionView::set_context_menu_callback_for_testing( | 216 void ToolbarActionView::set_context_menu_callback_for_testing( |
| 203 base::Callback<void(ToolbarActionView*)>* callback) { | 217 base::Callback<void(ToolbarActionView*)>* callback) { |
| 204 context_menu_callback = callback; | 218 context_menu_callback = callback; |
| 205 } | 219 } |
| 206 | 220 |
| 221 gfx::Size ToolbarActionView::GetPreferredSize() const { |
| 222 return gfx::Size(ToolbarActionsBar::IconWidth(false), |
| 223 ToolbarActionsBar::IconHeight()); |
| 224 } |
| 225 |
| 226 bool ToolbarActionView::OnMousePressed(const ui::MouseEvent& event) { |
| 227 // views::MenuButton actions are only triggered by left mouse clicks. |
| 228 if (event.IsOnlyLeftMouseButton()) |
| 229 ink_drop_delegate()->OnAction(views::InkDropState::ACTION_PENDING); |
| 230 return MenuButton::OnMousePressed(event); |
| 231 } |
| 232 |
| 233 void ToolbarActionView::OnGestureEvent(ui::GestureEvent* event) { |
| 234 // While the dropdown menu is showing, the button should not handle gestures. |
| 235 if (menu_) |
| 236 event->StopPropagation(); |
| 237 else |
| 238 MenuButton::OnGestureEvent(event); |
| 239 } |
| 240 |
| 241 void ToolbarActionView::OnDragDone() { |
| 242 views::MenuButton::OnDragDone(); |
| 243 delegate_->OnToolbarActionViewDragDone(); |
| 244 } |
| 245 |
| 246 void ToolbarActionView::ViewHierarchyChanged( |
| 247 const ViewHierarchyChangedDetails& details) { |
| 248 if (details.is_add && !called_register_command_ && GetFocusManager()) { |
| 249 view_controller_->RegisterCommand(); |
| 250 called_register_command_ = true; |
| 251 } |
| 252 |
| 253 MenuButton::ViewHierarchyChanged(details); |
| 254 } |
| 255 |
| 207 views::View* ToolbarActionView::GetAsView() { | 256 views::View* ToolbarActionView::GetAsView() { |
| 208 return this; | 257 return this; |
| 209 } | 258 } |
| 210 | 259 |
| 211 views::FocusManager* ToolbarActionView::GetFocusManagerForAccelerator() { | 260 views::FocusManager* ToolbarActionView::GetFocusManagerForAccelerator() { |
| 212 return GetFocusManager(); | 261 return GetFocusManager(); |
| 213 } | 262 } |
| 214 | 263 |
| 215 views::View* ToolbarActionView::GetReferenceViewForPopup() { | 264 views::View* ToolbarActionView::GetReferenceViewForPopup() { |
| 216 // Browser actions in the overflow menu can still show popups, so we may need | 265 // Browser actions in the overflow menu can still show popups, so we may need |
| 217 // a reference view other than this button's parent. If so, use the overflow | 266 // a reference view other than this button's parent. If so, use the overflow |
| 218 // view. | 267 // view. |
| 219 return visible() ? this : delegate_->GetOverflowReferenceView(); | 268 return visible() ? this : delegate_->GetOverflowReferenceView(); |
| 220 } | 269 } |
| 221 | 270 |
| 222 bool ToolbarActionView::IsMenuRunning() const { | 271 bool ToolbarActionView::IsMenuRunning() const { |
| 223 return menu_ != nullptr; | 272 return menu_ != nullptr; |
| 224 } | 273 } |
| 225 | 274 |
| 226 content::WebContents* ToolbarActionView::GetCurrentWebContents() const { | |
| 227 return delegate_->GetCurrentWebContents(); | |
| 228 } | |
| 229 | |
| 230 void ToolbarActionView::OnPopupShown(bool by_user) { | 275 void ToolbarActionView::OnPopupShown(bool by_user) { |
| 231 // If this was through direct user action, we press the menu button. | 276 // If this was through direct user action, we press the menu button. |
| 232 if (by_user) { | 277 if (by_user) { |
| 233 // We set the state of the menu button we're using as a reference view, | 278 // We set the state of the menu button we're using as a reference view, |
| 234 // which is either this or the overflow reference view. | 279 // which is either this or the overflow reference view. |
| 235 // This cast is safe because GetReferenceViewForPopup returns either |this| | 280 // This cast is safe because GetReferenceViewForPopup returns either |this| |
| 236 // or delegate_->GetOverflowReferenceView(), which returns a MenuButton. | 281 // or delegate_->GetOverflowReferenceView(), which returns a MenuButton. |
| 237 views::MenuButton* reference_view = | 282 views::MenuButton* reference_view = |
| 238 static_cast<views::MenuButton*>(GetReferenceViewForPopup()); | 283 static_cast<views::MenuButton*>(GetReferenceViewForPopup()); |
| 239 pressed_lock_.reset(new views::MenuButton::PressedLock(reference_view)); | 284 pressed_lock_.reset(new views::MenuButton::PressedLock(reference_view)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 264 weak_factory_.GetWeakPtr(), | 309 weak_factory_.GetWeakPtr(), |
| 265 source_type); | 310 source_type); |
| 266 } | 311 } |
| 267 if (CloseActiveMenuIfNeeded()) | 312 if (CloseActiveMenuIfNeeded()) |
| 268 return; | 313 return; |
| 269 | 314 |
| 270 // Otherwise, no other menu is showing, and we can proceed normally. | 315 // Otherwise, no other menu is showing, and we can proceed normally. |
| 271 DoShowContextMenu(source_type); | 316 DoShowContextMenu(source_type); |
| 272 } | 317 } |
| 273 | 318 |
| 319 gfx::Point ToolbarActionView::CalculateInkDropCenter() const { |
| 320 return GetLocalBounds().CenterPoint(); |
| 321 } |
| 322 |
| 274 void ToolbarActionView::DoShowContextMenu( | 323 void ToolbarActionView::DoShowContextMenu( |
| 275 ui::MenuSourceType source_type) { | 324 ui::MenuSourceType source_type) { |
| 276 ui::MenuModel* context_menu_model = view_controller_->GetContextMenu(); | 325 ui::MenuModel* context_menu_model = view_controller_->GetContextMenu(); |
| 277 // It's possible the action doesn't have a context menu. | 326 // It's possible the action doesn't have a context menu. |
| 278 if (!context_menu_model) | 327 if (!context_menu_model) |
| 279 return; | 328 return; |
| 280 | 329 |
| 281 DCHECK(visible()); // We should never show a context menu for a hidden item. | 330 DCHECK(visible()); // We should never show a context menu for a hidden item. |
| 282 DCHECK(!context_menu_owner); | 331 DCHECK(!context_menu_owner); |
| 283 | 332 |
| 284 gfx::Point screen_loc; | 333 gfx::Point screen_loc; |
| 285 ConvertPointToScreen(this, &screen_loc); | 334 ConvertPointToScreen(this, &screen_loc); |
| 286 | 335 |
| 287 int run_types = | 336 int run_types = |
| 288 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU; | 337 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU; |
| 289 if (delegate_->ShownInsideMenu()) | 338 if (delegate_->ShownInsideMenu()) |
| 290 run_types |= views::MenuRunner::IS_NESTED; | 339 run_types |= views::MenuRunner::IS_NESTED; |
| 291 | 340 |
| 292 // RunMenuAt expects a nested menu to be parented by the same widget as the | 341 // RunMenuAt expects a nested menu to be parented by the same widget as the |
| 293 // already visible menu, in this case the Chrome menu. | 342 // already visible menu, in this case the Chrome menu. |
| 294 views::Widget* parent = delegate_->ShownInsideMenu() ? | 343 views::Widget* parent = delegate_->ShownInsideMenu() ? |
| 295 delegate_->GetOverflowReferenceView()->GetWidget() : | 344 delegate_->GetOverflowReferenceView()->GetWidget() : |
| 296 GetWidget(); | 345 GetWidget(); |
| 297 | 346 |
| 347 ink_drop_delegate()->OnAction(views::InkDropState::ACTIVATED); |
| 348 |
| 298 views::MenuModelAdapter adapter(context_menu_model); | 349 views::MenuModelAdapter adapter(context_menu_model); |
| 299 menu_ = adapter.CreateMenu(); | 350 menu_ = adapter.CreateMenu(); |
| 300 menu_runner_.reset(new views::MenuRunner(menu_, run_types)); | 351 menu_runner_.reset(new views::MenuRunner(menu_, run_types)); |
| 301 | 352 |
| 302 if (context_menu_callback) | 353 if (context_menu_callback) |
| 303 context_menu_callback->Run(this); | 354 context_menu_callback->Run(this); |
| 304 if (menu_runner_->RunMenuAt(parent, this, gfx::Rect(screen_loc, size()), | 355 if (menu_runner_->RunMenuAt(parent, this, gfx::Rect(screen_loc, size()), |
| 305 views::MENU_ANCHOR_TOPLEFT, | 356 views::MENU_ANCHOR_TOPLEFT, |
| 306 source_type) == views::MenuRunner::MENU_DELETED) { | 357 source_type) == views::MenuRunner::MENU_DELETED) { |
| 307 return; | 358 return; |
| 308 } | 359 } |
| 360 ink_drop_delegate()->OnAction(views::InkDropState::DEACTIVATED); |
| 309 | 361 |
| 310 menu_runner_.reset(); | 362 menu_runner_.reset(); |
| 311 menu_ = nullptr; | 363 menu_ = nullptr; |
| 312 context_menu_owner = nullptr; | 364 context_menu_owner = nullptr; |
| 313 view_controller_->OnContextMenuClosed(); | 365 view_controller_->OnContextMenuClosed(); |
| 314 | 366 |
| 315 // If another extension action wants to show its context menu, allow it to. | 367 // If another extension action wants to show its context menu, allow it to. |
| 316 if (!followup_context_menu_task_.is_null()) { | 368 if (!followup_context_menu_task_.is_null()) { |
| 317 base::Closure task = followup_context_menu_task_; | 369 base::Closure task = followup_context_menu_task_; |
| 318 followup_context_menu_task_ = base::Closure(); | 370 followup_context_menu_task_ = base::Closure(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 333 if (menu_controller->in_nested_run()) { | 385 if (menu_controller->in_nested_run()) { |
| 334 // There is another menu showing. Close the outermost menu (since we are | 386 // There is another menu showing. Close the outermost menu (since we are |
| 335 // shown in the same menu, we don't want to close the whole thing). | 387 // shown in the same menu, we don't want to close the whole thing). |
| 336 menu_controller->Cancel(views::MenuController::EXIT_OUTERMOST); | 388 menu_controller->Cancel(views::MenuController::EXIT_OUTERMOST); |
| 337 return true; | 389 return true; |
| 338 } | 390 } |
| 339 } | 391 } |
| 340 | 392 |
| 341 return false; | 393 return false; |
| 342 } | 394 } |
| OLD | NEW |