summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ash/mus/shell_delegate_mus.cc2
-rw-r--r--ash/mus/shell_delegate_mus.h2
-rw-r--r--ash/root_window_controller.cc2
-rw-r--r--ash/shelf/shelf.cc8
-rw-r--r--ash/shelf/shelf.h4
-rw-r--r--ash/shelf/shelf_alignment_menu.cc36
-rw-r--r--ash/shelf/shelf_alignment_menu.h10
-rw-r--r--ash/shelf/shelf_layout_manager.cc24
-rw-r--r--ash/shelf/shelf_layout_manager.h14
-rw-r--r--ash/shelf/shelf_view.cc3
-rw-r--r--ash/shell.cc12
-rw-r--r--ash/shell.h8
-rw-r--r--ash/shell/context_menu.cc42
-rw-r--r--ash/shell/context_menu.h15
-rw-r--r--ash/shell/shell_delegate_impl.cc4
-rw-r--r--ash/shell/shell_delegate_impl.h2
-rw-r--r--ash/shell_delegate.h5
-rw-r--r--ash/test/test_shell_delegate.cc2
-rw-r--r--ash/test/test_shell_delegate.h2
-rw-r--r--chrome/browser/ui/ash/chrome_shell_delegate.cc4
-rw-r--r--chrome/browser/ui/ash/chrome_shell_delegate.h2
-rw-r--r--chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc40
-rw-r--r--chrome/browser/ui/ash/launcher/chrome_launcher_controller.h12
-rw-r--r--chrome/browser/ui/ash/launcher/launcher_context_menu.cc32
-rw-r--r--chrome/browser/ui/ash/launcher/launcher_context_menu.h19
-rw-r--r--chrome/browser/ui/ash/launcher/launcher_context_menu_unittest.cc21
26 files changed, 125 insertions, 202 deletions
diff --git a/ash/mus/shell_delegate_mus.cc b/ash/mus/shell_delegate_mus.cc
index 4aa6e13..7f627e1 100644
--- a/ash/mus/shell_delegate_mus.cc
+++ b/ash/mus/shell_delegate_mus.cc
@@ -197,7 +197,7 @@ MediaDelegate* ShellDelegateMus::CreateMediaDelegate() {
return new MediaDelegateStub;
}
-ui::MenuModel* ShellDelegateMus::CreateContextMenu(aura::Window* root_window,
+ui::MenuModel* ShellDelegateMus::CreateContextMenu(ash::Shelf* shelf,
const ShelfItem* item) {
NOTIMPLEMENTED();
return nullptr;
diff --git a/ash/mus/shell_delegate_mus.h b/ash/mus/shell_delegate_mus.h
index f0486ab..804663d 100644
--- a/ash/mus/shell_delegate_mus.h
+++ b/ash/mus/shell_delegate_mus.h
@@ -46,7 +46,7 @@ class ShellDelegateMus : public ash::ShellDelegate {
ash::AccessibilityDelegate* CreateAccessibilityDelegate() override;
ash::NewWindowDelegate* CreateNewWindowDelegate() override;
ash::MediaDelegate* CreateMediaDelegate() override;
- ui::MenuModel* CreateContextMenu(aura::Window* root_window,
+ ui::MenuModel* CreateContextMenu(ash::Shelf* shelf,
const ash::ShelfItem* item) override;
GPUSupport* CreateGPUSupport() override;
base::string16 GetProductName() const override;
diff --git a/ash/root_window_controller.cc b/ash/root_window_controller.cc
index 4d021bf..a2d8219 100644
--- a/ash/root_window_controller.cc
+++ b/ash/root_window_controller.cc
@@ -561,7 +561,7 @@ void RootWindowController::ShowContextMenu(const gfx::Point& location_in_screen,
ShellDelegate* delegate = Shell::GetInstance()->delegate();
DCHECK(delegate);
scoped_ptr<ui::MenuModel> menu_model(
- delegate->CreateContextMenu(GetRootWindow(), nullptr));
+ delegate->CreateContextMenu(shelf_->shelf(), nullptr));
if (!menu_model)
return;
diff --git a/ash/shelf/shelf.cc b/ash/shelf/shelf.cc
index 18dd34a..58904c4 100644
--- a/ash/shelf/shelf.cc
+++ b/ash/shelf/shelf.cc
@@ -79,6 +79,14 @@ bool Shelf::IsHorizontalAlignment() const {
alignment_ == SHELF_ALIGNMENT_TOP;
}
+void Shelf::SetAutoHideBehavior(ShelfAutoHideBehavior behavior) {
+ shelf_widget_->shelf_layout_manager()->SetAutoHideBehavior(behavior);
+}
+
+ShelfAutoHideBehavior Shelf::GetAutoHideBehavior() const {
+ return shelf_widget_->shelf_layout_manager()->auto_hide_behavior();
+}
+
gfx::Rect Shelf::GetScreenBoundsOfItemIconForWindow(
const aura::Window* window) {
ShelfID id = GetShelfIDForWindow(window);
diff --git a/ash/shelf/shelf.h b/ash/shelf/shelf.h
index 597dd37..f884458 100644
--- a/ash/shelf/shelf.h
+++ b/ash/shelf/shelf.h
@@ -60,6 +60,10 @@ class ASH_EXPORT Shelf {
ShelfAlignment alignment() const { return alignment_; }
bool IsHorizontalAlignment() const;
+ // Sets the ShelfAutoHideBehavior. See enum description for details.
+ void SetAutoHideBehavior(ShelfAutoHideBehavior behavior);
+ ShelfAutoHideBehavior GetAutoHideBehavior() const;
+
// A helper functions that chooses values specific to a shelf alignment.
template <typename T>
T SelectValueForShelfAlignment(T bottom, T left, T right, T top) const {
diff --git a/ash/shelf/shelf_alignment_menu.cc b/ash/shelf/shelf_alignment_menu.cc
index 5b14e8f..6d67ed4 100644
--- a/ash/shelf/shelf_alignment_menu.cc
+++ b/ash/shelf/shelf_alignment_menu.cc
@@ -6,17 +6,18 @@
#include "ash/metrics/user_metrics_recorder.h"
#include "ash/shelf/shelf.h"
+#include "ash/shelf/shelf_layout_manager.h"
#include "ash/shelf/shelf_types.h"
+#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
#include "grit/ash_strings.h"
#include "ui/aura/window.h"
namespace ash {
-ShelfAlignmentMenu::ShelfAlignmentMenu(aura::Window* root)
- : ui::SimpleMenuModel(NULL),
- root_window_(root) {
- DCHECK(root_window_);
+ShelfAlignmentMenu::ShelfAlignmentMenu(Shelf* shelf)
+ : ui::SimpleMenuModel(nullptr), shelf_(shelf) {
+ DCHECK(shelf_);
int align_group_id = 1;
set_delegate(this);
AddRadioItemWithStringId(MENU_ALIGN_LEFT,
@@ -33,10 +34,9 @@ ShelfAlignmentMenu::ShelfAlignmentMenu(aura::Window* root)
ShelfAlignmentMenu::~ShelfAlignmentMenu() {}
bool ShelfAlignmentMenu::IsCommandIdChecked(int command_id) const {
- return Shelf::ForWindow(root_window_)
- ->SelectValueForShelfAlignment(MENU_ALIGN_BOTTOM == command_id,
- MENU_ALIGN_LEFT == command_id,
- MENU_ALIGN_RIGHT == command_id, false);
+ return shelf_->SelectValueForShelfAlignment(
+ MENU_ALIGN_BOTTOM == command_id, MENU_ALIGN_LEFT == command_id,
+ MENU_ALIGN_RIGHT == command_id, false);
}
bool ShelfAlignmentMenu::IsCommandIdEnabled(int command_id) const {
@@ -50,24 +50,20 @@ bool ShelfAlignmentMenu::GetAcceleratorForCommandId(
}
void ShelfAlignmentMenu::ExecuteCommand(int command_id, int event_flags) {
+ Shell* shell = Shell::GetInstance();
+ ShelfLayoutManager* manager = shelf_->shelf_widget()->shelf_layout_manager();
switch (static_cast<MenuItem>(command_id)) {
case MENU_ALIGN_LEFT:
- Shell::GetInstance()->metrics()->
- RecordUserMetricsAction(UMA_SHELF_ALIGNMENT_SET_LEFT);
- Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT,
- root_window_);
+ shell->metrics()->RecordUserMetricsAction(UMA_SHELF_ALIGNMENT_SET_LEFT);
+ manager->SetAlignment(SHELF_ALIGNMENT_LEFT);
break;
case MENU_ALIGN_BOTTOM:
- Shell::GetInstance()->metrics()->
- RecordUserMetricsAction(UMA_SHELF_ALIGNMENT_SET_BOTTOM);
- Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_BOTTOM,
- root_window_);
+ shell->metrics()->RecordUserMetricsAction(UMA_SHELF_ALIGNMENT_SET_BOTTOM);
+ manager->SetAlignment(SHELF_ALIGNMENT_BOTTOM);
break;
case MENU_ALIGN_RIGHT:
- Shell::GetInstance()->metrics()->
- RecordUserMetricsAction(UMA_SHELF_ALIGNMENT_SET_RIGHT);
- Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_RIGHT,
- root_window_);
+ shell->metrics()->RecordUserMetricsAction(UMA_SHELF_ALIGNMENT_SET_RIGHT);
+ manager->SetAlignment(SHELF_ALIGNMENT_RIGHT);
break;
}
}
diff --git a/ash/shelf/shelf_alignment_menu.h b/ash/shelf/shelf_alignment_menu.h
index add20f0..98d1eef 100644
--- a/ash/shelf/shelf_alignment_menu.h
+++ b/ash/shelf/shelf_alignment_menu.h
@@ -9,17 +9,15 @@
#include "base/macros.h"
#include "ui/base/models/simple_menu_model.h"
-namespace aura {
-class RootWindow;
-}
-
namespace ash {
+class Shelf;
+
// Submenu for choosing the alignment of the launcher.
class ASH_EXPORT ShelfAlignmentMenu : public ui::SimpleMenuModel,
public ui::SimpleMenuModel::Delegate {
public:
- explicit ShelfAlignmentMenu(aura::Window* root);
+ explicit ShelfAlignmentMenu(Shelf* shelf);
~ShelfAlignmentMenu() override;
// ui::SimpleMenuModel::Delegate overrides:
@@ -37,7 +35,7 @@ class ASH_EXPORT ShelfAlignmentMenu : public ui::SimpleMenuModel,
MENU_ALIGN_BOTTOM,
};
- aura::Window* root_window_;
+ Shelf* shelf_;
DISALLOW_COPY_AND_ASSIGN(ShelfAlignmentMenu);
};
diff --git a/ash/shelf/shelf_layout_manager.cc b/ash/shelf/shelf_layout_manager.cc
index 2509d47..8b779fd 100644
--- a/ash/shelf/shelf_layout_manager.cc
+++ b/ash/shelf/shelf_layout_manager.cc
@@ -247,21 +247,20 @@ bool ShelfLayoutManager::IsVisible() const {
state_.auto_hide_state == SHELF_AUTO_HIDE_SHOWN));
}
-bool ShelfLayoutManager::SetAlignment(ShelfAlignment alignment) {
+void ShelfLayoutManager::SetAlignment(ShelfAlignment alignment) {
if (alignment_ == alignment)
- return false;
+ return;
alignment_ = alignment;
// The shelf will itself move to the bottom while locked or obscured by user
// login. If a request is sent to move while being obscured, we postpone the
// move until the user session is resumed.
- if (IsAlignmentLocked())
- return false;
-
- // This should not be called during the lock screen transitions.
- shelf_->SetAlignment(alignment);
- LayoutShelf();
- return true;
+ if (!IsAlignmentLocked()) {
+ shelf_->SetAlignment(alignment);
+ LayoutShelf();
+ Shell::GetInstance()->OnShelfAlignmentChanged(
+ shelf_->GetNativeWindow()->GetRootWindow());
+ }
}
ShelfAlignment ShelfLayoutManager::GetAlignment() const {
@@ -296,11 +295,6 @@ void ShelfLayoutManager::LayoutShelf() {
ShelfVisibilityState ShelfLayoutManager::CalculateShelfVisibility() {
switch(auto_hide_behavior_) {
case SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS:
-#if defined(OS_WIN)
- // Disable shelf auto-hide behavior on screen sides in Metro mode.
- if (GetAlignment() != SHELF_ALIGNMENT_BOTTOM)
- return SHELF_VISIBLE;
-#endif
return SHELF_AUTO_HIDE;
case SHELF_AUTO_HIDE_BEHAVIOR_NEVER:
return SHELF_VISIBLE;
@@ -1149,6 +1143,8 @@ void ShelfLayoutManager::UpdateShelfVisibilityAfterLoginUIChange() {
shelf_->SetAlignment(GetAlignment());
UpdateVisibilityState();
LayoutShelf();
+ Shell::GetInstance()->OnShelfAlignmentChanged(
+ shelf_->GetNativeWindow()->GetRootWindow());
}
bool ShelfLayoutManager::IsAlignmentLocked() const {
diff --git a/ash/shelf/shelf_layout_manager.h b/ash/shelf/shelf_layout_manager.h
index 3f21f004..ae4a281 100644
--- a/ash/shelf/shelf_layout_manager.h
+++ b/ash/shelf/shelf_layout_manager.h
@@ -90,16 +90,11 @@ class ASH_EXPORT ShelfLayoutManager
return auto_hide_behavior_;
}
- // Sets the alignment. Returns true if the alignment got changed. If nothing
- // has visually be changed, false will be returned. This can happen if either
- // the alignment was already set, or the shelf is currently locked and cannot
- // be changed at this time. In the latter case the change will be performed
- // once the shelf gets unlocked.
- bool SetAlignment(ShelfAlignment alignment);
+ // Sets the alignment; changes are delayed if the screen is locked.
+ void SetAlignment(ShelfAlignment alignment);
// Returns the desired alignment for the current state, either the user's
- // set alignment (alignment_) or SHELF_ALIGNMENT_BOTTOM when the screen
- // is locked.
+ // selected alignment or SHELF_ALIGNMENT_BOTTOM when the screen is locked.
ShelfAlignment GetAlignment() const;
void set_workspace_controller(WorkspaceController* controller) {
@@ -127,8 +122,7 @@ class ASH_EXPORT ShelfLayoutManager
return user_work_area_bounds_;
}
- // Stops any animations and sets the bounds of the shelf and status
- // widgets.
+ // Stops any animations and sets the bounds of the shelf and status widgets.
void LayoutShelf();
// Returns shelf visibility state based on current value of auto hide
diff --git a/ash/shelf/shelf_view.cc b/ash/shelf/shelf_view.cc
index 9088f6c..d15cccd 100644
--- a/ash/shelf/shelf_view.cc
+++ b/ash/shelf/shelf_view.cc
@@ -1794,8 +1794,7 @@ void ShelfView::ShowContextMenuForView(views::View* source,
}
context_menu_model_.reset(Shell::GetInstance()->delegate()->CreateContextMenu(
- source->GetWidget()->GetNativeView()->GetRootWindow(),
- &model_->items()[view_index]));
+ shelf_, &model_->items()[view_index]));
if (!context_menu_model_)
return;
diff --git a/ash/shell.cc b/ash/shell.cc
index 6949d6c..71231a2 100644
--- a/ash/shell.cc
+++ b/ash/shell.cc
@@ -523,17 +523,19 @@ ShelfAutoHideBehavior Shell::GetShelfAutoHideBehavior(
void Shell::SetShelfAlignment(ShelfAlignment alignment,
aura::Window* root_window) {
ShelfWidget* shelf_widget = GetRootWindowController(root_window)->shelf();
- if (shelf_widget->shelf_layout_manager()->SetAlignment(alignment)) {
- FOR_EACH_OBSERVER(
- ShellObserver, observers_, OnShelfAlignmentChanged(root_window));
- }
+ shelf_widget->shelf_layout_manager()->SetAlignment(alignment);
}
-ShelfAlignment Shell::GetShelfAlignment(const aura::Window* root_window) {
+ShelfAlignment Shell::GetShelfAlignment(const aura::Window* root_window) const {
ShelfWidget* shelf_widget = GetRootWindowController(root_window)->shelf();
return shelf_widget->shelf_layout_manager()->GetAlignment();
}
+void Shell::OnShelfAlignmentChanged(aura::Window* root_window) {
+ FOR_EACH_OBSERVER(ShellObserver, observers_,
+ OnShelfAlignmentChanged(root_window));
+}
+
void Shell::NotifyFullscreenStateChange(bool is_fullscreen,
aura::Window* root_window) {
FOR_EACH_OBSERVER(ShellObserver, observers_, OnFullscreenStateChanged(
diff --git a/ash/shell.h b/ash/shell.h
index 74d0f12..fbd85b8 100644
--- a/ash/shell.h
+++ b/ash/shell.h
@@ -463,9 +463,11 @@ class ASH_EXPORT Shell : public SystemModalContainerEventFilterDelegate,
aura::Window* root_window) const;
// Sets/gets shelf's alignment on |root_window|.
- void SetShelfAlignment(ShelfAlignment alignment,
- aura::Window* root_window);
- ShelfAlignment GetShelfAlignment(const aura::Window* root_window);
+ void SetShelfAlignment(ShelfAlignment alignment, aura::Window* root_window);
+ ShelfAlignment GetShelfAlignment(const aura::Window* root_window) const;
+
+ // Called when the alignment for a shelf changes.
+ void OnShelfAlignmentChanged(aura::Window* root_window);
// Notifies |observers_| when entering or exiting fullscreen mode in
// |root_window|.
diff --git a/ash/shell/context_menu.cc b/ash/shell/context_menu.cc
index 91f5abd..c07c547 100644
--- a/ash/shell/context_menu.cc
+++ b/ash/shell/context_menu.cc
@@ -4,20 +4,16 @@
#include "ash/shell/context_menu.h"
-#include "ash/root_window_controller.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_types.h"
-#include "ash/shell.h"
#include "grit/ash_strings.h"
namespace ash {
namespace shell {
-ContextMenu::ContextMenu(aura::Window* root)
- : ui::SimpleMenuModel(NULL),
- root_window_(root),
- alignment_menu_(root) {
- DCHECK(root_window_);
+ContextMenu::ContextMenu(ash::Shelf* shelf)
+ : ui::SimpleMenuModel(nullptr), shelf_(shelf), alignment_menu_(shelf) {
+ DCHECK(shelf_);
set_delegate(this);
AddCheckItemWithStringId(MENU_AUTO_HIDE,
IDS_ASH_SHELF_CONTEXT_MENU_AUTO_HIDE);
@@ -30,38 +26,26 @@ ContextMenu::~ContextMenu() {
}
bool ContextMenu::IsCommandIdChecked(int command_id) const {
- switch (command_id) {
- case MENU_AUTO_HIDE:
- return Shell::GetInstance()->GetShelfAutoHideBehavior(root_window_) ==
- ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS;
- default:
- return false;
- }
+ if (command_id == MENU_AUTO_HIDE)
+ return shelf_->GetAutoHideBehavior() == SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS;
+ return false;
}
bool ContextMenu::IsCommandIdEnabled(int command_id) const {
return true;
}
-bool ContextMenu::GetAcceleratorForCommandId(
- int command_id,
- ui::Accelerator* accelerator) {
+bool ContextMenu::GetAcceleratorForCommandId(int command_id,
+ ui::Accelerator* accelerator) {
return false;
}
void ContextMenu::ExecuteCommand(int command_id, int event_flags) {
- Shell* shell = Shell::GetInstance();
- switch (static_cast<MenuItem>(command_id)) {
- case MENU_AUTO_HIDE:
- shell->SetShelfAutoHideBehavior(
- shell->GetShelfAutoHideBehavior(root_window_) ==
- SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS ?
- SHELF_AUTO_HIDE_BEHAVIOR_NEVER :
- SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS,
- root_window_);
- break;
- case MENU_ALIGNMENT_MENU:
- break;
+ if (command_id == MENU_AUTO_HIDE) {
+ shelf_->SetAutoHideBehavior(shelf_->GetAutoHideBehavior() ==
+ SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
+ ? SHELF_AUTO_HIDE_BEHAVIOR_NEVER
+ : SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
}
}
diff --git a/ash/shell/context_menu.h b/ash/shell/context_menu.h
index 072e457..b604884 100644
--- a/ash/shell/context_menu.h
+++ b/ash/shell/context_menu.h
@@ -6,22 +6,20 @@
#define ASH_SHELL_CONTEXT_MENU_H_
#include "ash/shelf/shelf_alignment_menu.h"
-#include "ash/shelf/shelf_types.h"
#include "base/macros.h"
#include "ui/base/models/simple_menu_model.h"
-namespace aura {
-class RootWindow;
-}
-
namespace ash {
+
+class Shelf;
+
namespace shell {
-// Context menu for the ash_shell.
+// Context menu for the ash shell.
class ContextMenu : public ui::SimpleMenuModel,
public ui::SimpleMenuModel::Delegate {
public:
- explicit ContextMenu(aura::Window* root);
+ explicit ContextMenu(Shelf* shelf);
~ContextMenu() override;
// ui::SimpleMenuModel::Delegate overrides:
@@ -37,8 +35,7 @@ class ContextMenu : public ui::SimpleMenuModel,
MENU_ALIGNMENT_MENU,
};
- aura::Window* root_window_;
-
+ Shelf* shelf_;
ShelfAlignmentMenu alignment_menu_;
DISALLOW_COPY_AND_ASSIGN(ContextMenu);
diff --git a/ash/shell/shell_delegate_impl.cc b/ash/shell/shell_delegate_impl.cc
index d996a22..7353976 100644
--- a/ash/shell/shell_delegate_impl.cc
+++ b/ash/shell/shell_delegate_impl.cc
@@ -225,9 +225,9 @@ ash::MediaDelegate* ShellDelegateImpl::CreateMediaDelegate() {
}
ui::MenuModel* ShellDelegateImpl::CreateContextMenu(
- aura::Window* root_window,
+ ash::Shelf* shelf,
const ash::ShelfItem* item) {
- return new ContextMenu(root_window);
+ return new ContextMenu(shelf);
}
GPUSupport* ShellDelegateImpl::CreateGPUSupport() {
diff --git a/ash/shell/shell_delegate_impl.h b/ash/shell/shell_delegate_impl.h
index c53c702..7a5684b 100644
--- a/ash/shell/shell_delegate_impl.h
+++ b/ash/shell/shell_delegate_impl.h
@@ -48,7 +48,7 @@ class ShellDelegateImpl : public ash::ShellDelegate {
ash::AccessibilityDelegate* CreateAccessibilityDelegate() override;
ash::NewWindowDelegate* CreateNewWindowDelegate() override;
ash::MediaDelegate* CreateMediaDelegate() override;
- ui::MenuModel* CreateContextMenu(aura::Window* root_window,
+ ui::MenuModel* CreateContextMenu(ash::Shelf* shelf,
const ash::ShelfItem* item) override;
GPUSupport* CreateGPUSupport() override;
base::string16 GetProductName() const override;
diff --git a/ash/shell_delegate.h b/ash/shell_delegate.h
index cd36fd4..6569688 100644
--- a/ash/shell_delegate.h
+++ b/ash/shell_delegate.h
@@ -42,6 +42,7 @@ class ShelfDelegate;
class ShelfModel;
class SystemTrayDelegate;
class UserWallpaperDelegate;
+class Shelf;
struct ShelfItem;
class ASH_EXPORT VirtualKeyboardStateObserver {
@@ -132,9 +133,9 @@ class ASH_EXPORT ShellDelegate {
// Creates a media delegate. Shell takes ownership of the delegate.
virtual MediaDelegate* CreateMediaDelegate() = 0;
- // Creates a menu model for the |root_window| and optional shelf |item|.
+ // Creates a menu model for the |shelf| 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,
+ virtual ui::MenuModel* CreateContextMenu(ash::Shelf* shelf,
const ash::ShelfItem* item) = 0;
// Creates a GPU support object. Shell takes ownership of the object.
diff --git a/ash/test/test_shell_delegate.cc b/ash/test/test_shell_delegate.cc
index b5d7fc0..c0bbcbd 100644
--- a/ash/test/test_shell_delegate.cc
+++ b/ash/test/test_shell_delegate.cc
@@ -175,7 +175,7 @@ MediaDelegate* TestShellDelegate::CreateMediaDelegate() {
}
ui::MenuModel* TestShellDelegate::CreateContextMenu(
- aura::Window* root_window,
+ ash::Shelf* shelf,
const ash::ShelfItem* item) {
return nullptr;
}
diff --git a/ash/test/test_shell_delegate.h b/ash/test/test_shell_delegate.h
index 80de3b7..18f2dfe 100644
--- a/ash/test/test_shell_delegate.h
+++ b/ash/test/test_shell_delegate.h
@@ -55,7 +55,7 @@ class TestShellDelegate : public ShellDelegate {
AccessibilityDelegate* CreateAccessibilityDelegate() override;
NewWindowDelegate* CreateNewWindowDelegate() override;
MediaDelegate* CreateMediaDelegate() override;
- ui::MenuModel* CreateContextMenu(aura::Window* root_window,
+ ui::MenuModel* CreateContextMenu(ash::Shelf* shelf,
const ash::ShelfItem* item) override;
GPUSupport* CreateGPUSupport() override;
base::string16 GetProductName() const override;
diff --git a/chrome/browser/ui/ash/chrome_shell_delegate.cc b/chrome/browser/ui/ash/chrome_shell_delegate.cc
index a61c886..4d199ec 100644
--- a/chrome/browser/ui/ash/chrome_shell_delegate.cc
+++ b/chrome/browser/ui/ash/chrome_shell_delegate.cc
@@ -142,14 +142,14 @@ ash::ShelfDelegate* ChromeShellDelegate::CreateShelfDelegate(
}
ui::MenuModel* ChromeShellDelegate::CreateContextMenu(
- aura::Window* root_window,
+ ash::Shelf* shelf,
const ash::ShelfItem* item) {
DCHECK(shelf_delegate_);
// Don't show context menu for exclusive app runtime mode.
if (chrome::IsRunningInAppMode())
return nullptr;
- return new LauncherContextMenu(shelf_delegate_, item, root_window);
+ return new LauncherContextMenu(shelf_delegate_, item, shelf);
}
ash::GPUSupport* ChromeShellDelegate::CreateGPUSupport() {
diff --git a/chrome/browser/ui/ash/chrome_shell_delegate.h b/chrome/browser/ui/ash/chrome_shell_delegate.h
index 86827f8..0fcf87e7 100644
--- a/chrome/browser/ui/ash/chrome_shell_delegate.h
+++ b/chrome/browser/ui/ash/chrome_shell_delegate.h
@@ -61,7 +61,7 @@ class ChromeShellDelegate : public ash::ShellDelegate,
ash::AccessibilityDelegate* CreateAccessibilityDelegate() override;
ash::NewWindowDelegate* CreateNewWindowDelegate() override;
ash::MediaDelegate* CreateMediaDelegate() override;
- ui::MenuModel* CreateContextMenu(aura::Window* root_window,
+ ui::MenuModel* CreateContextMenu(ash::Shelf* shelf,
const ash::ShelfItem* item) override;
ash::GPUSupport* CreateGPUSupport() override;
base::string16 GetProductName() const override;
diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc b/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc
index 19b1cf1..3d5705e 100644
--- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc
+++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc
@@ -1031,34 +1031,6 @@ Profile* ChromeLauncherController::profile() {
return profile_;
}
-ash::ShelfAutoHideBehavior ChromeLauncherController::GetShelfAutoHideBehavior(
- aura::Window* root_window) const {
- return GetShelfAutoHideBehaviorFromPrefs(profile_, root_window);
-}
-
-bool ChromeLauncherController::CanUserModifyShelfAutoHideBehavior(
- aura::Window* root_window) const {
-#if defined(OS_WIN)
- // Disable shelf auto-hide behavior on screen sides in Metro mode.
- if (ash::Shell::GetInstance()->GetShelfAlignment(root_window) !=
- ash::SHELF_ALIGNMENT_BOTTOM) {
- return false;
- }
-#endif
- return profile_->GetPrefs()->
- FindPreference(prefs::kShelfAutoHideBehaviorLocal)->IsUserModifiable();
-}
-
-void ChromeLauncherController::ToggleShelfAutoHideBehavior(
- aura::Window* root_window) {
- ash::ShelfAutoHideBehavior behavior = GetShelfAutoHideBehavior(root_window) ==
- ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS ?
- ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER :
- ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS;
- SetShelfAutoHideBehaviorPrefs(behavior, root_window);
- return;
-}
-
void ChromeLauncherController::UpdateAppState(content::WebContents* contents,
AppState app_state) {
std::string app_id = app_tab_helper_->GetAppID(contents);
@@ -1840,11 +1812,9 @@ void ChromeLauncherController::SetShelfAutoHideBehaviorPrefs(
void ChromeLauncherController::SetShelfAutoHideBehaviorFromPrefs() {
aura::Window::Windows root_windows = ash::Shell::GetAllRootWindows();
-
- for (aura::Window::Windows::const_iterator iter = root_windows.begin();
- iter != root_windows.end(); ++iter) {
+ for (auto i = root_windows.begin(); i != root_windows.end(); ++i) {
ash::Shell::GetInstance()->SetShelfAutoHideBehavior(
- GetShelfAutoHideBehavior(*iter), *iter);
+ GetShelfAutoHideBehaviorFromPrefs(profile_, *i), *i);
}
}
@@ -1853,11 +1823,9 @@ void ChromeLauncherController::SetShelfAlignmentFromPrefs() {
return;
aura::Window::Windows root_windows = ash::Shell::GetAllRootWindows();
-
- for (aura::Window::Windows::const_iterator iter = root_windows.begin();
- iter != root_windows.end(); ++iter) {
+ for (auto i = root_windows.begin(); i != root_windows.end(); ++i) {
ash::Shell::GetInstance()->SetShelfAlignment(
- GetShelfAlignmentFromPrefs(profile_, *iter), *iter);
+ GetShelfAlignmentFromPrefs(profile_, *i), *i);
}
}
diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.h b/chrome/browser/ui/ash/launcher/chrome_launcher_controller.h
index 0544e85..69f1f30 100644
--- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.h
+++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller.h
@@ -249,18 +249,6 @@ class ChromeLauncherController
// cases this might change over time.
Profile* profile();
- // Gets the shelf auto-hide behavior on |root_window|.
- ash::ShelfAutoHideBehavior GetShelfAutoHideBehavior(
- aura::Window* root_window) const;
-
- // Returns |true| if the user is allowed to modify the shelf auto-hide
- // behavior on |root_window|.
- bool CanUserModifyShelfAutoHideBehavior(aura::Window* root_window) const;
-
- // Toggles the shelf auto-hide behavior on |root_window|. Does nothing if the
- // user is not allowed to modify the auto-hide behavior.
- void ToggleShelfAutoHideBehavior(aura::Window* root_window);
-
// Notify the controller that the state of an non platform app's tabs
// have changed,
void UpdateAppState(content::WebContents* contents, AppState app_state);
diff --git a/chrome/browser/ui/ash/launcher/launcher_context_menu.cc b/chrome/browser/ui/ash/launcher/launcher_context_menu.cc
index f923be8..1539ae9 100644
--- a/chrome/browser/ui/ash/launcher/launcher_context_menu.cc
+++ b/chrome/browser/ui/ash/launcher/launcher_context_menu.cc
@@ -8,8 +8,8 @@
#include "ash/desktop_background/user_wallpaper_delegate.h"
#include "ash/metrics/user_metrics_recorder.h"
-#include "ash/root_window_controller.h"
#include "ash/session/session_state_delegate.h"
+#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_item_delegate.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
@@ -23,6 +23,7 @@
#include "chrome/browser/ui/ash/chrome_shell_delegate.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
#include "chrome/common/extensions/extension_constants.h"
+#include "chrome/common/pref_names.h"
#include "chrome/grit/generated_resources.h"
#include "components/prefs/pref_service.h"
#include "content/public/common/context_menu_params.h"
@@ -35,24 +36,30 @@ bool MenuItemHasLauncherContext(const extensions::MenuItem* item) {
return item->contexts().Contains(extensions::MenuItem::LAUNCHER);
}
+// Returns true if the user can modify the |shelf|'s auto-hide behavior.
+bool CanUserModifyShelfAutoHideBehavior(const Profile* profile) {
+ const std::string& pref = prefs::kShelfAutoHideBehaviorLocal;
+ return profile->GetPrefs()->FindPreference(pref)->IsUserModifiable();
+}
+
} // namespace
LauncherContextMenu::LauncherContextMenu(ChromeLauncherController* controller,
const ash::ShelfItem* item,
- aura::Window* root_window)
+ ash::Shelf* shelf)
: ui::SimpleMenuModel(nullptr),
controller_(controller),
item_(item ? *item : ash::ShelfItem()),
- shelf_alignment_menu_(root_window),
- root_window_(root_window) {
- DCHECK(root_window_);
+ shelf_alignment_menu_(shelf),
+ shelf_(shelf) {
+ DCHECK(shelf_);
Init();
}
void LauncherContextMenu::Init() {
set_delegate(this);
- if (is_valid_item()) {
+ if (item_.id != 0) {
extension_items_.reset(new extensions::ContextMenuMatcher(
controller_->profile(), this, this,
base::Bind(MenuItemHasLauncherContext)));
@@ -150,7 +157,7 @@ void LauncherContextMenu::Init() {
// type of fullscreen. Do not show the auto-hide menu item while in fullscreen
// because it is confusing when the preference appears not to apply.
if (!IsFullScreenMode() &&
- controller_->CanUserModifyShelfAutoHideBehavior(root_window_)) {
+ CanUserModifyShelfAutoHideBehavior(controller_->profile())) {
AddCheckItemWithStringId(MENU_AUTO_HIDE,
IDS_ASH_SHELF_CONTEXT_MENU_AUTO_HIDE);
}
@@ -211,8 +218,8 @@ bool LauncherContextMenu::IsCommandIdChecked(int command_id) const {
return controller_->GetLaunchType(item_.id) ==
extensions::LAUNCH_TYPE_FULLSCREEN;
case MENU_AUTO_HIDE:
- return controller_->GetShelfAutoHideBehavior(root_window_) ==
- ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS;
+ return shelf_->GetAutoHideBehavior() ==
+ ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS;
default:
if (command_id < MENU_ITEM_COUNT)
return false;
@@ -233,7 +240,7 @@ bool LauncherContextMenu::IsCommandIdEnabled(int command_id) const {
return IncognitoModePrefs::GetAvailability(
controller_->profile()->GetPrefs()) != IncognitoModePrefs::FORCED;
case MENU_AUTO_HIDE:
- return controller_->CanUserModifyShelfAutoHideBehavior(root_window_);
+ return CanUserModifyShelfAutoHideBehavior(controller_->profile());
case MENU_NEW_INCOGNITO_WINDOW:
// Incognito windows are not allowed when incognito is disabled.
return IncognitoModePrefs::GetAvailability(
@@ -298,7 +305,10 @@ void LauncherContextMenu::ExecuteCommand(int command_id, int event_flags) {
controller_->SetLaunchType(item_.id, extensions::LAUNCH_TYPE_FULLSCREEN);
break;
case MENU_AUTO_HIDE:
- controller_->ToggleShelfAutoHideBehavior(root_window_);
+ shelf_->SetAutoHideBehavior(shelf_->GetAutoHideBehavior() ==
+ ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
+ ? ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER
+ : ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
break;
case MENU_NEW_WINDOW:
controller_->CreateNewWindow();
diff --git a/chrome/browser/ui/ash/launcher/launcher_context_menu.h b/chrome/browser/ui/ash/launcher/launcher_context_menu.h
index 159ea77..f7006c9 100644
--- a/chrome/browser/ui/ash/launcher/launcher_context_menu.h
+++ b/chrome/browser/ui/ash/launcher/launcher_context_menu.h
@@ -14,30 +14,21 @@
class ChromeLauncherController;
-namespace aura {
-class Window;
-}
-
namespace extensions {
class ContextMenuMatcher;
}
-// Context menu shown for a launcher item.
+// Context menu shown for the ash shell desktop, or for an item in the shelf.
class LauncherContextMenu : public ui::SimpleMenuModel,
public ui::SimpleMenuModel::Delegate {
public:
- // Creates a context menu for the desktop, or shelf |item|, in |root_window|.
LauncherContextMenu(ChromeLauncherController* controller,
const ash::ShelfItem* item,
- aura::Window* root_window);
-
+ ash::Shelf* shelf);
~LauncherContextMenu() override;
void Init();
- // ID of the item we're showing the context menu for.
- ash::ShelfID id() const { return item_.id; }
-
// ui::SimpleMenuModel::Delegate overrides:
bool IsItemForCommandIdDynamic(int command_id) const override;
base::string16 GetLabelForCommandId(int command_id) const override;
@@ -74,10 +65,6 @@ class LauncherContextMenu : public ui::SimpleMenuModel,
MENU_ITEM_COUNT
};
- // Does |item_| represent a valid item? See description of constructor for
- // details on why it may not be valid.
- bool is_valid_item() const { return item_.id != 0; }
-
ChromeLauncherController* controller_;
ash::ShelfItem item_;
@@ -86,7 +73,7 @@ class LauncherContextMenu : public ui::SimpleMenuModel,
scoped_ptr<extensions::ContextMenuMatcher> extension_items_;
- aura::Window* root_window_;
+ ash::Shelf* shelf_;
DISALLOW_COPY_AND_ASSIGN(LauncherContextMenu);
};
diff --git a/chrome/browser/ui/ash/launcher/launcher_context_menu_unittest.cc b/chrome/browser/ui/ash/launcher/launcher_context_menu_unittest.cc
index 87e1dc1..f41ae24 100644
--- a/chrome/browser/ui/ash/launcher/launcher_context_menu_unittest.cc
+++ b/chrome/browser/ui/ash/launcher/launcher_context_menu_unittest.cc
@@ -18,33 +18,21 @@
#include "components/prefs/pref_service.h"
#include "ui/aura/window_event_dispatcher.h"
-class TestChromeLauncherController : public ChromeLauncherController {
- public:
- TestChromeLauncherController(Profile* profile, ash::ShelfModel* model)
- : ChromeLauncherController(profile, model) {}
- bool IsLoggedInAsGuest() override { return false; }
- private:
- DISALLOW_COPY_AND_ASSIGN(TestChromeLauncherController);
-};
-
class LauncherContextMenuTest : public ash::test::AshTestBase {
protected:
static bool IsItemPresentInMenu(LauncherContextMenu* menu, int command_id) {
- DCHECK(menu);
return menu->GetIndexOfCommandId(command_id) != -1;
}
- LauncherContextMenuTest()
- : profile_(new TestingProfile()) {}
+ LauncherContextMenuTest() : profile_(new TestingProfile()) {}
void SetUp() override {
ash::test::AshTestBase::SetUp();
- controller_.reset(
- new TestChromeLauncherController(profile(), &shelf_model_));
+ controller_.reset(new ChromeLauncherController(profile(), &shelf_model_));
}
void TearDown() override {
- controller_.reset(NULL);
+ controller_.reset(nullptr);
ash::test::AshTestBase::TearDown();
}
@@ -53,7 +41,8 @@ class LauncherContextMenuTest : public ash::test::AshTestBase {
ash::ShelfItem item;
item.id = 1; // dummy id
item.type = shelf_item_type;
- return new LauncherContextMenu(controller_.get(), &item, CurrentContext());
+ ash::Shelf* shelf = ash::Shelf::ForWindow(CurrentContext());
+ return new LauncherContextMenu(controller_.get(), &item, shelf);
}
Profile* profile() { return profile_.get(); }