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

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

Issue 1043643002: Switch line layout to LayoutUnit. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: More TestExpectations tweaks 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/layout/LayoutDeprecatedFlexibleBox.cpp ('k') | Source/core/layout/LayoutObject.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 ASSERT_UNUSED(inlineBox, !inlineBox); 268 ASSERT_UNUSED(inlineBox, !inlineBox);
269 269
270 if (extraWidthToEndOfLine) 270 if (extraWidthToEndOfLine)
271 *extraWidthToEndOfLine = 0; 271 *extraWidthToEndOfLine = 0;
272 272
273 LayoutRect caretRect = localCaretRectForEmptyElement(borderAndPaddingWidth() , 0); 273 LayoutRect caretRect = localCaretRectForEmptyElement(borderAndPaddingWidth() , 0);
274 274
275 if (InlineBox* firstBox = firstLineBox()) { 275 if (InlineBox* firstBox = firstLineBox()) {
276 // FIXME: the call to roundedLayoutPoint() below is temporary and should be removed once 276 // FIXME: the call to roundedLayoutPoint() below is temporary and should be removed once
277 // the transition to LayoutUnit-based types is complete (crbug.com/32123 7) 277 // the transition to LayoutUnit-based types is complete (crbug.com/32123 7)
278 caretRect.moveBy(firstBox->topLeft().roundedLayoutPoint()); 278 caretRect.moveBy(firstBox->topLeft());
279 } 279 }
280 280
281 return caretRect; 281 return caretRect;
282 } 282 }
283 283
284 void LayoutInline::addChild(LayoutObject* newChild, LayoutObject* beforeChild) 284 void LayoutInline::addChild(LayoutObject* newChild, LayoutObject* beforeChild)
285 { 285 {
286 if (continuation()) 286 if (continuation())
287 return addChildToContinuation(newChild, beforeChild); 287 return addChildToContinuation(newChild, beforeChild);
288 return addChildIgnoringContinuation(newChild, beforeChild); 288 return addChildIgnoringContinuation(newChild, beforeChild);
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 InlinePainter(*this).paint(paintInfo, paintOffset); 554 InlinePainter(*this).paint(paintInfo, paintOffset);
555 } 555 }
556 556
557 template<typename GeneratorContext> 557 template<typename GeneratorContext>
558 void LayoutInline::generateLineBoxRects(GeneratorContext& yield) const 558 void LayoutInline::generateLineBoxRects(GeneratorContext& yield) const
559 { 559 {
560 if (!alwaysCreateLineBoxes()) { 560 if (!alwaysCreateLineBoxes()) {
561 generateCulledLineBoxRects(yield, this); 561 generateCulledLineBoxRects(yield, this);
562 } else if (InlineFlowBox* curr = firstLineBox()) { 562 } else if (InlineFlowBox* curr = firstLineBox()) {
563 for (; curr; curr = curr->nextLineBox()) 563 for (; curr; curr = curr->nextLineBox())
564 yield(FloatRect(curr->topLeft().toFloatPoint(), curr->size().toFloat Size())); 564 yield(LayoutRect(curr->topLeft(), curr->size()));
565 } else { 565 } else {
566 yield(FloatRect()); 566 yield(LayoutRect());
567 } 567 }
568 } 568 }
569 569
570 template<typename GeneratorContext> 570 template<typename GeneratorContext>
571 void LayoutInline::generateCulledLineBoxRects(GeneratorContext& yield, const Lay outInline* container) const 571 void LayoutInline::generateCulledLineBoxRects(GeneratorContext& yield, const Lay outInline* container) const
572 { 572 {
573 if (!culledInlineFirstLineBox()) { 573 if (!culledInlineFirstLineBox()) {
574 yield(FloatRect()); 574 yield(LayoutRect());
575 return; 575 return;
576 } 576 }
577 577
578 bool isHorizontal = style()->isHorizontalWritingMode(); 578 bool isHorizontal = style()->isHorizontalWritingMode();
579 579
580 for (LayoutObject* curr = firstChild(); curr; curr = curr->nextSibling()) { 580 for (LayoutObject* curr = firstChild(); curr; curr = curr->nextSibling()) {
581 if (curr->isFloatingOrOutOfFlowPositioned()) 581 if (curr->isFloatingOrOutOfFlowPositioned())
582 continue; 582 continue;
583 583
584 // We want to get the margin box in the inline direction, and then use o ur font ascent/descent in the block 584 // We want to get the margin box in the inline direction, and then use o ur font ascent/descent in the block
585 // direction (aligned to the root box's baseline). 585 // direction (aligned to the root box's baseline).
586 if (curr->isBox()) { 586 if (curr->isBox()) {
587 LayoutBox* currBox = toLayoutBox(curr); 587 LayoutBox* currBox = toLayoutBox(curr);
588 if (currBox->inlineBoxWrapper()) { 588 if (currBox->inlineBoxWrapper()) {
589 RootInlineBox& rootBox = currBox->inlineBoxWrapper()->root(); 589 RootInlineBox& rootBox = currBox->inlineBoxWrapper()->root();
590 int logicalTop = rootBox.logicalTop() + (rootBox.layoutObject(). style(rootBox.isFirstLineStyle())->font().fontMetrics().ascent() - container->st yle(rootBox.isFirstLineStyle())->font().fontMetrics().ascent()); 590 int logicalTop = rootBox.logicalTop() + (rootBox.layoutObject(). style(rootBox.isFirstLineStyle())->font().fontMetrics().ascent() - container->st yle(rootBox.isFirstLineStyle())->font().fontMetrics().ascent());
591 int logicalHeight = container->style(rootBox.isFirstLineStyle()) ->font().fontMetrics().height(); 591 int logicalHeight = container->style(rootBox.isFirstLineStyle()) ->font().fontMetrics().height();
592 if (isHorizontal) 592 if (isHorizontal)
593 yield(FloatRect(currBox->inlineBoxWrapper()->x() - currBox-> marginLeft(), logicalTop, (currBox->size().width() + currBox->marginWidth()).toF loat(), logicalHeight)); 593 yield(LayoutRect(currBox->inlineBoxWrapper()->x() - currBox- >marginLeft(), logicalTop, currBox->size().width() + currBox->marginWidth(), log icalHeight));
594 else 594 else
595 yield(FloatRect(logicalTop, currBox->inlineBoxWrapper()->y() - currBox->marginTop(), logicalHeight, (currBox->size().height() + currBox->mar ginHeight()).toFloat())); 595 yield(LayoutRect(logicalTop, currBox->inlineBoxWrapper()->y( ) - currBox->marginTop(), logicalHeight, currBox->size().height() + currBox->mar ginHeight()));
596 } 596 }
597 } else if (curr->isLayoutInline()) { 597 } else if (curr->isLayoutInline()) {
598 // If the child doesn't need line boxes either, then we can recur. 598 // If the child doesn't need line boxes either, then we can recur.
599 LayoutInline* currInline = toLayoutInline(curr); 599 LayoutInline* currInline = toLayoutInline(curr);
600 if (!currInline->alwaysCreateLineBoxes()) { 600 if (!currInline->alwaysCreateLineBoxes()) {
601 currInline->generateCulledLineBoxRects(yield, container); 601 currInline->generateCulledLineBoxRects(yield, container);
602 } else { 602 } else {
603 for (InlineFlowBox* childLine = currInline->firstLineBox(); chil dLine; childLine = childLine->nextLineBox()) { 603 for (InlineFlowBox* childLine = currInline->firstLineBox(); chil dLine; childLine = childLine->nextLineBox()) {
604 RootInlineBox& rootBox = childLine->root(); 604 RootInlineBox& rootBox = childLine->root();
605 int logicalTop = rootBox.logicalTop() + (rootBox.layoutObjec t().style(rootBox.isFirstLineStyle())->font().fontMetrics().ascent() - container ->style(rootBox.isFirstLineStyle())->font().fontMetrics().ascent()); 605 int logicalTop = rootBox.logicalTop() + (rootBox.layoutObjec t().style(rootBox.isFirstLineStyle())->font().fontMetrics().ascent() - container ->style(rootBox.isFirstLineStyle())->font().fontMetrics().ascent());
606 int logicalHeight = container->style(rootBox.isFirstLineStyl e())->font().fontMetrics().height(); 606 int logicalHeight = container->style(rootBox.isFirstLineStyl e())->font().fontMetrics().height();
607 if (isHorizontal) { 607 if (isHorizontal) {
608 yield(FloatRect(childLine->x() - childLine->marginLogica lLeft(), 608 yield(LayoutRect(childLine->x() - childLine->marginLogic alLeft(),
609 logicalTop, 609 logicalTop,
610 childLine->logicalWidth() + childLine->marginLogical Left() + childLine->marginLogicalRight(), 610 childLine->logicalWidth() + childLine->marginLogical Left() + childLine->marginLogicalRight(),
611 logicalHeight)); 611 logicalHeight));
612 } else { 612 } else {
613 yield(FloatRect(logicalTop, 613 yield(LayoutRect(logicalTop,
614 childLine->y() - childLine->marginLogicalLeft(), 614 childLine->y() - childLine->marginLogicalLeft(),
615 logicalHeight, 615 logicalHeight,
616 childLine->logicalWidth() + childLine->marginLogical Left() + childLine->marginLogicalRight())); 616 childLine->logicalWidth() + childLine->marginLogical Left() + childLine->marginLogicalRight()));
617 } 617 }
618 } 618 }
619 } 619 }
620 } else if (curr->isText()) { 620 } else if (curr->isText()) {
621 LayoutText* currText = toLayoutText(curr); 621 LayoutText* currText = toLayoutText(curr);
622 for (InlineTextBox* childText = currText->firstTextBox(); childText; childText = childText->nextTextBox()) { 622 for (InlineTextBox* childText = currText->firstTextBox(); childText; childText = childText->nextTextBox()) {
623 RootInlineBox& rootBox = childText->root(); 623 RootInlineBox& rootBox = childText->root();
624 int logicalTop = rootBox.logicalTop() + (rootBox.layoutObject(). style(rootBox.isFirstLineStyle())->font().fontMetrics().ascent() - container->st yle(rootBox.isFirstLineStyle())->font().fontMetrics().ascent()); 624 int logicalTop = rootBox.logicalTop() + (rootBox.layoutObject(). style(rootBox.isFirstLineStyle())->font().fontMetrics().ascent() - container->st yle(rootBox.isFirstLineStyle())->font().fontMetrics().ascent());
625 int logicalHeight = container->style(rootBox.isFirstLineStyle()) ->font().fontMetrics().height(); 625 int logicalHeight = container->style(rootBox.isFirstLineStyle()) ->font().fontMetrics().height();
626 if (isHorizontal) 626 if (isHorizontal)
627 yield(FloatRect(childText->x(), logicalTop, childText->logic alWidth(), logicalHeight)); 627 yield(LayoutRect(childText->x(), logicalTop, childText->logi calWidth(), logicalHeight));
628 else 628 else
629 yield(FloatRect(logicalTop, childText->y(), logicalHeight, c hildText->logicalWidth())); 629 yield(LayoutRect(logicalTop, childText->y(), logicalHeight, childText->logicalWidth()));
630 } 630 }
631 } 631 }
632 } 632 }
633 } 633 }
634 634
635 namespace { 635 namespace {
636 636
637 class AbsoluteRectsGeneratorContext { 637 class AbsoluteRectsGeneratorContext {
638 public: 638 public:
639 AbsoluteRectsGeneratorContext(Vector<IntRect>& rects, const LayoutPoint& acc umulatedOffset) 639 AbsoluteRectsGeneratorContext(Vector<IntRect>& rects, const LayoutPoint& acc umulatedOffset)
640 : m_rects(rects) 640 : m_rects(rects)
641 , m_accumulatedOffset(accumulatedOffset) { } 641 , m_accumulatedOffset(accumulatedOffset) { }
642 642
643 void operator()(const FloatRect& rect) 643 void operator()(const LayoutRect& rect)
644 { 644 {
645 IntRect intRect = enclosingIntRect(rect); 645 IntRect intRect = enclosingIntRect(rect);
646 intRect.move(m_accumulatedOffset.x(), m_accumulatedOffset.y()); 646 intRect.move(m_accumulatedOffset.x(), m_accumulatedOffset.y());
647 m_rects.append(intRect); 647 m_rects.append(intRect);
648 } 648 }
649 private: 649 private:
650 Vector<IntRect>& m_rects; 650 Vector<IntRect>& m_rects;
651 const LayoutPoint& m_accumulatedOffset; 651 const LayoutPoint& m_accumulatedOffset;
652 }; 652 };
653 653
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 generateLineBoxRects(context); 697 generateLineBoxRects(context);
698 698
699 if (const LayoutBoxModelObject* continuation = this->continuation()) 699 if (const LayoutBoxModelObject* continuation = this->continuation())
700 continuation->absoluteQuads(quads, wasFixed); 700 continuation->absoluteQuads(quads, wasFixed);
701 } 701 }
702 702
703 LayoutUnit LayoutInline::offsetLeft() const 703 LayoutUnit LayoutInline::offsetLeft() const
704 { 704 {
705 LayoutPoint topLeft; 705 LayoutPoint topLeft;
706 if (InlineBox* firstBox = firstLineBoxIncludingCulling()) { 706 if (InlineBox* firstBox = firstLineBoxIncludingCulling()) {
707 // FIXME: the call to flooredLayoutPoint() below is temporary and should be removed once 707 topLeft = firstBox->topLeft();
708 // the transition to LayoutUnit-based types is complete (crbug.com/32123 7)
709 topLeft = firstBox->topLeft().flooredLayoutPoint();
710 } 708 }
711 return adjustedPositionRelativeToOffsetParent(topLeft).x(); 709 return adjustedPositionRelativeToOffsetParent(topLeft).x();
712 } 710 }
713 711
714 LayoutUnit LayoutInline::offsetTop() const 712 LayoutUnit LayoutInline::offsetTop() const
715 { 713 {
716 LayoutPoint topLeft; 714 LayoutPoint topLeft;
717 if (InlineBox* firstBox = firstLineBoxIncludingCulling()) { 715 if (InlineBox* firstBox = firstLineBoxIncludingCulling()) {
718 // FIXME: the call to flooredLayoutPoint() below is temporary and should be removed once 716 topLeft = firstBox->topLeft();
719 // the transition to LayoutUnit-based types is complete (crbug.com/32123 7)
720 topLeft = firstBox->topLeft().flooredLayoutPoint();
721 } 717 }
722 return adjustedPositionRelativeToOffsetParent(topLeft).y(); 718 return adjustedPositionRelativeToOffsetParent(topLeft).y();
723 } 719 }
724 720
725 static LayoutUnit computeMargin(const LayoutInline* layoutObject, const Length& margin) 721 static LayoutUnit computeMargin(const LayoutInline* layoutObject, const Length& margin)
726 { 722 {
727 if (margin.isFixed()) 723 if (margin.isFixed())
728 return margin.value(); 724 return margin.value();
729 if (margin.hasPercent()) 725 if (margin.hasPercent())
730 return minimumValueForLength(margin, std::max(LayoutUnit(), layoutObject ->containingBlock()->availableLogicalWidth())); 726 return minimumValueForLength(margin, std::max(LayoutUnit(), layoutObject ->containingBlock()->availableLogicalWidth()));
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 } 868 }
873 869
874 IntRect result; 870 IntRect result;
875 871
876 // See <rdar://problem/5289721>, for an unknown reason the linked list here is sometimes inconsistent, first is non-zero and last is zero. We have been 872 // See <rdar://problem/5289721>, for an unknown reason the linked list here is sometimes inconsistent, first is non-zero and last is zero. We have been
877 // unable to reproduce this at all (and consequently unable to figure ot why this is happening). The assert will hopefully catch the problem in debug 873 // unable to reproduce this at all (and consequently unable to figure ot why this is happening). The assert will hopefully catch the problem in debug
878 // builds and help us someday figure out why. We also put in a redundant ch eck of lastLineBox() to avoid the crash for now. 874 // builds and help us someday figure out why. We also put in a redundant ch eck of lastLineBox() to avoid the crash for now.
879 ASSERT(!firstLineBox() == !lastLineBox()); // Either both are null or both e xist. 875 ASSERT(!firstLineBox() == !lastLineBox()); // Either both are null or both e xist.
880 if (firstLineBox() && lastLineBox()) { 876 if (firstLineBox() && lastLineBox()) {
881 // Return the width of the minimal left side and the maximal right side. 877 // Return the width of the minimal left side and the maximal right side.
882 float logicalLeftSide = 0; 878 LayoutUnit logicalLeftSide = 0;
883 float logicalRightSide = 0; 879 LayoutUnit logicalRightSide = 0;
884 for (InlineFlowBox* curr = firstLineBox(); curr; curr = curr->nextLineBo x()) { 880 for (InlineFlowBox* curr = firstLineBox(); curr; curr = curr->nextLineBo x()) {
885 if (curr == firstLineBox() || curr->logicalLeft() < logicalLeftSide) 881 if (curr == firstLineBox() || curr->logicalLeft() < logicalLeftSide)
886 logicalLeftSide = curr->logicalLeft(); 882 logicalLeftSide = curr->logicalLeft();
887 if (curr == firstLineBox() || curr->logicalRight() > logicalRightSid e) 883 if (curr == firstLineBox() || curr->logicalRight() > logicalRightSid e)
888 logicalRightSide = curr->logicalRight(); 884 logicalRightSide = curr->logicalRight();
889 } 885 }
890 886
891 bool isHorizontal = style()->isHorizontalWritingMode(); 887 bool isHorizontal = style()->isHorizontalWritingMode();
892 888
893 float x = isHorizontal ? logicalLeftSide : firstLineBox()->x().toFloat() ; 889 LayoutUnit x = isHorizontal ? logicalLeftSide : firstLineBox()->x();
894 float y = isHorizontal ? firstLineBox()->y().toFloat() : logicalLeftSide ; 890 LayoutUnit y = isHorizontal ? firstLineBox()->y() : logicalLeftSide;
895 float width = isHorizontal ? logicalRightSide - logicalLeftSide : lastLi neBox()->logicalBottom() - x; 891 LayoutUnit width = isHorizontal ? logicalRightSide - logicalLeftSide : l astLineBox()->logicalBottom() - x;
896 float height = isHorizontal ? lastLineBox()->logicalBottom() - y : logic alRightSide - logicalLeftSide; 892 LayoutUnit height = isHorizontal ? lastLineBox()->logicalBottom() - y : logicalRightSide - logicalLeftSide;
897 result = enclosingIntRect(FloatRect(x, y, width, height)); 893 result = enclosingIntRect(LayoutRect(x, y, width, height));
898 } 894 }
899 895
900 return result; 896 return result;
901 } 897 }
902 898
903 InlineBox* LayoutInline::culledInlineFirstLineBox() const 899 InlineBox* LayoutInline::culledInlineFirstLineBox() const
904 { 900 {
905 for (LayoutObject* curr = firstChild(); curr; curr = curr->nextSibling()) { 901 for (LayoutObject* curr = firstChild(); curr; curr = curr->nextSibling()) {
906 if (curr->isFloatingOrOutOfFlowPositioned()) 902 if (curr->isFloatingOrOutOfFlowPositioned())
907 continue; 903 continue;
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
1327 return LayoutSize(); 1323 return LayoutSize();
1328 1324
1329 // When we have an enclosing relpositioned inline, we need to add in the off set of the first line 1325 // When we have an enclosing relpositioned inline, we need to add in the off set of the first line
1330 // box from the rest of the content, but only in the cases where we know we' re positioned 1326 // box from the rest of the content, but only in the cases where we know we' re positioned
1331 // relative to the inline itself. 1327 // relative to the inline itself.
1332 1328
1333 LayoutSize logicalOffset; 1329 LayoutSize logicalOffset;
1334 LayoutUnit inlinePosition; 1330 LayoutUnit inlinePosition;
1335 LayoutUnit blockPosition; 1331 LayoutUnit blockPosition;
1336 if (firstLineBox()) { 1332 if (firstLineBox()) {
1337 inlinePosition = LayoutUnit::fromFloatRound(firstLineBox()->logicalLeft( )); 1333 inlinePosition = firstLineBox()->logicalLeft();
1338 blockPosition = firstLineBox()->logicalTop(); 1334 blockPosition = firstLineBox()->logicalTop();
1339 } else { 1335 } else {
1340 inlinePosition = layer()->staticInlinePosition(); 1336 inlinePosition = layer()->staticInlinePosition();
1341 blockPosition = layer()->staticBlockPosition(); 1337 blockPosition = layer()->staticBlockPosition();
1342 } 1338 }
1343 1339
1344 // Per http://www.w3.org/TR/CSS2/visudet.html#abs-non-replaced-width an abso lute positioned box 1340 // Per http://www.w3.org/TR/CSS2/visudet.html#abs-non-replaced-width an abso lute positioned box
1345 // with a static position should locate itself as though it is a normal flow box in relation to 1341 // with a static position should locate itself as though it is a normal flow box in relation to
1346 // its containing block. If this relative-positioned inline has a negative o ffset we need to 1342 // its containing block. If this relative-positioned inline has a negative o ffset we need to
1347 // compensate for it so that we align the positioned object with the edge of its containing block. 1343 // compensate for it so that we align the positioned object with the edge of its containing block.
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1449 } 1445 }
1450 1446
1451 void LayoutInline::invalidateDisplayItemClients(const LayoutBoxModelObject& pain tInvalidationContainer) const 1447 void LayoutInline::invalidateDisplayItemClients(const LayoutBoxModelObject& pain tInvalidationContainer) const
1452 { 1448 {
1453 LayoutBoxModelObject::invalidateDisplayItemClients(paintInvalidationContaine r); 1449 LayoutBoxModelObject::invalidateDisplayItemClients(paintInvalidationContaine r);
1454 for (InlineFlowBox* box = firstLineBox(); box; box = box->nextLineBox()) 1450 for (InlineFlowBox* box = firstLineBox(); box; box = box->nextLineBox())
1455 paintInvalidationContainer.invalidateDisplayItemClientOnBacking(*box); 1451 paintInvalidationContainer.invalidateDisplayItemClientOnBacking(*box);
1456 } 1452 }
1457 1453
1458 } // namespace blink 1454 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/layout/LayoutDeprecatedFlexibleBox.cpp ('k') | Source/core/layout/LayoutObject.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698