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

Side by Side Diff: ui/native_theme/native_theme_aura_unittest.cc

Issue 2009733002: Draw nicer arrows when the scrollbar buttons are not square. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: no floats allowed Created 4 years, 6 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 | « ui/native_theme/BUILD.gn ('k') | ui/native_theme/native_theme_base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/native_theme/native_theme_aura.h" 5 #include "ui/native_theme/native_theme_aura.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "third_party/skia/include/core/SkPath.h" 8 #include "third_party/skia/include/core/SkPath.h"
9 #include "ui/gfx/geometry/rect.h" 9 #include "ui/gfx/geometry/rect.h"
10 #include "ui/native_theme/native_theme.h" 10 #include "ui/native_theme/native_theme.h"
11 11
12 namespace ui { 12 namespace ui {
13 namespace { 13 namespace {
14 void VerifyPoint(SkPoint a, SkPoint b) { 14 void VerifyPoint(SkPoint a, SkPoint b) {
15 EXPECT_EQ(a.x(), b.x()); 15 EXPECT_EQ(a.x(), b.x());
16 EXPECT_EQ(a.y(), b.y()); 16 EXPECT_EQ(a.y(), b.y());
17 } 17 }
18 18
19 void VerifyTriangle(SkPath actualPath, SkPoint p0, SkPoint p1, SkPoint p2) { 19 void VerifyTriangle(SkPath actualPath, SkPoint p0, SkPoint p1, SkPoint p2) {
20 EXPECT_EQ(3, actualPath.countPoints()); 20 EXPECT_EQ(3, actualPath.countPoints());
21 VerifyPoint(p0, actualPath.getPoint(0)); 21 VerifyPoint(p0, actualPath.getPoint(0));
22 VerifyPoint(p1, actualPath.getPoint(1)); 22 VerifyPoint(p1, actualPath.getPoint(1));
23 VerifyPoint(p2, actualPath.getPoint(2)); 23 VerifyPoint(p2, actualPath.getPoint(2));
24 } 24 }
25 } 25 }
26 26
27 TEST(NativeThemeAuraTest, VerticalArrows) { 27 class NativeThemeAuraTest : public testing::Test {
28 NativeThemeAura* theme = NativeThemeAura::instance(); 28 protected:
29 NativeThemeAuraTest() : theme_(NativeThemeAura::instance()) {}
30
31 SkPath PathForArrow(const gfx::Rect& rect,
32 NativeTheme::Part direction) const {
33 return theme_->PathForArrow(rect, direction);
34 }
35
36 gfx::Rect BoundingRectForArrow(const gfx::Rect& rect) const {
37 return theme_->BoundingRectForArrow(rect);
38 }
39
40 private:
41 NativeThemeAura* theme_;
42 };
43
44 TEST_F(NativeThemeAuraTest, VerticalArrows) {
29 SkPath path; 45 SkPath path;
30 46
31 // Up arrow, sized for 1x. 47 // Up arrow, sized for 1x.
32 path = theme->PathForArrow(gfx::Rect(100, 200, 17, 17), 48 path =
33 NativeTheme::kScrollbarUpArrow); 49 PathForArrow(gfx::Rect(100, 200, 17, 17), NativeTheme::kScrollbarUpArrow);
34 VerifyTriangle(path, SkPoint::Make(105, 211), SkPoint::Make(112, 211), 50 VerifyTriangle(path, SkPoint::Make(105, 211), SkPoint::Make(112, 211),
35 SkPoint::Make(108.5, 207)); 51 SkPoint::Make(108.5, 207));
36 52
37 // 1.25x, should be larger. 53 // 1.25x, should be larger.
38 path = theme->PathForArrow(gfx::Rect(50, 70, 21, 21), 54 path =
39 NativeTheme::kScrollbarUpArrow); 55 PathForArrow(gfx::Rect(50, 70, 21, 21), NativeTheme::kScrollbarUpArrow);
40 VerifyTriangle(path, SkPoint::Make(56, 84), SkPoint::Make(65, 84), 56 VerifyTriangle(path, SkPoint::Make(56, 84), SkPoint::Make(65, 84),
41 SkPoint::Make(60.5, 79)); 57 SkPoint::Make(60.5, 79));
42 58
43 // Down arrow is just a flipped up arrow. 59 // Down arrow is just a flipped up arrow.
44 path = theme->PathForArrow(gfx::Rect(20, 80, 17, 17), 60 path =
45 NativeTheme::kScrollbarDownArrow); 61 PathForArrow(gfx::Rect(20, 80, 17, 17), NativeTheme::kScrollbarDownArrow);
46 VerifyTriangle(path, SkPoint::Make(25, 86), SkPoint::Make(32, 86), 62 VerifyTriangle(path, SkPoint::Make(25, 86), SkPoint::Make(32, 86),
47 SkPoint::Make(28.5, 90)); 63 SkPoint::Make(28.5, 90));
48 } 64 }
49 65
50 TEST(NativeThemeAuraTest, HorizontalArrows) { 66 TEST_F(NativeThemeAuraTest, HorizontalArrows) {
51 NativeThemeAura* theme = NativeThemeAura::instance();
52 SkPath path; 67 SkPath path;
53 68
54 // Right arrow, sized for 1x. 69 // Right arrow, sized for 1x.
55 path = theme->PathForArrow(gfx::Rect(100, 200, 17, 17), 70 path = PathForArrow(gfx::Rect(100, 200, 17, 17),
56 NativeTheme::kScrollbarRightArrow); 71 NativeTheme::kScrollbarRightArrow);
57 VerifyTriangle(path, SkPoint::Make(107, 205), SkPoint::Make(107, 212), 72 VerifyTriangle(path, SkPoint::Make(107, 205), SkPoint::Make(107, 212),
58 SkPoint::Make(111, 208.5)); 73 SkPoint::Make(111, 208.5));
59 74
60 // Button size for 1.25x, should be larger. 75 // Button size for 1.25x, should be larger.
61 path = theme->PathForArrow(gfx::Rect(50, 70, 21, 21), 76 path = PathForArrow(gfx::Rect(50, 70, 21, 21),
62 NativeTheme::kScrollbarRightArrow); 77 NativeTheme::kScrollbarRightArrow);
63 VerifyTriangle(path, SkPoint::Make(58, 76), SkPoint::Make(58, 85), 78 VerifyTriangle(path, SkPoint::Make(58, 76), SkPoint::Make(58, 85),
64 SkPoint::Make(63, 80.5)); 79 SkPoint::Make(63, 80.5));
65 80
66 // Left arrow is just a flipped right arrow. 81 // Left arrow is just a flipped right arrow.
67 path = theme->PathForArrow(gfx::Rect(20, 80, 17, 17), 82 path =
68 NativeTheme::kScrollbarLeftArrow); 83 PathForArrow(gfx::Rect(20, 80, 17, 17), NativeTheme::kScrollbarLeftArrow);
69 VerifyTriangle(path, SkPoint::Make(30, 85), SkPoint::Make(30, 92), 84 VerifyTriangle(path, SkPoint::Make(30, 85), SkPoint::Make(30, 92),
70 SkPoint::Make(26, 88.5)); 85 SkPoint::Make(26, 88.5));
71 } 86 }
72 87
88 TEST_F(NativeThemeAuraTest, ArrowForNonSquareButton) {
89 SkPath path =
90 PathForArrow(gfx::Rect(90, 80, 42, 37), NativeTheme::kScrollbarLeftArrow);
91 VerifyTriangle(path, SkPoint::Make(116, 89), SkPoint::Make(116, 109),
92 SkPoint::Make(105, 99));
93 }
94
95 TEST_F(NativeThemeAuraTest, BoundingRectSquare) {
96 gfx::Rect bounding_rect = BoundingRectForArrow(gfx::Rect(42, 61, 21, 21));
97 EXPECT_EQ(48.f, bounding_rect.x());
98 EXPECT_EQ(67.f, bounding_rect.y());
99 EXPECT_EQ(9.f, bounding_rect.width());
100 EXPECT_EQ(bounding_rect.width(), bounding_rect.height());
101 }
102
103 TEST_F(NativeThemeAuraTest, BoundingRectSlightlyRectangular) {
104 // Stretched horzontally.
105 gfx::Rect bounding_rect = BoundingRectForArrow(gfx::Rect(42, 61, 25, 20));
106 EXPECT_EQ(49.f, bounding_rect.x());
107 EXPECT_EQ(66.f, bounding_rect.y());
108 EXPECT_EQ(11.f, bounding_rect.width());
109 EXPECT_EQ(bounding_rect.width(), bounding_rect.height());
110
111 // Stretched vertically.
112 bounding_rect = BoundingRectForArrow(gfx::Rect(42, 61, 14, 10));
113 EXPECT_EQ(46.f, bounding_rect.x());
114 EXPECT_EQ(63.f, bounding_rect.y());
115 EXPECT_EQ(6.f, bounding_rect.width());
116 EXPECT_EQ(bounding_rect.width(), bounding_rect.height());
117 }
118
119 TEST_F(NativeThemeAuraTest, BoundingRectVeryRectangular) {
120 // Stretched horzontally.
121 gfx::Rect bounding_rect = BoundingRectForArrow(gfx::Rect(42, 61, 30, 8));
122 EXPECT_EQ(53.f, bounding_rect.x());
123 EXPECT_EQ(61.f, bounding_rect.y());
124 EXPECT_EQ(8.f, bounding_rect.width());
125 EXPECT_EQ(bounding_rect.width(), bounding_rect.height());
126
127 // Stretched vertically.
128 bounding_rect = BoundingRectForArrow(gfx::Rect(42, 61, 6, 44));
129 EXPECT_EQ(42.f, bounding_rect.x());
130 EXPECT_EQ(80.f, bounding_rect.y());
131 EXPECT_EQ(6.f, bounding_rect.width());
132 EXPECT_EQ(bounding_rect.width(), bounding_rect.height());
133 }
134
135 TEST_F(NativeThemeAuraTest, BoundingRectSnappedToWholePixels) {
136 gfx::Rect bounding_rect = BoundingRectForArrow(gfx::Rect(0, 0, 9, 10));
137 EXPECT_EQ(3.f, bounding_rect.x());
138
139 bounding_rect = BoundingRectForArrow(gfx::Rect(0, 0, 10, 9));
140 EXPECT_EQ(3.f, bounding_rect.y());
141 }
142
73 } // namespace ui 143 } // namespace ui
OLDNEW
« no previous file with comments | « ui/native_theme/BUILD.gn ('k') | ui/native_theme/native_theme_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698