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

Side by Side Diff: ash/wm/dim_window.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 unified diff | Download patch
« no previous file with comments | « ash/wm/dim_window.h ('k') | ash/wm/screen_dimmer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ash/wm/dim_window.h"
6 #include "base/time/time.h"
7 #include "ui/aura/client/aura_constants.h"
8 #include "ui/aura/window_property.h"
9 #include "ui/compositor/layer.h"
10 #include "ui/compositor/scoped_layer_animation_settings.h"
11 #include "ui/wm/core/visibility_controller.h"
12 #include "ui/wm/core/window_animations.h"
13
14 DECLARE_WINDOW_PROPERTY_TYPE(ash::DimWindow*);
15
16 namespace ash {
17 namespace {
18
19 DEFINE_LOCAL_WINDOW_PROPERTY_KEY(DimWindow*, kDimWindowKey, nullptr);
20
21 const int kDefaultDimAnimationDurationMs = 200;
22
23 const float kDefaultDimOpacity = 0.5f;
24
25 } // namespace
26
27 // static
28 DimWindow* DimWindow::Get(aura::Window* container) {
29 return container->GetProperty(kDimWindowKey);
30 }
31
32 DimWindow::DimWindow(aura::Window* parent)
33 : aura::Window(nullptr), parent_(parent) {
34 SetType(ui::wm::WINDOW_TYPE_NORMAL);
35 Init(ui::LAYER_SOLID_COLOR);
36 wm::SetWindowVisibilityChangesAnimated(this);
37 wm::SetWindowVisibilityAnimationType(
38 this, wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE);
39 wm::SetWindowVisibilityAnimationDuration(
40 this, base::TimeDelta::FromMilliseconds(kDefaultDimAnimationDurationMs));
41
42 SetDimOpacity(kDefaultDimOpacity);
43
44 parent->AddChild(this);
45 parent->AddObserver(this);
46 parent->SetProperty(kDimWindowKey, this);
47 parent->StackChildAtTop(this);
48
49 SetBounds(parent->bounds());
50 }
51
52 DimWindow::~DimWindow() {
53 if (parent_) {
54 parent_->ClearProperty(kDimWindowKey);
55 parent_->RemoveObserver(this);
56 parent_ = nullptr;
57 }
58 }
59
60 void DimWindow::SetDimOpacity(float target_opacity) {
61 layer()->SetColor(SkColorSetA(SK_ColorBLACK, 255 * target_opacity));
62 }
63
64 void DimWindow::OnWindowBoundsChanged(aura::Window* window,
65 const gfx::Rect& old_bounds,
66 const gfx::Rect& new_bounds) {
67 if (window == parent_)
68 SetBounds(new_bounds);
69 }
70
71 void DimWindow::OnWindowDestroying(Window* window) {
72 if (window == parent_) {
73 window->ClearProperty(kDimWindowKey);
74 window->RemoveObserver(this);
75 parent_ = nullptr;
76 }
77 }
78
79 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/dim_window.h ('k') | ash/wm/screen_dimmer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698