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

Side by Side Diff: Source/core/paint/BoxDecorationData.cpp

Issue 1088613002: CTM-independent BackgroundBleedBackgroundOverBorder implementation (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: review comments Created 5 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/paint/BoxDecorationData.h ('k') | Source/core/paint/BoxPainter.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 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 "config.h" 5 #include "config.h"
6 #include "core/paint/BoxDecorationData.h" 6 #include "core/paint/BoxDecorationData.h"
7 7
8 #include "core/layout/LayoutBox.h" 8 #include "core/layout/LayoutBox.h"
9 #include "core/style/BorderEdge.h" 9 #include "core/style/BorderEdge.h"
10 #include "core/style/ComputedStyle.h" 10 #include "core/style/ComputedStyle.h"
11 #include "platform/RuntimeEnabledFeatures.h" 11 #include "platform/RuntimeEnabledFeatures.h"
12 #include "platform/graphics/GraphicsContext.h" 12 #include "platform/graphics/GraphicsContext.h"
13 13
14 namespace blink { 14 namespace blink {
15 15
16 BoxDecorationData::BoxDecorationData(const LayoutBox& layoutBox, GraphicsContext * context) 16 BoxDecorationData::BoxDecorationData(const LayoutBox& layoutBox, GraphicsContext * context)
17 { 17 {
18 backgroundColor = layoutBox.style()->visitedDependentColor(CSSPropertyBackgr oundColor); 18 backgroundColor = layoutBox.style()->visitedDependentColor(CSSPropertyBackgr oundColor);
19 hasBackground = backgroundColor.alpha() || layoutBox.style()->hasBackgroundI mage(); 19 hasBackground = backgroundColor.alpha() || layoutBox.style()->hasBackgroundI mage();
20 ASSERT(hasBackground == layoutBox.style()->hasBackground()); 20 ASSERT(hasBackground == layoutBox.style()->hasBackground());
21 hasBorder = layoutBox.style()->hasBorder(); 21 hasBorder = layoutBox.style()->hasBorder();
22 hasAppearance = layoutBox.style()->hasAppearance(); 22 hasAppearance = layoutBox.style()->hasAppearance();
23 23
24 m_bleedAvoidance = determineBackgroundBleedAvoidance(layoutBox, context); 24 m_bleedAvoidance = determineBackgroundBleedAvoidance(layoutBox, context);
25 } 25 }
26 26
27 BackgroundBleedAvoidance BoxDecorationData::determineBackgroundBleedAvoidance(co nst LayoutBox& layoutBox, GraphicsContext* context) 27 namespace {
28
29 bool borderObscuresBackgroundEdge(const GraphicsContext& context, const Computed Style& style)
28 { 30 {
29 if (layoutBox.isDocumentElement())
30 return BackgroundBleedNone;
31
32 if (!hasBackground)
33 return BackgroundBleedNone;
34
35 if (!hasBorder || !layoutBox.style()->hasBorderRadius() || layoutBox.canRend erBorderImage()) {
36 if (layoutBox.backgroundShouldAlwaysBeClipped())
37 return BackgroundBleedClipBackground;
38 return BackgroundBleedNone;
39 }
40
41 // If display lists are enabled (via Slimming Paint), then simply clip the b ackground and do not
42 // perform advanced bleed-avoidance heuristics. These heuristics are not cor rect in the presence
43 // of impl-side rasterization or layerization, since the actual pixel-relati ve scaling and rotation
44 // of the content is not known to Blink.
45 if (RuntimeEnabledFeatures::slimmingPaintEnabled())
46 return BackgroundBleedClipBackground;
47
48 // FIXME: See crbug.com/382491. getCTM does not accurately reflect the scale at the time content is 31 // FIXME: See crbug.com/382491. getCTM does not accurately reflect the scale at the time content is
49 // rasterized, and should not be relied on to make decisions about bleeding. 32 // rasterized, and should not be relied on to make decisions about bleeding.
50 AffineTransform ctm = context->getCTM(); 33 AffineTransform ctm = context.getCTM();
51 FloatSize contextScaling(static_cast<float>(ctm.xScale()), static_cast<float >(ctm.yScale())); 34 FloatSize contextScale(static_cast<float>(ctm.xScale()), static_cast<float>( ctm.yScale()));
52 35
53 // Because RoundedRect uses IntRect internally the inset applied by the 36 // Because RoundedRect uses IntRect internally the inset applied by the
54 // BackgroundBleedShrinkBackground strategy cannot be less than one integer 37 // BackgroundBleedShrinkBackground strategy cannot be less than one integer
55 // layout coordinate, even with subpixel layout enabled. To take that into 38 // layout coordinate, even with subpixel layout enabled. To take that into
56 // account, we clamp the contextScaling to 1.0 for the following test so 39 // account, we clamp the contextScaling to 1.0 for the following test so
57 // that borderObscuresBackgroundEdge can only return true if the border 40 // that borderObscuresBackgroundEdge can only return true if the border
58 // widths are greater than 2 in both layout coordinates and screen 41 // widths are greater than 2 in both layout coordinates and screen
59 // coordinates. 42 // coordinates.
60 // This precaution will become obsolete if RoundedRect is ever promoted to 43 // This precaution will become obsolete if RoundedRect is ever promoted to
61 // a sub-pixel representation. 44 // a sub-pixel representation.
62 if (contextScaling.width() > 1) 45 if (contextScale.width() > 1)
63 contextScaling.setWidth(1); 46 contextScale.setWidth(1);
64 if (contextScaling.height() > 1) 47 if (contextScale.height() > 1)
65 contextScaling.setHeight(1); 48 contextScale.setHeight(1);
66 49
67 if (borderObscuresBackgroundEdge(*layoutBox.style(), contextScaling))
68 return BackgroundBleedShrinkBackground;
69 if (!hasAppearance && layoutBox.style()->borderObscuresBackground() && layou tBox.backgroundHasOpaqueTopLayer())
70 return BackgroundBleedBackgroundOverBorder;
71
72 return BackgroundBleedClipBackground;
73 }
74
75 bool BoxDecorationData::borderObscuresBackgroundEdge(const ComputedStyle& style, const FloatSize& contextScale) const
76 {
77 BorderEdge edges[4]; 50 BorderEdge edges[4];
78 style.getBorderEdgeInfo(edges); 51 style.getBorderEdgeInfo(edges);
79 52
80 for (int i = BSTop; i <= BSLeft; ++i) { 53 for (int i = BSTop; i <= BSLeft; ++i) {
81 const BorderEdge& currEdge = edges[i]; 54 const BorderEdge& currEdge = edges[i];
82 // FIXME: for vertical text 55 // FIXME: for vertical text
83 float axisScale = (i == BSTop || i == BSBottom) ? contextScale.height() : contextScale.width(); 56 float axisScale = (i == BSTop || i == BSBottom) ? contextScale.height() : contextScale.width();
84 if (!currEdge.obscuresBackgroundEdge(axisScale)) 57 if (!currEdge.obscuresBackgroundEdge(axisScale))
85 return false; 58 return false;
86 } 59 }
87 60
88 return true; 61 return true;
89 } 62 }
90 63
64 } // anonymous namespace
65
66 BackgroundBleedAvoidance BoxDecorationData::determineBackgroundBleedAvoidance(co nst LayoutBox& layoutBox, GraphicsContext* context)
67 {
68 if (layoutBox.isDocumentElement())
69 return BackgroundBleedNone;
70
71 if (!hasBackground)
72 return BackgroundBleedNone;
73
74 if (!hasBorder || !layoutBox.style()->hasBorderRadius() || layoutBox.canRend erBorderImage()) {
75 if (layoutBox.backgroundShouldAlwaysBeClipped())
76 return BackgroundBleedClipBackground;
77 return BackgroundBleedNone;
78 }
79
80 // If display lists are enabled (via Slimming Paint), then BackgroundBleedSh rinkBackground is not
81 // usable as is relies on device-space heuristics. These heuristics are not correct in the presence
82 // of impl-side rasterization or layerization, since the actual pixel-relati ve scaling and rotation
83 // of the content is not known to Blink.
84 if (!RuntimeEnabledFeatures::slimmingPaintEnabled() && borderObscuresBackgro undEdge(*context, *layoutBox.style()))
85 return BackgroundBleedShrinkBackground;
86
87 if (!hasAppearance && layoutBox.style()->borderObscuresBackground() && layou tBox.backgroundHasOpaqueTopLayer())
88 return BackgroundBleedBackgroundOverBorder;
89
90 return BackgroundBleedClipBackground;
91 }
92
91 } // namespace blink 93 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/paint/BoxDecorationData.h ('k') | Source/core/paint/BoxPainter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698