| 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/rendering/RootInlineBox.h" | |
| 28 #include "platform/PODFreeListArena.h" | |
| 29 #include "platform/PODIntervalTree.h" | |
| 30 #include "wtf/ListHashSet.h" | |
| 31 #include "wtf/OwnPtr.h" | |
| 32 | |
| 33 namespace blink { | |
| 34 | |
| 35 class RenderBlockFlow; | |
| 36 class RenderBox; | |
| 37 | |
| 38 // FIXME this should be removed once RenderBlockFlow::nextFloatLogicalBottomBelo
w doesn't need it anymore. (Bug 123931) | |
| 39 enum ShapeOutsideFloatOffsetMode { ShapeOutsideFloatShapeOffset, ShapeOutsideFlo
atMarginBoxOffset }; | |
| 40 | |
| 41 class FloatingObject { | |
| 42 WTF_MAKE_NONCOPYABLE(FloatingObject); WTF_MAKE_FAST_ALLOCATED; | |
| 43 public: | |
| 44 #ifndef NDEBUG | |
| 45 // Used by the PODIntervalTree for debugging the FloatingObject. | |
| 46 template <class> friend struct ValueToString; | |
| 47 #endif | |
| 48 | |
| 49 // Note that Type uses bits so you can use FloatLeftRight as a mask to query
for both left and right. | |
| 50 enum Type { FloatLeft = 1, FloatRight = 2, FloatLeftRight = 3 }; | |
| 51 | |
| 52 static PassOwnPtr<FloatingObject> create(RenderBox*); | |
| 53 | |
| 54 PassOwnPtr<FloatingObject> copyToNewContainer(LayoutSize, bool shouldPaint =
false, bool isDescendant = false) const; | |
| 55 | |
| 56 PassOwnPtr<FloatingObject> unsafeClone() const; | |
| 57 | |
| 58 Type type() const { return static_cast<Type>(m_type); } | |
| 59 RenderBox* renderer() const { return m_renderer; } | |
| 60 | |
| 61 bool isPlaced() const { return m_isPlaced; } | |
| 62 void setIsPlaced(bool placed = true) { m_isPlaced = placed; } | |
| 63 | |
| 64 LayoutUnit x() const { ASSERT(isPlaced()); return m_frameRect.x(); } | |
| 65 LayoutUnit maxX() const { ASSERT(isPlaced()); return m_frameRect.maxX(); } | |
| 66 LayoutUnit y() const { ASSERT(isPlaced()); return m_frameRect.y(); } | |
| 67 LayoutUnit maxY() const { ASSERT(isPlaced()); return m_frameRect.maxY(); } | |
| 68 LayoutUnit width() const { return m_frameRect.width(); } | |
| 69 LayoutUnit height() const { return m_frameRect.height(); } | |
| 70 | |
| 71 void setX(LayoutUnit x) { ASSERT(!isInPlacedTree()); m_frameRect.setX(x); } | |
| 72 void setY(LayoutUnit y) { ASSERT(!isInPlacedTree()); m_frameRect.setY(y); } | |
| 73 void setWidth(LayoutUnit width) { ASSERT(!isInPlacedTree()); m_frameRect.set
Width(width); } | |
| 74 void setHeight(LayoutUnit height) { ASSERT(!isInPlacedTree()); m_frameRect.s
etHeight(height); } | |
| 75 | |
| 76 const LayoutRect& frameRect() const { ASSERT(isPlaced()); return m_frameRect
; } | |
| 77 void setFrameRect(const LayoutRect& frameRect) { ASSERT(!isInPlacedTree());
m_frameRect = frameRect; } | |
| 78 | |
| 79 #if ENABLE(ASSERT) | |
| 80 bool isInPlacedTree() const { return m_isInPlacedTree; } | |
| 81 void setIsInPlacedTree(bool value) { m_isInPlacedTree = value; } | |
| 82 #endif | |
| 83 | |
| 84 bool shouldPaint() const { return m_shouldPaint; } | |
| 85 void setShouldPaint(bool shouldPaint) { m_shouldPaint = shouldPaint; } | |
| 86 bool isDescendant() const { return m_isDescendant; } | |
| 87 void setIsDescendant(bool isDescendant) { m_isDescendant = isDescendant; } | |
| 88 | |
| 89 // FIXME: Callers of these methods are dangerous and should be whitelisted e
xplicitly or removed. | |
| 90 RootInlineBox* originatingLine() const { return m_originatingLine; } | |
| 91 void setOriginatingLine(RootInlineBox* line) { m_originatingLine = line; } | |
| 92 | |
| 93 private: | |
| 94 explicit FloatingObject(RenderBox*); | |
| 95 FloatingObject(RenderBox*, Type, const LayoutRect&, bool shouldPaint, bool i
sDescendant); | |
| 96 | |
| 97 RenderBox* m_renderer; | |
| 98 RootInlineBox* m_originatingLine; | |
| 99 LayoutRect m_frameRect; | |
| 100 | |
| 101 unsigned m_type : 2; // Type (left or right aligned) | |
| 102 unsigned m_shouldPaint : 1; | |
| 103 unsigned m_isDescendant : 1; | |
| 104 unsigned m_isPlaced : 1; | |
| 105 #if ENABLE(ASSERT) | |
| 106 unsigned m_isInPlacedTree : 1; | |
| 107 #endif | |
| 108 }; | |
| 109 | |
| 110 struct FloatingObjectHashFunctions { | |
| 111 static unsigned hash(FloatingObject* key) { return DefaultHash<RenderBox*>::
Hash::hash(key->renderer()); } | |
| 112 static unsigned hash(const OwnPtr<FloatingObject>& key) { return hash(key.ge
t()); } | |
| 113 static unsigned hash(const PassOwnPtr<FloatingObject>& key) { return hash(ke
y.get()); } | |
| 114 static bool equal(OwnPtr<FloatingObject>& a, FloatingObject* b) { return a->
renderer() == b->renderer(); } | |
| 115 static bool equal(OwnPtr<FloatingObject>& a, const OwnPtr<FloatingObject>& b
) { return equal(a, b.get()); } | |
| 116 static bool equal(OwnPtr<FloatingObject>& a, const PassOwnPtr<FloatingObject
>& b) { return equal(a, b.get()); } | |
| 117 | |
| 118 static const bool safeToCompareToEmptyOrDeleted = true; | |
| 119 }; | |
| 120 struct FloatingObjectHashTranslator { | |
| 121 static unsigned hash(RenderBox* key) { return DefaultHash<RenderBox*>::Hash:
:hash(key); } | |
| 122 static bool equal(FloatingObject* a, RenderBox* b) { return a->renderer() ==
b; } | |
| 123 static bool equal(const OwnPtr<FloatingObject>& a, RenderBox* b) { return a-
>renderer() == b; } | |
| 124 }; | |
| 125 typedef ListHashSet<OwnPtr<FloatingObject>, 4, FloatingObjectHashFunctions> Floa
tingObjectSet; | |
| 126 typedef FloatingObjectSet::const_iterator FloatingObjectSetIterator; | |
| 127 typedef PODInterval<int, FloatingObject*> FloatingObjectInterval; | |
| 128 typedef PODIntervalTree<int, FloatingObject*> FloatingObjectTree; | |
| 129 typedef PODFreeListArena<PODRedBlackTree<FloatingObjectInterval>::Node> Interval
Arena; | |
| 130 typedef HashMap<RenderBox*, OwnPtr<FloatingObject> > RendererToFloatInfoMap; | |
| 131 | |
| 132 class FloatingObjects { | |
| 133 WTF_MAKE_NONCOPYABLE(FloatingObjects); WTF_MAKE_FAST_ALLOCATED; | |
| 134 public: | |
| 135 FloatingObjects(const RenderBlockFlow*, bool horizontalWritingMode); | |
| 136 ~FloatingObjects(); | |
| 137 | |
| 138 void clear(); | |
| 139 void moveAllToFloatInfoMap(RendererToFloatInfoMap&); | |
| 140 FloatingObject* add(PassOwnPtr<FloatingObject>); | |
| 141 void remove(FloatingObject*); | |
| 142 void addPlacedObject(FloatingObject*); | |
| 143 void removePlacedObject(FloatingObject*); | |
| 144 void setHorizontalWritingMode(bool b = true) { m_horizontalWritingMode = b;
} | |
| 145 | |
| 146 bool hasLeftObjects() const { return m_leftObjectsCount > 0; } | |
| 147 bool hasRightObjects() const { return m_rightObjectsCount > 0; } | |
| 148 const FloatingObjectSet& set() const { return m_set; } | |
| 149 void clearLineBoxTreePointers(); | |
| 150 | |
| 151 LayoutUnit logicalLeftOffset(LayoutUnit fixedOffset, LayoutUnit logicalTop,
LayoutUnit logicalHeight); | |
| 152 LayoutUnit logicalRightOffset(LayoutUnit fixedOffset, LayoutUnit logicalTop,
LayoutUnit logicalHeight); | |
| 153 | |
| 154 LayoutUnit logicalLeftOffsetForPositioningFloat(LayoutUnit fixedOffset, Layo
utUnit logicalTop, LayoutUnit* heightRemaining); | |
| 155 LayoutUnit logicalRightOffsetForPositioningFloat(LayoutUnit fixedOffset, Lay
outUnit logicalTop, LayoutUnit* heightRemaining); | |
| 156 | |
| 157 LayoutUnit lowestFloatLogicalBottom(FloatingObject::Type); | |
| 158 | |
| 159 private: | |
| 160 bool hasLowestFloatLogicalBottomCached(bool isHorizontal, FloatingObject::Ty
pe floatType) const; | |
| 161 LayoutUnit getCachedlowestFloatLogicalBottom(FloatingObject::Type floatType)
const; | |
| 162 void setCachedLowestFloatLogicalBottom(bool isHorizontal, FloatingObject::Ty
pe floatType, LayoutUnit value); | |
| 163 void markLowestFloatLogicalBottomCacheAsDirty(); | |
| 164 | |
| 165 void computePlacedFloatsTree(); | |
| 166 const FloatingObjectTree& placedFloatsTree() | |
| 167 { | |
| 168 if (!m_placedFloatsTree.isInitialized()) | |
| 169 computePlacedFloatsTree(); | |
| 170 return m_placedFloatsTree; | |
| 171 } | |
| 172 void increaseObjectsCount(FloatingObject::Type); | |
| 173 void decreaseObjectsCount(FloatingObject::Type); | |
| 174 FloatingObjectInterval intervalForFloatingObject(FloatingObject*); | |
| 175 | |
| 176 FloatingObjectSet m_set; | |
| 177 FloatingObjectTree m_placedFloatsTree; | |
| 178 unsigned m_leftObjectsCount; | |
| 179 unsigned m_rightObjectsCount; | |
| 180 bool m_horizontalWritingMode; | |
| 181 const RenderBlockFlow* m_renderer; | |
| 182 | |
| 183 struct FloatBottomCachedValue { | |
| 184 FloatBottomCachedValue(); | |
| 185 LayoutUnit value; | |
| 186 bool dirty; | |
| 187 }; | |
| 188 FloatBottomCachedValue m_lowestFloatBottomCache[2]; | |
| 189 bool m_cachedHorizontalWritingMode; | |
| 190 }; | |
| 191 | |
| 192 #ifndef NDEBUG | |
| 193 // These structures are used by PODIntervalTree for debugging purposes. | |
| 194 template <> struct ValueToString<int> { | |
| 195 static String string(const int value); | |
| 196 }; | |
| 197 template<> struct ValueToString<FloatingObject*> { | |
| 198 static String string(const FloatingObject*); | |
| 199 }; | |
| 200 #endif | |
| 201 | |
| 202 } // namespace blink | |
| 203 | |
| 204 #endif // FloatingObjects_h | |
| OLD | NEW |