diff options
author | varunjain@chromium.org <varunjain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-18 16:54:28 +0000 |
---|---|---|
committer | varunjain@chromium.org <varunjain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-18 16:54:28 +0000 |
commit | 940fb1c9ca08476b1d52fdb6e92b42e699f2d1e4 (patch) | |
tree | 49f2f8fbb112b16feadd07bef76f86bd5423f16b /ui/views | |
parent | cf43b6c19e56557cae9f0c36d3896b4576830475 (diff) | |
download | chromium_src-940fb1c9ca08476b1d52fdb6e92b42e699f2d1e4.zip chromium_src-940fb1c9ca08476b1d52fdb6e92b42e699f2d1e4.tar.gz chromium_src-940fb1c9ca08476b1d52fdb6e92b42e699f2d1e4.tar.bz2 |
Add ContextMenuSourceType to views::ContextMenuController::ShowContextMenuForView.
This will help bring context menu positioning logic to one place and unify the
positioning logic for all views.
BUG=239110
Review URL: https://chromiumcodereview.appspot.com/16979002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207019 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views')
28 files changed, 113 insertions, 61 deletions
diff --git a/ui/views/context_menu_controller.h b/ui/views/context_menu_controller.h index 23ebd27..dd137a9 100644 --- a/ui/views/context_menu_controller.h +++ b/ui/views/context_menu_controller.h @@ -5,6 +5,7 @@ #ifndef UI_VIEWS_CONTEXT_MENU_CONTROLLER_H_ #define UI_VIEWS_CONTEXT_MENU_CONTROLLER_H_ +#include "ui/base/ui_base_types.h" #include "ui/views/views_export.h" namespace gfx { @@ -30,7 +31,8 @@ class VIEWS_EXPORT ContextMenuController { // Invoked to show the context menu for |source|. // |point| is in screen coordinates. virtual void ShowContextMenuForView(View* source, - const gfx::Point& point) = 0; + const gfx::Point& point, + ui::MenuSourceType source_type) = 0; protected: virtual ~ContextMenuController() {} diff --git a/ui/views/controls/button/button_dropdown.cc b/ui/views/controls/button/button_dropdown.cc index a243cee..fa57e3b 100644 --- a/ui/views/controls/button/button_dropdown.cc +++ b/ui/views/controls/button/button_dropdown.cc @@ -70,7 +70,8 @@ bool ButtonDropDown::OnMousePressed(const ui::MouseEvent& event) { base::MessageLoop::current()->PostDelayedTask( FROM_HERE, base::Bind(&ButtonDropDown::ShowDropDownMenu, - show_menu_factory_.GetWeakPtr()), + show_menu_factory_.GetWeakPtr(), + ui::GetMenuSourceTypeForEvent(event)), base::TimeDelta::FromMilliseconds(kMenuTimerDelay)); } return ImageButton::OnMousePressed(event); @@ -85,7 +86,7 @@ bool ButtonDropDown::OnMouseDragged(const ui::MouseEvent& event) { // it immediately. if (event.y() > y_position_on_lbuttondown_ + GetHorizontalDragThreshold()) { show_menu_factory_.InvalidateWeakPtrs(); - ShowDropDownMenu(); + ShowDropDownMenu(ui::GetMenuSourceTypeForEvent(event)); } } @@ -132,12 +133,13 @@ void ButtonDropDown::GetAccessibleState(ui::AccessibleViewState* state) { } void ButtonDropDown::ShowContextMenuForView(View* source, - const gfx::Point& point) { + const gfx::Point& point, + ui::MenuSourceType source_type) { if (!enabled()) return; show_menu_factory_.InvalidateWeakPtrs(); - ShowDropDownMenu(); + ShowDropDownMenu(source_type); } bool ButtonDropDown::ShouldEnterPushedState(const ui::Event& event) { @@ -153,7 +155,7 @@ bool ButtonDropDown::ShouldShowMenu() { return true; } -void ButtonDropDown::ShowDropDownMenu() { +void ButtonDropDown::ShowDropDownMenu(ui::MenuSourceType source_type) { if (!ShouldShowMenu()) return; @@ -191,6 +193,7 @@ void ButtonDropDown::ShowDropDownMenu() { menu_runner_->RunMenuAt(GetWidget(), NULL, gfx::Rect(menu_position, gfx::Size(0, 0)), MenuItemView::TOPLEFT, + source_type, MenuRunner::HAS_MNEMONICS); if (result == MenuRunner::MENU_DELETED) return; @@ -202,6 +205,7 @@ void ButtonDropDown::ShowDropDownMenu() { menu_runner_->RunMenuAt(GetWidget(), NULL, gfx::Rect(menu_position, gfx::Size(0, 0)), MenuItemView::TOPLEFT, + source_type, MenuRunner::HAS_MNEMONICS); if (result == MenuRunner::MENU_DELETED) return; diff --git a/ui/views/controls/button/button_dropdown.h b/ui/views/controls/button/button_dropdown.h index 2842b04..f0a18fa 100644 --- a/ui/views/controls/button/button_dropdown.h +++ b/ui/views/controls/button/button_dropdown.h @@ -54,7 +54,8 @@ class VIEWS_EXPORT ButtonDropDown : public ImageButton, // Overridden from views::ContextMenuController virtual void ShowContextMenuForView(View* source, - const gfx::Point& point) OVERRIDE; + const gfx::Point& point, + ui::MenuSourceType source_type) OVERRIDE; protected: // Overridden from CustomButton. Returns true if the button should become @@ -67,7 +68,7 @@ class VIEWS_EXPORT ButtonDropDown : public ImageButton, virtual bool ShouldShowMenu(); // Function to show the dropdown menu. - virtual void ShowDropDownMenu(); + virtual void ShowDropDownMenu(ui::MenuSourceType source_type); private: // The model that populates the attached menu. diff --git a/ui/views/controls/button/custom_button.cc b/ui/views/controls/button/custom_button.cc index afb50bc..92e0a8e 100644 --- a/ui/views/controls/button/custom_button.cc +++ b/ui/views/controls/button/custom_button.cc @@ -247,7 +247,8 @@ bool CustomButton::AcceleratorPressed(const ui::Accelerator& accelerator) { return true; } -void CustomButton::ShowContextMenu(const gfx::Point& p, bool is_mouse_gesture) { +void CustomButton::ShowContextMenu(const gfx::Point& p, + ui::MenuSourceType source_type) { if (!context_menu_controller()) return; @@ -255,7 +256,7 @@ void CustomButton::ShowContextMenu(const gfx::Point& p, bool is_mouse_gesture) { // we won't get a mouse exited and reset state. Reset it now to be sure. if (state_ != STATE_DISABLED) SetState(STATE_NORMAL); - View::ShowContextMenu(p, is_mouse_gesture); + View::ShowContextMenu(p, source_type); } void CustomButton::OnDragDone() { diff --git a/ui/views/controls/button/custom_button.h b/ui/views/controls/button/custom_button.h index 7134502..37942a2 100644 --- a/ui/views/controls/button/custom_button.h +++ b/ui/views/controls/button/custom_button.h @@ -84,7 +84,7 @@ class VIEWS_EXPORT CustomButton : public Button, virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; virtual void ShowContextMenu(const gfx::Point& p, - bool is_mouse_gesture) OVERRIDE; + ui::MenuSourceType source_type) OVERRIDE; virtual void OnDragDone() OVERRIDE; virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; virtual void VisibilityChanged(View* starting_from, bool is_visible) OVERRIDE; diff --git a/ui/views/controls/combobox/native_combobox_views.cc b/ui/views/controls/combobox/native_combobox_views.cc index 791598b..8ef1efa 100644 --- a/ui/views/controls/combobox/native_combobox_views.cc +++ b/ui/views/controls/combobox/native_combobox_views.cc @@ -99,7 +99,7 @@ bool NativeComboboxViews::OnMousePressed(const ui::MouseEvent& mouse_event) { combobox_->RequestFocus(); if (mouse_event.IsLeftMouseButton()) { UpdateFromModel(); - ShowDropDownMenu(); + ShowDropDownMenu(ui::MENU_SOURCE_MOUSE); } return true; @@ -181,7 +181,7 @@ void NativeComboboxViews::OnBlur() { void NativeComboboxViews::OnGestureEvent(ui::GestureEvent* gesture) { if (gesture->type() == ui::ET_GESTURE_TAP) { UpdateFromModel(); - ShowDropDownMenu(); + ShowDropDownMenu(ui::MENU_SOURCE_TOUCH); gesture->StopPropagation(); return; } @@ -368,7 +368,7 @@ void NativeComboboxViews::PaintText(gfx::Canvas* canvas) { canvas->Restore(); } -void NativeComboboxViews::ShowDropDownMenu() { +void NativeComboboxViews::ShowDropDownMenu(ui::MenuSourceType source_type) { if (!dropdown_list_menu_runner_.get()) UpdateFromModel(); @@ -397,7 +397,8 @@ void NativeComboboxViews::ShowDropDownMenu() { dropdown_open_ = true; if (dropdown_list_menu_runner_->RunMenuAt( GetWidget(), NULL, bounds, MenuItemView::TOPLEFT, - MenuRunner::HAS_MNEMONICS) == MenuRunner::MENU_DELETED) + source_type, MenuRunner::HAS_MNEMONICS) == + MenuRunner::MENU_DELETED) return; dropdown_open_ = false; diff --git a/ui/views/controls/combobox/native_combobox_views.h b/ui/views/controls/combobox/native_combobox_views.h index 18f636c..3384b8a 100644 --- a/ui/views/controls/combobox/native_combobox_views.h +++ b/ui/views/controls/combobox/native_combobox_views.h @@ -73,7 +73,7 @@ class NativeComboboxViews : public views::View, void PaintText(gfx::Canvas* canvas); // Show the drop down list - void ShowDropDownMenu(); + void ShowDropDownMenu(ui::MenuSourceType source_type); // The parent combobox, the owner of this object. Combobox* combobox_; diff --git a/ui/views/controls/menu/menu_controller.cc b/ui/views/controls/menu/menu_controller.cc index 86cd597..f6c2abd 100644 --- a/ui/views/controls/menu/menu_controller.cc +++ b/ui/views/controls/menu/menu_controller.cc @@ -4,6 +4,10 @@ #include "ui/views/controls/menu/menu_controller.h" +#if defined(OS_WIN) +#include <windowsx.h> +#endif + #include "base/i18n/case_conversion.h" #include "base/i18n/rtl.h" #include "base/run_loop.h" @@ -490,7 +494,8 @@ void MenuController::OnMouseReleased(SubmenuView* source, == views::MenuItemView::kEmptyMenuItemViewID) menu = part.parent; - if (menu != NULL && ShowContextMenu(menu, source, event)) + if (menu != NULL && ShowContextMenu(menu, source, event, + ui::MENU_SOURCE_MOUSE)) return; } @@ -554,7 +559,7 @@ void MenuController::OnGestureEvent(SubmenuView* source, event->StopPropagation(); } else if (event->type() == ui::ET_GESTURE_LONG_PRESS) { if (part.type == MenuPart::MENU_ITEM && part.menu) { - if (ShowContextMenu(part.menu, source, *event)) + if (ShowContextMenu(part.menu, source, *event, ui::MENU_SOURCE_TOUCH)) event->StopPropagation(); } } else if (event->type() == ui::ET_GESTURE_TAP) { @@ -957,8 +962,11 @@ bool MenuController::Dispatch(const MSG& msg) { if (item && item->GetRootMenuItem() != item) { gfx::Point screen_loc(0, item->height()); View::ConvertPointToScreen(item, &screen_loc); + ui::MenuSourceType source_type = ui::MENU_SOURCE_MOUSE; + if (GET_X_LPARAM(msg.lParam) == -1 && GET_Y_LPARAM(msg.lParam) == -1) + source_type = ui::MENU_SOURCE_KEYBOARD; item->GetDelegate()->ShowContextMenu(item, item->GetCommand(), - screen_loc, false); + screen_loc, source_type); } return true; } @@ -1270,7 +1278,8 @@ bool MenuController::ShowSiblingMenu(SubmenuView* source, bool MenuController::ShowContextMenu(MenuItemView* menu_item, SubmenuView* source, - const ui::LocatedEvent& event) { + const ui::LocatedEvent& event, + ui::MenuSourceType source_type) { // Set the selection immediately, making sure the submenu is only open // if it already was. int selection_types = SELECTION_UPDATE_IMMEDIATELY; @@ -1281,7 +1290,7 @@ bool MenuController::ShowContextMenu(MenuItemView* menu_item, View::ConvertPointToScreen(source->GetScrollViewContainer(), &loc); if (menu_item->GetDelegate()->ShowContextMenu( - menu_item, menu_item->GetCommand(), loc, true)) { + menu_item, menu_item->GetCommand(), loc, source_type)) { SendMouseCaptureLostToActiveView(); return true; } diff --git a/ui/views/controls/menu/menu_controller.h b/ui/views/controls/menu/menu_controller.h index 8f0a847..45f38e5 100644 --- a/ui/views/controls/menu/menu_controller.h +++ b/ui/views/controls/menu/menu_controller.h @@ -291,7 +291,8 @@ class VIEWS_EXPORT MenuController : public base::MessageLoop::Dispatcher, // button. Returns whether a context menu was shown. bool ShowContextMenu(MenuItemView* menu_item, SubmenuView* source, - const ui::LocatedEvent& event); + const ui::LocatedEvent& event, + ui::MenuSourceType source_type); // Closes all menus, including any menus of nested invocations of Run. void CloseAllNestedMenus(); diff --git a/ui/views/controls/menu/menu_delegate.cc b/ui/views/controls/menu/menu_delegate.cc index cced8f2..90ab5cb 100644 --- a/ui/views/controls/menu/menu_delegate.cc +++ b/ui/views/controls/menu/menu_delegate.cc @@ -45,7 +45,7 @@ bool MenuDelegate::GetAccelerator(int id, ui::Accelerator* accelerator) { bool MenuDelegate::ShowContextMenu(MenuItemView* source, int id, const gfx::Point& p, - bool is_mouse_gesture) { + ui::MenuSourceType source_type) { return false; } diff --git a/ui/views/controls/menu/menu_delegate.h b/ui/views/controls/menu/menu_delegate.h index f530642..f171d57 100644 --- a/ui/views/controls/menu/menu_delegate.h +++ b/ui/views/controls/menu/menu_delegate.h @@ -99,7 +99,7 @@ class VIEWS_EXPORT MenuDelegate { virtual bool ShowContextMenu(MenuItemView* source, int id, const gfx::Point& p, - bool is_mouse_gesture); + ui::MenuSourceType source_type); // Controller virtual bool SupportsCommand(int id) const; diff --git a/ui/views/controls/menu/menu_runner.cc b/ui/views/controls/menu/menu_runner.cc index 1e8256e..3d19c4e 100644 --- a/ui/views/controls/menu/menu_runner.cc +++ b/ui/views/controls/menu/menu_runner.cc @@ -333,6 +333,7 @@ MenuRunner::RunResult MenuRunner::RunMenuAt(Widget* parent, MenuButton* button, const gfx::Rect& bounds, MenuItemView::AnchorPosition anchor, + ui::MenuSourceType source_type, int32 types) { // The parent of the nested menu will have created a DisplayChangeListener, so // we avoid creating a DisplayChangeListener if nested. Drop menus are @@ -341,12 +342,22 @@ MenuRunner::RunResult MenuRunner::RunMenuAt(Widget* parent, display_change_listener_.reset( internal::DisplayChangeListener::Create(parent, this)); } - if ((types & MenuRunner::CONTEXT_MENU) && - parent && - parent->GetCurrentEvent() && - !MenuItemView::IsBubble(anchor)) - anchor = parent->GetCurrentEvent()->IsGestureEvent() ? - MenuItemView::BOTTOMCENTER : MenuItemView::TOPLEFT; + + if (types & CONTEXT_MENU) { + switch (source_type) { + case ui::MENU_SOURCE_NONE: + case ui::MENU_SOURCE_KEYBOARD: + case ui::MENU_SOURCE_MOUSE: + anchor = MenuItemView::TOPLEFT; + break; + case ui::MENU_SOURCE_TOUCH: + case ui::MENU_SOURCE_TOUCH_EDIT_MENU: + anchor = MenuItemView::BOTTOMCENTER; + break; + default: + break; + } + } return holder_->RunMenuAt(parent, button, bounds, anchor, types); } diff --git a/ui/views/controls/menu/menu_runner.h b/ui/views/controls/menu/menu_runner.h index 2e9a133..0744373 100644 --- a/ui/views/controls/menu/menu_runner.h +++ b/ui/views/controls/menu/menu_runner.h @@ -95,6 +95,7 @@ class VIEWS_EXPORT MenuRunner { MenuButton* button, const gfx::Rect& bounds, MenuItemView::AnchorPosition anchor, + ui::MenuSourceType source_type, int32 types) WARN_UNUSED_RESULT; // Returns true if we're in a nested message loop running the menu. diff --git a/ui/views/controls/native_control.cc b/ui/views/controls/native_control.cc index 687f193..e6219e7 100644 --- a/ui/views/controls/native_control.cc +++ b/ui/views/controls/native_control.cc @@ -269,10 +269,12 @@ void NativeControl::OnContextMenu(const POINT& location) { if (!context_menu_controller()) return; - if (location.x == -1 && location.y == -1) - ShowContextMenu(GetKeyboardContextMenuLocation(), false); - else - ShowContextMenu(gfx::Point(location), true); + if (location.x == -1 && location.y == -1) { + ShowContextMenu(GetKeyboardContextMenuLocation(), + ui::MENU_SOURCE_KEYBOARD); + } else { + ShowContextMenu(gfx::Point(location), ui::MENU_SOURCE_MOUSE); + } } void NativeControl::OnFocus() { diff --git a/ui/views/controls/native_control_win.cc b/ui/views/controls/native_control_win.cc index 1b4f583..2b6c6d4 100644 --- a/ui/views/controls/native_control_win.cc +++ b/ui/views/controls/native_control_win.cc @@ -124,10 +124,12 @@ void NativeControlWin::ShowContextMenu(const gfx::Point& location) { if (!context_menu_controller()) return; - if (location.x() == -1 && location.y() == -1) - View::ShowContextMenu(GetKeyboardContextMenuLocation(), false); - else - View::ShowContextMenu(location, true); + if (location.x() == -1 && location.y() == -1) { + View::ShowContextMenu(GetKeyboardContextMenuLocation(), + ui::MENU_SOURCE_KEYBOARD); + } else { + View::ShowContextMenu(location, ui::MENU_SOURCE_MOUSE); + } } void NativeControlWin::NativeControlCreated(HWND native_control) { diff --git a/ui/views/controls/scrollbar/base_scroll_bar.cc b/ui/views/controls/scrollbar/base_scroll_bar.cc index 64b1d13..bf96a98 100644 --- a/ui/views/controls/scrollbar/base_scroll_bar.cc +++ b/ui/views/controls/scrollbar/base_scroll_bar.cc @@ -273,7 +273,9 @@ enum ScrollBarContextMenuCommands { ScrollBarContextMenuCommand_ScrollNext }; -void BaseScrollBar::ShowContextMenuForView(View* source, const gfx::Point& p) { +void BaseScrollBar::ShowContextMenuForView(View* source, + const gfx::Point& p, + ui::MenuSourceType source_type) { Widget* widget = GetWidget(); gfx::Rect widget_bounds = widget->GetWindowBoundsInScreen(); gfx::Point temp_pt(p.x() - widget_bounds.x(), p.y() - widget_bounds.y()); @@ -294,7 +296,7 @@ void BaseScrollBar::ShowContextMenuForView(View* source, const gfx::Point& p) { menu->AppendDelegateMenuItem(ScrollBarContextMenuCommand_ScrollPrev); menu->AppendDelegateMenuItem(ScrollBarContextMenuCommand_ScrollNext); if (menu_runner_->RunMenuAt(GetWidget(), NULL, gfx::Rect(p, gfx::Size()), - MenuItemView::TOPLEFT, MenuRunner::HAS_MNEMONICS | + views::MenuItemView::TOPLEFT, source_type, MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU) == MenuRunner::MENU_DELETED) return; diff --git a/ui/views/controls/scrollbar/base_scroll_bar.h b/ui/views/controls/scrollbar/base_scroll_bar.h index a62c3d8..a517b6c 100644 --- a/ui/views/controls/scrollbar/base_scroll_bar.h +++ b/ui/views/controls/scrollbar/base_scroll_bar.h @@ -89,7 +89,8 @@ class VIEWS_EXPORT BaseScrollBar : public ScrollBar, // ContextMenuController overrides: virtual void ShowContextMenuForView(View* source, - const gfx::Point& point) OVERRIDE; + const gfx::Point& point, + ui::MenuSourceType source_type) OVERRIDE; // Menu::Delegate overrides: virtual string16 GetLabel(int id) const OVERRIDE; diff --git a/ui/views/controls/textfield/native_textfield_views.cc b/ui/views/controls/textfield/native_textfield_views.cc index a86e5bc..b1f45eb 100644 --- a/ui/views/controls/textfield/native_textfield_views.cc +++ b/ui/views/controls/textfield/native_textfield_views.cc @@ -426,7 +426,7 @@ bool NativeTextfieldViews::DrawsHandles() { void NativeTextfieldViews::OpenContextMenu(const gfx::Point& anchor) { touch_selection_controller_.reset(); - ShowContextMenu(anchor, false); + ShowContextMenu(anchor, ui::MENU_SOURCE_TOUCH_EDIT_MENU); } gfx::NativeCursor NativeTextfieldViews::GetCursor(const ui::MouseEvent& event) { @@ -444,11 +444,14 @@ gfx::NativeCursor NativeTextfieldViews::GetCursor(const ui::MouseEvent& event) { ///////////////////////////////////////////////////////////////// // NativeTextfieldViews, ContextMenuController overrides: -void NativeTextfieldViews::ShowContextMenuForView(View* source, - const gfx::Point& point) { +void NativeTextfieldViews::ShowContextMenuForView( + View* source, + const gfx::Point& point, + ui::MenuSourceType source_type) { UpdateContextMenu(); if (context_menu_runner_->RunMenuAt(GetWidget(), NULL, gfx::Rect(point, gfx::Size()), views::MenuItemView::TOPLEFT, + source_type, MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU) == MenuRunner::MENU_DELETED) return; diff --git a/ui/views/controls/textfield/native_textfield_views.h b/ui/views/controls/textfield/native_textfield_views.h index 7e7dd28..9986a51 100644 --- a/ui/views/controls/textfield/native_textfield_views.h +++ b/ui/views/controls/textfield/native_textfield_views.h @@ -93,7 +93,8 @@ class VIEWS_EXPORT NativeTextfieldViews : public View, // ContextMenuController overrides: virtual void ShowContextMenuForView(View* source, - const gfx::Point& point) OVERRIDE; + const gfx::Point& point, + ui::MenuSourceType source_type) OVERRIDE; // Overridden from DragController: virtual void WriteDragDataForView(View* sender, diff --git a/ui/views/controls/textfield/native_textfield_win.cc b/ui/views/controls/textfield/native_textfield_win.cc index 5dae06f..8866cfe 100644 --- a/ui/views/controls/textfield/native_textfield_win.cc +++ b/ui/views/controls/textfield/native_textfield_win.cc @@ -613,7 +613,9 @@ void NativeTextfieldWin::OnChar(TCHAR ch, UINT repeat_count, UINT flags) { void NativeTextfieldWin::OnContextMenu(HWND window, const POINT& point) { POINT p(point); + ui::MenuSourceType source_type = ui::MENU_SOURCE_MOUSE; if (point.x == -1 || point.y == -1) { + source_type = ui::MENU_SOURCE_KEYBOARD; GetCaretPos(&p); MapWindowPoints(HWND_DESKTOP, &p, 1); } @@ -624,7 +626,7 @@ void NativeTextfieldWin::OnContextMenu(HWND window, const POINT& point) { ignore_result(context_menu_runner_->RunMenuAt(textfield_->GetWidget(), NULL, gfx::Rect(gfx::Point(p), gfx::Size()), MenuItemView::TOPLEFT, - MenuRunner::HAS_MNEMONICS)); + source_type, MenuRunner::HAS_MNEMONICS)); } void NativeTextfieldWin::OnCopy() { diff --git a/ui/views/controls/tree/tree_view.cc b/ui/views/controls/tree/tree_view.cc index e60b9c0..083a585 100644 --- a/ui/views/controls/tree/tree_view.cc +++ b/ui/views/controls/tree/tree_view.cc @@ -380,10 +380,11 @@ void TreeView::OnGestureEvent(ui::GestureEvent* event) { } } -void TreeView::ShowContextMenu(const gfx::Point& p, bool is_mouse_gesture) { +void TreeView::ShowContextMenu(const gfx::Point& p, + ui::MenuSourceType source_type) { if (!model_) return; - if (is_mouse_gesture) { + if (source_type == ui::MENU_SOURCE_MOUSE) { // Only invoke View's implementation (which notifies the // ContextMenuController) if over a node. gfx::Point local_point(p); @@ -397,7 +398,7 @@ void TreeView::ShowContextMenu(const gfx::Point& p, bool is_mouse_gesture) { if (!bounds.Contains(local_point)) return; } - View::ShowContextMenu(p, is_mouse_gesture); + View::ShowContextMenu(p, source_type); } void TreeView::GetAccessibleState(ui::AccessibleViewState* state) { diff --git a/ui/views/controls/tree/tree_view.h b/ui/views/controls/tree/tree_view.h index 295c20b..cca0b33 100644 --- a/ui/views/controls/tree/tree_view.h +++ b/ui/views/controls/tree/tree_view.h @@ -122,7 +122,7 @@ class VIEWS_EXPORT TreeView : public View, virtual ui::TextInputClient* GetTextInputClient() OVERRIDE; virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; virtual void ShowContextMenu(const gfx::Point& p, - bool is_mouse_gesture) OVERRIDE; + ui::MenuSourceType source_type) OVERRIDE; virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; // TreeModelObserver overrides: diff --git a/ui/views/examples/menu_example.cc b/ui/views/examples/menu_example.cc index 5da8d3c..307a6ca 100644 --- a/ui/views/examples/menu_example.cc +++ b/ui/views/examples/menu_example.cc @@ -189,7 +189,8 @@ void ExampleMenuButton::OnMenuButtonClicked(View* source, if (menu_runner_->RunMenuAt(source->GetWidget()->GetTopLevelWidget(), this, gfx::Rect(point, gfx::Size()), MenuItemView::TOPRIGHT, - MenuRunner::HAS_MNEMONICS) == MenuRunner::MENU_DELETED) + ui::MENU_SOURCE_NONE, MenuRunner::HAS_MNEMONICS) == + MenuRunner::MENU_DELETED) return; } diff --git a/ui/views/examples/tree_view_example.cc b/ui/views/examples/tree_view_example.cc index 9d1af4e..a7a51cb 100644 --- a/ui/views/examples/tree_view_example.cc +++ b/ui/views/examples/tree_view_example.cc @@ -123,14 +123,15 @@ bool TreeViewExample::CanEdit(TreeView* tree_view, } void TreeViewExample::ShowContextMenuForView(View* source, - const gfx::Point& point) { + const gfx::Point& point, + ui::MenuSourceType source_type) { ui::SimpleMenuModel context_menu_model(this); context_menu_model.AddItem(ID_EDIT, ASCIIToUTF16("Edit")); context_menu_model.AddItem(ID_REMOVE, ASCIIToUTF16("Remove")); context_menu_model.AddItem(ID_ADD, ASCIIToUTF16("Add")); context_menu_runner_.reset(new MenuRunner(&context_menu_model)); if (context_menu_runner_->RunMenuAt(source->GetWidget(), NULL, - gfx::Rect(point, gfx::Size()), MenuItemView::TOPLEFT, 0) == + gfx::Rect(point, gfx::Size()), MenuItemView::TOPLEFT, source_type, 0) == MenuRunner::MENU_DELETED) return; } diff --git a/ui/views/examples/tree_view_example.h b/ui/views/examples/tree_view_example.h index 74663d1..ffac4dd 100644 --- a/ui/views/examples/tree_view_example.h +++ b/ui/views/examples/tree_view_example.h @@ -56,7 +56,8 @@ class TreeViewExample : public ExampleBase, // ContextMenuController: virtual void ShowContextMenuForView(View* source, - const gfx::Point& point) OVERRIDE; + const gfx::Point& point, + ui::MenuSourceType source_type) OVERRIDE; // SimpleMenuModel::Delegate: virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; diff --git a/ui/views/view.cc b/ui/views/view.cc index d897859..637fcf8 100644 --- a/ui/views/view.cc +++ b/ui/views/view.cc @@ -137,7 +137,7 @@ class PostEventDispatchHandler : public ui::EventHandler { event->type() == ui::ET_GESTURE_TWO_FINGER_TAP)) { gfx::Point location(event->location()); View::ConvertPointToScreen(owner_, &location); - owner_->ShowContextMenu(location, true); + owner_->ShowContextMenu(location, ui::MENU_SOURCE_TOUCH); event->StopPropagation(); } } @@ -1148,11 +1148,12 @@ bool View::GetTooltipTextOrigin(const gfx::Point& p, gfx::Point* loc) const { // Context menus --------------------------------------------------------------- -void View::ShowContextMenu(const gfx::Point& p, bool is_mouse_gesture) { +void View::ShowContextMenu(const gfx::Point& p, + ui::MenuSourceType source_type) { if (!context_menu_controller_) return; - context_menu_controller_->ShowContextMenuForView(this, p); + context_menu_controller_->ShowContextMenuForView(this, p, source_type); } // static @@ -2117,7 +2118,7 @@ bool View::ProcessMousePressed(const ui::MouseEvent& event) { gfx::Point location(event.location()); if (HitTestPoint(location)) { ConvertPointToScreen(this, &location); - ShowContextMenu(location, true); + ShowContextMenu(location, ui::MENU_SOURCE_MOUSE); return true; } } @@ -2160,7 +2161,7 @@ void View::ProcessMouseReleased(const ui::MouseEvent& event) { OnMouseReleased(event); if (HitTestPoint(location)) { ConvertPointToScreen(this, &location); - ShowContextMenu(location, true); + ShowContextMenu(location, ui::MENU_SOURCE_MOUSE); } } else { OnMouseReleased(event); diff --git a/ui/views/view.h b/ui/views/view.h index 4b10f0c..2e3420b 100644 --- a/ui/views/view.h +++ b/ui/views/view.h @@ -22,6 +22,7 @@ #include "ui/base/dragdrop/os_exchange_data.h" #include "ui/base/events/event.h" #include "ui/base/events/event_target.h" +#include "ui/base/ui_base_types.h" #include "ui/compositor/layer_delegate.h" #include "ui/compositor/layer_owner.h" #include "ui/gfx/native_widget_types.h" @@ -826,7 +827,8 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, // to provide right-click menu display triggerd by the keyboard (i.e. for the // Chrome toolbar Back and Forward buttons). No source needs to be specified, // as it is always equal to the current View. - virtual void ShowContextMenu(const gfx::Point& p, bool is_mouse_gesture); + virtual void ShowContextMenu(const gfx::Point& p, + ui::MenuSourceType source_type); // On some platforms, we show context menu on mouse press instead of release. // This method returns true for those platforms. diff --git a/ui/views/widget/root_view.cc b/ui/views/widget/root_view.cc index a82e22c..98bf6e6 100644 --- a/ui/views/widget/root_view.cc +++ b/ui/views/widget/root_view.cc @@ -117,7 +117,8 @@ void RootView::DispatchKeyEvent(ui::KeyEvent* event) { // keyboard. if (v && v->enabled() && ((event->key_code() == ui::VKEY_APPS) || (event->key_code() == ui::VKEY_F10 && event->IsShiftDown()))) { - v->ShowContextMenu(v->GetKeyboardContextMenuLocation(), false); + v->ShowContextMenu(v->GetKeyboardContextMenuLocation(), + ui::MENU_SOURCE_KEYBOARD); event->StopPropagation(); return; } |