Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Unified Diff: ash/common/wm/window_dimmer.cc

Issue 2320273002: Refactors DimWindow and moves to ash/common (Closed)
Patch Set: feedback and member initializer ordering Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/common/wm/window_dimmer.h ('k') | ash/common/wm_root_window_controller.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/common/wm/window_dimmer.cc
diff --git a/ash/wm/dim_window.cc b/ash/common/wm/window_dimmer.cc
similarity index 25%
rename from ash/wm/dim_window.cc
rename to ash/common/wm/window_dimmer.cc
index 552789f54321b4322931d7db6c4700dd027c457d..bdd1109d9905c3b44ed9da1b3902386006559ade 100644
--- a/ash/wm/dim_window.cc
+++ b/ash/common/wm/window_dimmer.cc
@@ -2,77 +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;
} // 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));
+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));
+ window_->AddObserver(this);
SetDimOpacity(kDefaultDimOpacity);
- parent->AddChild(this);
+ parent->AddChild(window_);
parent->AddObserver(this);
- parent->SetProperty(kDimWindowKey, this);
- parent->StackChildAtTop(this);
+ parent->StackChildAtTop(window_);
- SetBounds(parent->bounds());
+ window_->SetBounds(gfx::Rect(parent_->GetBounds().size()));
}
-DimWindow::~DimWindow() {
- if (parent_) {
- parent_->ClearProperty(kDimWindowKey);
+WindowDimmer::~WindowDimmer() {
+ if (parent_)
parent_->RemoveObserver(this);
- parent_ = nullptr;
+ if (window_) {
+ window_->RemoveObserver(this);
+ window_->Destroy();
}
}
-void DimWindow::SetDimOpacity(float target_opacity) {
- layer()->SetColor(SkColorSetA(SK_ColorBLACK, 255 * target_opacity));
+void WindowDimmer::SetDimOpacity(float target_opacity) {
+ DCHECK(window_);
+ 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) {
+void WindowDimmer::OnWindowBoundsChanged(WmWindow* window,
+ const gfx::Rect& old_bounds,
+ const gfx::Rect& new_bounds) {
if (window == parent_)
- SetBounds(new_bounds);
+ window_->SetBounds(gfx::Rect(new_bounds.size()));
}
-void DimWindow::OnWindowDestroying(Window* window) {
+void WindowDimmer::OnWindowDestroying(WmWindow* window) {
if (window == parent_) {
- window->ClearProperty(kDimWindowKey);
- window->RemoveObserver(this);
+ parent_->RemoveObserver(this);
parent_ = nullptr;
+ } else {
+ DCHECK_EQ(window_, window);
+ window_->RemoveObserver(this);
+ window_ = nullptr;
+ }
+}
+
+void WindowDimmer::OnWindowTreeChanging(WmWindow* window,
+ const TreeChangeParams& params) {
+ if (window == window_ && params.target == window) {
+ // This may happen on a display change or some unexpected condition. Hide
+ // the window to ensure it isn't obscuring the wrong thing.
+ window_->Hide();
}
}
« no previous file with comments | « ash/common/wm/window_dimmer.h ('k') | ash/common/wm_root_window_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698