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

Unified Diff: Source/core/paint/NinePieceImageGrid.h

Issue 1180053009: Rewrite nine piece image painting code (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Some more polish Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/paint/NinePieceImageGrid.h
diff --git a/Source/core/paint/NinePieceImageGrid.h b/Source/core/paint/NinePieceImageGrid.h
new file mode 100644
index 0000000000000000000000000000000000000000..c8177d81ea18fa5823360c46778e0b1b7a234f0e
--- /dev/null
+++ b/Source/core/paint/NinePieceImageGrid.h
@@ -0,0 +1,110 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NinePieceImageGrid_h
+#define NinePieceImageGrid_h
+
+#include "platform/geometry/FloatRect.h"
+#include "platform/graphics/Image.h"
+#include "platform/heap/Heap.h"
+
+namespace blink {
+
+class BorderImageLength;
+class ComputedStyle;
+class FloatSize;
+class IntRect;
+class IntRectOutsets;
+class IntSize;
fs 2015/06/24 13:19:10 FloatSize, IntRect and IntSize are used in class d
davve 2015/06/24 13:35:26 Done. Removed some unused ones as well.
+class NinePieceImage;
+
+enum NinePiece {
+ MinPiece = 0,
+ TopLeftPiece = MinPiece,
+ BottomLeftPiece,
+ LeftPiece,
+ TopRightPiece,
+ BottomRightPiece,
+ RightPiece,
+ TopPiece,
+ BottomPiece,
+ MiddlePiece,
+ MaxPiece
+};
+
+inline NinePiece& operator++(NinePiece& piece)
+{
+ piece = static_cast<NinePiece>(static_cast<int>(piece) + 1);
+ return piece;
+}
+
+// The NinePieceImageGrid class is responsible for computing drawing information for the nine piece image.
+//
+// http://dev.w3.org/csswg/css-backgrounds-3/#border-image-process
+//
+// Given an image, a set of slices and a border area:
+//
+// | |
+// +---+---------+---+ +------------------+
+// | 1 | 7 | 4 | | border |
+// --+---+---------+---+--- | +------------+ |
+// | | | | | | | |
+// | 3 | 9 | 6 | | | css | |
+// | | image | | | | box | |
+// | | | | | | | |
+// --+---+---------+---+--- | | | |
+// | 2 | 8 | 5 | | +------------+ |
+// +---+---------+---+ | |
+// | | +------------------+
+//
+// it generates drawing information for the nine border pieces.
+class NinePieceImageGrid {
+ STACK_ALLOCATED();
+
+public:
+ NinePieceImageGrid(const NinePieceImage&, IntSize imageSize, IntRect borderImageArea,
+ const IntRectOutsets& borderWidths);
+
+ struct NinePieceDrawInfo {
+ bool isDrawable;
+ bool isCornerPiece;
+ FloatRect destination;
+ FloatRect source;
+
+ // tileScale and tileRule are only useful for non-corners, i.e. edge and center pieces.
+ FloatSize tileScale;
+ struct {
+ Image::TileRule horizontal;
+ Image::TileRule vertical;
+ } tileRule;
+ };
+ NinePieceDrawInfo getNinePieceDrawInfo(NinePiece) const;
+
+ struct Edge {
+ bool draw() const { return slice > 0 && width > 0; }
fs 2015/06/24 13:19:10 isDrawable? (or any for of query sounding name)
davve 2015/06/24 13:35:25 Yep, that's better.
+ float scale() const { return draw() ? (float)width / slice : 1; }
+ int slice;
+ int width;
+ };
+
+private:
+ void setDrawInfoCorner(NinePieceDrawInfo&, NinePiece) const;
+ void setDrawInfoEdge(NinePieceDrawInfo&, NinePiece) const;
+ void setDrawInfoMiddle(NinePieceDrawInfo&) const;
+
+ IntRect m_borderImageArea;
+ IntSize m_imageSize;
+ Image::TileRule m_horizontalTileRule;
+ Image::TileRule m_verticalTileRule;
+ bool m_fill;
+
+ Edge m_top;
+ Edge m_right;
+ Edge m_bottom;
+ Edge m_left;
+};
+
+} // namespace blink
+
+#endif // NinePieceImageGrid_h

Powered by Google App Engine
This is Rietveld 408576698