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

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

Issue 763173003: Convert RenderBlockFlow code to use FloatingObject references (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: more usage of const with floatingObject Created 5 years, 6 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
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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 } 205 }
206 } 206 }
207 207
208 LayoutUnit lowestFloatBottom = 0; 208 LayoutUnit lowestFloatBottom = 0;
209 const FloatingObjectSet& floatingObjectSet = set(); 209 const FloatingObjectSet& floatingObjectSet = set();
210 FloatingObjectSetIterator end = floatingObjectSet.end(); 210 FloatingObjectSetIterator end = floatingObjectSet.end();
211 if (floatType == FloatingObject::FloatLeftRight) { 211 if (floatType == FloatingObject::FloatLeftRight) {
212 LayoutUnit lowestFloatBottomLeft = 0; 212 LayoutUnit lowestFloatBottomLeft = 0;
213 LayoutUnit lowestFloatBottomRight = 0; 213 LayoutUnit lowestFloatBottomRight = 0;
214 for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end ; ++it) { 214 for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end ; ++it) {
215 FloatingObject* floatingObject = it->get(); 215 const FloatingObject& floatingObject = *it->get();
216 if (floatingObject->isPlaced()) { 216 if (floatingObject.isPlaced()) {
217 FloatingObject::Type curType = floatingObject->type(); 217 FloatingObject::Type curType = floatingObject.type();
218 LayoutUnit curFloatLogicalBottom = m_layoutObject->logicalBottom ForFloat(floatingObject); 218 LayoutUnit curFloatLogicalBottom = m_layoutObject->logicalBottom ForFloat(floatingObject);
219 if (curType & FloatingObject::FloatLeft) 219 if (curType & FloatingObject::FloatLeft)
220 lowestFloatBottomLeft = std::max(lowestFloatBottomLeft, curF loatLogicalBottom); 220 lowestFloatBottomLeft = std::max(lowestFloatBottomLeft, curF loatLogicalBottom);
221 if (curType & FloatingObject::FloatRight) 221 if (curType & FloatingObject::FloatRight)
222 lowestFloatBottomRight = std::max(lowestFloatBottomRight, cu rFloatLogicalBottom); 222 lowestFloatBottomRight = std::max(lowestFloatBottomRight, cu rFloatLogicalBottom);
223 } 223 }
224 } 224 }
225 lowestFloatBottom = std::max(lowestFloatBottomLeft, lowestFloatBottomRig ht); 225 lowestFloatBottom = std::max(lowestFloatBottomLeft, lowestFloatBottomRig ht);
226 setCachedLowestFloatLogicalBottom(isInHorizontalWritingMode, FloatingObj ect::FloatLeft, lowestFloatBottomLeft); 226 setCachedLowestFloatLogicalBottom(isInHorizontalWritingMode, FloatingObj ect::FloatLeft, lowestFloatBottomLeft);
227 setCachedLowestFloatLogicalBottom(isInHorizontalWritingMode, FloatingObj ect::FloatRight, lowestFloatBottomRight); 227 setCachedLowestFloatLogicalBottom(isInHorizontalWritingMode, FloatingObj ect::FloatRight, lowestFloatBottomRight);
228 } else { 228 } else {
229 for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end ; ++it) { 229 for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end ; ++it) {
230 FloatingObject* floatingObject = it->get(); 230 const FloatingObject& floatingObject = *it->get();
231 if (floatingObject->isPlaced() && floatingObject->type() == floatTyp e) 231 if (floatingObject.isPlaced() && floatingObject.type() == floatType)
232 lowestFloatBottom = std::max(lowestFloatBottom, m_layoutObject-> logicalBottomForFloat(floatingObject)); 232 lowestFloatBottom = std::max(lowestFloatBottom, m_layoutObject-> logicalBottomForFloat(floatingObject));
233 } 233 }
234 setCachedLowestFloatLogicalBottom(isInHorizontalWritingMode, floatType, lowestFloatBottom); 234 setCachedLowestFloatLogicalBottom(isInHorizontalWritingMode, floatType, lowestFloatBottom);
235 } 235 }
236 236
237 return lowestFloatBottom; 237 return lowestFloatBottom;
238 } 238 }
239 239
240 bool FloatingObjects::hasLowestFloatLogicalBottomCached(bool isHorizontal, Float ingObject::Type type) const 240 bool FloatingObjects::hasLowestFloatLogicalBottomCached(bool isHorizontal, Float ingObject::Type type) const
241 { 241 {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 } 288 }
289 289
290 inline void FloatingObjects::decreaseObjectsCount(FloatingObject::Type type) 290 inline void FloatingObjects::decreaseObjectsCount(FloatingObject::Type type)
291 { 291 {
292 if (type == FloatingObject::FloatLeft) 292 if (type == FloatingObject::FloatLeft)
293 m_leftObjectsCount--; 293 m_leftObjectsCount--;
294 else 294 else
295 m_rightObjectsCount--; 295 m_rightObjectsCount--;
296 } 296 }
297 297
298 inline FloatingObjectInterval FloatingObjects::intervalForFloatingObject(Floatin gObject* floatingObject) 298 inline FloatingObjectInterval FloatingObjects::intervalForFloatingObject(Floatin gObject& floatingObject)
299 { 299 {
300 if (m_horizontalWritingMode) 300 if (m_horizontalWritingMode)
301 return FloatingObjectInterval(floatingObject->frameRect().pixelSnappedY( ), floatingObject->frameRect().pixelSnappedMaxY(), floatingObject); 301 return FloatingObjectInterval(floatingObject.frameRect().pixelSnappedY() , floatingObject.frameRect().pixelSnappedMaxY(), &floatingObject);
302 return FloatingObjectInterval(floatingObject->frameRect().pixelSnappedX(), f loatingObject->frameRect().pixelSnappedMaxX(), floatingObject); 302 return FloatingObjectInterval(floatingObject.frameRect().pixelSnappedX(), fl oatingObject.frameRect().pixelSnappedMaxX(), &floatingObject);
303 } 303 }
304 304
305 void FloatingObjects::addPlacedObject(FloatingObject* floatingObject) 305 void FloatingObjects::addPlacedObject(FloatingObject& floatingObject)
306 { 306 {
307 ASSERT(!floatingObject->isInPlacedTree()); 307 ASSERT(!floatingObject.isInPlacedTree());
308 308
309 floatingObject->setIsPlaced(true); 309 floatingObject.setIsPlaced(true);
310 if (m_placedFloatsTree.isInitialized()) 310 if (m_placedFloatsTree.isInitialized())
311 m_placedFloatsTree.add(intervalForFloatingObject(floatingObject)); 311 m_placedFloatsTree.add(intervalForFloatingObject(floatingObject));
312 312
313 #if ENABLE(ASSERT) 313 #if ENABLE(ASSERT)
314 floatingObject->setIsInPlacedTree(true); 314 floatingObject.setIsInPlacedTree(true);
315 #endif 315 #endif
316 markLowestFloatLogicalBottomCacheAsDirty(); 316 markLowestFloatLogicalBottomCacheAsDirty();
317 } 317 }
318 318
319 void FloatingObjects::removePlacedObject(FloatingObject* floatingObject) 319 void FloatingObjects::removePlacedObject(FloatingObject& floatingObject)
320 { 320 {
321 ASSERT(floatingObject->isPlaced() && floatingObject->isInPlacedTree()); 321 ASSERT(floatingObject.isPlaced() && floatingObject.isInPlacedTree());
322 322
323 if (m_placedFloatsTree.isInitialized()) { 323 if (m_placedFloatsTree.isInitialized()) {
324 bool removed = m_placedFloatsTree.remove(intervalForFloatingObject(float ingObject)); 324 bool removed = m_placedFloatsTree.remove(intervalForFloatingObject(float ingObject));
325 ASSERT_UNUSED(removed, removed); 325 ASSERT_UNUSED(removed, removed);
326 } 326 }
327 327
328 floatingObject->setIsPlaced(false); 328 floatingObject.setIsPlaced(false);
329 #if ENABLE(ASSERT) 329 #if ENABLE(ASSERT)
330 floatingObject->setIsInPlacedTree(false); 330 floatingObject.setIsInPlacedTree(false);
331 #endif 331 #endif
332 markLowestFloatLogicalBottomCacheAsDirty(); 332 markLowestFloatLogicalBottomCacheAsDirty();
333 } 333 }
334 334
335 FloatingObject* FloatingObjects::add(PassOwnPtr<FloatingObject> floatingObject) 335 FloatingObject* FloatingObjects::add(PassOwnPtr<FloatingObject> floatingObject)
336 { 336 {
337 FloatingObject* newObject = floatingObject.leakPtr(); 337 FloatingObject* newObject = floatingObject.leakPtr();
338 increaseObjectsCount(newObject->type()); 338 increaseObjectsCount(newObject->type());
339 m_set.add(adoptPtr(newObject)); 339 m_set.add(adoptPtr(newObject));
340 if (newObject->isPlaced()) 340 if (newObject->isPlaced())
341 addPlacedObject(newObject); 341 addPlacedObject(*newObject);
342 markLowestFloatLogicalBottomCacheAsDirty(); 342 markLowestFloatLogicalBottomCacheAsDirty();
343 return newObject; 343 return newObject;
344 } 344 }
345 345
346 void FloatingObjects::remove(FloatingObject* toBeRemoved) 346 void FloatingObjects::remove(FloatingObject* toBeRemoved)
347 { 347 {
348 decreaseObjectsCount(toBeRemoved->type()); 348 decreaseObjectsCount(toBeRemoved->type());
349 OwnPtr<FloatingObject> floatingObject = m_set.take(toBeRemoved); 349 OwnPtr<FloatingObject> floatingObject = m_set.take(toBeRemoved);
350 ASSERT(floatingObject->isPlaced() || !floatingObject->isInPlacedTree()); 350 ASSERT(floatingObject->isPlaced() || !floatingObject->isInPlacedTree());
351 if (floatingObject->isPlaced()) 351 if (floatingObject->isPlaced())
352 removePlacedObject(floatingObject.get()); 352 removePlacedObject(*floatingObject);
353 markLowestFloatLogicalBottomCacheAsDirty(); 353 markLowestFloatLogicalBottomCacheAsDirty();
354 ASSERT(!floatingObject->originatingLine()); 354 ASSERT(!floatingObject->originatingLine());
355 } 355 }
356 356
357 void FloatingObjects::computePlacedFloatsTree() 357 void FloatingObjects::computePlacedFloatsTree()
358 { 358 {
359 ASSERT(!m_placedFloatsTree.isInitialized()); 359 ASSERT(!m_placedFloatsTree.isInitialized());
360 if (m_set.isEmpty()) 360 if (m_set.isEmpty())
361 return; 361 return;
362 m_placedFloatsTree.initIfNeeded(m_layoutObject->view()->intervalArena()); 362 m_placedFloatsTree.initIfNeeded(m_layoutObject->view()->intervalArena());
363 FloatingObjectSetIterator it = m_set.begin(); 363 FloatingObjectSetIterator it = m_set.begin();
364 FloatingObjectSetIterator end = m_set.end(); 364 FloatingObjectSetIterator end = m_set.end();
365 for (; it != end; ++it) { 365 for (; it != end; ++it) {
366 FloatingObject* floatingObject = it->get(); 366 FloatingObject& floatingObject = *it->get();
367 if (floatingObject->isPlaced()) 367 if (floatingObject.isPlaced())
368 m_placedFloatsTree.add(intervalForFloatingObject(floatingObject)); 368 m_placedFloatsTree.add(intervalForFloatingObject(floatingObject));
369 } 369 }
370 } 370 }
371 371
372 LayoutUnit FloatingObjects::logicalLeftOffsetForPositioningFloat(LayoutUnit fixe dOffset, LayoutUnit logicalTop, LayoutUnit *heightRemaining) 372 LayoutUnit FloatingObjects::logicalLeftOffsetForPositioningFloat(LayoutUnit fixe dOffset, LayoutUnit logicalTop, LayoutUnit *heightRemaining)
373 { 373 {
374 int logicalTopAsInt = roundToInt(logicalTop); 374 int logicalTopAsInt = roundToInt(logicalTop);
375 ComputeFloatOffsetForFloatLayoutAdapter<FloatingObject::FloatLeft> adapter(m _layoutObject, logicalTopAsInt, logicalTopAsInt, fixedOffset); 375 ComputeFloatOffsetForFloatLayoutAdapter<FloatingObject::FloatLeft> adapter(m _layoutObject, logicalTopAsInt, logicalTopAsInt, fixedOffset);
376 placedFloatsTree().allOverlapsWithAdapter(adapter); 376 placedFloatsTree().allOverlapsWithAdapter(adapter);
377 377
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 // The bottom of the object overlaps the float 431 // The bottom of the object overlaps the float
432 if (objectBottom > objectTop && objectBottom > floatTop && objectBottom <= f loatBottom) 432 if (objectBottom > objectTop && objectBottom > floatTop && objectBottom <= f loatBottom)
433 return true; 433 return true;
434 434
435 return false; 435 return false;
436 } 436 }
437 437
438 template<> 438 template<>
439 inline bool ComputeFloatOffsetForFloatLayoutAdapter<FloatingObject::FloatLeft>:: updateOffsetIfNeeded(const FloatingObject& floatingObject) 439 inline bool ComputeFloatOffsetForFloatLayoutAdapter<FloatingObject::FloatLeft>:: updateOffsetIfNeeded(const FloatingObject& floatingObject)
440 { 440 {
441 LayoutUnit logicalRight = m_layoutObject->logicalRightForFloat(&floatingObje ct); 441 LayoutUnit logicalRight = m_layoutObject->logicalRightForFloat(floatingObjec t);
442 if (logicalRight > m_offset) { 442 if (logicalRight > m_offset) {
443 m_offset = logicalRight; 443 m_offset = logicalRight;
444 return true; 444 return true;
445 } 445 }
446 return false; 446 return false;
447 } 447 }
448 448
449 template<> 449 template<>
450 inline bool ComputeFloatOffsetForFloatLayoutAdapter<FloatingObject::FloatRight>: :updateOffsetIfNeeded(const FloatingObject& floatingObject) 450 inline bool ComputeFloatOffsetForFloatLayoutAdapter<FloatingObject::FloatRight>: :updateOffsetIfNeeded(const FloatingObject& floatingObject)
451 { 451 {
452 LayoutUnit logicalLeft = m_layoutObject->logicalLeftForFloat(&floatingObject ); 452 LayoutUnit logicalLeft = m_layoutObject->logicalLeftForFloat(floatingObject) ;
453 if (logicalLeft < m_offset) { 453 if (logicalLeft < m_offset) {
454 m_offset = logicalLeft; 454 m_offset = logicalLeft;
455 return true; 455 return true;
456 } 456 }
457 return false; 457 return false;
458 } 458 }
459 459
460 template <FloatingObject::Type FloatTypeValue> 460 template <FloatingObject::Type FloatTypeValue>
461 LayoutUnit ComputeFloatOffsetForFloatLayoutAdapter<FloatTypeValue>::heightRemain ing() const 461 LayoutUnit ComputeFloatOffsetForFloatLayoutAdapter<FloatTypeValue>::heightRemain ing() const
462 { 462 {
463 return this->m_outermostFloat ? this->m_layoutObject->logicalBottomForFloat( this->m_outermostFloat) - this->m_lineTop : LayoutUnit(1); 463 return this->m_outermostFloat ? this->m_layoutObject->logicalBottomForFloat( *(this->m_outermostFloat)) - this->m_lineTop : LayoutUnit(1);
Julien - ping for review 2015/06/10 15:15:44 I don't think the parentheses are needed here due
Sunil Ratnu 2015/06/11 05:49:43 Done.
464 } 464 }
465 465
466 template <FloatingObject::Type FloatTypeValue> 466 template <FloatingObject::Type FloatTypeValue>
467 inline void ComputeFloatOffsetAdapter<FloatTypeValue>::collectIfNeeded(const Int ervalType& interval) 467 inline void ComputeFloatOffsetAdapter<FloatTypeValue>::collectIfNeeded(const Int ervalType& interval)
468 { 468 {
469 const FloatingObject* floatingObject = interval.data(); 469 const FloatingObject& floatingObject = *(interval.data());
470 if (floatingObject->type() != FloatTypeValue || !rangesIntersect(interval.lo w(), interval.high(), m_lineTop, m_lineBottom)) 470 if (floatingObject.type() != FloatTypeValue || !rangesIntersect(interval.low (), interval.high(), m_lineTop, m_lineBottom))
471 return; 471 return;
472 472
473 // Make sure the float hasn't changed since it was added to the placed float s tree. 473 // Make sure the float hasn't changed since it was added to the placed float s tree.
474 ASSERT(floatingObject->isPlaced()); 474 ASSERT(floatingObject.isPlaced());
475 ASSERT(interval.low() == m_layoutObject->pixelSnappedLogicalTopForFloat(floa tingObject)); 475 ASSERT(interval.low() == m_layoutObject->pixelSnappedLogicalTopForFloat(floa tingObject));
476 ASSERT(interval.high() == m_layoutObject->pixelSnappedLogicalBottomForFloat( floatingObject)); 476 ASSERT(interval.high() == m_layoutObject->pixelSnappedLogicalBottomForFloat( floatingObject));
477 477
478 bool floatIsNewExtreme = updateOffsetIfNeeded(*floatingObject); 478 bool floatIsNewExtreme = updateOffsetIfNeeded(floatingObject);
479 if (floatIsNewExtreme) 479 if (floatIsNewExtreme)
480 m_outermostFloat = floatingObject; 480 m_outermostFloat = &floatingObject;
481 } 481 }
482 482
483 template<> 483 template<>
484 inline bool ComputeFloatOffsetForLineLayoutAdapter<FloatingObject::FloatLeft>::u pdateOffsetIfNeeded(const FloatingObject& floatingObject) 484 inline bool ComputeFloatOffsetForLineLayoutAdapter<FloatingObject::FloatLeft>::u pdateOffsetIfNeeded(const FloatingObject& floatingObject)
485 { 485 {
486 LayoutUnit logicalRight = m_layoutObject->logicalRightForFloat(&floatingObje ct); 486 LayoutUnit logicalRight = m_layoutObject->logicalRightForFloat(floatingObjec t);
487 if (ShapeOutsideInfo* shapeOutside = floatingObject.layoutObject()->shapeOut sideInfo()) { 487 if (ShapeOutsideInfo* shapeOutside = floatingObject.layoutObject()->shapeOut sideInfo()) {
488 ShapeOutsideDeltas shapeDeltas = shapeOutside->computeDeltasForContainin gBlockLine(*m_layoutObject, floatingObject, m_lineTop, m_lineBottom - m_lineTop) ; 488 ShapeOutsideDeltas shapeDeltas = shapeOutside->computeDeltasForContainin gBlockLine(*m_layoutObject, floatingObject, m_lineTop, m_lineBottom - m_lineTop) ;
489 if (!shapeDeltas.lineOverlapsShape()) 489 if (!shapeDeltas.lineOverlapsShape())
490 return false; 490 return false;
491 491
492 logicalRight += shapeDeltas.rightMarginBoxDelta(); 492 logicalRight += shapeDeltas.rightMarginBoxDelta();
493 } 493 }
494 if (logicalRight > m_offset) { 494 if (logicalRight > m_offset) {
495 m_offset = logicalRight; 495 m_offset = logicalRight;
496 return true; 496 return true;
497 } 497 }
498 498
499 return false; 499 return false;
500 } 500 }
501 501
502 template<> 502 template<>
503 inline bool ComputeFloatOffsetForLineLayoutAdapter<FloatingObject::FloatRight>:: updateOffsetIfNeeded(const FloatingObject& floatingObject) 503 inline bool ComputeFloatOffsetForLineLayoutAdapter<FloatingObject::FloatRight>:: updateOffsetIfNeeded(const FloatingObject& floatingObject)
504 { 504 {
505 LayoutUnit logicalLeft = m_layoutObject->logicalLeftForFloat(&floatingObject ); 505 LayoutUnit logicalLeft = m_layoutObject->logicalLeftForFloat(floatingObject) ;
506 if (ShapeOutsideInfo* shapeOutside = floatingObject.layoutObject()->shapeOut sideInfo()) { 506 if (ShapeOutsideInfo* shapeOutside = floatingObject.layoutObject()->shapeOut sideInfo()) {
507 ShapeOutsideDeltas shapeDeltas = shapeOutside->computeDeltasForContainin gBlockLine(*m_layoutObject, floatingObject, m_lineTop, m_lineBottom - m_lineTop) ; 507 ShapeOutsideDeltas shapeDeltas = shapeOutside->computeDeltasForContainin gBlockLine(*m_layoutObject, floatingObject, m_lineTop, m_lineBottom - m_lineTop) ;
508 if (!shapeDeltas.lineOverlapsShape()) 508 if (!shapeDeltas.lineOverlapsShape())
509 return false; 509 return false;
510 510
511 logicalLeft += shapeDeltas.leftMarginBoxDelta(); 511 logicalLeft += shapeDeltas.leftMarginBoxDelta();
512 } 512 }
513 if (logicalLeft < m_offset) { 513 if (logicalLeft < m_offset) {
514 m_offset = logicalLeft; 514 m_offset = logicalLeft;
515 return true; 515 return true;
(...skipping 10 matching lines...) Expand all
526 } 526 }
527 527
528 String ValueToString<FloatingObject*>::string(const FloatingObject* floatingObje ct) 528 String ValueToString<FloatingObject*>::string(const FloatingObject* floatingObje ct)
529 { 529 {
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()); 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());
531 } 531 }
532 #endif 532 #endif
533 533
534 534
535 } // namespace blink 535 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698