[ash] Add TYPE_DIALOG and its item's LauncherContextMenu

This is third CL for adding an item for dialog.
This cl adds new LauncherItemType, TYPE_DIALOG, and 
implements a context menu of item created by ShelfWindowWatcher.

R=sky@chromium.org
BUG=121242
TEST=NONE

Review URL: https://codereview.chromium.org/107163005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243965 0039d316-1c4b-4281-b951-d872f2087c98
parent 531cf0b2
......@@ -35,6 +35,9 @@ enum LauncherItemType {
// Represents a windowed V1 browser app.
TYPE_WINDOWED_APP,
// Represents a dialog.
TYPE_DIALOG,
// Default value.
TYPE_UNDEFINED,
};
......
......@@ -541,7 +541,9 @@ 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()));
Shell::GetInstance()->delegate()->CreateContextMenu(root_window(),
NULL,
NULL));
if (!menu_model)
return;
......
......@@ -39,7 +39,9 @@ base::string16 AppListShelfItemDelegate::GetTitle() {
ui::MenuModel* AppListShelfItemDelegate::CreateContextMenu(
aura::Window* root_window) {
return Shell::GetInstance()->delegate()->CreateContextMenu(root_window);
return Shell::GetInstance()->delegate()->CreateContextMenu(root_window,
NULL,
NULL);
}
ShelfMenuModel* AppListShelfItemDelegate::CreateApplicationMenu(
......@@ -56,5 +58,8 @@ bool AppListShelfItemDelegate::ShouldShowTooltip() {
return true;
}
void AppListShelfItemDelegate::Close() {
}
} // namespace internal
} // namespace ash
......@@ -26,6 +26,7 @@ class AppListShelfItemDelegate : public ShelfItemDelegate {
virtual ShelfMenuModel* CreateApplicationMenu(int event_flags) OVERRIDE;
virtual bool IsDraggable() OVERRIDE;
virtual bool ShouldShowTooltip() OVERRIDE;
virtual void Close() OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(AppListShelfItemDelegate);
......
......@@ -59,6 +59,10 @@ class ASH_EXPORT ShelfItemDelegate {
// Returns true if a tooltip should be shown.
virtual bool ShouldShowTooltip() = 0;
// Closes all windows associated with this item.
virtual void Close() = 0;
};
} // namespace ash
......
......@@ -26,8 +26,10 @@ int LauncherItemTypeToWeight(LauncherItemType type) {
return 1;
case TYPE_PLATFORM_APP:
return 2;
case TYPE_APP_PANEL:
case TYPE_DIALOG:
return 3;
case TYPE_APP_PANEL:
return 4;
case TYPE_UNDEFINED:
NOTREACHED() << "LauncherItemType must be set";
return -1;
......@@ -42,8 +44,10 @@ int LauncherItemTypeToWeight(LauncherItemType type) {
return 1;
case TYPE_APP_LIST:
return 2;
case TYPE_APP_PANEL:
case TYPE_DIALOG:
return 3;
case TYPE_APP_PANEL:
return 4;
case TYPE_UNDEFINED:
NOTREACHED() << "LauncherItemType must be set";
return -1;
......
......@@ -918,6 +918,7 @@ views::View* ShelfView::CreateViewForItem(const LauncherItem& item) {
case TYPE_APP_SHORTCUT:
case TYPE_WINDOWED_APP:
case TYPE_PLATFORM_APP:
case TYPE_DIALOG:
case TYPE_APP_PANEL: {
ShelfButton* button = ShelfButton::Create(this, this, layout_manager_);
button->SetImage(item.image);
......@@ -1252,6 +1253,7 @@ bool ShelfView::SameDragType(LauncherItemType typea,
case TYPE_PLATFORM_APP:
case TYPE_WINDOWED_APP:
case TYPE_APP_PANEL:
case TYPE_DIALOG:
return typeb == typea;
case TYPE_UNDEFINED:
NOTREACHED() << "LauncherItemType must be set.";
......@@ -1614,6 +1616,7 @@ void ShelfView::ShelfItemChanged(int model_index,
case TYPE_APP_SHORTCUT:
case TYPE_WINDOWED_APP:
case TYPE_PLATFORM_APP:
case TYPE_DIALOG:
case TYPE_APP_PANEL: {
ShelfButton* button = static_cast<ShelfButton*>(view);
ReflectItemStatus(item, button);
......@@ -1788,6 +1791,7 @@ void ShelfView::ButtonPressed(views::Button* sender, const ui::Event& event) {
break;
case TYPE_APP_PANEL:
case TYPE_DIALOG:
break;
case TYPE_UNDEFINED:
......
......@@ -91,7 +91,7 @@ void ShelfWindowWatcher::AddLauncherItem(aura::Window* window) {
SetShelfItemDetailsForLauncherItem(&item, *item_details);
SetLauncherIDForWindow(id, window);
scoped_ptr<ShelfItemDelegate> item_delegate(
new ShelfWindowWatcherItemDelegate(window));
new ShelfWindowWatcherItemDelegate(window, model_));
// |item_delegate| is owned by |item_delegate_manager_|.
item_delegate_manager_->SetShelfItemDelegate(id, item_delegate.Pass());
model_->Add(item);
......
......@@ -4,7 +4,10 @@
#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/corewm/window_animations.h"
......@@ -14,8 +17,9 @@ namespace ash {
namespace internal {
ShelfWindowWatcherItemDelegate::ShelfWindowWatcherItemDelegate(
aura::Window* window)
: window_(window) {
aura::Window* window, ShelfModel* model)
: window_(window),
model_(model) {
}
ShelfWindowWatcherItemDelegate::~ShelfWindowWatcherItemDelegate() {
......@@ -47,8 +51,11 @@ base::string16 ShelfWindowWatcherItemDelegate::GetTitle() {
ui::MenuModel* ShelfWindowWatcherItemDelegate::CreateContextMenu(
aura::Window* root_window) {
// TODO(simonhong): Create ShelfItemContextMenu.
return NULL;
ash::LauncherItem item =
*(model_->ItemByID(GetLauncherIDForWindow(window_)));
return Shell::GetInstance()->delegate()->CreateContextMenu(root_window,
this,
&item);
}
ShelfMenuModel* ShelfWindowWatcherItemDelegate::CreateApplicationMenu(
......
......@@ -14,18 +14,18 @@ class Window;
}
namespace ash {
class ShelfModel;
namespace internal {
// ShelfItemDelegate for the items created by ShelfWindowWatcher.
class ShelfWindowWatcherItemDelegate : public ShelfItemDelegate {
public:
explicit ShelfWindowWatcherItemDelegate(aura::Window* window);
ShelfWindowWatcherItemDelegate(aura::Window* window, ShelfModel* model_);
virtual ~ShelfWindowWatcherItemDelegate();
// Closes the window associated with this item.
void Close();
private:
// ShelfItemDelegate overrides:
virtual bool ItemSelected(const ui::Event& event) OVERRIDE;
......@@ -34,10 +34,14 @@ class ShelfWindowWatcherItemDelegate : public ShelfItemDelegate {
virtual ShelfMenuModel* CreateApplicationMenu(int event_flags) OVERRIDE;
virtual bool IsDraggable() OVERRIDE;
virtual bool ShouldShowTooltip() OVERRIDE;
virtual void Close() OVERRIDE;
// Stores a Window associated with this item. Not owned.
aura::Window* window_;
// Not owned.
ShelfModel* model_;
DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcherItemDelegate);
};
......
......@@ -158,7 +158,10 @@ aura::client::UserActionClient* ShellDelegateImpl::CreateUserActionClient() {
return NULL;
}
ui::MenuModel* ShellDelegateImpl::CreateContextMenu(aura::Window* root) {
ui::MenuModel* ShellDelegateImpl::CreateContextMenu(
aura::Window* root,
ash::ShelfItemDelegate* item_delegate,
ash::LauncherItem* item) {
return new ContextMenu(root);
}
......
......@@ -55,7 +55,9 @@ class ShellDelegateImpl : public ash::ShellDelegate {
virtual ash::MediaDelegate* CreateMediaDelegate() OVERRIDE;
virtual aura::client::UserActionClient* CreateUserActionClient() OVERRIDE;
virtual ui::MenuModel* CreateContextMenu(
aura::Window* root_window) OVERRIDE;
aura::Window* root_window,
ash::ShelfItemDelegate* item_delegate,
ash::LauncherItem* item) OVERRIDE;
virtual WindowTreeHostFactory* CreateWindowTreeHostFactory() OVERRIDE;
virtual base::string16 GetProductName() const OVERRIDE;
......
......@@ -53,5 +53,8 @@ bool WindowWatcherShelfItemDelegate::ShouldShowTooltip() {
return true;
}
void WindowWatcherShelfItemDelegate::Close() {
}
} // namespace shell
} // namespace ash
......@@ -28,6 +28,7 @@ class WindowWatcherShelfItemDelegate : public ShelfItemDelegate {
virtual ShelfMenuModel* CreateApplicationMenu(int event_flags) OVERRIDE;
virtual bool IsDraggable() OVERRIDE;
virtual bool ShouldShowTooltip() OVERRIDE;
virtual void Close() OVERRIDE;
private:
LauncherID id_;
......
......@@ -49,6 +49,7 @@ class NewWindowDelegate;
class WindowTreeHostFactory;
class SessionStateDelegate;
class ShelfDelegate;
class ShelfItemDelegate;
class ShelfModel;
class SystemTrayDelegate;
class UserWallpaperDelegate;
......@@ -126,7 +127,12 @@ class ASH_EXPORT ShellDelegate {
virtual aura::client::UserActionClient* CreateUserActionClient() = 0;
// Creates a menu model of the context for the |root_window|.
virtual ui::MenuModel* CreateContextMenu(aura::Window* root_window) = 0;
// When a ContextMenu is used for an item created by ShelfWindowWatcher,
// passes its ShelfItemDelegate and LauncherItem.
virtual ui::MenuModel* CreateContextMenu(
aura::Window* root_window,
ash::ShelfItemDelegate* item_delegate,
ash::LauncherItem* item) = 0;
// Creates a root window host factory. Shell takes ownership of the returned
// value.
......
......@@ -48,5 +48,8 @@ bool TestShelfItemDelegate::ShouldShowTooltip() {
return true;
}
void TestShelfItemDelegate::Close() {
}
} // namespace test
} // namespace ash
......@@ -29,6 +29,7 @@ class TestShelfItemDelegate : public ShelfItemDelegate {
virtual ShelfMenuModel* CreateApplicationMenu(int event_flags) OVERRIDE;
virtual bool IsDraggable() OVERRIDE;
virtual bool ShouldShowTooltip() OVERRIDE;
virtual void Close() OVERRIDE;
private:
aura::Window* window_;
......
......@@ -139,7 +139,10 @@ aura::client::UserActionClient* TestShellDelegate::CreateUserActionClient() {
return NULL;
}
ui::MenuModel* TestShellDelegate::CreateContextMenu(aura::Window* root) {
ui::MenuModel* TestShellDelegate::CreateContextMenu(
aura::Window* root,
ash::ShelfItemDelegate* item_delegate,
ash::LauncherItem* item) {
return NULL;
}
......
......@@ -50,7 +50,10 @@ class TestShellDelegate : public ShellDelegate {
virtual NewWindowDelegate* CreateNewWindowDelegate() OVERRIDE;
virtual MediaDelegate* CreateMediaDelegate() OVERRIDE;
virtual aura::client::UserActionClient* CreateUserActionClient() OVERRIDE;
virtual ui::MenuModel* CreateContextMenu(aura::Window* root) OVERRIDE;
virtual ui::MenuModel* CreateContextMenu(
aura::Window* root,
ash::ShelfItemDelegate* item_delegate,
ash::LauncherItem* item) OVERRIDE;
virtual WindowTreeHostFactory* CreateWindowTreeHostFactory() OVERRIDE;
virtual base::string16 GetProductName() const OVERRIDE;
......
......@@ -127,12 +127,18 @@ aura::client::UserActionClient* ChromeShellDelegate::CreateUserActionClient() {
return new UserActionHandler;
}
ui::MenuModel* ChromeShellDelegate::CreateContextMenu(aura::Window* root) {
ui::MenuModel* ChromeShellDelegate::CreateContextMenu(
aura::Window* root,
ash::ShelfItemDelegate* item_delegate,
ash::LauncherItem* item) {
DCHECK(shelf_delegate_);
// Don't show context menu for exclusive app runtime mode.
if (chrome::IsRunningInAppMode())
return NULL;
if (item_delegate && item)
return new LauncherContextMenu(shelf_delegate_, item_delegate, item, root);
return new LauncherContextMenu(shelf_delegate_, root);
}
......
......@@ -17,6 +17,10 @@
class Browser;
namespace ash {
class ShelfItemDelegate;
}
namespace content {
class WebContents;
}
......@@ -57,7 +61,10 @@ class ChromeShellDelegate : public ash::ShellDelegate,
virtual ash::NewWindowDelegate* CreateNewWindowDelegate() OVERRIDE;
virtual ash::MediaDelegate* CreateMediaDelegate() OVERRIDE;
virtual aura::client::UserActionClient* CreateUserActionClient() OVERRIDE;
virtual ui::MenuModel* CreateContextMenu(aura::Window* root) OVERRIDE;
virtual ui::MenuModel* CreateContextMenu(
aura::Window* root,
ash::ShelfItemDelegate* item_delegate,
ash::LauncherItem* item) OVERRIDE;
virtual ash::WindowTreeHostFactory* CreateWindowTreeHostFactory() OVERRIDE;
virtual base::string16 GetProductName() const OVERRIDE;
......
......@@ -40,7 +40,6 @@ class AppShortcutLauncherItemController : public LauncherItemController {
virtual bool IsVisible() const OVERRIDE;
virtual void Launch(ash::LaunchSource source, int event_flags) OVERRIDE;
virtual bool Activate(ash::LaunchSource source) OVERRIDE;
virtual void Close() OVERRIDE;
virtual ChromeLauncherAppMenuItems GetApplicationList(
int event_flags) OVERRIDE;
virtual bool ItemSelected(const ui::Event& event) OVERRIDE;
......@@ -50,6 +49,7 @@ class AppShortcutLauncherItemController : public LauncherItemController {
virtual ash::ShelfMenuModel* CreateApplicationMenu(int event_flags) OVERRIDE;
virtual bool IsDraggable() OVERRIDE;
virtual bool ShouldShowTooltip() OVERRIDE;
virtual void Close() OVERRIDE;
// Get the refocus url pattern, which can be used to identify this application
// from a URL link.
......
......@@ -34,7 +34,6 @@ class BrowserShortcutLauncherItemController : public LauncherItemController {
virtual bool IsVisible() const OVERRIDE;
virtual void Launch(ash::LaunchSource source, int event_flags) OVERRIDE;
virtual bool Activate(ash::LaunchSource source) OVERRIDE;
virtual void Close() OVERRIDE;
virtual ChromeLauncherAppMenuItems GetApplicationList(
int event_flags) OVERRIDE;
virtual bool ItemSelected(const ui::Event& event) OVERRIDE;
......@@ -44,6 +43,7 @@ class BrowserShortcutLauncherItemController : public LauncherItemController {
virtual ash::ShelfMenuModel* CreateApplicationMenu(int event_flags) OVERRIDE;
virtual bool IsDraggable() OVERRIDE;
virtual bool ShouldShowTooltip() OVERRIDE;
virtual void Close() OVERRIDE;
private:
// Get the favicon for the browser list entry for |web_contents|.
......
......@@ -9,6 +9,7 @@
#include "ash/desktop_background/user_wallpaper_delegate.h"
#include "ash/metrics/user_metrics_recorder.h"
#include "ash/root_window_controller.h"
#include "ash/shelf/shelf_item_delegate.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
#include "base/bind.h"
......@@ -42,7 +43,24 @@ LauncherContextMenu::LauncherContextMenu(ChromeLauncherController* controller,
controller_(controller),
item_(*item),
shelf_alignment_menu_(root),
root_window_(root) {
root_window_(root),
item_delegate_(NULL) {
DCHECK(item);
DCHECK(root_window_);
Init();
}
LauncherContextMenu::LauncherContextMenu(
ChromeLauncherController* controller,
ash::ShelfItemDelegate* item_delegate,
ash::LauncherItem* item,
aura::Window* root)
: ui::SimpleMenuModel(NULL),
controller_(controller),
item_(*item),
shelf_alignment_menu_(root),
root_window_(root),
item_delegate_(item_delegate) {
DCHECK(item);
DCHECK(root_window_);
Init();
......@@ -57,7 +75,8 @@ LauncherContextMenu::LauncherContextMenu(ChromeLauncherController* controller,
extension_items_(new extensions::ContextMenuMatcher(
controller->profile(), this, this,
base::Bind(MenuItemHasLauncherContext))),
root_window_(root) {
root_window_(root),
item_delegate_(NULL) {
DCHECK(root_window_);
Init();
}
......@@ -120,6 +139,9 @@ void LauncherContextMenu::Init() {
AddItem(MENU_NEW_INCOGNITO_WINDOW,
l10n_util::GetStringUTF16(IDS_LAUNCHER_NEW_INCOGNITO_WINDOW));
}
} else if (item_.type == ash::TYPE_DIALOG) {
AddItem(MENU_CLOSE,
l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_CLOSE));
} else {
if (item_.type == ash::TYPE_PLATFORM_APP) {
AddItem(
......@@ -246,7 +268,13 @@ void LauncherContextMenu::ExecuteCommand(int command_id, int event_flags) {
controller_->Launch(item_.id, ui::EF_NONE);
break;
case MENU_CLOSE:
controller_->Close(item_.id);
if (item_.type == ash::TYPE_DIALOG) {
DCHECK(item_delegate_);
item_delegate_->Close();
} else {
// TODO(simonhong): Use ShelfItemDelegate::Close().
controller_->Close(item_.id);
}
ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction(
ash::UMA_CLOSE_THROUGH_CONTEXT_MENU);
break;
......
......@@ -14,6 +14,10 @@
class ChromeLauncherController;
namespace ash {
class ShelfItemDelegate;
}
namespace aura {
class Window;
}
......@@ -31,6 +35,13 @@ class LauncherContextMenu : public ui::SimpleMenuModel,
LauncherContextMenu(ChromeLauncherController* controller,
const ash::LauncherItem* item,
aura::Window* root_window);
// Creates a menu used by item created by ShelfWindowWatcher.
LauncherContextMenu(ChromeLauncherController* controller,
ash::ShelfItemDelegate* item_delegate,
ash::LauncherItem* item,
aura::Window* root_window);
// Creates a menu used as a desktop context menu on |root_window|.
LauncherContextMenu(ChromeLauncherController* controller,
aura::Window* root_window);
......@@ -90,6 +101,9 @@ class LauncherContextMenu : public ui::SimpleMenuModel,
aura::Window* root_window_;
// Not owned.
ash::ShelfItemDelegate* item_delegate_;
DISALLOW_COPY_AND_ASSIGN(LauncherContextMenu);
};
......
......@@ -78,9 +78,6 @@ class LauncherItemController : public ash::ShelfItemDelegate {
// Returns true when a new item got created.
virtual bool Activate(ash::LaunchSource source) = 0;
// Closes all windows associated with this item.
virtual void Close() = 0;
// Called to retrieve the list of running applications.
virtual ChromeLauncherAppMenuItems GetApplicationList(int event_flags) = 0;
......
......@@ -59,7 +59,6 @@ class ShellWindowLauncherItemController : public LauncherItemController,
virtual bool IsVisible() const OVERRIDE;
virtual void Launch(ash::LaunchSource source, int event_flags) OVERRIDE;
virtual bool Activate(ash::LaunchSource source) OVERRIDE;
virtual void Close() OVERRIDE;
virtual ChromeLauncherAppMenuItems GetApplicationList(
int event_flags) OVERRIDE;
virtual bool ItemSelected(const ui::Event& eent) OVERRIDE;
......@@ -68,6 +67,7 @@ class ShellWindowLauncherItemController : public LauncherItemController,
virtual ash::ShelfMenuModel* CreateApplicationMenu(int event_flags) OVERRIDE;
virtual bool IsDraggable() OVERRIDE;
virtual bool ShouldShowTooltip() OVERRIDE;
virtual void Close() OVERRIDE;
// aura::WindowObserver overrides:
virtual void OnWindowPropertyChanged(aura::Window* window,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment