Reviewed by Ken.
authordarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Jul 2004 20:04:08 +0000 (20:04 +0000)
committerdarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Jul 2004 20:04:08 +0000 (20:04 +0000)
        - added constants for motion across entire document for use in operations like
          move to beginning of document

        * khtml/xml/dom_selection.h: Added DOCUMENT to ETextGranularity.
        * khtml/xml/dom_selection.cpp:
        (DOM::Selection::modifyExtendingRightForward): Added case for DOCUMENT.
        (DOM::Selection::modifyMovingRightForward): Added case for DOCUMENT.
        (DOM::Selection::modifyExtendingLeftBackward): Added case for DOCUMENT.
        (DOM::Selection::modifyMovingLeftBackward): Added case for DOCUMENT.
        (DOM::Selection::validate): Changed if statements into switch statement,
        added case for DOCUMENT.

        * kwq/WebCoreBridge.h: Added WebCoreBridge to WebSelectionGranularity.

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

WebCore/ChangeLog-2005-08-23
WebCore/khtml/editing/SelectionController.cpp
WebCore/khtml/editing/SelectionController.h
WebCore/khtml/editing/selection.cpp
WebCore/khtml/editing/selection.h
WebCore/khtml/xml/dom_selection.cpp
WebCore/khtml/xml/dom_selection.h
WebCore/kwq/WebCoreBridge.h

index f9a9cd8c47e99c265ca2b74c0cebd1253c7080ff..f958427ba5fece4179758ec32c455c60bc1ab2ad 100644 (file)
@@ -1,3 +1,21 @@
+2004-07-29  Darin Adler  <darin@apple.com>
+
+        Reviewed by Ken.
+
+        - added constants for motion across entire document for use in operations like
+          move to beginning of document
+
+        * khtml/xml/dom_selection.h: Added DOCUMENT to ETextGranularity.
+        * khtml/xml/dom_selection.cpp:
+        (DOM::Selection::modifyExtendingRightForward): Added case for DOCUMENT.
+        (DOM::Selection::modifyMovingRightForward): Added case for DOCUMENT.
+        (DOM::Selection::modifyExtendingLeftBackward): Added case for DOCUMENT.
+        (DOM::Selection::modifyMovingLeftBackward): Added case for DOCUMENT.
+        (DOM::Selection::validate): Changed if statements into switch statement,
+        added case for DOCUMENT.
+
+        * kwq/WebCoreBridge.h: Added WebCoreBridge to WebSelectionGranularity.
+
 2004-07-28  Trey Matteson  <trey@apple.com>
 
        Small refinement of last checkin.  The text iterators now return reasonable values
index 2235abaca02ae0f31cb6d4bd7fc7eca7c0321775..fd5ec46392ce19643268c07aa207a1af59f6e262 100644 (file)
@@ -211,15 +211,18 @@ Position Selection::modifyExtendingRightForward(ETextGranularity granularity)
         case LINE:
             pos = pos.nextLinePosition(xPosForVerticalArrowNavigation(EXTENT));
             break;
+        case PARAGRAPH:
+            // not implemented
+            break;
+        case DOCUMENT:
+            pos = Position(start().node()->getDocument()->documentElement(), 1);
+            break;
         case LINE_BOUNDARY: {
             Selection selection;
             startAndEndLineNodesIncludingNode(end().node(), end().offset(), selection);
             pos = selection.end();
             break;
         }
-        case PARAGRAPH:
-            // not implemented
-            break;
     }
     return pos;
 }
@@ -241,15 +244,18 @@ Position Selection::modifyMovingRightForward(ETextGranularity granularity)
         case LINE:
             pos = end().nextLinePosition(xPosForVerticalArrowNavigation(END, state() == RANGE));
             break;
+        case PARAGRAPH:
+            // not implemented
+            break;
+        case DOCUMENT:
+            pos = Position(start().node()->getDocument()->documentElement(), 1);
+            break;
         case LINE_BOUNDARY: {
             Selection selection;
             startAndEndLineNodesIncludingNode(end().node(), end().offset(), selection);
             pos = selection.end();
             break;
         }
-        case PARAGRAPH:
-            // not implemented
-            break;
     }
     return pos;
 }
@@ -271,15 +277,18 @@ Position Selection::modifyExtendingLeftBackward(ETextGranularity granularity)
         case LINE:
             pos = pos.previousLinePosition(xPosForVerticalArrowNavigation(EXTENT));
             break;
+        case PARAGRAPH:
+            // not implemented
+            break;
+        case DOCUMENT:
+            pos = Position(start().node()->getDocument()->documentElement(), 0);
+            break;
         case LINE_BOUNDARY: {
             Selection selection;
             startAndEndLineNodesIncludingNode(start().node(), start().offset(), selection);
             pos = selection.start();
             break;
         }
-        case PARAGRAPH:
-            // not implemented
-            break;
     }
     return pos;
 }
@@ -301,15 +310,18 @@ Position Selection::modifyMovingLeftBackward(ETextGranularity granularity)
         case LINE:
             pos = start().previousLinePosition(xPosForVerticalArrowNavigation(START, state() == RANGE));
             break;
+        case PARAGRAPH:
+            // not implemented
+            break;
+        case DOCUMENT:
+            pos = Position(start().node()->getDocument()->documentElement(), 0);
+            break;
         case LINE_BOUNDARY: {
             Selection selection;
             startAndEndLineNodesIncludingNode(start().node(), start().offset(), selection);
             pos = selection.start();
             break;
         }
-        case PARAGRAPH:
-            // not implemented
-            break;
     }
     return pos;
 }
@@ -620,60 +632,73 @@ void Selection::validate(ETextGranularity granularity)
     }
 
     // calculate the correct start and end positions
-    if (granularity == CHARACTER) {
-        if (m_baseIsStart)
-            assignStartAndEnd(base(), extent());
-        else
-            assignStartAndEnd(extent(), base());
-    }
-    else if (granularity == WORD) {
-        int baseStartOffset = base().offset();
-        int baseEndOffset = base().offset();
-        int extentStartOffset = extent().offset();
-        int extentEndOffset = extent().offset();
-        if (base().notEmpty() && (base().node()->nodeType() == Node::TEXT_NODE || base().node()->nodeType() == Node::CDATA_SECTION_NODE)) {
-            DOMString t = base().node()->nodeValue();
-            QChar *chars = t.unicode();
-            uint len = t.length();
-            findWordBoundary(chars, len, base().offset(), &baseStartOffset, &baseEndOffset);
-        }
-        if (extent().notEmpty() && (extent().node()->nodeType() == Node::TEXT_NODE || extent().node()->nodeType() == Node::CDATA_SECTION_NODE)) {
-            DOMString t = extent().node()->nodeValue();
-            QChar *chars = t.unicode();
-            uint len = t.length();
-            findWordBoundary(chars, len, extent().offset(), &extentStartOffset, &extentEndOffset);
-        }
-        if (m_baseIsStart) {
-            assignStart(Position(base().node(), baseStartOffset));
-            assignEnd(Position(extent().node(), extentEndOffset));
-        }
-        else {
-            assignStart(Position(extent().node(), extentStartOffset));
-            assignEnd(Position(base().node(), baseEndOffset));
-        }
-    }
-    else {  // granularity == LINE 
-        Selection baseSelection = *this;
-        Selection extentSelection = *this;
-        if (base().notEmpty() && (base().node()->nodeType() == Node::TEXT_NODE || base().node()->nodeType() == Node::CDATA_SECTION_NODE)) {
-            if (startAndEndLineNodesIncludingNode(base().node(), base().offset(), baseSelection)) {
-                assignStart(Position(baseSelection.base().node(), baseSelection.base().offset()));
-                assignEnd(Position(baseSelection.extent().node(), baseSelection.extent().offset()));
+    switch (granularity) {
+        case CHARACTER:
+            if (m_baseIsStart)
+                assignStartAndEnd(base(), extent());
+            else
+                assignStartAndEnd(extent(), base());
+            break;
+        case WORD: {
+            int baseStartOffset = base().offset();
+            int baseEndOffset = base().offset();
+            int extentStartOffset = extent().offset();
+            int extentEndOffset = extent().offset();
+            if (base().notEmpty() && (base().node()->nodeType() == Node::TEXT_NODE || base().node()->nodeType() == Node::CDATA_SECTION_NODE)) {
+                DOMString t = base().node()->nodeValue();
+                QChar *chars = t.unicode();
+                uint len = t.length();
+                findWordBoundary(chars, len, base().offset(), &baseStartOffset, &baseEndOffset);
             }
-        }
-        if (extent().notEmpty() && (extent().node()->nodeType() == Node::TEXT_NODE || extent().node()->nodeType() == Node::CDATA_SECTION_NODE)) {
-            if (startAndEndLineNodesIncludingNode(extent().node(), extent().offset(), extentSelection)) {
-                assignStart(Position(extentSelection.base().node(), extentSelection.base().offset()));
-                assignEnd(Position(extentSelection.extent().node(), extentSelection.extent().offset()));
+            if (extent().notEmpty() && (extent().node()->nodeType() == Node::TEXT_NODE || extent().node()->nodeType() == Node::CDATA_SECTION_NODE)) {
+                DOMString t = extent().node()->nodeValue();
+                QChar *chars = t.unicode();
+                uint len = t.length();
+                findWordBoundary(chars, len, extent().offset(), &extentStartOffset, &extentEndOffset);
+            }
+            if (m_baseIsStart) {
+                assignStart(Position(base().node(), baseStartOffset));
+                assignEnd(Position(extent().node(), extentEndOffset));
             }
+            else {
+                assignStart(Position(extent().node(), extentStartOffset));
+                assignEnd(Position(base().node(), baseEndOffset));
+            }
+            break;
         }
-        if (m_baseIsStart) {
-            assignStart(baseSelection.start());
-            assignEnd(extentSelection.end());
+        case LINE:
+        case LINE_BOUNDARY: {
+            Selection baseSelection = *this;
+            Selection extentSelection = *this;
+            if (base().notEmpty() && (base().node()->nodeType() == Node::TEXT_NODE || base().node()->nodeType() == Node::CDATA_SECTION_NODE)) {
+                if (startAndEndLineNodesIncludingNode(base().node(), base().offset(), baseSelection)) {
+                    assignStart(Position(baseSelection.base().node(), baseSelection.base().offset()));
+                    assignEnd(Position(baseSelection.extent().node(), baseSelection.extent().offset()));
+                }
+            }
+            if (extent().notEmpty() && (extent().node()->nodeType() == Node::TEXT_NODE || extent().node()->nodeType() == Node::CDATA_SECTION_NODE)) {
+                if (startAndEndLineNodesIncludingNode(extent().node(), extent().offset(), extentSelection)) {
+                    assignStart(Position(extentSelection.base().node(), extentSelection.base().offset()));
+                    assignEnd(Position(extentSelection.extent().node(), extentSelection.extent().offset()));
+                }
+            }
+            if (m_baseIsStart) {
+                assignStart(baseSelection.start());
+                assignEnd(extentSelection.end());
+            }
+            else {
+                assignStart(extentSelection.start());
+                assignEnd(baseSelection.end());
+            }
         }
-        else {
-            assignStart(extentSelection.start());
-            assignEnd(baseSelection.end());
+        case PARAGRAPH:
+            // not implemented
+            break;
+        case DOCUMENT: {
+            NodeImpl *topNode = start().node()->getDocument()->documentElement();
+            assignStart(Position(topNode, 0));
+            assignEnd(Position(topNode, 1));
+            break;
         }
     }
 
index ba2a8f99d9fa41f113849ffaaf4999fd1d8fbdae..b5f81705c11aa07f9cf8ac22b5617f28ce84f380 100644 (file)
@@ -48,7 +48,7 @@ public:
     enum EState { NONE, CARET, RANGE };
     enum EAlter { MOVE, EXTEND };
     enum EDirection { FORWARD, BACKWARD, RIGHT, LEFT };
-    enum ETextGranularity { CHARACTER, WORD, LINE, PARAGRAPH, LINE_BOUNDARY };
+    enum ETextGranularity { CHARACTER, WORD, LINE, PARAGRAPH, DOCUMENT, LINE_BOUNDARY };
 
     Selection();
     Selection(const Range &);
index 2235abaca02ae0f31cb6d4bd7fc7eca7c0321775..fd5ec46392ce19643268c07aa207a1af59f6e262 100644 (file)
@@ -211,15 +211,18 @@ Position Selection::modifyExtendingRightForward(ETextGranularity granularity)
         case LINE:
             pos = pos.nextLinePosition(xPosForVerticalArrowNavigation(EXTENT));
             break;
+        case PARAGRAPH:
+            // not implemented
+            break;
+        case DOCUMENT:
+            pos = Position(start().node()->getDocument()->documentElement(), 1);
+            break;
         case LINE_BOUNDARY: {
             Selection selection;
             startAndEndLineNodesIncludingNode(end().node(), end().offset(), selection);
             pos = selection.end();
             break;
         }
-        case PARAGRAPH:
-            // not implemented
-            break;
     }
     return pos;
 }
@@ -241,15 +244,18 @@ Position Selection::modifyMovingRightForward(ETextGranularity granularity)
         case LINE:
             pos = end().nextLinePosition(xPosForVerticalArrowNavigation(END, state() == RANGE));
             break;
+        case PARAGRAPH:
+            // not implemented
+            break;
+        case DOCUMENT:
+            pos = Position(start().node()->getDocument()->documentElement(), 1);
+            break;
         case LINE_BOUNDARY: {
             Selection selection;
             startAndEndLineNodesIncludingNode(end().node(), end().offset(), selection);
             pos = selection.end();
             break;
         }
-        case PARAGRAPH:
-            // not implemented
-            break;
     }
     return pos;
 }
@@ -271,15 +277,18 @@ Position Selection::modifyExtendingLeftBackward(ETextGranularity granularity)
         case LINE:
             pos = pos.previousLinePosition(xPosForVerticalArrowNavigation(EXTENT));
             break;
+        case PARAGRAPH:
+            // not implemented
+            break;
+        case DOCUMENT:
+            pos = Position(start().node()->getDocument()->documentElement(), 0);
+            break;
         case LINE_BOUNDARY: {
             Selection selection;
             startAndEndLineNodesIncludingNode(start().node(), start().offset(), selection);
             pos = selection.start();
             break;
         }
-        case PARAGRAPH:
-            // not implemented
-            break;
     }
     return pos;
 }
@@ -301,15 +310,18 @@ Position Selection::modifyMovingLeftBackward(ETextGranularity granularity)
         case LINE:
             pos = start().previousLinePosition(xPosForVerticalArrowNavigation(START, state() == RANGE));
             break;
+        case PARAGRAPH:
+            // not implemented
+            break;
+        case DOCUMENT:
+            pos = Position(start().node()->getDocument()->documentElement(), 0);
+            break;
         case LINE_BOUNDARY: {
             Selection selection;
             startAndEndLineNodesIncludingNode(start().node(), start().offset(), selection);
             pos = selection.start();
             break;
         }
-        case PARAGRAPH:
-            // not implemented
-            break;
     }
     return pos;
 }
@@ -620,60 +632,73 @@ void Selection::validate(ETextGranularity granularity)
     }
 
     // calculate the correct start and end positions
-    if (granularity == CHARACTER) {
-        if (m_baseIsStart)
-            assignStartAndEnd(base(), extent());
-        else
-            assignStartAndEnd(extent(), base());
-    }
-    else if (granularity == WORD) {
-        int baseStartOffset = base().offset();
-        int baseEndOffset = base().offset();
-        int extentStartOffset = extent().offset();
-        int extentEndOffset = extent().offset();
-        if (base().notEmpty() && (base().node()->nodeType() == Node::TEXT_NODE || base().node()->nodeType() == Node::CDATA_SECTION_NODE)) {
-            DOMString t = base().node()->nodeValue();
-            QChar *chars = t.unicode();
-            uint len = t.length();
-            findWordBoundary(chars, len, base().offset(), &baseStartOffset, &baseEndOffset);
-        }
-        if (extent().notEmpty() && (extent().node()->nodeType() == Node::TEXT_NODE || extent().node()->nodeType() == Node::CDATA_SECTION_NODE)) {
-            DOMString t = extent().node()->nodeValue();
-            QChar *chars = t.unicode();
-            uint len = t.length();
-            findWordBoundary(chars, len, extent().offset(), &extentStartOffset, &extentEndOffset);
-        }
-        if (m_baseIsStart) {
-            assignStart(Position(base().node(), baseStartOffset));
-            assignEnd(Position(extent().node(), extentEndOffset));
-        }
-        else {
-            assignStart(Position(extent().node(), extentStartOffset));
-            assignEnd(Position(base().node(), baseEndOffset));
-        }
-    }
-    else {  // granularity == LINE 
-        Selection baseSelection = *this;
-        Selection extentSelection = *this;
-        if (base().notEmpty() && (base().node()->nodeType() == Node::TEXT_NODE || base().node()->nodeType() == Node::CDATA_SECTION_NODE)) {
-            if (startAndEndLineNodesIncludingNode(base().node(), base().offset(), baseSelection)) {
-                assignStart(Position(baseSelection.base().node(), baseSelection.base().offset()));
-                assignEnd(Position(baseSelection.extent().node(), baseSelection.extent().offset()));
+    switch (granularity) {
+        case CHARACTER:
+            if (m_baseIsStart)
+                assignStartAndEnd(base(), extent());
+            else
+                assignStartAndEnd(extent(), base());
+            break;
+        case WORD: {
+            int baseStartOffset = base().offset();
+            int baseEndOffset = base().offset();
+            int extentStartOffset = extent().offset();
+            int extentEndOffset = extent().offset();
+            if (base().notEmpty() && (base().node()->nodeType() == Node::TEXT_NODE || base().node()->nodeType() == Node::CDATA_SECTION_NODE)) {
+                DOMString t = base().node()->nodeValue();
+                QChar *chars = t.unicode();
+                uint len = t.length();
+                findWordBoundary(chars, len, base().offset(), &baseStartOffset, &baseEndOffset);
             }
-        }
-        if (extent().notEmpty() && (extent().node()->nodeType() == Node::TEXT_NODE || extent().node()->nodeType() == Node::CDATA_SECTION_NODE)) {
-            if (startAndEndLineNodesIncludingNode(extent().node(), extent().offset(), extentSelection)) {
-                assignStart(Position(extentSelection.base().node(), extentSelection.base().offset()));
-                assignEnd(Position(extentSelection.extent().node(), extentSelection.extent().offset()));
+            if (extent().notEmpty() && (extent().node()->nodeType() == Node::TEXT_NODE || extent().node()->nodeType() == Node::CDATA_SECTION_NODE)) {
+                DOMString t = extent().node()->nodeValue();
+                QChar *chars = t.unicode();
+                uint len = t.length();
+                findWordBoundary(chars, len, extent().offset(), &extentStartOffset, &extentEndOffset);
+            }
+            if (m_baseIsStart) {
+                assignStart(Position(base().node(), baseStartOffset));
+                assignEnd(Position(extent().node(), extentEndOffset));
             }
+            else {
+                assignStart(Position(extent().node(), extentStartOffset));
+                assignEnd(Position(base().node(), baseEndOffset));
+            }
+            break;
         }
-        if (m_baseIsStart) {
-            assignStart(baseSelection.start());
-            assignEnd(extentSelection.end());
+        case LINE:
+        case LINE_BOUNDARY: {
+            Selection baseSelection = *this;
+            Selection extentSelection = *this;
+            if (base().notEmpty() && (base().node()->nodeType() == Node::TEXT_NODE || base().node()->nodeType() == Node::CDATA_SECTION_NODE)) {
+                if (startAndEndLineNodesIncludingNode(base().node(), base().offset(), baseSelection)) {
+                    assignStart(Position(baseSelection.base().node(), baseSelection.base().offset()));
+                    assignEnd(Position(baseSelection.extent().node(), baseSelection.extent().offset()));
+                }
+            }
+            if (extent().notEmpty() && (extent().node()->nodeType() == Node::TEXT_NODE || extent().node()->nodeType() == Node::CDATA_SECTION_NODE)) {
+                if (startAndEndLineNodesIncludingNode(extent().node(), extent().offset(), extentSelection)) {
+                    assignStart(Position(extentSelection.base().node(), extentSelection.base().offset()));
+                    assignEnd(Position(extentSelection.extent().node(), extentSelection.extent().offset()));
+                }
+            }
+            if (m_baseIsStart) {
+                assignStart(baseSelection.start());
+                assignEnd(extentSelection.end());
+            }
+            else {
+                assignStart(extentSelection.start());
+                assignEnd(baseSelection.end());
+            }
         }
-        else {
-            assignStart(extentSelection.start());
-            assignEnd(baseSelection.end());
+        case PARAGRAPH:
+            // not implemented
+            break;
+        case DOCUMENT: {
+            NodeImpl *topNode = start().node()->getDocument()->documentElement();
+            assignStart(Position(topNode, 0));
+            assignEnd(Position(topNode, 1));
+            break;
         }
     }
 
index ba2a8f99d9fa41f113849ffaaf4999fd1d8fbdae..b5f81705c11aa07f9cf8ac22b5617f28ce84f380 100644 (file)
@@ -48,7 +48,7 @@ public:
     enum EState { NONE, CARET, RANGE };
     enum EAlter { MOVE, EXTEND };
     enum EDirection { FORWARD, BACKWARD, RIGHT, LEFT };
-    enum ETextGranularity { CHARACTER, WORD, LINE, PARAGRAPH, LINE_BOUNDARY };
+    enum ETextGranularity { CHARACTER, WORD, LINE, PARAGRAPH, DOCUMENT, LINE_BOUNDARY };
 
     Selection();
     Selection(const Range &);
index 2235abaca02ae0f31cb6d4bd7fc7eca7c0321775..fd5ec46392ce19643268c07aa207a1af59f6e262 100644 (file)
@@ -211,15 +211,18 @@ Position Selection::modifyExtendingRightForward(ETextGranularity granularity)
         case LINE:
             pos = pos.nextLinePosition(xPosForVerticalArrowNavigation(EXTENT));
             break;
+        case PARAGRAPH:
+            // not implemented
+            break;
+        case DOCUMENT:
+            pos = Position(start().node()->getDocument()->documentElement(), 1);
+            break;
         case LINE_BOUNDARY: {
             Selection selection;
             startAndEndLineNodesIncludingNode(end().node(), end().offset(), selection);
             pos = selection.end();
             break;
         }
-        case PARAGRAPH:
-            // not implemented
-            break;
     }
     return pos;
 }
@@ -241,15 +244,18 @@ Position Selection::modifyMovingRightForward(ETextGranularity granularity)
         case LINE:
             pos = end().nextLinePosition(xPosForVerticalArrowNavigation(END, state() == RANGE));
             break;
+        case PARAGRAPH:
+            // not implemented
+            break;
+        case DOCUMENT:
+            pos = Position(start().node()->getDocument()->documentElement(), 1);
+            break;
         case LINE_BOUNDARY: {
             Selection selection;
             startAndEndLineNodesIncludingNode(end().node(), end().offset(), selection);
             pos = selection.end();
             break;
         }
-        case PARAGRAPH:
-            // not implemented
-            break;
     }
     return pos;
 }
@@ -271,15 +277,18 @@ Position Selection::modifyExtendingLeftBackward(ETextGranularity granularity)
         case LINE:
             pos = pos.previousLinePosition(xPosForVerticalArrowNavigation(EXTENT));
             break;
+        case PARAGRAPH:
+            // not implemented
+            break;
+        case DOCUMENT:
+            pos = Position(start().node()->getDocument()->documentElement(), 0);
+            break;
         case LINE_BOUNDARY: {
             Selection selection;
             startAndEndLineNodesIncludingNode(start().node(), start().offset(), selection);
             pos = selection.start();
             break;
         }
-        case PARAGRAPH:
-            // not implemented
-            break;
     }
     return pos;
 }
@@ -301,15 +310,18 @@ Position Selection::modifyMovingLeftBackward(ETextGranularity granularity)
         case LINE:
             pos = start().previousLinePosition(xPosForVerticalArrowNavigation(START, state() == RANGE));
             break;
+        case PARAGRAPH:
+            // not implemented
+            break;
+        case DOCUMENT:
+            pos = Position(start().node()->getDocument()->documentElement(), 0);
+            break;
         case LINE_BOUNDARY: {
             Selection selection;
             startAndEndLineNodesIncludingNode(start().node(), start().offset(), selection);
             pos = selection.start();
             break;
         }
-        case PARAGRAPH:
-            // not implemented
-            break;
     }
     return pos;
 }
@@ -620,60 +632,73 @@ void Selection::validate(ETextGranularity granularity)
     }
 
     // calculate the correct start and end positions
-    if (granularity == CHARACTER) {
-        if (m_baseIsStart)
-            assignStartAndEnd(base(), extent());
-        else
-            assignStartAndEnd(extent(), base());
-    }
-    else if (granularity == WORD) {
-        int baseStartOffset = base().offset();
-        int baseEndOffset = base().offset();
-        int extentStartOffset = extent().offset();
-        int extentEndOffset = extent().offset();
-        if (base().notEmpty() && (base().node()->nodeType() == Node::TEXT_NODE || base().node()->nodeType() == Node::CDATA_SECTION_NODE)) {
-            DOMString t = base().node()->nodeValue();
-            QChar *chars = t.unicode();
-            uint len = t.length();
-            findWordBoundary(chars, len, base().offset(), &baseStartOffset, &baseEndOffset);
-        }
-        if (extent().notEmpty() && (extent().node()->nodeType() == Node::TEXT_NODE || extent().node()->nodeType() == Node::CDATA_SECTION_NODE)) {
-            DOMString t = extent().node()->nodeValue();
-            QChar *chars = t.unicode();
-            uint len = t.length();
-            findWordBoundary(chars, len, extent().offset(), &extentStartOffset, &extentEndOffset);
-        }
-        if (m_baseIsStart) {
-            assignStart(Position(base().node(), baseStartOffset));
-            assignEnd(Position(extent().node(), extentEndOffset));
-        }
-        else {
-            assignStart(Position(extent().node(), extentStartOffset));
-            assignEnd(Position(base().node(), baseEndOffset));
-        }
-    }
-    else {  // granularity == LINE 
-        Selection baseSelection = *this;
-        Selection extentSelection = *this;
-        if (base().notEmpty() && (base().node()->nodeType() == Node::TEXT_NODE || base().node()->nodeType() == Node::CDATA_SECTION_NODE)) {
-            if (startAndEndLineNodesIncludingNode(base().node(), base().offset(), baseSelection)) {
-                assignStart(Position(baseSelection.base().node(), baseSelection.base().offset()));
-                assignEnd(Position(baseSelection.extent().node(), baseSelection.extent().offset()));
+    switch (granularity) {
+        case CHARACTER:
+            if (m_baseIsStart)
+                assignStartAndEnd(base(), extent());
+            else
+                assignStartAndEnd(extent(), base());
+            break;
+        case WORD: {
+            int baseStartOffset = base().offset();
+            int baseEndOffset = base().offset();
+            int extentStartOffset = extent().offset();
+            int extentEndOffset = extent().offset();
+            if (base().notEmpty() && (base().node()->nodeType() == Node::TEXT_NODE || base().node()->nodeType() == Node::CDATA_SECTION_NODE)) {
+                DOMString t = base().node()->nodeValue();
+                QChar *chars = t.unicode();
+                uint len = t.length();
+                findWordBoundary(chars, len, base().offset(), &baseStartOffset, &baseEndOffset);
             }
-        }
-        if (extent().notEmpty() && (extent().node()->nodeType() == Node::TEXT_NODE || extent().node()->nodeType() == Node::CDATA_SECTION_NODE)) {
-            if (startAndEndLineNodesIncludingNode(extent().node(), extent().offset(), extentSelection)) {
-                assignStart(Position(extentSelection.base().node(), extentSelection.base().offset()));
-                assignEnd(Position(extentSelection.extent().node(), extentSelection.extent().offset()));
+            if (extent().notEmpty() && (extent().node()->nodeType() == Node::TEXT_NODE || extent().node()->nodeType() == Node::CDATA_SECTION_NODE)) {
+                DOMString t = extent().node()->nodeValue();
+                QChar *chars = t.unicode();
+                uint len = t.length();
+                findWordBoundary(chars, len, extent().offset(), &extentStartOffset, &extentEndOffset);
+            }
+            if (m_baseIsStart) {
+                assignStart(Position(base().node(), baseStartOffset));
+                assignEnd(Position(extent().node(), extentEndOffset));
             }
+            else {
+                assignStart(Position(extent().node(), extentStartOffset));
+                assignEnd(Position(base().node(), baseEndOffset));
+            }
+            break;
         }
-        if (m_baseIsStart) {
-            assignStart(baseSelection.start());
-            assignEnd(extentSelection.end());
+        case LINE:
+        case LINE_BOUNDARY: {
+            Selection baseSelection = *this;
+            Selection extentSelection = *this;
+            if (base().notEmpty() && (base().node()->nodeType() == Node::TEXT_NODE || base().node()->nodeType() == Node::CDATA_SECTION_NODE)) {
+                if (startAndEndLineNodesIncludingNode(base().node(), base().offset(), baseSelection)) {
+                    assignStart(Position(baseSelection.base().node(), baseSelection.base().offset()));
+                    assignEnd(Position(baseSelection.extent().node(), baseSelection.extent().offset()));
+                }
+            }
+            if (extent().notEmpty() && (extent().node()->nodeType() == Node::TEXT_NODE || extent().node()->nodeType() == Node::CDATA_SECTION_NODE)) {
+                if (startAndEndLineNodesIncludingNode(extent().node(), extent().offset(), extentSelection)) {
+                    assignStart(Position(extentSelection.base().node(), extentSelection.base().offset()));
+                    assignEnd(Position(extentSelection.extent().node(), extentSelection.extent().offset()));
+                }
+            }
+            if (m_baseIsStart) {
+                assignStart(baseSelection.start());
+                assignEnd(extentSelection.end());
+            }
+            else {
+                assignStart(extentSelection.start());
+                assignEnd(baseSelection.end());
+            }
         }
-        else {
-            assignStart(extentSelection.start());
-            assignEnd(baseSelection.end());
+        case PARAGRAPH:
+            // not implemented
+            break;
+        case DOCUMENT: {
+            NodeImpl *topNode = start().node()->getDocument()->documentElement();
+            assignStart(Position(topNode, 0));
+            assignEnd(Position(topNode, 1));
+            break;
         }
     }
 
index ba2a8f99d9fa41f113849ffaaf4999fd1d8fbdae..b5f81705c11aa07f9cf8ac22b5617f28ce84f380 100644 (file)
@@ -48,7 +48,7 @@ public:
     enum EState { NONE, CARET, RANGE };
     enum EAlter { MOVE, EXTEND };
     enum EDirection { FORWARD, BACKWARD, RIGHT, LEFT };
-    enum ETextGranularity { CHARACTER, WORD, LINE, PARAGRAPH, LINE_BOUNDARY };
+    enum ETextGranularity { CHARACTER, WORD, LINE, PARAGRAPH, DOCUMENT, LINE_BOUNDARY };
 
     Selection();
     Selection(const Range &);
index 1de686bd5333ba7d61d45a10f5f39c0d3252af83..420d64c5959bc708cd26466244362bde1e6045fc 100644 (file)
@@ -107,7 +107,8 @@ typedef enum {
     WebSelectByWord,
     WebSelectByLine,
     WebSelectByParagraph,
-    WebSelectToLineBoundary,
+    WebSelectByDocument,
+    WebSelectToLineBoundary
 } WebSelectionGranularity;