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