Chromium Code Reviews| Index: ash/common/wm/window_dimmer.cc |
| diff --git a/ash/wm/dim_window.cc b/ash/common/wm/window_dimmer.cc |
| similarity index 21% |
| rename from ash/wm/dim_window.cc |
| rename to ash/common/wm/window_dimmer.cc |
| index 552789f54321b4322931d7db6c4700dd027c457d..b182cfdc201b4d77bb4aeb23d8557773cf26aedb 100644 |
| --- a/ash/wm/dim_window.cc |
| +++ b/ash/common/wm/window_dimmer.cc |
| @@ -2,78 +2,84 @@ |
| // 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 "ash/common/wm/window_dimmer.h" |
| + |
| +#include <memory> |
| + |
| +#include "ash/common/wm_shell.h" |
| +#include "ash/common/wm_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; |
| +const char kWindowDimmerKey[] = "window_dimmer_key"; |
| + |
| } // namespace |
| +struct WindowDimmer::Data : public base::SupportsUserData::Data { |
| + ~Data() override { delete window_dimmer; } |
|
James Cook
2016/09/09 00:03:35
So is the point of all this userdata to ensure tha
sky
2016/09/09 03:50:04
The main motivation for user data is the same as t
|
| + |
| + WindowDimmer* window_dimmer; |
| +}; |
| + |
| // static |
| -DimWindow* DimWindow::Get(aura::Window* container) { |
| - return container->GetProperty(kDimWindowKey); |
| +WindowDimmer* WindowDimmer::Get(WmWindow* container) { |
| + Data* data = static_cast<Data*>( |
| + container->GetUserData()->GetUserData(kWindowDimmerKey)); |
| + return data ? data->window_dimmer : nullptr; |
| } |
| -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)); |
| +WindowDimmer::WindowDimmer(WmWindow* parent) |
| + : parent_(parent), |
| + window_(WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_NORMAL, |
| + ui::LAYER_SOLID_COLOR)) { |
| + window_->SetVisibilityChangesAnimated(); |
| + window_->SetVisibilityAnimationType( |
| + ::wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); |
| + window_->SetVisibilityAnimationDuration( |
| + base::TimeDelta::FromMilliseconds(kDefaultDimAnimationDurationMs)); |
| SetDimOpacity(kDefaultDimOpacity); |
| - parent->AddChild(this); |
| + parent->AddChild(window_); |
| parent->AddObserver(this); |
| - parent->SetProperty(kDimWindowKey, this); |
| - parent->StackChildAtTop(this); |
| + parent->StackChildAtTop(window_); |
| + |
| + window_->SetBounds(gfx::Rect(parent_->GetBounds().size())); |
| - SetBounds(parent->bounds()); |
| + Data* data = new Data; |
| + data->window_dimmer = this; |
| + parent->GetUserData()->SetUserData(kWindowDimmerKey, data); |
| } |
| -DimWindow::~DimWindow() { |
| - if (parent_) { |
| - parent_->ClearProperty(kDimWindowKey); |
| - parent_->RemoveObserver(this); |
| - parent_ = nullptr; |
| - } |
| +void WindowDimmer::Destroy() { |
| + window_->Destroy(); |
| + parent_->RemoveObserver(this); |
| + // RemoveUserData() riggers deleting this. |
|
James Cook
2016/09/09 00:03:35
nit: triggers
sky
2016/09/09 03:50:04
Done.
|
| + parent_->GetUserData()->RemoveUserData(kWindowDimmerKey); |
| } |
| -void DimWindow::SetDimOpacity(float target_opacity) { |
| - layer()->SetColor(SkColorSetA(SK_ColorBLACK, 255 * target_opacity)); |
| +void WindowDimmer::SetDimOpacity(float target_opacity) { |
| + window_->GetLayer()->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 WindowDimmer::OnWindowBoundsChanged(WmWindow* window, |
| + const gfx::Rect& old_bounds, |
| + const gfx::Rect& new_bounds) { |
| + DCHECK_EQ(window, parent_); |
| + window_->SetBounds(gfx::Rect(new_bounds.size())); |
| } |
| -void DimWindow::OnWindowDestroying(Window* window) { |
| - if (window == parent_) { |
| - window->ClearProperty(kDimWindowKey); |
| - window->RemoveObserver(this); |
| - parent_ = nullptr; |
| - } |
| +WindowDimmer::~WindowDimmer() { |
| + parent_->RemoveObserver(this); |
| } |
| } // namespace ash |