diff options
author | davemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-16 18:24:46 +0000 |
---|---|---|
committer | davemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-16 18:24:46 +0000 |
commit | b7d0812e4f6744e851cf874f2e6354cbfc05d921 (patch) | |
tree | 50ce96a2e4eed94181e035413185928fad04f022 /ash | |
parent | 2c60c8ac55953d49b59d7595a95a850ddc6ef2e1 (diff) | |
download | chromium_src-b7d0812e4f6744e851cf874f2e6354cbfc05d921.zip chromium_src-b7d0812e4f6744e851cf874f2e6354cbfc05d921.tar.gz chromium_src-b7d0812e4f6744e851cf874f2e6354cbfc05d921.tar.bz2 |
Dim shelf when maximized
BUG=146959
Test=Visual
Review URL: https://codereview.chromium.org/10916321
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@157054 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/launcher/launcher.cc | 77 | ||||
-rw-r--r-- | ash/launcher/launcher.h | 8 | ||||
-rw-r--r-- | ash/shell.cc | 3 | ||||
-rw-r--r-- | ash/wm/shelf_layout_manager.cc | 11 | ||||
-rw-r--r-- | ash/wm/shelf_layout_manager_unittest.cc | 31 |
5 files changed, 128 insertions, 2 deletions
diff --git a/ash/launcher/launcher.cc b/ash/launcher/launcher.cc index 73df792..dea2681 100644 --- a/ash/launcher/launcher.cc +++ b/ash/launcher/launcher.cc @@ -29,6 +29,8 @@ namespace { // Size of black border at bottom (or side) of launcher. const int kNumBlackPixels = 3; +// Alpha to paint dimming image with. +const int kDimAlpha = 96; } namespace ash { @@ -78,6 +80,39 @@ class Launcher::DelegateView : public views::WidgetDelegate, DISALLOW_COPY_AND_ASSIGN(DelegateView); }; +// Class used to slightly dim shelf items when maximized and visible. +class DimmerView : public views::View, public views::WidgetDelegate { + public: + DimmerView() {} + ~DimmerView() {} + + // views::WidgetDelegateView overrides: + virtual views::Widget* GetWidget() OVERRIDE { + return View::GetWidget(); + } + virtual const views::Widget* GetWidget() const OVERRIDE { + return View::GetWidget(); + } + + void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE { + SkPaint paint; + static const gfx::ImageSkia* launcher_background = NULL; + if (!launcher_background) { + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + launcher_background = + rb.GetImageNamed(IDR_AURA_LAUNCHER_DIMMING).ToImageSkia(); + } + paint.setAlpha(kDimAlpha); + canvas->DrawImageInt( + *launcher_background, + 0, 0, launcher_background->width(), launcher_background->height(), + 0, 0, width(), height(), + false, + paint); + } + DISALLOW_COPY_AND_ASSIGN(DimmerView); +}; + Launcher::DelegateView::DelegateView(Launcher* launcher) : launcher_(launcher), focus_cycler_(NULL), @@ -108,9 +143,9 @@ void Launcher::DelegateView::Layout() { void Launcher::DelegateView::OnPaintBackground(gfx::Canvas* canvas) { if (launcher_->alignment_ == SHELF_ALIGNMENT_BOTTOM) { SkPaint paint; - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); static const gfx::ImageSkia* launcher_background = NULL; if (!launcher_background) { + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); launcher_background = rb.GetImageNamed(IDR_AURA_LAUNCHER_BACKGROUND).ToImageSkia(); } @@ -200,6 +235,40 @@ void Launcher::SetPaintsBackground( background_animator_.SetPaintsBackground(value, change_type); } +void Launcher::SetDimsShelf(bool value) { + if (value == (dimmer_.get() != NULL)) + return; + + if (value) { + dimmer_.reset(new views::Widget); + views::Widget::InitParams params( + views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); + params.transparent = true; + params.can_activate = false; + params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; + params.parent = Shell::GetContainer( + window_container_->GetRootWindow(), + ash::internal::kShellWindowId_LauncherContainer); + params.accept_events = false; + dimmer_->Init(params); + dimmer_->GetNativeWindow()->SetName("LauncherDimmer"); + gfx::Size pref = + static_cast<views::View*>(launcher_view_)->GetPreferredSize(); + dimmer_->SetBounds(widget_->GetWindowBoundsInScreen()); + // The launcher should not take focus when it is initially shown. + dimmer_->set_focus_on_creation(false); + dimmer_->SetContentsView(new DimmerView); + dimmer_->GetNativeView()->SetName("LauncherDimmerView"); + dimmer_->Show(); + } else { + dimmer_.reset(NULL); + } +} + +bool Launcher::GetDimsShelf() const { + return dimmer_.get() && dimmer_->IsVisible(); +} + void Launcher::SetStatusSize(const gfx::Size& size) { if (status_size_ == size) return; @@ -261,6 +330,12 @@ views::View* Launcher::GetAppListButtonView() const { return launcher_view_->GetAppListButtonView(); } +void Launcher::SetWidgetBounds(const gfx::Rect bounds) { + widget_->SetBounds(bounds); + if (dimmer_.get()) + dimmer_->SetBounds(bounds); +} + internal::LauncherView* Launcher::GetLauncherViewForTest() { return launcher_view_; } diff --git a/ash/launcher/launcher.h b/ash/launcher/launcher.h index d889e61..c9947a7 100644 --- a/ash/launcher/launcher.h +++ b/ash/launcher/launcher.h @@ -60,6 +60,10 @@ class ASH_EXPORT Launcher { return background_animator_.paints_background(); } + // Causes shelf items to be slightly dimmed. + void SetDimsShelf(bool value); + bool GetDimsShelf() const; + // Sets the size of the status area. void SetStatusSize(const gfx::Size& size); const gfx::Size& status_size() const { return status_size_; } @@ -87,6 +91,9 @@ class ASH_EXPORT Launcher { views::View* GetAppListButtonView() const; + // Sets the bounds of the launcher widget, and the dimmer if visible. + void SetWidgetBounds(const gfx::Rect bounds); + // Only to be called for testing. Retrieves the LauncherView. // TODO(sky): remove this! internal::LauncherView* GetLauncherViewForTest(); @@ -105,6 +112,7 @@ class ASH_EXPORT Launcher { // Widget hosting the view. scoped_ptr<views::Widget> widget_; + scoped_ptr<views::Widget> dimmer_; aura::Window* window_container_; diff --git a/ash/shell.cc b/ash/shell.cc index 69008b8..59209d6 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -238,6 +238,9 @@ Shell::~Shell() { // TODO(xiyuan): Move it back when app list container is no longer needed. app_list_controller_.reset(); + + // Closing the windows frees the workspace controller. + shelf_->set_workspace_controller(NULL); // Destroy all child windows including widgets. display_controller_->CloseChildWindows(); diff --git a/ash/wm/shelf_layout_manager.cc b/ash/wm/shelf_layout_manager.cc index c88d2f1..4c44ee8 100644 --- a/ash/wm/shelf_layout_manager.cc +++ b/ash/wm/shelf_layout_manager.cc @@ -253,7 +253,7 @@ void ShelfLayoutManager::LayoutShelf() { CalculateTargetBounds(state_, &target_bounds); if (launcher_widget()) { GetLayer(launcher_widget())->SetOpacity(target_bounds.opacity); - launcher_widget()->SetBounds( + launcher_->SetWidgetBounds( ScreenAsh::ConvertRectToScreen( launcher_widget()->GetNativeView()->parent(), target_bounds.launcher_bounds_in_root)); @@ -515,6 +515,15 @@ void ShelfLayoutManager::SetState(VisibilityState visibility_state) { state.auto_hide_state = CalculateAutoHideState(visibility_state); state.is_screen_locked = delegate && delegate->IsScreenLocked(); + // It's possible for SetState() when a window becomes maximized but the state + // won't have changed value. Do the dimming check before the early exit. + if (launcher_ && workspace_controller_) { + launcher_->SetDimsShelf( + (state.visibility_state == VISIBLE) && + workspace_controller_->GetWindowState() == + WORKSPACE_WINDOW_STATE_MAXIMIZED); + } + if (state_.Equals(state)) return; // Nothing changed. diff --git a/ash/wm/shelf_layout_manager_unittest.cc b/ash/wm/shelf_layout_manager_unittest.cc index c74d549..84fcfd5 100644 --- a/ash/wm/shelf_layout_manager_unittest.cc +++ b/ash/wm/shelf_layout_manager_unittest.cc @@ -783,5 +783,36 @@ TEST_F(ShelfLayoutManagerTest, WorkAreaChangeWorkspace) { widget_two->GetNativeWindow()->bounds().ToString()); } +// Confirm that the shelf is dimmed only when content is maximized and +// shelf is not autohidden. +TEST_F(ShelfLayoutManagerTest, Dimming) { + Shell::GetInstance()->shelf()->SetAutoHideBehavior( + SHELF_AUTO_HIDE_BEHAVIOR_NEVER); + scoped_ptr<aura::Window> w1(CreateTestWindow()); + w1->Show(); + wm::ActivateWindow(w1.get()); + + // Normal window doesn't dim shelf. + w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); + EXPECT_FALSE(Shell::GetInstance()->launcher()->GetDimsShelf()); + + // Maximized window does. + w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); + EXPECT_TRUE(Shell::GetInstance()->launcher()->GetDimsShelf()); + + // Change back to normal stops dimming. + w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); + EXPECT_FALSE(Shell::GetInstance()->launcher()->GetDimsShelf()); + + // Changing back to maximized dims again. + w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); + EXPECT_TRUE(Shell::GetInstance()->launcher()->GetDimsShelf()); + + // Changing shelf to autohide stops dimming. + Shell::GetInstance()->shelf()->SetAutoHideBehavior( + SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); + EXPECT_FALSE(Shell::GetInstance()->launcher()->GetDimsShelf()); +} + } // namespace internal } // namespace ash |