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

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

Issue 2586653002: Improve CrOS WM shadow drawing for small windows. (Closed)
Patch Set: wrapping Created 4 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 | « ui/wm/core/shadow.cc ('k') | 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/macros.h" 7 #include "base/macros.h"
8 #include "ui/aura/test/aura_test_base.h" 8 #include "ui/aura/test/aura_test_base.h"
9 9
10 namespace wm { 10 namespace wm {
11 namespace { 11 namespace {
12 12
13 gfx::Insets InsetsForElevation(int elevation) {
14 return -gfx::Insets(2 * elevation) + gfx::Insets(elevation, 0, -elevation, 0);
15 }
16
13 using ShadowTest = aura::test::AuraTestBase; 17 using ShadowTest = aura::test::AuraTestBase;
14 18
15 // Test if the proper content bounds is calculated based on the current style. 19 // Test if the proper content bounds is calculated based on the current style.
16 TEST_F(ShadowTest, SetContentBounds) { 20 TEST_F(ShadowTest, SetContentBounds) {
17 // Verify that layer bounds are outset from content bounds. 21 // Verify that layer bounds are outset from content bounds.
18 Shadow shadow; 22 Shadow shadow;
19 { 23 {
20 shadow.Init(Shadow::STYLE_ACTIVE); 24 shadow.Init(Shadow::STYLE_ACTIVE);
21 gfx::Rect content_bounds(100, 100, 300, 300); 25 gfx::Rect content_bounds(100, 100, 300, 300);
22 shadow.SetContentBounds(content_bounds); 26 shadow.SetContentBounds(content_bounds);
23 EXPECT_EQ(content_bounds, shadow.content_bounds()); 27 EXPECT_EQ(content_bounds, shadow.content_bounds());
24 gfx::Rect shadow_bounds(content_bounds); 28 gfx::Rect shadow_bounds(content_bounds);
25 int elevation = 24; 29 shadow_bounds.Inset(InsetsForElevation(24));
26 shadow_bounds.Inset(-gfx::Insets(2 * elevation) +
27 gfx::Insets(elevation, 0, -elevation, 0));
28 EXPECT_EQ(shadow_bounds, shadow.layer()->bounds()); 30 EXPECT_EQ(shadow_bounds, shadow.layer()->bounds());
29 } 31 }
30 32
31 { 33 {
32 shadow.SetStyle(Shadow::STYLE_SMALL); 34 shadow.SetStyle(Shadow::STYLE_SMALL);
33 gfx::Rect content_bounds(100, 100, 300, 300); 35 gfx::Rect content_bounds(100, 100, 300, 300);
34 shadow.SetContentBounds(content_bounds); 36 shadow.SetContentBounds(content_bounds);
35 EXPECT_EQ(content_bounds, shadow.content_bounds()); 37 EXPECT_EQ(content_bounds, shadow.content_bounds());
36 gfx::Rect shadow_bounds(content_bounds); 38 gfx::Rect shadow_bounds(content_bounds);
37 int elevation = 6; 39 shadow_bounds.Inset(InsetsForElevation(6));
38 shadow_bounds.Inset(-gfx::Insets(2 * elevation) +
39 gfx::Insets(elevation, 0, -elevation, 0));
40 EXPECT_EQ(shadow_bounds, shadow.layer()->bounds()); 40 EXPECT_EQ(shadow_bounds, shadow.layer()->bounds());
41 } 41 }
42 } 42 }
43
44 // Test that the elevation is reduced when the contents are too small to handle
45 // the full elevation.
46 TEST_F(ShadowTest, AdjustElevationForSmallContents) {
47 Shadow shadow;
48 shadow.Init(Shadow::STYLE_ACTIVE);
49 {
50 gfx::Rect content_bounds(100, 100, 300, 300);
51 shadow.SetContentBounds(content_bounds);
52 gfx::Rect shadow_bounds(content_bounds);
53 shadow_bounds.Inset(InsetsForElevation(24));
54 EXPECT_EQ(shadow_bounds, shadow.layer()->bounds());
55 }
56
57 {
58 constexpr int kWidth = 80;
59 gfx::Rect content_bounds(100, 100, kWidth, 300);
60 shadow.SetContentBounds(content_bounds);
61 gfx::Rect shadow_bounds(content_bounds);
62 shadow_bounds.Inset(InsetsForElevation((kWidth - 4) / 4));
63 EXPECT_EQ(shadow_bounds, shadow.layer()->bounds());
64 }
65
66 {
67 constexpr int kHeight = 80;
68 gfx::Rect content_bounds(100, 100, 300, kHeight);
69 shadow.SetContentBounds(content_bounds);
70 gfx::Rect shadow_bounds(content_bounds);
71 shadow_bounds.Inset(InsetsForElevation((kHeight - 4) / 4));
72 EXPECT_EQ(shadow_bounds, shadow.layer()->bounds());
73 }
74 }
43 75
44 } // namespace 76 } // namespace
45 } // namespace wm 77 } // namespace wm
OLDNEW
« no previous file with comments | « ui/wm/core/shadow.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698