OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef NinePieceImageGrid_h |
| 6 #define NinePieceImageGrid_h |
| 7 |
| 8 #include "platform/geometry/FloatRect.h" |
| 9 #include "platform/geometry/FloatSize.h" |
| 10 #include "platform/geometry/IntRect.h" |
| 11 #include "platform/geometry/IntSize.h" |
| 12 #include "platform/graphics/Image.h" |
| 13 #include "platform/heap/Heap.h" |
| 14 |
| 15 namespace blink { |
| 16 |
| 17 class IntRectOutsets; |
| 18 class NinePieceImage; |
| 19 |
| 20 enum NinePiece { |
| 21 MinPiece = 0, |
| 22 TopLeftPiece = MinPiece, |
| 23 BottomLeftPiece, |
| 24 LeftPiece, |
| 25 TopRightPiece, |
| 26 BottomRightPiece, |
| 27 RightPiece, |
| 28 TopPiece, |
| 29 BottomPiece, |
| 30 MiddlePiece, |
| 31 MaxPiece |
| 32 }; |
| 33 |
| 34 inline NinePiece& operator++(NinePiece& piece) |
| 35 { |
| 36 piece = static_cast<NinePiece>(static_cast<int>(piece) + 1); |
| 37 return piece; |
| 38 } |
| 39 |
| 40 // The NinePieceImageGrid class is responsible for computing drawing information
for the nine piece image. |
| 41 // |
| 42 // http://dev.w3.org/csswg/css-backgrounds-3/#border-image-process |
| 43 // |
| 44 // Given an image, a set of slices and a border area: |
| 45 // |
| 46 // | | |
| 47 // +---+---------+---+ +------------------+ |
| 48 // | 1 | 7 | 4 | | border | |
| 49 // --+---+---------+---+--- | +------------+ | |
| 50 // | | | | | | | | |
| 51 // | 3 | 9 | 6 | | | css | | |
| 52 // | | image | | | | box | | |
| 53 // | | | | | | | | |
| 54 // --+---+---------+---+--- | | | | |
| 55 // | 2 | 8 | 5 | | +------------+ | |
| 56 // +---+---------+---+ | | |
| 57 // | | +------------------+ |
| 58 // |
| 59 // it generates drawing information for the nine border pieces. |
| 60 class NinePieceImageGrid { |
| 61 STACK_ALLOCATED(); |
| 62 |
| 63 public: |
| 64 NinePieceImageGrid(const NinePieceImage&, IntSize imageSize, IntRect borderI
mageArea, |
| 65 const IntRectOutsets& borderWidths); |
| 66 |
| 67 struct NinePieceDrawInfo { |
| 68 bool isDrawable; |
| 69 bool isCornerPiece; |
| 70 FloatRect destination; |
| 71 FloatRect source; |
| 72 |
| 73 // tileScale and tileRule are only useful for non-corners, i.e. edge and
center pieces. |
| 74 FloatSize tileScale; |
| 75 struct { |
| 76 Image::TileRule horizontal; |
| 77 Image::TileRule vertical; |
| 78 } tileRule; |
| 79 }; |
| 80 NinePieceDrawInfo getNinePieceDrawInfo(NinePiece) const; |
| 81 |
| 82 struct Edge { |
| 83 bool isDrawable() const { return slice > 0 && width > 0; } |
| 84 float scale() const { return isDrawable() ? (float)width / slice : 1; } |
| 85 int slice; |
| 86 int width; |
| 87 }; |
| 88 |
| 89 private: |
| 90 void setDrawInfoCorner(NinePieceDrawInfo&, NinePiece) const; |
| 91 void setDrawInfoEdge(NinePieceDrawInfo&, NinePiece) const; |
| 92 void setDrawInfoMiddle(NinePieceDrawInfo&) const; |
| 93 |
| 94 IntRect m_borderImageArea; |
| 95 IntSize m_imageSize; |
| 96 Image::TileRule m_horizontalTileRule; |
| 97 Image::TileRule m_verticalTileRule; |
| 98 bool m_fill; |
| 99 |
| 100 Edge m_top; |
| 101 Edge m_right; |
| 102 Edge m_bottom; |
| 103 Edge m_left; |
| 104 }; |
| 105 |
| 106 } // namespace blink |
| 107 |
| 108 #endif // NinePieceImageGrid_h |
OLD | NEW |