diff options
Diffstat (limited to 'ash')
-rw-r--r-- | ash/ash.gyp | 3 | ||||
-rw-r--r-- | ash/ash_strings.grd | 6 | ||||
-rw-r--r-- | ash/launcher/launcher_context_menu.cc | 84 | ||||
-rw-r--r-- | ash/launcher/launcher_context_menu.h | 49 | ||||
-rw-r--r-- | ash/launcher/launcher_context_menu_unittest.cc | 53 | ||||
-rw-r--r-- | ash/shell.cc | 4 | ||||
-rw-r--r-- | ash/shell.h | 3 | ||||
-rw-r--r-- | ash/shell/launcher_delegate_impl.cc | 3 | ||||
-rw-r--r-- | ash/wm/workspace/workspace_manager.cc | 21 | ||||
-rw-r--r-- | ash/wm/workspace/workspace_manager.h | 10 | ||||
-rw-r--r-- | ash/wm/workspace_controller.cc | 4 | ||||
-rw-r--r-- | ash/wm/workspace_controller.h | 2 |
12 files changed, 212 insertions, 30 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp index ad6445b..c88621a 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -88,6 +88,8 @@ 'launcher/launcher.h', 'launcher/launcher_button.cc', 'launcher/launcher_button.h', + 'launcher/launcher_context_menu.cc', + 'launcher/launcher_context_menu.h', 'launcher/launcher_delegate.h', 'launcher/launcher_model.cc', 'launcher/launcher_model.h', @@ -335,6 +337,7 @@ 'drag_drop/drag_drop_controller_unittest.cc', 'focus_cycler_unittest.cc', 'ime/input_method_event_filter_unittest.cc', + 'launcher/launcher_context_menu_unittest.cc', 'launcher/launcher_model_unittest.cc', 'launcher/launcher_unittest.cc', 'monitor/multi_monitor_manager_unittest.cc', diff --git a/ash/ash_strings.grd b/ash/ash_strings.grd index 7ba89c5..7150e9a 100644 --- a/ash/ash_strings.grd +++ b/ash/ash_strings.grd @@ -173,6 +173,12 @@ This file contains the strings for ash. <message name="IDS_AURA_LAUNCHER_OVERFLOW_NAME" desc="The title used for the Aura overflow button in the launcher"> Overflow Button </message> + <message name="IDS_AURA_LAUNCHER_CONTEXT_MENU_AUTO_HIDE_MAXIMIZED" desc="Title of the menu item in the context menu for auto-hiding the launcher when the current window is maximized"> + Autohide launcher when maximized + </message> + <message name="IDS_AURA_LAUNCHER_CONTEXT_MENU_AUTO_HIDE_NOT_MAXIMIZED" desc="Title of the menu item in the context menu for auto-hiding the launcher when the current window is not maximized"> + Autohide launcher + </message> <message name="IDS_AURA_SET_DESKTOP_WALLPAPER" desc="The label used for change wallpaper in context menu"> Set Wallpaper... diff --git a/ash/launcher/launcher_context_menu.cc b/ash/launcher/launcher_context_menu.cc new file mode 100644 index 0000000..3872ade --- /dev/null +++ b/ash/launcher/launcher_context_menu.cc @@ -0,0 +1,84 @@ +// 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/launcher/launcher_context_menu.h" + +#include "ash/shell.h" +#include "grit/ash_strings.h" +#include "ui/base/l10n/l10n_util.h" + +namespace ash { + +LauncherContextMenu::LauncherContextMenu() : ui::SimpleMenuModel(NULL) { + set_delegate(this); + AddCheckItemWithStringId(MENU_AUTO_HIDE, GetAutoHideResourceStringId()); +} + +LauncherContextMenu::~LauncherContextMenu() { +} + +// static +bool LauncherContextMenu::IsAutoHideMenuHideChecked() { + ash::Shell* shell = ash::Shell::GetInstance(); + ash::ShelfAutoHideBehavior auto_hide_behavior = + shell->GetShelfAutoHideBehavior(); + return (shell->IsInMaximizedMode() && + (auto_hide_behavior == ash::SHELF_AUTO_HIDE_BEHAVIOR_DEFAULT || + auto_hide_behavior == ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS)) || + (!shell->IsInMaximizedMode() && + auto_hide_behavior == ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); +} + +// static +void LauncherContextMenu::ToggleAutoHideMenu() { + ash::Shell* shell = ash::Shell::GetInstance(); + ash::ShelfAutoHideBehavior auto_hide_behavior; + if (shell->IsInMaximizedMode()) { + if (IsAutoHideMenuHideChecked()) + auto_hide_behavior = ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER; + else + auto_hide_behavior = ash::SHELF_AUTO_HIDE_BEHAVIOR_DEFAULT; + } else if (IsAutoHideMenuHideChecked()) { + auto_hide_behavior = ash::SHELF_AUTO_HIDE_BEHAVIOR_DEFAULT; + } else { + auto_hide_behavior = ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; + } + shell->SetShelfAutoHideBehavior(auto_hide_behavior); +} + +// static +int LauncherContextMenu::GetAutoHideResourceStringId() { + return ash::Shell::GetInstance()->IsInMaximizedMode() ? + IDS_AURA_LAUNCHER_CONTEXT_MENU_AUTO_HIDE_MAXIMIZED : + IDS_AURA_LAUNCHER_CONTEXT_MENU_AUTO_HIDE_NOT_MAXIMIZED; +} + +bool LauncherContextMenu::IsCommandIdChecked(int command_id) const { + switch (command_id) { + case MENU_AUTO_HIDE: + return IsAutoHideMenuHideChecked(); + default: + return false; + } +} + +bool LauncherContextMenu::IsCommandIdEnabled(int command_id) const { + return true; +} + +bool LauncherContextMenu::GetAcceleratorForCommandId( + int command_id, + ui::Accelerator* accelerator) { + return false; +} + +void LauncherContextMenu::ExecuteCommand(int command_id) { + switch (static_cast<MenuItem>(command_id)) { + case MENU_AUTO_HIDE: + ToggleAutoHideMenu(); + break; + } +} + +} // namespace ash diff --git a/ash/launcher/launcher_context_menu.h b/ash/launcher/launcher_context_menu.h new file mode 100644 index 0000000..a7f638f --- /dev/null +++ b/ash/launcher/launcher_context_menu.h @@ -0,0 +1,49 @@ +// 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_WM_LAUNCHER_LAUNCHER_CONTEXT_MENU_H_ +#define ASH_WM_LAUNCHER_LAUNCHER_CONTEXT_MENU_H_ +#pragma once + +#include "ash/ash_export.h" +#include "base/basictypes.h" +#include "ui/base/models/simple_menu_model.h" + +namespace ash { + +// Context menu for the launcher. +class ASH_EXPORT LauncherContextMenu : public ui::SimpleMenuModel, + public ui::SimpleMenuModel::Delegate { + public: + LauncherContextMenu(); + virtual ~LauncherContextMenu(); + + // Returns true if the auto-hide menu item is checked. + static bool IsAutoHideMenuHideChecked(); + + // Toggles the state of the auto-hide menu item. + static void ToggleAutoHideMenu(); + + // Returns the resource id for the auto-hide menu. + static int GetAutoHideResourceStringId(); + + // ui::SimpleMenuModel::Delegate overrides: + virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; + virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; + virtual bool GetAcceleratorForCommandId( + int command_id, + ui::Accelerator* accelerator) OVERRIDE; + virtual void ExecuteCommand(int command_id) OVERRIDE; + + private: + enum MenuItem { + MENU_AUTO_HIDE, + }; + + DISALLOW_COPY_AND_ASSIGN(LauncherContextMenu); +}; + +} // namespace ash + +#endif // ASH_WM_LAUNCHER_LAUNCHER_CONTEXT_MENU_H_ diff --git a/ash/launcher/launcher_context_menu_unittest.cc b/ash/launcher/launcher_context_menu_unittest.cc new file mode 100644 index 0000000..5143d69 --- /dev/null +++ b/ash/launcher/launcher_context_menu_unittest.cc @@ -0,0 +1,53 @@ +// 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/launcher/launcher_context_menu.h" + +#include "ash/shell.h" +#include "ash/test/ash_test_base.h" +#include "ash/wm/property_util.h" +#include "ash/wm/window_util.h" +#include "ui/aura/client/aura_constants.h" +#include "ui/aura/window.h" +#include "ui/base/ui_base_types.h" +#include "ui/gfx/compositor/layer.h" + +namespace ash { + +typedef test::AshTestBase LauncherContextMenuTest; + +// Various assertions around IsAutoHideMenuHideChecked() and +// ToggleAutoHideMenu(). +TEST_F(LauncherContextMenuTest, ToggleAutoHide) { + scoped_ptr<aura::Window> window(new aura::Window(NULL)); + window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); + window->SetType(aura::client::WINDOW_TYPE_NORMAL); + window->Init(ui::LAYER_TEXTURED); + window->SetParent(NULL); + window->Show(); + + Shell* shell = Shell::GetInstance(); + // If the auto-hide behavior isn't DEFAULT, the rest of the tests don't make + // sense. + EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_DEFAULT, + shell->GetShelfAutoHideBehavior()); + EXPECT_FALSE(LauncherContextMenu::IsAutoHideMenuHideChecked()); + LauncherContextMenu::ToggleAutoHideMenu(); + EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, + shell->GetShelfAutoHideBehavior()); + LauncherContextMenu::ToggleAutoHideMenu(); + EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_DEFAULT, + shell->GetShelfAutoHideBehavior()); + + window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); + EXPECT_TRUE(LauncherContextMenu::IsAutoHideMenuHideChecked()); + LauncherContextMenu::ToggleAutoHideMenu(); + EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER, + shell->GetShelfAutoHideBehavior()); + LauncherContextMenu::ToggleAutoHideMenu(); + EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_DEFAULT, + shell->GetShelfAutoHideBehavior()); +} + +} // namespace ash diff --git a/ash/shell.cc b/ash/shell.cc index 8fc842c..d273752 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -894,6 +894,10 @@ int Shell::GetGridSize() const { return workspace_controller_->workspace_manager()->grid_size(); } +bool Shell::IsInMaximizedMode() const { + return workspace_controller_->workspace_manager()->IsInMaximizedMode(); +} + //////////////////////////////////////////////////////////////////////////////// // Shell, private: diff --git a/ash/shell.h b/ash/shell.h index f7fda36..35632a5 100644 --- a/ash/shell.h +++ b/ash/shell.h @@ -235,6 +235,9 @@ class ASH_EXPORT Shell { // Returns the size of the grid. int GetGridSize() const; + // Returns true if in maximized or fullscreen mode. + bool IsInMaximizedMode() const; + static void set_initially_hide_cursor(bool hide) { initially_hide_cursor_ = hide; } diff --git a/ash/shell/launcher_delegate_impl.cc b/ash/shell/launcher_delegate_impl.cc index 9d7fe27..ddf4add 100644 --- a/ash/shell/launcher_delegate_impl.cc +++ b/ash/shell/launcher_delegate_impl.cc @@ -4,6 +4,7 @@ #include "ash/shell/launcher_delegate_impl.h" +#include "ash/launcher/launcher_context_menu.h" #include "ash/shell/toplevel_window.h" #include "ash/shell/window_watcher.h" #include "ash/wm/window_util.h" @@ -52,7 +53,7 @@ ui::MenuModel* LauncherDelegateImpl::CreateContextMenu( } ui::MenuModel* LauncherDelegateImpl::CreateContextMenuForLauncher() { - return NULL; + return new LauncherContextMenu; } ash::LauncherID LauncherDelegateImpl::GetIDByWindow(aura::Window* window) { diff --git a/ash/wm/workspace/workspace_manager.cc b/ash/wm/workspace/workspace_manager.cc index e461d9e..05ab750 100644 --- a/ash/wm/workspace/workspace_manager.cc +++ b/ash/wm/workspace/workspace_manager.cc @@ -33,13 +33,6 @@ namespace { -// The horizontal margein between workspaces in pixels. -const int kWorkspaceHorizontalMargin = 50; - -// Minimum/maximum scale for overview mode. -const float kMaxOverviewScale = 0.9f; -const float kMinOverviewScale = 0.3f; - // Returns a list of all the windows with layers in |result|. void BuildWindowList(const std::vector<aura::Window*>& windows, std::vector<aura::Window*>* result) { @@ -70,7 +63,6 @@ namespace internal { WorkspaceManager::WorkspaceManager(aura::Window* contents_view) : contents_view_(contents_view), active_workspace_(NULL), - is_overview_(false), ignored_window_(NULL), grid_size_(0), shelf_(NULL) { @@ -92,6 +84,11 @@ bool WorkspaceManager::IsManagingWindow(aura::Window* window) const { return FindBy(window) != NULL; } +bool WorkspaceManager::IsInMaximizedMode() const { + return active_workspace_ && + active_workspace_->type() == Workspace::TYPE_MAXIMIZED; +} + void WorkspaceManager::AddWindow(aura::Window* window) { DCHECK(IsManagedWindow(window)); @@ -146,12 +143,6 @@ void WorkspaceManager::SetActiveWorkspaceByWindow(aura::Window* window) { workspace->Activate(); } -void WorkspaceManager::SetOverview(bool overview) { - if (is_overview_ == overview) - return; - NOTIMPLEMENTED(); -} - gfx::Rect WorkspaceManager::AlignBoundsToGrid(const gfx::Rect& bounds) { if (grid_size_ <= 1) return bounds; @@ -296,8 +287,6 @@ void WorkspaceManager::SetActiveWorkspace(Workspace* workspace) { last_active ? ANIMATE : DONT_ANIMATE, true); UpdateShelfVisibility(); } - - is_overview_ = false; } // Returns the index of the workspace that contains the |window|. diff --git a/ash/wm/workspace/workspace_manager.h b/ash/wm/workspace/workspace_manager.h index 9912f8d..6da00e7 100644 --- a/ash/wm/workspace/workspace_manager.h +++ b/ash/wm/workspace/workspace_manager.h @@ -55,6 +55,9 @@ class ASH_EXPORT WorkspaceManager { // Returns true if the |window| is managed by the WorkspaceManager. bool IsManagingWindow(aura::Window* window) const; + // Returns true if in maximized or fullscreen mode. + bool IsInMaximizedMode() const; + // Adds/removes a window creating/destroying workspace as necessary. void AddWindow(aura::Window* window); void RemoveWindow(aura::Window* window); @@ -73,10 +76,6 @@ class ASH_EXPORT WorkspaceManager { // Returns the bounds in which a window can be moved/resized. gfx::Rect GetDragAreaBounds(); - // Turn on/off overview mode. - void SetOverview(bool overview); - bool is_overview() const { return is_overview_; } - // Returns the window the layout manager should allow the size to be set for. // TODO: maybe this should be set on WorkspaceLayoutManager. aura::Window* ignored_window() { return ignored_window_; } @@ -166,9 +165,6 @@ class ASH_EXPORT WorkspaceManager { std::vector<Workspace*> workspaces_; - // True if the workspace manager is in overview mode. - bool is_overview_; - // The window that WorkspaceManager does not set the bounds on. aura::Window* ignored_window_; diff --git a/ash/wm/workspace_controller.cc b/ash/wm/workspace_controller.cc index ba652c2..07674df 100644 --- a/ash/wm/workspace_controller.cc +++ b/ash/wm/workspace_controller.cc @@ -45,10 +45,6 @@ WorkspaceController::~WorkspaceController() { viewport_->SetLayoutManager(NULL); } -void WorkspaceController::ToggleOverview() { - workspace_manager_->SetOverview(!workspace_manager_->is_overview()); -} - void WorkspaceController::SetGridSize(int grid_size) { workspace_manager_->set_grid_size(grid_size); event_filter_->set_grid_size(grid_size); diff --git a/ash/wm/workspace_controller.h b/ash/wm/workspace_controller.h index b95ca21..fba7ac2 100644 --- a/ash/wm/workspace_controller.h +++ b/ash/wm/workspace_controller.h @@ -32,8 +32,6 @@ class ASH_EXPORT WorkspaceController : explicit WorkspaceController(aura::Window* viewport); virtual ~WorkspaceController(); - void ToggleOverview(); - // Returns the workspace manager that this controller owns. WorkspaceManager* workspace_manager() { return workspace_manager_.get(); |