| 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 #include "config.h" | |
| 25 #include "core/rendering/FloatingObjects.h" | |
| 26 | |
| 27 #include "core/rendering/RenderBlockFlow.h" | |
| 28 #include "core/rendering/RenderBox.h" | |
| 29 #include "core/rendering/RenderView.h" | |
| 30 | |
| 31 using namespace WTF; | |
| 32 | |
| 33 namespace blink { | |
| 34 | |
| 35 struct SameSizeAsFloatingObject { | |
| 36 void* pointers[2]; | |
| 37 LayoutRect rect; | |
| 38 uint32_t bitfields : 8; | |
| 39 }; | |
| 40 | |
| 41 COMPILE_ASSERT(sizeof(FloatingObject) == sizeof(SameSizeAsFloatingObject), Float
ingObject_should_stay_small); | |
| 42 | |
| 43 FloatingObject::FloatingObject(RenderBox* renderer) | |
| 44 : m_renderer(renderer) | |
| 45 , m_originatingLine(0) | |
| 46 , m_shouldPaint(true) | |
| 47 , m_isDescendant(false) | |
| 48 , m_isPlaced(false) | |
| 49 #if ENABLE(ASSERT) | |
| 50 , m_isInPlacedTree(false) | |
| 51 #endif | |
| 52 { | |
| 53 EFloat type = renderer->style()->floating(); | |
| 54 ASSERT(type != NoFloat); | |
| 55 if (type == LeftFloat) | |
| 56 m_type = FloatLeft; | |
| 57 else if (type == RightFloat) | |
| 58 m_type = FloatRight; | |
| 59 } | |
| 60 | |
| 61 FloatingObject::FloatingObject(RenderBox* renderer, Type type, const LayoutRect&
frameRect, bool shouldPaint, bool isDescendant) | |
| 62 : m_renderer(renderer) | |
| 63 , m_originatingLine(0) | |
| 64 , m_frameRect(frameRect) | |
| 65 , m_type(type) | |
| 66 , m_shouldPaint(shouldPaint) | |
| 67 , m_isDescendant(isDescendant) | |
| 68 , m_isPlaced(true) | |
| 69 #if ENABLE(ASSERT) | |
| 70 , m_isInPlacedTree(false) | |
| 71 #endif | |
| 72 { | |
| 73 } | |
| 74 | |
| 75 PassOwnPtr<FloatingObject> FloatingObject::create(RenderBox* renderer) | |
| 76 { | |
| 77 OwnPtr<FloatingObject> newObj = adoptPtr(new FloatingObject(renderer)); | |
| 78 newObj->setShouldPaint(!renderer->hasSelfPaintingLayer()); // If a layer exi
sts, the float will paint itself. Otherwise someone else will. | |
| 79 newObj->setIsDescendant(true); | |
| 80 | |
| 81 return newObj.release(); | |
| 82 } | |
| 83 | |
| 84 PassOwnPtr<FloatingObject> FloatingObject::copyToNewContainer(LayoutSize offset,
bool shouldPaint, bool isDescendant) const | |
| 85 { | |
| 86 return adoptPtr(new FloatingObject(renderer(), type(), LayoutRect(frameRect(
).location() - offset, frameRect().size()), shouldPaint, isDescendant)); | |
| 87 } | |
| 88 | |
| 89 PassOwnPtr<FloatingObject> FloatingObject::unsafeClone() const | |
| 90 { | |
| 91 OwnPtr<FloatingObject> cloneObject = adoptPtr(new FloatingObject(renderer(),
type(), m_frameRect, m_shouldPaint, m_isDescendant)); | |
| 92 cloneObject->m_isPlaced = m_isPlaced; | |
| 93 return cloneObject.release(); | |
| 94 } | |
| 95 | |
| 96 template <FloatingObject::Type FloatTypeValue> | |
| 97 class ComputeFloatOffsetAdapter { | |
| 98 public: | |
| 99 typedef FloatingObjectInterval IntervalType; | |
| 100 | |
| 101 ComputeFloatOffsetAdapter(const RenderBlockFlow* renderer, int lineTop, int
lineBottom, LayoutUnit offset) | |
| 102 : m_renderer(renderer) | |
| 103 , m_lineTop(lineTop) | |
| 104 , m_lineBottom(lineBottom) | |
| 105 , m_offset(offset) | |
| 106 , m_outermostFloat(0) | |
| 107 { | |
| 108 } | |
| 109 | |
| 110 virtual ~ComputeFloatOffsetAdapter() { } | |
| 111 | |
| 112 int lowValue() const { return m_lineTop; } | |
| 113 int highValue() const { return m_lineBottom; } | |
| 114 void collectIfNeeded(const IntervalType&); | |
| 115 | |
| 116 LayoutUnit offset() const { return m_offset; } | |
| 117 | |
| 118 protected: | |
| 119 virtual bool updateOffsetIfNeeded(const FloatingObject&) = 0; | |
| 120 | |
| 121 const RenderBlockFlow* m_renderer; | |
| 122 int m_lineTop; | |
| 123 int m_lineBottom; | |
| 124 LayoutUnit m_offset; | |
| 125 const FloatingObject* m_outermostFloat; | |
| 126 }; | |
| 127 | |
| 128 template <FloatingObject::Type FloatTypeValue> | |
| 129 class ComputeFloatOffsetForFloatLayoutAdapter : public ComputeFloatOffsetAdapter
<FloatTypeValue> { | |
| 130 public: | |
| 131 ComputeFloatOffsetForFloatLayoutAdapter(const RenderBlockFlow* renderer, Lay
outUnit lineTop, LayoutUnit lineBottom, LayoutUnit offset) | |
| 132 : ComputeFloatOffsetAdapter<FloatTypeValue>(renderer, lineTop, lineBotto
m, offset) | |
| 133 { | |
| 134 } | |
| 135 | |
| 136 virtual ~ComputeFloatOffsetForFloatLayoutAdapter() { } | |
| 137 | |
| 138 LayoutUnit heightRemaining() const; | |
| 139 | |
| 140 protected: | |
| 141 virtual bool updateOffsetIfNeeded(const FloatingObject&) override final; | |
| 142 }; | |
| 143 | |
| 144 template <FloatingObject::Type FloatTypeValue> | |
| 145 class ComputeFloatOffsetForLineLayoutAdapter : public ComputeFloatOffsetAdapter<
FloatTypeValue> { | |
| 146 public: | |
| 147 ComputeFloatOffsetForLineLayoutAdapter(const RenderBlockFlow* renderer, Layo
utUnit lineTop, LayoutUnit lineBottom, LayoutUnit offset) | |
| 148 : ComputeFloatOffsetAdapter<FloatTypeValue>(renderer, lineTop, lineBotto
m, offset) | |
| 149 { | |
| 150 } | |
| 151 | |
| 152 virtual ~ComputeFloatOffsetForLineLayoutAdapter() { } | |
| 153 | |
| 154 protected: | |
| 155 virtual bool updateOffsetIfNeeded(const FloatingObject&) override final; | |
| 156 }; | |
| 157 | |
| 158 | |
| 159 FloatingObjects::~FloatingObjects() | |
| 160 { | |
| 161 } | |
| 162 void FloatingObjects::clearLineBoxTreePointers() | |
| 163 { | |
| 164 // Clear references to originating lines, since the lines are being deleted | |
| 165 FloatingObjectSetIterator end = m_set.end(); | |
| 166 for (FloatingObjectSetIterator it = m_set.begin(); it != end; ++it) { | |
| 167 ASSERT(!((*it)->originatingLine()) || (*it)->originatingLine()->renderer
() == m_renderer); | |
| 168 (*it)->setOriginatingLine(0); | |
| 169 } | |
| 170 } | |
| 171 | |
| 172 FloatingObjects::FloatingObjects(const RenderBlockFlow* renderer, bool horizonta
lWritingMode) | |
| 173 : m_placedFloatsTree(UninitializedTree) | |
| 174 , m_leftObjectsCount(0) | |
| 175 , m_rightObjectsCount(0) | |
| 176 , m_horizontalWritingMode(horizontalWritingMode) | |
| 177 , m_renderer(renderer) | |
| 178 , m_cachedHorizontalWritingMode(false) | |
| 179 { | |
| 180 } | |
| 181 | |
| 182 void FloatingObjects::clear() | |
| 183 { | |
| 184 m_set.clear(); | |
| 185 m_placedFloatsTree.clear(); | |
| 186 m_leftObjectsCount = 0; | |
| 187 m_rightObjectsCount = 0; | |
| 188 markLowestFloatLogicalBottomCacheAsDirty(); | |
| 189 } | |
| 190 | |
| 191 LayoutUnit FloatingObjects::lowestFloatLogicalBottom(FloatingObject::Type floatT
ype) | |
| 192 { | |
| 193 bool isInHorizontalWritingMode = m_horizontalWritingMode; | |
| 194 if (floatType != FloatingObject::FloatLeftRight) { | |
| 195 if (hasLowestFloatLogicalBottomCached(isInHorizontalWritingMode, floatTy
pe)) | |
| 196 return getCachedlowestFloatLogicalBottom(floatType); | |
| 197 } else { | |
| 198 if (hasLowestFloatLogicalBottomCached(isInHorizontalWritingMode, Floatin
gObject::FloatLeft) && hasLowestFloatLogicalBottomCached(isInHorizontalWritingMo
de, FloatingObject::FloatRight)) { | |
| 199 return std::max(getCachedlowestFloatLogicalBottom(FloatingObject::Fl
oatLeft), | |
| 200 getCachedlowestFloatLogicalBottom(FloatingObject::FloatRight)); | |
| 201 } | |
| 202 } | |
| 203 | |
| 204 LayoutUnit lowestFloatBottom = 0; | |
| 205 const FloatingObjectSet& floatingObjectSet = set(); | |
| 206 FloatingObjectSetIterator end = floatingObjectSet.end(); | |
| 207 if (floatType == FloatingObject::FloatLeftRight) { | |
| 208 LayoutUnit lowestFloatBottomLeft = 0; | |
| 209 LayoutUnit lowestFloatBottomRight = 0; | |
| 210 for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end
; ++it) { | |
| 211 FloatingObject* floatingObject = it->get(); | |
| 212 if (floatingObject->isPlaced()) { | |
| 213 FloatingObject::Type curType = floatingObject->type(); | |
| 214 LayoutUnit curFloatLogicalBottom = m_renderer->logicalBottomForF
loat(floatingObject); | |
| 215 if (curType & FloatingObject::FloatLeft) | |
| 216 lowestFloatBottomLeft = std::max(lowestFloatBottomLeft, curF
loatLogicalBottom); | |
| 217 if (curType & FloatingObject::FloatRight) | |
| 218 lowestFloatBottomRight = std::max(lowestFloatBottomRight, cu
rFloatLogicalBottom); | |
| 219 } | |
| 220 } | |
| 221 lowestFloatBottom = std::max(lowestFloatBottomLeft, lowestFloatBottomRig
ht); | |
| 222 setCachedLowestFloatLogicalBottom(isInHorizontalWritingMode, FloatingObj
ect::FloatLeft, lowestFloatBottomLeft); | |
| 223 setCachedLowestFloatLogicalBottom(isInHorizontalWritingMode, FloatingObj
ect::FloatRight, lowestFloatBottomRight); | |
| 224 } else { | |
| 225 for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end
; ++it) { | |
| 226 FloatingObject* floatingObject = it->get(); | |
| 227 if (floatingObject->isPlaced() && floatingObject->type() == floatTyp
e) | |
| 228 lowestFloatBottom = std::max(lowestFloatBottom, m_renderer->logi
calBottomForFloat(floatingObject)); | |
| 229 } | |
| 230 setCachedLowestFloatLogicalBottom(isInHorizontalWritingMode, floatType,
lowestFloatBottom); | |
| 231 } | |
| 232 | |
| 233 return lowestFloatBottom; | |
| 234 } | |
| 235 | |
| 236 bool FloatingObjects::hasLowestFloatLogicalBottomCached(bool isHorizontal, Float
ingObject::Type type) const | |
| 237 { | |
| 238 int floatIndex = static_cast<int>(type) - 1; | |
| 239 ASSERT(floatIndex < static_cast<int>(sizeof(m_lowestFloatBottomCache) / size
of(FloatBottomCachedValue))); | |
| 240 ASSERT(floatIndex >= 0); | |
| 241 return (m_cachedHorizontalWritingMode == isHorizontal && !m_lowestFloatBotto
mCache[floatIndex].dirty); | |
| 242 } | |
| 243 | |
| 244 LayoutUnit FloatingObjects::getCachedlowestFloatLogicalBottom(FloatingObject::Ty
pe type) const | |
| 245 { | |
| 246 int floatIndex = static_cast<int>(type) - 1; | |
| 247 ASSERT(floatIndex < static_cast<int>(sizeof(m_lowestFloatBottomCache) / size
of(FloatBottomCachedValue))); | |
| 248 ASSERT(floatIndex >= 0); | |
| 249 return m_lowestFloatBottomCache[floatIndex].value; | |
| 250 } | |
| 251 | |
| 252 void FloatingObjects::setCachedLowestFloatLogicalBottom(bool isHorizontal, Float
ingObject::Type type, LayoutUnit value) | |
| 253 { | |
| 254 int floatIndex = static_cast<int>(type) - 1; | |
| 255 ASSERT(floatIndex < static_cast<int>(sizeof(m_lowestFloatBottomCache) / size
of(FloatBottomCachedValue))); | |
| 256 ASSERT(floatIndex >= 0); | |
| 257 m_cachedHorizontalWritingMode = isHorizontal; | |
| 258 m_lowestFloatBottomCache[floatIndex].value = value; | |
| 259 m_lowestFloatBottomCache[floatIndex].dirty = false; | |
| 260 } | |
| 261 | |
| 262 void FloatingObjects::markLowestFloatLogicalBottomCacheAsDirty() | |
| 263 { | |
| 264 for (size_t i = 0; i < sizeof(m_lowestFloatBottomCache) / sizeof(FloatBottom
CachedValue); ++i) | |
| 265 m_lowestFloatBottomCache[i].dirty = true; | |
| 266 } | |
| 267 | |
| 268 void FloatingObjects::moveAllToFloatInfoMap(RendererToFloatInfoMap& map) | |
| 269 { | |
| 270 while (!m_set.isEmpty()) { | |
| 271 OwnPtr<FloatingObject> floatingObject = m_set.takeFirst(); | |
| 272 RenderBox* renderer = floatingObject->renderer(); | |
| 273 map.add(renderer, floatingObject.release()); | |
| 274 } | |
| 275 clear(); | |
| 276 } | |
| 277 | |
| 278 inline void FloatingObjects::increaseObjectsCount(FloatingObject::Type type) | |
| 279 { | |
| 280 if (type == FloatingObject::FloatLeft) | |
| 281 m_leftObjectsCount++; | |
| 282 else | |
| 283 m_rightObjectsCount++; | |
| 284 } | |
| 285 | |
| 286 inline void FloatingObjects::decreaseObjectsCount(FloatingObject::Type type) | |
| 287 { | |
| 288 if (type == FloatingObject::FloatLeft) | |
| 289 m_leftObjectsCount--; | |
| 290 else | |
| 291 m_rightObjectsCount--; | |
| 292 } | |
| 293 | |
| 294 inline FloatingObjectInterval FloatingObjects::intervalForFloatingObject(Floatin
gObject* floatingObject) | |
| 295 { | |
| 296 if (m_horizontalWritingMode) | |
| 297 return FloatingObjectInterval(floatingObject->frameRect().pixelSnappedY(
), floatingObject->frameRect().pixelSnappedMaxY(), floatingObject); | |
| 298 return FloatingObjectInterval(floatingObject->frameRect().pixelSnappedX(), f
loatingObject->frameRect().pixelSnappedMaxX(), floatingObject); | |
| 299 } | |
| 300 | |
| 301 void FloatingObjects::addPlacedObject(FloatingObject* floatingObject) | |
| 302 { | |
| 303 ASSERT(!floatingObject->isInPlacedTree()); | |
| 304 | |
| 305 floatingObject->setIsPlaced(true); | |
| 306 if (m_placedFloatsTree.isInitialized()) | |
| 307 m_placedFloatsTree.add(intervalForFloatingObject(floatingObject)); | |
| 308 | |
| 309 #if ENABLE(ASSERT) | |
| 310 floatingObject->setIsInPlacedTree(true); | |
| 311 #endif | |
| 312 markLowestFloatLogicalBottomCacheAsDirty(); | |
| 313 } | |
| 314 | |
| 315 void FloatingObjects::removePlacedObject(FloatingObject* floatingObject) | |
| 316 { | |
| 317 ASSERT(floatingObject->isPlaced() && floatingObject->isInPlacedTree()); | |
| 318 | |
| 319 if (m_placedFloatsTree.isInitialized()) { | |
| 320 bool removed = m_placedFloatsTree.remove(intervalForFloatingObject(float
ingObject)); | |
| 321 ASSERT_UNUSED(removed, removed); | |
| 322 } | |
| 323 | |
| 324 floatingObject->setIsPlaced(false); | |
| 325 #if ENABLE(ASSERT) | |
| 326 floatingObject->setIsInPlacedTree(false); | |
| 327 #endif | |
| 328 markLowestFloatLogicalBottomCacheAsDirty(); | |
| 329 } | |
| 330 | |
| 331 FloatingObject* FloatingObjects::add(PassOwnPtr<FloatingObject> floatingObject) | |
| 332 { | |
| 333 FloatingObject* newObject = floatingObject.leakPtr(); | |
| 334 increaseObjectsCount(newObject->type()); | |
| 335 m_set.add(adoptPtr(newObject)); | |
| 336 if (newObject->isPlaced()) | |
| 337 addPlacedObject(newObject); | |
| 338 markLowestFloatLogicalBottomCacheAsDirty(); | |
| 339 return newObject; | |
| 340 } | |
| 341 | |
| 342 void FloatingObjects::remove(FloatingObject* toBeRemoved) | |
| 343 { | |
| 344 decreaseObjectsCount(toBeRemoved->type()); | |
| 345 OwnPtr<FloatingObject> floatingObject = m_set.take(toBeRemoved); | |
| 346 ASSERT(floatingObject->isPlaced() || !floatingObject->isInPlacedTree()); | |
| 347 if (floatingObject->isPlaced()) | |
| 348 removePlacedObject(floatingObject.get()); | |
| 349 markLowestFloatLogicalBottomCacheAsDirty(); | |
| 350 ASSERT(!floatingObject->originatingLine()); | |
| 351 } | |
| 352 | |
| 353 void FloatingObjects::computePlacedFloatsTree() | |
| 354 { | |
| 355 ASSERT(!m_placedFloatsTree.isInitialized()); | |
| 356 if (m_set.isEmpty()) | |
| 357 return; | |
| 358 m_placedFloatsTree.initIfNeeded(m_renderer->view()->intervalArena()); | |
| 359 FloatingObjectSetIterator it = m_set.begin(); | |
| 360 FloatingObjectSetIterator end = m_set.end(); | |
| 361 for (; it != end; ++it) { | |
| 362 FloatingObject* floatingObject = it->get(); | |
| 363 if (floatingObject->isPlaced()) | |
| 364 m_placedFloatsTree.add(intervalForFloatingObject(floatingObject)); | |
| 365 } | |
| 366 } | |
| 367 | |
| 368 LayoutUnit FloatingObjects::logicalLeftOffsetForPositioningFloat(LayoutUnit fixe
dOffset, LayoutUnit logicalTop, LayoutUnit *heightRemaining) | |
| 369 { | |
| 370 int logicalTopAsInt = roundToInt(logicalTop); | |
| 371 ComputeFloatOffsetForFloatLayoutAdapter<FloatingObject::FloatLeft> adapter(m
_renderer, logicalTopAsInt, logicalTopAsInt, fixedOffset); | |
| 372 placedFloatsTree().allOverlapsWithAdapter(adapter); | |
| 373 | |
| 374 if (heightRemaining) | |
| 375 *heightRemaining = adapter.heightRemaining(); | |
| 376 | |
| 377 return adapter.offset(); | |
| 378 } | |
| 379 | |
| 380 LayoutUnit FloatingObjects::logicalRightOffsetForPositioningFloat(LayoutUnit fix
edOffset, LayoutUnit logicalTop, LayoutUnit *heightRemaining) | |
| 381 { | |
| 382 int logicalTopAsInt = roundToInt(logicalTop); | |
| 383 ComputeFloatOffsetForFloatLayoutAdapter<FloatingObject::FloatRight> adapter(
m_renderer, logicalTopAsInt, logicalTopAsInt, fixedOffset); | |
| 384 placedFloatsTree().allOverlapsWithAdapter(adapter); | |
| 385 | |
| 386 if (heightRemaining) | |
| 387 *heightRemaining = adapter.heightRemaining(); | |
| 388 | |
| 389 return std::min(fixedOffset, adapter.offset()); | |
| 390 } | |
| 391 | |
| 392 LayoutUnit FloatingObjects::logicalLeftOffset(LayoutUnit fixedOffset, LayoutUnit
logicalTop, LayoutUnit logicalHeight) | |
| 393 { | |
| 394 ComputeFloatOffsetForLineLayoutAdapter<FloatingObject::FloatLeft> adapter(m_
renderer, roundToInt(logicalTop), roundToInt(logicalTop + logicalHeight), fixedO
ffset); | |
| 395 placedFloatsTree().allOverlapsWithAdapter(adapter); | |
| 396 | |
| 397 return adapter.offset(); | |
| 398 } | |
| 399 | |
| 400 LayoutUnit FloatingObjects::logicalRightOffset(LayoutUnit fixedOffset, LayoutUni
t logicalTop, LayoutUnit logicalHeight) | |
| 401 { | |
| 402 ComputeFloatOffsetForLineLayoutAdapter<FloatingObject::FloatRight> adapter(m
_renderer, roundToInt(logicalTop), roundToInt(logicalTop + logicalHeight), fixed
Offset); | |
| 403 placedFloatsTree().allOverlapsWithAdapter(adapter); | |
| 404 | |
| 405 return std::min(fixedOffset, adapter.offset()); | |
| 406 } | |
| 407 | |
| 408 FloatingObjects::FloatBottomCachedValue::FloatBottomCachedValue() | |
| 409 : value(0) | |
| 410 , dirty(true) | |
| 411 { | |
| 412 } | |
| 413 | |
| 414 inline static bool rangesIntersect(int floatTop, int floatBottom, int objectTop,
int objectBottom) | |
| 415 { | |
| 416 if (objectTop >= floatBottom || objectBottom < floatTop) | |
| 417 return false; | |
| 418 | |
| 419 // The top of the object overlaps the float | |
| 420 if (objectTop >= floatTop) | |
| 421 return true; | |
| 422 | |
| 423 // The object encloses the float | |
| 424 if (objectTop < floatTop && objectBottom > floatBottom) | |
| 425 return true; | |
| 426 | |
| 427 // The bottom of the object overlaps the float | |
| 428 if (objectBottom > objectTop && objectBottom > floatTop && objectBottom <= f
loatBottom) | |
| 429 return true; | |
| 430 | |
| 431 return false; | |
| 432 } | |
| 433 | |
| 434 template<> | |
| 435 inline bool ComputeFloatOffsetForFloatLayoutAdapter<FloatingObject::FloatLeft>::
updateOffsetIfNeeded(const FloatingObject& floatingObject) | |
| 436 { | |
| 437 LayoutUnit logicalRight = m_renderer->logicalRightForFloat(&floatingObject); | |
| 438 if (logicalRight > m_offset) { | |
| 439 m_offset = logicalRight; | |
| 440 return true; | |
| 441 } | |
| 442 return false; | |
| 443 } | |
| 444 | |
| 445 template<> | |
| 446 inline bool ComputeFloatOffsetForFloatLayoutAdapter<FloatingObject::FloatRight>:
:updateOffsetIfNeeded(const FloatingObject& floatingObject) | |
| 447 { | |
| 448 LayoutUnit logicalLeft = m_renderer->logicalLeftForFloat(&floatingObject); | |
| 449 if (logicalLeft < m_offset) { | |
| 450 m_offset = logicalLeft; | |
| 451 return true; | |
| 452 } | |
| 453 return false; | |
| 454 } | |
| 455 | |
| 456 template <FloatingObject::Type FloatTypeValue> | |
| 457 LayoutUnit ComputeFloatOffsetForFloatLayoutAdapter<FloatTypeValue>::heightRemain
ing() const | |
| 458 { | |
| 459 return this->m_outermostFloat ? this->m_renderer->logicalBottomForFloat(this
->m_outermostFloat) - this->m_lineTop : LayoutUnit(1); | |
| 460 } | |
| 461 | |
| 462 template <FloatingObject::Type FloatTypeValue> | |
| 463 inline void ComputeFloatOffsetAdapter<FloatTypeValue>::collectIfNeeded(const Int
ervalType& interval) | |
| 464 { | |
| 465 const FloatingObject* floatingObject = interval.data(); | |
| 466 if (floatingObject->type() != FloatTypeValue || !rangesIntersect(interval.lo
w(), interval.high(), m_lineTop, m_lineBottom)) | |
| 467 return; | |
| 468 | |
| 469 // Make sure the float hasn't changed since it was added to the placed float
s tree. | |
| 470 ASSERT(floatingObject->isPlaced()); | |
| 471 ASSERT(interval.low() == m_renderer->pixelSnappedLogicalTopForFloat(floating
Object)); | |
| 472 ASSERT(interval.high() == m_renderer->pixelSnappedLogicalBottomForFloat(floa
tingObject)); | |
| 473 | |
| 474 bool floatIsNewExtreme = updateOffsetIfNeeded(*floatingObject); | |
| 475 if (floatIsNewExtreme) | |
| 476 m_outermostFloat = floatingObject; | |
| 477 } | |
| 478 | |
| 479 template<> | |
| 480 inline bool ComputeFloatOffsetForLineLayoutAdapter<FloatingObject::FloatLeft>::u
pdateOffsetIfNeeded(const FloatingObject& floatingObject) | |
| 481 { | |
| 482 LayoutUnit logicalRight = m_renderer->logicalRightForFloat(&floatingObject); | |
| 483 if (ShapeOutsideInfo* shapeOutside = floatingObject.renderer()->shapeOutside
Info()) { | |
| 484 ShapeOutsideDeltas shapeDeltas = shapeOutside->computeDeltasForContainin
gBlockLine(*m_renderer, floatingObject, m_lineTop, m_lineBottom - m_lineTop); | |
| 485 if (!shapeDeltas.lineOverlapsShape()) | |
| 486 return false; | |
| 487 | |
| 488 logicalRight += shapeDeltas.rightMarginBoxDelta(); | |
| 489 } | |
| 490 if (logicalRight > m_offset) { | |
| 491 m_offset = logicalRight; | |
| 492 return true; | |
| 493 } | |
| 494 | |
| 495 return false; | |
| 496 } | |
| 497 | |
| 498 template<> | |
| 499 inline bool ComputeFloatOffsetForLineLayoutAdapter<FloatingObject::FloatRight>::
updateOffsetIfNeeded(const FloatingObject& floatingObject) | |
| 500 { | |
| 501 LayoutUnit logicalLeft = m_renderer->logicalLeftForFloat(&floatingObject); | |
| 502 if (ShapeOutsideInfo* shapeOutside = floatingObject.renderer()->shapeOutside
Info()) { | |
| 503 ShapeOutsideDeltas shapeDeltas = shapeOutside->computeDeltasForContainin
gBlockLine(*m_renderer, floatingObject, m_lineTop, m_lineBottom - m_lineTop); | |
| 504 if (!shapeDeltas.lineOverlapsShape()) | |
| 505 return false; | |
| 506 | |
| 507 logicalLeft += shapeDeltas.leftMarginBoxDelta(); | |
| 508 } | |
| 509 if (logicalLeft < m_offset) { | |
| 510 m_offset = logicalLeft; | |
| 511 return true; | |
| 512 } | |
| 513 | |
| 514 return false; | |
| 515 } | |
| 516 | |
| 517 #ifndef NDEBUG | |
| 518 // These helpers are only used by the PODIntervalTree for debugging purposes. | |
| 519 String ValueToString<int>::string(const int value) | |
| 520 { | |
| 521 return String::number(value); | |
| 522 } | |
| 523 | |
| 524 String ValueToString<FloatingObject*>::string(const FloatingObject* floatingObje
ct) | |
| 525 { | |
| 526 return String::format("%p (%dx%d %dx%d)", floatingObject, floatingObject->fr
ameRect().pixelSnappedX(), floatingObject->frameRect().pixelSnappedY(), floating
Object->frameRect().pixelSnappedMaxX(), floatingObject->frameRect().pixelSnapped
MaxY()); | |
| 527 } | |
| 528 #endif | |
| 529 | |
| 530 | |
| 531 } // namespace blink | |
| OLD | NEW |