[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

kocienda kocienda at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 08:50:29 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 494e85e0c33f772f1fd8161fad8c574df304e01d
Author: kocienda <kocienda at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Jul 14 21:43:25 2004 +0000

            Reviewed by Hyatt
    
            * khtml/rendering/render_block.cpp:
            (khtml::RenderBlock::paintObject): Change back to start() from caretPosition().
            Since the policy is now to move the selection to rendered content, if possible,
            when the selection is set, there is no longer any reason to have the additional
            caretPosition() function to store where the caret should be drawn.
            * khtml/xml/dom_docimpl.cpp:
            (DocumentImpl::updateSelection): No longer any need to call closestRenderedPosition here.
            This is done in Selection::validate.
            * khtml/xml/dom_position.cpp:
            (DOM::Position::closestRenderedPosition): Improved algorithm. Now much simpler.
            * khtml/xml/dom_selection.cpp:
            (DOM::Selection::Selection): caretPosition() and m_caretPosition now obsolete.
            (DOM::Selection::init): Ditto.
            (DOM::Selection::modifyExtendingRightForward): No longer any need to call
            closestRenderedPosition here. This is done in Selection::validate.
            (DOM::Selection::modifyMovingRightForward): Ditto.
            (DOM::Selection::modifyExtendingLeftBackward): Ditto.
            (DOM::Selection::modifyMovingLeftBackward): Ditto.
            (DOM::Selection::layoutCaret): Ditto.
            (DOM::Selection::validate): Add code to move the selection to rendered content if possible.
            * khtml/xml/dom_selection.h: caretPosition() and m_caretPosition now obsolete.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@7028 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index 8c0d281..39aa2a1 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,29 @@
+2004-07-14  Ken Kocienda  <kocienda at apple.com>
+
+        Reviewed by Hyatt
+
+        * khtml/rendering/render_block.cpp: 
+        (khtml::RenderBlock::paintObject): Change back to start() from caretPosition().
+        Since the policy is now to move the selection to rendered content, if possible,
+        when the selection is set, there is no longer any reason to have the additional
+        caretPosition() function to store where the caret should be drawn.
+        * khtml/xml/dom_docimpl.cpp:
+        (DocumentImpl::updateSelection): No longer any need to call closestRenderedPosition here.
+        This is done in Selection::validate.
+        * khtml/xml/dom_position.cpp:
+        (DOM::Position::closestRenderedPosition): Improved algorithm. Now much simpler.
+        * khtml/xml/dom_selection.cpp:
+        (DOM::Selection::Selection): caretPosition() and m_caretPosition now obsolete.
+        (DOM::Selection::init): Ditto.
+        (DOM::Selection::modifyExtendingRightForward): No longer any need to call 
+        closestRenderedPosition here. This is done in Selection::validate.
+        (DOM::Selection::modifyMovingRightForward): Ditto.
+        (DOM::Selection::modifyExtendingLeftBackward): Ditto.
+        (DOM::Selection::modifyMovingLeftBackward): Ditto.
+        (DOM::Selection::layoutCaret): Ditto.
+        (DOM::Selection::validate): Add code to move the selection to rendered content if possible.
+        * khtml/xml/dom_selection.h: caretPosition() and m_caretPosition now obsolete.
+
 2004-07-14  David Hyatt  <hyatt at apple.com>
 
 	Fix for 3716082, assert when you dynamically remove float or position styles.
diff --git a/WebCore/khtml/editing/SelectionController.cpp b/WebCore/khtml/editing/SelectionController.cpp
index f199eda..147cca6 100644
--- a/WebCore/khtml/editing/SelectionController.cpp
+++ b/WebCore/khtml/editing/SelectionController.cpp
@@ -120,7 +120,6 @@ Selection::Selection(const Selection &o)
         m_caretX = o.m_caretX;
         m_caretY = o.m_caretY;
         m_caretSize = o.m_caretSize;
-        m_caretPosition = o.m_caretPosition;
     }
 }
 
@@ -131,7 +130,6 @@ void Selection::init()
     m_caretX = 0;
     m_caretY = 0;
     m_caretSize = 0;
-    m_caretPosition = emptyPosition();
     m_baseIsStart = true;
     m_needsCaretLayout = true;
     m_modifyBiasSet = false;
@@ -202,7 +200,7 @@ Position Selection::modifyExtendingRightForward(ETextGranularity granularity)
         m_modifyBiasSet = true;
         assignBaseAndExtent(start(), end());
     }
-    Position pos = extent().closestRenderedPosition(affinity());
+    Position pos = extent();
     switch (granularity) {
         case CHARACTER:
             pos = pos.nextCharacterPosition();
@@ -227,15 +225,15 @@ Position Selection::modifyMovingRightForward(ETextGranularity granularity)
     switch (granularity) {
         case CHARACTER:
             if (state() == RANGE) 
-                pos = end().closestRenderedPosition(affinity());
+                pos = end();
             else
-                pos = extent().closestRenderedPosition(affinity()).nextCharacterPosition();
+                pos = extent().nextCharacterPosition();
             break;
         case WORD:
-            pos = extent().closestRenderedPosition(affinity()).nextWordPosition();
+            pos = extent().nextWordPosition();
             break;
         case LINE:
-            pos = end().closestRenderedPosition(affinity()).nextLinePosition(xPosForVerticalArrowNavigation(END, state() == RANGE));
+            pos = end().nextLinePosition(xPosForVerticalArrowNavigation(END, state() == RANGE));
             break;
         case PARAGRAPH:
             // not implemented
@@ -250,7 +248,7 @@ Position Selection::modifyExtendingLeftBackward(ETextGranularity granularity)
         m_modifyBiasSet = true;
         assignBaseAndExtent(end(), start());
     }
-    Position pos = extent().closestRenderedPosition(affinity());
+    Position pos = extent();
     switch (granularity) {
         case CHARACTER:
             pos = pos.previousCharacterPosition();
@@ -275,15 +273,15 @@ Position Selection::modifyMovingLeftBackward(ETextGranularity granularity)
     switch (granularity) {
         case CHARACTER:
             if (state() == RANGE) 
-                pos = start().closestRenderedPosition(affinity());
+                pos = start();
             else
-                pos = extent().closestRenderedPosition(affinity()).previousCharacterPosition();
+                pos = extent().previousCharacterPosition();
             break;
         case WORD:
-            pos = extent().closestRenderedPosition(affinity()).previousWordPosition();
+            pos = extent().previousWordPosition();
             break;
         case LINE:
-            pos = start().closestRenderedPosition(affinity()).previousLinePosition(xPosForVerticalArrowNavigation(START, state() == RANGE));
+            pos = start().previousLinePosition(xPosForVerticalArrowNavigation(START, state() == RANGE));
             break;
         case PARAGRAPH:
             // not implemented
@@ -470,16 +468,7 @@ Range Selection::toRange() const
 
 void Selection::layoutCaret()
 {
-    if (state() != CARET) {
-        m_caretX = m_caretY = m_caretSize = 0;
-        return;
-    }
-    
-    Position pos = start();
-    if (!pos.inRenderedContent())
-        pos = pos.closestRenderedPosition(affinity());
-
-    if (pos.isEmpty() || !pos.inRenderedContent()) {
+    if (state() != CARET || isEmpty() || !start().inRenderedContent()) {
         m_caretX = m_caretY = m_caretSize = 0;
         return;
     }
@@ -487,8 +476,7 @@ void Selection::layoutCaret()
     // EDIT FIXME: Enhance call to pass along selection 
     // upstream/downstream affinity to get the right position.
     int w;
-    m_caretPosition = pos;
-    pos.node()->renderer()->caretPos(pos.offset(), true, m_caretX, m_caretY, w, m_caretSize);
+    start().node()->renderer()->caretPos(start().offset(), true, m_caretX, m_caretY, w, m_caretSize);
 
     m_needsCaretLayout = false;
 }
@@ -562,14 +550,24 @@ void Selection::validate(ETextGranularity granularity)
 {
     // move the base and extent nodes to their equivalent leaf positions
     bool baseAndExtentEqual = base() == extent();
+    bool updatedLayout = false;
     if (base().notEmpty()) {
-        Position pos = base().equivalentLeafPosition();
+        base().node()->getDocument()->updateLayout();
+        updatedLayout = true;
+        Position pos = base().equivalentDeepPosition();
+        Position renderedPos(pos.closestRenderedPosition(affinity()));
+        if (renderedPos.notEmpty())
+            pos = renderedPos;
         assignBase(pos);
         if (baseAndExtentEqual)
             assignExtent(pos);
     }
     if (extent().notEmpty() && !baseAndExtentEqual) {
-        assignExtent(extent().equivalentLeafPosition());
+        if (!updatedLayout)
+            extent().node()->getDocument()->updateLayout();
+        Position pos(extent().equivalentDeepPosition());
+        Position renderedPos(pos.closestRenderedPosition(affinity()));
+        assignExtent(renderedPos.notEmpty() ? renderedPos : pos);
     }
 
     // make sure we do not have a dangling start or end
@@ -577,11 +575,15 @@ void Selection::validate(ETextGranularity granularity)
         assignStartAndEnd(emptyPosition(), emptyPosition());
         m_baseIsStart = true;
     }
-    else if (base().isEmpty() || extent().isEmpty()) {
+    else if (base().isEmpty()) {
+        assignBase(extent());
+        m_baseIsStart = true;
+    }
+    else if (extent().isEmpty()) {
+        assignExtent(base());
         m_baseIsStart = true;
     }
     else {
-        // adjust m_baseIsStart as needed
         if (base().node() == extent().node()) {
             if (base().offset() > extent().offset())
                 m_baseIsStart = false;
diff --git a/WebCore/khtml/editing/SelectionController.h b/WebCore/khtml/editing/SelectionController.h
index 9eb67d4..72a12de 100644
--- a/WebCore/khtml/editing/SelectionController.h
+++ b/WebCore/khtml/editing/SelectionController.h
@@ -81,7 +81,6 @@ public:
     Position extent() const { return m_extent; }
     Position start() const { return m_start; }
     Position end() const { return m_end; }
-    Position caretPosition() const { return m_caretPosition; }
 
     QRect getRepaintRect() const;
     void setNeedsLayout(bool flag=true);
@@ -142,7 +141,6 @@ private:
     int m_caretX;                 // caret coordinates, size, and position
     int m_caretY;
     int m_caretSize;
-    Position m_caretPosition;               
     
     bool m_baseIsStart : 1;       // true if base node is before the extent node
     bool m_needsCaretLayout : 1;  // true if the caret position needs to be calculated
diff --git a/WebCore/khtml/editing/selection.cpp b/WebCore/khtml/editing/selection.cpp
index f199eda..147cca6 100644
--- a/WebCore/khtml/editing/selection.cpp
+++ b/WebCore/khtml/editing/selection.cpp
@@ -120,7 +120,6 @@ Selection::Selection(const Selection &o)
         m_caretX = o.m_caretX;
         m_caretY = o.m_caretY;
         m_caretSize = o.m_caretSize;
-        m_caretPosition = o.m_caretPosition;
     }
 }
 
@@ -131,7 +130,6 @@ void Selection::init()
     m_caretX = 0;
     m_caretY = 0;
     m_caretSize = 0;
-    m_caretPosition = emptyPosition();
     m_baseIsStart = true;
     m_needsCaretLayout = true;
     m_modifyBiasSet = false;
@@ -202,7 +200,7 @@ Position Selection::modifyExtendingRightForward(ETextGranularity granularity)
         m_modifyBiasSet = true;
         assignBaseAndExtent(start(), end());
     }
-    Position pos = extent().closestRenderedPosition(affinity());
+    Position pos = extent();
     switch (granularity) {
         case CHARACTER:
             pos = pos.nextCharacterPosition();
@@ -227,15 +225,15 @@ Position Selection::modifyMovingRightForward(ETextGranularity granularity)
     switch (granularity) {
         case CHARACTER:
             if (state() == RANGE) 
-                pos = end().closestRenderedPosition(affinity());
+                pos = end();
             else
-                pos = extent().closestRenderedPosition(affinity()).nextCharacterPosition();
+                pos = extent().nextCharacterPosition();
             break;
         case WORD:
-            pos = extent().closestRenderedPosition(affinity()).nextWordPosition();
+            pos = extent().nextWordPosition();
             break;
         case LINE:
-            pos = end().closestRenderedPosition(affinity()).nextLinePosition(xPosForVerticalArrowNavigation(END, state() == RANGE));
+            pos = end().nextLinePosition(xPosForVerticalArrowNavigation(END, state() == RANGE));
             break;
         case PARAGRAPH:
             // not implemented
@@ -250,7 +248,7 @@ Position Selection::modifyExtendingLeftBackward(ETextGranularity granularity)
         m_modifyBiasSet = true;
         assignBaseAndExtent(end(), start());
     }
-    Position pos = extent().closestRenderedPosition(affinity());
+    Position pos = extent();
     switch (granularity) {
         case CHARACTER:
             pos = pos.previousCharacterPosition();
@@ -275,15 +273,15 @@ Position Selection::modifyMovingLeftBackward(ETextGranularity granularity)
     switch (granularity) {
         case CHARACTER:
             if (state() == RANGE) 
-                pos = start().closestRenderedPosition(affinity());
+                pos = start();
             else
-                pos = extent().closestRenderedPosition(affinity()).previousCharacterPosition();
+                pos = extent().previousCharacterPosition();
             break;
         case WORD:
-            pos = extent().closestRenderedPosition(affinity()).previousWordPosition();
+            pos = extent().previousWordPosition();
             break;
         case LINE:
-            pos = start().closestRenderedPosition(affinity()).previousLinePosition(xPosForVerticalArrowNavigation(START, state() == RANGE));
+            pos = start().previousLinePosition(xPosForVerticalArrowNavigation(START, state() == RANGE));
             break;
         case PARAGRAPH:
             // not implemented
@@ -470,16 +468,7 @@ Range Selection::toRange() const
 
 void Selection::layoutCaret()
 {
-    if (state() != CARET) {
-        m_caretX = m_caretY = m_caretSize = 0;
-        return;
-    }
-    
-    Position pos = start();
-    if (!pos.inRenderedContent())
-        pos = pos.closestRenderedPosition(affinity());
-
-    if (pos.isEmpty() || !pos.inRenderedContent()) {
+    if (state() != CARET || isEmpty() || !start().inRenderedContent()) {
         m_caretX = m_caretY = m_caretSize = 0;
         return;
     }
@@ -487,8 +476,7 @@ void Selection::layoutCaret()
     // EDIT FIXME: Enhance call to pass along selection 
     // upstream/downstream affinity to get the right position.
     int w;
-    m_caretPosition = pos;
-    pos.node()->renderer()->caretPos(pos.offset(), true, m_caretX, m_caretY, w, m_caretSize);
+    start().node()->renderer()->caretPos(start().offset(), true, m_caretX, m_caretY, w, m_caretSize);
 
     m_needsCaretLayout = false;
 }
@@ -562,14 +550,24 @@ void Selection::validate(ETextGranularity granularity)
 {
     // move the base and extent nodes to their equivalent leaf positions
     bool baseAndExtentEqual = base() == extent();
+    bool updatedLayout = false;
     if (base().notEmpty()) {
-        Position pos = base().equivalentLeafPosition();
+        base().node()->getDocument()->updateLayout();
+        updatedLayout = true;
+        Position pos = base().equivalentDeepPosition();
+        Position renderedPos(pos.closestRenderedPosition(affinity()));
+        if (renderedPos.notEmpty())
+            pos = renderedPos;
         assignBase(pos);
         if (baseAndExtentEqual)
             assignExtent(pos);
     }
     if (extent().notEmpty() && !baseAndExtentEqual) {
-        assignExtent(extent().equivalentLeafPosition());
+        if (!updatedLayout)
+            extent().node()->getDocument()->updateLayout();
+        Position pos(extent().equivalentDeepPosition());
+        Position renderedPos(pos.closestRenderedPosition(affinity()));
+        assignExtent(renderedPos.notEmpty() ? renderedPos : pos);
     }
 
     // make sure we do not have a dangling start or end
@@ -577,11 +575,15 @@ void Selection::validate(ETextGranularity granularity)
         assignStartAndEnd(emptyPosition(), emptyPosition());
         m_baseIsStart = true;
     }
-    else if (base().isEmpty() || extent().isEmpty()) {
+    else if (base().isEmpty()) {
+        assignBase(extent());
+        m_baseIsStart = true;
+    }
+    else if (extent().isEmpty()) {
+        assignExtent(base());
         m_baseIsStart = true;
     }
     else {
-        // adjust m_baseIsStart as needed
         if (base().node() == extent().node()) {
             if (base().offset() > extent().offset())
                 m_baseIsStart = false;
diff --git a/WebCore/khtml/editing/selection.h b/WebCore/khtml/editing/selection.h
index 9eb67d4..72a12de 100644
--- a/WebCore/khtml/editing/selection.h
+++ b/WebCore/khtml/editing/selection.h
@@ -81,7 +81,6 @@ public:
     Position extent() const { return m_extent; }
     Position start() const { return m_start; }
     Position end() const { return m_end; }
-    Position caretPosition() const { return m_caretPosition; }
 
     QRect getRepaintRect() const;
     void setNeedsLayout(bool flag=true);
@@ -142,7 +141,6 @@ private:
     int m_caretX;                 // caret coordinates, size, and position
     int m_caretY;
     int m_caretSize;
-    Position m_caretPosition;               
     
     bool m_baseIsStart : 1;       // true if base node is before the extent node
     bool m_needsCaretLayout : 1;  // true if the caret position needs to be calculated
diff --git a/WebCore/khtml/rendering/render_block.cpp b/WebCore/khtml/rendering/render_block.cpp
index 1dfd50f..b89ebf7 100644
--- a/WebCore/khtml/rendering/render_block.cpp
+++ b/WebCore/khtml/rendering/render_block.cpp
@@ -1310,7 +1310,7 @@ void RenderBlock::paintObject(PaintInfo& i, int _tx, int _ty)
     */
     if (paintAction == PaintActionForeground) {
         const Selection &s = document()->part()->selection();
-        NodeImpl *caretNode = s.caretPosition().node();
+        NodeImpl *caretNode = s.start().node();
         RenderObject *renderer = caretNode ? caretNode->renderer() : 0;
         if (renderer && renderer->containingBlock() == this && caretNode->isContentEditable()) {
             document()->part()->paintCaret(i.p, i.r);
diff --git a/WebCore/khtml/xml/dom_docimpl.cpp b/WebCore/khtml/xml/dom_docimpl.cpp
index 7105dd7..8c10196 100644
--- a/WebCore/khtml/xml/dom_docimpl.cpp
+++ b/WebCore/khtml/xml/dom_docimpl.cpp
@@ -1236,8 +1236,8 @@ void DocumentImpl::updateSelection()
         canvas->clearSelection();
     }
     else {
-        Position startPos(s.start().closestRenderedPosition(s.affinity()));
-        Position endPos(s.end().closestRenderedPosition(s.affinity()));
+        Position startPos(s.start());
+        Position endPos(s.end());
         if (startPos.notEmpty() && endPos.notEmpty()) {
             RenderObject *startRenderer = startPos.node()->renderer();
             RenderObject *endRenderer = endPos.node()->renderer();
diff --git a/WebCore/khtml/xml/dom_position.cpp b/WebCore/khtml/xml/dom_position.cpp
index dd688c5..9b9ccc7 100644
--- a/WebCore/khtml/xml/dom_position.cpp
+++ b/WebCore/khtml/xml/dom_position.cpp
@@ -594,31 +594,41 @@ Position Position::closestRenderedPosition(EAffinity affinity) const
         return *this;
 
     Position pos;
+    PositionIterator it(*this);
     
-    pos = affinity == UPSTREAM ? equivalentUpstreamPosition() : equivalentDownstreamPosition();
-    if (pos.inRenderedContent())
-        return pos;
-
-    pos = affinity == DOWNSTREAM ? equivalentDownstreamPosition() : equivalentUpstreamPosition();
-    if (pos.inRenderedContent())
-        return pos;
-    
-    pos = *this;
-    Position prev(previousCharacterPosition());    
-    while (prev != pos && prev.node()->inSameContainingBlockFlowElement(node())) {
-        if (prev.inRenderedContent())
-            return prev;
-        pos = prev;
-        prev = pos.previousCharacterPosition();
-    }
-    
-    pos = *this;
-    Position next(nextCharacterPosition());    
-    while (next != pos && next.node()->inSameContainingBlockFlowElement(node())) {
-        if (next.inRenderedContent())
-            return next;
-        pos = next;
-        next = pos.nextCharacterPosition();
+    switch (affinity) {
+        case UPSTREAM:
+            // look upstream first
+            it.setPosition(*this);
+            while (!it.atStart()) {
+                it.previous();
+                if (it.current().inRenderedContent())
+                    return it.current();
+            }
+            // if this does not find something rendered, look downstream
+            it.setPosition(*this);
+            while (!it.atEnd()) {
+                it.next();
+                if (it.current().inRenderedContent())
+                    return it.current();
+            }
+            break;
+        case DOWNSTREAM:
+            // look downstream first
+            it.setPosition(*this);
+            while (!it.atEnd()) {
+                it.next();
+                if (it.current().inRenderedContent())
+                    return it.current();
+            }
+            // if this does not find something rendered, look upstream
+            it.setPosition(*this);
+            while (!it.atStart()) {
+                it.previous();
+                if (it.current().inRenderedContent())
+                    return it.current();
+            }
+            break;
     }
     
     return Position();
diff --git a/WebCore/khtml/xml/dom_selection.cpp b/WebCore/khtml/xml/dom_selection.cpp
index f199eda..147cca6 100644
--- a/WebCore/khtml/xml/dom_selection.cpp
+++ b/WebCore/khtml/xml/dom_selection.cpp
@@ -120,7 +120,6 @@ Selection::Selection(const Selection &o)
         m_caretX = o.m_caretX;
         m_caretY = o.m_caretY;
         m_caretSize = o.m_caretSize;
-        m_caretPosition = o.m_caretPosition;
     }
 }
 
@@ -131,7 +130,6 @@ void Selection::init()
     m_caretX = 0;
     m_caretY = 0;
     m_caretSize = 0;
-    m_caretPosition = emptyPosition();
     m_baseIsStart = true;
     m_needsCaretLayout = true;
     m_modifyBiasSet = false;
@@ -202,7 +200,7 @@ Position Selection::modifyExtendingRightForward(ETextGranularity granularity)
         m_modifyBiasSet = true;
         assignBaseAndExtent(start(), end());
     }
-    Position pos = extent().closestRenderedPosition(affinity());
+    Position pos = extent();
     switch (granularity) {
         case CHARACTER:
             pos = pos.nextCharacterPosition();
@@ -227,15 +225,15 @@ Position Selection::modifyMovingRightForward(ETextGranularity granularity)
     switch (granularity) {
         case CHARACTER:
             if (state() == RANGE) 
-                pos = end().closestRenderedPosition(affinity());
+                pos = end();
             else
-                pos = extent().closestRenderedPosition(affinity()).nextCharacterPosition();
+                pos = extent().nextCharacterPosition();
             break;
         case WORD:
-            pos = extent().closestRenderedPosition(affinity()).nextWordPosition();
+            pos = extent().nextWordPosition();
             break;
         case LINE:
-            pos = end().closestRenderedPosition(affinity()).nextLinePosition(xPosForVerticalArrowNavigation(END, state() == RANGE));
+            pos = end().nextLinePosition(xPosForVerticalArrowNavigation(END, state() == RANGE));
             break;
         case PARAGRAPH:
             // not implemented
@@ -250,7 +248,7 @@ Position Selection::modifyExtendingLeftBackward(ETextGranularity granularity)
         m_modifyBiasSet = true;
         assignBaseAndExtent(end(), start());
     }
-    Position pos = extent().closestRenderedPosition(affinity());
+    Position pos = extent();
     switch (granularity) {
         case CHARACTER:
             pos = pos.previousCharacterPosition();
@@ -275,15 +273,15 @@ Position Selection::modifyMovingLeftBackward(ETextGranularity granularity)
     switch (granularity) {
         case CHARACTER:
             if (state() == RANGE) 
-                pos = start().closestRenderedPosition(affinity());
+                pos = start();
             else
-                pos = extent().closestRenderedPosition(affinity()).previousCharacterPosition();
+                pos = extent().previousCharacterPosition();
             break;
         case WORD:
-            pos = extent().closestRenderedPosition(affinity()).previousWordPosition();
+            pos = extent().previousWordPosition();
             break;
         case LINE:
-            pos = start().closestRenderedPosition(affinity()).previousLinePosition(xPosForVerticalArrowNavigation(START, state() == RANGE));
+            pos = start().previousLinePosition(xPosForVerticalArrowNavigation(START, state() == RANGE));
             break;
         case PARAGRAPH:
             // not implemented
@@ -470,16 +468,7 @@ Range Selection::toRange() const
 
 void Selection::layoutCaret()
 {
-    if (state() != CARET) {
-        m_caretX = m_caretY = m_caretSize = 0;
-        return;
-    }
-    
-    Position pos = start();
-    if (!pos.inRenderedContent())
-        pos = pos.closestRenderedPosition(affinity());
-
-    if (pos.isEmpty() || !pos.inRenderedContent()) {
+    if (state() != CARET || isEmpty() || !start().inRenderedContent()) {
         m_caretX = m_caretY = m_caretSize = 0;
         return;
     }
@@ -487,8 +476,7 @@ void Selection::layoutCaret()
     // EDIT FIXME: Enhance call to pass along selection 
     // upstream/downstream affinity to get the right position.
     int w;
-    m_caretPosition = pos;
-    pos.node()->renderer()->caretPos(pos.offset(), true, m_caretX, m_caretY, w, m_caretSize);
+    start().node()->renderer()->caretPos(start().offset(), true, m_caretX, m_caretY, w, m_caretSize);
 
     m_needsCaretLayout = false;
 }
@@ -562,14 +550,24 @@ void Selection::validate(ETextGranularity granularity)
 {
     // move the base and extent nodes to their equivalent leaf positions
     bool baseAndExtentEqual = base() == extent();
+    bool updatedLayout = false;
     if (base().notEmpty()) {
-        Position pos = base().equivalentLeafPosition();
+        base().node()->getDocument()->updateLayout();
+        updatedLayout = true;
+        Position pos = base().equivalentDeepPosition();
+        Position renderedPos(pos.closestRenderedPosition(affinity()));
+        if (renderedPos.notEmpty())
+            pos = renderedPos;
         assignBase(pos);
         if (baseAndExtentEqual)
             assignExtent(pos);
     }
     if (extent().notEmpty() && !baseAndExtentEqual) {
-        assignExtent(extent().equivalentLeafPosition());
+        if (!updatedLayout)
+            extent().node()->getDocument()->updateLayout();
+        Position pos(extent().equivalentDeepPosition());
+        Position renderedPos(pos.closestRenderedPosition(affinity()));
+        assignExtent(renderedPos.notEmpty() ? renderedPos : pos);
     }
 
     // make sure we do not have a dangling start or end
@@ -577,11 +575,15 @@ void Selection::validate(ETextGranularity granularity)
         assignStartAndEnd(emptyPosition(), emptyPosition());
         m_baseIsStart = true;
     }
-    else if (base().isEmpty() || extent().isEmpty()) {
+    else if (base().isEmpty()) {
+        assignBase(extent());
+        m_baseIsStart = true;
+    }
+    else if (extent().isEmpty()) {
+        assignExtent(base());
         m_baseIsStart = true;
     }
     else {
-        // adjust m_baseIsStart as needed
         if (base().node() == extent().node()) {
             if (base().offset() > extent().offset())
                 m_baseIsStart = false;
diff --git a/WebCore/khtml/xml/dom_selection.h b/WebCore/khtml/xml/dom_selection.h
index 9eb67d4..72a12de 100644
--- a/WebCore/khtml/xml/dom_selection.h
+++ b/WebCore/khtml/xml/dom_selection.h
@@ -81,7 +81,6 @@ public:
     Position extent() const { return m_extent; }
     Position start() const { return m_start; }
     Position end() const { return m_end; }
-    Position caretPosition() const { return m_caretPosition; }
 
     QRect getRepaintRect() const;
     void setNeedsLayout(bool flag=true);
@@ -142,7 +141,6 @@ private:
     int m_caretX;                 // caret coordinates, size, and position
     int m_caretY;
     int m_caretSize;
-    Position m_caretPosition;               
     
     bool m_baseIsStart : 1;       // true if base node is before the extent node
     bool m_needsCaretLayout : 1;  // true if the caret position needs to be calculated

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list