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

Side by Side Diff: ui/wm/core/shadow.cc

Issue 798673002: Use 0.2f opacity only when the shadow animation is applied. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/wm/core/shadow.h" 5 #include "ui/wm/core/shadow.h"
6 6
7 #include "third_party/skia/include/core/SkBitmap.h" 7 #include "third_party/skia/include/core/SkBitmap.h"
8 #include "ui/base/resource/resource_bundle.h" 8 #include "ui/base/resource/resource_bundle.h"
9 #include "ui/compositor/layer.h" 9 #include "ui/compositor/layer.h"
10 #include "ui/compositor/scoped_layer_animation_settings.h" 10 #include "ui/compositor/scoped_layer_animation_settings.h"
11 #include "ui/resources/grit/ui_resources.h" 11 #include "ui/resources/grit/ui_resources.h"
12 12
13 namespace { 13 namespace {
14 14
15 // Shadow opacity for different styles. 15 // The opacity used for active shadow when animating between
16 const float kActiveShadowOpacity = 1.0f; 16 // inactive/active shadow.
17 const float kInactiveShadowOpacity = 0.2f; 17 const float kInactiveShadowAnimationOpacity = 0.2f;
18 const float kSmallShadowOpacity = 1.0f;
19 18
20 // Shadow aperture for different styles. 19 // Shadow aperture for different styles.
21 // Note that this may be greater than interior inset to allow shadows with 20 // Note that this may be greater than interior inset to allow shadows with
22 // curved corners that extend inwards beyond a window's borders. 21 // curved corners that extend inwards beyond a window's borders.
23 const int kActiveInteriorAperture = 134; 22 const int kActiveInteriorAperture = 134;
24 const int kInactiveInteriorAperture = 134; 23 const int kInactiveInteriorAperture = 134;
25 const int kSmallInteriorAperture = 9; 24 const int kSmallInteriorAperture = 9;
26 25
27 // Interior inset for different styles. 26 // Interior inset for different styles.
28 const int kActiveInteriorInset = 64; 27 const int kActiveInteriorInset = 64;
29 const int kInactiveInteriorInset = 64; 28 const int kInactiveInteriorInset = 64;
30 const int kSmallInteriorInset = 4; 29 const int kSmallInteriorInset = 4;
31 30
32 // Duration for opacity animation in milliseconds. 31 // Duration for opacity animation in milliseconds.
33 const int kShadowAnimationDurationMs = 100; 32 const int kShadowAnimationDurationMs = 100;
34 33
35 float GetOpacityForStyle(wm::Shadow::Style style) {
36 switch (style) {
37 case wm::Shadow::STYLE_ACTIVE:
38 return kActiveShadowOpacity;
39 case wm::Shadow::STYLE_INACTIVE:
40 return kInactiveShadowOpacity;
41 case wm::Shadow::STYLE_SMALL:
42 return kSmallShadowOpacity;
43 }
44 return 1.0f;
45 }
46
47 int GetShadowApertureForStyle(wm::Shadow::Style style) { 34 int GetShadowApertureForStyle(wm::Shadow::Style style) {
48 switch (style) { 35 switch (style) {
49 case wm::Shadow::STYLE_ACTIVE: 36 case wm::Shadow::STYLE_ACTIVE:
50 return kActiveInteriorAperture; 37 return kActiveInteriorAperture;
51 case wm::Shadow::STYLE_INACTIVE: 38 case wm::Shadow::STYLE_INACTIVE:
52 return kInactiveInteriorAperture; 39 return kInactiveInteriorAperture;
53 case wm::Shadow::STYLE_SMALL: 40 case wm::Shadow::STYLE_SMALL:
54 return kSmallInteriorAperture; 41 return kSmallInteriorAperture;
55 } 42 }
56 return 0; 43 return 0;
(...skipping 25 matching lines...) Expand all
82 style_ = style; 69 style_ = style;
83 70
84 layer_.reset(new ui::Layer(ui::LAYER_NOT_DRAWN)); 71 layer_.reset(new ui::Layer(ui::LAYER_NOT_DRAWN));
85 shadow_layer_.reset(new ui::Layer(ui::LAYER_NINE_PATCH)); 72 shadow_layer_.reset(new ui::Layer(ui::LAYER_NINE_PATCH));
86 layer()->Add(shadow_layer_.get()); 73 layer()->Add(shadow_layer_.get());
87 74
88 UpdateImagesForStyle(); 75 UpdateImagesForStyle();
89 shadow_layer_->set_name("Shadow"); 76 shadow_layer_->set_name("Shadow");
90 shadow_layer_->SetVisible(true); 77 shadow_layer_->SetVisible(true);
91 shadow_layer_->SetFillsBoundsOpaquely(false); 78 shadow_layer_->SetFillsBoundsOpaquely(false);
92 shadow_layer_->SetOpacity(GetOpacityForStyle(style_));
93 } 79 }
94 80
95 void Shadow::SetContentBounds(const gfx::Rect& content_bounds) { 81 void Shadow::SetContentBounds(const gfx::Rect& content_bounds) {
96 content_bounds_ = content_bounds; 82 content_bounds_ = content_bounds;
97 UpdateLayerBounds(); 83 UpdateLayerBounds();
98 } 84 }
99 85
100 void Shadow::SetStyle(Style style) { 86 void Shadow::SetStyle(Style style) {
101 if (style_ == style) 87 if (style_ == style)
102 return; 88 return;
103 89
104 Style old_style = style_; 90 Style old_style = style_;
105 style_ = style; 91 style_ = style;
106 92
107 // Stop waiting for any as yet unfinished implicit animations. 93 // Stop waiting for any as yet unfinished implicit animations.
108 StopObservingImplicitAnimations(); 94 StopObservingImplicitAnimations();
109 95
110 // If we're switching to or from the small style, don't bother with 96 // If we're switching to or from the small style, don't bother with
111 // animations. 97 // animations.
112 if (style == STYLE_SMALL || old_style == STYLE_SMALL) { 98 if (style == STYLE_SMALL || old_style == STYLE_SMALL) {
113 UpdateImagesForStyle(); 99 UpdateImagesForStyle();
114 shadow_layer_->SetOpacity(GetOpacityForStyle(style)); 100 // Make sure the shadow is fully opaque.
101 shadow_layer_->SetOpacity(1.0f);
115 return; 102 return;
116 } 103 }
117 104
118 // If we're becoming active, switch images now. Because the inactive image 105 // If we're becoming active, switch images now. Because the inactive image
119 // has a very low opacity the switch isn't noticeable and this approach 106 // has a very low opacity the switch isn't noticeable and this approach
120 // allows us to use only a single set of shadow images at a time. 107 // allows us to use only a single set of shadow images at a time.
121 if (style == STYLE_ACTIVE) { 108 if (style == STYLE_ACTIVE) {
122 UpdateImagesForStyle(); 109 UpdateImagesForStyle();
123 // Opacity was baked into inactive image, start opacity low to match. 110 // Opacity was baked into inactive image, start opacity low to match.
124 shadow_layer_->SetOpacity(kInactiveShadowOpacity); 111 shadow_layer_->SetOpacity(kInactiveShadowAnimationOpacity);
125 } 112 }
126 113
127 { 114 {
128 // Property sets within this scope will be implicitly animated. 115 // Property sets within this scope will be implicitly animated.
129 ui::ScopedLayerAnimationSettings settings(shadow_layer_->GetAnimator()); 116 ui::ScopedLayerAnimationSettings settings(shadow_layer_->GetAnimator());
130 settings.AddObserver(this); 117 settings.AddObserver(this);
131 settings.SetTransitionDuration( 118 settings.SetTransitionDuration(
132 base::TimeDelta::FromMilliseconds(kShadowAnimationDurationMs)); 119 base::TimeDelta::FromMilliseconds(kShadowAnimationDurationMs));
133 switch (style_) { 120 switch (style_) {
134 case STYLE_ACTIVE: 121 case STYLE_ACTIVE:
135 shadow_layer_->SetOpacity(kActiveShadowOpacity); 122 // Animate the active shadow from kInactiveShadowAnimationOpacity to
123 // 1.0f.
124 shadow_layer_->SetOpacity(1.0f);
136 break; 125 break;
137 case STYLE_INACTIVE: 126 case STYLE_INACTIVE:
138 shadow_layer_->SetOpacity(kInactiveShadowOpacity); 127 // The opacity will be reset to 1.0f when animation is completed.
128 shadow_layer_->SetOpacity(kInactiveShadowAnimationOpacity);
139 break; 129 break;
140 default: 130 default:
141 NOTREACHED() << "Unhandled style " << style_; 131 NOTREACHED() << "Unhandled style " << style_;
142 break; 132 break;
143 } 133 }
144 } 134 }
145 } 135 }
146 136
147 void Shadow::OnImplicitAnimationsCompleted() { 137 void Shadow::OnImplicitAnimationsCompleted() {
148 // If we just finished going inactive, switch images. This doesn't cause 138 // If we just finished going inactive, switch images. This doesn't cause
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 int aperture_y = std::min(aperture, layer_bounds.height() / 2); 184 int aperture_y = std::min(aperture, layer_bounds.height() / 2);
195 shadow_layer_->UpdateNinePatchLayerAperture( 185 shadow_layer_->UpdateNinePatchLayerAperture(
196 gfx::Rect(aperture_x, aperture_y, 186 gfx::Rect(aperture_x, aperture_y,
197 image_size_.width() - aperture_x * 2, 187 image_size_.width() - aperture_x * 2,
198 image_size_.height() - aperture_y * 2)); 188 image_size_.height() - aperture_y * 2));
199 shadow_layer_->UpdateNinePatchLayerBorder( 189 shadow_layer_->UpdateNinePatchLayerBorder(
200 gfx::Rect(aperture_x, aperture_y, aperture_x * 2, aperture_y * 2)); 190 gfx::Rect(aperture_x, aperture_y, aperture_x * 2, aperture_y * 2));
201 } 191 }
202 192
203 } // namespace wm 193 } // namespace wm
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698