Changeset 150782 in webkit


Ignore:
Timestamp:
May 27, 2013 4:40:38 PM (11 years ago)
Author:
Darin Adler
Message:

Move isBlockFlowElement and related functions out of the Node class into editing code
https://bugs.webkit.org/show_bug.cgi?id=116846

Reviewed by Antti Koivisto.

  • dom/Node.cpp: Removed isBlockFlowElement, enclosingBlockFlowElement, and

inSameContainingBlockFlowElement. These are all editing functions that don't
belong in the Node class, and mostly-deprecated ones to boot.

  • dom/Node.h: Ditto.
  • dom/Position.cpp:

(WebCore::inSameEnclosingBlockFlowElement): Added. This editing-specific function
is used only here, so put it here.
(WebCore::Position::rendersInDifferentPosition): Updated to call new function above.
(WebCore::Position::leadingWhitespacePosition): Ditto.

  • editing/InsertLineBreakCommand.cpp:

(WebCore::InsertLineBreakCommand::insertNodeAfterPosition): Use
deprecatedEnclosingBlockFlowElement at its new location.
(WebCore::InsertLineBreakCommand::insertNodeBeforePosition): Ditto.

  • editing/InsertListCommand.cpp:

(WebCore::InsertListCommand::doApplyForSingleParagraph): use
isBlockFlowElement at its new location.

  • editing/ReplaceSelectionCommand.cpp:

(WebCore::enclosingInline): Ditto.

  • editing/VisiblePosition.cpp:

(WebCore::VisiblePosition::canonicalPosition): Use deprecatedEnclosingBlockFlowElement
at its new location.
(WebCore::enclosingBlockFlowElement): Ditto. Also added FIXME.

  • editing/VisibleSelection.cpp:

(WebCore::makeSearchRange): Ditto.

  • editing/htmlediting.cpp:

(WebCore::isBlockFlowElement): Added. Same as the Node::isBlockFlowElement
function, but here because this is an editing function, not suitable as a Node member.
(WebCore::deprecatedEnclosingBlockFlowElement): Ditto. Added "deprecated" to the name
since the Node member function had a comment saying it was deprecated. Also changed so
it tolerates a 0 for an argument, which made it easier for one caller.

  • editing/htmlediting.h: Added the two new functions.
Location:
trunk/Source/WebCore
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r150778 r150782  
     12013-05-27  Darin Adler  <darin@apple.com>
     2
     3        Move isBlockFlowElement and related functions out of the Node class into editing code
     4        https://bugs.webkit.org/show_bug.cgi?id=116846
     5
     6        Reviewed by Antti Koivisto.
     7
     8        * dom/Node.cpp: Removed isBlockFlowElement, enclosingBlockFlowElement, and
     9        inSameContainingBlockFlowElement. These are all editing functions that don't
     10        belong in the Node class, and mostly-deprecated ones to boot.
     11        * dom/Node.h: Ditto.
     12
     13        * dom/Position.cpp:
     14        (WebCore::inSameEnclosingBlockFlowElement): Added. This editing-specific function
     15        is used only here, so put it here.
     16        (WebCore::Position::rendersInDifferentPosition): Updated to call new function above.
     17        (WebCore::Position::leadingWhitespacePosition): Ditto.
     18
     19        * editing/InsertLineBreakCommand.cpp:
     20        (WebCore::InsertLineBreakCommand::insertNodeAfterPosition): Use
     21        deprecatedEnclosingBlockFlowElement at its new location.
     22        (WebCore::InsertLineBreakCommand::insertNodeBeforePosition): Ditto.
     23
     24        * editing/InsertListCommand.cpp:
     25        (WebCore::InsertListCommand::doApplyForSingleParagraph): use
     26        isBlockFlowElement at its new location.
     27        * editing/ReplaceSelectionCommand.cpp:
     28        (WebCore::enclosingInline): Ditto.
     29
     30        * editing/VisiblePosition.cpp:
     31        (WebCore::VisiblePosition::canonicalPosition): Use deprecatedEnclosingBlockFlowElement
     32        at its new location.
     33        (WebCore::enclosingBlockFlowElement): Ditto. Also added FIXME.
     34        * editing/VisibleSelection.cpp:
     35        (WebCore::makeSearchRange): Ditto.
     36
     37        * editing/htmlediting.cpp:
     38        (WebCore::isBlockFlowElement): Added. Same as the Node::isBlockFlowElement
     39        function, but here because this is an editing function, not suitable as a Node member.
     40        (WebCore::deprecatedEnclosingBlockFlowElement): Ditto. Added "deprecated" to the name
     41        since the Node member function had a comment saying it was deprecated. Also changed so
     42        it tolerates a 0 for an argument, which made it easier for one caller.
     43
     44        * editing/htmlediting.h: Added the two new functions.
     45
    1462013-05-27  Seokju Kwon  <seokju.kwon@gmail.com>
    247
  • trunk/Source/WebCore/dom/Node.cpp

    r150722 r150782  
    12661266}
    12671267
    1268 bool Node::isBlockFlowElement() const
    1269 {
    1270     return isElementNode() && renderer() && renderer()->isBlockFlow();
    1271 }
    1272 
    1273 Element *Node::enclosingBlockFlowElement() const
    1274 {
    1275     Node *n = const_cast<Node *>(this);
    1276     if (isBlockFlowElement())
    1277         return toElement(n);
    1278 
    1279     while (1) {
    1280         n = n->parentNode();
    1281         if (!n)
    1282             break;
    1283         if (n->isBlockFlowElement() || n->hasTagName(bodyTag))
    1284             return toElement(n);
    1285     }
    1286     return 0;
    1287 }
    1288 
    12891268bool Node::isRootEditableElement() const
    12901269{
     
    13131292    }
    13141293    return result;
    1315 }
    1316 
    1317 bool Node::inSameContainingBlockFlowElement(Node *n)
    1318 {
    1319     return n ? enclosingBlockFlowElement() == n->enclosingBlockFlowElement() : false;
    13201294}
    13211295
  • trunk/Source/WebCore/dom/Node.h

    r150722 r150782  
    305305    Node* enclosingLinkEventParentOrSelf();
    306306
    307     bool isBlockFlowElement() const;
    308 
    309307    // These low-level calls give the caller responsibility for maintaining the integrity of the tree.
    310308    void setPreviousSibling(Node* previous) { m_previous = previous; }
     
    329327    Node* previousLeafNode() const;
    330328
    331     // enclosingBlockFlowElement() is deprecated. Use enclosingBlock instead.
    332     Element* enclosingBlockFlowElement() const;
    333 
    334329    bool isRootEditableElement() const;
    335330    Element* rootEditableElement() const;
    336331    Element* rootEditableElement(EditableType) const;
    337 
    338     bool inSameContainingBlockFlowElement(Node*);
    339332
    340333    // Called by the parser when this element's close tag is reached,
  • trunk/Source/WebCore/dom/Position.cpp

    r145818 r150782  
    994994}
    995995
     996static bool inSameEnclosingBlockFlowElement(Node* a, Node* b)
     997{
     998    return a && b && deprecatedEnclosingBlockFlowElement(a) == deprecatedEnclosingBlockFlowElement(b);
     999}
     1000
    9961001bool Position::rendersInDifferentPosition(const Position &pos) const
    9971002{
     
    10301035        return true;
    10311036               
    1032     if (deprecatedNode()->enclosingBlockFlowElement() != pos.deprecatedNode()->enclosingBlockFlowElement())
     1037    if (!inSameEnclosingBlockFlowElement(deprecatedNode(), pos.deprecatedNode()))
    10331038        return true;
    10341039
     
    10911096
    10921097    Position prev = previousCharacterPosition(affinity);
    1093     if (prev != *this && prev.deprecatedNode()->inSameContainingBlockFlowElement(deprecatedNode()) && prev.deprecatedNode()->isTextNode()) {
     1098    if (prev != *this && inSameEnclosingBlockFlowElement(deprecatedNode(), prev.deprecatedNode()) && prev.deprecatedNode()->isTextNode()) {
    10941099        String string = toText(prev.deprecatedNode())->data();
    10951100        UChar c = string[prev.deprecatedEditingOffset()];
  • trunk/Source/WebCore/editing/InsertLineBreakCommand.cpp

    r148545 r150782  
    5959    // position is a block, do an append. We don't want to insert
    6060    // the BR *after* the block.
    61     Element* cb = pos.deprecatedNode()->enclosingBlockFlowElement();
     61    Element* cb = deprecatedEnclosingBlockFlowElement(pos.deprecatedNode());
    6262    if (cb == pos.deprecatedNode())
    6363        appendNode(node, cb);
     
    7171    // position is a block, do an append. We don't want to insert
    7272    // the BR *before* the block.
    73     Element* cb = pos.deprecatedNode()->enclosingBlockFlowElement();
     73    Element* cb = deprecatedEnclosingBlockFlowElement(pos.deprecatedNode());
    7474    if (cb == pos.deprecatedNode())
    7575        appendNode(node, cb);
  • trunk/Source/WebCore/editing/InsertListCommand.cpp

    r147388 r150782  
    220220
    221221            Node* firstChildInList = enclosingListChild(VisiblePosition(firstPositionInNode(listNode.get())).deepEquivalent().deprecatedNode(), listNode.get());
    222             Node* outerBlock = firstChildInList->isBlockFlowElement() ? firstChildInList : listNode.get();
     222            Node* outerBlock = isBlockFlowElement(firstChildInList) ? firstChildInList : listNode.get();
    223223           
    224224            moveParagraphWithClones(firstPositionInNode(listNode.get()), lastPositionInNode(listNode.get()), newList.get(), outerBlock);
  • trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp

    r148251 r150782  
    843843{
    844844    while (ContainerNode* parent = node->parentNode()) {
    845         if (parent->isBlockFlowElement() || parent->hasTagName(bodyTag))
     845        if (isBlockFlowElement(parent) || parent->hasTagName(bodyTag))
    846846            return node;
    847847        // Stop if any previous sibling is a block.
    848848        for (Node* sibling = node->previousSibling(); sibling; sibling = sibling->previousSibling()) {
    849             if (sibling->isBlockFlowElement())
     849            if (isBlockFlowElement(sibling))
    850850                return node;
    851851        }
  • trunk/Source/WebCore/editing/VisiblePosition.cpp

    r144911 r150782  
    559559
    560560    // The new position should be in the same block flow element. Favor that.
    561     Node* originalBlock = node ? node->enclosingBlockFlowElement() : 0;
     561    Element* originalBlock = deprecatedEnclosingBlockFlowElement(node);
    562562    bool nextIsOutsideOriginalBlock = !nextNode->isDescendantOf(originalBlock) && nextNode != originalBlock;
    563563    bool prevIsOutsideOriginalBlock = !prevNode->isDescendantOf(originalBlock) && prevNode != originalBlock;
     
    712712}
    713713
    714 Element* enclosingBlockFlowElement(const VisiblePosition &visiblePosition)
     714// FIXME: Maybe this should be deprecated too, like the underlying function?
     715Element* enclosingBlockFlowElement(const VisiblePosition& visiblePosition)
    715716{
    716717    if (visiblePosition.isNull())
    717718        return NULL;
    718719
    719     return visiblePosition.deepEquivalent().deprecatedNode()->enclosingBlockFlowElement();
     720    return deprecatedEnclosingBlockFlowElement(visiblePosition.deepEquivalent().deprecatedNode());
    720721}
    721722
  • trunk/Source/WebCore/editing/VisibleSelection.cpp

    r144911 r150782  
    208208    if (!de)
    209209        return 0;
    210     Node* boundary = n->enclosingBlockFlowElement();
     210    Element* boundary = deprecatedEnclosingBlockFlowElement(n);
    211211    if (!boundary)
    212212        return 0;
  • trunk/Source/WebCore/editing/htmlediting.cpp

    r150712 r150782  
    12091209}
    12101210
     1211// FIXME: Should this be deprecated like deprecatedEnclosingBlockFlowElement is?
     1212bool isBlockFlowElement(const Node* node)
     1213{
     1214    if (!node->isElementNode())
     1215        return false;
     1216    RenderObject* renderer = node->renderer();
     1217    return renderer && renderer->isBlockFlow();
     1218}
     1219
     1220Element* deprecatedEnclosingBlockFlowElement(Node* node)
     1221{
     1222    if (!node)
     1223        return 0;
     1224    if (isBlockFlowElement(node))
     1225        return toElement(node);
     1226    while ((node = node->parentNode())) {
     1227        if (isBlockFlowElement(node) || node->hasTagName(bodyTag))
     1228            return toElement(node);
     1229    }
     1230    return 0;
     1231}
     1232
    12111233} // namespace WebCore
  • trunk/Source/WebCore/editing/htmlediting.h

    r150712 r150782  
    6262Node* lowestEditableAncestor(Node*);
    6363
     64Element* deprecatedEnclosingBlockFlowElement(Node*); // Use enclosingBlock instead.
    6465Element* enclosingBlock(Node*, EditingBoundaryCrossingRule = CannotCrossEditingBoundary);
    6566Node* enclosingTableCell(const Position&);
     
    9899bool isAtomicNode(const Node*);
    99100bool isBlock(const Node*);
     101bool isBlockFlowElement(const Node*);
    100102bool isInline(const Node*);
    101103bool isSpecialElement(const Node*);
     
    114116bool areIdenticalElements(const Node*, const Node*);
    115117bool isNonTableCellHTMLBlockElement(const Node*);
     118
    116119TextDirection directionOfEnclosingBlock(const Position&);
    117120
Note: See TracChangeset for help on using the changeset viewer.