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

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 target opacity of shadow animation for different styles.
16 const float kActiveShadowOpacity = 1.0f; 16 const float kActiveShadowOpacity = 1.0f;
James Cook 2014/12/11 22:34:04 I would just delete this constant and inline the u
oshima 2014/12/12 21:23:45 Done.
17 const float kInactiveShadowOpacity = 0.2f; 17 const float kInactiveShadowOpacity = 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_)); 79 shadow_layer_->SetOpacity(1.0f);
oshima 2014/12/12 21:23:45 I removed this because 1.0f is default.
93 } 80 }
94 81
95 void Shadow::SetContentBounds(const gfx::Rect& content_bounds) { 82 void Shadow::SetContentBounds(const gfx::Rect& content_bounds) {
96 content_bounds_ = content_bounds; 83 content_bounds_ = content_bounds;
97 UpdateLayerBounds(); 84 UpdateLayerBounds();
98 } 85 }
99 86
100 void Shadow::SetStyle(Style style) { 87 void Shadow::SetStyle(Style style) {
101 if (style_ == style) 88 if (style_ == style)
102 return; 89 return;
103 90
104 Style old_style = style_; 91 Style old_style = style_;
105 style_ = style; 92 style_ = style;
106 93
107 // Stop waiting for any as yet unfinished implicit animations. 94 // Stop waiting for any as yet unfinished implicit animations.
108 StopObservingImplicitAnimations(); 95 StopObservingImplicitAnimations();
109 96
110 // If we're switching to or from the small style, don't bother with 97 // If we're switching to or from the small style, don't bother with
111 // animations. 98 // animations.
112 if (style == STYLE_SMALL || old_style == STYLE_SMALL) { 99 if (style == STYLE_SMALL || old_style == STYLE_SMALL) {
113 UpdateImagesForStyle(); 100 UpdateImagesForStyle();
114 shadow_layer_->SetOpacity(GetOpacityForStyle(style)); 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(kInactiveShadowOpacity);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 int aperture_y = std::min(aperture, layer_bounds.height() / 2); 181 int aperture_y = std::min(aperture, layer_bounds.height() / 2);
195 shadow_layer_->UpdateNinePatchLayerAperture( 182 shadow_layer_->UpdateNinePatchLayerAperture(
196 gfx::Rect(aperture_x, aperture_y, 183 gfx::Rect(aperture_x, aperture_y,
197 image_size_.width() - aperture_x * 2, 184 image_size_.width() - aperture_x * 2,
198 image_size_.height() - aperture_y * 2)); 185 image_size_.height() - aperture_y * 2));
199 shadow_layer_->UpdateNinePatchLayerBorder( 186 shadow_layer_->UpdateNinePatchLayerBorder(
200 gfx::Rect(aperture_x, aperture_y, aperture_x * 2, aperture_y * 2)); 187 gfx::Rect(aperture_x, aperture_y, aperture_x * 2, aperture_y * 2));
201 } 188 }
202 189
203 } // namespace wm 190 } // 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