Changeset 181654 in webkit


Ignore:
Timestamp:
Mar 17, 2015, 11:58:59 AM (11 years ago)
Author:
Simon Fraser
Message:

Move some code from LogicalSelectionOffsetCaches into RenderElement
https://bugs.webkit.org/show_bug.cgi?id=142758

Reviewed by Myles C. Maxfield.

LogicalSelectionOffsetCaches had some useful code regarding containing blocks etc
that should be used in more places, so move it into RenderElement.

No behavior change.

  • rendering/LogicalSelectionOffsetCaches.h:

(WebCore::LogicalSelectionOffsetCaches::LogicalSelectionOffsetCaches):
(WebCore::isContainingBlockCandidateForAbsolutelyPositionedObject): Deleted.
(WebCore::isNonRenderBlockInline): Deleted.
(WebCore::containingBlockForFixedPosition): Deleted.
(WebCore::containingBlockForAbsolutePosition): Deleted.
(WebCore::containingBlockForObjectInFlow): Deleted.

  • rendering/RenderBlock.cpp: No need to initialize static data.

(WebCore::RenderBlock::positionedObjects): nullptr

  • rendering/RenderElement.cpp:

(WebCore::RenderElement::containingBlockForFixedPosition):
(WebCore::RenderElement::containingBlockForAbsolutePosition):
(WebCore::isNonRenderBlockInline):
(WebCore::RenderElement::containingBlockForObjectInFlow):

  • rendering/RenderElement.h:

(WebCore::RenderElement::canContainAbsolutelyPositionedObjects):

  • rendering/RenderLayer.cpp:

(WebCore::isContainerForPositioned):

  • rendering/RenderObject.cpp:

(WebCore::RenderObject::containingBlock):

Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r181653 r181654  
     12015-03-17  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Move some code from LogicalSelectionOffsetCaches into RenderElement
     4        https://bugs.webkit.org/show_bug.cgi?id=142758
     5
     6        Reviewed by Myles C. Maxfield.
     7
     8        LogicalSelectionOffsetCaches had some useful code regarding containing blocks etc
     9        that should be used in more places, so move it into RenderElement.
     10       
     11        No behavior change.
     12
     13        * rendering/LogicalSelectionOffsetCaches.h:
     14        (WebCore::LogicalSelectionOffsetCaches::LogicalSelectionOffsetCaches):
     15        (WebCore::isContainingBlockCandidateForAbsolutelyPositionedObject): Deleted.
     16        (WebCore::isNonRenderBlockInline): Deleted.
     17        (WebCore::containingBlockForFixedPosition): Deleted.
     18        (WebCore::containingBlockForAbsolutePosition): Deleted.
     19        (WebCore::containingBlockForObjectInFlow): Deleted.
     20        * rendering/RenderBlock.cpp: No need to initialize static data.
     21        (WebCore::RenderBlock::positionedObjects): nullptr
     22        * rendering/RenderElement.cpp:
     23        (WebCore::RenderElement::containingBlockForFixedPosition):
     24        (WebCore::RenderElement::containingBlockForAbsolutePosition):
     25        (WebCore::isNonRenderBlockInline):
     26        (WebCore::RenderElement::containingBlockForObjectInFlow):
     27        * rendering/RenderElement.h:
     28        (WebCore::RenderElement::canContainAbsolutelyPositionedObjects):
     29        * rendering/RenderLayer.cpp:
     30        (WebCore::isContainerForPositioned):
     31        * rendering/RenderObject.cpp:
     32        (WebCore::RenderObject::containingBlock):
     33
    1342015-03-17  Alex Christensen  <achristensen@webkit.org>
    235
  • trunk/Source/WebCore/rendering/LogicalSelectionOffsetCaches.h

    r177200 r181654  
    2525
    2626namespace WebCore {
    27 
    28 // FIXME: share code with RenderObject::container().
    29 static inline bool isContainingBlockCandidateForAbsolutelyPositionedObject(RenderElement& object)
    30 {
    31     // FIXME: hasTransformRelatedProperty() includes preserves3D() check, but this may need to change: https://www.w3.org/Bugs/Public/show_bug.cgi?id=27566
    32     return object.style().position() != StaticPosition
    33         || (object.isRenderBlock() && object.hasTransformRelatedProperty())
    34         || object.isSVGForeignObject()
    35         || object.isRenderView();
    36 }
    37 
    38 static inline bool isNonRenderBlockInline(RenderElement& object)
    39 {
    40     return (object.isInline() && !object.isReplaced()) || !object.isRenderBlock();
    41 }
    42 
    43 // FIXME: share code with RenderObject::container().
    44 static inline RenderBlock* containingBlockForFixedPosition(RenderElement* parent)
    45 {
    46     RenderElement* object = parent;
    47     while (object && !object->canContainFixedPositionObjects())
    48         object = object->parent();
    49     ASSERT(!object || !object->isAnonymousBlock());
    50     return downcast<RenderBlock>(object);
    51 }
    52 
    53 static inline RenderBlock* containingBlockForAbsolutePosition(RenderElement* parent)
    54 {
    55     RenderElement* object = parent;
    56     while (object && !isContainingBlockCandidateForAbsolutelyPositionedObject(*object))
    57         object = object->parent();
    58 
    59     // For a relatively positioned inline, return its nearest non-anonymous containing block,
    60     // not the inline itself, to avoid having a positioned objects list in all RenderInlines
    61     // and use RenderBlock* as RenderElement::containingBlock's return type.
    62     // Use RenderBlock::container() to obtain the inline.
    63     if (object && !is<RenderBlock>(*object))
    64         object = object->containingBlock();
    65 
    66     while (object && object->isAnonymousBlock())
    67         object = object->containingBlock();
    68 
    69     return downcast<RenderBlock>(object);
    70 }
    71 
    72 static inline RenderBlock* containingBlockForObjectInFlow(RenderElement* parent)
    73 {
    74     RenderElement* object = parent;
    75     while (object && isNonRenderBlockInline(*object))
    76         object = object->parent();
    77     return downcast<RenderBlock>(object);
    78 }
    7927
    8028class LogicalSelectionOffsetCaches {
     
    14593
    14694        // LogicalSelectionOffsetCaches should not be used on an orphaned tree.
    147         m_containingBlockForFixedPosition.setBlock(containingBlockForFixedPosition(parent), 0);
    148         m_containingBlockForAbsolutePosition.setBlock(containingBlockForAbsolutePosition(parent), 0);
    149         m_containingBlockForInflowPosition.setBlock(containingBlockForObjectInFlow(parent), 0);
     95        m_containingBlockForFixedPosition.setBlock(parent->containingBlockForFixedPosition(), nullptr);
     96        m_containingBlockForAbsolutePosition.setBlock(parent->containingBlockForAbsolutePosition(), nullptr);
     97        m_containingBlockForInflowPosition.setBlock(parent->containingBlockForObjectInFlow(), nullptr);
    15098    }
    15199
     
    157105            m_containingBlockForFixedPosition.setBlock(&block, &cache);
    158106
    159         if (isContainingBlockCandidateForAbsolutelyPositionedObject(block) && !block.isRenderInline() && !block.isAnonymousBlock())
     107        if (block.canContainAbsolutelyPositionedObjects() && !block.isRenderInline() && !block.isAnonymousBlock())
    160108            m_containingBlockForFixedPosition.setBlock(&block, &cache);
    161109
  • trunk/Source/WebCore/rendering/RenderBlock.cpp

    r181505 r181654  
    9191COMPILE_ASSERT(sizeof(RenderBlock) == sizeof(SameSizeAsRenderBlock), RenderBlock_should_stay_small);
    9292
    93 static TrackedDescendantsMap* gPositionedDescendantsMap = 0;
    94 static TrackedDescendantsMap* gPercentHeightDescendantsMap = 0;
    95 
    96 static TrackedContainerMap* gPositionedContainerMap = 0;
    97 static TrackedContainerMap* gPercentHeightContainerMap = 0;
     93static TrackedDescendantsMap* gPositionedDescendantsMap;
     94static TrackedDescendantsMap* gPercentHeightDescendantsMap;
     95
     96static TrackedContainerMap* gPositionedContainerMap;
     97static TrackedContainerMap* gPercentHeightContainerMap;
    9898
    9999typedef HashMap<RenderBlock*, std::unique_ptr<ListHashSet<RenderInline*>>> ContinuationOutlineTableMap;
     
    21452145    if (gPositionedDescendantsMap)
    21462146        return gPositionedDescendantsMap->get(this);
    2147     return 0;
     2147    return nullptr;
    21482148}
    21492149
  • trunk/Source/WebCore/rendering/RenderElement.cpp

    r181164 r181654  
    3838#include "HTMLNames.h"
    3939#include "FlowThreadController.h"
     40#include "RenderBlock.h"
    4041#include "RenderCounter.h"
    4142#include "RenderDeprecatedFlexibleBox.h"
     
    14971498}
    14981499
     1500RenderBlock* RenderElement::containingBlockForFixedPosition() const
     1501{
     1502    const RenderElement* object = this;
     1503    while (object && !object->canContainFixedPositionObjects())
     1504        object = object->parent();
     1505
     1506    ASSERT(!object || !object->isAnonymousBlock());
     1507    return const_cast<RenderBlock*>(downcast<RenderBlock>(object));
     1508}
     1509
     1510RenderBlock* RenderElement::containingBlockForAbsolutePosition() const
     1511{
     1512    const RenderElement* object = this;
     1513    while (object && !object->canContainAbsolutelyPositionedObjects())
     1514        object = object->parent();
     1515
     1516    // For a relatively positioned inline, return its nearest non-anonymous containing block,
     1517    // not the inline itself, to avoid having a positioned objects list in all RenderInlines
     1518    // and use RenderBlock* as RenderElement::containingBlock's return type.
     1519    // Use RenderBlock::container() to obtain the inline.
     1520    if (object && !is<RenderBlock>(*object))
     1521        object = object->containingBlock();
     1522
     1523    while (object && object->isAnonymousBlock())
     1524        object = object->containingBlock();
     1525
     1526    return const_cast<RenderBlock*>(downcast<RenderBlock>(object));
     1527}
     1528
     1529static inline bool isNonRenderBlockInline(const RenderElement& object)
     1530{
     1531    return (object.isInline() && !object.isReplaced()) || !object.isRenderBlock();
     1532}
     1533
     1534RenderBlock* RenderElement::containingBlockForObjectInFlow() const
     1535{
     1536    const RenderElement* object = this;
     1537    while (object && isNonRenderBlockInline(*object))
     1538        object = object->parent();
     1539    return const_cast<RenderBlock*>(downcast<RenderBlock>(object));
     1540}
     1541
    14991542Color RenderElement::selectionColor(int colorProperty) const
    15001543{
  • trunk/Source/WebCore/rendering/RenderElement.h

    r180150 r181654  
    3030
    3131class ControlStates;
     32class RenderBlock;
    3233
    3334class RenderElement : public RenderObject {
     
    6465
    6566    bool canContainFixedPositionObjects() const;
     67    bool canContainAbsolutelyPositionedObjects() const;
     68
     69    RenderBlock* containingBlockForFixedPosition() const;
     70    RenderBlock* containingBlockForAbsolutePosition() const;
     71    RenderBlock* containingBlockForObjectInFlow() const;
    6672
    6773    Color selectionColor(int colorProperty) const;
     
    394400}
    395401
     402inline bool RenderElement::canContainAbsolutelyPositionedObjects() const
     403{
     404    return style().position() != StaticPosition
     405        || (isRenderBlock() && hasTransformRelatedProperty())
     406        || isSVGForeignObject()
     407        || isRenderView();
     408}
     409
    396410inline bool RenderObject::isRenderLayerModelObject() const
    397411{
  • trunk/Source/WebCore/rendering/RenderLayer.cpp

    r181515 r181654  
    7878#include "HitTestResult.h"
    7979#include "InspectorInstrumentation.h"
    80 #include "LogicalSelectionOffsetCaches.h"
    8180#include "OverflowEvent.h"
    8281#include "OverlapTestRequestClient.h"
     
    14351434
    14361435    case AbsolutePosition:
    1437         return isContainingBlockCandidateForAbsolutelyPositionedObject(layer.renderer());
     1436        return layer.renderer().canContainAbsolutelyPositionedObjects();
    14381437   
    14391438    default:
  • trunk/Source/WebCore/rendering/RenderObject.cpp

    r181505 r181654  
    694694    const RenderStyle& style = this->style();
    695695    if (!is<RenderText>(*this) && style.position() == FixedPosition)
    696         parent = containingBlockForFixedPosition(parent);
     696        parent = parent->containingBlockForFixedPosition();
    697697    else if (!is<RenderText>(*this) && style.position() == AbsolutePosition)
    698         parent = containingBlockForAbsolutePosition(parent);
     698        parent = parent->containingBlockForAbsolutePosition();
    699699    else
    700         parent = containingBlockForObjectInFlow(parent);
     700        parent = parent->containingBlockForObjectInFlow();
    701701
    702702    if (!is<RenderBlock>(parent))
Note: See TracChangeset for help on using the changeset viewer.