[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:41:31 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit b5566b6641ddc664ea91c37a7f1e421efb07158d
Author: kocienda <kocienda at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Mon May 24 22:18:27 2004 +0000

            Reviewed by Richard
    
            * khtml/xml/dom_selection.cpp:
            (DOM::Selection::toRange): Improved the code to return ranges that are
            convenient to use by WebKit code which needs to perform text-editor-like
            operations with ranges. Comments in the code describe this behavior.
            (DOM::Selection::nodeIsBeforeNode): Make this method const.
            * khtml/xml/dom_selection.h: Ditto.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@6676 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index 794126a..dfdf161 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,14 @@
+2004-05-24  Ken Kocienda  <kocienda at apple.com>
+
+        Reviewed by Richard
+
+        * khtml/xml/dom_selection.cpp:
+        (DOM::Selection::toRange): Improved the code to return ranges that are
+        convenient to use by WebKit code which needs to perform text-editor-like
+        operations with ranges. Comments in the code describe this behavior.
+        (DOM::Selection::nodeIsBeforeNode): Make this method const.
+        * khtml/xml/dom_selection.h: Ditto.
+
 2004-05-24  Chris Blumenberg  <cblu at apple.com>
 
 	Improved editing via drag.
diff --git a/WebCore/khtml/editing/SelectionController.cpp b/WebCore/khtml/editing/SelectionController.cpp
index 04217f4..b28bbe5 100644
--- a/WebCore/khtml/editing/SelectionController.cpp
+++ b/WebCore/khtml/editing/SelectionController.cpp
@@ -397,8 +397,39 @@ Range Selection::toRange() const
     if (isEmpty())
         return Range();
 
-    Position s(start().equivalentRangeCompliantPosition());
-    Position e(end().equivalentRangeCompliantPosition());
+    Position s, e;
+    if (state() == CARET) {
+        // If the selection is a caret, move the range start upstream. This helps us match
+        // the conventions of text editors tested, which make style determinations based
+        // on the character before the caret, if any. 
+        s = start().equivalentUpstreamPosition().equivalentRangeCompliantPosition();
+        e = s;
+    }
+    else {
+        // If the selection is a range, select the minimum range that encompasses the selection.
+        // Again, this is to match the conventions of text editors tested, which make style 
+        // determinations based on the first character of the selection. 
+        // For instance, this operation helps to make sure that the "X" selected below is the 
+        // only thing selected. The range should not be allowed to "leak" out to the end of the 
+        // previous text node, or to the beginning of the next text node, each of which has a 
+        // different style.
+        // 
+        // On a treasure map, <b>X</b> marks the spot.
+        //                       ^ selected
+        //
+        ASSERT(state() == RANGE);
+        s = start().equivalentDownstreamPosition().equivalentRangeCompliantPosition();
+        e = end().equivalentUpstreamPosition().equivalentRangeCompliantPosition();
+        if ((s.node() == e.node() && s.offset() > e.offset()) || !nodeIsBeforeNode(s.node(), e.node())) {
+            // Make sure the start is before the end.
+            // The end can wind up before the start if collapsed whitespace is the only thing selected.
+            Position tmp = s;
+            s = e;
+            e = tmp;
+        }
+    }
+    ASSERT((s.node() == e.node() && s.offset() <= e.offset()) || nodeIsBeforeNode(s.node(), e.node()));
+
     return Range(Node(s.node()), s.offset(), Node(e.node()), e.offset());
 }
 
@@ -628,7 +659,7 @@ bool Selection::moveToRenderedContent()
     return false;
 }
 
-bool Selection::nodeIsBeforeNode(NodeImpl *n1, NodeImpl *n2) 
+bool Selection::nodeIsBeforeNode(NodeImpl *n1, NodeImpl *n2) const
 {
     if (!n1 || !n2) 
         return true;
diff --git a/WebCore/khtml/editing/SelectionController.h b/WebCore/khtml/editing/SelectionController.h
index d131d40..04f7499 100644
--- a/WebCore/khtml/editing/SelectionController.h
+++ b/WebCore/khtml/editing/SelectionController.h
@@ -124,7 +124,7 @@ private:
     void needsCaretRepaint();
     void paintCaret(QPainter *p, const QRect &rect);
 
-    bool nodeIsBeforeNode(NodeImpl *n1, NodeImpl *n2);
+    bool nodeIsBeforeNode(NodeImpl *n1, NodeImpl *n2) const;
     int xPosForVerticalArrowNavigation(EPositionType, bool recalc=false) const;
 
     Position m_base;              // base position for the selection
diff --git a/WebCore/khtml/editing/selection.cpp b/WebCore/khtml/editing/selection.cpp
index 04217f4..b28bbe5 100644
--- a/WebCore/khtml/editing/selection.cpp
+++ b/WebCore/khtml/editing/selection.cpp
@@ -397,8 +397,39 @@ Range Selection::toRange() const
     if (isEmpty())
         return Range();
 
-    Position s(start().equivalentRangeCompliantPosition());
-    Position e(end().equivalentRangeCompliantPosition());
+    Position s, e;
+    if (state() == CARET) {
+        // If the selection is a caret, move the range start upstream. This helps us match
+        // the conventions of text editors tested, which make style determinations based
+        // on the character before the caret, if any. 
+        s = start().equivalentUpstreamPosition().equivalentRangeCompliantPosition();
+        e = s;
+    }
+    else {
+        // If the selection is a range, select the minimum range that encompasses the selection.
+        // Again, this is to match the conventions of text editors tested, which make style 
+        // determinations based on the first character of the selection. 
+        // For instance, this operation helps to make sure that the "X" selected below is the 
+        // only thing selected. The range should not be allowed to "leak" out to the end of the 
+        // previous text node, or to the beginning of the next text node, each of which has a 
+        // different style.
+        // 
+        // On a treasure map, <b>X</b> marks the spot.
+        //                       ^ selected
+        //
+        ASSERT(state() == RANGE);
+        s = start().equivalentDownstreamPosition().equivalentRangeCompliantPosition();
+        e = end().equivalentUpstreamPosition().equivalentRangeCompliantPosition();
+        if ((s.node() == e.node() && s.offset() > e.offset()) || !nodeIsBeforeNode(s.node(), e.node())) {
+            // Make sure the start is before the end.
+            // The end can wind up before the start if collapsed whitespace is the only thing selected.
+            Position tmp = s;
+            s = e;
+            e = tmp;
+        }
+    }
+    ASSERT((s.node() == e.node() && s.offset() <= e.offset()) || nodeIsBeforeNode(s.node(), e.node()));
+
     return Range(Node(s.node()), s.offset(), Node(e.node()), e.offset());
 }
 
@@ -628,7 +659,7 @@ bool Selection::moveToRenderedContent()
     return false;
 }
 
-bool Selection::nodeIsBeforeNode(NodeImpl *n1, NodeImpl *n2) 
+bool Selection::nodeIsBeforeNode(NodeImpl *n1, NodeImpl *n2) const
 {
     if (!n1 || !n2) 
         return true;
diff --git a/WebCore/khtml/editing/selection.h b/WebCore/khtml/editing/selection.h
index d131d40..04f7499 100644
--- a/WebCore/khtml/editing/selection.h
+++ b/WebCore/khtml/editing/selection.h
@@ -124,7 +124,7 @@ private:
     void needsCaretRepaint();
     void paintCaret(QPainter *p, const QRect &rect);
 
-    bool nodeIsBeforeNode(NodeImpl *n1, NodeImpl *n2);
+    bool nodeIsBeforeNode(NodeImpl *n1, NodeImpl *n2) const;
     int xPosForVerticalArrowNavigation(EPositionType, bool recalc=false) const;
 
     Position m_base;              // base position for the selection
diff --git a/WebCore/khtml/xml/dom_selection.cpp b/WebCore/khtml/xml/dom_selection.cpp
index 04217f4..b28bbe5 100644
--- a/WebCore/khtml/xml/dom_selection.cpp
+++ b/WebCore/khtml/xml/dom_selection.cpp
@@ -397,8 +397,39 @@ Range Selection::toRange() const
     if (isEmpty())
         return Range();
 
-    Position s(start().equivalentRangeCompliantPosition());
-    Position e(end().equivalentRangeCompliantPosition());
+    Position s, e;
+    if (state() == CARET) {
+        // If the selection is a caret, move the range start upstream. This helps us match
+        // the conventions of text editors tested, which make style determinations based
+        // on the character before the caret, if any. 
+        s = start().equivalentUpstreamPosition().equivalentRangeCompliantPosition();
+        e = s;
+    }
+    else {
+        // If the selection is a range, select the minimum range that encompasses the selection.
+        // Again, this is to match the conventions of text editors tested, which make style 
+        // determinations based on the first character of the selection. 
+        // For instance, this operation helps to make sure that the "X" selected below is the 
+        // only thing selected. The range should not be allowed to "leak" out to the end of the 
+        // previous text node, or to the beginning of the next text node, each of which has a 
+        // different style.
+        // 
+        // On a treasure map, <b>X</b> marks the spot.
+        //                       ^ selected
+        //
+        ASSERT(state() == RANGE);
+        s = start().equivalentDownstreamPosition().equivalentRangeCompliantPosition();
+        e = end().equivalentUpstreamPosition().equivalentRangeCompliantPosition();
+        if ((s.node() == e.node() && s.offset() > e.offset()) || !nodeIsBeforeNode(s.node(), e.node())) {
+            // Make sure the start is before the end.
+            // The end can wind up before the start if collapsed whitespace is the only thing selected.
+            Position tmp = s;
+            s = e;
+            e = tmp;
+        }
+    }
+    ASSERT((s.node() == e.node() && s.offset() <= e.offset()) || nodeIsBeforeNode(s.node(), e.node()));
+
     return Range(Node(s.node()), s.offset(), Node(e.node()), e.offset());
 }
 
@@ -628,7 +659,7 @@ bool Selection::moveToRenderedContent()
     return false;
 }
 
-bool Selection::nodeIsBeforeNode(NodeImpl *n1, NodeImpl *n2) 
+bool Selection::nodeIsBeforeNode(NodeImpl *n1, NodeImpl *n2) const
 {
     if (!n1 || !n2) 
         return true;
diff --git a/WebCore/khtml/xml/dom_selection.h b/WebCore/khtml/xml/dom_selection.h
index d131d40..04f7499 100644
--- a/WebCore/khtml/xml/dom_selection.h
+++ b/WebCore/khtml/xml/dom_selection.h
@@ -124,7 +124,7 @@ private:
     void needsCaretRepaint();
     void paintCaret(QPainter *p, const QRect &rect);
 
-    bool nodeIsBeforeNode(NodeImpl *n1, NodeImpl *n2);
+    bool nodeIsBeforeNode(NodeImpl *n1, NodeImpl *n2) const;
     int xPosForVerticalArrowNavigation(EPositionType, bool recalc=false) const;
 
     Position m_base;              // base position for the selection

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list