0

Add Wallpaper option to launcher context menu

BUG=143015

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@161391 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
saintlou@chromium.org
2012-10-11 20:27:28 +00:00
parent 98648a35e5
commit cb054f97d1
10 changed files with 25 additions and 138 deletions

@ -147,8 +147,6 @@
'screenshot_delegate.h',
'shell.cc',
'shell.h',
'shell_context_menu.cc',
'shell_context_menu.h',
'shell_delegate.h',
'shell_factory.h',
'shell_window_ids.h',

@ -152,7 +152,7 @@ bool DesktopBackgroundView::OnMousePressed(const ui::MouseEvent& event) {
void DesktopBackgroundView::ShowContextMenuForView(views::View* source,
const gfx::Point& point) {
Shell::GetInstance()->ShowBackgroundMenu(GetWidget(), point);
Shell::GetInstance()->ShowContextMenu(point);
}
views::Widget* CreateDesktopBackground(aura::RootWindow* root_window,

@ -343,6 +343,10 @@ 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();
}

@ -85,6 +85,9 @@ 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;

@ -25,7 +25,6 @@
#include "ash/magnifier/magnification_controller.h"
#include "ash/root_window_controller.h"
#include "ash/screen_ash.h"
#include "ash/shell_context_menu.h"
#include "ash/shell_delegate.h"
#include "ash/shell_factory.h"
#include "ash/shell_window_ids.h"
@ -390,7 +389,6 @@ void Shell::Init() {
nested_dispatcher_controller_.reset(new NestedDispatcherController);
accelerator_controller_.reset(new AcceleratorController);
#endif
shell_context_menu_.reset(new internal::ShellContextMenu);
// The order in which event filters are added is significant.
user_activity_detector_.reset(new UserActivityDetector);
@ -523,16 +521,15 @@ void Shell::RemoveEnvEventFilter(aura::EventFilter* filter) {
aura::Env::GetInstance()->RemovePreTargetHandler(filter);
}
void Shell::ShowBackgroundMenu(views::Widget* widget,
const gfx::Point& location) {
void Shell::ShowContextMenu(const gfx::Point& location) {
// No context menus if user have not logged in.
if (!delegate_.get() || !delegate_->IsUserLoggedIn())
return;
// No context menus when screen is locked.
if (IsScreenLocked())
return;
if (shell_context_menu_.get())
shell_context_menu_->ShowMenu(widget, location);
if (launcher())
launcher()->ShowContextMenu(location);
}
void Shell::ToggleAppList() {

@ -97,7 +97,6 @@ class RootWindowLayoutManager;
class ScreenPositionController;
class ShadowController;
class ShelfLayoutManager;
class ShellContextMenu;
class SlowAnimationEventFilter;
class StackingController;
class StatusAreaWidget;
@ -192,8 +191,9 @@ class ASH_EXPORT Shell : CursorDelegate,
void AddEnvEventFilter(aura::EventFilter* filter);
void RemoveEnvEventFilter(aura::EventFilter* filter);
// Shows the background menu over |widget|.
void ShowBackgroundMenu(views::Widget* widget, const gfx::Point& location);
// Shows the context menu for the background and launcher at
// |location| (in screen coordinates).
void ShowContextMenu(const gfx::Point& location);
// Toggles app list.
void ToggleAppList();
@ -436,7 +436,6 @@ class ASH_EXPORT Shell : CursorDelegate,
scoped_ptr<internal::AppListController> app_list_controller_;
scoped_ptr<internal::ShellContextMenu> shell_context_menu_;
scoped_ptr<internal::StackingController> stacking_controller_;
scoped_ptr<internal::ActivationController> activation_controller_;
scoped_ptr<internal::CaptureController> capture_controller_;

@ -1,72 +0,0 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/shell_context_menu.h"
#include "ash/desktop_background/desktop_background_controller.h"
#include "ash/display/display_controller.h"
#include "ash/shell.h"
#include "grit/ash_strings.h"
#include "ui/aura/window.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/views/controls/menu/menu_model_adapter.h"
#include "ui/views/controls/menu/menu_runner.h"
#include "ui/views/widget/widget.h"
namespace ash {
namespace internal {
ShellContextMenu::ShellContextMenu() {
}
ShellContextMenu::~ShellContextMenu() {
}
void ShellContextMenu::ShowMenu(views::Widget* widget,
const gfx::Point& location) {
ui::SimpleMenuModel menu_model(this);
menu_model.AddItem(MENU_CHANGE_WALLPAPER,
l10n_util::GetStringUTF16(IDS_AURA_SET_DESKTOP_WALLPAPER));
views::MenuModelAdapter menu_model_adapter(&menu_model);
menu_runner_.reset(new views::MenuRunner(menu_model_adapter.CreateMenu()));
if (menu_runner_->RunMenuAt(
widget, NULL, gfx::Rect(location, gfx::Size()),
views::MenuItemView::TOPLEFT, views::MenuRunner::HAS_MNEMONICS |
views::MenuRunner::CONTEXT_MENU) == views::MenuRunner::MENU_DELETED)
return;
}
bool ShellContextMenu::IsCommandIdChecked(int command_id) const {
return false;
}
bool ShellContextMenu::IsCommandIdEnabled(int command_id) const {
switch (static_cast<MenuItem>(command_id)) {
case MENU_CHANGE_WALLPAPER: {
return Shell::GetInstance()->user_wallpaper_delegate()->
CanOpenSetWallpaperPage();
}
default:
return true;
}
}
void ShellContextMenu::ExecuteCommand(int command_id) {
switch (static_cast<MenuItem>(command_id)) {
case MENU_CHANGE_WALLPAPER: {
Shell::GetInstance()->user_wallpaper_delegate()->
OpenSetWallpaperPage();
break;
}
}
}
bool ShellContextMenu::GetAcceleratorForCommandId(
int command_id,
ui::Accelerator* accelerator) {
return false;
}
} // namespace internal
} // namespace ash

@ -1,53 +0,0 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SHELL_CONTEXT_MENU_H_
#define ASH_SHELL_CONTEXT_MENU_H_
#include "base/memory/scoped_ptr.h"
#include "ui/base/models/simple_menu_model.h"
namespace gfx {
class Point;
class Size;
}
namespace views {
class MenuRunner;
class Widget;
}
namespace ash {
namespace internal {
class ShellContextMenu : public ui::SimpleMenuModel::Delegate {
public:
ShellContextMenu();
virtual ~ShellContextMenu();
// Shows the context menu when right click on background.
void ShowMenu(views::Widget* widget, const gfx::Point& location);
// ui::SimpleMenuModel::Delegate overrides:
virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
virtual void ExecuteCommand(int command_id) OVERRIDE;
virtual bool GetAcceleratorForCommandId(
int command_id,
ui::Accelerator* accelerator) OVERRIDE;
private:
enum MenuItem {
MENU_CHANGE_WALLPAPER,
};
scoped_ptr<views::MenuRunner> menu_runner_;
DISALLOW_COPY_AND_ASSIGN(ShellContextMenu);
};
} // namespace internal
} // namespace ash
#endif // ASH_SHELL_CONTEXT_MENU_H_

@ -4,6 +4,7 @@
#include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
#include "ash/desktop_background/desktop_background_controller.h"
#include "ash/launcher/launcher_context_menu.h"
#include "ash/shell.h"
#include "base/command_line.h"
@ -99,6 +100,8 @@ LauncherContextMenu::LauncherContextMenu(ChromeLauncherController* controller,
IDS_AURA_LAUNCHER_CONTEXT_MENU_POSITION,
&alignment_menu_);
}
AddItem(MENU_CHANGE_WALLPAPER,
l10n_util::GetStringUTF16(IDS_AURA_SET_DESKTOP_WALLPAPER));
}
LauncherContextMenu::~LauncherContextMenu() {
@ -130,6 +133,9 @@ bool LauncherContextMenu::IsCommandIdEnabled(int command_id) const {
case MENU_PIN:
return item_.type == ash::TYPE_PLATFORM_APP ||
controller_->IsPinnable(item_.id);
case MENU_CHANGE_WALLPAPER:
return ash::Shell::GetInstance()->user_wallpaper_delegate()->
CanOpenSetWallpaperPage();
default:
return extension_items_->IsCommandIdEnabled(command_id);
}
@ -180,6 +186,10 @@ void LauncherContextMenu::ExecuteCommand(int command_id) {
break;
case MENU_ALIGNMENT_MENU:
break;
case MENU_CHANGE_WALLPAPER:
ash::Shell::GetInstance()->user_wallpaper_delegate()->
OpenSetWallpaperPage();
break;
default:
extension_items_->ExecuteCommand(command_id, NULL,
content::ContextMenuParams());

@ -51,6 +51,7 @@ class LauncherContextMenu : public ui::SimpleMenuModel,
MENU_NEW_WINDOW,
MENU_NEW_INCOGNITO_WINDOW,
MENU_ALIGNMENT_MENU,
MENU_CHANGE_WALLPAPER,
};
// Does |item_| represent a valid item? See description of constructor for