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

Side by Side Diff: third_party/WebKit/Source/core/style/BorderEdge.cpp

Issue 2640143005: Support subpixel layout for borders. (Closed)
Patch Set: Rebased patch set. Created 3 years, 10 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
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 "core/style/BorderEdge.h" 5 #include "core/style/BorderEdge.h"
6 6
7 namespace blink { 7 namespace blink {
8 8
9 BorderEdge::BorderEdge(int edgeWidth, 9 BorderEdge::BorderEdge(float edgeWidth,
10 const Color& edgeColor, 10 const Color& edgeColor,
11 EBorderStyle edgeStyle, 11 EBorderStyle edgeStyle,
12 bool edgeIsPresent) 12 bool edgeIsPresent)
13 : width(edgeWidth), 13 : color(edgeColor),
14 color(edgeColor),
15 isPresent(edgeIsPresent), 14 isPresent(edgeIsPresent),
16 style(edgeStyle) { 15 style(edgeStyle),
16 m_width(edgeWidth) {
pdr. 2017/01/27 20:28:44 Can width be negative? If not, can you DCHECK that
Karl Øygard 2017/02/10 12:53:18 Done.
17 if (style == BorderStyleDouble && edgeWidth < 3) 17 if (style == BorderStyleDouble && edgeWidth < 3)
18 style = BorderStyleSolid; 18 style = BorderStyleSolid;
19 } 19 }
20 20
21 BorderEdge::BorderEdge() 21 BorderEdge::BorderEdge() : isPresent(false), style(BorderStyleHidden) {}
22 : width(0), isPresent(false), style(BorderStyleHidden) {}
23 22
24 bool BorderEdge::hasVisibleColorAndStyle() const { 23 bool BorderEdge::hasVisibleColorAndStyle() const {
25 return style > BorderStyleHidden && color.alpha() > 0; 24 return style > BorderStyleHidden && color.alpha() > 0;
26 } 25 }
27 26
28 bool BorderEdge::shouldRender() const { 27 bool BorderEdge::shouldRender() const {
29 return isPresent && width && hasVisibleColorAndStyle(); 28 return isPresent && m_width && hasVisibleColorAndStyle();
30 } 29 }
31 30
32 bool BorderEdge::presentButInvisible() const { 31 bool BorderEdge::presentButInvisible() const {
33 return usedWidth() && !hasVisibleColorAndStyle(); 32 return usedWidth() && !hasVisibleColorAndStyle();
34 } 33 }
35 34
36 bool BorderEdge::obscuresBackgroundEdge() const { 35 bool BorderEdge::obscuresBackgroundEdge() const {
37 if (!isPresent || color.hasAlpha() || style == BorderStyleHidden) 36 if (!isPresent || color.hasAlpha() || style == BorderStyleHidden)
38 return false; 37 return false;
39 38
40 if (style == BorderStyleDotted || style == BorderStyleDashed) 39 if (style == BorderStyleDotted || style == BorderStyleDashed)
41 return false; 40 return false;
42 41
43 return true; 42 return true;
44 } 43 }
45 44
46 bool BorderEdge::obscuresBackground() const { 45 bool BorderEdge::obscuresBackground() const {
47 if (!isPresent || color.hasAlpha() || style == BorderStyleHidden) 46 if (!isPresent || color.hasAlpha() || style == BorderStyleHidden)
48 return false; 47 return false;
49 48
50 if (style == BorderStyleDotted || style == BorderStyleDashed || 49 if (style == BorderStyleDotted || style == BorderStyleDashed ||
51 style == BorderStyleDouble) 50 style == BorderStyleDouble)
52 return false; 51 return false;
53 52
54 return true; 53 return true;
55 } 54 }
56 55
57 int BorderEdge::usedWidth() const { 56 float BorderEdge::usedWidth() const {
58 return isPresent ? width : 0; 57 return isPresent ? m_width : 0;
59 } 58 }
60 59
61 int BorderEdge::getDoubleBorderStripeWidth(DoubleBorderStripe stripe) const { 60 float BorderEdge::getDoubleBorderStripeWidth(DoubleBorderStripe stripe) const {
62 ASSERT(stripe == DoubleBorderStripeOuter || 61 ASSERT(stripe == DoubleBorderStripeOuter ||
63 stripe == DoubleBorderStripeInner); 62 stripe == DoubleBorderStripeInner);
64 63
65 // We need certain integer rounding results. 64 return roundf(stripe == DoubleBorderStripeOuter ? usedWidth() / 3
66 return stripe == DoubleBorderStripeOuter ? (usedWidth() + 1) / 3 65 : (usedWidth() * 2) / 3);
67 : (usedWidth() * 2 + 1) / 3;
68 } 66 }
69 67
70 bool BorderEdge::sharesColorWith(const BorderEdge& other) const { 68 bool BorderEdge::sharesColorWith(const BorderEdge& other) const {
71 return color == other.color; 69 return color == other.color;
72 } 70 }
73 71
74 } // namespace blink 72 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698