OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * (C) 2007 David Smith (catfish.man@gmail.com) |
| 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc.
All rights reserved. |
| 6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
| 7 * |
| 8 * This library is free software; you can redistribute it and/or |
| 9 * modify it under the terms of the GNU Library General Public |
| 10 * License as published by the Free Software Foundation; either |
| 11 * version 2 of the License, or (at your option) any later version. |
| 12 * |
| 13 * This library is distributed in the hope that it will be useful, |
| 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 * Library General Public License for more details. |
| 17 * |
| 18 * You should have received a copy of the GNU Library General Public License |
| 19 * along with this library; see the file COPYING.LIB. If not, write to |
| 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 21 * Boston, MA 02110-1301, USA. |
| 22 */ |
| 23 |
| 24 #ifndef FloatingObjects_h |
| 25 #define FloatingObjects_h |
| 26 |
| 27 #include "core/platform/PODFreeListArena.h" |
| 28 #include "core/platform/PODIntervalTree.h" |
| 29 #include "core/rendering/RootInlineBox.h" |
| 30 #include "wtf/ListHashSet.h" |
| 31 |
| 32 namespace WebCore { |
| 33 |
| 34 class RenderBlock; |
| 35 class RenderBox; |
| 36 |
| 37 enum ShapeOutsideFloatOffsetMode { ShapeOutsideFloatShapeOffset, ShapeOutsideFlo
atMarginBoxOffset }; |
| 38 |
| 39 class FloatingObject { |
| 40 WTF_MAKE_NONCOPYABLE(FloatingObject); WTF_MAKE_FAST_ALLOCATED; |
| 41 public: |
| 42 #ifndef NDEBUG |
| 43 // Used by the PODIntervalTree for debugging the FloatingObject. |
| 44 template <class> friend struct ValueToString; |
| 45 #endif |
| 46 |
| 47 // Note that Type uses bits so you can use FloatLeftRight as a mask to query
for both left and right. |
| 48 enum Type { FloatLeft = 1, FloatRight = 2, FloatLeftRight = 3 }; |
| 49 |
| 50 FloatingObject(EFloat type) |
| 51 : m_renderer(0) |
| 52 , m_originatingLine(0) |
| 53 , m_paginationStrut(0) |
| 54 , m_shouldPaint(true) |
| 55 , m_isDescendant(false) |
| 56 , m_isPlaced(false) |
| 57 #ifndef NDEBUG |
| 58 , m_isInPlacedTree(false) |
| 59 #endif |
| 60 { |
| 61 ASSERT(type != NoFloat); |
| 62 if (type == LeftFloat) |
| 63 m_type = FloatLeft; |
| 64 else if (type == RightFloat) |
| 65 m_type = FloatRight; |
| 66 } |
| 67 |
| 68 FloatingObject(Type type, const LayoutRect& frameRect) |
| 69 : m_renderer(0) |
| 70 , m_originatingLine(0) |
| 71 , m_frameRect(frameRect) |
| 72 , m_paginationStrut(0) |
| 73 , m_type(type) |
| 74 , m_shouldPaint(true) |
| 75 , m_isDescendant(false) |
| 76 , m_isPlaced(true) |
| 77 #ifndef NDEBUG |
| 78 , m_isInPlacedTree(false) |
| 79 #endif |
| 80 { |
| 81 } |
| 82 |
| 83 FloatingObject* clone() const |
| 84 { |
| 85 FloatingObject* cloneObject = new FloatingObject(type(), m_frameRect); |
| 86 cloneObject->m_renderer = m_renderer; |
| 87 cloneObject->m_originatingLine = m_originatingLine; |
| 88 cloneObject->m_paginationStrut = m_paginationStrut; |
| 89 cloneObject->m_shouldPaint = m_shouldPaint; |
| 90 cloneObject->m_isDescendant = m_isDescendant; |
| 91 cloneObject->m_isPlaced = m_isPlaced; |
| 92 return cloneObject; |
| 93 } |
| 94 |
| 95 Type type() const { return static_cast<Type>(m_type); } |
| 96 RenderBox* renderer() const { return m_renderer; } |
| 97 |
| 98 bool isPlaced() const { return m_isPlaced; } |
| 99 void setIsPlaced(bool placed = true) { m_isPlaced = placed; } |
| 100 |
| 101 LayoutUnit x() const { ASSERT(isPlaced()); return m_frameRect.x(); } |
| 102 LayoutUnit maxX() const { ASSERT(isPlaced()); return m_frameRect.maxX(); } |
| 103 LayoutUnit y() const { ASSERT(isPlaced()); return m_frameRect.y(); } |
| 104 LayoutUnit maxY() const { ASSERT(isPlaced()); return m_frameRect.maxY(); } |
| 105 LayoutUnit width() const { return m_frameRect.width(); } |
| 106 LayoutUnit height() const { return m_frameRect.height(); } |
| 107 |
| 108 void setX(LayoutUnit x) { ASSERT(!isInPlacedTree()); m_frameRect.setX(x); } |
| 109 void setY(LayoutUnit y) { ASSERT(!isInPlacedTree()); m_frameRect.setY(y); } |
| 110 void setWidth(LayoutUnit width) { ASSERT(!isInPlacedTree()); m_frameRect.set
Width(width); } |
| 111 void setHeight(LayoutUnit height) { ASSERT(!isInPlacedTree()); m_frameRect.s
etHeight(height); } |
| 112 |
| 113 const LayoutRect& frameRect() const { ASSERT(isPlaced()); return m_frameRect
; } |
| 114 void setFrameRect(const LayoutRect& frameRect) { ASSERT(!isInPlacedTree());
m_frameRect = frameRect; } |
| 115 |
| 116 int paginationStrut() const { return m_paginationStrut; } |
| 117 void setPaginationStrut(int strut) { m_paginationStrut = strut; } |
| 118 |
| 119 #ifndef NDEBUG |
| 120 bool isInPlacedTree() const { return m_isInPlacedTree; } |
| 121 void setIsInPlacedTree(bool value) { m_isInPlacedTree = value; } |
| 122 #endif |
| 123 |
| 124 bool shouldPaint() const { return m_shouldPaint; } |
| 125 void setShouldPaint(bool shouldPaint) { m_shouldPaint = shouldPaint; } |
| 126 bool isDescendant() const { return m_isDescendant; } |
| 127 void setIsDescendant(bool isDescendant) { m_isDescendant = isDescendant; } |
| 128 |
| 129 // FIXME: Callers of these methods are dangerous and should be whitelisted e
xplicitly or removed. |
| 130 void setRenderer(RenderBox* renderer) { m_renderer = renderer; } |
| 131 RootInlineBox* originatingLine() const { return m_originatingLine; } |
| 132 void setOriginatingLine(RootInlineBox* line) { m_originatingLine = line; } |
| 133 |
| 134 LayoutUnit logicalTop(bool isHorizontalWritingMode) const { return isHorizon
talWritingMode ? y() : x(); } |
| 135 LayoutUnit logicalBottom(bool isHorizontalWritingMode) const { return isHori
zontalWritingMode ? maxY() : maxX(); } |
| 136 LayoutUnit logicalLeft(bool isHorizontalWritingMode) const { return isHorizo
ntalWritingMode ? x() : y(); } |
| 137 LayoutUnit logicalRight(bool isHorizontalWritingMode) const { return isHoriz
ontalWritingMode ? maxX() : maxY(); } |
| 138 LayoutUnit logicalWidth(bool isHorizontalWritingMode) const { return isHoriz
ontalWritingMode ? width() : height(); } |
| 139 |
| 140 int pixelSnappedLogicalTop(bool isHorizontalWritingMode) const { return isHo
rizontalWritingMode ? frameRect().pixelSnappedY() : frameRect().pixelSnappedX();
} |
| 141 int pixelSnappedLogicalBottom(bool isHorizontalWritingMode) const { return i
sHorizontalWritingMode ? frameRect().pixelSnappedMaxY() : frameRect().pixelSnapp
edMaxX(); } |
| 142 int pixelSnappedLogicalLeft(bool isHorizontalWritingMode) const { return isH
orizontalWritingMode ? frameRect().pixelSnappedX() : frameRect().pixelSnappedY()
; } |
| 143 int pixelSnappedLogicalRight(bool isHorizontalWritingMode) const { return is
HorizontalWritingMode ? frameRect().pixelSnappedMaxX() : frameRect().pixelSnappe
dMaxY(); } |
| 144 |
| 145 void setLogicalTop(LayoutUnit logicalTop, bool isHorizontalWritingMode) |
| 146 { |
| 147 if (isHorizontalWritingMode) |
| 148 setY(logicalTop); |
| 149 else |
| 150 setX(logicalTop); |
| 151 } |
| 152 void setLogicalLeft(LayoutUnit logicalLeft, bool isHorizontalWritingMode) |
| 153 { |
| 154 if (isHorizontalWritingMode) |
| 155 setX(logicalLeft); |
| 156 else |
| 157 setY(logicalLeft); |
| 158 } |
| 159 void setLogicalHeight(LayoutUnit logicalHeight, bool isHorizontalWritingMode
) |
| 160 { |
| 161 if (isHorizontalWritingMode) |
| 162 setHeight(logicalHeight); |
| 163 else |
| 164 setWidth(logicalHeight); |
| 165 } |
| 166 void setLogicalWidth(LayoutUnit logicalWidth, bool isHorizontalWritingMode) |
| 167 { |
| 168 if (isHorizontalWritingMode) |
| 169 setWidth(logicalWidth); |
| 170 else |
| 171 setHeight(logicalWidth); |
| 172 } |
| 173 |
| 174 private: |
| 175 RenderBox* m_renderer; |
| 176 RootInlineBox* m_originatingLine; |
| 177 LayoutRect m_frameRect; |
| 178 int m_paginationStrut; // FIXME: Is this class size-sensitive? Does this nee
d 32-bits? |
| 179 |
| 180 unsigned m_type : 2; // Type (left or right aligned) |
| 181 unsigned m_shouldPaint : 1; |
| 182 unsigned m_isDescendant : 1; |
| 183 unsigned m_isPlaced : 1; |
| 184 #ifndef NDEBUG |
| 185 unsigned m_isInPlacedTree : 1; |
| 186 #endif |
| 187 }; |
| 188 |
| 189 struct FloatingObjectHashFunctions { |
| 190 static unsigned hash(FloatingObject* key) { return DefaultHash<RenderBox*>::
Hash::hash(key->renderer()); } |
| 191 static bool equal(FloatingObject* a, FloatingObject* b) { return a->renderer
() == b->renderer(); } |
| 192 static const bool safeToCompareToEmptyOrDeleted = true; |
| 193 }; |
| 194 struct FloatingObjectHashTranslator { |
| 195 static unsigned hash(RenderBox* key) { return DefaultHash<RenderBox*>::Hash:
:hash(key); } |
| 196 static bool equal(FloatingObject* a, RenderBox* b) { return a->renderer() ==
b; } |
| 197 }; |
| 198 typedef ListHashSet<FloatingObject*, 4, FloatingObjectHashFunctions> FloatingObj
ectSet; |
| 199 typedef FloatingObjectSet::const_iterator FloatingObjectSetIterator; |
| 200 typedef PODInterval<int, FloatingObject*> FloatingObjectInterval; |
| 201 typedef PODIntervalTree<int, FloatingObject*> FloatingObjectTree; |
| 202 typedef PODFreeListArena<PODRedBlackTree<FloatingObjectInterval>::Node> Interval
Arena; |
| 203 |
| 204 class FloatingObjects { |
| 205 WTF_MAKE_NONCOPYABLE(FloatingObjects); WTF_MAKE_FAST_ALLOCATED; |
| 206 public: |
| 207 FloatingObjects(const RenderBlock*, bool horizontalWritingMode); |
| 208 ~FloatingObjects(); |
| 209 |
| 210 void clear(); |
| 211 void add(FloatingObject*); |
| 212 void remove(FloatingObject*); |
| 213 void addPlacedObject(FloatingObject*); |
| 214 void removePlacedObject(FloatingObject*); |
| 215 void setHorizontalWritingMode(bool b = true) { m_horizontalWritingMode = b;
} |
| 216 |
| 217 bool hasLeftObjects() const { return m_leftObjectsCount > 0; } |
| 218 bool hasRightObjects() const { return m_rightObjectsCount > 0; } |
| 219 const FloatingObjectSet& set() const { return m_set; } |
| 220 void clearLineBoxTreePointers(); |
| 221 LayoutUnit logicalLeftOffset(LayoutUnit fixedOffset, LayoutUnit logicalTop,
LayoutUnit logicalHeight, ShapeOutsideFloatOffsetMode = ShapeOutsideFloatShapeOf
fset, LayoutUnit* heightRemaining = 0); |
| 222 LayoutUnit logicalRightOffset(LayoutUnit fixedOffset, LayoutUnit logicalTop,
LayoutUnit logicalHeight, ShapeOutsideFloatOffsetMode = ShapeOutsideFloatShapeO
ffset, LayoutUnit* heightRemaining = 0); |
| 223 private: |
| 224 void computePlacedFloatsTree(); |
| 225 const FloatingObjectTree& placedFloatsTree() |
| 226 { |
| 227 if (!m_placedFloatsTree.isInitialized()) |
| 228 computePlacedFloatsTree(); |
| 229 return m_placedFloatsTree; |
| 230 } |
| 231 void increaseObjectsCount(FloatingObject::Type); |
| 232 void decreaseObjectsCount(FloatingObject::Type); |
| 233 FloatingObjectInterval intervalForFloatingObject(FloatingObject*); |
| 234 |
| 235 FloatingObjectSet m_set; |
| 236 FloatingObjectTree m_placedFloatsTree; |
| 237 unsigned m_leftObjectsCount; |
| 238 unsigned m_rightObjectsCount; |
| 239 bool m_horizontalWritingMode; |
| 240 const RenderBlock* m_renderer; |
| 241 }; |
| 242 |
| 243 #ifndef NDEBUG |
| 244 // These structures are used by PODIntervalTree for debugging purposes. |
| 245 template <> struct ValueToString<int> { |
| 246 static String string(const int value); |
| 247 }; |
| 248 template<> struct ValueToString<FloatingObject*> { |
| 249 static String string(const FloatingObject*); |
| 250 }; |
| 251 #endif |
| 252 |
| 253 } // namespace WebCore |
| 254 |
| 255 #endif // FloatingObjects_h |
OLD | NEW |