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 /ash | |
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 'ash')
-rw-r--r-- | ash/desktop_background/desktop_background_view.cc | 8 | ||||
-rw-r--r-- | ash/desktop_background/desktop_background_view.h | 3 | ||||
-rw-r--r-- | ash/launcher/launcher.cc | 4 | ||||
-rw-r--r-- | ash/launcher/launcher.h | 3 | ||||
-rw-r--r-- | ash/launcher/launcher_button.cc | 4 | ||||
-rw-r--r-- | ash/launcher/launcher_button.h | 2 | ||||
-rw-r--r-- | ash/launcher/launcher_unittest.cc | 2 | ||||
-rw-r--r-- | ash/launcher/launcher_view.cc | 24 | ||||
-rw-r--r-- | ash/launcher/launcher_view.h | 8 | ||||
-rw-r--r-- | ash/root_window_controller.cc | 7 | ||||
-rw-r--r-- | ash/root_window_controller.h | 4 | ||||
-rw-r--r-- | ash/shell.cc | 5 | ||||
-rw-r--r-- | ash/shell.h | 4 | ||||
-rw-r--r-- | ash/shell/window_type_launcher.cc | 10 | ||||
-rw-r--r-- | ash/shell/window_type_launcher.h | 3 | ||||
-rw-r--r-- | ash/system/web_notification/web_notification_tray.cc | 5 | ||||
-rw-r--r-- | ash/system/web_notification/web_notification_tray.h | 2 |
17 files changed, 57 insertions, 41 deletions
diff --git a/ash/desktop_background/desktop_background_view.cc b/ash/desktop_background/desktop_background_view.cc index 141ad47..e27a183 100644 --- a/ash/desktop_background/desktop_background_view.cc +++ b/ash/desktop_background/desktop_background_view.cc @@ -170,9 +170,11 @@ bool DesktopBackgroundView::OnMousePressed(const ui::MouseEvent& event) { return true; } -void DesktopBackgroundView::ShowContextMenuForView(views::View* source, - const gfx::Point& point) { - Shell::GetInstance()->ShowContextMenu(point); +void DesktopBackgroundView::ShowContextMenuForView( + views::View* source, + const gfx::Point& point, + ui::MenuSourceType source_type) { + Shell::GetInstance()->ShowContextMenu(point, source_type); } views::Widget* CreateDesktopBackground(aura::RootWindow* root_window, diff --git a/ash/desktop_background/desktop_background_view.h b/ash/desktop_background/desktop_background_view.h index 8528e77..dbd3320 100644 --- a/ash/desktop_background/desktop_background_view.h +++ b/ash/desktop_background/desktop_background_view.h @@ -25,7 +25,8 @@ class DesktopBackgroundView : public views::View, // Overridden from views::ContextMenuController: virtual void ShowContextMenuForView(views::View* source, - const gfx::Point& point) OVERRIDE; + const gfx::Point& point, + ui::MenuSourceType source_type) OVERRIDE; DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundView); }; diff --git a/ash/launcher/launcher.cc b/ash/launcher/launcher.cc index 335029a..8991c35 100644 --- a/ash/launcher/launcher.cc +++ b/ash/launcher/launcher.cc @@ -130,10 +130,6 @@ bool Launcher::IsShowingMenu() const { return launcher_view_->IsShowingMenu(); } -void Launcher::ShowContextMenu(const gfx::Point& location) { - launcher_view_->ShowContextMenu(location, false); -} - bool Launcher::IsShowingOverflowBubble() const { return launcher_view_->IsShowingOverflowBubble(); } diff --git a/ash/launcher/launcher.h b/ash/launcher/launcher.h index 7d7f3cd..caeb63f 100644 --- a/ash/launcher/launcher.h +++ b/ash/launcher/launcher.h @@ -80,9 +80,6 @@ class ASH_EXPORT Launcher { // Returns true if the Launcher is showing a context menu. bool IsShowingMenu() const; - // Show the context menu for the Launcher. - void ShowContextMenu(const gfx::Point& location); - bool IsShowingOverflowBubble() const; void SetVisible(bool visible) const; diff --git a/ash/launcher/launcher_button.cc b/ash/launcher/launcher_button.cc index 8c15a22..f275b0a 100644 --- a/ash/launcher/launcher_button.cc +++ b/ash/launcher/launcher_button.cc @@ -327,14 +327,14 @@ gfx::Rect LauncherButton::GetIconBounds() const { } void LauncherButton::ShowContextMenu(const gfx::Point& p, - bool is_mouse_gesture) { + ui::MenuSourceType source_type) { if (!context_menu_controller()) return; bool destroyed = false; destroyed_flag_ = &destroyed; - CustomButton::ShowContextMenu(p, is_mouse_gesture); + CustomButton::ShowContextMenu(p, source_type); if (!destroyed) { destroyed_flag_ = NULL; diff --git a/ash/launcher/launcher_button.h b/ash/launcher/launcher_button.h index 41169e8..707aac0 100644 --- a/ash/launcher/launcher_button.h +++ b/ash/launcher/launcher_button.h @@ -59,7 +59,7 @@ class ASH_EXPORT LauncherButton : public views::CustomButton { // Overrides to views::CustomButton: virtual void ShowContextMenu(const gfx::Point& p, - bool is_mouse_gesture) OVERRIDE; + ui::MenuSourceType source_type) OVERRIDE; protected: LauncherButton(views::ButtonListener* listener, diff --git a/ash/launcher/launcher_unittest.cc b/ash/launcher/launcher_unittest.cc index 59d6a67..b1798e3 100644 --- a/ash/launcher/launcher_unittest.cc +++ b/ash/launcher/launcher_unittest.cc @@ -75,7 +75,7 @@ TEST_F(LauncherTest, checkHoverAfterMenu) { ASSERT_EQ(++button_count, test.GetButtonCount()); LauncherButton* button = test.GetButton(index); button->AddState(LauncherButton::STATE_HOVERED); - button->ShowContextMenu(gfx::Point(), true); + button->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); EXPECT_FALSE(button->state() & LauncherButton::STATE_HOVERED); // Remove it. diff --git a/ash/launcher/launcher_view.cc b/ash/launcher/launcher_view.cc index 0d1f898..70292f2 100644 --- a/ash/launcher/launcher_view.cc +++ b/ash/launcher/launcher_view.cc @@ -1498,14 +1498,14 @@ void LauncherView::ButtonPressed(views::Button* sender, } if (model_->items()[view_index].type != TYPE_APP_LIST) - ShowListMenuForView(model_->items()[view_index], sender, event.flags()); + ShowListMenuForView(model_->items()[view_index], sender, event); } bool LauncherView::ShowListMenuForView(const LauncherItem& item, views::View* source, - int event_flags) { + const ui::Event& event) { scoped_ptr<ash::LauncherMenuModel> menu_model; - menu_model.reset(delegate_->CreateApplicationMenu(item, event_flags)); + menu_model.reset(delegate_->CreateApplicationMenu(item, event.flags())); // Make sure we have a menu and it has at least two items in addition to the // application title and the 3 spacing separators. @@ -1516,12 +1516,14 @@ bool LauncherView::ShowListMenuForView(const LauncherItem& item, new LauncherMenuModelAdapter(menu_model.get())), source, gfx::Point(), - false); + false, + ui::GetMenuSourceTypeForEvent(event)); return true; } void LauncherView::ShowContextMenuForView(views::View* source, - const gfx::Point& point) { + const gfx::Point& point, + ui:: MenuSourceType source_type) { int view_index = view_model_->GetIndexOfView(source); if (view_index != -1 && model_->items()[view_index].type == TYPE_APP_LIST) { @@ -1531,7 +1533,7 @@ void LauncherView::ShowContextMenuForView(views::View* source, tooltip_->Close(); if (view_index == -1) { - Shell::GetInstance()->ShowContextMenu(point); + Shell::GetInstance()->ShowContextMenu(point, source_type); return; } scoped_ptr<ui::MenuModel> menu_model(delegate_->CreateContextMenu( @@ -1547,14 +1549,16 @@ void LauncherView::ShowContextMenuForView(views::View* source, new views::MenuModelAdapter(menu_model.get())), source, point, - true); + true, + source_type); } void LauncherView::ShowMenu( scoped_ptr<views::MenuModelAdapter> menu_model_adapter, views::View* source, const gfx::Point& click_point, - bool context_menu) { + bool context_menu, + ui::MenuSourceType source_type) { closing_event_time_ = base::TimeDelta(); launcher_menu_runner_.reset( new views::MenuRunner(menu_model_adapter->CreateMenu())); @@ -1612,7 +1616,9 @@ void LauncherView::ShowMenu( NULL, anchor_point, menu_alignment, - views::MenuRunner::CONTEXT_MENU) == views::MenuRunner::MENU_DELETED) { + source_type, + context_menu ? views::MenuRunner::CONTEXT_MENU : 0) == + views::MenuRunner::MENU_DELETED) { if (!got_deleted) { got_deleted_ = NULL; shelf->ForceUndimming(false); diff --git a/ash/launcher/launcher_view.h b/ash/launcher/launcher_view.h index 0bee1c9..aa59f1e 100644 --- a/ash/launcher/launcher_view.h +++ b/ash/launcher/launcher_view.h @@ -243,11 +243,12 @@ class ASH_EXPORT LauncherView : public views::View, // The |event_flags| are the flags of the event which triggered this menu. bool ShowListMenuForView(const LauncherItem& item, views::View* source, - int event_flags); + const ui::Event& event); // Overridden from views::ContextMenuController: virtual void ShowContextMenuForView(views::View* source, - const gfx::Point& point) OVERRIDE; + const gfx::Point& point, + ui::MenuSourceType source_type) OVERRIDE; // Show either a context or normal click menu of given |menu_model_adapter|. // If |context_menu| is set, the displayed menu is a context menu and not @@ -256,7 +257,8 @@ class ASH_EXPORT LauncherView : public views::View, void ShowMenu(scoped_ptr<views::MenuModelAdapter> menu_model_adapter, views::View* source, const gfx::Point& click_point, - bool context_menu); + bool context_menu, + ui::MenuSourceType source_type); // Overridden from views::BoundsAnimatorObserver: virtual void OnBoundsAnimatorProgressed( diff --git a/ash/root_window_controller.cc b/ash/root_window_controller.cc index 8e1d400..af6e946 100644 --- a/ash/root_window_controller.cc +++ b/ash/root_window_controller.cc @@ -426,8 +426,8 @@ SystemTray* RootWindowController::GetSystemTray() { return shelf_->status_area_widget()->system_tray(); } -void RootWindowController::ShowContextMenu( - const gfx::Point& location_in_screen) { +void RootWindowController::ShowContextMenu(const gfx::Point& location_in_screen, + ui::MenuSourceType source_type) { DCHECK(Shell::GetInstance()->delegate()); scoped_ptr<ui::MenuModel> menu_model( Shell::GetInstance()->delegate()->CreateContextMenu(root_window())); @@ -444,7 +444,8 @@ void RootWindowController::ShowContextMenu( views::MenuRunner menu_runner(menu_model.get()); if (menu_runner.RunMenuAt(background->widget(), NULL, gfx::Rect(location_in_screen, gfx::Size()), - views::MenuItemView::TOPLEFT, views::MenuRunner::CONTEXT_MENU) == + views::MenuItemView::TOPLEFT, source_type, + views::MenuRunner::CONTEXT_MENU) == views::MenuRunner::MENU_DELETED) { return; } diff --git a/ash/root_window_controller.h b/ash/root_window_controller.h index 79c5f5e..2c02b20 100644 --- a/ash/root_window_controller.h +++ b/ash/root_window_controller.h @@ -10,6 +10,7 @@ #include "ash/system/user/login_status.h" #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" +#include "ui/base/ui_base_types.h" class SkBitmap; @@ -108,7 +109,8 @@ class ASH_EXPORT RootWindowController { // Shows context menu at the |location_in_screen|. This uses // |ShellDelegate::CreateContextMenu| to define the content of the menu. - void ShowContextMenu(const gfx::Point& location_in_screen); + void ShowContextMenu(const gfx::Point& location_in_screen, + ui::MenuSourceType source_type); // Returns the layout-manager for the appropriate modal-container. If the // window is inside the lockscreen modal container, then the layout manager diff --git a/ash/shell.cc b/ash/shell.cc index 1cc177f..1bda4db 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -621,7 +621,8 @@ void Shell::Init() { } } -void Shell::ShowContextMenu(const gfx::Point& location_in_screen) { +void Shell::ShowContextMenu(const gfx::Point& location_in_screen, + ui::MenuSourceType source_type) { // No context menus if there is no session with an active user. if (!session_state_delegate_->NumberOfLoggedInUsers()) return; @@ -639,7 +640,7 @@ void Shell::ShowContextMenu(const gfx::Point& location_in_screen) { CHECK(rwc) << "root=" << root << ", location:" << location_in_screen.ToString(); if (rwc) - rwc->ShowContextMenu(location_in_screen); + rwc->ShowContextMenu(location_in_screen, source_type); } void Shell::ToggleAppList(aura::Window* window) { diff --git a/ash/shell.h b/ash/shell.h index a420293..f8649dc 100644 --- a/ash/shell.h +++ b/ash/shell.h @@ -19,6 +19,7 @@ #include "base/observer_list.h" #include "ui/aura/client/activation_change_observer.h" #include "ui/base/events/event_target.h" +#include "ui/base/ui_base_types.h" #include "ui/gfx/insets.h" #include "ui/gfx/screen.h" #include "ui/gfx/size.h" @@ -211,7 +212,8 @@ class ASH_EXPORT Shell // Shows the context menu for the background and launcher at // |location_in_screen| (in screen coordinates). - void ShowContextMenu(const gfx::Point& location_in_screen); + void ShowContextMenu(const gfx::Point& location_in_screen, + ui::MenuSourceType source_type); // Toggles the app list. |window| specifies in which display the app // list should be shown. If this is NULL, the active root window diff --git a/ash/shell/window_type_launcher.cc b/ash/shell/window_type_launcher.cc index f87250d..4bfe453 100644 --- a/ash/shell/window_type_launcher.cc +++ b/ash/shell/window_type_launcher.cc @@ -388,8 +388,10 @@ void WindowTypeLauncher::ExecuteCommand(int id, int event_flags) { #endif // !defined(OS_MACOSX) #if !defined(OS_MACOSX) -void WindowTypeLauncher::ShowContextMenuForView(views::View* source, - const gfx::Point& point) { +void WindowTypeLauncher::ShowContextMenuForView( + views::View* source, + const gfx::Point& point, + ui::MenuSourceType source_type) { MenuItemView* root = new MenuItemView(this); root->AppendMenuItem(COMMAND_NEW_WINDOW, ASCIIToUTF16("New Window"), @@ -399,8 +401,10 @@ void WindowTypeLauncher::ShowContextMenuForView(views::View* source, MenuItemView::NORMAL); // MenuRunner takes ownership of root. menu_runner_.reset(new MenuRunner(root)); - if (menu_runner_->RunMenuAt(GetWidget(), NULL, gfx::Rect(point, gfx::Size()), + if (menu_runner_->RunMenuAt(GetWidget(), NULL, + gfx::Rect(point, gfx::Size()), MenuItemView::TOPLEFT, + source_type, MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU) == MenuRunner::MENU_DELETED) return; diff --git a/ash/shell/window_type_launcher.h b/ash/shell/window_type_launcher.h index de2159e..29d703d 100644 --- a/ash/shell/window_type_launcher.h +++ b/ash/shell/window_type_launcher.h @@ -61,7 +61,8 @@ class WindowTypeLauncher : public views::WidgetDelegateView, // Override from views::ContextMenuController: virtual void ShowContextMenuForView(views::View* source, - const gfx::Point& point) OVERRIDE; + const gfx::Point& point, + ui::MenuSourceType source_type) OVERRIDE; #endif // !defined(OS_MACOSX) views::LabelButton* create_button_; diff --git a/ash/system/web_notification/web_notification_tray.cc b/ash/system/web_notification/web_notification_tray.cc index c428bea..9579442 100644 --- a/ash/system/web_notification/web_notification_tray.cc +++ b/ash/system/web_notification/web_notification_tray.cc @@ -302,7 +302,7 @@ bool WebNotificationTray::ShouldShowMessageCenter() { status_area_widget()->system_tray()->HasNotificationBubble()); } -void WebNotificationTray::ShowQuietModeMenu() { +void WebNotificationTray::ShowQuietModeMenu(const ui::Event& event) { base::AutoReset<bool> reset(&should_block_shelf_auto_hide_, true); scoped_ptr<ui::MenuModel> menu_model( message_center_tray_->CreateQuietModeMenu()); @@ -314,6 +314,7 @@ void WebNotificationTray::ShowQuietModeMenu() { NULL, gfx::Rect(point, bounds().size()), views::MenuItemView::BUBBLE_ABOVE, + ui::GetMenuSourceTypeForEvent(event), views::MenuRunner::HAS_MNEMONICS) == views::MenuRunner::MENU_DELETED) return; @@ -410,7 +411,7 @@ void WebNotificationTray::HideBubbleWithView( bool WebNotificationTray::PerformAction(const ui::Event& event) { if (ShouldShowQuietModeMenu(event)) { - ShowQuietModeMenu(); + ShowQuietModeMenu(event); return true; } diff --git a/ash/system/web_notification/web_notification_tray.h b/ash/system/web_notification/web_notification_tray.h index 8b3aff8..df7a663 100644 --- a/ash/system/web_notification/web_notification_tray.h +++ b/ash/system/web_notification/web_notification_tray.h @@ -126,7 +126,7 @@ class ASH_EXPORT WebNotificationTray bool ShouldShowQuietModeMenu(const ui::Event& event); // Shows the quiet mode menu. - void ShowQuietModeMenu(); + void ShowQuietModeMenu(const ui::Event& event); internal::WebNotificationBubbleWrapper* message_center_bubble() const { return message_center_bubble_.get(); |