Changeset 117359 in webkit


Ignore:
Timestamp:
May 16, 2012 4:24:34 PM (12 years ago)
Author:
rniwa@webkit.org
Message:

Merge nextRootInlineBox with nextLinePosition
https://bugs.webkit.org/show_bug.cgi?id=81593

Reviewed by Enrica Casucci.

Call previousRootInlineBox and nextRootInlineBox in previousLinePosition and nextLinePosition respectively
to share the code. Moved out the nullity check of startBox and extracted the renderer's node from the former
two, and added editableType to their argument lists to match the interface in both use cases.

Also moved out the code to extract root inline box using RenderedPosition from those two functions and
expanded in call sites since previousLinePosition and nextLinePosition need to return the candidate position
even when the root inline box doesn't exist. To this end, renamed previousRootInlineBox and nextRootInlineBox
to previousRootInlineBoxCandidatePosition and nextRootInlineBoxCandidatePosition respectively.

In addition, got rid of one version of nextLeafWithSameEditability that adjusted node with respect to offset
This variant did:

Node* child = node->childNode(offset);
node = child ? child->nextLeafNode() : node->lastDescendant()->nextLeafNode();

instead of:

node = node->nextLeafNode();

at the beginning of the function. Observe that the former code is logically equivalent to:

Node* child = node->childNode(offset);
node = child ? child : node->lastDescendant();
node = node->nextLeafNode();

Thus, the first two lines of this logically equivalent code is added in nextLinePosition wherein we used to
call the removed variant.

This refactoring with no behavioral change would help us resolving the bug 81490.

  • editing/visible_units.cpp:

(WebCore::previousRootInlineBoxCandidatePosition): Renamed from previousRootInlineBox.
(WebCore::nextRootInlineBoxCandidatePosition): Renamed from nextRootInlineBox.
(WebCore::logicallyPreviousBox): Checks the nullity of startBox's renderer and node. Also extracts the root
inline box out of the position per the interface change.
(WebCore::logicallyNextBox): Ditto.
(WebCore::previousLinePosition): Calls previousRootInlineBoxCandidatePosition.
(WebCore::nextLinePosition): Calls nextRootInlineBoxCandidatePosition.

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r117355 r117359  
     12012-05-16  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Merge nextRootInlineBox with nextLinePosition
     4        https://bugs.webkit.org/show_bug.cgi?id=81593
     5
     6        Reviewed by Enrica Casucci.
     7
     8        Call previousRootInlineBox and nextRootInlineBox in previousLinePosition and nextLinePosition respectively
     9        to share the code. Moved out the nullity check of startBox and extracted the renderer's node from the former
     10        two, and added editableType to their argument lists to match the interface in both use cases.
     11
     12        Also moved out the code to extract root inline box using RenderedPosition from those two functions and
     13        expanded in call sites since previousLinePosition and nextLinePosition need to return the candidate position
     14        even when the root inline box doesn't exist. To this end, renamed previousRootInlineBox and nextRootInlineBox
     15        to previousRootInlineBoxCandidatePosition and nextRootInlineBoxCandidatePosition respectively.
     16
     17        In addition, got rid of one version of nextLeafWithSameEditability that adjusted node with respect to offset
     18        This variant did:
     19
     20        Node* child = node->childNode(offset);
     21        node = child ? child->nextLeafNode() : node->lastDescendant()->nextLeafNode();
     22
     23        instead of:
     24
     25        node = node->nextLeafNode();
     26
     27        at the beginning of the function. Observe that the former code is logically equivalent to:
     28
     29        Node* child = node->childNode(offset);
     30        node = child ? child : node->lastDescendant();
     31        node = node->nextLeafNode();
     32
     33        Thus, the first two lines of this logically equivalent code is added in nextLinePosition wherein we used to
     34        call the removed variant.
     35
     36        This refactoring with no behavioral change would help us resolving the bug 81490.
     37
     38        * editing/visible_units.cpp:
     39        (WebCore::previousRootInlineBoxCandidatePosition): Renamed from previousRootInlineBox.
     40        (WebCore::nextRootInlineBoxCandidatePosition): Renamed from nextRootInlineBox.
     41        (WebCore::logicallyPreviousBox): Checks the nullity of startBox's renderer and node. Also extracts the root
     42        inline box out of the position per the interface change.
     43        (WebCore::logicallyNextBox): Ditto.
     44        (WebCore::previousLinePosition): Calls previousRootInlineBoxCandidatePosition.
     45        (WebCore::nextLinePosition): Calls nextRootInlineBoxCandidatePosition.
     46
    1472012-05-16  Noel Gordon  <noel.gordon@gmail.com>
    248
  • trunk/Source/WebCore/editing/visible_units.cpp

    r115788 r117359  
    7070}
    7171
    72 static Node* nextLeafWithSameEditability(Node* node, int offset)
    73 {
    74     bool editable = node->rendererIsEditable();
    75     ASSERT(offset >= 0);
    76     Node* child = node->childNode(offset);
    77     node = child ? child->nextLeafNode() : node->lastDescendant()->nextLeafNode();
    78     while (node) {
    79         if (editable == node->rendererIsEditable())
    80             return node;
    81         node = node->nextLeafNode();
    82     }
    83     return 0;
    84 }
    85 
    8672static Node* nextLeafWithSameEditability(Node* node, EditableType editableType = ContentIsEditable)
    8773{
     
    10086
    10187// FIXME: consolidate with code in previousLinePosition.
    102 static const RootInlineBox* previousRootInlineBox(const InlineBox* box, const VisiblePosition& visiblePosition)
    103 {
    104     Node* highestRoot = highestEditableRoot(visiblePosition.deepEquivalent(), ContentIsEditable);
    105 
    106     if (!box->renderer() || !box->renderer()->node())
    107         return 0;
    108 
    109     Node* node = box->renderer()->node();
     88static Position previousRootInlineBoxCandidatePosition(Node* node, const VisiblePosition& visiblePosition, EditableType editableType)
     89{
     90    Node* highestRoot = highestEditableRoot(visiblePosition.deepEquivalent(), editableType);
    11091    Node* enclosingBlockNode = enclosingNodeWithNonInlineRenderer(node);
    111     Node* previousNode = previousLeafWithSameEditability(node, ContentIsEditable);
     92    Node* previousNode = previousLeafWithSameEditability(node, editableType);
    11293
    11394    while (previousNode && enclosingBlockNode == enclosingNodeWithNonInlineRenderer(previousNode))
    114         previousNode = previousLeafWithSameEditability(previousNode, ContentIsEditable);
     95        previousNode = previousLeafWithSameEditability(previousNode, editableType);
    11596 
    11697    while (previousNode && !previousNode->isShadowRoot()) {
    117         if (highestEditableRoot(firstPositionInOrBeforeNode(previousNode), ContentIsEditable) != highestRoot)
     98        if (highestEditableRoot(firstPositionInOrBeforeNode(previousNode), editableType) != highestRoot)
    11899            break;
    119100
     
    121102            createLegacyEditingPosition(previousNode, caretMaxOffset(previousNode));
    122103       
    123         if (pos.isCandidate()) {
    124             RenderedPosition renderedPos(pos, DOWNSTREAM);
    125             RootInlineBox* root = renderedPos.rootBox();
    126             if (root)
    127                 return root;
    128         }
    129 
    130         previousNode = previousLeafWithSameEditability(previousNode, ContentIsEditable);
    131     }
    132     return 0;
    133 }
    134 
    135 static const RootInlineBox* nextRootInlineBox(const InlineBox* box, const VisiblePosition& visiblePosition)
    136 {
    137     Node* highestRoot = highestEditableRoot(visiblePosition.deepEquivalent(), ContentIsEditable);
    138 
    139     if (!box->renderer() || !box->renderer()->node())
    140         return 0;
    141 
    142     Node* node = box->renderer()->node();
     104        if (pos.isCandidate())
     105            return pos;
     106
     107        previousNode = previousLeafWithSameEditability(previousNode, editableType);
     108    }
     109    return Position();
     110}
     111
     112static Position nextRootInlineBoxCandidatePosition(Node* node, const VisiblePosition& visiblePosition, EditableType editableType)
     113{
     114    Node* highestRoot = highestEditableRoot(visiblePosition.deepEquivalent(), editableType);
    143115    Node* enclosingBlockNode = enclosingNodeWithNonInlineRenderer(node);
    144     Node* nextNode = nextLeafWithSameEditability(node, ContentIsEditable);
     116    Node* nextNode = nextLeafWithSameEditability(node, editableType);
    145117    while (nextNode && enclosingBlockNode == enclosingNodeWithNonInlineRenderer(nextNode))
    146118        nextNode = nextLeafWithSameEditability(nextNode, ContentIsEditable);
    147119 
    148120    while (nextNode && !nextNode->isShadowRoot()) {
    149         if (highestEditableRoot(firstPositionInOrBeforeNode(nextNode), ContentIsEditable) != highestRoot)
     121        if (highestEditableRoot(firstPositionInOrBeforeNode(nextNode), editableType) != highestRoot)
    150122            break;
    151123
     
    153125        pos = createLegacyEditingPosition(nextNode, caretMinOffset(nextNode));
    154126       
    155         if (pos.isCandidate()) {
    156             RenderedPosition renderedPos(pos, DOWNSTREAM);
    157             RootInlineBox* root = renderedPos.rootBox();
    158             if (root)
    159                 return root;
    160         }
    161 
    162         nextNode = nextLeafWithSameEditability(nextNode, ContentIsEditable);
    163     }
    164     return 0;
     127        if (pos.isCandidate())
     128            return pos;
     129
     130        nextNode = nextLeafWithSameEditability(nextNode, editableType);
     131    }
     132    return Position();
    165133}
    166134
     
    258226        return previousBox;
    259227
    260     while (1) {
    261         const RootInlineBox* previousRoot = previousRootInlineBox(startBox, visiblePosition);
     228    while (1) {
     229        Node* startNode = startBox->renderer() ? startBox->renderer()->node() : 0;
     230        if (!startNode)
     231            break;
     232
     233        Position position = previousRootInlineBoxCandidatePosition(startNode, visiblePosition, ContentIsEditable);
     234        if (position.isNull())
     235            break;
     236
     237        RenderedPosition renderedPosition(position, DOWNSTREAM);
     238        RootInlineBox* previousRoot = renderedPosition.rootBox();
    262239        if (!previousRoot)
    263240            break;
     
    290267        return nextBox;
    291268
    292     while (1) {
    293         const RootInlineBox* nextRoot = nextRootInlineBox(startBox, visiblePosition);
     269    while (1) {
     270        Node* startNode = startBox->renderer() ? startBox->renderer()->node() : 0;
     271        if (!startNode)
     272            break;
     273
     274        Position position = nextRootInlineBoxCandidatePosition(startNode, visiblePosition, ContentIsEditable);
     275        if (position.isNull())
     276            break;
     277
     278        RenderedPosition renderedPosition(position, DOWNSTREAM);
     279        RootInlineBox* nextRoot = renderedPosition.rootBox();
    294280        if (!nextRoot)
    295281            break;
     
    952938    Position p = visiblePosition.deepEquivalent();
    953939    Node* node = p.deprecatedNode();
    954     Node* highestRoot = highestEditableRoot(p, editableType);
    955940
    956941    if (!node)
     
    976961
    977962    if (!root) {
    978         // This containing editable block does not have a previous line.
    979         // Need to move back to previous containing editable block in this root editable
    980         // block and find the last root line box in that block.
    981         Node* startBlock = enclosingNodeWithNonInlineRenderer(node);
    982         Node* n = previousLeafWithSameEditability(node, editableType);
    983         while (n && startBlock == enclosingNodeWithNonInlineRenderer(n))
    984             n = previousLeafWithSameEditability(n, editableType);
    985         while (n) {
    986             if (highestEditableRoot(firstPositionInOrBeforeNode(n), editableType) != highestRoot)
    987                 break;
    988             Position pos = n->hasTagName(brTag) ? positionBeforeNode(n) : createLegacyEditingPosition(n, caretMaxOffset(n));
    989             if (pos.isCandidate()) {
    990                 pos.getInlineBoxAndOffset(DOWNSTREAM, box, ignoredCaretOffset);
    991                 if (box) {
    992                     // previous root line box found
    993                     root = box->root();
    994                     break;
    995                 }
    996 
    997                 return VisiblePosition(pos, DOWNSTREAM);
    998             }
    999             n = previousLeafWithSameEditability(n, editableType);
     963        Position position = previousRootInlineBoxCandidatePosition(node, visiblePosition, editableType);
     964        if (position.isNotNull()) {
     965            RenderedPosition renderedPosition(position);
     966            root = renderedPosition.rootBox();
     967            if (!root)
     968                return position;
    1000969        }
    1001970    }
     
    1020989}
    1021990
    1022 
    1023991VisiblePosition nextLinePosition(const VisiblePosition &visiblePosition, int lineDirectionPoint, EditableType editableType)
    1024992{
    1025993    Position p = visiblePosition.deepEquivalent();
    1026994    Node* node = p.deprecatedNode();
    1027     Node* highestRoot = highestEditableRoot(p, editableType);
    1028995
    1029996    if (!node)
     
    10491016
    10501017    if (!root) {
    1051         // This containing editable block does not have a next line.
    1052         // Need to move forward to next containing editable block in this root editable
    1053         // block and find the first root line box in that block.
    1054         Node* startBlock = enclosingNodeWithNonInlineRenderer(node);
    1055         Node* n = nextLeafWithSameEditability(node, p.deprecatedEditingOffset());
    1056         while (n && startBlock == enclosingNodeWithNonInlineRenderer(n))
    1057             n = nextLeafWithSameEditability(n, editableType);
    1058         while (n) {
    1059             if (highestEditableRoot(firstPositionInOrBeforeNode(n), editableType) != highestRoot)
    1060                 break;
    1061             Position pos = createLegacyEditingPosition(n, caretMinOffset(n));
    1062             if (pos.isCandidate()) {
    1063                 ASSERT(n->renderer());
    1064                 pos.getInlineBoxAndOffset(DOWNSTREAM, box, ignoredCaretOffset);
    1065                 if (box) {
    1066                     // next root line box found
    1067                     root = box->root();
    1068                     break;
    1069                 }
    1070 
    1071                 return VisiblePosition(pos, DOWNSTREAM);
    1072             }
    1073             n = nextLeafWithSameEditability(n, editableType);
     1018        // FIXME: We need do the same in previousLinePosition.
     1019        Node* child = node->childNode(p.deprecatedEditingOffset());
     1020        node = child ? child : node->lastDescendant();
     1021        Position position = nextRootInlineBoxCandidatePosition(node, visiblePosition, editableType);
     1022        if (position.isNotNull()) {
     1023            RenderedPosition renderedPosition(position);
     1024            root = renderedPosition.rootBox();
     1025            if (!root)
     1026                return position;
    10741027        }
    10751028    }
Note: See TracChangeset for help on using the changeset viewer.