diff options
author | jonross@chromium.org <jonross@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-12 04:34:27 +0000 |
---|---|---|
committer | jonross@chromium.org <jonross@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-12 04:34:27 +0000 |
commit | 1bafabf6bb65876fee18f19f066a4ce7af376d2e (patch) | |
tree | 6db65e09d5b27c6f2d219566245e564312e28199 /ash | |
parent | b4c72667519699208beea04f88c8b3fdd27683d7 (diff) | |
download | chromium_src-1bafabf6bb65876fee18f19f066a4ce7af376d2e.zip chromium_src-1bafabf6bb65876fee18f19f066a4ce7af376d2e.tar.gz chromium_src-1bafabf6bb65876fee18f19f066a4ce7af376d2e.tar.bz2 |
Add a new status area control for Overview Mode. This control is only available while Maximize Mode is active.
BUG=337590
TEST=OverviewModeTrayTest.*
Review URL: https://codereview.chromium.org/180743016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@256420 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/ash.gyp | 3 | ||||
-rw-r--r-- | ash/ash_strings.grd | 5 | ||||
-rw-r--r-- | ash/resources/ash_resources.grd | 1 | ||||
-rw-r--r-- | ash/shell.cc | 8 | ||||
-rw-r--r-- | ash/shell.h | 7 | ||||
-rw-r--r-- | ash/shell_observer.h | 8 | ||||
-rw-r--r-- | ash/system/overview/overview_button_tray.cc | 106 | ||||
-rw-r--r-- | ash/system/overview/overview_button_tray.h | 58 | ||||
-rw-r--r-- | ash/system/overview/overview_button_tray_unittest.cc | 121 | ||||
-rw-r--r-- | ash/system/status_area_widget.cc | 30 | ||||
-rw-r--r-- | ash/system/status_area_widget.h | 6 | ||||
-rw-r--r-- | ash/wm/maximize_mode/maximize_mode_window_manager.cc | 2 |
12 files changed, 345 insertions, 10 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp index d7282b7..d57129c 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -367,6 +367,8 @@ 'system/keyboard_brightness/keyboard_brightness_control_delegate.h', 'system/locale/locale_notification_controller.cc', 'system/locale/locale_notification_controller.h', + 'system/overview/overview_button_tray.h', + 'system/overview/overview_button_tray.cc', 'system/session/logout_button_observer.h', 'system/session/logout_button_tray.cc', 'system/session/logout_button_tray.h', @@ -927,6 +929,7 @@ 'system/chromeos/tray_display_unittest.cc', 'system/date/date_view_unittest.cc', 'system/session/logout_confirmation_controller_unittest.cc', + 'system/overview/overview_button_tray_unittest.cc', 'system/session/tray_session_length_limit_unittest.cc', 'system/tray/system_tray_unittest.cc', 'system/tray/tray_details_view_unittest.cc', diff --git a/ash/ash_strings.grd b/ash/ash_strings.grd index 3bd706bc..e0531e4 100644 --- a/ash/ash_strings.grd +++ b/ash/ash_strings.grd @@ -624,6 +624,11 @@ Press Shift + Alt to switch. search </message> + <!-- Overview Mode --> + <message name="IDS_ASH_OVERVIEW_BUTTON_ACCESSIBLE_NAME" desc="The accessible name for the Overview button in the system tray."> + Toggle window overview + </message> + <!-- ChromeOS-specific strings --> <if expr="chromeos"> <part file="ash_chromeos_strings.grdp" /> diff --git a/ash/resources/ash_resources.grd b/ash/resources/ash_resources.grd index a650f4f0..4111872 100644 --- a/ash/resources/ash_resources.grd +++ b/ash/resources/ash_resources.grd @@ -163,6 +163,7 @@ <structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_NETWORK_INFO_HOVER" file="cros/network/status_network_info_hover.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_NOTIFICATION_3G" file="cros/network/notification_3g.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_NOTIFICATION_LTE" file="cros/network/notification_lte.png" /> + <structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_OVERVIEW_MODE" file="cros/status/status_overview_mode.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_POWER_SMALL" file="cros/status/status_power_small_all.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_POWER_SMALL_DARK" file="cros/status/status_power_small_all_dark.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_POWER_SMALL_CHARGING_UNRELIABLE" file="cros/status/status_power_small_all_fluctuating.png" /> diff --git a/ash/shell.cc b/ash/shell.cc index 08ae512..9dde5c4 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -389,6 +389,14 @@ void Shell::OnOverviewModeEnding() { FOR_EACH_OBSERVER(ShellObserver, observers_, OnOverviewModeEnding()); } +void Shell::OnMaximizeModeStarted() { + FOR_EACH_OBSERVER(ShellObserver, observers_, OnMaximizeModeStarted()); +} + +void Shell::OnMaximizeModeEnded() { + FOR_EACH_OBSERVER(ShellObserver, observers_, OnMaximizeModeEnded()); +} + void Shell::CreateShelf() { RootWindowControllerList controllers = GetAllRootWindowControllers(); for (RootWindowControllerList::iterator iter = controllers.begin(); diff --git a/ash/shell.h b/ash/shell.h index 49fbda9..4b0df83 100644 --- a/ash/shell.h +++ b/ash/shell.h @@ -299,6 +299,13 @@ class ASH_EXPORT Shell // to their final position). void OnOverviewModeEnding(); + // Called after maximize mode has started, windows might still animate though. + void OnMaximizeModeStarted(); + + // Called after maximize mode has ended, windows might still be returning to + // their original position. + void OnMaximizeModeEnded(); + // Initializes |shelf_|. Does nothing if it's already initialized. void CreateShelf(); diff --git a/ash/shell_observer.h b/ash/shell_observer.h index c2b652c..d1b3d86 100644 --- a/ash/shell_observer.h +++ b/ash/shell_observer.h @@ -47,6 +47,14 @@ class ASH_EXPORT ShellObserver { // to their final position). virtual void OnOverviewModeEnding() {} + // Called when the always maximize mode has started. Windows might still + // animate though. + virtual void OnMaximizeModeStarted() {} + + // Called when the always maximize mode has ended. Windows may still be + // animating but have been restored. + virtual void OnMaximizeModeEnded() {} + protected: virtual ~ShellObserver() {} }; diff --git a/ash/system/overview/overview_button_tray.cc b/ash/system/overview/overview_button_tray.cc new file mode 100644 index 0000000..4ca4166 --- /dev/null +++ b/ash/system/overview/overview_button_tray.cc @@ -0,0 +1,106 @@ +// Copyright 2014 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/system/overview/overview_button_tray.h" + +#include "ash/shelf/shelf_types.h" +#include "ash/shell.h" +#include "ash/system/tray/tray_utils.h" +#include "ash/wm/overview/window_selector_controller.h" +#include "grit/ash_resources.h" +#include "grit/ash_strings.h" +#include "ui/base/l10n/l10n_util.h" +#include "ui/base/resource/resource_bundle.h" +#include "ui/views/border.h" +#include "ui/views/controls/image_view.h" + +namespace { + +// Predefined padding for the icon used in this tray. These are to be set to the +// border of the icon, depending on the current shelf_alignment() +const int kHorizontalShelfHorizontalPadding = 8; +const int kHorizontalShelfVerticalPadding = 4; +const int kVerticalShelfHorizontalPadding = 2; +const int kVerticalShelfVerticalPadding = 5; + +} // namespace + +namespace ash { + +OverviewButtonTray::OverviewButtonTray( + internal::StatusAreaWidget* status_area_widget) + : TrayBackgroundView(status_area_widget), + icon_(NULL) { + SetContentsBackground(); + + ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); + icon_ = new views::ImageView(); + icon_->SetImage( + bundle.GetImageNamed(IDR_AURA_UBER_TRAY_OVERVIEW_MODE).ToImageSkia()); + SetIconBorderForShelfAlignment(); + tray_container()->AddChildView(icon_); + + SetVisible(Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled()); + + Shell::GetInstance()->AddShellObserver(this); +} + +OverviewButtonTray::~OverviewButtonTray() { + Shell::GetInstance()->RemoveShellObserver(this); +} + +bool OverviewButtonTray::PerformAction(const ui::Event& event) { + Shell::GetInstance()->window_selector_controller()->ToggleOverview(); + return true; +} + +void OverviewButtonTray::OnMaximizeModeStarted() { + SetVisible(true); +} + +void OverviewButtonTray::OnMaximizeModeEnded() { + SetVisible(false); +} + +bool OverviewButtonTray::ClickedOutsideBubble() { + // This class has no bubbles dismiss, but acknowledge that the message was + // handled. + return true; +} + +base::string16 OverviewButtonTray::GetAccessibleNameForTray() { + return l10n_util::GetStringUTF16(IDS_ASH_OVERVIEW_BUTTON_ACCESSIBLE_NAME); +} + +void OverviewButtonTray::HideBubbleWithView( + const views::TrayBubbleView* bubble_view) { + // This class has no bubbles to hide. +} + +void OverviewButtonTray::SetShelfAlignment(ShelfAlignment alignment) { + if (alignment == shelf_alignment()) + return; + + TrayBackgroundView::SetShelfAlignment(alignment); + SetIconBorderForShelfAlignment(); +} + +void OverviewButtonTray::SetIconBorderForShelfAlignment() { + if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM || + shelf_alignment() == SHELF_ALIGNMENT_TOP) { + icon_->SetBorder(views::Border::CreateEmptyBorder( + kHorizontalShelfVerticalPadding, + kHorizontalShelfHorizontalPadding, + kHorizontalShelfVerticalPadding, + kHorizontalShelfHorizontalPadding)); + } else { + icon_->SetBorder(views::Border::CreateEmptyBorder( + kVerticalShelfVerticalPadding, + kVerticalShelfHorizontalPadding, + kVerticalShelfVerticalPadding, + kVerticalShelfHorizontalPadding)); + } +} + +} // namespace ash diff --git a/ash/system/overview/overview_button_tray.h b/ash/system/overview/overview_button_tray.h new file mode 100644 index 0000000..0a16e47 --- /dev/null +++ b/ash/system/overview/overview_button_tray.h @@ -0,0 +1,58 @@ +// Copyright 2014 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_SYSTEM_OVERVIEW_OVERVIEW_BUTTON_TRAY_H_ +#define ASH_SYSTEM_OVERVIEW_OVERVIEW_BUTTON_TRAY_H_ + +#include "ash/ash_export.h" +#include "ash/shell_observer.h" +#include "ash/system/tray/tray_background_view.h" + +namespace views { +class ImageView; +} + +namespace ash { + +// Status area tray for showing a toggle for Overview Mode. Overview Mode +// is equivalent to WindowSelectorController being in selection mode. +// This hosts a ShellObserver that listens for the activation of Maximize Mode +// This tray will only be visible while in this state. This tray does not +// provide any bubble view windows. +class ASH_EXPORT OverviewButtonTray : public internal::TrayBackgroundView, + public ShellObserver { + public: + explicit OverviewButtonTray(internal::StatusAreaWidget* status_area_widget); + virtual ~OverviewButtonTray(); + + // internal::ActionableView: + virtual bool PerformAction(const ui::Event& event) OVERRIDE; + + // ShellObserver: + virtual void OnMaximizeModeStarted() OVERRIDE; + virtual void OnMaximizeModeEnded() OVERRIDE; + + // internal::TrayBackgroundView: + virtual bool ClickedOutsideBubble() OVERRIDE; + virtual base::string16 GetAccessibleNameForTray() OVERRIDE; + virtual void HideBubbleWithView( + const views::TrayBubbleView* bubble_view) OVERRIDE; + virtual void SetShelfAlignment(ShelfAlignment alignment) OVERRIDE; + + private: + friend class OverviewButtonTrayTest; + + // Creates a new border for the icon. The padding is determined based on the + // alignment of the shelf. + void SetIconBorderForShelfAlignment(); + + // Weak pointer, will be parented by TrayContainer for its lifetime. + views::ImageView* icon_; + + DISALLOW_COPY_AND_ASSIGN(OverviewButtonTray); +}; + +} // namespace ash + +#endif // ASH_SYSTEM_OVERVIEW_OVERVIEW_BUTTON_TRAY_H_ diff --git a/ash/system/overview/overview_button_tray_unittest.cc b/ash/system/overview/overview_button_tray_unittest.cc new file mode 100644 index 0000000..201fd1d --- /dev/null +++ b/ash/system/overview/overview_button_tray_unittest.cc @@ -0,0 +1,121 @@ +// Copyright 2014 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/system/overview/overview_button_tray.h" + +#include "ash/display/display_manager.h" +#include "ash/root_window_controller.h" +#include "ash/shelf/shelf_types.h" +#include "ash/shelf/shelf_widget.h" +#include "ash/shell.h" +#include "ash/system/status_area_widget.h" +#include "ash/test/ash_test_base.h" +#include "ash/wm/overview/window_selector_controller.h" +#include "base/time/time.h" +#include "ui/events/event.h" +#include "ui/events/event_constants.h" +#include "ui/events/gestures/gesture_types.h" +#include "ui/views/controls/image_view.h" + +namespace ash { + +namespace { + +OverviewButtonTray* GetTray() { + return Shell::GetPrimaryRootWindowController()->shelf()-> + status_area_widget()->overview_button_tray(); +} + +OverviewButtonTray* GetSecondaryTray() { + internal::RootWindowController* primary_controller = + Shell::GetPrimaryRootWindowController(); + Shell::RootWindowControllerList controllers = + Shell::GetAllRootWindowControllers(); + for (size_t i = 0; i < controllers.size(); ++i) { + if (controllers[i] != primary_controller) { + return controllers[i]->shelf()-> + status_area_widget()->overview_button_tray(); + } + } + + return NULL; +} + +} // namespace + +class OverviewButtonTrayTest : public test::AshTestBase { + public: + OverviewButtonTrayTest() {} + virtual ~OverviewButtonTrayTest() {} + + protected: + views::ImageView* GetImageView(OverviewButtonTray* tray) { + return tray->icon_; + } + + private: + DISALLOW_COPY_AND_ASSIGN(OverviewButtonTrayTest); +}; + +// Ensures that creation doesn't cause any crashes and adds the image icon. +TEST_F(OverviewButtonTrayTest, BasicConstruction) { + EXPECT_TRUE(GetImageView(GetTray()) != NULL); +} + +// Test that maximize mode toggle changes visibility. +// OverviewButtonTray should only be visible when MaximizeMode is enabled. +// By default the system should not have MaximizeMode enabled. +TEST_F(OverviewButtonTrayTest, MaximizeModeObserverOnMaximizeModeToggled) { + ASSERT_FALSE(GetTray()->visible()); + Shell::GetInstance()->EnableMaximizeModeWindowManager(true); + EXPECT_TRUE(GetTray()->visible()); + + Shell::GetInstance()->EnableMaximizeModeWindowManager(false); + EXPECT_FALSE(GetTray()->visible()); +} + +// Tests that activating this control brings up window selection mode. +TEST_F(OverviewButtonTrayTest, PerformAction) { + ASSERT_FALSE(Shell::GetInstance()->window_selector_controller()-> + IsSelecting()); + + // Overview Mode only works when there is a window + scoped_ptr<aura::Window> window( + CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); + ui::GestureEvent tap(ui::ET_GESTURE_TAP, 0, 0, 0, base::TimeDelta(), + ui::GestureEventDetails(ui::ET_GESTURE_TAP, 0.0f, 0.0f), 0); + GetTray()->PerformAction(tap); + EXPECT_TRUE(Shell::GetInstance()->window_selector_controller()-> + IsSelecting()); +} + +// Tests that a second OverviewButtonTray has been created, and only shows +// when MaximizeMode has been enabled, when we are using multiple displays. +// By default the DisplayManger is in extended mode. +TEST_F(OverviewButtonTrayTest, DisplaysOnBothDisplays) { + if (!SupportsMultipleDisplays()) + return; + + UpdateDisplay("400x400,200x200"); + EXPECT_FALSE(GetTray()->visible()); + EXPECT_FALSE(GetSecondaryTray()->visible()); + Shell::GetInstance()->EnableMaximizeModeWindowManager(true); + EXPECT_TRUE(GetTray()->visible()); + EXPECT_TRUE(GetSecondaryTray()->visible()); + Shell::GetInstance()->EnableMaximizeModeWindowManager(false); +} + +// Tests if Maximize Mode is enabled before a secondary display is attached +// that the second OverviewButtonTray should be created in a visible state. +TEST_F(OverviewButtonTrayTest, SecondaryTrayCreatedVisible) { + if (!SupportsMultipleDisplays()) + return; + + Shell::GetInstance()->EnableMaximizeModeWindowManager(true); + UpdateDisplay("400x400,200x200"); + EXPECT_TRUE(GetSecondaryTray()->visible()); + Shell::GetInstance()->EnableMaximizeModeWindowManager(false); +} + +} // namespace ash diff --git a/ash/system/status_area_widget.cc b/ash/system/status_area_widget.cc index d302efc..798ea8e 100644 --- a/ash/system/status_area_widget.cc +++ b/ash/system/status_area_widget.cc @@ -11,6 +11,7 @@ #include "ash/shell_delegate.h" #include "ash/shell_window_ids.h" #include "ash/system/bluetooth/bluetooth_observer.h" +#include "ash/system/overview/overview_button_tray.h" #include "ash/system/session/logout_button_tray.h" #include "ash/system/status_area_widget_delegate.h" #include "ash/system/tray/system_tray.h" @@ -33,6 +34,7 @@ const char StatusAreaWidget::kNativeViewName[] = "StatusAreaWidget"; StatusAreaWidget::StatusAreaWidget(aura::Window* status_container) : status_area_widget_delegate_(new internal::StatusAreaWidgetDelegate), + overview_button_tray_(NULL), system_tray_(NULL), web_notification_tray_(NULL), logout_button_tray_(NULL), @@ -55,26 +57,25 @@ StatusAreaWidget::~StatusAreaWidget() { } void StatusAreaWidget::CreateTrayViews() { + AddOverviewButtonTray(); AddSystemTray(); AddWebNotificationTray(); AddLogoutButtonTray(); #if defined(OS_CHROMEOS) AddVirtualKeyboardTray(); #endif + SystemTrayDelegate* delegate = ash::Shell::GetInstance()->system_tray_delegate(); DCHECK(delegate); // Initialize after all trays have been created. - if (system_tray_) - system_tray_->InitializeTrayItems(delegate); - if (web_notification_tray_) - web_notification_tray_->Initialize(); - if (logout_button_tray_) - logout_button_tray_->Initialize(); + system_tray_->InitializeTrayItems(delegate); + web_notification_tray_->Initialize(); + logout_button_tray_->Initialize(); #if defined(OS_CHROMEOS) - if (virtual_keyboard_tray_) - virtual_keyboard_tray_->Initialize(); + virtual_keyboard_tray_->Initialize(); #endif + overview_button_tray_->Initialize(); UpdateAfterLoginStatusChange(delegate->GetUserLoginStatus()); } @@ -92,6 +93,8 @@ void StatusAreaWidget::Shutdown() { delete virtual_keyboard_tray_; virtual_keyboard_tray_ = NULL; #endif + delete overview_button_tray_; + overview_button_tray_ = NULL; } bool StatusAreaWidget::ShouldShowShelf() const { @@ -106,8 +109,8 @@ bool StatusAreaWidget::ShouldShowShelf() const { // If the shelf is currently visible, don't hide the shelf if the mouse // is in any of the notification bubbles. return (system_tray_ && system_tray_->IsMouseInNotificationBubble()) || - (web_notification_tray_ && - web_notification_tray_->IsMouseInNotificationBubble()); + (web_notification_tray_ && + web_notification_tray_->IsMouseInNotificationBubble()); } bool StatusAreaWidget::IsMessageBubbleShown() const { @@ -144,6 +147,11 @@ void StatusAreaWidget::AddVirtualKeyboardTray() { } #endif +void StatusAreaWidget::AddOverviewButtonTray() { + overview_button_tray_ = new OverviewButtonTray(this); + status_area_widget_delegate_->AddTray(overview_button_tray_); +} + void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) { status_area_widget_delegate_->set_alignment(alignment); if (system_tray_) @@ -156,6 +164,8 @@ void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) { if (virtual_keyboard_tray_) virtual_keyboard_tray_->SetShelfAlignment(alignment); #endif + if (overview_button_tray_) + overview_button_tray_->SetShelfAlignment(alignment); status_area_widget_delegate_->UpdateLayout(); } diff --git a/ash/system/status_area_widget.h b/ash/system/status_area_widget.h index 9933c73..3b58a10 100644 --- a/ash/system/status_area_widget.h +++ b/ash/system/status_area_widget.h @@ -12,6 +12,7 @@ namespace ash { +class OverviewButtonTray; class ShellDelegate; class SystemTray; class WebNotificationTray; @@ -56,6 +57,9 @@ class ASH_EXPORT StatusAreaWidget : public views::Widget { WebNotificationTray* web_notification_tray() { return web_notification_tray_; } + OverviewButtonTray* overview_button_tray() { + return overview_button_tray_; + } user::LoginStatus login_status() const { return login_status_; } @@ -77,9 +81,11 @@ class ASH_EXPORT StatusAreaWidget : public views::Widget { #if defined(OS_CHROMEOS) void AddVirtualKeyboardTray(); #endif + void AddOverviewButtonTray(); // Weak pointers to View classes that are parented to StatusAreaWidget: internal::StatusAreaWidgetDelegate* status_area_widget_delegate_; + OverviewButtonTray* overview_button_tray_; SystemTray* system_tray_; WebNotificationTray* web_notification_tray_; LogoutButtonTray* logout_button_tray_; diff --git a/ash/wm/maximize_mode/maximize_mode_window_manager.cc b/ash/wm/maximize_mode/maximize_mode_window_manager.cc index 6858f36..24be9cb 100644 --- a/ash/wm/maximize_mode/maximize_mode_window_manager.cc +++ b/ash/wm/maximize_mode/maximize_mode_window_manager.cc @@ -22,6 +22,7 @@ MaximizeModeWindowManager::~MaximizeModeWindowManager() { EnableBackdropBehindTopWindowOnEachDisplay(false); RemoveWindowCreationObservers(); RestoreAllWindows(); + Shell::GetInstance()->OnMaximizeModeEnded(); } int MaximizeModeWindowManager::GetNumberOfManagedWindows() { @@ -93,6 +94,7 @@ MaximizeModeWindowManager::MaximizeModeWindowManager() MaximizeAllWindows(); AddWindowCreationObservers(); EnableBackdropBehindTopWindowOnEachDisplay(true); + Shell::GetInstance()->OnMaximizeModeStarted(); Shell::GetScreen()->AddObserver(this); Shell::GetInstance()->AddShellObserver(this); } |