summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authormsw <msw@chromium.org>2016-03-03 16:55:30 -0800
committerCommit bot <commit-bot@chromium.org>2016-03-04 00:56:52 +0000
commit141c6b246d3cbb3212f76602ca40915c152af89a (patch)
tree868d70ec80d26dbf91ccda25ef1d295947a04c3b /ash
parent243b2e8fb9cdd09cf9ec11aa2a68e26c76e00ee7 (diff)
downloadchromium_src-141c6b246d3cbb3212f76602ca40915c152af89a.zip
chromium_src-141c6b246d3cbb3212f76602ca40915c152af89a.tar.gz
chromium_src-141c6b246d3cbb3212f76602ca40915c152af89a.tar.bz2
Simplify ash context menu creation.
Remove ash::ShelfItemDelegate::CreateContextMenu. Use ash::ShellDelegate::CreateContextMenu instead. (this is what all the impls do anyway...) Don't pass the ShelfItemDelegate, look up as needed. Only create |extension_items_| as needed. Don't ask |extension_items_| for local enabled/checked state. Remove non-cros logic from LauncherContextMenu. Support null in GetAppIDForShelfID for app list button. TODO: Refine menu model creation pattern to support mash. BUG=557406 TEST=No behavior changes or regressions. R=sky@chromium.org Review URL: https://codereview.chromium.org/1762813002 Cr-Commit-Position: refs/heads/master@{#379158}
Diffstat (limited to 'ash')
-rw-r--r--ash/mus/shelf_delegate_mus.cc5
-rw-r--r--ash/mus/shell_delegate_mus.cc6
-rw-r--r--ash/mus/shell_delegate_mus.h3
-rw-r--r--ash/root_window_controller.cc6
-rw-r--r--ash/shelf/app_list_shelf_item_delegate.cc8
-rw-r--r--ash/shelf/app_list_shelf_item_delegate.h1
-rw-r--r--ash/shelf/shelf_item_delegate.h9
-rw-r--r--ash/shelf/shelf_view.cc8
-rw-r--r--ash/shelf/shelf_window_watcher.cc2
-rw-r--r--ash/shelf/shelf_window_watcher_item_delegate.cc21
-rw-r--r--ash/shelf/shelf_window_watcher_item_delegate.h8
-rw-r--r--ash/shell/shell_delegate_impl.cc7
-rw-r--r--ash/shell/shell_delegate_impl.h3
-rw-r--r--ash/shell/window_watcher_shelf_item_delegate.cc7
-rw-r--r--ash/shell/window_watcher_shelf_item_delegate.h1
-rw-r--r--ash/shell_delegate.h21
-rw-r--r--ash/test/test_shelf_item_delegate.cc14
-rw-r--r--ash/test/test_shelf_item_delegate.h1
-rw-r--r--ash/test/test_shell_delegate.cc11
-rw-r--r--ash/test/test_shell_delegate.h5
20 files changed, 34 insertions, 113 deletions
diff --git a/ash/mus/shelf_delegate_mus.cc b/ash/mus/shelf_delegate_mus.cc
index c405fb7..ce3698a 100644
--- a/ash/mus/shelf_delegate_mus.cc
+++ b/ash/mus/shelf_delegate_mus.cc
@@ -51,11 +51,6 @@ class ShelfItemDelegateMus : public ShelfItemDelegate {
base::string16 GetTitle() override { return title_; }
- ui::MenuModel* CreateContextMenu(aura::Window* root_window) override {
- NOTIMPLEMENTED();
- return nullptr;
- }
-
bool CanPin() const override {
NOTIMPLEMENTED();
return false;
diff --git a/ash/mus/shell_delegate_mus.cc b/ash/mus/shell_delegate_mus.cc
index f2c0de4..4aa6e13 100644
--- a/ash/mus/shell_delegate_mus.cc
+++ b/ash/mus/shell_delegate_mus.cc
@@ -197,10 +197,8 @@ MediaDelegate* ShellDelegateMus::CreateMediaDelegate() {
return new MediaDelegateStub;
}
-ui::MenuModel* ShellDelegateMus::CreateContextMenu(
- aura::Window* root_window,
- ShelfItemDelegate* item_delegate,
- ShelfItem* item) {
+ui::MenuModel* ShellDelegateMus::CreateContextMenu(aura::Window* root_window,
+ const ShelfItem* item) {
NOTIMPLEMENTED();
return nullptr;
}
diff --git a/ash/mus/shell_delegate_mus.h b/ash/mus/shell_delegate_mus.h
index a9ca638..f0486ab 100644
--- a/ash/mus/shell_delegate_mus.h
+++ b/ash/mus/shell_delegate_mus.h
@@ -47,8 +47,7 @@ class ShellDelegateMus : public ash::ShellDelegate {
ash::NewWindowDelegate* CreateNewWindowDelegate() override;
ash::MediaDelegate* CreateMediaDelegate() override;
ui::MenuModel* CreateContextMenu(aura::Window* root_window,
- ash::ShelfItemDelegate* item_delegate,
- ash::ShelfItem* item) override;
+ const ash::ShelfItem* item) override;
GPUSupport* CreateGPUSupport() override;
base::string16 GetProductName() const override;
gfx::Image GetDeprecatedAcceleratorImage() const override;
diff --git a/ash/root_window_controller.cc b/ash/root_window_controller.cc
index 1ae8355..4d021bf 100644
--- a/ash/root_window_controller.cc
+++ b/ash/root_window_controller.cc
@@ -558,10 +558,10 @@ SystemTray* RootWindowController::GetSystemTray() {
void RootWindowController::ShowContextMenu(const gfx::Point& location_in_screen,
ui::MenuSourceType source_type) {
- DCHECK(Shell::GetInstance()->delegate());
+ ShellDelegate* delegate = Shell::GetInstance()->delegate();
+ DCHECK(delegate);
scoped_ptr<ui::MenuModel> menu_model(
- Shell::GetInstance()->delegate()->CreateContextMenu(
- GetRootWindow(), NULL, NULL));
+ delegate->CreateContextMenu(GetRootWindow(), nullptr));
if (!menu_model)
return;
diff --git a/ash/shelf/app_list_shelf_item_delegate.cc b/ash/shelf/app_list_shelf_item_delegate.cc
index f510732..6bac70b 100644
--- a/ash/shelf/app_list_shelf_item_delegate.cc
+++ b/ash/shelf/app_list_shelf_item_delegate.cc
@@ -6,7 +6,6 @@
#include "ash/shelf/shelf_model.h"
#include "ash/shell.h"
-#include "ash/shell_delegate.h"
#include "grit/ash_strings.h"
#include "ui/app_list/app_list_switches.h"
#include "ui/base/l10n/l10n_util.h"
@@ -46,13 +45,6 @@ base::string16 AppListShelfItemDelegate::GetTitle() {
return l10n_util::GetStringUTF16(title_id);
}
-ui::MenuModel* AppListShelfItemDelegate::CreateContextMenu(
- aura::Window* root_window) {
- return Shell::GetInstance()->delegate()->CreateContextMenu(root_window,
- NULL,
- NULL);
-}
-
ShelfMenuModel* AppListShelfItemDelegate::CreateApplicationMenu(
int event_flags) {
// AppList does not show an application menu.
diff --git a/ash/shelf/app_list_shelf_item_delegate.h b/ash/shelf/app_list_shelf_item_delegate.h
index 38f46f5..46c7ded 100644
--- a/ash/shelf/app_list_shelf_item_delegate.h
+++ b/ash/shelf/app_list_shelf_item_delegate.h
@@ -22,7 +22,6 @@ class AppListShelfItemDelegate : public ShelfItemDelegate {
ShelfItemDelegate::PerformedAction ItemSelected(
const ui::Event& event) override;
base::string16 GetTitle() override;
- ui::MenuModel* CreateContextMenu(aura::Window* root_window) override;
ShelfMenuModel* CreateApplicationMenu(int event_flags) override;
bool IsDraggable() override;
bool CanPin() const override;
diff --git a/ash/shelf/shelf_item_delegate.h b/ash/shelf/shelf_item_delegate.h
index 260e069..16ffb990 100644
--- a/ash/shelf/shelf_item_delegate.h
+++ b/ash/shelf/shelf_item_delegate.h
@@ -8,10 +8,6 @@
#include "ash/ash_export.h"
#include "base/strings/string16.h"
-namespace aura {
-class Window;
-}
-
namespace ui {
class Event;
class MenuModel;
@@ -52,11 +48,6 @@ class ASH_EXPORT ShelfItemDelegate {
// Returns the title to display.
virtual base::string16 GetTitle() = 0;
- // Returns the context menumodel for the specified item on
- // |root_window|. Return NULL if there should be no context
- // menu. The caller takes ownership of the returned model.
- virtual ui::MenuModel* CreateContextMenu(aura::Window* root_window) = 0;
-
// Returns whether the user can change the pin status of this item.
// Pinning may be disallowed by policy if this app is pinned by pre-defined
// pinned app list.
diff --git a/ash/shelf/shelf_view.cc b/ash/shelf/shelf_view.cc
index 262aed8..1217e74 100644
--- a/ash/shelf/shelf_view.cc
+++ b/ash/shelf/shelf_view.cc
@@ -26,6 +26,7 @@
#include "ash/shelf/shelf_tooltip_manager.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
+#include "ash/shell_delegate.h"
#include "ash/wm/coordinate_conversion.h"
#include "base/auto_reset.h"
#include "base/memory/scoped_ptr.h"
@@ -1796,10 +1797,9 @@ void ShelfView::ShowContextMenuForView(views::View* source,
return;
}
- ShelfItemDelegate* item_delegate = item_manager_->GetShelfItemDelegate(
- model_->items()[view_index].id);
- context_menu_model_.reset(item_delegate->CreateContextMenu(
- source->GetWidget()->GetNativeView()->GetRootWindow()));
+ context_menu_model_.reset(Shell::GetInstance()->delegate()->CreateContextMenu(
+ source->GetWidget()->GetNativeView()->GetRootWindow(),
+ &model_->items()[view_index]));
if (!context_menu_model_)
return;
diff --git a/ash/shelf/shelf_window_watcher.cc b/ash/shelf/shelf_window_watcher.cc
index 80df891..f7daa1e 100644
--- a/ash/shelf/shelf_window_watcher.cc
+++ b/ash/shelf/shelf_window_watcher.cc
@@ -136,7 +136,7 @@ void ShelfWindowWatcher::AddShelfItem(aura::Window* window) {
SetShelfItemDetailsForShelfItem(&item, *item_details);
SetShelfIDForWindow(id, window);
scoped_ptr<ShelfItemDelegate> item_delegate(
- new ShelfWindowWatcherItemDelegate(window, model_));
+ new ShelfWindowWatcherItemDelegate(window));
// |item_delegate| is owned by |item_delegate_manager_|.
item_delegate_manager_->SetShelfItemDelegate(id, std::move(item_delegate));
model_->Add(item);
diff --git a/ash/shelf/shelf_window_watcher_item_delegate.cc b/ash/shelf/shelf_window_watcher_item_delegate.cc
index 1619557..a6fa6d1 100644
--- a/ash/shelf/shelf_window_watcher_item_delegate.cc
+++ b/ash/shelf/shelf_window_watcher_item_delegate.cc
@@ -4,10 +4,8 @@
#include "ash/shelf/shelf_window_watcher_item_delegate.h"
-#include "ash/shelf/shelf_model.h"
#include "ash/shelf/shelf_util.h"
#include "ash/shell.h"
-#include "ash/shell_delegate.h"
#include "ash/wm/window_state.h"
#include "ui/aura/window.h"
#include "ui/views/widget/widget.h"
@@ -16,13 +14,10 @@
namespace ash {
ShelfWindowWatcherItemDelegate::ShelfWindowWatcherItemDelegate(
- aura::Window* window, ShelfModel* model)
- : window_(window),
- model_(model) {
-}
+ aura::Window* window)
+ : window_(window) {}
-ShelfWindowWatcherItemDelegate::~ShelfWindowWatcherItemDelegate() {
-}
+ShelfWindowWatcherItemDelegate::~ShelfWindowWatcherItemDelegate() {}
void ShelfWindowWatcherItemDelegate::Close() {
views::Widget::GetWidgetForNativeWindow(window_)->Close();
@@ -49,17 +44,9 @@ base::string16 ShelfWindowWatcherItemDelegate::GetTitle() {
return GetShelfItemDetailsForWindow(window_)->title;
}
-ui::MenuModel* ShelfWindowWatcherItemDelegate::CreateContextMenu(
- aura::Window* root_window) {
- ash::ShelfItem item = *(model_->ItemByID(GetShelfIDForWindow(window_)));
- return Shell::GetInstance()->delegate()->CreateContextMenu(root_window,
- this,
- &item);
-}
-
ShelfMenuModel* ShelfWindowWatcherItemDelegate::CreateApplicationMenu(
int event_flags) {
- return NULL;
+ return nullptr;
}
bool ShelfWindowWatcherItemDelegate::IsDraggable() {
diff --git a/ash/shelf/shelf_window_watcher_item_delegate.h b/ash/shelf/shelf_window_watcher_item_delegate.h
index 7d751d6..60b98c3 100644
--- a/ash/shelf/shelf_window_watcher_item_delegate.h
+++ b/ash/shelf/shelf_window_watcher_item_delegate.h
@@ -14,13 +14,11 @@ class Window;
}
namespace ash {
-class ShelfModel;
// ShelfItemDelegate for the items created by ShelfWindowWatcher.
class ShelfWindowWatcherItemDelegate : public ShelfItemDelegate {
public:
- ShelfWindowWatcherItemDelegate(aura::Window* window, ShelfModel* model_);
-
+ explicit ShelfWindowWatcherItemDelegate(aura::Window* window);
~ShelfWindowWatcherItemDelegate() override;
private:
@@ -28,7 +26,6 @@ class ShelfWindowWatcherItemDelegate : public ShelfItemDelegate {
ShelfItemDelegate::PerformedAction ItemSelected(
const ui::Event& event) override;
base::string16 GetTitle() override;
- ui::MenuModel* CreateContextMenu(aura::Window* root_window) override;
ShelfMenuModel* CreateApplicationMenu(int event_flags) override;
bool IsDraggable() override;
bool CanPin() const override;
@@ -38,9 +35,6 @@ class ShelfWindowWatcherItemDelegate : public ShelfItemDelegate {
// Stores a Window associated with this item. Not owned.
aura::Window* window_;
- // Not owned.
- ShelfModel* model_;
-
DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcherItemDelegate);
};
diff --git a/ash/shell/shell_delegate_impl.cc b/ash/shell/shell_delegate_impl.cc
index a53be83..d996a22 100644
--- a/ash/shell/shell_delegate_impl.cc
+++ b/ash/shell/shell_delegate_impl.cc
@@ -225,10 +225,9 @@ ash::MediaDelegate* ShellDelegateImpl::CreateMediaDelegate() {
}
ui::MenuModel* ShellDelegateImpl::CreateContextMenu(
- aura::Window* root,
- ash::ShelfItemDelegate* item_delegate,
- ash::ShelfItem* item) {
- return new ContextMenu(root);
+ aura::Window* root_window,
+ const ash::ShelfItem* item) {
+ return new ContextMenu(root_window);
}
GPUSupport* ShellDelegateImpl::CreateGPUSupport() {
diff --git a/ash/shell/shell_delegate_impl.h b/ash/shell/shell_delegate_impl.h
index dbcaa59..c53c702 100644
--- a/ash/shell/shell_delegate_impl.h
+++ b/ash/shell/shell_delegate_impl.h
@@ -49,8 +49,7 @@ class ShellDelegateImpl : public ash::ShellDelegate {
ash::NewWindowDelegate* CreateNewWindowDelegate() override;
ash::MediaDelegate* CreateMediaDelegate() override;
ui::MenuModel* CreateContextMenu(aura::Window* root_window,
- ash::ShelfItemDelegate* item_delegate,
- ash::ShelfItem* item) override;
+ const ash::ShelfItem* item) override;
GPUSupport* CreateGPUSupport() override;
base::string16 GetProductName() const override;
gfx::Image GetDeprecatedAcceleratorImage() const override;
diff --git a/ash/shell/window_watcher_shelf_item_delegate.cc b/ash/shell/window_watcher_shelf_item_delegate.cc
index 2d4d2ca..ca33759 100644
--- a/ash/shell/window_watcher_shelf_item_delegate.cc
+++ b/ash/shell/window_watcher_shelf_item_delegate.cc
@@ -36,14 +36,9 @@ base::string16 WindowWatcherShelfItemDelegate::GetTitle() {
return watcher_->GetWindowByID(id_)->title();
}
-ui::MenuModel* WindowWatcherShelfItemDelegate::CreateContextMenu(
- aura::Window* root_window) {
- return NULL;
-}
-
ShelfMenuModel* WindowWatcherShelfItemDelegate::CreateApplicationMenu(
int event_flags) {
- return NULL;
+ return nullptr;
}
bool WindowWatcherShelfItemDelegate::IsDraggable() {
diff --git a/ash/shell/window_watcher_shelf_item_delegate.h b/ash/shell/window_watcher_shelf_item_delegate.h
index a9fbc0ea..2bbc05b 100644
--- a/ash/shell/window_watcher_shelf_item_delegate.h
+++ b/ash/shell/window_watcher_shelf_item_delegate.h
@@ -25,7 +25,6 @@ class WindowWatcherShelfItemDelegate : public ShelfItemDelegate {
ShelfItemDelegate::PerformedAction ItemSelected(
const ui::Event& event) override;
base::string16 GetTitle() override;
- ui::MenuModel* CreateContextMenu(aura::Window* root_window) override;
ShelfMenuModel* CreateApplicationMenu(int event_flags) override;
bool IsDraggable() override;
bool CanPin() const override;
diff --git a/ash/shell_delegate.h b/ash/shell_delegate.h
index c66eb15..cd36fd4 100644
--- a/ash/shell_delegate.h
+++ b/ash/shell_delegate.h
@@ -17,14 +17,9 @@ class AppListViewDelegate;
}
namespace aura {
-class RootWindow;
class Window;
}
-namespace content {
-class BrowserContext;
-}
-
namespace gfx {
class Image;
}
@@ -33,10 +28,6 @@ namespace ui {
class MenuModel;
}
-namespace views {
-class Widget;
-}
-
namespace keyboard {
class KeyboardUI;
}
@@ -48,7 +39,6 @@ class MediaDelegate;
class NewWindowDelegate;
class SessionStateDelegate;
class ShelfDelegate;
-class ShelfItemDelegate;
class ShelfModel;
class SystemTrayDelegate;
class UserWallpaperDelegate;
@@ -142,13 +132,10 @@ class ASH_EXPORT ShellDelegate {
// Creates a media delegate. Shell takes ownership of the delegate.
virtual MediaDelegate* CreateMediaDelegate() = 0;
- // Creates a menu model of the context for the |root_window|.
- // When a ContextMenu is used for an item created by ShelfWindowWatcher,
- // passes its ShelfItemDelegate and ShelfItem.
- virtual ui::MenuModel* CreateContextMenu(
- aura::Window* root_window,
- ash::ShelfItemDelegate* item_delegate,
- ash::ShelfItem* item) = 0;
+ // Creates a menu model for the |root_window| and optional shelf |item|.
+ // If |item| is null, this creates a context menu for the desktop or shelf.
+ virtual ui::MenuModel* CreateContextMenu(aura::Window* root_window,
+ const ash::ShelfItem* item) = 0;
// Creates a GPU support object. Shell takes ownership of the object.
virtual GPUSupport* CreateGPUSupport() = 0;
diff --git a/ash/test/test_shelf_item_delegate.cc b/ash/test/test_shelf_item_delegate.cc
index 7679154..c9c3a39 100644
--- a/ash/test/test_shelf_item_delegate.cc
+++ b/ash/test/test_shelf_item_delegate.cc
@@ -13,8 +13,7 @@ namespace test {
TestShelfItemDelegate::TestShelfItemDelegate(aura::Window* window)
: window_(window), is_draggable_(true) {}
-TestShelfItemDelegate::~TestShelfItemDelegate() {
-}
+TestShelfItemDelegate::~TestShelfItemDelegate() {}
ShelfItemDelegate::PerformedAction TestShelfItemDelegate::ItemSelected(
const ui::Event& event) {
@@ -32,13 +31,8 @@ base::string16 TestShelfItemDelegate::GetTitle() {
return window_ ? window_->title() : base::string16();
}
-ui::MenuModel* TestShelfItemDelegate::CreateContextMenu(
- aura::Window* root_window) {
- return NULL;
-}
-
ShelfMenuModel* TestShelfItemDelegate::CreateApplicationMenu(int event_flags) {
- return NULL;
+ return nullptr;
}
bool TestShelfItemDelegate::IsDraggable() {
@@ -53,7 +47,7 @@ bool TestShelfItemDelegate::ShouldShowTooltip() {
return true;
}
-void TestShelfItemDelegate::Close() {
-}
+void TestShelfItemDelegate::Close() {}
+
} // namespace test
} // namespace ash
diff --git a/ash/test/test_shelf_item_delegate.h b/ash/test/test_shelf_item_delegate.h
index cba7721..ffb5996 100644
--- a/ash/test/test_shelf_item_delegate.h
+++ b/ash/test/test_shelf_item_delegate.h
@@ -28,7 +28,6 @@ class TestShelfItemDelegate : public ShelfItemDelegate {
ShelfItemDelegate::PerformedAction ItemSelected(
const ui::Event& event) override;
base::string16 GetTitle() override;
- ui::MenuModel* CreateContextMenu(aura::Window* root_window) override;
ShelfMenuModel* CreateApplicationMenu(int event_flags) override;
bool IsDraggable() override;
bool CanPin() const override;
diff --git a/ash/test/test_shell_delegate.cc b/ash/test/test_shell_delegate.cc
index ed468dc..b5d7fc0 100644
--- a/ash/test/test_shell_delegate.cc
+++ b/ash/test/test_shell_delegate.cc
@@ -31,10 +31,6 @@
#include "ash/system/tray/system_tray_notifier.h"
#endif
-namespace content {
-class BrowserContext;
-}
-
namespace ash {
namespace test {
namespace {
@@ -179,10 +175,9 @@ MediaDelegate* TestShellDelegate::CreateMediaDelegate() {
}
ui::MenuModel* TestShellDelegate::CreateContextMenu(
- aura::Window* root,
- ash::ShelfItemDelegate* item_delegate,
- ash::ShelfItem* item) {
- return NULL;
+ aura::Window* root_window,
+ const ash::ShelfItem* item) {
+ return nullptr;
}
GPUSupport* TestShellDelegate::CreateGPUSupport() {
diff --git a/ash/test/test_shell_delegate.h b/ash/test/test_shell_delegate.h
index 8c79ead..80de3b7 100644
--- a/ash/test/test_shell_delegate.h
+++ b/ash/test/test_shell_delegate.h
@@ -55,9 +55,8 @@ class TestShellDelegate : public ShellDelegate {
AccessibilityDelegate* CreateAccessibilityDelegate() override;
NewWindowDelegate* CreateNewWindowDelegate() override;
MediaDelegate* CreateMediaDelegate() override;
- ui::MenuModel* CreateContextMenu(aura::Window* root,
- ash::ShelfItemDelegate* item_delegate,
- ash::ShelfItem* item) override;
+ ui::MenuModel* CreateContextMenu(aura::Window* root_window,
+ const ash::ShelfItem* item) override;
GPUSupport* CreateGPUSupport() override;
base::string16 GetProductName() const override;
gfx::Image GetDeprecatedAcceleratorImage() const override;