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

Side by Side Diff: third_party/WebKit/Source/core/paint/NinePieceImageGrid.cpp

Issue 1477393003: Use LayoutUnit in NinePieceImage drawing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase on top of leviw's sub-pixel changes Created 5 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/NinePieceImageGrid.h" 6 #include "core/paint/NinePieceImageGrid.h"
7 7
8 #include "core/style/ComputedStyle.h" 8 #include "core/style/ComputedStyle.h"
9 #include "core/style/NinePieceImage.h" 9 #include "core/style/NinePieceImage.h"
10 #include "platform/LengthFunctions.h" 10 #include "platform/LengthFunctions.h"
11 #include "platform/geometry/FloatSize.h" 11 #include "platform/geometry/FloatSize.h"
12 #include "platform/geometry/IntSize.h"
13 12
14 namespace blink { 13 namespace blink {
15 14
16 static LayoutUnit computeEdgeWidth(const BorderImageLength& borderSlice, int bor derSide, const LayoutUnit& imageSide, 15 static LayoutUnit computeEdgeWidth(const BorderImageLength& borderSlice, int bor derSide, const LayoutUnit& imageSide,
17 const LayoutUnit& boxExtent) 16 const LayoutUnit& boxExtent)
18 { 17 {
19 if (borderSlice.isNumber()) 18 if (borderSlice.isNumber())
20 return borderSlice.number() * borderSide; 19 return borderSlice.number() * borderSide;
21 if (borderSlice.length().isAuto()) 20 if (borderSlice.length().isAuto())
22 return imageSide; 21 return imageSide;
23 return valueForLength(borderSlice.length(), boxExtent); 22 return valueForLength(borderSlice.length(), boxExtent);
24 } 23 }
25 24
26 static int computeEdgeSlice(const Length& slice, LayoutUnit maximum) 25 static int computeEdgeSlice(const Length& slice, LayoutUnit maximum)
27 { 26 {
28 return std::min<int>(maximum, valueForLength(slice, maximum)); 27 return std::min<int>(maximum, valueForLength(slice, maximum));
29 } 28 }
30 29
31 NinePieceImageGrid::NinePieceImageGrid(const NinePieceImage& ninePieceImage, Int Size imageSize, IntRect borderImageArea, 30 NinePieceImageGrid::NinePieceImageGrid(const NinePieceImage& ninePieceImage, Lay outSize imageSize, LayoutRect borderImageArea,
32 const IntRectOutsets& borderWidths) 31 const IntRectOutsets& borderWidths)
33 : m_borderImageArea(borderImageArea) 32 : m_borderImageArea(borderImageArea)
34 , m_imageSize(imageSize) 33 , m_imageSize(imageSize)
35 , m_horizontalTileRule((Image::TileRule)ninePieceImage.horizontalRule()) 34 , m_horizontalTileRule((Image::TileRule)ninePieceImage.horizontalRule())
36 , m_verticalTileRule((Image::TileRule)ninePieceImage.verticalRule()) 35 , m_verticalTileRule((Image::TileRule)ninePieceImage.verticalRule())
37 , m_fill(ninePieceImage.fill()) 36 , m_fill(ninePieceImage.fill())
38 { 37 {
39 StyleImage* styleImage = ninePieceImage.image(); 38 StyleImage* styleImage = ninePieceImage.image();
40 ASSERT(styleImage); 39 ASSERT(styleImage);
41 40
(...skipping 22 matching lines...) Expand all
64 if (borderSideScaleFactor < 1) { 63 if (borderSideScaleFactor < 1) {
65 m_top.width *= borderSideScaleFactor; 64 m_top.width *= borderSideScaleFactor;
66 m_right.width *= borderSideScaleFactor; 65 m_right.width *= borderSideScaleFactor;
67 m_bottom.width *= borderSideScaleFactor; 66 m_bottom.width *= borderSideScaleFactor;
68 m_left.width *= borderSideScaleFactor; 67 m_left.width *= borderSideScaleFactor;
69 } 68 }
70 } 69 }
71 70
72 // Given a rectangle, construct a subrectangle using offset, width and height. N egative offsets are relative to the 71 // Given a rectangle, construct a subrectangle using offset, width and height. N egative offsets are relative to the
73 // extent of the given rectangle. 72 // extent of the given rectangle.
74 static FloatRect subrect(IntRect rect, float offsetX, float offsetY, float width , float height) 73 static FloatRect subrect(LayoutRect rect, float offsetX, float offsetY, float wi dth, float height)
75 { 74 {
76 float baseX = rect.x(); 75 float baseX = rect.x();
77 if (offsetX < 0) 76 if (offsetX < 0)
78 baseX = rect.maxX(); 77 baseX = rect.maxX();
79 78
80 float baseY = rect.y(); 79 float baseY = rect.y();
81 if (offsetY < 0) 80 if (offsetY < 0)
82 baseY = rect.maxY(); 81 baseY = rect.maxY();
83 82
84 return FloatRect(baseX + offsetX, baseY + offsetY, width, height); 83 return FloatRect(baseX + offsetX, baseY + offsetY, width, height);
85 } 84 }
86 85
87 static FloatRect subrect(IntSize size, float offsetX, float offsetY, float width , float height) 86 static FloatRect subrect(LayoutSize size, float offsetX, float offsetY, float wi dth, float height)
88 { 87 {
89 return subrect(IntRect(IntPoint(), size), offsetX, offsetY, width, height); 88 return subrect(LayoutRect(LayoutPoint(), size), offsetX, offsetY, width, hei ght);
90 } 89 }
91 90
92 static inline void setCornerPiece(NinePieceImageGrid::NinePieceDrawInfo& drawInf o, bool isDrawable, 91 static inline void setCornerPiece(NinePieceImageGrid::NinePieceDrawInfo& drawInf o, bool isDrawable,
93 const FloatRect& source, const FloatRect& destination) 92 const FloatRect& source, const FloatRect& destination)
94 { 93 {
95 drawInfo.isDrawable = isDrawable; 94 drawInfo.isDrawable = isDrawable;
96 if (drawInfo.isDrawable) { 95 if (drawInfo.isDrawable) {
97 drawInfo.source = source; 96 drawInfo.source = source;
98 drawInfo.destination = destination; 97 drawInfo.destination = destination;
99 } 98 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 if (drawInfo.isDrawable) { 148 if (drawInfo.isDrawable) {
150 drawInfo.source = source; 149 drawInfo.source = source;
151 drawInfo.destination = destination; 150 drawInfo.destination = destination;
152 drawInfo.tileScale = FloatSize(edge.scale(), edge.scale()); 151 drawInfo.tileScale = FloatSize(edge.scale(), edge.scale());
153 drawInfo.tileRule = { Image::StretchTile, tileRule }; 152 drawInfo.tileRule = { Image::StretchTile, tileRule };
154 } 153 }
155 } 154 }
156 155
157 void NinePieceImageGrid::setDrawInfoEdge(NinePieceDrawInfo& drawInfo, NinePiece piece) const 156 void NinePieceImageGrid::setDrawInfoEdge(NinePieceDrawInfo& drawInfo, NinePiece piece) const
158 { 157 {
159 IntSize edgeSourceSize = m_imageSize - IntSize(m_left.slice + m_right.slice, m_top.slice + m_bottom.slice); 158 LayoutSize edgeSourceSize = m_imageSize - LayoutSize(m_left.slice + m_right. slice, m_top.slice + m_bottom.slice);
160 IntSize edgeDestinationSize = m_borderImageArea.size() - IntSize(m_left.widt h + m_right.width, m_top.width + m_bottom.width); 159 LayoutSize edgeDestinationSize = m_borderImageArea.size() - LayoutSize(m_lef t.width + m_right.width, m_top.width + m_bottom.width);
161 160
162 switch (piece) { 161 switch (piece) {
163 case LeftPiece: 162 case LeftPiece:
164 setVerticalEdge(drawInfo, m_left, 163 setVerticalEdge(drawInfo, m_left,
165 subrect(m_imageSize, 0, m_top.slice, m_left.slice, edgeSourceSize.he ight()), 164 subrect(m_imageSize, 0, m_top.slice, m_left.slice, edgeSourceSize.he ight()),
166 subrect(m_borderImageArea, 0, m_top.width, m_left.width, edgeDestina tionSize.height()), 165 subrect(m_borderImageArea, 0, m_top.width, m_left.width, edgeDestina tionSize.height()),
167 m_verticalTileRule); 166 m_verticalTileRule);
168 break; 167 break;
169 case RightPiece: 168 case RightPiece:
170 setVerticalEdge(drawInfo, m_right, 169 setVerticalEdge(drawInfo, m_right,
(...skipping 14 matching lines...) Expand all
185 m_horizontalTileRule); 184 m_horizontalTileRule);
186 break; 185 break;
187 default: 186 default:
188 ASSERT_NOT_REACHED(); 187 ASSERT_NOT_REACHED();
189 break; 188 break;
190 } 189 }
191 } 190 }
192 191
193 void NinePieceImageGrid::setDrawInfoMiddle(NinePieceDrawInfo& drawInfo) const 192 void NinePieceImageGrid::setDrawInfoMiddle(NinePieceDrawInfo& drawInfo) const
194 { 193 {
195 IntSize sourceSize = m_imageSize - IntSize(m_left.slice + m_right.slice, m_t op.slice + m_bottom.slice); 194 LayoutSize sourceSize = m_imageSize - LayoutSize(m_left.slice + m_right.slic e, m_top.slice + m_bottom.slice);
196 IntSize destinationSize = 195 LayoutSize destinationSize =
197 m_borderImageArea.size() - IntSize(m_left.width + m_right.width, m_top.w idth + m_bottom.width); 196 m_borderImageArea.size() - LayoutSize(m_left.width + m_right.width, m_to p.width + m_bottom.width);
198 197
199 drawInfo.isDrawable = m_fill && !sourceSize.isEmpty() && !destinationSize.is Empty(); 198 drawInfo.isDrawable = m_fill && !sourceSize.isEmpty() && !destinationSize.is Empty();
200 if (!drawInfo.isDrawable) 199 if (!drawInfo.isDrawable)
201 return; 200 return;
202 201
203 drawInfo.source = subrect(m_imageSize, m_left.slice, m_top.slice, sourceSize .width(), sourceSize.height()); 202 drawInfo.source = subrect(m_imageSize, m_left.slice, m_top.slice, sourceSize .width(), sourceSize.height());
204 drawInfo.destination = subrect(m_borderImageArea, m_left.width, m_top.width, 203 drawInfo.destination = subrect(m_borderImageArea, m_left.width, m_top.width,
205 destinationSize.width(), destinationSize.height()); 204 destinationSize.width(), destinationSize.height());
206 205
207 FloatSize middleScaleFactor(1, 1); 206 FloatSize middleScaleFactor(1, 1);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 setDrawInfoCorner(drawInfo, piece); 240 setDrawInfoCorner(drawInfo, piece);
242 else if (piece != MiddlePiece) 241 else if (piece != MiddlePiece)
243 setDrawInfoEdge(drawInfo, piece); 242 setDrawInfoEdge(drawInfo, piece);
244 else 243 else
245 setDrawInfoMiddle(drawInfo); 244 setDrawInfoMiddle(drawInfo);
246 245
247 return drawInfo; 246 return drawInfo;
248 } 247 }
249 248
250 } // namespace blink 249 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698