diff options
Diffstat (limited to 'ash')
-rw-r--r-- | ash/launcher/launcher_view.cc | 55 | ||||
-rw-r--r-- | ash/launcher/launcher_view.h | 13 |
2 files changed, 49 insertions, 19 deletions
diff --git a/ash/launcher/launcher_view.cc b/ash/launcher/launcher_view.cc index 667559b..c2fa2cc 100644 --- a/ash/launcher/launcher_view.cc +++ b/ash/launcher/launcher_view.cc @@ -17,6 +17,7 @@ #include "ash/launcher/overflow_bubble.h" #include "ash/launcher/overflow_button.h" #include "ash/launcher/tabbed_launcher_button.h" +#include "ash/root_window_controller.h" #include "ash/shell_delegate.h" #include "ash/wm/shelf_layout_manager.h" #include "base/auto_reset.h" @@ -1223,8 +1224,7 @@ void LauncherView::ButtonPressed(views::Button* sender, if (!call_object_handler) { // ShowListMenuForView only returns true if the menu was shown. if (ShowListMenuForView(model_->items()[view_index], - sender, - sender->GetBoundsInScreen().CenterPoint())) { + sender)) { // When the menu was shown it is possible that this got deleted. return; } @@ -1257,8 +1257,7 @@ void LauncherView::ButtonPressed(views::Button* sender, } bool LauncherView::ShowListMenuForView(const LauncherItem& item, - views::View* source, - const gfx::Point& point) { + views::View* source) { scoped_ptr<ui::MenuModel> menu_model; menu_model.reset(delegate_->CreateApplicationMenu(item)); @@ -1267,7 +1266,7 @@ bool LauncherView::ShowListMenuForView(const LauncherItem& item, if (!menu_model.get() || menu_model->GetItemCount() <= 1) return false; - ShowMenu(menu_model.get(), source, point); + ShowMenu(menu_model.get(), source, false); return true; } @@ -1292,21 +1291,53 @@ void LauncherView::ShowContextMenuForView(views::View* source, &context_menu_id_, view_index == -1 ? 0 : model_->items()[view_index].id); - ShowMenu(menu_model.get(), source, point); + ShowMenu(menu_model.get(), source, true); } void LauncherView::ShowMenu(ui::MenuModel* menu_model, views::View* source, - const gfx::Point& point) { - LauncherMenuModelAdapter menu_model_adapter(menu_model); + bool context_menu) { + launcher_menu_runner_.reset(); + scoped_ptr<views::MenuModelAdapter> menu_model_adapter; + if (context_menu) + menu_model_adapter.reset(new views::MenuModelAdapter(menu_model)); + else + menu_model_adapter.reset(new LauncherMenuModelAdapter(menu_model)); + launcher_menu_runner_.reset( - new views::MenuRunner(menu_model_adapter.CreateMenu())); + new views::MenuRunner(menu_model_adapter->CreateMenu())); + + // Determine the menu alignment dependent on the shelf. + views::MenuItemView::AnchorPosition menu_alignment = + views::MenuItemView::TOPLEFT; + + ash::ShelfAlignment align = RootWindowController::ForLauncher( + GetWidget()->GetNativeView())->shelf()->GetAlignment(); + + switch (align) { + case ash::SHELF_ALIGNMENT_BOTTOM: + menu_alignment = views::MenuItemView::BUBBLE_ABOVE; + break; + case ash::SHELF_ALIGNMENT_LEFT: + menu_alignment = views::MenuItemView::BUBBLE_RIGHT; + break; + case ash::SHELF_ALIGNMENT_RIGHT: + menu_alignment = views::MenuItemView::BUBBLE_LEFT; + break; + case ash::SHELF_ALIGNMENT_TOP: + menu_alignment = views::MenuItemView::BUBBLE_BELOW; + break; + } + const gfx::Rect anchor_point = source->GetBoundsInScreen(); + // NOTE: if you convert to HAS_MNEMONICS be sure and update menu building // code. if (launcher_menu_runner_->RunMenuAt( - source->GetWidget(), NULL, gfx::Rect(point, gfx::Size()), - views::MenuItemView::TOPLEFT, views::MenuRunner::CONTEXT_MENU) == - views::MenuRunner::MENU_DELETED) + source->GetWidget(), + NULL, + anchor_point, + menu_alignment, + views::MenuRunner::CONTEXT_MENU) == views::MenuRunner::MENU_DELETED) return; Shell::GetInstance()->UpdateShelfVisibility(); diff --git a/ash/launcher/launcher_view.h b/ash/launcher/launcher_view.h index 0e57169..9ebed0a 100644 --- a/ash/launcher/launcher_view.h +++ b/ash/launcher/launcher_view.h @@ -220,21 +220,20 @@ class ASH_EXPORT LauncherView : public views::View, // Show the list of all running items for this |item|. It will return true // when the menu was shown and false if there were no possible items to // choose from. |source| specifies the view which is responsible for showing - // the menu and |point| is the origin for the point. - // TODO(skuhne): Depending on the menu type we use in the end (hover vs. - // click), |point| might become obsolete. + // the menu, and the bubble will point towards it. bool ShowListMenuForView(const LauncherItem& item, - views::View* source, - const gfx::Point& point); + views::View* source); // Overridden from views::ContextMenuController: virtual void ShowContextMenuForView(views::View* source, const gfx::Point& point) OVERRIDE; // Show either a context or normal click menu of given |menu_model|. + // If |context_menu| is set, the displayed menu is a context menu and not + // a menu listing one or more running applications. void ShowMenu(ui::MenuModel* menu_model, - views::View*source, - const gfx::Point& point); + views::View* source, + bool context_menu); // Overridden from views::BoundsAnimatorObserver: virtual void OnBoundsAnimatorProgressed( |