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

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

Issue 2392443009: reflow comments in core/paint (Closed)
Patch Set: Created 4 years, 2 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 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 "core/paint/NinePieceImageGrid.h" 5 #include "core/paint/NinePieceImageGrid.h"
6 6
7 #include "core/style/ComputedStyle.h" 7 #include "core/style/ComputedStyle.h"
8 #include "core/style/NinePieceImage.h" 8 #include "core/style/NinePieceImage.h"
9 #include "platform/LengthFunctions.h" 9 #include "platform/LengthFunctions.h"
10 #include "platform/geometry/FloatSize.h" 10 #include "platform/geometry/FloatSize.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 m_right.width = computeEdgeWidth(ninePieceImage.borderSlices().right(), 52 m_right.width = computeEdgeWidth(ninePieceImage.borderSlices().right(),
53 borderWidths.right(), m_right.slice, 53 borderWidths.right(), m_right.slice,
54 borderImageArea.width()); 54 borderImageArea.width());
55 m_bottom.width = computeEdgeWidth(ninePieceImage.borderSlices().bottom(), 55 m_bottom.width = computeEdgeWidth(ninePieceImage.borderSlices().bottom(),
56 borderWidths.bottom(), m_bottom.slice, 56 borderWidths.bottom(), m_bottom.slice,
57 borderImageArea.height()); 57 borderImageArea.height());
58 m_left.width = computeEdgeWidth(ninePieceImage.borderSlices().left(), 58 m_left.width = computeEdgeWidth(ninePieceImage.borderSlices().left(),
59 borderWidths.left(), m_left.slice, 59 borderWidths.left(), m_left.slice,
60 borderImageArea.width()); 60 borderImageArea.width());
61 61
62 // The spec says: Given Lwidth as the width of the border image area, Lheight as its height, and Wside as the border 62 // The spec says: Given Lwidth as the width of the border image area, Lheight
63 // image width offset for the side, let f = min(Lwidth/(Wleft+Wright), Lheight /(Wtop+Wbottom)). If f < 1, then all W 63 // as its height, and Wside as the border image width offset for the side, let
64 // are reduced by multiplying them by f. 64 // f = min(Lwidth/(Wleft+Wright), Lheight/(Wtop+Wbottom)). If f < 1, then all
65 // W are reduced by multiplying them by f.
65 int borderSideWidth = std::max(1, m_left.width + m_right.width); 66 int borderSideWidth = std::max(1, m_left.width + m_right.width);
66 int borderSideHeight = std::max(1, m_top.width + m_bottom.width); 67 int borderSideHeight = std::max(1, m_top.width + m_bottom.width);
67 float borderSideScaleFactor = 68 float borderSideScaleFactor =
68 std::min((float)borderImageArea.width() / borderSideWidth, 69 std::min((float)borderImageArea.width() / borderSideWidth,
69 (float)borderImageArea.height() / borderSideHeight); 70 (float)borderImageArea.height() / borderSideHeight);
70 if (borderSideScaleFactor < 1) { 71 if (borderSideScaleFactor < 1) {
71 m_top.width *= borderSideScaleFactor; 72 m_top.width *= borderSideScaleFactor;
72 m_right.width *= borderSideScaleFactor; 73 m_right.width *= borderSideScaleFactor;
73 m_bottom.width *= borderSideScaleFactor; 74 m_bottom.width *= borderSideScaleFactor;
74 m_left.width *= borderSideScaleFactor; 75 m_left.width *= borderSideScaleFactor;
75 } 76 }
76 } 77 }
77 78
78 // Given a rectangle, construct a subrectangle using offset, width and height. N egative offsets are relative to the 79 // Given a rectangle, construct a subrectangle using offset, width and height.
79 // extent of the given rectangle. 80 // Negative offsets are relative to the extent of the given rectangle.
80 static FloatRect subrect(IntRect rect, 81 static FloatRect subrect(IntRect rect,
81 float offsetX, 82 float offsetX,
82 float offsetY, 83 float offsetY,
83 float width, 84 float width,
84 float height) { 85 float height) {
85 float baseX = rect.x(); 86 float baseX = rect.x();
86 if (offsetX < 0) 87 if (offsetX < 0)
87 baseX = rect.maxX(); 88 baseX = rect.maxX();
88 89
89 float baseY = rect.y(); 90 float baseY = rect.y();
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 middleScaleFactor.setWidth(m_top.scale()); 252 middleScaleFactor.setWidth(m_top.scale());
252 else if (m_bottom.isDrawable()) 253 else if (m_bottom.isDrawable())
253 middleScaleFactor.setWidth(m_bottom.scale()); 254 middleScaleFactor.setWidth(m_bottom.scale());
254 255
255 if (m_left.isDrawable()) 256 if (m_left.isDrawable())
256 middleScaleFactor.setHeight(m_left.scale()); 257 middleScaleFactor.setHeight(m_left.scale());
257 else if (m_right.isDrawable()) 258 else if (m_right.isDrawable())
258 middleScaleFactor.setHeight(m_right.scale()); 259 middleScaleFactor.setHeight(m_right.scale());
259 260
260 if (!sourceSize.isEmpty()) { 261 if (!sourceSize.isEmpty()) {
261 // For "stretch" rules, just override the scale factor and replace. We only have to do this for the center tile, 262 // For "stretch" rules, just override the scale factor and replace. We only
262 // since sides don't even use the scale factor unless they have a rule other than "stretch". The middle however 263 // have to do this for the center tile, since sides don't even use the scale
263 // can have "stretch" specified in one axis but not the other, so we have to correct the scale here. 264 // factor unless they have a rule other than "stretch". The middle however
265 // can have "stretch" specified in one axis but not the other, so we have to
266 // correct the scale here.
264 if (m_horizontalTileRule == (Image::TileRule)StretchImageRule) 267 if (m_horizontalTileRule == (Image::TileRule)StretchImageRule)
265 middleScaleFactor.setWidth((float)destinationSize.width() / 268 middleScaleFactor.setWidth((float)destinationSize.width() /
266 sourceSize.width()); 269 sourceSize.width());
267 270
268 if (m_verticalTileRule == (Image::TileRule)StretchImageRule) 271 if (m_verticalTileRule == (Image::TileRule)StretchImageRule)
269 middleScaleFactor.setHeight((float)destinationSize.height() / 272 middleScaleFactor.setHeight((float)destinationSize.height() /
270 sourceSize.height()); 273 sourceSize.height());
271 } 274 }
272 275
273 drawInfo.tileScale = middleScaleFactor; 276 drawInfo.tileScale = middleScaleFactor;
(...skipping 11 matching lines...) Expand all
285 piece == BottomRightPiece; 288 piece == BottomRightPiece;
286 289
287 if (drawInfo.isCornerPiece) 290 if (drawInfo.isCornerPiece)
288 setDrawInfoCorner(drawInfo, piece); 291 setDrawInfoCorner(drawInfo, piece);
289 else if (piece != MiddlePiece) 292 else if (piece != MiddlePiece)
290 setDrawInfoEdge(drawInfo, piece); 293 setDrawInfoEdge(drawInfo, piece);
291 else 294 else
292 setDrawInfoMiddle(drawInfo); 295 setDrawInfoMiddle(drawInfo);
293 296
294 if (imageScaleFactor != 1) { 297 if (imageScaleFactor != 1) {
295 // The nine piece grid is computed in unscaled image coordinates but must be drawn using 298 // The nine piece grid is computed in unscaled image coordinates but must be
296 // scaled image coordinates. 299 // drawn using scaled image coordinates.
297 drawInfo.source.scale(imageScaleFactor); 300 drawInfo.source.scale(imageScaleFactor);
298 301
299 // Compensate for source scaling by scaling down the individual tiles. 302 // Compensate for source scaling by scaling down the individual tiles.
300 drawInfo.tileScale.scale(1 / imageScaleFactor); 303 drawInfo.tileScale.scale(1 / imageScaleFactor);
301 } 304 }
302 305
303 return drawInfo; 306 return drawInfo;
304 } 307 }
305 308
306 } // namespace blink 309 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698