| OLD | NEW |
| 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 Loading... |
| 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 // Given a size, construct a subrectangle using offset, width and height. Negati
ve offsets are relative to the |
| 87 // extent of the given size. |
| 88 static FloatRect subrect(LayoutSize size, float offsetX, float offsetY, float wi
dth, float height) |
| 88 { | 89 { |
| 89 return subrect(IntRect(IntPoint(), size), offsetX, offsetY, width, height); | 90 return subrect(LayoutRect(LayoutPoint(), size), offsetX, offsetY, width, hei
ght); |
| 90 } | 91 } |
| 91 | 92 |
| 92 static inline void setCornerPiece(NinePieceImageGrid::NinePieceDrawInfo& drawInf
o, bool isDrawable, | 93 static inline void setCornerPiece(NinePieceImageGrid::NinePieceDrawInfo& drawInf
o, bool isDrawable, |
| 93 const FloatRect& source, const FloatRect& destination) | 94 const FloatRect& source, const FloatRect& destination) |
| 94 { | 95 { |
| 95 drawInfo.isDrawable = isDrawable; | 96 drawInfo.isDrawable = isDrawable; |
| 96 if (drawInfo.isDrawable) { | 97 if (drawInfo.isDrawable) { |
| 97 drawInfo.source = source; | 98 drawInfo.source = source; |
| 98 drawInfo.destination = destination; | 99 drawInfo.destination = destination; |
| 99 } | 100 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 if (drawInfo.isDrawable) { | 150 if (drawInfo.isDrawable) { |
| 150 drawInfo.source = source; | 151 drawInfo.source = source; |
| 151 drawInfo.destination = destination; | 152 drawInfo.destination = destination; |
| 152 drawInfo.tileScale = FloatSize(edge.scale(), edge.scale()); | 153 drawInfo.tileScale = FloatSize(edge.scale(), edge.scale()); |
| 153 drawInfo.tileRule = { Image::StretchTile, tileRule }; | 154 drawInfo.tileRule = { Image::StretchTile, tileRule }; |
| 154 } | 155 } |
| 155 } | 156 } |
| 156 | 157 |
| 157 void NinePieceImageGrid::setDrawInfoEdge(NinePieceDrawInfo& drawInfo, NinePiece
piece) const | 158 void NinePieceImageGrid::setDrawInfoEdge(NinePieceDrawInfo& drawInfo, NinePiece
piece) const |
| 158 { | 159 { |
| 159 IntSize edgeSourceSize = m_imageSize - IntSize(m_left.slice + m_right.slice,
m_top.slice + m_bottom.slice); | 160 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); | 161 LayoutSize edgeDestinationSize = m_borderImageArea.size() - LayoutSize(m_lef
t.width + m_right.width, m_top.width + m_bottom.width); |
| 161 | 162 |
| 162 switch (piece) { | 163 switch (piece) { |
| 163 case LeftPiece: | 164 case LeftPiece: |
| 164 setVerticalEdge(drawInfo, m_left, | 165 setVerticalEdge(drawInfo, m_left, |
| 165 subrect(m_imageSize, 0, m_top.slice, m_left.slice, edgeSourceSize.he
ight()), | 166 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()), | 167 subrect(m_borderImageArea, 0, m_top.width, m_left.width, edgeDestina
tionSize.height()), |
| 167 m_verticalTileRule); | 168 m_verticalTileRule); |
| 168 break; | 169 break; |
| 169 case RightPiece: | 170 case RightPiece: |
| 170 setVerticalEdge(drawInfo, m_right, | 171 setVerticalEdge(drawInfo, m_right, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 185 m_horizontalTileRule); | 186 m_horizontalTileRule); |
| 186 break; | 187 break; |
| 187 default: | 188 default: |
| 188 ASSERT_NOT_REACHED(); | 189 ASSERT_NOT_REACHED(); |
| 189 break; | 190 break; |
| 190 } | 191 } |
| 191 } | 192 } |
| 192 | 193 |
| 193 void NinePieceImageGrid::setDrawInfoMiddle(NinePieceDrawInfo& drawInfo) const | 194 void NinePieceImageGrid::setDrawInfoMiddle(NinePieceDrawInfo& drawInfo) const |
| 194 { | 195 { |
| 195 IntSize sourceSize = m_imageSize - IntSize(m_left.slice + m_right.slice, m_t
op.slice + m_bottom.slice); | 196 LayoutSize sourceSize = m_imageSize - LayoutSize(m_left.slice + m_right.slic
e, m_top.slice + m_bottom.slice); |
| 196 IntSize destinationSize = | 197 LayoutSize destinationSize = |
| 197 m_borderImageArea.size() - IntSize(m_left.width + m_right.width, m_top.w
idth + m_bottom.width); | 198 m_borderImageArea.size() - LayoutSize(m_left.width + m_right.width, m_to
p.width + m_bottom.width); |
| 198 | 199 |
| 199 drawInfo.isDrawable = m_fill && !sourceSize.isEmpty() && !destinationSize.is
Empty(); | 200 drawInfo.isDrawable = m_fill && !sourceSize.isEmpty() && !destinationSize.is
Empty(); |
| 200 if (!drawInfo.isDrawable) | 201 if (!drawInfo.isDrawable) |
| 201 return; | 202 return; |
| 202 | 203 |
| 203 drawInfo.source = subrect(m_imageSize, m_left.slice, m_top.slice, sourceSize
.width(), sourceSize.height()); | 204 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, | 205 drawInfo.destination = subrect(m_borderImageArea, m_left.width, m_top.width, |
| 205 destinationSize.width(), destinationSize.height()); | 206 destinationSize.width(), destinationSize.height()); |
| 206 | 207 |
| 207 FloatSize middleScaleFactor(1, 1); | 208 FloatSize middleScaleFactor(1, 1); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 setDrawInfoCorner(drawInfo, piece); | 242 setDrawInfoCorner(drawInfo, piece); |
| 242 else if (piece != MiddlePiece) | 243 else if (piece != MiddlePiece) |
| 243 setDrawInfoEdge(drawInfo, piece); | 244 setDrawInfoEdge(drawInfo, piece); |
| 244 else | 245 else |
| 245 setDrawInfoMiddle(drawInfo); | 246 setDrawInfoMiddle(drawInfo); |
| 246 | 247 |
| 247 return drawInfo; | 248 return drawInfo; |
| 248 } | 249 } |
| 249 | 250 |
| 250 } // namespace blink | 251 } // namespace blink |
| OLD | NEW |