| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/views/controls/menu/menu_runner.h" | 5 #include "ui/views/controls/menu/menu_runner.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "ui/base/models/menu_model.h" | 10 #include "ui/base/models/menu_model.h" |
| 11 #include "ui/views/controls/button/menu_button.h" | 11 #include "ui/views/controls/button/menu_button.h" |
| 12 #include "ui/views/controls/menu/menu_controller.h" | 12 #include "ui/views/controls/menu/menu_controller.h" |
| 13 #include "ui/views/controls/menu/menu_controller_delegate.h" | 13 #include "ui/views/controls/menu/menu_controller_delegate.h" |
| 14 #include "ui/views/controls/menu/menu_delegate.h" | 14 #include "ui/views/controls/menu/menu_delegate.h" |
| 15 #include "ui/views/controls/menu/menu_item_view.h" |
| 15 #include "ui/views/controls/menu/menu_model_adapter.h" | 16 #include "ui/views/controls/menu/menu_model_adapter.h" |
| 16 #include "ui/views/controls/menu/menu_runner_handler.h" | 17 #include "ui/views/controls/menu/menu_runner_handler.h" |
| 17 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
| 18 | 19 |
| 19 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
| 20 #include "base/win/win_util.h" | 21 #include "base/win/win_util.h" |
| 21 #endif | 22 #endif |
| 22 | 23 |
| 23 namespace views { | 24 namespace views { |
| 24 | 25 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 36 | 37 |
| 37 bool running() const { return running_; } | 38 bool running() const { return running_; } |
| 38 | 39 |
| 39 // See description above class for details. | 40 // See description above class for details. |
| 40 void Release(); | 41 void Release(); |
| 41 | 42 |
| 42 // Runs the menu. | 43 // Runs the menu. |
| 43 MenuRunner::RunResult RunMenuAt(Widget* parent, | 44 MenuRunner::RunResult RunMenuAt(Widget* parent, |
| 44 MenuButton* button, | 45 MenuButton* button, |
| 45 const gfx::Rect& bounds, | 46 const gfx::Rect& bounds, |
| 46 MenuItemView::AnchorPosition anchor, | 47 ui::MenuAnchorPosition anchor, |
| 47 int32 types) WARN_UNUSED_RESULT; | 48 int32 types) WARN_UNUSED_RESULT; |
| 48 | 49 |
| 49 void Cancel(); | 50 void Cancel(); |
| 50 | 51 |
| 51 // Returns the time from the event which closed the menu - or 0. | 52 // Returns the time from the event which closed the menu - or 0. |
| 52 base::TimeDelta closing_event_time() const; | 53 base::TimeDelta closing_event_time() const; |
| 53 | 54 |
| 54 // MenuControllerDelegate: | 55 // MenuControllerDelegate: |
| 55 virtual void DropMenuClosed(NotifyType type, MenuItemView* menu) OVERRIDE; | 56 virtual void DropMenuClosed(NotifyType type, MenuItemView* menu) OVERRIDE; |
| 56 virtual void SiblingMenuCreated(MenuItemView* menu) OVERRIDE; | 57 virtual void SiblingMenuCreated(MenuItemView* menu) OVERRIDE; |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 } | 291 } |
| 291 | 292 |
| 292 MenuRunner::~MenuRunner() { | 293 MenuRunner::~MenuRunner() { |
| 293 holder_->Release(); | 294 holder_->Release(); |
| 294 } | 295 } |
| 295 | 296 |
| 296 MenuItemView* MenuRunner::GetMenu() { | 297 MenuItemView* MenuRunner::GetMenu() { |
| 297 return holder_->menu(); | 298 return holder_->menu(); |
| 298 } | 299 } |
| 299 | 300 |
| 301 template<> |
| 300 MenuRunner::RunResult MenuRunner::RunMenuAt(Widget* parent, | 302 MenuRunner::RunResult MenuRunner::RunMenuAt(Widget* parent, |
| 301 MenuButton* button, | 303 MenuButton* button, |
| 302 const gfx::Rect& bounds, | 304 const gfx::Rect& bounds, |
| 303 MenuItemView::AnchorPosition anchor, | 305 ui::MenuAnchorPosition menu_anchor, |
| 304 ui::MenuSourceType source_type, | 306 ui::MenuSourceType source_type, |
| 305 int32 types) { | 307 int32 types) { |
| 308 MenuItemView::AnchorPosition anchor = |
| 309 static_cast<MenuItemView::AnchorPosition>(menu_anchor); |
| 306 if (runner_handler_.get()) { | 310 if (runner_handler_.get()) { |
| 307 return runner_handler_->RunMenuAt(parent, button, bounds, anchor, | 311 return runner_handler_->RunMenuAt(parent, button, bounds, anchor, |
| 308 source_type, types); | 312 source_type, types); |
| 309 } | 313 } |
| 310 | 314 |
| 311 // The parent of the nested menu will have created a DisplayChangeListener, so | 315 // The parent of the nested menu will have created a DisplayChangeListener, so |
| 312 // we avoid creating a DisplayChangeListener if nested. Drop menus are | 316 // we avoid creating a DisplayChangeListener if nested. Drop menus are |
| 313 // transient, so we don't cancel in that case. | 317 // transient, so we don't cancel in that case. |
| 314 if ((types & (IS_NESTED | FOR_DROP)) == 0 && parent) { | 318 if ((types & (IS_NESTED | FOR_DROP)) == 0 && parent) { |
| 315 display_change_listener_.reset( | 319 display_change_listener_.reset( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 346 base::TimeDelta MenuRunner::closing_event_time() const { | 350 base::TimeDelta MenuRunner::closing_event_time() const { |
| 347 return holder_->closing_event_time(); | 351 return holder_->closing_event_time(); |
| 348 } | 352 } |
| 349 | 353 |
| 350 void MenuRunner::SetRunnerHandler( | 354 void MenuRunner::SetRunnerHandler( |
| 351 scoped_ptr<MenuRunnerHandler> runner_handler) { | 355 scoped_ptr<MenuRunnerHandler> runner_handler) { |
| 352 runner_handler_ = runner_handler.Pass(); | 356 runner_handler_ = runner_handler.Pass(); |
| 353 } | 357 } |
| 354 | 358 |
| 355 } // namespace views | 359 } // namespace views |
| OLD | NEW |