Changeset 156618 in webkit


Ignore:
Timestamp:
Sep 29, 2013, 1:50:01 PM (11 years ago)
Author:
Antti Koivisto
Message:

Tighten typing in inline rendering
https://bugs.webkit.org/show_bug.cgi?id=122076

Reviewed by Andreas Kling.

More RenderElement, const, &, etc.

  • dom/Position.cpp:

(WebCore::Position::hasRenderedNonAnonymousDescendantsWithHeight):

  • rendering/InlineFlowBox.cpp:

(WebCore::isLastChildForRenderer):
(WebCore::isAncestorAndWithinBlock):
(WebCore::InlineFlowBox::determineSpacingForFlowBoxes):
(WebCore::InlineFlowBox::nodeAtPoint):

  • rendering/InlineIterator.h:

(WebCore::InlineIterator::InlineIterator):
(WebCore::InlineIterator::root):
(WebCore::isEmptyInline):
(WebCore::bidiNextShared):
(WebCore::bidiNextSkippingEmptyInlines):
(WebCore::bidiNextIncludingEmptyInlines):
(WebCore::bidiFirstSkippingEmptyInlines):

  • rendering/RenderBlockLineLayout.cpp:

(WebCore::inlineLogicalWidth):
(WebCore::alwaysRequiresLineBox):
(WebCore::requiresLineBox):
(WebCore::canBreakAtThisPosition):
(WebCore::LineBreaker::nextSegmentBreak):

  • rendering/shapes/ShapeInsideInfo.h:

(WebCore::LineSegmentIterator::LineSegmentIterator):

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r156615 r156618  
     12013-09-29  Antti Koivisto  <antti@apple.com>
     2
     3        Tighten typing in inline rendering
     4        https://bugs.webkit.org/show_bug.cgi?id=122076
     5
     6        Reviewed by Andreas Kling.
     7       
     8        More RenderElement, const, &, etc.
     9
     10        * dom/Position.cpp:
     11        (WebCore::Position::hasRenderedNonAnonymousDescendantsWithHeight):
     12        * rendering/InlineFlowBox.cpp:
     13        (WebCore::isLastChildForRenderer):
     14        (WebCore::isAncestorAndWithinBlock):
     15        (WebCore::InlineFlowBox::determineSpacingForFlowBoxes):
     16        (WebCore::InlineFlowBox::nodeAtPoint):
     17        * rendering/InlineIterator.h:
     18        (WebCore::InlineIterator::InlineIterator):
     19        (WebCore::InlineIterator::root):
     20        (WebCore::isEmptyInline):
     21        (WebCore::bidiNextShared):
     22        (WebCore::bidiNextSkippingEmptyInlines):
     23        (WebCore::bidiNextIncludingEmptyInlines):
     24        (WebCore::bidiFirstSkippingEmptyInlines):
     25        * rendering/RenderBlockLineLayout.cpp:
     26        (WebCore::inlineLogicalWidth):
     27        (WebCore::alwaysRequiresLineBox):
     28        (WebCore::requiresLineBox):
     29        (WebCore::canBreakAtThisPosition):
     30        (WebCore::LineBreaker::nextSegmentBreak):
     31        * rendering/shapes/ShapeInsideInfo.h:
     32        (WebCore::LineSegmentIterator::LineSegmentIterator):
     33
    1342013-09-28  Sam Weinig  <sam@webkit.org>
    235
  • trunk/Source/WebCore/dom/Position.cpp

    r156424 r156618  
    855855{
    856856    RenderObject* stop = renderer.nextInPreOrderAfterChildren();
    857     for (RenderObject* o = renderer.firstChild(); o && o != stop; o = o->nextInPreOrder())
    858         if (o->nonPseudoNode()) {
    859             if ((o->isText() && boundingBoxLogicalHeight(o, toRenderText(o)->linesBoundingBox()))
    860                 || (o->isLineBreak() && boundingBoxLogicalHeight(o, toRenderLineBreak(o)->linesBoundingBox()))
    861                 || (o->isBox() && toRenderBox(o)->pixelSnappedLogicalHeight())
    862                 || (o->isRenderInline() && isEmptyInline(o) && boundingBoxLogicalHeight(o, toRenderInline(o)->linesBoundingBox())))
     857    for (RenderObject* o = renderer.firstChild(); o && o != stop; o = o->nextInPreOrder()) {
     858        if (!o->nonPseudoNode())
     859            continue;
     860        if (o->isText()) {
     861            if (boundingBoxLogicalHeight(o, toRenderText(o)->linesBoundingBox()))
    863862                return true;
    864         }
     863            continue;
     864        }
     865        if (o->isLineBreak()) {
     866            if (boundingBoxLogicalHeight(o, toRenderLineBreak(o)->linesBoundingBox()))
     867                return true;
     868            continue;
     869        }
     870        if (o->isBox()) {
     871            if (toRenderBox(o)->pixelSnappedLogicalHeight())
     872                return true;
     873            continue;
     874        }
     875        if (o->isRenderInline()) {
     876            const RenderInline& renderInline = toRenderInline(*o);
     877            if (isEmptyInline(renderInline) && boundingBoxLogicalHeight(o, renderInline.linesBoundingBox()))
     878                return true;
     879            continue;
     880        }
     881    }
    865882    return false;
    866883}
  • trunk/Source/WebCore/rendering/InlineFlowBox.cpp

    r156613 r156618  
    270270}
    271271
    272 static inline bool isLastChildForRenderer(RenderElement* ancestor, RenderObject* child)
     272static inline bool isLastChildForRenderer(const RenderElement& ancestor, const RenderObject* child)
    273273{
    274274    if (!child)
    275275        return false;
    276276   
    277     if (child == ancestor)
     277    if (child == &ancestor)
    278278        return true;
    279279
    280     RenderObject* curr = child;
    281     RenderElement* parent = curr->parent();
     280    const RenderObject* curr = child;
     281    const RenderElement* parent = curr->parent();
    282282    while (parent && (!parent->isRenderBlock() || parent->isInline())) {
    283283        if (parent->lastChild() != curr)
    284284            return false;
    285         if (parent == ancestor)
     285        if (parent == &ancestor)
    286286            return true;
    287287           
     
    293293}
    294294
    295 static bool isAncestorAndWithinBlock(RenderObject& ancestor, RenderObject* child)
    296 {
    297     RenderObject* object = child;
     295static bool isAncestorAndWithinBlock(const RenderInline& ancestor, const RenderObject* child)
     296{
     297    const RenderObject* object = child;
    298298    while (object && (!object->isRenderBlock() || object->isInline())) {
    299299        if (object == &ancestor)
     
    332332        if (!lineBoxList.lastLineBox()->isConstructed()) {
    333333            RenderInline& inlineFlow = toRenderInline(renderer());
    334             bool isLastObjectOnLine = !isAncestorAndWithinBlock(renderer(), logicallyLastRunRenderer) || (isLastChildForRenderer(&renderer(), logicallyLastRunRenderer) && !isLogicallyLastRunWrapped);
     334            bool isLastObjectOnLine = !isAncestorAndWithinBlock(inlineFlow, logicallyLastRunRenderer) || (isLastChildForRenderer(renderer(), logicallyLastRunRenderer) && !isLogicallyLastRunWrapped);
    335335
    336336            // We include the border under these conditions:
     
    10191019    // Check children first.
    10201020    // We need to account for culled inline parents of the hit-tested nodes, so that they may also get included in area-based hit-tests.
    1021     RenderObject* culledParent = 0;
     1021    RenderElement* culledParent = 0;
    10221022    for (InlineBox* curr = lastChild(); curr; curr = curr->prevOnLine()) {
    10231023        if (curr->renderer().isText() || !curr->boxModelObject()->hasSelfPaintingLayer()) {
    1024             RenderObject* newParent = 0;
     1024            RenderElement* newParent = 0;
    10251025            // Culled parents are only relevant for area-based hit-tests, so ignore it in point-based ones.
    10261026            if (locationInContainer.isRectBasedTest()) {
  • trunk/Source/WebCore/rendering/InlineIterator.h

    r156285 r156618  
    2626#include "BidiRun.h"
    2727#include "RenderBlock.h"
     28#include "RenderInline.h"
    2829#include "RenderText.h"
    2930#include <wtf/StdLibExtras.h>
     
    4445    }
    4546
    46     InlineIterator(RenderObject* root, RenderObject* o, unsigned p)
     47    InlineIterator(RenderElement* root, RenderObject* o, unsigned p)
    4748        : m_root(root)
    4849        , m_obj(o)
     
    6869    RenderObject* object() const { return m_obj; }
    6970    unsigned offset() const { return m_pos; }
    70     RenderObject* root() const { return m_root; }
     71    RenderElement* root() const { return m_root; }
    7172
    7273    void fastIncrementInTextNode();
     
    9192
    9293private:
    93     RenderObject* m_root;
     94    RenderElement* m_root;
    9495
    9596    // FIXME: These should be private.
     
    176177};
    177178
    178 static bool isEmptyInline(RenderObject* object)
    179 {
    180     if (!object->isRenderInline())
    181         return false;
    182 
    183     for (RenderObject* curr = toRenderElement(object)->firstChild(); curr; curr = curr->nextSibling()) {
     179static bool isEmptyInline(const RenderInline& renderer)
     180{
     181    for (RenderObject* curr = renderer.firstChild(); curr; curr = curr->nextSibling()) {
    184182        if (curr->isFloatingOrOutOfFlowPositioned())
    185183            continue;
    186         if (curr->isText() && toRenderText(curr)->isAllCollapsibleWhitespace())
     184        if (curr->isText()) {
     185            if (!toRenderText(curr)->isAllCollapsibleWhitespace())
     186                return false;
    187187            continue;
    188 
    189         if (!isEmptyInline(curr))
     188        }
     189        if (!curr->isRenderInline() || !isEmptyInline(toRenderInline(*curr)))
    190190            return false;
    191191    }
     
    197197// a bidi resolver as it enters/exits inlines (so it can push/pop embedding levels).
    198198template <class Observer>
    199 static inline RenderObject* bidiNextShared(RenderObject* root, RenderObject* current, Observer* observer = 0, EmptyInlineBehavior emptyInlineBehavior = SkipEmptyInlines, bool* endOfInlinePtr = 0)
     199static inline RenderObject* bidiNextShared(RenderElement* root, RenderObject* current, Observer* observer = 0, EmptyInlineBehavior emptyInlineBehavior = SkipEmptyInlines, bool* endOfInlinePtr = 0)
    200200{
    201201    RenderObject* next = 0;
     
    242242
    243243        if (isIteratorTarget(next)
    244             || ((emptyInlineBehavior == IncludeEmptyInlines || isEmptyInline(next)) // Always return EMPTY inlines.
    245                 && next->isRenderInline()))
     244            || (next->isRenderInline() && (emptyInlineBehavior == IncludeEmptyInlines || isEmptyInline(toRenderInline(*next)))))
    246245            break;
    247246        current = next;
     
    255254
    256255template <class Observer>
    257 static inline RenderObject* bidiNextSkippingEmptyInlines(RenderObject* root, RenderObject* current, Observer* observer)
     256static inline RenderObject* bidiNextSkippingEmptyInlines(RenderElement* root, RenderObject* current, Observer* observer)
    258257{
    259258    // The SkipEmptyInlines callers never care about endOfInlinePtr.
     
    262261
    263262// This makes callers cleaner as they don't have to specify a type for the observer when not providing one.
    264 static inline RenderObject* bidiNextSkippingEmptyInlines(RenderObject* root, RenderObject* current)
     263static inline RenderObject* bidiNextSkippingEmptyInlines(RenderElement* root, RenderObject* current)
    265264{
    266265    InlineBidiResolver* observer = 0;
     
    268267}
    269268
    270 static inline RenderObject* bidiNextIncludingEmptyInlines(RenderObject* root, RenderObject* current, bool* endOfInlinePtr = 0)
     269static inline RenderObject* bidiNextIncludingEmptyInlines(RenderElement* root, RenderObject* current, bool* endOfInlinePtr = 0)
    271270{
    272271    InlineBidiResolver* observer = 0; // Callers who include empty inlines, never use an observer.
     
    282281    if (o->isRenderInline()) {
    283282        notifyObserverEnteredObject(resolver, o);
    284         if (!isEmptyInline(o))
     283        if (!isEmptyInline(toRenderInline(*o)))
    285284            o = bidiNextSkippingEmptyInlines(root, o, resolver);
    286285        else {
  • trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp

    r156614 r156618  
    125125#endif
    126126
    127 static inline LayoutUnit borderPaddingMarginStart(RenderInline* child)
    128 {
    129     return child->marginStart() + child->paddingStart() + child->borderStart();
    130 }
    131 
    132 static inline LayoutUnit borderPaddingMarginEnd(RenderInline* child)
    133 {
    134     return child->marginEnd() + child->paddingEnd() + child->borderEnd();
     127static inline LayoutUnit borderPaddingMarginStart(const RenderInline& child)
     128{
     129    return child.marginStart() + child.paddingStart() + child.borderStart();
     130}
     131
     132static inline LayoutUnit borderPaddingMarginEnd(const RenderInline& child)
     133{
     134    return child.marginEnd() + child.paddingEnd() + child.borderEnd();
    135135}
    136136
     
    153153    unsigned lineDepth = 1;
    154154    LayoutUnit extraWidth = 0;
    155     RenderObject* parent = child->parent();
     155    RenderElement* parent = child->parent();
    156156    while (parent->isRenderInline() && lineDepth++ < cMaxLineDepth) {
    157         RenderInline* parentAsRenderInline = toRenderInline(parent);
     157        const RenderInline& parentAsRenderInline = toRenderInline(*parent);
    158158        if (!isEmptyInline(parentAsRenderInline)) {
    159159            checkStartEdge = checkStartEdge && shouldAddBorderPaddingMargin(previousInFlowSibling(child));
     
    623623};
    624624
    625 static inline const RenderStyle& lineStyle(RenderElement& renderer, const LineInfo& lineInfo)
     625static inline const RenderStyle& lineStyle(const RenderElement& renderer, const LineInfo& lineInfo)
    626626{
    627627    return lineInfo.isFirstLine() ? *renderer.firstLineStyle() : *renderer.style();
     
    22172217}
    22182218
    2219 static bool requiresLineBoxForContent(RenderInline* flow, const LineInfo& lineInfo)
    2220 {
    2221     RenderElement* parent = flow->parent();
    2222     if (flow->document().inNoQuirksMode()) {
    2223         const RenderStyle& flowStyle = lineStyle(*flow, lineInfo);
     2219static bool requiresLineBoxForContent(const RenderInline& flow, const LineInfo& lineInfo)
     2220{
     2221    RenderElement* parent = flow.parent();
     2222    if (flow.document().inNoQuirksMode()) {
     2223        const RenderStyle& flowStyle = lineStyle(flow, lineInfo);
    22242224        const RenderStyle& parentStyle = lineStyle(*parent, lineInfo);
    22252225        if (flowStyle.lineHeight() != parentStyle.lineHeight()
     
    22312231}
    22322232
    2233 static bool hasInlineDirectionBordersPaddingOrMargin(RenderInline* flow)
     2233static bool hasInlineDirectionBordersPaddingOrMargin(const RenderInline& flow)
    22342234{
    22352235    // Where an empty inline is split across anonymous blocks we should only give lineboxes to the 'sides' of the
    22362236    // inline that have borders, padding or margin.
    2237     bool shouldApplyStartBorderPaddingOrMargin = !flow->parent()->isAnonymousBlock() || !flow->isInlineElementContinuation();
    2238     if (shouldApplyStartBorderPaddingOrMargin && (flow->borderStart() || flow->marginStart() || flow->paddingStart()))
     2237    bool shouldApplyStartBorderPaddingOrMargin = !flow.parent()->isAnonymousBlock() || !flow.isInlineElementContinuation();
     2238    if (shouldApplyStartBorderPaddingOrMargin && (flow.borderStart() || flow.marginStart() || flow.paddingStart()))
    22392239        return true;
    22402240
    2241     bool shouldApplyEndBorderPaddingOrMargin = !flow->parent()->isAnonymousBlock() || flow->isInlineElementContinuation() || !flow->inlineElementContinuation();
    2242     return shouldApplyEndBorderPaddingOrMargin && (flow->borderEnd() || flow->marginEnd() || flow->paddingEnd());
    2243 }
    2244 
    2245 static bool alwaysRequiresLineBox(RenderObject* flow)
     2241    bool shouldApplyEndBorderPaddingOrMargin = !flow.parent()->isAnonymousBlock() || flow.isInlineElementContinuation() || !flow.inlineElementContinuation();
     2242    return shouldApplyEndBorderPaddingOrMargin && (flow.borderEnd() || flow.marginEnd() || flow.paddingEnd());
     2243}
     2244
     2245static bool alwaysRequiresLineBox(const RenderInline& flow)
    22462246{
    22472247    // FIXME: Right now, we only allow line boxes for inlines that are truly empty.
    22482248    // We need to fix this, though, because at the very least, inlines containing only
    22492249    // ignorable whitespace should should also have line boxes.
    2250     return isEmptyInline(flow) && hasInlineDirectionBordersPaddingOrMargin(toRenderInline(flow));
     2250    return isEmptyInline(flow) && hasInlineDirectionBordersPaddingOrMargin(flow);
    22512251}
    22522252
     
    22592259        return true;
    22602260
    2261     if (it.m_obj->isRenderInline() && !alwaysRequiresLineBox(it.m_obj) && !requiresLineBoxForContent(toRenderInline(it.m_obj), lineInfo))
    2262         return false;
     2261    bool rendererIsEmptyInline = false;
     2262    if (it.m_obj->isRenderInline()) {
     2263        const RenderInline& inlineRenderer = toRenderInline(*it.m_obj);
     2264        if (!alwaysRequiresLineBox(inlineRenderer) && !requiresLineBoxForContent(inlineRenderer, lineInfo))
     2265            return false;
     2266        rendererIsEmptyInline = isEmptyInline(inlineRenderer);
     2267    }
    22632268
    22642269    if (!shouldCollapseWhiteSpace(it.m_obj->style(), lineInfo, whitespacePosition))
     
    22672272    UChar current = it.current();
    22682273    bool notJustWhitespace = current != ' ' && current != '\t' && current != softHyphen && (current != '\n' || it.m_obj->preservesNewline()) && !skipNonBreakingSpace(it, lineInfo);
    2269     return notJustWhitespace || isEmptyInline(it.m_obj);
     2274    return notJustWhitespace || rendererIsEmptyInline;
    22702275}
    22712276
     
    26082613
    26092614    // Avoid breaking before empty inlines.
    2610     if (next && isEmptyInline(next))
     2615    if (next && next->isRenderInline() && isEmptyInline(toRenderInline(*next)))
    26112616        return false;
    26122617
     
    26182623        return autoWrap;
    26192624
    2620     bool nextIsText = (next && (current.m_obj->isText() || isEmptyInline(current.m_obj)) && next->isText() && (autoWrap || next->style()->autoWrap()));
    2621     if (!nextIsText)
     2625    bool nextIsAutoWrappingText = (next && next->isText() && (autoWrap || next->style()->autoWrap()));
     2626    if (!nextIsAutoWrappingText)
     2627        return autoWrap;
     2628    bool currentIsTextOrEmptyInline = current.m_obj->isText() || (current.m_obj->isRenderInline() && isEmptyInline(toRenderInline(*current.m_obj)));
     2629    if (!currentIsTextOrEmptyInline)
    26222630        return autoWrap;
    26232631
     
    28212829            renderTextInfo.m_lineBreakIterator.updatePriorContext(replacementCharacter);
    28222830        } else if (current.m_obj->isRenderInline()) {
     2831            RenderInline& flowBox = toRenderInline(*current.m_obj);
    28232832            // Right now, we should only encounter empty inlines here.
    2824             ASSERT(isEmptyInline(current.m_obj));
    2825 
    2826             RenderInline* flowBox = toRenderInline(current.m_obj);
    2827 
     2833            ASSERT(isEmptyInline(flowBox));
    28282834            // Now that some inline flows have line boxes, if we are already ignoring spaces, we need
    28292835            // to make sure that we stop to include this object and then start ignoring spaces again.
    28302836            // If this object is at the start of the line, we need to behave like list markers and
    28312837            // start ignoring spaces.
    2832             bool requiresLineBox = alwaysRequiresLineBox(current.m_obj);
     2838            bool requiresLineBox = alwaysRequiresLineBox(flowBox);
    28332839            if (requiresLineBox || requiresLineBoxForContent(flowBox, lineInfo)) {
    28342840                // An empty inline that only has line-height, vertical-align or font-metrics will only get a
     
    28472853                    ignoringSpaces = true;
    28482854                } else {
    2849                     trailingObjects.appendBoxIfNeeded(flowBox);
     2855                    trailingObjects.appendBoxIfNeeded(&flowBox);
    28502856                }
    28512857            }
  • trunk/Source/WebCore/rendering/shapes/ShapeInsideInfo.h

    r156176 r156618  
    4141class InlineIterator;
    4242class RenderBlock;
     43class RenderElement;
    4344class RenderObject;
    4445
    4546struct LineSegmentIterator {
    46     RenderObject* root;
     47    RenderElement* root;
    4748    RenderObject* object;
    4849    unsigned offset;
    49     LineSegmentIterator(RenderObject* root, RenderObject* object, unsigned offset)
     50    LineSegmentIterator(RenderElement* root, RenderObject* object, unsigned offset)
    5051        : root(root)
    5152        , object(object)
Note: See TracChangeset for help on using the changeset viewer.