2009-07-09 Roland Steiner <rolandsteiner@google.com>
authorbfulgham@webkit.org <bfulgham@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 10 Jul 2009 05:26:42 +0000 (05:26 +0000)
committerbfulgham@webkit.org <bfulgham@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 10 Jul 2009 05:26:42 +0000 (05:26 +0000)
        Reviewed by Maciej Stachowiak.

        added InlineBox::isLeaf()
        firstLeafChild()/lastLeafChild() not virtual and not callable on InlineBox anymore.
        firstLeafChild()/lastLeafChild() will no longer return a node outside of the given subtree.
        Removed firstLeafChildAfterBox()/lastLeafChildBeforeBox()
        Removed potentially quadratic behavior if all nodes before/after a given box are empty InlineFlowBoxes

        Currently, these methods are called on RootInlineBox objects only, so above changes should not have
        any observable effect (only the removal of the square performance behavior could apply,
        but the conditions for that are probably of a rather theoretical nature).

        * rendering/InlineBox.cpp:
        (WebCore::InlineBox::nextLeafChild):
        (WebCore::InlineBox::prevLeafChild):
        * rendering/InlineBox.h:
        (WebCore::InlineBox::isLeaf):
        * rendering/InlineFlowBox.cpp:
        (WebCore::InlineFlowBox::firstLeafChild):
        (WebCore::InlineFlowBox::lastLeafChild):
        * rendering/InlineFlowBox.h:
        (WebCore::InlineFlowBox::firstChild):
        (WebCore::InlineFlowBox::lastChild):
        (WebCore::InlineFlowBox::isLeaf):
        * rendering/RootInlineBox.cpp:
        (WebCore::RootInlineBox::closestLeafChildForXPos):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@45702 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/rendering/InlineBox.cpp
WebCore/rendering/InlineBox.h
WebCore/rendering/InlineFlowBox.cpp
WebCore/rendering/InlineFlowBox.h
WebCore/rendering/RootInlineBox.cpp

index 580bbd8..56ac191 100644 (file)
@@ -2,6 +2,35 @@
 
         Reviewed by Maciej Stachowiak.
 
+        added InlineBox::isLeaf()
+        firstLeafChild()/lastLeafChild() not virtual and not callable on InlineBox anymore.
+        firstLeafChild()/lastLeafChild() will no longer return a node outside of the given subtree.   
+        Removed firstLeafChildAfterBox()/lastLeafChildBeforeBox()
+        Removed potentially quadratic behavior if all nodes before/after a given box are empty InlineFlowBoxes
+
+        Currently, these methods are called on RootInlineBox objects only, so above changes should not have
+        any observable effect (only the removal of the square performance behavior could apply, 
+        but the conditions for that are probably of a rather theoretical nature).
+
+        * rendering/InlineBox.cpp:
+        (WebCore::InlineBox::nextLeafChild):
+        (WebCore::InlineBox::prevLeafChild):
+        * rendering/InlineBox.h:
+        (WebCore::InlineBox::isLeaf):
+        * rendering/InlineFlowBox.cpp:
+        (WebCore::InlineFlowBox::firstLeafChild):
+        (WebCore::InlineFlowBox::lastLeafChild):
+        * rendering/InlineFlowBox.h:
+        (WebCore::InlineFlowBox::firstChild):
+        (WebCore::InlineFlowBox::lastChild):
+        (WebCore::InlineFlowBox::isLeaf):
+        * rendering/RootInlineBox.cpp:
+        (WebCore::RootInlineBox::closestLeafChildForXPos):
+
+2009-07-09  Roland Steiner  <rolandsteiner@google.com>
+
+        Reviewed by Maciej Stachowiak.
+
         Added InlineBox::baselinePosition() and lineHeight() methods
         (adapted remaining code accordingly to use those methods)
 
index 564de8a..bbf11b3 100644 (file)
@@ -244,26 +244,26 @@ bool InlineBox::prevOnLineExists() const
     return m_prevOnLineExists;
 }
 
-InlineBox* InlineBox::firstLeafChild()
+InlineBox* InlineBox::nextLeafChild() const
 {
-    return this;
+    InlineBox* leaf = 0;
+    for (InlineBox* box = nextOnLine(); box && !leaf; box = box->nextOnLine())
+        leaf = box->isLeaf() ? box : static_cast<InlineFlowBox*>(box)->firstLeafChild();
+    if (!leaf && parent())
+        leaf = parent()->nextLeafChild();
+    return leaf;
 }
-
-InlineBox* InlineBox::lastLeafChild()
-{
-    return this;
-}
-
-InlineBox* InlineBox::nextLeafChild()
-{
-    return parent() ? parent()->firstLeafChildAfterBox(this) : 0;
-}
-
-InlineBox* InlineBox::prevLeafChild()
+    
+InlineBox* InlineBox::prevLeafChild() const
 {
-    return parent() ? parent()->lastLeafChildBeforeBox(this) : 0;
+    InlineBox* leaf = 0;
+    for (InlineBox* box = prevOnLine(); box && !leaf; box = box->prevOnLine())
+        leaf = box->isLeaf() ? box : static_cast<InlineFlowBox*>(box)->lastLeafChild();
+    if (!leaf && parent())
+        leaf = parent()->prevLeafChild();
+    return leaf;
 }
-
+    
 RenderObject::SelectionState InlineBox::selectionState()
 {
     return renderer()->selectionState();
index c8cd2c2..0f66edd 100644 (file)
@@ -175,10 +175,10 @@ public:
     bool nextOnLineExists() const;
     bool prevOnLineExists() const;
 
-    virtual InlineBox* firstLeafChild();
-    virtual InlineBox* lastLeafChild();
-    InlineBox* nextLeafChild();
-    InlineBox* prevLeafChild();
+    virtual bool isLeaf() const { return true; }
+    
+    InlineBox* nextLeafChild() const;
+    InlineBox* prevLeafChild() const;
         
     RenderObject* renderer() const { return m_renderer; }
 
index d61f419..e46ba38 100644 (file)
@@ -981,33 +981,19 @@ void InlineFlowBox::paintTextDecorations(RenderObject::PaintInfo& paintInfo, int
     }
 }
 
-InlineBox* InlineFlowBox::firstLeafChild()
-{
-    return firstLeafChildAfterBox();
-}
-
-InlineBox* InlineFlowBox::lastLeafChild()
-{
-    return lastLeafChildBeforeBox();
-}
-
-InlineBox* InlineFlowBox::firstLeafChildAfterBox(InlineBox* start)
+InlineBox* InlineFlowBox::firstLeafChild() const
 {
     InlineBox* leaf = 0;
-    for (InlineBox* box = start ? start->nextOnLine() : firstChild(); box && !leaf; box = box->nextOnLine())
-        leaf = box->firstLeafChild();
-    if (start && !leaf && parent())
-        return parent()->firstLeafChildAfterBox(this);
+    for (InlineBox* child = firstChild(); child && !leaf; child = child->nextOnLine())
+        leaf = child->isLeaf() ? child : static_cast<InlineFlowBox*>(child)->firstLeafChild();
     return leaf;
 }
 
-InlineBox* InlineFlowBox::lastLeafChildBeforeBox(InlineBox* start)
+InlineBox* InlineFlowBox::lastLeafChild() const
 {
     InlineBox* leaf = 0;
-    for (InlineBox* box = start ? start->prevOnLine() : lastChild(); box && !leaf; box = box->prevOnLine())
-        leaf = box->lastLeafChild();
-    if (start && !leaf && parent())
-        return parent()->lastLeafChildBeforeBox(this);
+    for (InlineBox* child = lastChild(); child && !leaf; child = child->prevOnLine())
+        leaf = child->isLeaf() ? child : static_cast<InlineFlowBox*>(child)->lastLeafChild();
     return leaf;
 }
 
index ab1b6f2..9bb1162 100644 (file)
@@ -58,13 +58,13 @@ public:
     InlineFlowBox* prevFlowBox() const { return static_cast<InlineFlowBox*>(m_prevLine); }
     InlineFlowBox* nextFlowBox() const { return static_cast<InlineFlowBox*>(m_nextLine); }
 
-    InlineBox* firstChild() { checkConsistency(); return m_firstChild; }
-    InlineBox* lastChild() { checkConsistency(); return m_lastChild; }
+    InlineBox* firstChild() const { checkConsistency(); return m_firstChild; }
+    InlineBox* lastChild() const { checkConsistency(); return m_lastChild; }
 
-    virtual InlineBox* firstLeafChild();
-    virtual InlineBox* lastLeafChild();
-    InlineBox* firstLeafChildAfterBox(InlineBox* start = 0);
-    InlineBox* lastLeafChildBeforeBox(InlineBox* start = 0);
+    virtual bool isLeaf() const { return false; }
+    
+    InlineBox* firstLeafChild() const;
+    InlineBox* lastLeafChild() const;
 
     virtual void setConstructed()
     {
index ed125ee..e8f04da 100644 (file)
@@ -355,8 +355,8 @@ static bool isEditableLeaf(InlineBox* leaf)
 
 InlineBox* RootInlineBox::closestLeafChildForXPos(int x, bool onlyEditableLeaves)
 {
-    InlineBox* firstLeaf = firstLeafChildAfterBox();
-    InlineBox* lastLeaf = lastLeafChildBeforeBox();
+    InlineBox* firstLeaf = firstLeafChild();
+    InlineBox* lastLeaf = lastLeafChild();
     if (firstLeaf == lastLeaf && (!onlyEditableLeaves || isEditableLeaf(firstLeaf)))
         return firstLeaf;