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

Side by Side Diff: Source/core/layout/FloatingObjects.cpp

Issue 1106533002: Formatting contexts should always expand to enclose floats (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Updated Created 5 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2007 David Smith (catfish.man@gmail.com) 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. 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. 6 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 FloatingObject::FloatingObject(LayoutBox* layoutObject) 44 FloatingObject::FloatingObject(LayoutBox* layoutObject)
45 : m_layoutObject(layoutObject) 45 : m_layoutObject(layoutObject)
46 , m_originatingLine(0) 46 , m_originatingLine(0)
47 , m_paginationStrut(0) 47 , m_paginationStrut(0)
48 , m_shouldPaint(true) 48 , m_shouldPaint(true)
49 , m_isDescendant(false) 49 , m_isDescendant(false)
50 , m_isPlaced(false) 50 , m_isPlaced(false)
51 #if ENABLE(ASSERT) 51 #if ENABLE(ASSERT)
52 , m_isInPlacedTree(false) 52 , m_isInPlacedTree(false)
53 #endif 53 #endif
54 , m_isLowestNonOverhangingFloatInChild(false)
54 { 55 {
55 EFloat type = layoutObject->style()->floating(); 56 EFloat type = layoutObject->style()->floating();
56 ASSERT(type != NoFloat); 57 ASSERT(type != NoFloat);
57 if (type == LeftFloat) 58 if (type == LeftFloat)
58 m_type = FloatLeft; 59 m_type = FloatLeft;
59 else if (type == RightFloat) 60 else if (type == RightFloat)
60 m_type = FloatRight; 61 m_type = FloatRight;
61 } 62 }
62 63
63 FloatingObject::FloatingObject(LayoutBox* layoutObject, Type type, const LayoutR ect& frameRect, bool shouldPaint, bool isDescendant) 64 FloatingObject::FloatingObject(LayoutBox* layoutObject, Type type, const LayoutR ect& frameRect, bool shouldPaint, bool isDescendant, bool isLowestNonOverhanging FloatInChild)
64 : m_layoutObject(layoutObject) 65 : m_layoutObject(layoutObject)
65 , m_originatingLine(0) 66 , m_originatingLine(0)
66 , m_frameRect(frameRect) 67 , m_frameRect(frameRect)
67 , m_paginationStrut(0) 68 , m_paginationStrut(0)
68 , m_type(type) 69 , m_type(type)
69 , m_shouldPaint(shouldPaint) 70 , m_shouldPaint(shouldPaint)
70 , m_isDescendant(isDescendant) 71 , m_isDescendant(isDescendant)
71 , m_isPlaced(true) 72 , m_isPlaced(true)
72 #if ENABLE(ASSERT) 73 #if ENABLE(ASSERT)
73 , m_isInPlacedTree(false) 74 , m_isInPlacedTree(false)
74 #endif 75 #endif
76 , m_isLowestNonOverhangingFloatInChild(isLowestNonOverhangingFloatInChild)
75 { 77 {
76 } 78 }
77 79
78 PassOwnPtr<FloatingObject> FloatingObject::create(LayoutBox* layoutObject) 80 PassOwnPtr<FloatingObject> FloatingObject::create(LayoutBox* layoutObject)
79 { 81 {
80 OwnPtr<FloatingObject> newObj = adoptPtr(new FloatingObject(layoutObject)); 82 OwnPtr<FloatingObject> newObj = adoptPtr(new FloatingObject(layoutObject));
81 newObj->setShouldPaint(!layoutObject->hasSelfPaintingLayer()); // If a layer exists, the float will paint itself. Otherwise someone else will. 83 newObj->setShouldPaint(!layoutObject->hasSelfPaintingLayer()); // If a layer exists, the float will paint itself. Otherwise someone else will.
82 newObj->setIsDescendant(true); 84 newObj->setIsDescendant(true);
83 85
84 return newObj.release(); 86 return newObj.release();
85 } 87 }
86 88
87 PassOwnPtr<FloatingObject> FloatingObject::copyToNewContainer(LayoutSize offset, bool shouldPaint, bool isDescendant) const 89 PassOwnPtr<FloatingObject> FloatingObject::copyToNewContainer(LayoutSize offset, bool shouldPaint, bool isDescendant) const
88 { 90 {
89 return adoptPtr(new FloatingObject(layoutObject(), type(), LayoutRect(frameR ect().location() - offset, frameRect().size()), shouldPaint, isDescendant)); 91 return adoptPtr(new FloatingObject(layoutObject(), type(), LayoutRect(frameR ect().location() - offset, frameRect().size()), shouldPaint, isDescendant, isLow estNonOverhangingFloatInChild()));
90 } 92 }
91 93
92 PassOwnPtr<FloatingObject> FloatingObject::unsafeClone() const 94 PassOwnPtr<FloatingObject> FloatingObject::unsafeClone() const
93 { 95 {
94 OwnPtr<FloatingObject> cloneObject = adoptPtr(new FloatingObject(layoutObjec t(), type(), m_frameRect, m_shouldPaint, m_isDescendant)); 96 OwnPtr<FloatingObject> cloneObject = adoptPtr(new FloatingObject(layoutObjec t(), type(), m_frameRect, m_shouldPaint, m_isDescendant, false));
95 cloneObject->m_paginationStrut = m_paginationStrut; 97 cloneObject->m_paginationStrut = m_paginationStrut;
96 cloneObject->m_isPlaced = m_isPlaced; 98 cloneObject->m_isPlaced = m_isPlaced;
97 return cloneObject.release(); 99 return cloneObject.release();
98 } 100 }
99 101
100 template <FloatingObject::Type FloatTypeValue> 102 template <FloatingObject::Type FloatTypeValue>
101 class ComputeFloatOffsetAdapter { 103 class ComputeFloatOffsetAdapter {
102 public: 104 public:
103 typedef FloatingObjectInterval IntervalType; 105 typedef FloatingObjectInterval IntervalType;
104 106
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 } 175 }
174 } 176 }
175 177
176 FloatingObjects::FloatingObjects(const LayoutBlockFlow* layoutObject, bool horiz ontalWritingMode) 178 FloatingObjects::FloatingObjects(const LayoutBlockFlow* layoutObject, bool horiz ontalWritingMode)
177 : m_placedFloatsTree(UninitializedTree) 179 : m_placedFloatsTree(UninitializedTree)
178 , m_leftObjectsCount(0) 180 , m_leftObjectsCount(0)
179 , m_rightObjectsCount(0) 181 , m_rightObjectsCount(0)
180 , m_horizontalWritingMode(horizontalWritingMode) 182 , m_horizontalWritingMode(horizontalWritingMode)
181 , m_layoutObject(layoutObject) 183 , m_layoutObject(layoutObject)
182 , m_cachedHorizontalWritingMode(false) 184 , m_cachedHorizontalWritingMode(false)
185 , m_lowestFloatObject(nullptr)
183 { 186 {
184 } 187 }
185 188
186 void FloatingObjects::clear() 189 void FloatingObjects::clear()
187 { 190 {
188 m_set.clear(); 191 m_set.clear();
189 m_placedFloatsTree.clear(); 192 m_placedFloatsTree.clear();
190 m_leftObjectsCount = 0; 193 m_leftObjectsCount = 0;
191 m_rightObjectsCount = 0; 194 m_rightObjectsCount = 0;
192 markLowestFloatLogicalBottomCacheAsDirty(); 195 markLowestFloatLogicalBottomCacheAsDirty();
196 m_lowestFloatObject = nullptr;
193 } 197 }
194 198
195 LayoutUnit FloatingObjects::lowestFloatLogicalBottom(FloatingObject::Type floatT ype) 199 LayoutUnit FloatingObjects::lowestFloatLogicalBottom(FloatingObject::Type floatT ype)
196 { 200 {
197 bool isInHorizontalWritingMode = m_horizontalWritingMode; 201 bool isInHorizontalWritingMode = m_horizontalWritingMode;
198 if (floatType != FloatingObject::FloatLeftRight) { 202 if (floatType != FloatingObject::FloatLeftRight) {
199 if (hasLowestFloatLogicalBottomCached(isInHorizontalWritingMode, floatTy pe)) 203 if (hasLowestFloatLogicalBottomCached(isInHorizontalWritingMode, floatTy pe))
200 return getCachedlowestFloatLogicalBottom(floatType); 204 return getCachedlowestFloatLogicalBottom(floatType);
201 } else { 205 } else {
202 if (hasLowestFloatLogicalBottomCached(isInHorizontalWritingMode, Floatin gObject::FloatLeft) && hasLowestFloatLogicalBottomCached(isInHorizontalWritingMo de, FloatingObject::FloatRight)) { 206 if (hasLowestFloatLogicalBottomCached(isInHorizontalWritingMode, Floatin gObject::FloatLeft) && hasLowestFloatLogicalBottomCached(isInHorizontalWritingMo de, FloatingObject::FloatRight)) {
203 return std::max(getCachedlowestFloatLogicalBottom(FloatingObject::Fl oatLeft), 207 return std::max(getCachedlowestFloatLogicalBottom(FloatingObject::Fl oatLeft),
204 getCachedlowestFloatLogicalBottom(FloatingObject::FloatRight)); 208 getCachedlowestFloatLogicalBottom(FloatingObject::FloatRight));
205 } 209 }
206 } 210 }
207 211
208 LayoutUnit lowestFloatBottom = 0; 212 LayoutUnit lowestFloatBottom = 0;
209 const FloatingObjectSet& floatingObjectSet = set(); 213 const FloatingObjectSet& floatingObjectSet = set();
214 FloatingObject* lowestFloatObject = nullptr;
210 FloatingObjectSetIterator end = floatingObjectSet.end(); 215 FloatingObjectSetIterator end = floatingObjectSet.end();
211 if (floatType == FloatingObject::FloatLeftRight) { 216 if (floatType == FloatingObject::FloatLeftRight) {
212 LayoutUnit lowestFloatBottomLeft = 0; 217 LayoutUnit lowestFloatBottomLeft = 0;
213 LayoutUnit lowestFloatBottomRight = 0; 218 LayoutUnit lowestFloatBottomRight = 0;
219 FloatingObject* floatingObject = nullptr;
214 for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end ; ++it) { 220 for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end ; ++it) {
215 FloatingObject* floatingObject = it->get(); 221 floatingObject = it->get();
216 if (floatingObject->isPlaced()) { 222 if (floatingObject->isPlaced()) {
217 FloatingObject::Type curType = floatingObject->type(); 223 FloatingObject::Type curType = floatingObject->type();
218 LayoutUnit curFloatLogicalBottom = m_layoutObject->logicalBottom ForFloat(floatingObject); 224 LayoutUnit curFloatLogicalBottom = m_layoutObject->logicalBottom ForFloat(floatingObject);
225 if (curFloatLogicalBottom > std::max(lowestFloatBottomLeft, lowe stFloatBottomRight))
226 lowestFloatObject = floatingObject;
219 if (curType & FloatingObject::FloatLeft) 227 if (curType & FloatingObject::FloatLeft)
220 lowestFloatBottomLeft = std::max(lowestFloatBottomLeft, curF loatLogicalBottom); 228 lowestFloatBottomLeft = std::max(lowestFloatBottomLeft, curF loatLogicalBottom);
221 if (curType & FloatingObject::FloatRight) 229 if (curType & FloatingObject::FloatRight)
222 lowestFloatBottomRight = std::max(lowestFloatBottomRight, cu rFloatLogicalBottom); 230 lowestFloatBottomRight = std::max(lowestFloatBottomRight, cu rFloatLogicalBottom);
223 } 231 }
224 } 232 }
225 lowestFloatBottom = std::max(lowestFloatBottomLeft, lowestFloatBottomRig ht); 233 lowestFloatBottom = std::max(lowestFloatBottomLeft, lowestFloatBottomRig ht);
234 setLowestFloatObject(lowestFloatObject);
226 setCachedLowestFloatLogicalBottom(isInHorizontalWritingMode, FloatingObj ect::FloatLeft, lowestFloatBottomLeft); 235 setCachedLowestFloatLogicalBottom(isInHorizontalWritingMode, FloatingObj ect::FloatLeft, lowestFloatBottomLeft);
227 setCachedLowestFloatLogicalBottom(isInHorizontalWritingMode, FloatingObj ect::FloatRight, lowestFloatBottomRight); 236 setCachedLowestFloatLogicalBottom(isInHorizontalWritingMode, FloatingObj ect::FloatRight, lowestFloatBottomRight);
228 } else { 237 } else {
238 FloatingObject* floatingObject = nullptr;
229 for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end ; ++it) { 239 for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end ; ++it) {
230 FloatingObject* floatingObject = it->get(); 240 floatingObject = it->get();
231 if (floatingObject->isPlaced() && floatingObject->type() == floatTyp e) 241 if (floatingObject->isPlaced() && floatingObject->type() == floatTyp e) {
242 if (m_layoutObject->logicalBottomForFloat(floatingObject) > lowe stFloatBottom)
243 lowestFloatObject = floatingObject;
232 lowestFloatBottom = std::max(lowestFloatBottom, m_layoutObject-> logicalBottomForFloat(floatingObject)); 244 lowestFloatBottom = std::max(lowestFloatBottom, m_layoutObject-> logicalBottomForFloat(floatingObject));
245 }
233 } 246 }
247 setLowestFloatObject(lowestFloatObject);
234 setCachedLowestFloatLogicalBottom(isInHorizontalWritingMode, floatType, lowestFloatBottom); 248 setCachedLowestFloatLogicalBottom(isInHorizontalWritingMode, floatType, lowestFloatBottom);
235 } 249 }
236 250
237 return lowestFloatBottom; 251 return lowestFloatBottom;
238 } 252 }
239 253
240 bool FloatingObjects::hasLowestFloatLogicalBottomCached(bool isHorizontal, Float ingObject::Type type) const 254 bool FloatingObjects::hasLowestFloatLogicalBottomCached(bool isHorizontal, Float ingObject::Type type) const
241 { 255 {
242 int floatIndex = static_cast<int>(type) - 1; 256 int floatIndex = static_cast<int>(type) - 1;
243 ASSERT(floatIndex < static_cast<int>(sizeof(m_lowestFloatBottomCache) / size of(FloatBottomCachedValue))); 257 ASSERT(floatIndex < static_cast<int>(sizeof(m_lowestFloatBottomCache) / size of(FloatBottomCachedValue)));
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 } 540 }
527 541
528 String ValueToString<FloatingObject*>::string(const FloatingObject* floatingObje ct) 542 String ValueToString<FloatingObject*>::string(const FloatingObject* floatingObje ct)
529 { 543 {
530 return String::format("%p (%dx%d %dx%d)", floatingObject, floatingObject->fr ameRect().pixelSnappedX(), floatingObject->frameRect().pixelSnappedY(), floating Object->frameRect().pixelSnappedMaxX(), floatingObject->frameRect().pixelSnapped MaxY()); 544 return String::format("%p (%dx%d %dx%d)", floatingObject, floatingObject->fr ameRect().pixelSnappedX(), floatingObject->frameRect().pixelSnappedY(), floating Object->frameRect().pixelSnappedMaxX(), floatingObject->frameRect().pixelSnapped MaxY());
531 } 545 }
532 #endif 546 #endif
533 547
534 548
535 } // namespace blink 549 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698