diff options
-rw-r--r-- | ash/ash.gyp | 2 | ||||
-rw-r--r-- | ash/root_window_controller.cc | 3 | ||||
-rw-r--r-- | ash/root_window_controller.h | 4 | ||||
-rw-r--r-- | ash/shell.cc | 8 | ||||
-rw-r--r-- | ash/shell.h | 3 | ||||
-rw-r--r-- | ash/wm/dim_window.cc | 79 | ||||
-rw-r--r-- | ash/wm/dim_window.h | 35 | ||||
-rw-r--r-- | ash/wm/screen_dimmer.cc | 100 | ||||
-rw-r--r-- | ash/wm/screen_dimmer.h | 53 | ||||
-rw-r--r-- | ash/wm/screen_dimmer_unittest.cc | 47 | ||||
-rw-r--r-- | ash/wm/system_modal_container_layout_manager.cc | 66 | ||||
-rw-r--r-- | ash/wm/system_modal_container_layout_manager.h | 8 | ||||
-rw-r--r-- | chrome/browser/chromeos/dbus/chrome_display_power_service_provider_delegate.cc | 3 | ||||
-rw-r--r-- | ui/wm/core/visibility_controller.cc | 14 | ||||
-rw-r--r-- | ui/wm/core/visibility_controller.h | 12 | ||||
-rw-r--r-- | ui/wm/core/visibility_controller_unittest.cc | 34 |
16 files changed, 151 insertions, 320 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp index 20960ee..e994b16 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -525,8 +525,6 @@ 'wm/default_state.h', 'wm/default_window_resizer.cc', 'wm/default_window_resizer.h', - 'wm/dim_window.cc', - 'wm/dim_window.h', 'wm/dock/docked_window_layout_manager.cc', 'wm/dock/docked_window_layout_manager.h', 'wm/dock/docked_window_layout_manager_observer.h', diff --git a/ash/root_window_controller.cc b/ash/root_window_controller.cc index c693858..97fd09e 100644 --- a/ash/root_window_controller.cc +++ b/ash/root_window_controller.cc @@ -39,6 +39,7 @@ #include "ash/wm/panels/panel_layout_manager.h" #include "ash/wm/panels/panel_window_event_handler.h" #include "ash/wm/root_window_layout_manager.h" +#include "ash/wm/screen_dimmer.h" #include "ash/wm/stacking_controller.h" #include "ash/wm/status_area_layout_manager.h" #include "ash/wm/system_background_controller.h" @@ -366,6 +367,7 @@ void RootWindowController::Shutdown() { CloseChildWindows(); GetRootWindowSettings(root_window)->controller = NULL; + screen_dimmer_.reset(); workspace_controller_.reset(); // Forget with the display ID so that display lookup // ends up with invalid display. @@ -692,6 +694,7 @@ RootWindowController::RootWindowController(AshWindowTreeHost* ash_host) touch_hud_projection_(NULL) { aura::Window* root_window = GetRootWindow(); GetRootWindowSettings(root_window)->controller = this; + screen_dimmer_.reset(new ScreenDimmer(root_window)); stacking_controller_.reset(new StackingController); aura::client::SetWindowTreeClient(root_window, stacking_controller_.get()); diff --git a/ash/root_window_controller.h b/ash/root_window_controller.h index 1138a0d..ffa19e1 100644 --- a/ash/root_window_controller.h +++ b/ash/root_window_controller.h @@ -54,6 +54,7 @@ class DesktopBackgroundWidgetController; class DockedWindowLayoutManager; class PanelLayoutManager; class RootWindowLayoutManager; +class ScreenDimmer; class ShelfLayoutManager; class ShelfWidget; class StackingController; @@ -120,6 +121,8 @@ class ASH_EXPORT RootWindowController : public ShellObserver { return always_on_top_controller_.get(); } + ScreenDimmer* screen_dimmer() { return screen_dimmer_.get(); } + // Access the shelf associated with this root window controller, // NULL if no such shelf exists. ShelfWidget* shelf() { return shelf_.get(); } @@ -293,6 +296,7 @@ class ASH_EXPORT RootWindowController : public ShellObserver { scoped_ptr<AshTouchExplorationManager> touch_exploration_manager_; #endif + scoped_ptr<ScreenDimmer> screen_dimmer_; scoped_ptr<WorkspaceController> workspace_controller_; scoped_ptr<AlwaysOnTopController> always_on_top_controller_; diff --git a/ash/shell.cc b/ash/shell.cc index 27697f6..72eb8eb 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -68,6 +68,7 @@ #include "ash/wm/power_button_controller.h" #include "ash/wm/resize_shadow_controller.h" #include "ash/wm/root_window_layout_manager.h" +#include "ash/wm/screen_dimmer.h" #include "ash/wm/system_gesture_event_filter.h" #include "ash/wm/system_modal_container_event_filter.h" #include "ash/wm/system_modal_container_layout_manager.h" @@ -523,6 +524,13 @@ ShelfAlignment Shell::GetShelfAlignment(const aura::Window* root_window) { ->GetAlignment(); } +void Shell::SetDimming(bool should_dim) { + RootWindowControllerList controllers = GetAllRootWindowControllers(); + for (RootWindowControllerList::iterator iter = controllers.begin(); + iter != controllers.end(); ++iter) + (*iter)->screen_dimmer()->SetDimming(should_dim); +} + 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 5bdf6dd..86382cd 100644 --- a/ash/shell.h +++ b/ash/shell.h @@ -467,6 +467,9 @@ class ASH_EXPORT Shell : public SystemModalContainerEventFilterDelegate, aura::Window* root_window); ShelfAlignment GetShelfAlignment(const aura::Window* root_window); + // Dims or undims the screen. + void SetDimming(bool should_dim); + // Notifies |observers_| when entering or exiting fullscreen mode in // |root_window|. void NotifyFullscreenStateChange(bool is_fullscreen, diff --git a/ash/wm/dim_window.cc b/ash/wm/dim_window.cc deleted file mode 100644 index 552789f..0000000 --- a/ash/wm/dim_window.cc +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright 2015 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/wm/dim_window.h" -#include "base/time/time.h" -#include "ui/aura/client/aura_constants.h" -#include "ui/aura/window_property.h" -#include "ui/compositor/layer.h" -#include "ui/compositor/scoped_layer_animation_settings.h" -#include "ui/wm/core/visibility_controller.h" -#include "ui/wm/core/window_animations.h" - -DECLARE_WINDOW_PROPERTY_TYPE(ash::DimWindow*); - -namespace ash { -namespace { - -DEFINE_LOCAL_WINDOW_PROPERTY_KEY(DimWindow*, kDimWindowKey, nullptr); - -const int kDefaultDimAnimationDurationMs = 200; - -const float kDefaultDimOpacity = 0.5f; - -} // namespace - -// static -DimWindow* DimWindow::Get(aura::Window* container) { - return container->GetProperty(kDimWindowKey); -} - -DimWindow::DimWindow(aura::Window* parent) - : aura::Window(nullptr), parent_(parent) { - SetType(ui::wm::WINDOW_TYPE_NORMAL); - Init(ui::LAYER_SOLID_COLOR); - wm::SetWindowVisibilityChangesAnimated(this); - wm::SetWindowVisibilityAnimationType( - this, wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); - wm::SetWindowVisibilityAnimationDuration( - this, base::TimeDelta::FromMilliseconds(kDefaultDimAnimationDurationMs)); - - SetDimOpacity(kDefaultDimOpacity); - - parent->AddChild(this); - parent->AddObserver(this); - parent->SetProperty(kDimWindowKey, this); - parent->StackChildAtTop(this); - - SetBounds(parent->bounds()); -} - -DimWindow::~DimWindow() { - if (parent_) { - parent_->ClearProperty(kDimWindowKey); - parent_->RemoveObserver(this); - parent_ = nullptr; - } -} - -void DimWindow::SetDimOpacity(float target_opacity) { - layer()->SetColor(SkColorSetA(SK_ColorBLACK, 255 * target_opacity)); -} - -void DimWindow::OnWindowBoundsChanged(aura::Window* window, - const gfx::Rect& old_bounds, - const gfx::Rect& new_bounds) { - if (window == parent_) - SetBounds(new_bounds); -} - -void DimWindow::OnWindowDestroying(Window* window) { - if (window == parent_) { - window->ClearProperty(kDimWindowKey); - window->RemoveObserver(this); - parent_ = nullptr; - } -} - -} // namespace ash diff --git a/ash/wm/dim_window.h b/ash/wm/dim_window.h deleted file mode 100644 index 8d86c63..0000000 --- a/ash/wm/dim_window.h +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2015 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/ash_export.h" -#include "base/macros.h" -#include "ui/aura/window.h" -#include "ui/aura/window_observer.h" - -namespace ash { - -// A window used to dim the child windows of the given container. -class ASH_EXPORT DimWindow : public aura::Window, public aura::WindowObserver { - public: - // Return a dim window for the container if any, or nullptr. - static DimWindow* Get(aura::Window* container); - - explicit DimWindow(aura::Window* parent); - ~DimWindow() override; - - void SetDimOpacity(float target_opacity); - - // aura::WindowObserver: - void OnWindowBoundsChanged(aura::Window* window, - const gfx::Rect& old_bounds, - const gfx::Rect& new_bounds) override; - void OnWindowDestroying(aura::Window* window) override; - - private: - aura::Window* parent_; - - DISALLOW_COPY_AND_ASSIGN(DimWindow); -}; - -} // namespace ash diff --git a/ash/wm/screen_dimmer.cc b/ash/wm/screen_dimmer.cc index 6c74888..90edc69 100644 --- a/ash/wm/screen_dimmer.cc +++ b/ash/wm/screen_dimmer.cc @@ -5,102 +5,62 @@ #include "ash/wm/screen_dimmer.h" #include "ash/shell.h" -#include "ash/wm/dim_window.h" #include "base/time/time.h" #include "ui/aura/window_event_dispatcher.h" -#include "ui/aura/window_property.h" #include "ui/compositor/layer.h" #include "ui/compositor/scoped_layer_animation_settings.h" #include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/size.h" -DECLARE_WINDOW_PROPERTY_TYPE(ash::ScreenDimmer*); - namespace ash { namespace { -DEFINE_OWNED_WINDOW_PROPERTY_KEY(ScreenDimmer, kScreenDimmerKey, nullptr); - -// Opacity when it's dimming the entire screen. -const float kDimmingLayerOpacityForRoot = 0.4f; -const int kRootWindowMagicId = -100; +// Opacity for |dimming_layer_| when it's dimming the screen. +const float kDimmingLayerOpacity = 0.4f; -std::vector<aura::Window*> GetAllContainers(int container_id) { - return container_id == kRootWindowMagicId - ? Shell::GetAllRootWindows() - : Shell::GetContainersFromAllRootWindows(container_id, nullptr); -} +// Duration for dimming animations, in milliseconds. +const int kDimmingTransitionMs = 200; } // namespace -// static -ScreenDimmer* ScreenDimmer::GetForContainer(int container_id) { - aura::Window* primary_container = FindContainer(container_id); - ScreenDimmer* dimmer = primary_container->GetProperty(kScreenDimmerKey); - if (!dimmer) { - dimmer = new ScreenDimmer(container_id); - primary_container->SetProperty(kScreenDimmerKey, dimmer); - } - return dimmer; -} - -// static -ScreenDimmer* ScreenDimmer::GetForRoot() { - ScreenDimmer* dimmer = GetForContainer(kRootWindowMagicId); - // Root window's dimmer - dimmer->target_opacity_ = kDimmingLayerOpacityForRoot; - return dimmer; -} - -ScreenDimmer::ScreenDimmer(int container_id) - : container_id_(container_id), target_opacity_(0.5f), is_dimming_(false) { - Shell::GetInstance()->AddShellObserver(this); +ScreenDimmer::ScreenDimmer(aura::Window* root_window) + : root_window_(root_window), + currently_dimming_(false) { + root_window_->AddObserver(this); } ScreenDimmer::~ScreenDimmer() { - Shell::GetInstance()->RemoveShellObserver(this); + root_window_->RemoveObserver(this); } void ScreenDimmer::SetDimming(bool should_dim) { - if (should_dim == is_dimming_) + if (should_dim == currently_dimming_) return; - is_dimming_ = should_dim; - - Update(should_dim); -} -ScreenDimmer* ScreenDimmer::FindForTest(int container_id) { - return FindContainer(container_id)->GetProperty(kScreenDimmerKey); -} + if (!dimming_layer_) { + dimming_layer_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); + dimming_layer_->SetColor(SK_ColorBLACK); + dimming_layer_->SetOpacity(0.0f); + ui::Layer* root_layer = root_window_->layer(); + dimming_layer_->SetBounds(root_layer->bounds()); + root_layer->Add(dimming_layer_.get()); + root_layer->StackAtTop(dimming_layer_.get()); + } -// static -aura::Window* ScreenDimmer::FindContainer(int container_id) { - aura::Window* primary = Shell::GetPrimaryRootWindow(); - return container_id == kRootWindowMagicId - ? primary - : primary->GetChildById(container_id); -} + currently_dimming_ = should_dim; -void ScreenDimmer::OnRootWindowAdded(aura::Window* root_window) { - Update(is_dimming_); + ui::ScopedLayerAnimationSettings scoped_settings( + dimming_layer_->GetAnimator()); + scoped_settings.SetTransitionDuration( + base::TimeDelta::FromMilliseconds(kDimmingTransitionMs)); + dimming_layer_->SetOpacity(should_dim ? kDimmingLayerOpacity : 0.0f); } -void ScreenDimmer::Update(bool should_dim) { - for (aura::Window* container : GetAllContainers(container_id_)) { - DimWindow* dim = DimWindow::Get(container); - if (should_dim) { - if (!dim) { - dim = new DimWindow(container); - dim->SetDimOpacity(target_opacity_); - } - dim->Show(); - } else { - if (dim) { - dim->Hide(); - delete dim; - } - } - } +void ScreenDimmer::OnWindowBoundsChanged(aura::Window* root, + const gfx::Rect& old_bounds, + const gfx::Rect& new_bounds) { + if (dimming_layer_) + dimming_layer_->SetBounds(gfx::Rect(root->bounds().size())); } } // namespace ash diff --git a/ash/wm/screen_dimmer.h b/ash/wm/screen_dimmer.h index 6d26e68..a0b3fa5 100644 --- a/ash/wm/screen_dimmer.h +++ b/ash/wm/screen_dimmer.h @@ -6,7 +6,6 @@ #define ASH_WM_SCREEN_DIMMER_H_ #include "ash/ash_export.h" -#include "ash/shell_observer.h" #include "base/basictypes.h" #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" @@ -17,52 +16,50 @@ class Layer; } namespace ash { -class DimWindow; // ScreenDimmer displays a partially-opaque layer above everything -// else in the given container window to darken the display. It shouldn't be -// used for long-term brightness adjustments due to performance +// else in the root window to darken the display. It shouldn't be used +// for long-term brightness adjustments due to performance // considerations -- it's only intended for cases where we want to // briefly dim the screen (e.g. to indicate to the user that we're // about to suspend a machine that lacks an internal backlight that // can be adjusted). -class ASH_EXPORT ScreenDimmer : ShellObserver { +class ASH_EXPORT ScreenDimmer : public aura::WindowObserver { public: - // Creates a screen dimmer for the containers given by |container_id|. - // It's owned by the container in the primary root window and will be - // destroyed when the container is destroyed. - static ScreenDimmer* GetForContainer(int container_id); + class TestApi { + public: + explicit TestApi(ScreenDimmer* dimmer) : dimmer_(dimmer) {} - // Creates a dimmer a root window level. This is used for suspend animation. - static ScreenDimmer* GetForRoot(); + ui::Layer* layer() { return dimmer_->dimming_layer_.get(); } + private: + ScreenDimmer* dimmer_; // not owned + + DISALLOW_COPY_AND_ASSIGN(TestApi); + }; + + explicit ScreenDimmer(aura::Window* root_window); ~ScreenDimmer() override; - // Dim or undim the layers. + // Dim or undim the root window. void SetDimming(bool should_dim); - bool is_dimming() const { return is_dimming_; } - - // Find a ScreenDimmer in the container, or nullptr if it does not exist. - static ScreenDimmer* FindForTest(int container_id); + // aura::WindowObserver overrides: + void OnWindowBoundsChanged(aura::Window* root_window, + const gfx::Rect& old_bounds, + const gfx::Rect& new_bounds) override; private: - static aura::Window* FindContainer(int container_id); - - explicit ScreenDimmer(int container_id); - - // ShellObserver: - void OnRootWindowAdded(aura::Window* root_window) override; + friend class TestApi; - // Update the dimming state. This will also create a new DimWindow - // if necessary. (Used when a new display is connected) - void Update(bool should_dim); + aura::Window* root_window_; - int container_id_; - float target_opacity_; + // Partially-opaque layer that's stacked above all of the root window's + // children and used to dim the screen. NULL until the first time we dim. + scoped_ptr<ui::Layer> dimming_layer_; // Are we currently dimming the screen? - bool is_dimming_; + bool currently_dimming_; DISALLOW_COPY_AND_ASSIGN(ScreenDimmer); }; diff --git a/ash/wm/screen_dimmer_unittest.cc b/ash/wm/screen_dimmer_unittest.cc index 9b1bdc6..244beec 100644 --- a/ash/wm/screen_dimmer_unittest.cc +++ b/ash/wm/screen_dimmer_unittest.cc @@ -7,7 +7,6 @@ #include "ash/root_window_controller.h" #include "ash/shell.h" #include "ash/test/ash_test_base.h" -#include "ash/wm/dim_window.h" #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" #include "ui/aura/window_event_dispatcher.h" @@ -18,56 +17,53 @@ namespace test { class ScreenDimmerTest : public AshTestBase { public: - ScreenDimmerTest() : dimmer_(nullptr) {} + ScreenDimmerTest() : dimmer_(NULL) {} ~ScreenDimmerTest() override {} void SetUp() override { AshTestBase::SetUp(); - dimmer_ = ScreenDimmer::GetForRoot(); - } - - aura::Window* GetDimWindow() { - return DimWindow::Get(Shell::GetPrimaryRootWindow()); - } - - ui::Layer* GetDimWindowLayer() { - aura::Window* window = GetDimWindow(); - return window ? window->layer() : nullptr; + dimmer_ = Shell::GetPrimaryRootWindowController()->screen_dimmer(); + test_api_.reset(new ScreenDimmer::TestApi(dimmer_)); } protected: ScreenDimmer* dimmer_; // not owned + scoped_ptr<ScreenDimmer::TestApi> test_api_; + private: DISALLOW_COPY_AND_ASSIGN(ScreenDimmerTest); }; TEST_F(ScreenDimmerTest, DimAndUndim) { // Don't create a layer until we need to. - EXPECT_EQ(nullptr, GetDimWindowLayer()); + EXPECT_TRUE(test_api_->layer() == NULL); dimmer_->SetDimming(false); - EXPECT_EQ(nullptr, GetDimWindowLayer()); + EXPECT_TRUE(test_api_->layer() == NULL); // When we enable dimming, the layer should be created and stacked at the top // of the root's children. dimmer_->SetDimming(true); - ASSERT_NE(nullptr, GetDimWindowLayer()); + ASSERT_TRUE(test_api_->layer() != NULL); ui::Layer* root_layer = Shell::GetPrimaryRootWindow()->layer(); ASSERT_TRUE(!root_layer->children().empty()); - EXPECT_EQ(GetDimWindowLayer(), root_layer->children().back()); - EXPECT_TRUE(GetDimWindowLayer()->visible()); - EXPECT_GT(GetDimWindowLayer()->GetTargetOpacity(), 0.0f); + EXPECT_EQ(test_api_->layer(), root_layer->children().back()); + EXPECT_TRUE(test_api_->layer()->visible()); + EXPECT_GT(test_api_->layer()->GetTargetOpacity(), 0.0f); - // When we disable dimming, the layer should be removed. + // When we disable dimming, the layer should be animated back to full + // transparency. dimmer_->SetDimming(false); - ASSERT_EQ(nullptr, GetDimWindowLayer()); + ASSERT_TRUE(test_api_->layer() != NULL); + EXPECT_TRUE(test_api_->layer()->visible()); + EXPECT_FLOAT_EQ(0.0f, test_api_->layer()->GetTargetOpacity()); } TEST_F(ScreenDimmerTest, ResizeLayer) { // The dimming layer should be initially sized to cover the root window. dimmer_->SetDimming(true); - ui::Layer* dimming_layer = GetDimWindowLayer(); - ASSERT_TRUE(dimming_layer != nullptr); + ui::Layer* dimming_layer = test_api_->layer(); + ASSERT_TRUE(dimming_layer != NULL); ui::Layer* root_layer = Shell::GetPrimaryRootWindow()->layer(); EXPECT_EQ(gfx::Rect(root_layer->bounds().size()).ToString(), dimming_layer->bounds().ToString()); @@ -79,12 +75,5 @@ TEST_F(ScreenDimmerTest, ResizeLayer) { EXPECT_EQ(kNewBounds.ToString(), dimming_layer->bounds().ToString()); } -TEST_F(ScreenDimmerTest, RootDimmer) { - ScreenDimmer* root_dimmer = ScreenDimmer::GetForRoot(); - // -100 is the magic number for root window. - EXPECT_EQ(root_dimmer, ScreenDimmer::FindForTest(-100)); - EXPECT_EQ(nullptr, ScreenDimmer::FindForTest(-1)); -} - } // namespace test } // namespace ash diff --git a/ash/wm/system_modal_container_layout_manager.cc b/ash/wm/system_modal_container_layout_manager.cc index 725cd2b..e5702fa 100644 --- a/ash/wm/system_modal_container_layout_manager.cc +++ b/ash/wm/system_modal_container_layout_manager.cc @@ -9,26 +9,35 @@ #include "ash/session/session_state_delegate.h" #include "ash/shell.h" #include "ash/shell_window_ids.h" -#include "ash/wm/dim_window.h" +#include "ash/wm/system_modal_container_event_filter.h" +#include "ash/wm/window_animations.h" #include "ash/wm/window_util.h" +#include "base/bind.h" #include "ui/aura/client/aura_constants.h" #include "ui/aura/client/capture_client.h" #include "ui/aura/window.h" +#include "ui/aura/window_event_dispatcher.h" #include "ui/aura/window_property.h" +#include "ui/base/ui_base_switches_util.h" #include "ui/compositor/layer.h" +#include "ui/compositor/layer_animator.h" +#include "ui/compositor/scoped_layer_animation_settings.h" +#include "ui/events/event.h" +#include "ui/gfx/screen.h" #include "ui/keyboard/keyboard_controller.h" +#include "ui/views/background.h" +#include "ui/views/view.h" +#include "ui/views/widget/widget.h" +#include "ui/wm/core/compound_event_filter.h" namespace ash { -namespace { -// The center point of the window can diverge this much from the center point // If this is set to true, the window will get centered. DEFINE_WINDOW_PROPERTY_KEY(bool, kCenteredKey, false); // The center point of the window can diverge this much from the center point // of the container to be kept centered upon resizing operations. const int kCenterPixelDelta = 32; -} //////////////////////////////////////////////////////////////////////////////// // SystemModalContainerLayoutManager, public: @@ -37,7 +46,8 @@ SystemModalContainerLayoutManager::SystemModalContainerLayoutManager( aura::Window* container) : SnapToPixelLayoutManager(container), container_(container), - modal_background_(nullptr) {} + modal_background_(NULL) { +} SystemModalContainerLayoutManager::~SystemModalContainerLayoutManager() { } @@ -46,12 +56,17 @@ SystemModalContainerLayoutManager::~SystemModalContainerLayoutManager() { // SystemModalContainerLayoutManager, aura::LayoutManager implementation: void SystemModalContainerLayoutManager::OnWindowResized() { + if (modal_background_) { + // Note: we have to set the entire bounds with the screen offset. + modal_background_->SetBounds( + Shell::GetScreen()->GetDisplayNearestWindow(container_).bounds()); + } PositionDialogsAfterWorkAreaResize(); } void SystemModalContainerLayoutManager::OnWindowAddedToLayout( aura::Window* child) { - DCHECK(child == modal_background_ || + DCHECK((modal_background_ && child == modal_background_->GetNativeView()) || child->type() == ui::wm::WINDOW_TYPE_NORMAL || child->type() == ui::wm::WINDOW_TYPE_POPUP); DCHECK( @@ -97,10 +112,10 @@ void SystemModalContainerLayoutManager::OnWindowPropertyChanged( void SystemModalContainerLayoutManager::OnWindowDestroying( aura::Window* window) { - if (modal_background_ == window) { + if (modal_background_ && modal_background_->GetNativeView() == window) { if (keyboard::KeyboardController::GetInstance()) keyboard::KeyboardController::GetInstance()->RemoveObserver(this); - modal_background_ = nullptr; + modal_background_ = NULL; } } @@ -140,14 +155,32 @@ bool SystemModalContainerLayoutManager::ActivateNextModalWindow() { void SystemModalContainerLayoutManager::CreateModalBackground() { if (!modal_background_) { - modal_background_ = new DimWindow(container_); - modal_background_->SetName( + modal_background_ = new views::Widget; + views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); + params.parent = container_; + params.bounds = Shell::GetScreen()->GetDisplayNearestWindow( + container_).bounds(); + modal_background_->Init(params); + modal_background_->GetNativeView()->SetName( "SystemModalContainerLayoutManager.ModalBackground"); + views::View* contents_view = new views::View(); + // TODO(jamescook): This could be SK_ColorWHITE for the new dialog style. + contents_view->set_background( + views::Background::CreateSolidBackground(SK_ColorBLACK)); + modal_background_->SetContentsView(contents_view); + modal_background_->GetNativeView()->layer()->SetOpacity(0.0f); // There isn't always a keyboard controller. if (keyboard::KeyboardController::GetInstance()) keyboard::KeyboardController::GetInstance()->AddObserver(this); } + + ui::ScopedLayerAnimationSettings settings( + modal_background_->GetNativeView()->layer()->GetAnimator()); + // Show should not be called with a target opacity of 0. We therefore start + // the fade to show animation before Show() is called. + modal_background_->GetNativeView()->layer()->SetOpacity(0.5f); modal_background_->Show(); + container_->StackChildAtTop(modal_background_->GetNativeView()); } void SystemModalContainerLayoutManager::DestroyModalBackground() { @@ -156,11 +189,11 @@ void SystemModalContainerLayoutManager::DestroyModalBackground() { if (modal_background_) { if (keyboard::KeyboardController::GetInstance()) keyboard::KeyboardController::GetInstance()->RemoveObserver(this); - modal_background_->Hide(); - // Explicitly delete instead of using scoped_ptr as the owner of the - // window is its parent. - delete modal_background_; - modal_background_ = nullptr; + ::wm::ScopedHidingAnimationSettings settings( + modal_background_->GetNativeView()); + modal_background_->Close(); + modal_background_->GetNativeView()->layer()->SetOpacity(0.0f); + modal_background_ = NULL; } } @@ -174,7 +207,8 @@ bool SystemModalContainerLayoutManager::IsModalBackground( SystemModalContainerLayoutManager* layout_manager = static_cast<SystemModalContainerLayoutManager*>( window->parent()->layout_manager()); - return layout_manager->modal_background_ == window; + return layout_manager->modal_background_ && + layout_manager->modal_background_->GetNativeWindow() == window; } //////////////////////////////////////////////////////////////////////////////// diff --git a/ash/wm/system_modal_container_layout_manager.h b/ash/wm/system_modal_container_layout_manager.h index 5818708..59c0eac 100644 --- a/ash/wm/system_modal_container_layout_manager.h +++ b/ash/wm/system_modal_container_layout_manager.h @@ -22,9 +22,11 @@ class EventFilter; namespace gfx { class Rect; } +namespace views { +class Widget; +} namespace ash { -class DimWindow; // LayoutManager for the modal window container. // System modal windows which are centered on the screen will be kept centered @@ -96,9 +98,9 @@ class ASH_EXPORT SystemModalContainerLayoutManager // The container that owns the layout manager. aura::Window* container_; - // A window that dims the windows behind the modal window(s) being + // A widget that dims the windows behind the modal window(s) being // shown in |container_|. - DimWindow* modal_background_; + views::Widget* modal_background_; // A stack of modal windows. Only the topmost can receive events. std::vector<aura::Window*> modal_windows_; diff --git a/chrome/browser/chromeos/dbus/chrome_display_power_service_provider_delegate.cc b/chrome/browser/chromeos/dbus/chrome_display_power_service_provider_delegate.cc index e5badf7..57269d9 100644 --- a/chrome/browser/chromeos/dbus/chrome_display_power_service_provider_delegate.cc +++ b/chrome/browser/chromeos/dbus/chrome_display_power_service_provider_delegate.cc @@ -5,7 +5,6 @@ #include "chrome/browser/chromeos/dbus/chrome_display_power_service_provider_delegate.h" #include "ash/shell.h" -#include "ash/wm/screen_dimmer.h" #include "ui/base/user_activity/user_activity_detector.h" #include "ui/display/chromeos/display_configurator.h" @@ -33,7 +32,7 @@ void ChromeDisplayPowerServiceProviderDelegate::SetDisplayPower( } void ChromeDisplayPowerServiceProviderDelegate::SetDimming(bool dimmed) { - ash::ScreenDimmer::GetForRoot()->SetDimming(dimmed); + ash::Shell::GetInstance()->SetDimming(dimmed); } } // namespace chromeos diff --git a/ui/wm/core/visibility_controller.cc b/ui/wm/core/visibility_controller.cc index fd7bb88a..fc187a9 100644 --- a/ui/wm/core/visibility_controller.cc +++ b/ui/wm/core/visibility_controller.cc @@ -18,14 +18,9 @@ namespace { DEFINE_WINDOW_PROPERTY_KEY( bool, kChildWindowVisibilityChangesAnimatedKey, false); -// A window with this property set will animate upon its visibility changes. -DEFINE_WINDOW_PROPERTY_KEY(bool, kWindowVisibilityChangesAnimatedKey, false); - bool ShouldAnimateWindow(aura::Window* window) { - return (window->parent() && - window->parent()->GetProperty( - kChildWindowVisibilityChangesAnimatedKey)) || - window->GetProperty(kWindowVisibilityChangesAnimatedKey); + return window->parent() && window->parent()->GetProperty( + kChildWindowVisibilityChangesAnimatedKey); } } // namespace @@ -86,12 +81,9 @@ SuspendChildWindowVisibilityAnimations:: window_->ClearProperty(kChildWindowVisibilityChangesAnimatedKey); } -void SetWindowVisibilityChangesAnimated(aura::Window* window) { - window->SetProperty(kWindowVisibilityChangesAnimatedKey, true); -} - void SetChildWindowVisibilityChangesAnimated(aura::Window* window) { window->SetProperty(kChildWindowVisibilityChangesAnimatedKey, true); } } // namespace wm + diff --git a/ui/wm/core/visibility_controller.h b/ui/wm/core/visibility_controller.h index 0e30454..c6f5258 100644 --- a/ui/wm/core/visibility_controller.h +++ b/ui/wm/core/visibility_controller.h @@ -64,17 +64,7 @@ class WM_EXPORT SuspendChildWindowVisibilityAnimations { DISALLOW_COPY_AND_ASSIGN(SuspendChildWindowVisibilityAnimations); }; -// Enable visibility change animation for specific |window|. Use this if -// you want to enable visibility change animation on a specific window without -// affecting other windows in the same container. Calling this on a window -// whose animation is already enabled either by this function, or -// via SetChildWindowVisibilityChangesAnimatedbelow below is allowed and -// the animation stays enabled. -void WM_EXPORT SetWindowVisibilityChangesAnimated(aura::Window* window); - -// Enable visibiilty change animation for all children of the |window|. -// Tyically applied to a container whose child windows should be animated -// when their visibility changes. +// Tells |window| to animate visibility changes to its children. void WM_EXPORT SetChildWindowVisibilityChangesAnimated( aura::Window* window); diff --git a/ui/wm/core/visibility_controller_unittest.cc b/ui/wm/core/visibility_controller_unittest.cc index 39a1d49..01731ef 100644 --- a/ui/wm/core/visibility_controller_unittest.cc +++ b/ui/wm/core/visibility_controller_unittest.cc @@ -13,7 +13,6 @@ #include "ui/compositor/layer_animator.h" #include "ui/compositor/scoped_animation_duration_scale_mode.h" #include "ui/compositor/scoped_layer_animation_settings.h" -#include "ui/wm/core/window_animations.h" namespace wm { @@ -54,37 +53,4 @@ TEST_F(VisibilityControllerTest, AnimateTransparencyToZeroAndHideHides) { EXPECT_FALSE(window->IsVisible()); } -// Test if SetWindowVisibilityChagngesAnimated will animate the specified -// window. -TEST_F(VisibilityControllerTest, SetWindowVisibilityChagnesAnimated) { - // We cannot disable animations for this test. - ui::ScopedAnimationDurationScaleMode test_duration_mode( - ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); - - VisibilityController controller; - aura::client::SetVisibilityClient(root_window(), &controller); - - aura::test::TestWindowDelegate d; - scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate( - &d, -2, gfx::Rect(0, 0, 50, 50), root_window())); - // Test using Show animation because Hide animation detaches the window's - // layer. - window->Hide(); - ASSERT_FALSE(window->IsVisible()); - - SetWindowVisibilityChangesAnimated(window.get()); - SetWindowVisibilityAnimationDuration(window.get(), - base::TimeDelta::FromMilliseconds(5)); - SetWindowVisibilityAnimationType(window.get(), - WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); - window->Show(); - EXPECT_TRUE(window->layer()->GetAnimator()->is_animating()); - EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity()); - EXPECT_EQ(0.0f, window->layer()->opacity()); - - window->layer()->GetAnimator()->StopAnimating(); - EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity()); - EXPECT_EQ(1.0f, window->layer()->opacity()); -} - } // namespace wm |