[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:35:10 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit a0cfbd3afa15a3457bfa78fef00e9b14fbcbc990
Author: kocienda <kocienda at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Apr 20 22:17:08 2004 +0000

            Reviewed by Hyatt
    
            Renamed DOMPosition class to Position.
            Renamed KHTMLSelection to Selection and moved to DOM namespace.
    
            * ForwardingHeaders/xml/dom_selection.h: Added.
            * WebCore.pbproj/project.pbxproj: Go Xcode!
            * khtml/khtml_selection.cpp: Removed.
            * khtml/khtml_selection.h: Removed.
            * khtml/xml/dom_position.cpp: Renamed DOMPosition to Position
            * khtml/xml/dom_position.h: Ditto.
            * khtml/xml/dom_selection.cpp: New home for renamed Selection object.
            * khtml/xml/dom_selection.h: Ditto.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@6432 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index 5f22656..0bd17f4 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,6 +1,22 @@
 2004-04-20  Ken Kocienda  <kocienda at apple.com>
 
         Reviewed by Hyatt
+        
+        Renamed DOMPosition class to Position.
+        Renamed KHTMLSelection to Selection and moved to DOM namespace.
+
+        * ForwardingHeaders/xml/dom_selection.h: Added.
+        * WebCore.pbproj/project.pbxproj: Go Xcode!
+        * khtml/khtml_selection.cpp: Removed.
+        * khtml/khtml_selection.h: Removed.
+        * khtml/xml/dom_position.cpp: Renamed DOMPosition to Position
+        * khtml/xml/dom_position.h: Ditto.
+        * khtml/xml/dom_selection.cpp: New home for renamed Selection object.
+        * khtml/xml/dom_selection.h: Ditto.
+
+2004-04-20  Ken Kocienda  <kocienda at apple.com>
+
+        Reviewed by Hyatt
 
         * WebCore.pbproj/project.pbxproj:
         * khtml/khtml_part.cpp:
diff --git a/WebCore/ForwardingHeaders/xml/dom_selection.h b/WebCore/ForwardingHeaders/xml/dom_selection.h
new file mode 100644
index 0000000..dbbd2a9
--- /dev/null
+++ b/WebCore/ForwardingHeaders/xml/dom_selection.h
@@ -0,0 +1 @@
+#include <dom_selection.h>
diff --git a/WebCore/WebCore.pbproj/project.pbxproj b/WebCore/WebCore.pbproj/project.pbxproj
index cdde0e8..7e8aa2f 100644
--- a/WebCore/WebCore.pbproj/project.pbxproj
+++ b/WebCore/WebCore.pbproj/project.pbxproj
@@ -508,7 +508,6 @@
 				BC745A1D05955F390058C893,
 				BCBDB03A0597B36E00B83B92,
 				BCBDB096059A28B100B83B92,
-				BEB1DD3205C1980700DD1F43,
 				BC7FDE3405C1D9AB0070A902,
 				BC7E782205C5EB700088A50F,
 				BC3B364905C9D5E200E42902,
@@ -533,6 +532,7 @@
 				832556E5061DF155007B8054,
 				BC86FB8F061F5C23006BB822,
 				BE8BD8F506359F6000D3F20B,
+				BE8BD90B0635CC2F00D3F20B,
 			);
 			isa = PBXHeadersBuildPhase;
 			runOnlyForDeploymentPostprocessing = 0;
@@ -799,7 +799,6 @@
 				BC745A1C05955F390058C893,
 				BCBDB0390597B36E00B83B92,
 				BCBDB095059A28B100B83B92,
-				BEB1DD3105C1980700DD1F43,
 				BC7FDE3305C1D9AB0070A902,
 				BC3B364805C9D5E200E42902,
 				BC433AD005D3046F003A5A14,
@@ -815,6 +814,7 @@
 				832556E7061DF161007B8054,
 				BC86FB90061F5C23006BB822,
 				BE8BD8F406359F6000D3F20B,
+				BE8BD90A0635CC2F00D3F20B,
 			);
 			isa = PBXSourcesBuildPhase;
 			runOnlyForDeploymentPostprocessing = 0;
@@ -862,7 +862,7 @@
 			isa = PBXShellScriptBuildPhase;
 			runOnlyForDeploymentPostprocessing = 0;
 			shellPath = /bin/sh;
-			shellScript = "#if [ -f ../Tools/Scripts/embed-into-alex ]; then sh ../Tools/Scripts/embed-into-alex; fi";
+			shellScript = "if [ -f ../Tools/Scripts/embed-into-alex ]; then sh ../Tools/Scripts/embed-into-alex; fi";
 		};
 //250
 //251
@@ -2746,6 +2746,34 @@
 			settings = {
 			};
 		};
+		BE8BD9080635CC2F00D3F20B = {
+			fileEncoding = 30;
+			isa = PBXFileReference;
+			lastKnownFileType = sourcecode.cpp.cpp;
+			path = dom_selection.cpp;
+			refType = 4;
+			sourceTree = "<group>";
+		};
+		BE8BD9090635CC2F00D3F20B = {
+			fileEncoding = 30;
+			isa = PBXFileReference;
+			lastKnownFileType = sourcecode.c.h;
+			path = dom_selection.h;
+			refType = 4;
+			sourceTree = "<group>";
+		};
+		BE8BD90A0635CC2F00D3F20B = {
+			fileRef = BE8BD9080635CC2F00D3F20B;
+			isa = PBXBuildFile;
+			settings = {
+			};
+		};
+		BE8BD90B0635CC2F00D3F20B = {
+			fileRef = BE8BD9090635CC2F00D3F20B;
+			isa = PBXBuildFile;
+			settings = {
+			};
+		};
 		BE9185DD05EE59B80081354D = {
 			fileEncoding = 30;
 			isa = PBXFileReference;
@@ -2989,34 +3017,6 @@
 			refType = 4;
 			sourceTree = "<group>";
 		};
-		BEB1DD2F05C1980700DD1F43 = {
-			fileEncoding = 30;
-			isa = PBXFileReference;
-			lastKnownFileType = sourcecode.cpp.cpp;
-			path = khtml_selection.cpp;
-			refType = 4;
-			sourceTree = "<group>";
-		};
-		BEB1DD3005C1980700DD1F43 = {
-			fileEncoding = 30;
-			isa = PBXFileReference;
-			lastKnownFileType = sourcecode.c.h;
-			path = khtml_selection.h;
-			refType = 4;
-			sourceTree = "<group>";
-		};
-		BEB1DD3105C1980700DD1F43 = {
-			fileRef = BEB1DD2F05C1980700DD1F43;
-			isa = PBXBuildFile;
-			settings = {
-			};
-		};
-		BEB1DD3205C1980700DD1F43 = {
-			fileRef = BEB1DD3005C1980700DD1F43;
-			isa = PBXBuildFile;
-			settings = {
-			};
-		};
 		BEF7EEA005FF8F0D009717EE = {
 			fileEncoding = 30;
 			isa = PBXFileReference;
@@ -3292,8 +3292,6 @@
 				F523D15402DE42AD018635CA,
 				F523D15602DE42AD018635CA,
 				F523D15302DE42AD018635CA,
-				BEB1DD2F05C1980700DD1F43,
-				BEB1DD3005C1980700DD1F43,
 				F523D15702DE42AD018635CA,
 				F523D15802DE42AD018635CA,
 			);
@@ -6393,6 +6391,8 @@
 				F523D2FA02DE4476018635CA,
 				BE91FC8B06133666005E3790,
 				BE91FC8C06133666005E3790,
+				BE8BD9080635CC2F00D3F20B,
+				BE8BD9090635CC2F00D3F20B,
 				F523D2FB02DE4476018635CA,
 				F523D2FC02DE4476018635CA,
 				F523D2FD02DE4476018635CA,
diff --git a/WebCore/khtml/ecma/kjs_window.cpp b/WebCore/khtml/ecma/kjs_window.cpp
index 1f07288..ea69dc7 100644
--- a/WebCore/khtml/ecma/kjs_window.cpp
+++ b/WebCore/khtml/ecma/kjs_window.cpp
@@ -53,12 +53,12 @@
 
 #include "khtmlview.h"
 #include "khtml_part.h"
-#include "khtml_selection.h"
 #include "dom/dom_string.h"
 #include "dom/dom_node.h"
 #include "editing/htmlediting.h"
 #include "xml/dom2_eventsimpl.h"
 #include "xml/dom_docimpl.h"
+#include "xml/dom_selection.h"
 #include "html/html_documentimpl.h"
 
 using DOM::DocumentImpl;
@@ -2168,14 +2168,14 @@ Value Selection::get(ExecState *exec, const Identifier &p) const
         case ExtentOffset:
             return Number(m_part->selection().extentOffset());
         case IsCollapsed:
-            return Boolean(m_part->selection().state() == KHTMLSelection::CARET);
+            return Boolean(m_part->selection().state() == DOM::Selection::CARET);
         case _Type: {
             switch (m_part->selection().state()) {
-                case KHTMLSelection::NONE:
+                case DOM::Selection::NONE:
                     return String("None");
-                case KHTMLSelection::CARET:
+                case DOM::Selection::CARET:
                     return String("Caret");
-                case KHTMLSelection::RANGE:
+                case DOM::Selection::RANGE:
                     return String("Range");
             }
         }
@@ -2214,7 +2214,7 @@ Value Selection::toPrimitive(ExecState *exec, Type) const
 
 UString Selection::toString(ExecState *) const
 {
-    if (m_part->selection().state() != KHTMLSelection::RANGE)
+    if (m_part->selection().state() != DOM::Selection::RANGE)
         return UString("");
     return UString(m_part->selection().toRange().toString());
 }
@@ -2236,15 +2236,15 @@ Value SelectionFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
         switch (id) {
             case Selection::Collapse:
                 TypingCommand::closeTyping(part->lastEditCommand());
-                part->setSelection(KHTMLSelection(KJS::toNode(args[0]).handle(), args[1].toInt32(exec)));
+                part->setSelection(DOM::Selection(KJS::toNode(args[0]).handle(), args[1].toInt32(exec)));
                 break;
             case Selection::CollapseToEnd:
                 TypingCommand::closeTyping(part->lastEditCommand());
-                part->setSelection(KHTMLSelection(part->selection().endPosition()));
+                part->setSelection(DOM::Selection(part->selection().endPosition()));
                 break;
             case Selection::CollapseToStart:
                 TypingCommand::closeTyping(part->lastEditCommand());
-                part->setSelection(KHTMLSelection(part->selection().startPosition()));
+                part->setSelection(DOM::Selection(part->selection().startPosition()));
                 break;
             case Selection::Empty:
                 TypingCommand::closeTyping(part->lastEditCommand());
@@ -2252,32 +2252,32 @@ Value SelectionFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
                 break;
             case Selection::SetBaseAndExtent:
                 TypingCommand::closeTyping(part->lastEditCommand());
-                part->setSelection(KHTMLSelection(KJS::toNode(args[0]).handle(), args[1].toInt32(exec), KJS::toNode(args[2]).handle(), args[3].toInt32(exec)));
+                part->setSelection(DOM::Selection(KJS::toNode(args[0]).handle(), args[1].toInt32(exec), KJS::toNode(args[2]).handle(), args[3].toInt32(exec)));
                 break;
             case Selection::SetPosition:
                 TypingCommand::closeTyping(part->lastEditCommand());
-                part->setSelection(KHTMLSelection(KJS::toNode(args[0]).handle(), args[1].toInt32(exec)));
+                part->setSelection(DOM::Selection(KJS::toNode(args[0]).handle(), args[1].toInt32(exec)));
                 break;
             case Selection::Modify: {
                 TypingCommand::closeTyping(part->lastEditCommand());
-                KHTMLSelection s(part->selection());
-                KHTMLSelection::EAlter alter = KHTMLSelection::MOVE;
+                DOM::Selection s(part->selection());
+                DOM::Selection::EAlter alter = DOM::Selection::MOVE;
                 if (args[0].toString(exec).string().lower() == "extend")
-                    alter = KHTMLSelection::EXTEND;
+                    alter = DOM::Selection::EXTEND;
                 DOMString directionString = args[1].toString(exec).string().lower();
-                KHTMLSelection::EDirection direction = KHTMLSelection::FORWARD;
+                DOM::Selection::EDirection direction = DOM::Selection::FORWARD;
                 if (directionString == "backward")
-                    direction = KHTMLSelection::BACKWARD;
+                    direction = DOM::Selection::BACKWARD;
                 else if (directionString == "left")
-                    direction = KHTMLSelection::LEFT;
+                    direction = DOM::Selection::LEFT;
                 if (directionString == "right")
-                    direction = KHTMLSelection::RIGHT;
-                KHTMLSelection::ETextGranularity granularity = KHTMLSelection::CHARACTER;
+                    direction = DOM::Selection::RIGHT;
+                DOM::Selection::ETextGranularity granularity = DOM::Selection::CHARACTER;
                 DOMString granularityString = args[2].toString(exec).string().lower();
                 if (granularityString == "word")
-                    granularity = KHTMLSelection::WORD;
+                    granularity = DOM::Selection::WORD;
                 else if (granularityString == "line")
-                    granularity = KHTMLSelection::LINE;
+                    granularity = DOM::Selection::LINE;
                 s.modify(alter, direction, granularity);
                 part->setSelection(s);
             }
diff --git a/WebCore/khtml/editing/SelectionController.cpp b/WebCore/khtml/editing/SelectionController.cpp
index 82dc803..e59b11f 100644
--- a/WebCore/khtml/editing/SelectionController.cpp
+++ b/WebCore/khtml/editing/SelectionController.cpp
@@ -23,7 +23,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
   
-#include "khtml_selection.h"
+#include "dom_selection.h"
 
 #include "htmltags.h"
 #include "khtml_part.h"
@@ -52,15 +52,8 @@
 #define EDIT_DEBUG 0
 #endif
 
-using DOM::DocumentImpl;
-using DOM::DOMPosition;
-using DOM::DOMString;
-using DOM::EditIterator;
-using DOM::ElementImpl;
-using DOM::Node;
-using DOM::NodeImpl;
-using DOM::Range;
-using DOM::TextImpl;
+namespace DOM {
+
 using khtml::InlineTextBox;
 using khtml::RenderObject;
 using khtml::RenderText;
@@ -68,16 +61,16 @@ using khtml::RenderText;
 #if APPLE_CHANGES
 static bool firstRunAt(RenderObject *renderNode, int y, NodeImpl *&startNode, long &startOffset);
 static bool lastRunAt(RenderObject *renderNode, int y, NodeImpl *&endNode, long &endOffset);
-static bool startAndEndLineNodesIncludingNode(DOM::NodeImpl *node, int offset, KHTMLSelection &selection);
+static bool startAndEndLineNodesIncludingNode(DOM::NodeImpl *node, int offset, Selection &selection);
 #endif
 
 
-KHTMLSelection::KHTMLSelection()
+Selection::Selection()
 {
     init();
 }
 
-KHTMLSelection::KHTMLSelection(NodeImpl *node, long offset)
+Selection::Selection(NodeImpl *node, long offset)
 {
     init();
 
@@ -89,7 +82,7 @@ KHTMLSelection::KHTMLSelection(NodeImpl *node, long offset)
     validate();
 }
 
-KHTMLSelection::KHTMLSelection(const DOMPosition &pos)
+Selection::Selection(const Position &pos)
 {
     init();
 
@@ -101,7 +94,7 @@ KHTMLSelection::KHTMLSelection(const DOMPosition &pos)
     validate();
 }
 
-KHTMLSelection::KHTMLSelection(const DOMPosition &base, const DOMPosition &extent)
+Selection::Selection(const Position &base, const Position &extent)
 {
     init();
 
@@ -113,7 +106,7 @@ KHTMLSelection::KHTMLSelection(const DOMPosition &base, const DOMPosition &exten
     validate();
 }
 
-KHTMLSelection::KHTMLSelection(NodeImpl *baseNode, long baseOffset, NodeImpl *endNode, long endOffset)
+Selection::Selection(NodeImpl *baseNode, long baseOffset, NodeImpl *endNode, long endOffset)
 {
     init();
 
@@ -125,7 +118,7 @@ KHTMLSelection::KHTMLSelection(NodeImpl *baseNode, long baseOffset, NodeImpl *en
     validate();
 }
 
-KHTMLSelection::KHTMLSelection(const KHTMLSelection &o)
+Selection::Selection(const Selection &o)
 {
     init();
     
@@ -157,7 +150,7 @@ KHTMLSelection::KHTMLSelection(const KHTMLSelection &o)
     }
 }
 
-void KHTMLSelection::init()
+void Selection::init()
 {
     m_baseNode = 0;
     m_baseOffset = 0;
@@ -176,7 +169,7 @@ void KHTMLSelection::init()
     m_modifyBiasSet = false;
 }
 
-KHTMLSelection::~KHTMLSelection()
+Selection::~Selection()
 {
     if (m_baseNode)
         m_baseNode->deref();
@@ -188,7 +181,7 @@ KHTMLSelection::~KHTMLSelection()
         m_endNode->deref();
 }
 
-KHTMLSelection &KHTMLSelection::operator=(const KHTMLSelection &o)
+Selection &Selection::operator=(const Selection &o)
 {
 	setBaseNode(o.baseNode());
 	setExtentNode(o.extentNode());
@@ -220,28 +213,28 @@ KHTMLSelection &KHTMLSelection::operator=(const KHTMLSelection &o)
     return *this;
 }
 
-void KHTMLSelection::moveTo(DOM::NodeImpl *node, long offset)
+void Selection::moveTo(DOM::NodeImpl *node, long offset)
 {
     moveTo(node, offset, node, offset);
 }
 
-void KHTMLSelection::moveTo(const DOM::Range &r)
+void Selection::moveTo(const DOM::Range &r)
 {
 	moveTo(r.startContainer().handle(), r.startOffset(), 
 		r.endContainer().handle(), r.endOffset());
 }
 
-void KHTMLSelection::moveTo(const DOM::DOMPosition &pos)
+void Selection::moveTo(const DOM::Position &pos)
 {
 	moveTo(pos.node(), pos.offset());
 }
 
-void KHTMLSelection::moveTo(const KHTMLSelection &o)
+void Selection::moveTo(const Selection &o)
 {
 	moveTo(o.baseNode(), o.baseOffset(), o.extentNode(), o.extentOffset());
 }
 
-void KHTMLSelection::moveTo(DOM::NodeImpl *baseNode, long baseOffset, DOM::NodeImpl *extentNode, long extentOffset)
+void Selection::moveTo(DOM::NodeImpl *baseNode, long baseOffset, DOM::NodeImpl *extentNode, long extentOffset)
 {
 	setBaseNode(baseNode);
 	setExtentNode(extentNode);
@@ -250,9 +243,9 @@ void KHTMLSelection::moveTo(DOM::NodeImpl *baseNode, long baseOffset, DOM::NodeI
 	validate();
 }
 
-bool KHTMLSelection::modify(EAlter alter, EDirection dir, ETextGranularity granularity)
+bool Selection::modify(EAlter alter, EDirection dir, ETextGranularity granularity)
 {
-    DOMPosition pos;
+    Position pos;
     
     switch (dir) {
         // EDIT FIXME: This needs to handle bidi
@@ -364,7 +357,7 @@ bool KHTMLSelection::modify(EAlter alter, EDirection dir, ETextGranularity granu
     return true;
 }
 
-bool KHTMLSelection::expandUsingGranularity(ETextGranularity granularity)
+bool Selection::expandUsingGranularity(ETextGranularity granularity)
 {
     if (state() == NONE)
         return false;
@@ -373,14 +366,14 @@ bool KHTMLSelection::expandUsingGranularity(ETextGranularity granularity)
     return true;
 }
 
-int KHTMLSelection::xPosForVerticalArrowNavigation(EPositionType type, bool recalc) const
+int Selection::xPosForVerticalArrowNavigation(EPositionType type, bool recalc) const
 {
     int x = 0;
 
     if (state() == NONE)
         return x;
 
-    DOMPosition pos;
+    Position pos;
     switch (type) {
         case START:
             pos = startPosition();
@@ -412,7 +405,7 @@ int KHTMLSelection::xPosForVerticalArrowNavigation(EPositionType type, bool reca
     return x;
 }
 
-void KHTMLSelection::clear()
+void Selection::clear()
 {
 	setBaseNode(0);
 	setExtentNode(0);
@@ -421,26 +414,26 @@ void KHTMLSelection::clear()
 	validate();
 }
 
-void KHTMLSelection::setBase(DOM::NodeImpl *node, long offset)
+void Selection::setBase(DOM::NodeImpl *node, long offset)
 {
 	setBaseNode(node);
 	setBaseOffset(offset);
 	validate();
 }
 
-void KHTMLSelection::setExtent(DOM::NodeImpl *node, long offset)
+void Selection::setExtent(DOM::NodeImpl *node, long offset)
 {
 	setExtentNode(node);
 	setExtentOffset(offset);
 	validate();
 }
 
-void KHTMLSelection::setNeedsLayout(bool flag)
+void Selection::setNeedsLayout(bool flag)
 {
     m_needsCaretLayout = flag;
 }
 
-Range KHTMLSelection::toRange() const
+Range Selection::toRange() const
 {
     if (isEmpty())
         return Range();
@@ -448,7 +441,7 @@ Range KHTMLSelection::toRange() const
     return Range(Node(startNode()), startOffset(), Node(endNode()), endOffset());
 }
 
-void KHTMLSelection::layoutCaret()
+void Selection::layoutCaret()
 {
     if (isEmpty() || !startNode()->renderer()) {
         m_caretX = m_caretY = m_caretSize = 0;
@@ -461,13 +454,13 @@ void KHTMLSelection::layoutCaret()
     m_needsCaretLayout = false;
 }
 
-QRect KHTMLSelection::getRepaintRect()
+QRect Selection::getRepaintRect()
 {
     // EDIT FIXME: fudge a bit to make sure we don't leave behind artifacts
     return QRect(m_caretX - 1, m_caretY - 1, 3, m_caretSize + 2);
 }
 
-void KHTMLSelection::needsCaretRepaint()
+void Selection::needsCaretRepaint()
 {
     if (isEmpty())
         return;
@@ -500,7 +493,7 @@ void KHTMLSelection::needsCaretRepaint()
     v->updateContents(getRepaintRect(), false);
 }
 
-void KHTMLSelection::paintCaret(QPainter *p, const QRect &rect)
+void Selection::paintCaret(QPainter *p, const QRect &rect)
 {
     if (isEmpty())
         return;
@@ -509,7 +502,7 @@ void KHTMLSelection::paintCaret(QPainter *p, const QRect &rect)
         return;
 
     if (m_needsCaretLayout) {
-        DOMPosition pos = DOMPosition(startNode(), startOffset());
+        Position pos = Position(startNode(), startOffset());
         if (!pos.inRenderedContent()) {
             moveToRenderedContent();
         }
@@ -527,7 +520,7 @@ void KHTMLSelection::paintCaret(QPainter *p, const QRect &rect)
     }
 }
 
-void KHTMLSelection::setBaseNode(DOM::NodeImpl *node)
+void Selection::setBaseNode(DOM::NodeImpl *node)
 {
 	if (m_baseNode == node)
 		return;
@@ -541,12 +534,12 @@ void KHTMLSelection::setBaseNode(DOM::NodeImpl *node)
 		m_baseNode->ref();
 }
 
-void KHTMLSelection::setBaseOffset(long offset)
+void Selection::setBaseOffset(long offset)
 {
 	m_baseOffset = offset;
 }
 
-void KHTMLSelection::setExtentNode(DOM::NodeImpl *node)
+void Selection::setExtentNode(DOM::NodeImpl *node)
 {
 	if (m_extentNode == node)
 		return;
@@ -560,12 +553,12 @@ void KHTMLSelection::setExtentNode(DOM::NodeImpl *node)
 		m_extentNode->ref();
 }
 	
-void KHTMLSelection::setExtentOffset(long offset)
+void Selection::setExtentOffset(long offset)
 {
 	m_extentOffset = offset;
 }
 
-void KHTMLSelection::setStartNode(DOM::NodeImpl *node)
+void Selection::setStartNode(DOM::NodeImpl *node)
 {
 	if (m_startNode == node)
 		return;
@@ -579,12 +572,12 @@ void KHTMLSelection::setStartNode(DOM::NodeImpl *node)
 		m_startNode->ref();
 }
 
-void KHTMLSelection::setStartOffset(long offset)
+void Selection::setStartOffset(long offset)
 {
 	m_startOffset = offset;
 }
 
-void KHTMLSelection::setEndNode(DOM::NodeImpl *node)
+void Selection::setEndNode(DOM::NodeImpl *node)
 {
 	if (m_endNode == node)
 		return;
@@ -598,17 +591,17 @@ void KHTMLSelection::setEndNode(DOM::NodeImpl *node)
 		m_endNode->ref();
 }
 	
-void KHTMLSelection::setEndOffset(long offset)
+void Selection::setEndOffset(long offset)
 {
 	m_endOffset = offset;
 }
 
-void KHTMLSelection::validate(ETextGranularity granularity)
+void Selection::validate(ETextGranularity granularity)
 {
     // move the base and extent nodes to their equivalent leaf positions
     bool baseAndExtentEqual = m_baseNode == m_extentNode && m_baseOffset == m_extentOffset;
     if (m_baseNode) {
-        DOMPosition pos = basePosition().equivalentLeafPosition();
+        Position pos = basePosition().equivalentLeafPosition();
         m_baseNode = pos.node();
         m_baseOffset = pos.offset();
         if (baseAndExtentEqual) {
@@ -617,7 +610,7 @@ void KHTMLSelection::validate(ETextGranularity granularity)
         }
     }
     if (m_extentNode && !baseAndExtentEqual) {
-        DOMPosition pos = extentPosition().equivalentLeafPosition();
+        Position pos = extentPosition().equivalentLeafPosition();
         m_extentNode = pos.node();
         m_extentOffset = pos.offset();
     }
@@ -712,8 +705,8 @@ void KHTMLSelection::validate(ETextGranularity granularity)
         }
     }
     else {  // granularity == LINE
-        KHTMLSelection baseSelection = *this;
-        KHTMLSelection extentSelection = *this;
+        Selection baseSelection = *this;
+        Selection extentSelection = *this;
         if (m_baseNode && (m_baseNode->nodeType() == Node::TEXT_NODE || m_baseNode->nodeType() == Node::CDATA_SECTION_NODE)) {
             if (startAndEndLineNodesIncludingNode(m_baseNode, m_baseOffset, baseSelection)) {
                 setStartNode(baseSelection.baseNode());
@@ -760,7 +753,7 @@ void KHTMLSelection::validate(ETextGranularity granularity)
 #endif
 }
 
-bool KHTMLSelection::moveToRenderedContent()
+bool Selection::moveToRenderedContent()
 {
     if (isEmpty())
         return false;
@@ -768,19 +761,19 @@ bool KHTMLSelection::moveToRenderedContent()
     if (m_state != CARET)
         return false;
 
-    DOMPosition pos = DOMPosition(startNode(), startOffset());
+    Position pos = Position(startNode(), startOffset());
     if (pos.inRenderedContent())
         return true;
         
     // not currently rendered, try moving to prev
-    DOMPosition prev = pos.previousCharacterPosition();
+    Position prev = pos.previousCharacterPosition();
     if (prev != pos && prev.node()->inSameContainingEditableBlock(pos.node())) {
         moveTo(prev);
         return true;
     }
 
     // could not be moved to prev, try next
-    DOMPosition next = pos.nextCharacterPosition();
+    Position next = pos.nextCharacterPosition();
     if (next != pos && next.node()->inSameContainingEditableBlock(pos.node())) {
         moveTo(next);
         return true;
@@ -789,27 +782,27 @@ bool KHTMLSelection::moveToRenderedContent()
     return false;
 }
 
-DOMPosition KHTMLSelection::basePosition() const
+Position Selection::basePosition() const
 {
-    return DOMPosition(baseNode(), baseOffset());
+    return Position(baseNode(), baseOffset());
 }
 
-DOMPosition KHTMLSelection::extentPosition() const
+Position Selection::extentPosition() const
 {
-    return DOMPosition(extentNode(), extentOffset());
+    return Position(extentNode(), extentOffset());
 }
 
-DOMPosition KHTMLSelection::startPosition() const
+Position Selection::startPosition() const
 {
-    return DOMPosition(startNode(), startOffset());
+    return Position(startNode(), startOffset());
 }
 
-DOMPosition KHTMLSelection::endPosition() const
+Position Selection::endPosition() const
 {
-    return DOMPosition(endNode(), endOffset());
+    return Position(endNode(), endOffset());
 }
 
-bool KHTMLSelection::nodeIsBeforeNode(NodeImpl *n1, NodeImpl *n2) 
+bool Selection::nodeIsBeforeNode(NodeImpl *n1, NodeImpl *n2) 
 {
 	if (!n1 || !n2) 
 		return true;
@@ -921,7 +914,7 @@ static bool lastRunAt(RenderObject *renderNode, int y, NodeImpl *&endNode, long
     }
 }
 
-static bool startAndEndLineNodesIncludingNode(DOM::NodeImpl *node, int offset, KHTMLSelection &selection)
+static bool startAndEndLineNodesIncludingNode(DOM::NodeImpl *node, int offset, Selection &selection)
 {
     if (node && (node->nodeType() == Node::TEXT_NODE || node->nodeType() == Node::CDATA_SECTION_NODE)) {
         int pos;
@@ -964,7 +957,7 @@ static bool startAndEndLineNodesIncludingNode(DOM::NodeImpl *node, int offset, K
     return false;
 }
 
-void KHTMLSelection::debugRenderer(RenderObject *r, bool selected) const
+void Selection::debugRenderer(RenderObject *r, bool selected) const
 {
     if (r->node()->isElementNode()) {
         ElementImpl *element = static_cast<ElementImpl *>(r->node());
@@ -1037,7 +1030,7 @@ void KHTMLSelection::debugRenderer(RenderObject *r, bool selected) const
     }
 }
 
-void KHTMLSelection::debugPosition() const
+void Selection::debugPosition() const
 {
     if (!startNode())
         return;
@@ -1046,20 +1039,20 @@ void KHTMLSelection::debugPosition() const
     
     //RenderObject *r = 0;
 
-    fprintf(stderr, "KHTMLSelection =================\n");
+    fprintf(stderr, "Selection =================\n");
 
     if (startPosition() == endPosition()) {
-        DOMPosition pos = startPosition();
-        DOMPosition upstream = pos.equivalentUpstreamPosition();
-        DOMPosition downstream = pos.equivalentDownstreamPosition();
+        Position pos = startPosition();
+        Position upstream = pos.equivalentUpstreamPosition();
+        Position downstream = pos.equivalentDownstreamPosition();
         fprintf(stderr, "upstream:   %s %p:%d\n", getTagName(upstream.node()->id()).string().latin1(), upstream.node(), upstream.offset());
         fprintf(stderr, "pos:        %s %p:%d\n", getTagName(pos.node()->id()).string().latin1(), pos.node(), pos.offset());
         fprintf(stderr, "downstream: %s %p:%d\n", getTagName(downstream.node()->id()).string().latin1(), downstream.node(), downstream.offset());
     }
     else {
-        DOMPosition pos = startPosition();
-        DOMPosition upstream = pos.equivalentUpstreamPosition();
-        DOMPosition downstream = pos.equivalentDownstreamPosition();
+        Position pos = startPosition();
+        Position upstream = pos.equivalentUpstreamPosition();
+        Position downstream = pos.equivalentDownstreamPosition();
         fprintf(stderr, "upstream:   %s %p:%d\n", getTagName(upstream.node()->id()).string().latin1(), upstream.node(), upstream.offset());
         fprintf(stderr, "start:      %s %p:%d\n", getTagName(pos.node()->id()).string().latin1(), pos.node(), pos.offset());
         fprintf(stderr, "downstream: %s %p:%d\n", getTagName(downstream.node()->id()).string().latin1(), downstream.node(), downstream.offset());
@@ -1113,3 +1106,5 @@ void KHTMLSelection::debugPosition() const
 }
 
 #endif
+
+} // namespace DOM
diff --git a/WebCore/khtml/editing/SelectionController.h b/WebCore/khtml/editing/SelectionController.h
index 326a0ea..01fcb1b 100644
--- a/WebCore/khtml/editing/SelectionController.h
+++ b/WebCore/khtml/editing/SelectionController.h
@@ -23,33 +23,33 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-#ifndef __khtml_selection_h__
-#define __khtml_selection_h__
+#ifndef __dom_selection_h__
+#define __dom_selection_h__
 
 class KHTMLPart;
 class QPainter;
 class QRect;
 
-namespace DOM {
-    class DOMPosition;
-    class NodeImpl;
-    class Range;
-};
-
 namespace khtml {
     class RenderObject;
 }
 
-class KHTMLSelection
+namespace DOM {
+
+class NodeImpl;
+class Position;
+class Range;
+
+class Selection
 {
 public:
-    KHTMLSelection();
-    KHTMLSelection(DOM::NodeImpl *node, long offset);
-    KHTMLSelection(const DOM::DOMPosition &);
-    KHTMLSelection(const DOM::DOMPosition &, const DOM::DOMPosition &);
-    KHTMLSelection(DOM::NodeImpl *startNode, long startOffset, DOM::NodeImpl *endNode, long endOffset);
-    KHTMLSelection(const KHTMLSelection &);
-    ~KHTMLSelection();
+    Selection();
+    Selection(NodeImpl *node, long offset);
+    Selection(const Position &);
+    Selection(const Position &, const Position &);
+    Selection(NodeImpl *startNode, long startOffset, NodeImpl *endNode, long endOffset);
+    Selection(const Selection &);
+    ~Selection();
 
 	enum EState { NONE, CARET, RANGE };
 	enum EAlter { MOVE, EXTEND };
@@ -58,52 +58,52 @@ public:
 
 	EState state() const { return m_state; }
 
-    void moveTo(DOM::NodeImpl *node, long offset);
-    void moveTo(const DOM::Range &);
-    void moveTo(const DOM::DOMPosition &);
-    void moveTo(const KHTMLSelection &);
-    void moveTo(DOM::NodeImpl *baseNode, long baseOffset, DOM::NodeImpl *extentNode, long extentOffset);
+    void moveTo(NodeImpl *node, long offset);
+    void moveTo(const Range &);
+    void moveTo(const Position &);
+    void moveTo(const Selection &);
+    void moveTo(NodeImpl *baseNode, long baseOffset, NodeImpl *extentNode, long extentOffset);
     bool modify(EAlter, EDirection, ETextGranularity);
     bool expandUsingGranularity(ETextGranularity);
     void clear();
 
     bool moveToRenderedContent();
     
-    void setBase(DOM::NodeImpl *node, long offset);
-    void setExtent(DOM::NodeImpl *node, long offset);
+    void setBase(NodeImpl *node, long offset);
+    void setExtent(NodeImpl *node, long offset);
 
-    DOM::NodeImpl *baseNode() const { return m_baseNode; }
+    NodeImpl *baseNode() const { return m_baseNode; }
     long baseOffset() const { return m_baseOffset; }
 
-    DOM::NodeImpl *extentNode() const { return m_extentNode; }
+    NodeImpl *extentNode() const { return m_extentNode; }
     long extentOffset() const { return m_extentOffset; }
 
-    DOM::NodeImpl *startNode() const { return m_startNode; }
+    NodeImpl *startNode() const { return m_startNode; }
     long startOffset() const { return m_startOffset; }
 
-    DOM::NodeImpl *endNode() const { return m_endNode; }
+    NodeImpl *endNode() const { return m_endNode; }
     long endOffset() const { return m_endOffset; }
 
-    DOM::DOMPosition basePosition() const;
-    DOM::DOMPosition extentPosition() const;
-    DOM::DOMPosition startPosition() const;
-    DOM::DOMPosition endPosition() const;
+    Position basePosition() const;
+    Position extentPosition() const;
+    Position startPosition() const;
+    Position endPosition() const;
 
     void setNeedsLayout(bool flag=true);
     void clearModifyBias() { m_modifyBiasSet = false; }
     
     bool isEmpty() const { return state() == NONE; }
     bool notEmpty() const { return !isEmpty(); }
-    DOM::Range toRange() const;
+    Range toRange() const;
 
     
     void debugPosition() const;
     void debugRenderer(khtml::RenderObject *r, bool selected) const;
 
-    KHTMLSelection &operator=(const KHTMLSelection &o);
+    Selection &operator=(const Selection &o);
     
-    friend bool operator==(const KHTMLSelection &a, const KHTMLSelection &b);
-    friend bool operator!=(const KHTMLSelection &a, const KHTMLSelection &b);
+    friend bool operator==(const Selection &a, const Selection &b);
+    friend bool operator!=(const Selection &a, const Selection &b);
     
     friend class KHTMLPart;
 
@@ -118,29 +118,29 @@ private:
     QRect getRepaintRect();
     void paintCaret(QPainter *p, const QRect &rect);
 
-	void setBaseNode(DOM::NodeImpl *);
+	void setBaseNode(NodeImpl *);
 	void setBaseOffset(long);
-	void setExtentNode(DOM::NodeImpl *);
+	void setExtentNode(NodeImpl *);
 	void setExtentOffset(long);
 
-	void setStartNode(DOM::NodeImpl *);
+	void setStartNode(NodeImpl *);
 	void setStartOffset(long);
-	void setEndNode(DOM::NodeImpl *);
+	void setEndNode(NodeImpl *);
 	void setEndOffset(long);
 
-    bool nodeIsBeforeNode(DOM::NodeImpl *n1, DOM::NodeImpl *n2);
+    bool nodeIsBeforeNode(NodeImpl *n1, NodeImpl *n2);
 
     void calculateStartAndEnd(ETextGranularity select=CHARACTER);
     int xPosForVerticalArrowNavigation(EPositionType, bool recalc=false) const;
     
-    DOM::NodeImpl *m_baseNode;    // base node for the selection
+    NodeImpl *m_baseNode;    // base node for the selection
     long m_baseOffset;            // offset into base node where selection is
-    DOM::NodeImpl *m_extentNode;  // extent node for the selection
+    NodeImpl *m_extentNode;  // extent node for the selection
     long m_extentOffset;          // offset into extent node where selection is
 
-    DOM::NodeImpl *m_startNode;   // start node for the selection (read-only)
+    NodeImpl *m_startNode;   // start node for the selection (read-only)
     long m_startOffset;           // offset into start node where selection is (read-only)
-    DOM::NodeImpl *m_endNode;     // end node for the selection (read-only)
+    NodeImpl *m_endNode;     // end node for the selection (read-only)
     long m_endOffset;             // offset into end node where selection is (read-only)
 
 	EState m_state;               // the state of the selection
@@ -155,15 +155,17 @@ private:
 };
 
 
-inline bool operator==(const KHTMLSelection &a, const KHTMLSelection &b)
+inline bool operator==(const Selection &a, const Selection &b)
 {
     return a.startNode() == b.startNode() && a.startOffset() == b.startOffset() &&
         a.endNode() == b.endNode() && a.endOffset() == b.endOffset();
 }
 
-inline bool operator!=(const KHTMLSelection &a, const KHTMLSelection &b)
+inline bool operator!=(const Selection &a, const Selection &b)
 {
     return !(a == b);
 }
 
-#endif
\ No newline at end of file
+} // namespace DOM
+
+#endif  // __dom_selection_h__
\ No newline at end of file
diff --git a/WebCore/khtml/editing/htmlediting.cpp b/WebCore/khtml/editing/htmlediting.cpp
index d3156a3..77d1051 100644
--- a/WebCore/khtml/editing/htmlediting.cpp
+++ b/WebCore/khtml/editing/htmlediting.cpp
@@ -27,10 +27,10 @@
 #include "htmlediting_impl.h"
 
 #include "khtml_part.h"
-#include "khtml_selection.h"
 #include "dom/dom_position.h"
 #include "xml/dom_docimpl.h"
 #include "xml/dom_nodeimpl.h"
+#include "xml/dom_selection.h"
 #include "xml/dom_textimpl.h"
 
 #if APPLE_CHANGES
@@ -39,9 +39,10 @@
 #endif
 
 using DOM::DocumentImpl;
-using DOM::DOMPosition;
+using DOM::Position;
 using DOM::DOMString;
 using DOM::NodeImpl;
+using DOM::Selection;
 using DOM::TextImpl;
 
 using khtml::AppendNodeCommand;
@@ -158,25 +159,25 @@ DocumentImpl * const EditCommand::document() const
     return get()->document();
 }
 
-KHTMLSelection EditCommand::startingSelection() const
+Selection EditCommand::startingSelection() const
 {
-    IF_IMPL_NULL_RETURN_ARG(KHTMLSelection());
+    IF_IMPL_NULL_RETURN_ARG(Selection());
     return get()->startingSelection();
 }
 
-KHTMLSelection EditCommand::endingSelection() const
+Selection EditCommand::endingSelection() const
 {
-    IF_IMPL_NULL_RETURN_ARG(KHTMLSelection());
+    IF_IMPL_NULL_RETURN_ARG(Selection());
     return get()->endingSelection();
 }
 
-void EditCommand::setStartingSelection(const KHTMLSelection &s)
+void EditCommand::setStartingSelection(const Selection &s)
 {
     IF_IMPL_NULL_RETURN;
     get()->setStartingSelection(s);
 }
 
-void EditCommand::setEndingSelection(const KHTMLSelection &s)
+void EditCommand::setEndingSelection(const Selection &s)
 {
     IF_IMPL_NULL_RETURN;
     get()->setEndingSelection(s);
@@ -281,7 +282,7 @@ DeleteCollapsibleWhitespaceCommand::DeleteCollapsibleWhitespaceCommand(DocumentI
 {
 }
 
-DeleteCollapsibleWhitespaceCommand::DeleteCollapsibleWhitespaceCommand(DocumentImpl *document, const KHTMLSelection &selection)
+DeleteCollapsibleWhitespaceCommand::DeleteCollapsibleWhitespaceCommand(DocumentImpl *document, const Selection &selection)
     : CompositeEditCommand(new DeleteCollapsibleWhitespaceCommandImpl(document, selection))
 {
 }
@@ -303,7 +304,7 @@ DeleteSelectionCommand::DeleteSelectionCommand(DocumentImpl *document)
 {
 }
 
-DeleteSelectionCommand::DeleteSelectionCommand(DocumentImpl *document, const KHTMLSelection &selection)
+DeleteSelectionCommand::DeleteSelectionCommand(DocumentImpl *document, const Selection &selection)
     : CompositeEditCommand(new DeleteSelectionCommandImpl(document, selection))
 {
 }
diff --git a/WebCore/khtml/editing/htmlediting.h b/WebCore/khtml/editing/htmlediting.h
index cf158d1..25ad852 100644
--- a/WebCore/khtml/editing/htmlediting.h
+++ b/WebCore/khtml/editing/htmlediting.h
@@ -27,17 +27,16 @@
 #define __htmlediting_h__
 
 #include "dom_position.h"
+#include "dom_selection.h"
 #include "dom_string.h"
-#include "khtml_selection.h"
 #include "shared.h"
 
-class KHTMLSelection;
-
 namespace DOM {
     class DocumentImpl;
-    class DOMPosition;
     class DOMString;
     class NodeImpl;
+    class Position;
+    class Selection;
     class TextImpl;
 };
 
@@ -101,11 +100,11 @@ public:
 
     virtual DOM::DocumentImpl * const document() const = 0;
 
-    virtual KHTMLSelection startingSelection() const = 0;
-    virtual KHTMLSelection endingSelection() const = 0;
+    virtual DOM::Selection startingSelection() const = 0;
+    virtual DOM::Selection endingSelection() const = 0;
 
-    virtual void setStartingSelection(const KHTMLSelection &s) = 0;
-    virtual void setEndingSelection(const KHTMLSelection &s) = 0;
+    virtual void setStartingSelection(const DOM::Selection &s) = 0;
+    virtual void setEndingSelection(const DOM::Selection &s) = 0;
 
     virtual void moveToStartingSelection() = 0;
     virtual void moveToEndingSelection() = 0;
@@ -136,11 +135,11 @@ public:
 
     DOM::DocumentImpl * const document() const;
 
-    KHTMLSelection startingSelection() const;
-    KHTMLSelection endingSelection() const;
+    DOM::Selection startingSelection() const;
+    DOM::Selection endingSelection() const;
 
-    void setStartingSelection(const KHTMLSelection &s);
-    void setEndingSelection(const KHTMLSelection &s);
+    void setStartingSelection(const DOM::Selection &s);
+    void setEndingSelection(const DOM::Selection &s);
 
     void moveToStartingSelection();
     void moveToEndingSelection();
@@ -193,7 +192,7 @@ class DeleteCollapsibleWhitespaceCommand : public CompositeEditCommand
 {
 public:
 	DeleteCollapsibleWhitespaceCommand(DOM::DocumentImpl *document);
-	DeleteCollapsibleWhitespaceCommand(DOM::DocumentImpl *document, const KHTMLSelection &selection);
+	DeleteCollapsibleWhitespaceCommand(DOM::DocumentImpl *document, const DOM::Selection &selection);
     
 	virtual ~DeleteCollapsibleWhitespaceCommand();
 
@@ -208,7 +207,7 @@ class DeleteSelectionCommand : public CompositeEditCommand
 {
 public:
 	DeleteSelectionCommand(DOM::DocumentImpl *document);
-	DeleteSelectionCommand(DOM::DocumentImpl *document, const KHTMLSelection &selection);
+	DeleteSelectionCommand(DOM::DocumentImpl *document, const DOM::Selection &selection);
 	virtual ~DeleteSelectionCommand();
 
 private:
diff --git a/WebCore/khtml/editing/htmlediting_impl.cpp b/WebCore/khtml/editing/htmlediting_impl.cpp
index 1dfc336..9aea952 100644
--- a/WebCore/khtml/editing/htmlediting_impl.cpp
+++ b/WebCore/khtml/editing/htmlediting_impl.cpp
@@ -31,7 +31,6 @@
 #include "htmlattrs.h"
 #include "htmltags.h"
 #include "khtml_part.h"
-#include "khtml_selection.h"
 #include "khtmlview.h"
 #include "rendering/render_object.h"
 #include "rendering/render_style.h"
@@ -40,6 +39,7 @@
 #include "xml/dom_elementimpl.h"
 #include "xml/dom_edititerator.h"
 #include "xml/dom_nodeimpl.h"
+#include "xml/dom_selection.h"
 #include "xml/dom_stringimpl.h"
 #include "xml/dom_textimpl.h"
 #include "xml/dom2_rangeimpl.h"
@@ -51,7 +51,6 @@
 
 using DOM::DocumentFragmentImpl;
 using DOM::DocumentImpl;
-using DOM::DOMPosition;
 using DOM::DOMString;
 using DOM::DOMStringImpl;
 using DOM::EditingTextImpl;
@@ -62,8 +61,10 @@ using DOM::HTMLImageElementImpl;
 using DOM::Node;
 using DOM::NodeImpl;
 using DOM::NodeListImpl;
+using DOM::Position;
 using DOM::Range;
 using DOM::RangeImpl;
+using DOM::Selection;
 using DOM::TextImpl;
 
 using khtml::AppendNodeCommand;
@@ -132,7 +133,7 @@ static inline bool isWS(const DOMString &text)
     return isWS(text[0]);
 }
 
-static inline bool isWS(const DOMPosition &pos)
+static inline bool isWS(const Position &pos)
 {
     if (!pos.node())
         return false;
@@ -178,29 +179,29 @@ static bool shouldPruneNode(NodeImpl *node)
     return true;
 }
 
-static DOMPosition leadingWhitespacePosition(const DOMPosition &pos)
+static Position leadingWhitespacePosition(const Position &pos)
 {
     ASSERT(pos.notEmpty());
 
-    KHTMLSelection selection(pos);
-    DOMPosition prev = pos.previousCharacterPosition();
+    Selection selection(pos);
+    Position prev = pos.previousCharacterPosition();
     if (prev != pos && prev.node()->inSameContainingEditableBlock(pos.node()) && prev.node()->isTextNode()) {
         DOMString string = static_cast<TextImpl *>(prev.node())->data();
         if (isWS(string[prev.offset()]))
             return prev;
     }
 
-    return DOMPosition();
+    return Position();
 }
 
-static DOMPosition trailingWhitespacePosition(const DOMPosition &pos)
+static Position trailingWhitespacePosition(const Position &pos)
 {
     ASSERT(pos.notEmpty());
 
     if (pos.node()->isTextNode()) {
         TextImpl *textNode = static_cast<TextImpl *>(pos.node());
         if (pos.offset() >= (long)textNode->length()) {
-            DOMPosition next = pos.nextCharacterPosition();
+            Position next = pos.nextCharacterPosition();
             if (next != pos && next.node()->inSameContainingEditableBlock(pos.node()) && next.node()->isTextNode()) {
                 DOMString string = static_cast<TextImpl *>(next.node())->data();
                 if (isWS(string[0]))
@@ -214,7 +215,7 @@ static DOMPosition trailingWhitespacePosition(const DOMPosition &pos)
         }
     }
 
-    return DOMPosition();
+    return Position();
 }
 
 static bool textNodesAreJoinable(TextImpl *text1, TextImpl *text2)
@@ -231,7 +232,7 @@ static DOMString &nonBreakingSpaceString()
     return nonBreakingSpaceString;
 }
 
-static void debugPosition(const char *prefix, const DOMPosition &pos)
+static void debugPosition(const char *prefix, const Position &pos)
 {
     LOG(Editing, "%s%s %p : %d", prefix, getTagName(pos.node()->id()).string().latin1(), pos.node(), pos.offset());
 }
@@ -313,7 +314,7 @@ void EditCommandImpl::doReapply()
     doApply();
 }
 
-void EditCommandImpl::setStartingSelection(const KHTMLSelection &s)
+void EditCommandImpl::setStartingSelection(const Selection &s)
 {
     m_startingSelection = s;
     EditCommand cmd = parent();
@@ -324,7 +325,7 @@ void EditCommandImpl::setStartingSelection(const KHTMLSelection &s)
     moveToStartingSelection();
 }
 
-void EditCommandImpl::setEndingSelection(const KHTMLSelection &s)
+void EditCommandImpl::setEndingSelection(const Selection &s)
 {
     m_endingSelection = s;
     EditCommand cmd = parent();
@@ -513,15 +514,15 @@ void CompositeEditCommandImpl::replaceText(DOM::TextImpl *node, long offset, lon
 
 void CompositeEditCommandImpl::deleteSelection()
 {
-    if (endingSelection().state() == KHTMLSelection::RANGE) {
+    if (endingSelection().state() == Selection::RANGE) {
         DeleteSelectionCommand cmd(document());
         applyCommandToComposite(cmd);
     }
 }
 
-void CompositeEditCommandImpl::deleteSelection(const KHTMLSelection &selection)
+void CompositeEditCommandImpl::deleteSelection(const Selection &selection)
 {
-    if (selection.state() == KHTMLSelection::RANGE) {
+    if (selection.state() == Selection::RANGE) {
         DeleteSelectionCommand cmd(document(), selection);
         applyCommandToComposite(cmd);
     }
@@ -533,7 +534,7 @@ void CompositeEditCommandImpl::deleteCollapsibleWhitespace()
     applyCommandToComposite(cmd);
 }
 
-void CompositeEditCommandImpl::deleteCollapsibleWhitespace(const KHTMLSelection &selection)
+void CompositeEditCommandImpl::deleteCollapsibleWhitespace(const Selection &selection)
 {
     DeleteCollapsibleWhitespaceCommand cmd(document(), selection);
     applyCommandToComposite(cmd);
@@ -596,7 +597,7 @@ DeleteCollapsibleWhitespaceCommandImpl::DeleteCollapsibleWhitespaceCommandImpl(D
 {
 }
 
-DeleteCollapsibleWhitespaceCommandImpl::DeleteCollapsibleWhitespaceCommandImpl(DocumentImpl *document, const KHTMLSelection &selection)
+DeleteCollapsibleWhitespaceCommandImpl::DeleteCollapsibleWhitespaceCommandImpl(DocumentImpl *document, const Selection &selection)
     : CompositeEditCommandImpl(document), m_selectionToCollapse(selection), m_charactersDeleted(0)
 {
 }
@@ -610,7 +611,7 @@ int DeleteCollapsibleWhitespaceCommandImpl::commandID() const
     return DeleteCollapsibleWhitespaceCommandID;
 }
 
-static bool shouldDeleteUpstreamPosition(const DOMPosition &pos)
+static bool shouldDeleteUpstreamPosition(const Position &pos)
 {
     if (!pos.node()->isTextNode())
         return false;
@@ -642,10 +643,10 @@ static bool shouldDeleteUpstreamPosition(const DOMPosition &pos)
     return true;
 }
 
-DOMPosition DeleteCollapsibleWhitespaceCommandImpl::deleteWhitespace(const DOMPosition &pos)
+Position DeleteCollapsibleWhitespaceCommandImpl::deleteWhitespace(const Position &pos)
 {
-    DOMPosition upstream = pos.equivalentUpstreamPosition();
-    DOMPosition downstream = pos.equivalentDownstreamPosition();
+    Position upstream = pos.equivalentUpstreamPosition();
+    Position downstream = pos.equivalentDownstreamPosition();
     
     bool del = shouldDeleteUpstreamPosition(upstream);
 
@@ -669,18 +670,18 @@ DOMPosition DeleteCollapsibleWhitespaceCommandImpl::deleteWhitespace(const DOMPo
         return upstream;
         
     EditIterator it(upstream);
-    DOMPosition deleteStart = upstream;
+    Position deleteStart = upstream;
     if (!del) {
         deleteStart = it.peekNext();
         if (deleteStart == downstream)
             return upstream;
     }
     
-    DOMPosition endingPosition = upstream;
+    Position endingPosition = upstream;
     
     while (it.current() != downstream) {
 
-        DOMPosition next = it.peekNext();
+        Position next = it.peekNext();
         if (next.node() != deleteStart.node()) {
             ASSERT(deleteStart.node()->isTextNode());
             TextImpl *textNode = static_cast<TextImpl *>(deleteStart.node());
@@ -688,7 +689,7 @@ DOMPosition DeleteCollapsibleWhitespaceCommandImpl::deleteWhitespace(const DOMPo
             if (count == textNode->length()) {
                 LOG(Editing, "   removeNodeAndPrune 1: [%p]\n", textNode);
                 if (textNode == endingPosition.node())
-                    endingPosition = DOMPosition(next.node(), next.node()->caretMinOffset());
+                    endingPosition = Position(next.node(), next.node()->caretMinOffset());
                 removeNodeAndPrune(textNode);
             }
             else {
@@ -711,7 +712,7 @@ DOMPosition DeleteCollapsibleWhitespaceCommandImpl::deleteWhitespace(const DOMPo
                 LOG(Editing, "   deleteText 2: [%p:%d:%d:%d]\n", textNode, textNode->length(), deleteStart.offset(), count);
                 deleteText(textNode, deleteStart.offset(), count);
                 m_charactersDeleted = count;
-                endingPosition = DOMPosition(downstream.node(), downstream.offset() - m_charactersDeleted);
+                endingPosition = Position(downstream.node(), downstream.offset() - m_charactersDeleted);
             }
         }
         
@@ -724,21 +725,21 @@ DOMPosition DeleteCollapsibleWhitespaceCommandImpl::deleteWhitespace(const DOMPo
 void DeleteCollapsibleWhitespaceCommandImpl::doApply()
 {
     int state = m_selectionToCollapse.state();
-    if (state == KHTMLSelection::CARET) {
-        DOMPosition endPosition = deleteWhitespace(m_selectionToCollapse.startPosition());
+    if (state == Selection::CARET) {
+        Position endPosition = deleteWhitespace(m_selectionToCollapse.startPosition());
         setEndingSelection(endPosition);
         LOG(Editing, "-----------------------------------------------------\n");
     }
-    else if (state == KHTMLSelection::RANGE) {
-        DOMPosition startPosition = deleteWhitespace(m_selectionToCollapse.startPosition());
+    else if (state == Selection::RANGE) {
+        Position startPosition = deleteWhitespace(m_selectionToCollapse.startPosition());
         LOG(Editing, "-----------------------------------------------------\n");
-        DOMPosition endPosition = m_selectionToCollapse.endPosition();
+        Position endPosition = m_selectionToCollapse.endPosition();
         if (m_charactersDeleted > 0 && startPosition.node() == endPosition.node()) {
             LOG(Editing, "adjust end position by %d\n", m_charactersDeleted);
-            endPosition = DOMPosition(endPosition.node(), endPosition.offset() - m_charactersDeleted);
+            endPosition = Position(endPosition.node(), endPosition.offset() - m_charactersDeleted);
         }
         endPosition = deleteWhitespace(endPosition);
-        setEndingSelection(KHTMLSelection(startPosition, endPosition));
+        setEndingSelection(Selection(startPosition, endPosition));
         LOG(Editing, "=====================================================\n");
     }
 }
@@ -752,7 +753,7 @@ DeleteSelectionCommandImpl::DeleteSelectionCommandImpl(DOM::DocumentImpl *docume
     m_selectionToDelete = endingSelection();
 }
 
-DeleteSelectionCommandImpl::DeleteSelectionCommandImpl(DOM::DocumentImpl *document, const KHTMLSelection &selection)
+DeleteSelectionCommandImpl::DeleteSelectionCommandImpl(DOM::DocumentImpl *document, const Selection &selection)
     : CompositeEditCommandImpl(document)
 {
     m_selectionToDelete = selection;
@@ -769,12 +770,12 @@ int DeleteSelectionCommandImpl::commandID() const
 
 void DeleteSelectionCommandImpl::joinTextNodesWithSameStyle()
 {
-    KHTMLSelection selection = endingSelection();
+    Selection selection = endingSelection();
 
-    if (selection.state() != KHTMLSelection::CARET)
+    if (selection.state() != Selection::CARET)
         return;
 
-    DOMPosition pos = selection.startPosition();
+    Position pos = selection.startPosition();
     
     if (!pos.node()->isTextNode())
         return;
@@ -783,35 +784,35 @@ void DeleteSelectionCommandImpl::joinTextNodesWithSameStyle()
     
     if (pos.offset() == 0) {
         EditIterator it(pos);
-        DOMPosition prev = it.previous();
+        Position prev = it.previous();
         if (prev == pos)
             return;
         if (prev.node()->isTextNode()) {
             TextImpl *prevTextNode = static_cast<TextImpl *>(prev.node());
             if (textNodesAreJoinable(prevTextNode, textNode)) {
                 joinTextNodes(prevTextNode, textNode);
-                setEndingSelection(DOMPosition(textNode, prevTextNode->length()));
+                setEndingSelection(Position(textNode, prevTextNode->length()));
                 LOG(Editing, "joinTextNodesWithSameStyle [1]\n");
             }
         }
     }
     else if (pos.offset() == (long)textNode->length()) {
         EditIterator it(pos);
-        DOMPosition next = it.next();
+        Position next = it.next();
         if (next == pos)
             return;
         if (next.node()->isTextNode()) {
             TextImpl *nextTextNode = static_cast<TextImpl *>(next.node());
             if (textNodesAreJoinable(textNode, nextTextNode)) {
                 joinTextNodes(textNode, nextTextNode);
-                setEndingSelection(DOMPosition(nextTextNode, pos.offset()));
+                setEndingSelection(Position(nextTextNode, pos.offset()));
                 LOG(Editing, "joinTextNodesWithSameStyle [2]\n");
             }
         }
     }
 }
 
-bool DeleteSelectionCommandImpl::containsOnlyWhitespace(const DOMPosition &start, const DOMPosition &end)
+bool DeleteSelectionCommandImpl::containsOnlyWhitespace(const Position &start, const Position &end)
 {
     // Returns whether the range contains only whitespace characters.
     // This is inclusive of the start, but not of the end.
@@ -834,19 +835,19 @@ bool DeleteSelectionCommandImpl::containsOnlyWhitespace(const DOMPosition &start
 
 void DeleteSelectionCommandImpl::doApply()
 {
-    if (m_selectionToDelete.state() != KHTMLSelection::RANGE)
+    if (m_selectionToDelete.state() != Selection::RANGE)
         return;
 
     deleteCollapsibleWhitespace(m_selectionToDelete);
-    KHTMLSelection selection = endingSelection();
+    Selection selection = endingSelection();
 
-    DOMPosition endingPosition;
+    Position endingPosition;
     bool adjustEndingPositionDownstream = false;
 
-    DOMPosition upstreamStart = selection.startPosition().equivalentUpstreamPosition();
-    DOMPosition downstreamStart = selection.startPosition().equivalentDownstreamPosition();
-    DOMPosition upstreamEnd = selection.endPosition().equivalentUpstreamPosition();
-    DOMPosition downstreamEnd = selection.endPosition().equivalentDownstreamPosition();
+    Position upstreamStart = selection.startPosition().equivalentUpstreamPosition();
+    Position downstreamStart = selection.startPosition().equivalentDownstreamPosition();
+    Position upstreamEnd = selection.endPosition().equivalentUpstreamPosition();
+    Position downstreamEnd = selection.endPosition().equivalentDownstreamPosition();
 
     bool onlyWhitespace = containsOnlyWhitespace(upstreamStart, downstreamEnd);
  
@@ -880,7 +881,7 @@ void DeleteSelectionCommandImpl::doApply()
     // Start is not completely selected
     if (startAtStartOfBlock) {
         LOG(Editing,  "ending position case 1");
-        endingPosition = DOMPosition(downstreamStart.node()->containingEditableBlock(), 1);
+        endingPosition = Position(downstreamStart.node()->containingEditableBlock(), 1);
         adjustEndingPositionDownstream = true;
     }
     else if (!startCompletelySelected) {
@@ -903,10 +904,10 @@ void DeleteSelectionCommandImpl::doApply()
     //
     if ((startAtStartOfBlock && !endAtEndOfBlock) || (!startCompletelySelected && adjustEndingPositionDownstream)) {
         // convert trailing whitespace
-        DOMPosition trailing = trailingWhitespacePosition(downstreamEnd.equivalentDownstreamPosition());
+        Position trailing = trailingWhitespacePosition(downstreamEnd.equivalentDownstreamPosition());
         if (trailing.notEmpty()) {
             debugPosition("convertTrailingWhitespace: ", trailing);
-            DOMPosition collapse = trailing.nextCharacterPosition();
+            Position collapse = trailing.nextCharacterPosition();
             if (collapse != trailing)
                 deleteCollapsibleWhitespace(collapse);
             TextImpl *textNode = static_cast<TextImpl *>(trailing.node());
@@ -915,7 +916,7 @@ void DeleteSelectionCommandImpl::doApply()
     }
     else if (!startAtStartOfBlock && endAtEndOfBlock) {
         // convert leading whitespace
-        DOMPosition leading = leadingWhitespacePosition(upstreamStart.equivalentUpstreamPosition());
+        Position leading = leadingWhitespacePosition(upstreamStart.equivalentUpstreamPosition());
         if (leading.notEmpty()) {
             debugPosition("convertLeadingWhitespace:  ", leading);
             TextImpl *textNode = static_cast<TextImpl *>(leading.node());
@@ -924,8 +925,8 @@ void DeleteSelectionCommandImpl::doApply()
     }
     else if (!startAtStartOfBlock && !endAtEndOfBlock) {
         // convert contiguous whitespace
-        DOMPosition leading = leadingWhitespacePosition(upstreamStart.equivalentUpstreamPosition());
-        DOMPosition trailing = trailingWhitespacePosition(downstreamEnd.equivalentDownstreamPosition());
+        Position leading = leadingWhitespacePosition(upstreamStart.equivalentUpstreamPosition());
+        Position trailing = trailingWhitespacePosition(downstreamEnd.equivalentDownstreamPosition());
         if (leading.notEmpty() && trailing.notEmpty()) {
             debugPosition("convertLeadingWhitespace [contiguous]:  ", leading);
             TextImpl *textNode = static_cast<TextImpl *>(leading.node());
@@ -1074,13 +1075,13 @@ int InputNewlineCommandImpl::commandID() const
 void InputNewlineCommandImpl::doApply()
 {
     deleteSelection();
-    KHTMLSelection selection = endingSelection();
+    Selection selection = endingSelection();
 
     int exceptionCode = 0;
     ElementImpl *breakNode = document()->createHTMLElement("BR", exceptionCode);
     ASSERT(exceptionCode == 0);
 
-    DOMPosition pos = selection.startPosition().equivalentDownstreamPosition();
+    Position pos = selection.startPosition().equivalentDownstreamPosition();
     bool atEnd = pos.offset() >= pos.node()->caretMaxOffset();
     bool atStart = pos.offset() <= pos.node()->caretMinOffset();
     bool atEndOfBlock = pos.isLastRenderedPositionInEditableBlock();
@@ -1092,18 +1093,18 @@ void InputNewlineCommandImpl::doApply()
         // But for right now, it gets the BR to render.
         TextImpl *editingTextNode = document()->createEditingTextNode(nonBreakingSpaceString());
         insertNodeAfter(editingTextNode, breakNode);
-        setEndingSelection(DOMPosition(editingTextNode, 1));
+        setEndingSelection(Position(editingTextNode, 1));
         editingTextNode->deref();
     }
     else if (atEnd) {
         LOG(Editing, "input newline case 2");
         insertNodeAfter(breakNode, pos.node());
-        setEndingSelection(DOMPosition(breakNode, 0));
+        setEndingSelection(Position(breakNode, 0));
     }
     else if (atStart) {
         LOG(Editing, "input newline case 3");
         insertNodeAt(breakNode, pos.node(), 0);
-        setEndingSelection(DOMPosition(pos.node(), 0));
+        setEndingSelection(Position(pos.node(), 0));
     }
     else {
         LOG(Editing, "input newline case 4");
@@ -1114,7 +1115,7 @@ void InputNewlineCommandImpl::doApply()
         insertNodeBefore(textBeforeNode, textNode);
         insertNodeBefore(breakNode, textNode);
         textBeforeNode->deref();
-        setEndingSelection(DOMPosition(textNode, 0));
+        setEndingSelection(Position(textNode, 0));
     }
         
     breakNode->deref();
@@ -1152,7 +1153,7 @@ void InputTextCommandImpl::deleteCharacter()
 {
     ASSERT(state() == Applied);
 
-    KHTMLSelection selection = endingSelection();
+    Selection selection = endingSelection();
 
     if (!selection.startNode()->isTextNode())
         return;
@@ -1163,20 +1164,20 @@ void InputTextCommandImpl::deleteCharacter()
         TextImpl *textNode = static_cast<TextImpl *>(selection.startNode());
         textNode->deleteData(offset, 1, exceptionCode);
         ASSERT(exceptionCode == 0);
-        selection = KHTMLSelection(textNode, offset);
+        selection = Selection(textNode, offset);
         setEndingSelection(selection);
         m_charactersAdded--;
     }
 }
 
-DOMPosition InputTextCommandImpl::prepareForTextInsertion(bool adjustDownstream)
+Position InputTextCommandImpl::prepareForTextInsertion(bool adjustDownstream)
 {
     // Prepare for text input by looking at the current position.
     // It may be necessary to insert a text node to receive characters.
-    KHTMLSelection selection = endingSelection();
-    ASSERT(selection.state() == KHTMLSelection::CARET);
+    Selection selection = endingSelection();
+    ASSERT(selection.state() == Selection::CARET);
     
-    DOMPosition pos = selection.startPosition();
+    Position pos = selection.startPosition();
     if (adjustDownstream)
         pos = pos.equivalentDownstreamPosition();
     else
@@ -1207,7 +1208,7 @@ DOMPosition InputTextCommandImpl::prepareForTextInsertion(bool adjustDownstream)
         else
             ASSERT_NOT_REACHED();
         
-        pos = DOMPosition(m_insertedTextNode, 0);
+        pos = Position(m_insertedTextNode, 0);
     }
     
     return pos;
@@ -1215,11 +1216,11 @@ DOMPosition InputTextCommandImpl::prepareForTextInsertion(bool adjustDownstream)
 
 void InputTextCommandImpl::execute(const DOMString &text)
 {
-    KHTMLSelection selection = endingSelection();
+    Selection selection = endingSelection();
     bool adjustDownstream = selection.startPosition().isFirstRenderedPositionOnLine();
 
     // Delete the current selection, or collapse whitespace, as needed
-    if (selection.state() == KHTMLSelection::RANGE)
+    if (selection.state() == Selection::RANGE)
         deleteSelection();
     else
         deleteCollapsibleWhitespace();
@@ -1227,7 +1228,7 @@ void InputTextCommandImpl::execute(const DOMString &text)
     // EDIT FIXME: Need to take typing style from upstream text, if any.
     
     // Make sure the document is set up to receive text
-    DOMPosition pos = prepareForTextInsertion(adjustDownstream);
+    Position pos = prepareForTextInsertion(adjustDownstream);
     
     TextImpl *textNode = static_cast<TextImpl *>(pos.node());
     long offset = pos.offset();
@@ -1250,7 +1251,7 @@ void InputTextCommandImpl::execute(const DOMString &text)
         }
         insertText(textNode, offset, text);
     }
-    setEndingSelection(DOMPosition(textNode, offset + text.length()));
+    setEndingSelection(Position(textNode, offset + text.length()));
     m_charactersAdded += text.length();
 }
 
@@ -1273,8 +1274,8 @@ void InputTextCommandImpl::insertSpace(TextImpl *textNode, unsigned long offset)
     if (count > 0) {
         // By checking the character at the downstream position, we can
         // check if there is a rendered WS at the caret
-        DOMPosition pos(textNode, offset);
-        DOMPosition downstream = pos.equivalentDownstreamPosition();
+        Position pos(textNode, offset);
+        Position downstream = pos.equivalentDownstreamPosition();
         if (downstream.offset() < (long)text.length() && isWS(text[downstream.offset()]))
             count--; // leave this WS in
         if (count > 0)
@@ -1486,10 +1487,10 @@ void PasteMarkupCommandImpl::doApply()
     ASSERT(firstChild);
     ASSERT(lastChild);
     
-    KHTMLSelection selection = endingSelection();
+    Selection selection = endingSelection();
 
     // Delete the current selection, or collapse whitespace, as needed
-    if (selection.state() == KHTMLSelection::RANGE)
+    if (selection.state() == Selection::RANGE)
         deleteSelection();
     else
         deleteCollapsibleWhitespace();
@@ -1526,7 +1527,7 @@ void PasteMarkupCommandImpl::doApply()
             leaf = nextChild;
         }
         
-        setEndingSelection(DOMPosition(leaf, leaf->caretMaxOffset()));
+        setEndingSelection(Position(leaf, leaf->caretMaxOffset()));
     }
 }
 
@@ -1750,11 +1751,11 @@ void TypingCommandImpl::insertNewline()
 
 void TypingCommandImpl::issueCommandForDeleteKey()
 {
-    KHTMLSelection selectionToDelete = endingSelection();
-    ASSERT(selectionToDelete.state() != KHTMLSelection::NONE);
+    Selection selectionToDelete = endingSelection();
+    ASSERT(selectionToDelete.state() != Selection::NONE);
     
-    if (selectionToDelete.state() == KHTMLSelection::CARET)
-        selectionToDelete = KHTMLSelection(selectionToDelete.startPosition().previousCharacterPosition(), selectionToDelete.startPosition());
+    if (selectionToDelete.state() == Selection::CARET)
+        selectionToDelete = Selection(selectionToDelete.startPosition().previousCharacterPosition(), selectionToDelete.startPosition());
     deleteSelection(selectionToDelete);
 }
 
diff --git a/WebCore/khtml/editing/htmlediting_impl.h b/WebCore/khtml/editing/htmlediting_impl.h
index 5d20e39..ca22c31 100644
--- a/WebCore/khtml/editing/htmlediting_impl.h
+++ b/WebCore/khtml/editing/htmlediting_impl.h
@@ -29,19 +29,18 @@
 #include "htmlediting.h"
 
 #include "dom_position.h"
+#include "dom_selection.h"
 #include "dom_string.h"
-#include "khtml_selection.h"
 #include "qvaluelist.h"
 #include "shared.h"
 
-class KHTMLSelection;
-
 namespace DOM {
     class DocumentImpl;
-    class DOMPosition;
     class DOMString;
     class ElementImpl;
     class NodeImpl;
+    class Position;
+    class Selection;
     class TextImpl;
 };
 
@@ -73,14 +72,14 @@ public:
 
     virtual DOM::DocumentImpl * const document() const { return m_document; }
 
-    KHTMLSelection startingSelection() const { return m_startingSelection; }
-    KHTMLSelection endingSelection() const { return m_endingSelection; }
+    DOM::Selection startingSelection() const { return m_startingSelection; }
+    DOM::Selection endingSelection() const { return m_endingSelection; }
         
     ECommandState state() const { return m_state; }
     void setState(ECommandState state) { m_state = state; }
 
-    void setStartingSelection(const KHTMLSelection &s);
-    void setEndingSelection(const KHTMLSelection &s);
+    void setStartingSelection(const DOM::Selection &s);
+    void setEndingSelection(const DOM::Selection &s);
 
     void moveToStartingSelection();
     void moveToEndingSelection();
@@ -88,8 +87,8 @@ public:
 private:
     DOM::DocumentImpl *m_document;
     ECommandState m_state;
-    KHTMLSelection m_startingSelection;
-    KHTMLSelection m_endingSelection;
+    DOM::Selection m_startingSelection;
+    DOM::Selection m_endingSelection;
     EditCommand m_parent;
 };
 
@@ -126,10 +125,10 @@ protected:
     void deleteText(DOM::TextImpl *node, long offset, long count);
     void replaceText(DOM::TextImpl *node, long offset, long count, const DOM::DOMString &replacementText);
     void deleteSelection();
-    void deleteSelection(const KHTMLSelection &selection);
+    void deleteSelection(const DOM::Selection &selection);
     void deleteKeyPressed();
     void deleteCollapsibleWhitespace();
-    void deleteCollapsibleWhitespace(const KHTMLSelection &selection);
+    void deleteCollapsibleWhitespace(const DOM::Selection &selection);
 
     QValueList<EditCommand> m_cmds;
 };
@@ -165,7 +164,7 @@ class DeleteCollapsibleWhitespaceCommandImpl : public CompositeEditCommandImpl
 { 
 public:
 	DeleteCollapsibleWhitespaceCommandImpl(DOM::DocumentImpl *document);
-	DeleteCollapsibleWhitespaceCommandImpl(DOM::DocumentImpl *document, const KHTMLSelection &selection);
+	DeleteCollapsibleWhitespaceCommandImpl(DOM::DocumentImpl *document, const DOM::Selection &selection);
     
 	virtual ~DeleteCollapsibleWhitespaceCommandImpl();
 	
@@ -174,9 +173,9 @@ public:
 	virtual void doApply();
 
 private:
-    DOM::DOMPosition deleteWhitespace(const DOM::DOMPosition &pos);
+    DOM::Position deleteWhitespace(const DOM::Position &pos);
 
-    KHTMLSelection m_selectionToCollapse;
+    DOM::Selection m_selectionToCollapse;
     unsigned long m_charactersDeleted;
 };
 
@@ -187,7 +186,7 @@ class DeleteSelectionCommandImpl : public CompositeEditCommandImpl
 { 
 public:
 	DeleteSelectionCommandImpl(DOM::DocumentImpl *document);
-	DeleteSelectionCommandImpl(DOM::DocumentImpl *document, const KHTMLSelection &selection);
+	DeleteSelectionCommandImpl(DOM::DocumentImpl *document, const DOM::Selection &selection);
     
 	virtual ~DeleteSelectionCommandImpl();
 	
@@ -196,11 +195,11 @@ public:
 	virtual void doApply();
     
 private:
-    void deleteDownstreamWS(const DOM::DOMPosition &start);
-    bool containsOnlyWhitespace(const DOM::DOMPosition &start, const DOM::DOMPosition &end);
+    void deleteDownstreamWS(const DOM::Position &start);
+    bool containsOnlyWhitespace(const DOM::Position &start, const DOM::Position &end);
     void joinTextNodesWithSameStyle();
 
-    KHTMLSelection m_selectionToDelete;
+    DOM::Selection m_selectionToDelete;
 };
 
 //------------------------------------------------------------------------------------------
@@ -261,7 +260,7 @@ public:
     unsigned long charactersAdded() const { return m_charactersAdded; }
     
 private:
-    DOM::DOMPosition prepareForTextInsertion(bool adjustDownstream);
+    DOM::Position prepareForTextInsertion(bool adjustDownstream);
     void execute(const DOM::DOMString &text);
     void insertSpace(DOM::TextImpl *textNode, unsigned long offset);
 
diff --git a/WebCore/khtml/editing/selection.cpp b/WebCore/khtml/editing/selection.cpp
index 82dc803..e59b11f 100644
--- a/WebCore/khtml/editing/selection.cpp
+++ b/WebCore/khtml/editing/selection.cpp
@@ -23,7 +23,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
   
-#include "khtml_selection.h"
+#include "dom_selection.h"
 
 #include "htmltags.h"
 #include "khtml_part.h"
@@ -52,15 +52,8 @@
 #define EDIT_DEBUG 0
 #endif
 
-using DOM::DocumentImpl;
-using DOM::DOMPosition;
-using DOM::DOMString;
-using DOM::EditIterator;
-using DOM::ElementImpl;
-using DOM::Node;
-using DOM::NodeImpl;
-using DOM::Range;
-using DOM::TextImpl;
+namespace DOM {
+
 using khtml::InlineTextBox;
 using khtml::RenderObject;
 using khtml::RenderText;
@@ -68,16 +61,16 @@ using khtml::RenderText;
 #if APPLE_CHANGES
 static bool firstRunAt(RenderObject *renderNode, int y, NodeImpl *&startNode, long &startOffset);
 static bool lastRunAt(RenderObject *renderNode, int y, NodeImpl *&endNode, long &endOffset);
-static bool startAndEndLineNodesIncludingNode(DOM::NodeImpl *node, int offset, KHTMLSelection &selection);
+static bool startAndEndLineNodesIncludingNode(DOM::NodeImpl *node, int offset, Selection &selection);
 #endif
 
 
-KHTMLSelection::KHTMLSelection()
+Selection::Selection()
 {
     init();
 }
 
-KHTMLSelection::KHTMLSelection(NodeImpl *node, long offset)
+Selection::Selection(NodeImpl *node, long offset)
 {
     init();
 
@@ -89,7 +82,7 @@ KHTMLSelection::KHTMLSelection(NodeImpl *node, long offset)
     validate();
 }
 
-KHTMLSelection::KHTMLSelection(const DOMPosition &pos)
+Selection::Selection(const Position &pos)
 {
     init();
 
@@ -101,7 +94,7 @@ KHTMLSelection::KHTMLSelection(const DOMPosition &pos)
     validate();
 }
 
-KHTMLSelection::KHTMLSelection(const DOMPosition &base, const DOMPosition &extent)
+Selection::Selection(const Position &base, const Position &extent)
 {
     init();
 
@@ -113,7 +106,7 @@ KHTMLSelection::KHTMLSelection(const DOMPosition &base, const DOMPosition &exten
     validate();
 }
 
-KHTMLSelection::KHTMLSelection(NodeImpl *baseNode, long baseOffset, NodeImpl *endNode, long endOffset)
+Selection::Selection(NodeImpl *baseNode, long baseOffset, NodeImpl *endNode, long endOffset)
 {
     init();
 
@@ -125,7 +118,7 @@ KHTMLSelection::KHTMLSelection(NodeImpl *baseNode, long baseOffset, NodeImpl *en
     validate();
 }
 
-KHTMLSelection::KHTMLSelection(const KHTMLSelection &o)
+Selection::Selection(const Selection &o)
 {
     init();
     
@@ -157,7 +150,7 @@ KHTMLSelection::KHTMLSelection(const KHTMLSelection &o)
     }
 }
 
-void KHTMLSelection::init()
+void Selection::init()
 {
     m_baseNode = 0;
     m_baseOffset = 0;
@@ -176,7 +169,7 @@ void KHTMLSelection::init()
     m_modifyBiasSet = false;
 }
 
-KHTMLSelection::~KHTMLSelection()
+Selection::~Selection()
 {
     if (m_baseNode)
         m_baseNode->deref();
@@ -188,7 +181,7 @@ KHTMLSelection::~KHTMLSelection()
         m_endNode->deref();
 }
 
-KHTMLSelection &KHTMLSelection::operator=(const KHTMLSelection &o)
+Selection &Selection::operator=(const Selection &o)
 {
 	setBaseNode(o.baseNode());
 	setExtentNode(o.extentNode());
@@ -220,28 +213,28 @@ KHTMLSelection &KHTMLSelection::operator=(const KHTMLSelection &o)
     return *this;
 }
 
-void KHTMLSelection::moveTo(DOM::NodeImpl *node, long offset)
+void Selection::moveTo(DOM::NodeImpl *node, long offset)
 {
     moveTo(node, offset, node, offset);
 }
 
-void KHTMLSelection::moveTo(const DOM::Range &r)
+void Selection::moveTo(const DOM::Range &r)
 {
 	moveTo(r.startContainer().handle(), r.startOffset(), 
 		r.endContainer().handle(), r.endOffset());
 }
 
-void KHTMLSelection::moveTo(const DOM::DOMPosition &pos)
+void Selection::moveTo(const DOM::Position &pos)
 {
 	moveTo(pos.node(), pos.offset());
 }
 
-void KHTMLSelection::moveTo(const KHTMLSelection &o)
+void Selection::moveTo(const Selection &o)
 {
 	moveTo(o.baseNode(), o.baseOffset(), o.extentNode(), o.extentOffset());
 }
 
-void KHTMLSelection::moveTo(DOM::NodeImpl *baseNode, long baseOffset, DOM::NodeImpl *extentNode, long extentOffset)
+void Selection::moveTo(DOM::NodeImpl *baseNode, long baseOffset, DOM::NodeImpl *extentNode, long extentOffset)
 {
 	setBaseNode(baseNode);
 	setExtentNode(extentNode);
@@ -250,9 +243,9 @@ void KHTMLSelection::moveTo(DOM::NodeImpl *baseNode, long baseOffset, DOM::NodeI
 	validate();
 }
 
-bool KHTMLSelection::modify(EAlter alter, EDirection dir, ETextGranularity granularity)
+bool Selection::modify(EAlter alter, EDirection dir, ETextGranularity granularity)
 {
-    DOMPosition pos;
+    Position pos;
     
     switch (dir) {
         // EDIT FIXME: This needs to handle bidi
@@ -364,7 +357,7 @@ bool KHTMLSelection::modify(EAlter alter, EDirection dir, ETextGranularity granu
     return true;
 }
 
-bool KHTMLSelection::expandUsingGranularity(ETextGranularity granularity)
+bool Selection::expandUsingGranularity(ETextGranularity granularity)
 {
     if (state() == NONE)
         return false;
@@ -373,14 +366,14 @@ bool KHTMLSelection::expandUsingGranularity(ETextGranularity granularity)
     return true;
 }
 
-int KHTMLSelection::xPosForVerticalArrowNavigation(EPositionType type, bool recalc) const
+int Selection::xPosForVerticalArrowNavigation(EPositionType type, bool recalc) const
 {
     int x = 0;
 
     if (state() == NONE)
         return x;
 
-    DOMPosition pos;
+    Position pos;
     switch (type) {
         case START:
             pos = startPosition();
@@ -412,7 +405,7 @@ int KHTMLSelection::xPosForVerticalArrowNavigation(EPositionType type, bool reca
     return x;
 }
 
-void KHTMLSelection::clear()
+void Selection::clear()
 {
 	setBaseNode(0);
 	setExtentNode(0);
@@ -421,26 +414,26 @@ void KHTMLSelection::clear()
 	validate();
 }
 
-void KHTMLSelection::setBase(DOM::NodeImpl *node, long offset)
+void Selection::setBase(DOM::NodeImpl *node, long offset)
 {
 	setBaseNode(node);
 	setBaseOffset(offset);
 	validate();
 }
 
-void KHTMLSelection::setExtent(DOM::NodeImpl *node, long offset)
+void Selection::setExtent(DOM::NodeImpl *node, long offset)
 {
 	setExtentNode(node);
 	setExtentOffset(offset);
 	validate();
 }
 
-void KHTMLSelection::setNeedsLayout(bool flag)
+void Selection::setNeedsLayout(bool flag)
 {
     m_needsCaretLayout = flag;
 }
 
-Range KHTMLSelection::toRange() const
+Range Selection::toRange() const
 {
     if (isEmpty())
         return Range();
@@ -448,7 +441,7 @@ Range KHTMLSelection::toRange() const
     return Range(Node(startNode()), startOffset(), Node(endNode()), endOffset());
 }
 
-void KHTMLSelection::layoutCaret()
+void Selection::layoutCaret()
 {
     if (isEmpty() || !startNode()->renderer()) {
         m_caretX = m_caretY = m_caretSize = 0;
@@ -461,13 +454,13 @@ void KHTMLSelection::layoutCaret()
     m_needsCaretLayout = false;
 }
 
-QRect KHTMLSelection::getRepaintRect()
+QRect Selection::getRepaintRect()
 {
     // EDIT FIXME: fudge a bit to make sure we don't leave behind artifacts
     return QRect(m_caretX - 1, m_caretY - 1, 3, m_caretSize + 2);
 }
 
-void KHTMLSelection::needsCaretRepaint()
+void Selection::needsCaretRepaint()
 {
     if (isEmpty())
         return;
@@ -500,7 +493,7 @@ void KHTMLSelection::needsCaretRepaint()
     v->updateContents(getRepaintRect(), false);
 }
 
-void KHTMLSelection::paintCaret(QPainter *p, const QRect &rect)
+void Selection::paintCaret(QPainter *p, const QRect &rect)
 {
     if (isEmpty())
         return;
@@ -509,7 +502,7 @@ void KHTMLSelection::paintCaret(QPainter *p, const QRect &rect)
         return;
 
     if (m_needsCaretLayout) {
-        DOMPosition pos = DOMPosition(startNode(), startOffset());
+        Position pos = Position(startNode(), startOffset());
         if (!pos.inRenderedContent()) {
             moveToRenderedContent();
         }
@@ -527,7 +520,7 @@ void KHTMLSelection::paintCaret(QPainter *p, const QRect &rect)
     }
 }
 
-void KHTMLSelection::setBaseNode(DOM::NodeImpl *node)
+void Selection::setBaseNode(DOM::NodeImpl *node)
 {
 	if (m_baseNode == node)
 		return;
@@ -541,12 +534,12 @@ void KHTMLSelection::setBaseNode(DOM::NodeImpl *node)
 		m_baseNode->ref();
 }
 
-void KHTMLSelection::setBaseOffset(long offset)
+void Selection::setBaseOffset(long offset)
 {
 	m_baseOffset = offset;
 }
 
-void KHTMLSelection::setExtentNode(DOM::NodeImpl *node)
+void Selection::setExtentNode(DOM::NodeImpl *node)
 {
 	if (m_extentNode == node)
 		return;
@@ -560,12 +553,12 @@ void KHTMLSelection::setExtentNode(DOM::NodeImpl *node)
 		m_extentNode->ref();
 }
 	
-void KHTMLSelection::setExtentOffset(long offset)
+void Selection::setExtentOffset(long offset)
 {
 	m_extentOffset = offset;
 }
 
-void KHTMLSelection::setStartNode(DOM::NodeImpl *node)
+void Selection::setStartNode(DOM::NodeImpl *node)
 {
 	if (m_startNode == node)
 		return;
@@ -579,12 +572,12 @@ void KHTMLSelection::setStartNode(DOM::NodeImpl *node)
 		m_startNode->ref();
 }
 
-void KHTMLSelection::setStartOffset(long offset)
+void Selection::setStartOffset(long offset)
 {
 	m_startOffset = offset;
 }
 
-void KHTMLSelection::setEndNode(DOM::NodeImpl *node)
+void Selection::setEndNode(DOM::NodeImpl *node)
 {
 	if (m_endNode == node)
 		return;
@@ -598,17 +591,17 @@ void KHTMLSelection::setEndNode(DOM::NodeImpl *node)
 		m_endNode->ref();
 }
 	
-void KHTMLSelection::setEndOffset(long offset)
+void Selection::setEndOffset(long offset)
 {
 	m_endOffset = offset;
 }
 
-void KHTMLSelection::validate(ETextGranularity granularity)
+void Selection::validate(ETextGranularity granularity)
 {
     // move the base and extent nodes to their equivalent leaf positions
     bool baseAndExtentEqual = m_baseNode == m_extentNode && m_baseOffset == m_extentOffset;
     if (m_baseNode) {
-        DOMPosition pos = basePosition().equivalentLeafPosition();
+        Position pos = basePosition().equivalentLeafPosition();
         m_baseNode = pos.node();
         m_baseOffset = pos.offset();
         if (baseAndExtentEqual) {
@@ -617,7 +610,7 @@ void KHTMLSelection::validate(ETextGranularity granularity)
         }
     }
     if (m_extentNode && !baseAndExtentEqual) {
-        DOMPosition pos = extentPosition().equivalentLeafPosition();
+        Position pos = extentPosition().equivalentLeafPosition();
         m_extentNode = pos.node();
         m_extentOffset = pos.offset();
     }
@@ -712,8 +705,8 @@ void KHTMLSelection::validate(ETextGranularity granularity)
         }
     }
     else {  // granularity == LINE
-        KHTMLSelection baseSelection = *this;
-        KHTMLSelection extentSelection = *this;
+        Selection baseSelection = *this;
+        Selection extentSelection = *this;
         if (m_baseNode && (m_baseNode->nodeType() == Node::TEXT_NODE || m_baseNode->nodeType() == Node::CDATA_SECTION_NODE)) {
             if (startAndEndLineNodesIncludingNode(m_baseNode, m_baseOffset, baseSelection)) {
                 setStartNode(baseSelection.baseNode());
@@ -760,7 +753,7 @@ void KHTMLSelection::validate(ETextGranularity granularity)
 #endif
 }
 
-bool KHTMLSelection::moveToRenderedContent()
+bool Selection::moveToRenderedContent()
 {
     if (isEmpty())
         return false;
@@ -768,19 +761,19 @@ bool KHTMLSelection::moveToRenderedContent()
     if (m_state != CARET)
         return false;
 
-    DOMPosition pos = DOMPosition(startNode(), startOffset());
+    Position pos = Position(startNode(), startOffset());
     if (pos.inRenderedContent())
         return true;
         
     // not currently rendered, try moving to prev
-    DOMPosition prev = pos.previousCharacterPosition();
+    Position prev = pos.previousCharacterPosition();
     if (prev != pos && prev.node()->inSameContainingEditableBlock(pos.node())) {
         moveTo(prev);
         return true;
     }
 
     // could not be moved to prev, try next
-    DOMPosition next = pos.nextCharacterPosition();
+    Position next = pos.nextCharacterPosition();
     if (next != pos && next.node()->inSameContainingEditableBlock(pos.node())) {
         moveTo(next);
         return true;
@@ -789,27 +782,27 @@ bool KHTMLSelection::moveToRenderedContent()
     return false;
 }
 
-DOMPosition KHTMLSelection::basePosition() const
+Position Selection::basePosition() const
 {
-    return DOMPosition(baseNode(), baseOffset());
+    return Position(baseNode(), baseOffset());
 }
 
-DOMPosition KHTMLSelection::extentPosition() const
+Position Selection::extentPosition() const
 {
-    return DOMPosition(extentNode(), extentOffset());
+    return Position(extentNode(), extentOffset());
 }
 
-DOMPosition KHTMLSelection::startPosition() const
+Position Selection::startPosition() const
 {
-    return DOMPosition(startNode(), startOffset());
+    return Position(startNode(), startOffset());
 }
 
-DOMPosition KHTMLSelection::endPosition() const
+Position Selection::endPosition() const
 {
-    return DOMPosition(endNode(), endOffset());
+    return Position(endNode(), endOffset());
 }
 
-bool KHTMLSelection::nodeIsBeforeNode(NodeImpl *n1, NodeImpl *n2) 
+bool Selection::nodeIsBeforeNode(NodeImpl *n1, NodeImpl *n2) 
 {
 	if (!n1 || !n2) 
 		return true;
@@ -921,7 +914,7 @@ static bool lastRunAt(RenderObject *renderNode, int y, NodeImpl *&endNode, long
     }
 }
 
-static bool startAndEndLineNodesIncludingNode(DOM::NodeImpl *node, int offset, KHTMLSelection &selection)
+static bool startAndEndLineNodesIncludingNode(DOM::NodeImpl *node, int offset, Selection &selection)
 {
     if (node && (node->nodeType() == Node::TEXT_NODE || node->nodeType() == Node::CDATA_SECTION_NODE)) {
         int pos;
@@ -964,7 +957,7 @@ static bool startAndEndLineNodesIncludingNode(DOM::NodeImpl *node, int offset, K
     return false;
 }
 
-void KHTMLSelection::debugRenderer(RenderObject *r, bool selected) const
+void Selection::debugRenderer(RenderObject *r, bool selected) const
 {
     if (r->node()->isElementNode()) {
         ElementImpl *element = static_cast<ElementImpl *>(r->node());
@@ -1037,7 +1030,7 @@ void KHTMLSelection::debugRenderer(RenderObject *r, bool selected) const
     }
 }
 
-void KHTMLSelection::debugPosition() const
+void Selection::debugPosition() const
 {
     if (!startNode())
         return;
@@ -1046,20 +1039,20 @@ void KHTMLSelection::debugPosition() const
     
     //RenderObject *r = 0;
 
-    fprintf(stderr, "KHTMLSelection =================\n");
+    fprintf(stderr, "Selection =================\n");
 
     if (startPosition() == endPosition()) {
-        DOMPosition pos = startPosition();
-        DOMPosition upstream = pos.equivalentUpstreamPosition();
-        DOMPosition downstream = pos.equivalentDownstreamPosition();
+        Position pos = startPosition();
+        Position upstream = pos.equivalentUpstreamPosition();
+        Position downstream = pos.equivalentDownstreamPosition();
         fprintf(stderr, "upstream:   %s %p:%d\n", getTagName(upstream.node()->id()).string().latin1(), upstream.node(), upstream.offset());
         fprintf(stderr, "pos:        %s %p:%d\n", getTagName(pos.node()->id()).string().latin1(), pos.node(), pos.offset());
         fprintf(stderr, "downstream: %s %p:%d\n", getTagName(downstream.node()->id()).string().latin1(), downstream.node(), downstream.offset());
     }
     else {
-        DOMPosition pos = startPosition();
-        DOMPosition upstream = pos.equivalentUpstreamPosition();
-        DOMPosition downstream = pos.equivalentDownstreamPosition();
+        Position pos = startPosition();
+        Position upstream = pos.equivalentUpstreamPosition();
+        Position downstream = pos.equivalentDownstreamPosition();
         fprintf(stderr, "upstream:   %s %p:%d\n", getTagName(upstream.node()->id()).string().latin1(), upstream.node(), upstream.offset());
         fprintf(stderr, "start:      %s %p:%d\n", getTagName(pos.node()->id()).string().latin1(), pos.node(), pos.offset());
         fprintf(stderr, "downstream: %s %p:%d\n", getTagName(downstream.node()->id()).string().latin1(), downstream.node(), downstream.offset());
@@ -1113,3 +1106,5 @@ void KHTMLSelection::debugPosition() const
 }
 
 #endif
+
+} // namespace DOM
diff --git a/WebCore/khtml/editing/selection.h b/WebCore/khtml/editing/selection.h
index 326a0ea..01fcb1b 100644
--- a/WebCore/khtml/editing/selection.h
+++ b/WebCore/khtml/editing/selection.h
@@ -23,33 +23,33 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-#ifndef __khtml_selection_h__
-#define __khtml_selection_h__
+#ifndef __dom_selection_h__
+#define __dom_selection_h__
 
 class KHTMLPart;
 class QPainter;
 class QRect;
 
-namespace DOM {
-    class DOMPosition;
-    class NodeImpl;
-    class Range;
-};
-
 namespace khtml {
     class RenderObject;
 }
 
-class KHTMLSelection
+namespace DOM {
+
+class NodeImpl;
+class Position;
+class Range;
+
+class Selection
 {
 public:
-    KHTMLSelection();
-    KHTMLSelection(DOM::NodeImpl *node, long offset);
-    KHTMLSelection(const DOM::DOMPosition &);
-    KHTMLSelection(const DOM::DOMPosition &, const DOM::DOMPosition &);
-    KHTMLSelection(DOM::NodeImpl *startNode, long startOffset, DOM::NodeImpl *endNode, long endOffset);
-    KHTMLSelection(const KHTMLSelection &);
-    ~KHTMLSelection();
+    Selection();
+    Selection(NodeImpl *node, long offset);
+    Selection(const Position &);
+    Selection(const Position &, const Position &);
+    Selection(NodeImpl *startNode, long startOffset, NodeImpl *endNode, long endOffset);
+    Selection(const Selection &);
+    ~Selection();
 
 	enum EState { NONE, CARET, RANGE };
 	enum EAlter { MOVE, EXTEND };
@@ -58,52 +58,52 @@ public:
 
 	EState state() const { return m_state; }
 
-    void moveTo(DOM::NodeImpl *node, long offset);
-    void moveTo(const DOM::Range &);
-    void moveTo(const DOM::DOMPosition &);
-    void moveTo(const KHTMLSelection &);
-    void moveTo(DOM::NodeImpl *baseNode, long baseOffset, DOM::NodeImpl *extentNode, long extentOffset);
+    void moveTo(NodeImpl *node, long offset);
+    void moveTo(const Range &);
+    void moveTo(const Position &);
+    void moveTo(const Selection &);
+    void moveTo(NodeImpl *baseNode, long baseOffset, NodeImpl *extentNode, long extentOffset);
     bool modify(EAlter, EDirection, ETextGranularity);
     bool expandUsingGranularity(ETextGranularity);
     void clear();
 
     bool moveToRenderedContent();
     
-    void setBase(DOM::NodeImpl *node, long offset);
-    void setExtent(DOM::NodeImpl *node, long offset);
+    void setBase(NodeImpl *node, long offset);
+    void setExtent(NodeImpl *node, long offset);
 
-    DOM::NodeImpl *baseNode() const { return m_baseNode; }
+    NodeImpl *baseNode() const { return m_baseNode; }
     long baseOffset() const { return m_baseOffset; }
 
-    DOM::NodeImpl *extentNode() const { return m_extentNode; }
+    NodeImpl *extentNode() const { return m_extentNode; }
     long extentOffset() const { return m_extentOffset; }
 
-    DOM::NodeImpl *startNode() const { return m_startNode; }
+    NodeImpl *startNode() const { return m_startNode; }
     long startOffset() const { return m_startOffset; }
 
-    DOM::NodeImpl *endNode() const { return m_endNode; }
+    NodeImpl *endNode() const { return m_endNode; }
     long endOffset() const { return m_endOffset; }
 
-    DOM::DOMPosition basePosition() const;
-    DOM::DOMPosition extentPosition() const;
-    DOM::DOMPosition startPosition() const;
-    DOM::DOMPosition endPosition() const;
+    Position basePosition() const;
+    Position extentPosition() const;
+    Position startPosition() const;
+    Position endPosition() const;
 
     void setNeedsLayout(bool flag=true);
     void clearModifyBias() { m_modifyBiasSet = false; }
     
     bool isEmpty() const { return state() == NONE; }
     bool notEmpty() const { return !isEmpty(); }
-    DOM::Range toRange() const;
+    Range toRange() const;
 
     
     void debugPosition() const;
     void debugRenderer(khtml::RenderObject *r, bool selected) const;
 
-    KHTMLSelection &operator=(const KHTMLSelection &o);
+    Selection &operator=(const Selection &o);
     
-    friend bool operator==(const KHTMLSelection &a, const KHTMLSelection &b);
-    friend bool operator!=(const KHTMLSelection &a, const KHTMLSelection &b);
+    friend bool operator==(const Selection &a, const Selection &b);
+    friend bool operator!=(const Selection &a, const Selection &b);
     
     friend class KHTMLPart;
 
@@ -118,29 +118,29 @@ private:
     QRect getRepaintRect();
     void paintCaret(QPainter *p, const QRect &rect);
 
-	void setBaseNode(DOM::NodeImpl *);
+	void setBaseNode(NodeImpl *);
 	void setBaseOffset(long);
-	void setExtentNode(DOM::NodeImpl *);
+	void setExtentNode(NodeImpl *);
 	void setExtentOffset(long);
 
-	void setStartNode(DOM::NodeImpl *);
+	void setStartNode(NodeImpl *);
 	void setStartOffset(long);
-	void setEndNode(DOM::NodeImpl *);
+	void setEndNode(NodeImpl *);
 	void setEndOffset(long);
 
-    bool nodeIsBeforeNode(DOM::NodeImpl *n1, DOM::NodeImpl *n2);
+    bool nodeIsBeforeNode(NodeImpl *n1, NodeImpl *n2);
 
     void calculateStartAndEnd(ETextGranularity select=CHARACTER);
     int xPosForVerticalArrowNavigation(EPositionType, bool recalc=false) const;
     
-    DOM::NodeImpl *m_baseNode;    // base node for the selection
+    NodeImpl *m_baseNode;    // base node for the selection
     long m_baseOffset;            // offset into base node where selection is
-    DOM::NodeImpl *m_extentNode;  // extent node for the selection
+    NodeImpl *m_extentNode;  // extent node for the selection
     long m_extentOffset;          // offset into extent node where selection is
 
-    DOM::NodeImpl *m_startNode;   // start node for the selection (read-only)
+    NodeImpl *m_startNode;   // start node for the selection (read-only)
     long m_startOffset;           // offset into start node where selection is (read-only)
-    DOM::NodeImpl *m_endNode;     // end node for the selection (read-only)
+    NodeImpl *m_endNode;     // end node for the selection (read-only)
     long m_endOffset;             // offset into end node where selection is (read-only)
 
 	EState m_state;               // the state of the selection
@@ -155,15 +155,17 @@ private:
 };
 
 
-inline bool operator==(const KHTMLSelection &a, const KHTMLSelection &b)
+inline bool operator==(const Selection &a, const Selection &b)
 {
     return a.startNode() == b.startNode() && a.startOffset() == b.startOffset() &&
         a.endNode() == b.endNode() && a.endOffset() == b.endOffset();
 }
 
-inline bool operator!=(const KHTMLSelection &a, const KHTMLSelection &b)
+inline bool operator!=(const Selection &a, const Selection &b)
 {
     return !(a == b);
 }
 
-#endif
\ No newline at end of file
+} // namespace DOM
+
+#endif  // __dom_selection_h__
\ No newline at end of file
diff --git a/WebCore/khtml/html/html_elementimpl.cpp b/WebCore/khtml/html/html_elementimpl.cpp
index 2d8c634..4b4df19 100644
--- a/WebCore/khtml/html/html_elementimpl.cpp
+++ b/WebCore/khtml/html/html_elementimpl.cpp
@@ -37,7 +37,6 @@
 
 #include "khtmlview.h"
 #include "khtml_part.h"
-#include "khtml_selection.h"
 
 #include "rendering/render_object.h"
 #include "rendering/render_replaced.h"
@@ -46,6 +45,7 @@
 #include "css/cssproperties.h"
 #include "css/cssvalues.h"
 #include "css/css_ruleimpl.h"
+#include "xml/dom_selection.h"
 #include "xml/dom_textimpl.h"
 #include "xml/dom2_eventsimpl.h"
 
diff --git a/WebCore/khtml/khtml_events.cpp b/WebCore/khtml/khtml_events.cpp
index f920b47..259de03 100644
--- a/WebCore/khtml/khtml_events.cpp
+++ b/WebCore/khtml/khtml_events.cpp
@@ -53,7 +53,7 @@ khtml::MouseEvent::~MouseEvent()
 
 long khtml::MouseEvent::offset() const
 {
-    DOMPosition pos;
+    Position pos;
     if (innerNode().handle()) {
         // FIXME: Shouldn't be necessary to skip text nodes.
         DOM::Node inner = innerNode();
diff --git a/WebCore/khtml/khtml_part.cpp b/WebCore/khtml/khtml_part.cpp
index 1ae0d19..d4eac1c 100644
--- a/WebCore/khtml/khtml_part.cpp
+++ b/WebCore/khtml/khtml_part.cpp
@@ -47,6 +47,7 @@
 #include "rendering/render_frames.h"
 #include "misc/htmlhashes.h"
 #include "misc/loader.h"
+#include "xml/dom_selection.h"
 #include "xml/dom2_eventsimpl.h"
 #include "xml/xml_tokenizer.h"
 #include "css/cssstyleselector.h"
@@ -54,7 +55,6 @@
 using namespace DOM;
 
 #include "khtmlview.h"
-#include "khtml_selection.h"
 #include <kparts/partmanager.h>
 #include "ecma/kjs_proxy.h"
 #include "khtml_settings.h"
@@ -2226,7 +2226,7 @@ bool KHTMLPart::findTextNext( const QString &str, bool forward, bool caseSensiti
                   ->posOfChar(d->m_findPos, x, y);
                 d->m_view->setContentsPos(x-50, y-50);
 #endif
-                KHTMLSelection s = selection();
+                Selection s = selection();
                 s.moveTo(d->m_findNode, d->m_findPos, d->m_findNode, d->m_findPos + matchLen);
                 setSelection(s);
                 return true;
@@ -2462,12 +2462,12 @@ bool KHTMLPart::hasSelection() const
     return !d->m_selection.isEmpty();
 }
 
-const KHTMLSelection &KHTMLPart::selection() const
+const Selection &KHTMLPart::selection() const
 {
     return d->m_selection;
 }
 
-void KHTMLPart::setSelection(const KHTMLSelection &s)
+void KHTMLPart::setSelection(const Selection &s)
 {
     if (d->m_selection != s) {
         clearCaretRectIfNeeded(); 
@@ -2479,7 +2479,7 @@ void KHTMLPart::setSelection(const KHTMLSelection &s)
 
 void KHTMLPart::takeSelectionFrom(const EditCommand &cmd, bool useEndingSelection)
 {
-    KHTMLSelection s;
+    Selection s;
     if (useEndingSelection)
         s = cmd.endingSelection();
     else
@@ -2497,7 +2497,7 @@ void KHTMLPart::clearSelection()
 {
     clearCaretRectIfNeeded();
     setFocusNodeIfNeeded(d->m_selection);
-    d->m_selection = KHTMLSelection();
+    d->m_selection = Selection();
     notifySelectionChanged();
 }
 
@@ -2537,9 +2537,9 @@ void KHTMLPart::clearCaretRectIfNeeded()
     }        
 }
 
-void KHTMLPart::setFocusNodeIfNeeded(const KHTMLSelection &s)
+void KHTMLPart::setFocusNodeIfNeeded(const Selection &s)
 {
-    if (!xmlDocImpl() || s.state() == KHTMLSelection::NONE)
+    if (!xmlDocImpl() || s.state() == Selection::NONE)
         return;
 
     NodeImpl *n = s.startNode();
@@ -2574,7 +2574,7 @@ void KHTMLPart::notifySelectionChanged(bool endTyping)
 
     // see if a new caret blink timer needs to be started
     if (d->m_caretVisible && d->m_caretBlinks && 
-        d->m_selection.state() == KHTMLSelection::CARET && d->m_selection.startNode()->isContentEditable()) {
+        d->m_selection.state() == Selection::CARET && d->m_selection.startNode()->isContentEditable()) {
         d->m_caretBlinkTimer = startTimer(CARET_BLINK_FREQUENCY);
         d->m_caretPaint = true;
         d->m_selection.needsCaretRepaint();
@@ -2608,7 +2608,7 @@ void KHTMLPart::timerEvent(QTimerEvent *e)
     if (e->timerId() == d->m_caretBlinkTimer && 
         d->m_caretVisible && 
         d->m_caretBlinks && 
-        d->m_selection.state() == KHTMLSelection::CARET) {
+        d->m_selection.state() == Selection::CARET) {
         d->m_caretPaint = !d->m_caretPaint;
         d->m_selection.needsCaretRepaint();
     }
@@ -4482,7 +4482,7 @@ void KHTMLPart::customEvent( QCustomEvent *event )
 bool KHTMLPart::isPointInsideSelection(int x, int y)
 {
     // Treat an empty selection like no selection.
-    if (d->m_selection.state() == KHTMLSelection::CARET)
+    if (d->m_selection.state() == Selection::CARET)
         return false;
     if (!xmlDocImpl()->renderer()) {
         return false;
@@ -4501,7 +4501,7 @@ bool KHTMLPart::isPointInsideSelection(int x, int y)
     }
     int ax, ay;
     innerNode->renderer()->absolutePosition(ax, ay);
-    DOMPosition pos(innerNode->positionForCoordinates(ax, ay));
+    Position pos(innerNode->positionForCoordinates(ax, ay));
     if (pos.isEmpty()) {
         return false;
     }
@@ -4538,18 +4538,18 @@ void KHTMLPart::handleMousePressEventDoubleClick(khtml::MousePressEvent *event)
     QMouseEvent *mouse = event->qmouseEvent();
     DOM::Node innerNode = event->innerNode();
 
-    KHTMLSelection selection;
+    Selection selection;
 
     if (mouse->button() == LeftButton && !innerNode.isNull() && innerNode.handle()->renderer()) {
-        DOMPosition pos(innerNode.handle()->positionForCoordinates(event->x(), event->y()));
+        Position pos(innerNode.handle()->positionForCoordinates(event->x(), event->y()));
         if (pos.node() && (pos.node()->nodeType() == Node::TEXT_NODE || pos.node()->nodeType() == Node::CDATA_SECTION_NODE)) {
             selection.moveTo(pos);
-            selection.expandUsingGranularity(KHTMLSelection::WORD);
+            selection.expandUsingGranularity(Selection::WORD);
         }
     }
     
-    if (selection.state() != KHTMLSelection::CARET) {
-        d->m_textElement = KHTMLSelection::WORD;
+    if (selection.state() != Selection::CARET) {
+        d->m_textElement = Selection::WORD;
     }
     
     setSelection(selection);
@@ -4561,18 +4561,18 @@ void KHTMLPart::handleMousePressEventTripleClick(khtml::MousePressEvent *event)
     QMouseEvent *mouse = event->qmouseEvent();
     DOM::Node innerNode = event->innerNode();
     
-    KHTMLSelection selection;
+    Selection selection;
     
     if (mouse->button() == LeftButton && !innerNode.isNull() && innerNode.handle()->renderer()) {
-        DOMPosition pos(innerNode.handle()->positionForCoordinates(event->x(), event->y()));
+        Position pos(innerNode.handle()->positionForCoordinates(event->x(), event->y()));
         if (pos.node() && (pos.node()->nodeType() == Node::TEXT_NODE || pos.node()->nodeType() == Node::CDATA_SECTION_NODE)) {
             selection.moveTo(pos);
-            selection.expandUsingGranularity(KHTMLSelection::LINE);
+            selection.expandUsingGranularity(Selection::LINE);
         }
     }
     
-    if (selection.state() != KHTMLSelection::CARET) {
-        d->m_textElement = KHTMLSelection::LINE;
+    if (selection.state() != Selection::CARET) {
+        d->m_textElement = Selection::LINE;
     }
     
     setSelection(selection);
@@ -4587,7 +4587,7 @@ void KHTMLPart::handleMousePressEventSingleClick(khtml::MousePressEvent *event)
     DOM::Node innerNode = event->innerNode();
     
     if (mouse->button() == LeftButton) {
-        KHTMLSelection selection;
+        Selection selection;
         if (!innerNode.isNull() && innerNode.handle()->renderer()) {
 #if APPLE_CHANGES
             // Don't restart the selection when the mouse is pressed on an
@@ -4596,9 +4596,9 @@ void KHTMLPart::handleMousePressEventSingleClick(khtml::MousePressEvent *event)
                 return;
             }
 #endif
-            DOMPosition pos(innerNode.handle()->positionForCoordinates(event->x(), event->y()));
+            Position pos(innerNode.handle()->positionForCoordinates(event->x(), event->y()));
             if (pos.isEmpty())
-                pos = DOMPosition(innerNode.handle(), innerNode.handle()->caretMinOffset());
+                pos = Position(innerNode.handle(), innerNode.handle()->caretMinOffset());
             selection = pos;
         }
 
@@ -4638,7 +4638,7 @@ void KHTMLPart::khtmlMousePressEvent(khtml::MousePressEvent *event)
         d->m_dragLastPos = mouse->globalPos();
 #else
 #if APPLE_CHANGES
-        d->m_textElement = KHTMLSelection::CHARACTER;
+        d->m_textElement = Selection::CHARACTER;
         d->m_mouseMovedSinceLastMousePress = false;
 
 		if (mouse->clickCount() == 2) {
@@ -4797,7 +4797,7 @@ void KHTMLPart::handleMouseMoveEventSelection(khtml::MouseMoveEvent *event)
     	return;
 
 	// handle making selection
-	DOMPosition pos(innerNode.handle()->positionForCoordinates(event->x(), event->y()));
+	Position pos(innerNode.handle()->positionForCoordinates(event->x(), event->y()));
 
 #if APPLE_CHANGES
 	// Don't modify the selection if we're not on a node.
@@ -4806,7 +4806,7 @@ void KHTMLPart::handleMouseMoveEventSelection(khtml::MouseMoveEvent *event)
 
 	// Restart the selection if this is the first mouse move. This work is usually
 	// done in khtmlMousePressEvent, but not if the mouse press was on an existing selection.
-	KHTMLSelection sel = selection();
+	Selection sel = selection();
     sel.clearModifyBias();
     if (!d->m_mouseMovedSinceLastMousePress) {
 		d->m_mouseMovedSinceLastMousePress = true;
@@ -4817,7 +4817,7 @@ void KHTMLPart::handleMouseMoveEventSelection(khtml::MouseMoveEvent *event)
     sel.setExtent(pos.node(), pos.offset());
 
 #if APPLE_CHANGES
-    if (d->m_textElement != KHTMLSelection::CHARACTER) {
+    if (d->m_textElement != Selection::CHARACTER) {
         sel.expandUsingGranularity(d->m_textElement);
     }
 #endif    
@@ -4882,9 +4882,9 @@ void KHTMLPart::khtmlMouseReleaseEvent( khtml::MouseReleaseEvent *event )
     // However, if we are editing, place the caret.
 	if (d->m_dragStartPos.x() == event->qmouseEvent()->x() &&
 		d->m_dragStartPos.y() == event->qmouseEvent()->y() &&
-		d->m_selection.state() == KHTMLSelection::RANGE &&
-        d->m_textElement == KHTMLSelection::CHARACTER) {
-            KHTMLSelection selection;
+		d->m_selection.state() == Selection::RANGE &&
+        d->m_textElement == Selection::CHARACTER) {
+            Selection selection;
             if (isEditingAtNode(d->m_selection.baseNode()))
                 selection.moveTo(d->m_selection.baseNode()->positionForCoordinates(event->x(), event->y()));
             setSelection(selection);
@@ -5093,7 +5093,7 @@ void KHTMLPart::selectAll()
     return;
   Q_ASSERT(first->renderer());
   Q_ASSERT(last->renderer());
-  KHTMLSelection selection(first, 0, last, last->nodeValue().length());
+  Selection selection(first, 0, last, last->nodeValue().length());
   setSelection(selection);
 }
 
diff --git a/WebCore/khtml/khtml_part.h b/WebCore/khtml/khtml_part.h
index 0173e6a..7b0c935 100644
--- a/WebCore/khtml/khtml_part.h
+++ b/WebCore/khtml/khtml_part.h
@@ -40,7 +40,6 @@
 class KHTMLPartPrivate;
 class KHTMLPartBrowserExtension;
 class KJSProxy;
-class KHTMLSelection;
 class KHTMLView;
 class KHTMLSettings;
 class KJavaAppletContext;
@@ -62,6 +61,7 @@ namespace DOM
   class Node;
   class HTMLEventListener;
   class EventListener;
+  class Selection;
 }
 
 using DOM::TristateFlag;
@@ -572,12 +572,12 @@ public:
   /**
    * Returns the selected part of the HTML.
    */
-  const KHTMLSelection &selection() const;
+  const DOM::Selection &selection() const;
 
   /**
    * Sets the current selection.
    */
-  void setSelection(const KHTMLSelection &);
+  void setSelection(const DOM::Selection &);
 
   /**
    * Sets the current selection, using the given edit command.
@@ -1101,7 +1101,7 @@ private:
   /**
    * @internal
    */
-  void setFocusNodeIfNeeded(const KHTMLSelection &);
+  void setFocusNodeIfNeeded(const DOM::Selection &);
 
   /**
    * @internal
@@ -1210,7 +1210,7 @@ private:
 
   KHTMLPartPrivate *d;
   friend class KHTMLPartPrivate;
-  friend class KHTMLSelection;
+  friend class DOM::Selection;
 
 #if APPLE_CHANGES
 public:  
diff --git a/WebCore/khtml/khtml_selection.cpp b/WebCore/khtml/khtml_selection.cpp
deleted file mode 100644
index 82dc803..0000000
--- a/WebCore/khtml/khtml_selection.cpp
+++ /dev/null
@@ -1,1115 +0,0 @@
-/*
- * Copyright (C) 2003 Apple Computer, Inc.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
- */
-  
-#include "khtml_selection.h"
-
-#include "htmltags.h"
-#include "khtml_part.h"
-#include "khtmlview.h"
-#include "qevent.h"
-#include "qpainter.h"
-#include "qrect.h"
-#include "dom/dom2_range.h"
-#include "dom/dom_node.h"
-#include "dom/dom_position.h"
-#include "dom/dom_string.h"
-#include "rendering/render_object.h"
-#include "rendering/render_style.h"
-#include "rendering/render_text.h"
-#include "xml/dom_docimpl.h"
-#include "xml/dom_edititerator.h"
-#include "xml/dom_elementimpl.h"
-#include "xml/dom_nodeimpl.h"
-#include "xml/dom_textimpl.h"
-
-#if APPLE_CHANGES
-#include <KWQAssertions.h>
-#include <KWQTextUtilities.h>
-#include <CoreServices/CoreServices.h>
-
-#define EDIT_DEBUG 0
-#endif
-
-using DOM::DocumentImpl;
-using DOM::DOMPosition;
-using DOM::DOMString;
-using DOM::EditIterator;
-using DOM::ElementImpl;
-using DOM::Node;
-using DOM::NodeImpl;
-using DOM::Range;
-using DOM::TextImpl;
-using khtml::InlineTextBox;
-using khtml::RenderObject;
-using khtml::RenderText;
-
-#if APPLE_CHANGES
-static bool firstRunAt(RenderObject *renderNode, int y, NodeImpl *&startNode, long &startOffset);
-static bool lastRunAt(RenderObject *renderNode, int y, NodeImpl *&endNode, long &endOffset);
-static bool startAndEndLineNodesIncludingNode(DOM::NodeImpl *node, int offset, KHTMLSelection &selection);
-#endif
-
-
-KHTMLSelection::KHTMLSelection()
-{
-    init();
-}
-
-KHTMLSelection::KHTMLSelection(NodeImpl *node, long offset)
-{
-    init();
-
-	setBaseNode(node);
-	setExtentNode(node);
-	setBaseOffset(offset);
-	setExtentOffset(offset);
-
-    validate();
-}
-
-KHTMLSelection::KHTMLSelection(const DOMPosition &pos)
-{
-    init();
-
-	setBaseNode(pos.node());
-	setExtentNode(pos.node());
-	setBaseOffset(pos.offset());
-	setExtentOffset(pos.offset());
-
-    validate();
-}
-
-KHTMLSelection::KHTMLSelection(const DOMPosition &base, const DOMPosition &extent)
-{
-    init();
-
-	setBaseNode(base.node());
-	setExtentNode(extent.node());
-	setBaseOffset(base.offset());
-	setExtentOffset(extent.offset());
-
-    validate();
-}
-
-KHTMLSelection::KHTMLSelection(NodeImpl *baseNode, long baseOffset, NodeImpl *endNode, long endOffset)
-{
-    init();
-
-	setBaseNode(baseNode);
-	setExtentNode(endNode);
-	setBaseOffset(baseOffset);
-	setExtentOffset(endOffset);
-
-    validate();
-}
-
-KHTMLSelection::KHTMLSelection(const KHTMLSelection &o)
-{
-    init();
-    
-	setBaseNode(o.baseNode());
-	setExtentNode(o.extentNode());
-	setBaseOffset(o.baseOffset());
-	setExtentOffset(o.extentOffset());
-
-	setStartNode(o.startNode());
-	setEndNode(o.endNode());
-	setStartOffset(o.startOffset());
-	setEndOffset(o.endOffset());
-
-    m_state = o.m_state;
-
-    m_baseIsStart = o.m_baseIsStart;
-    m_needsCaretLayout = o.m_needsCaretLayout;
-    m_modifyBiasSet = o.m_modifyBiasSet;
-    
-    // Only copy the coordinates over if the other object
-    // has had a layout, otherwise keep the current
-    // coordinates. This prevents drawing artifacts from
-    // remaining when the caret is painted and then moves,
-    // and the old rectangle needs to be repainted.
-    if (!m_needsCaretLayout) {
-        m_caretX = o.m_caretX;
-        m_caretY = o.m_caretY;
-        m_caretSize = o.m_caretSize;
-    }
-}
-
-void KHTMLSelection::init()
-{
-    m_baseNode = 0;
-    m_baseOffset = 0;
-    m_extentNode = 0; 
-    m_extentOffset = 0;
-    m_startNode = 0;
-    m_startOffset = 0;
-    m_endNode = 0;
-    m_endOffset = 0;
-    m_state = NONE; 
-    m_caretX = 0;
-    m_caretY = 0;
-    m_caretSize = 0;
-    m_baseIsStart = true;
-    m_needsCaretLayout = true;
-    m_modifyBiasSet = false;
-}
-
-KHTMLSelection::~KHTMLSelection()
-{
-    if (m_baseNode)
-        m_baseNode->deref();
-    if (m_extentNode)
-        m_extentNode->deref();
-    if (m_startNode)
-        m_startNode->deref();
-    if (m_endNode)
-        m_endNode->deref();
-}
-
-KHTMLSelection &KHTMLSelection::operator=(const KHTMLSelection &o)
-{
-	setBaseNode(o.baseNode());
-	setExtentNode(o.extentNode());
-	setBaseOffset(o.baseOffset());
-	setExtentOffset(o.extentOffset());
-
-	setStartNode(o.startNode());
-	setEndNode(o.endNode());
-	setStartOffset(o.startOffset());
-	setEndOffset(o.endOffset());
-
-    m_state = o.m_state;
-
-    m_baseIsStart = o.m_baseIsStart;
-    m_needsCaretLayout = o.m_needsCaretLayout;
-    m_modifyBiasSet = o.m_modifyBiasSet;
-    
-    // Only copy the coordinates over if the other object
-    // has had a layout, otherwise keep the current
-    // coordinates. This prevents drawing artifacts from
-    // remaining when the caret is painted and then moves,
-    // and the old rectangle needs to be repainted.
-    if (!m_needsCaretLayout) {
-        m_caretX = o.m_caretX;
-        m_caretY = o.m_caretY;
-        m_caretSize = o.m_caretSize;
-    }
-    
-    return *this;
-}
-
-void KHTMLSelection::moveTo(DOM::NodeImpl *node, long offset)
-{
-    moveTo(node, offset, node, offset);
-}
-
-void KHTMLSelection::moveTo(const DOM::Range &r)
-{
-	moveTo(r.startContainer().handle(), r.startOffset(), 
-		r.endContainer().handle(), r.endOffset());
-}
-
-void KHTMLSelection::moveTo(const DOM::DOMPosition &pos)
-{
-	moveTo(pos.node(), pos.offset());
-}
-
-void KHTMLSelection::moveTo(const KHTMLSelection &o)
-{
-	moveTo(o.baseNode(), o.baseOffset(), o.extentNode(), o.extentOffset());
-}
-
-void KHTMLSelection::moveTo(DOM::NodeImpl *baseNode, long baseOffset, DOM::NodeImpl *extentNode, long extentOffset)
-{
-	setBaseNode(baseNode);
-	setExtentNode(extentNode);
-	setBaseOffset(baseOffset);
-	setExtentOffset(extentOffset);
-	validate();
-}
-
-bool KHTMLSelection::modify(EAlter alter, EDirection dir, ETextGranularity granularity)
-{
-    DOMPosition pos;
-    
-    switch (dir) {
-        // EDIT FIXME: This needs to handle bidi
-        case RIGHT:
-        case FORWARD:
-            if (alter == EXTEND) {
-                if (!m_modifyBiasSet) {
-                    m_modifyBiasSet = true;
-                    setBaseNode(startNode());
-                    setBaseOffset(startOffset());
-                    setExtentNode(endNode());
-                    setExtentOffset(endOffset());
-                }
-                if (granularity == CHARACTER)
-                    pos = extentPosition().nextCharacterPosition();
-                else if (granularity == WORD)
-                    pos = extentPosition().nextWordPosition();
-            }
-            else {
-                m_modifyBiasSet = false;
-                if (state() == RANGE) {
-                    if (granularity == CHARACTER)
-                        pos = endPosition();
-                    else if (granularity == WORD)
-                        pos = extentPosition().nextWordPosition();
-                }
-                else {
-                    if (granularity == CHARACTER)
-                        pos = extentPosition().nextCharacterPosition();
-                    else if (granularity == WORD)
-                        pos = extentPosition().nextWordPosition();
-                }
-            }
-            break;
-        // EDIT FIXME: This needs to handle bidi
-        case LEFT:
-        case BACKWARD:
-            if (alter == EXTEND) {
-                if (!m_modifyBiasSet) {
-                    m_modifyBiasSet = true;
-                    setBaseNode(endNode());
-                    setBaseOffset(endOffset());
-                    setExtentNode(startNode());
-                    setExtentOffset(startOffset());
-                }
-                if (granularity == CHARACTER)
-                    pos = extentPosition().previousCharacterPosition();
-                else if (granularity == WORD)
-                    pos = extentPosition().previousWordPosition();
-            }
-            else {
-                m_modifyBiasSet = false;
-                if (state() == RANGE) {
-                    if (granularity == CHARACTER)
-                        pos = startPosition();
-                    else if (granularity == WORD)
-                        pos = extentPosition().previousWordPosition();
-                }
-                else {
-                    if (granularity == CHARACTER)
-                        pos = extentPosition().previousCharacterPosition();
-                    else if (granularity == WORD)
-                        pos = extentPosition().previousWordPosition();
-                }
-            }
-            break;
-        case UP:
-            if (alter == EXTEND) {
-                if (!m_modifyBiasSet) {
-                    m_modifyBiasSet = true;
-                    setBaseNode(endNode());
-                    setBaseOffset(endOffset());
-                    setExtentNode(startNode());
-                    setExtentOffset(startOffset());
-                }
-                pos = extentPosition().previousLinePosition(xPosForVerticalArrowNavigation(EXTENT));
-            }
-            else {
-                m_modifyBiasSet = false;
-                pos = startPosition().previousLinePosition(xPosForVerticalArrowNavigation(START, state()==RANGE));
-            }
-            break;
-        case DOWN:
-            if (alter == EXTEND) {
-                if (!m_modifyBiasSet) {
-                    m_modifyBiasSet = true;
-                    setBaseNode(startNode());
-                    setBaseOffset(startOffset());
-                    setExtentNode(endNode());
-                    setExtentOffset(endOffset());
-                }
-                pos = extentPosition().nextLinePosition(xPosForVerticalArrowNavigation(EXTENT));
-            }
-            else {
-                m_modifyBiasSet = false;
-                pos = endPosition().nextLinePosition(xPosForVerticalArrowNavigation(END, state()==RANGE));
-            }
-            break;
-    }
-    
-    if (pos.isEmpty())
-        return false;
-    
-    if (alter == MOVE)
-        moveTo(pos.node(), pos.offset());
-    else // alter == EXTEND
-        setExtent(pos.node(), pos.offset());
-    
-    return true;
-}
-
-bool KHTMLSelection::expandUsingGranularity(ETextGranularity granularity)
-{
-    if (state() == NONE)
-        return false;
-        
-    validate(granularity);
-    return true;
-}
-
-int KHTMLSelection::xPosForVerticalArrowNavigation(EPositionType type, bool recalc) const
-{
-    int x = 0;
-
-    if (state() == NONE)
-        return x;
-
-    DOMPosition pos;
-    switch (type) {
-        case START:
-            pos = startPosition();
-            break;
-        case END:
-            pos = endPosition();
-            break;
-        case BASE:
-            pos = basePosition();
-            break;
-        case EXTENT:
-            pos = extentPosition();
-            break;
-    }
-
-    KHTMLPart *part = pos.node()->getDocument()->part();
-    if (!part)
-        return x;
-        
-    if (recalc || part->xPosForVerticalArrowNavigation() == KHTMLPart::NoXPosForVerticalArrowNavigation) {
-        int y, w, h;
-        pos.node()->renderer()->caretPos(pos.offset(), true, x, y, w, h);
-        part->setXPosForVerticalArrowNavigation(x);
-    }
-    else {
-        x = part->xPosForVerticalArrowNavigation();
-    }
-
-    return x;
-}
-
-void KHTMLSelection::clear()
-{
-	setBaseNode(0);
-	setExtentNode(0);
-	setBaseOffset(0);
-	setExtentOffset(0);
-	validate();
-}
-
-void KHTMLSelection::setBase(DOM::NodeImpl *node, long offset)
-{
-	setBaseNode(node);
-	setBaseOffset(offset);
-	validate();
-}
-
-void KHTMLSelection::setExtent(DOM::NodeImpl *node, long offset)
-{
-	setExtentNode(node);
-	setExtentOffset(offset);
-	validate();
-}
-
-void KHTMLSelection::setNeedsLayout(bool flag)
-{
-    m_needsCaretLayout = flag;
-}
-
-Range KHTMLSelection::toRange() const
-{
-    if (isEmpty())
-        return Range();
-
-    return Range(Node(startNode()), startOffset(), Node(endNode()), endOffset());
-}
-
-void KHTMLSelection::layoutCaret()
-{
-    if (isEmpty() || !startNode()->renderer()) {
-        m_caretX = m_caretY = m_caretSize = 0;
-    }
-    else {
-        int w;
-        startNode()->renderer()->caretPos(startOffset(), true, m_caretX, m_caretY, w, m_caretSize);
-    }
-
-    m_needsCaretLayout = false;
-}
-
-QRect KHTMLSelection::getRepaintRect()
-{
-    // EDIT FIXME: fudge a bit to make sure we don't leave behind artifacts
-    return QRect(m_caretX - 1, m_caretY - 1, 3, m_caretSize + 2);
-}
-
-void KHTMLSelection::needsCaretRepaint()
-{
-    if (isEmpty())
-        return;
-
-    if (!startNode()->getDocument())
-        return;
-
-    KHTMLView *v = startNode()->getDocument()->view();
-    if (!v)
-        return;
-
-    if (m_needsCaretLayout) {
-        // repaint old position and calculate new position
-        v->updateContents(getRepaintRect(), false);
-        layoutCaret();
-        
-        // EDIT FIXME: This is an unfortunate hack.
-        // Basically, we can't trust this layout position since we 
-        // can't guarantee that the check to see if we are in unrendered 
-        // content will work at this point. We may have to wait for
-        // a layout and re-render of the document to happen. So, resetting this
-        // flag will cause another caret layout to happen the first time
-        // that we try to paint the caret after this call. That one will work since
-        // it happens after the document has accounted for any editing
-        // changes which may have been done.
-        // And, we need to leave this layout here so the caret moves right 
-        // away after clicking.
-        m_needsCaretLayout = true;
-    }
-    v->updateContents(getRepaintRect(), false);
-}
-
-void KHTMLSelection::paintCaret(QPainter *p, const QRect &rect)
-{
-    if (isEmpty())
-        return;
-
-    if (m_state != CARET)
-        return;
-
-    if (m_needsCaretLayout) {
-        DOMPosition pos = DOMPosition(startNode(), startOffset());
-        if (!pos.inRenderedContent()) {
-            moveToRenderedContent();
-        }
-        layoutCaret();
-    }
-
-    QRect caretRect(m_caretX, m_caretY, 1, m_caretSize);
-    if (caretRect.intersects(rect)) {
-        QPen pen = p->pen();
-        pen.setStyle(Qt::SolidLine);
-        pen.setColor(Qt::black);
-        pen.setWidth(1);
-        p->setPen(pen);
-        p->drawLine(caretRect.left(), caretRect.top(), caretRect.left(), caretRect.bottom());
-    }
-}
-
-void KHTMLSelection::setBaseNode(DOM::NodeImpl *node)
-{
-	if (m_baseNode == node)
-		return;
-
-	if (m_baseNode)
-		m_baseNode->deref();
-	
-	m_baseNode = node;
-	
-	if (m_baseNode)
-		m_baseNode->ref();
-}
-
-void KHTMLSelection::setBaseOffset(long offset)
-{
-	m_baseOffset = offset;
-}
-
-void KHTMLSelection::setExtentNode(DOM::NodeImpl *node)
-{
-	if (m_extentNode == node)
-		return;
-
-	if (m_extentNode)
-		m_extentNode->deref();
-	
-	m_extentNode = node;
-	
-	if (m_extentNode)
-		m_extentNode->ref();
-}
-	
-void KHTMLSelection::setExtentOffset(long offset)
-{
-	m_extentOffset = offset;
-}
-
-void KHTMLSelection::setStartNode(DOM::NodeImpl *node)
-{
-	if (m_startNode == node)
-		return;
-
-	if (m_startNode)
-		m_startNode->deref();
-	
-	m_startNode = node;
-	
-	if (m_startNode)
-		m_startNode->ref();
-}
-
-void KHTMLSelection::setStartOffset(long offset)
-{
-	m_startOffset = offset;
-}
-
-void KHTMLSelection::setEndNode(DOM::NodeImpl *node)
-{
-	if (m_endNode == node)
-		return;
-
-	if (m_endNode)
-		m_endNode->deref();
-	
-	m_endNode = node;
-	
-	if (m_endNode)
-		m_endNode->ref();
-}
-	
-void KHTMLSelection::setEndOffset(long offset)
-{
-	m_endOffset = offset;
-}
-
-void KHTMLSelection::validate(ETextGranularity granularity)
-{
-    // move the base and extent nodes to their equivalent leaf positions
-    bool baseAndExtentEqual = m_baseNode == m_extentNode && m_baseOffset == m_extentOffset;
-    if (m_baseNode) {
-        DOMPosition pos = basePosition().equivalentLeafPosition();
-        m_baseNode = pos.node();
-        m_baseOffset = pos.offset();
-        if (baseAndExtentEqual) {
-            m_extentNode = pos.node();
-            m_extentOffset = pos.offset();
-        }
-    }
-    if (m_extentNode && !baseAndExtentEqual) {
-        DOMPosition pos = extentPosition().equivalentLeafPosition();
-        m_extentNode = pos.node();
-        m_extentOffset = pos.offset();
-    }
-
-    // make sure we do not have a dangling start or end
-	if (!m_baseNode && !m_extentNode) {
-        setBaseOffset(0);
-        setExtentOffset(0);
-        m_baseIsStart = true;
-    }
-	else if (!m_baseNode) {
-		setBaseNode(m_extentNode);
-		setBaseOffset(m_extentOffset);
-        m_baseIsStart = true;
-	}
-	else if (!m_extentNode) {
-		setExtentNode(m_baseNode);
-		setExtentOffset(m_baseOffset);
-        m_baseIsStart = true;
-	}
-    else {
-        // adjust m_baseIsStart as needed
-        if (m_baseNode == m_extentNode) {
-            if (m_baseOffset > m_extentOffset)
-                m_baseIsStart = false;
-            else 
-                m_baseIsStart = true;
-        }
-        else if (nodeIsBeforeNode(m_baseNode, m_extentNode))
-            m_baseIsStart = true;
-        else
-            m_baseIsStart = false;
-    }
-
-    // calculate the correct start and end positions
-#if !APPLE_CHANGES
-    if (m_baseIsStart) {
-        setStartNode(m_baseNode);
-        setStartOffset(m_baseOffset);
-        setEndNode(m_extentNode);
-        setEndOffset(m_extentOffset);
-    }
-    else {
-        setStartNode(m_extentNode);
-        setStartOffset(m_extentOffset);
-        setEndNode(m_baseNode);
-        setEndOffset(m_baseOffset);
-    }
-#else
-    if (granularity == CHARACTER) {
-        if (m_baseIsStart) {
-            setStartNode(m_baseNode);
-            setStartOffset(m_baseOffset);
-            setEndNode(m_extentNode);
-            setEndOffset(m_extentOffset);
-        }
-        else {
-            setStartNode(m_extentNode);
-            setStartOffset(m_extentOffset);
-            setEndNode(m_baseNode);
-            setEndOffset(m_baseOffset);
-        }
-    }
-    else if (granularity == WORD) {
-        int baseStartOffset = m_baseOffset;
-        int baseEndOffset = m_baseOffset;
-        int extentStartOffset = m_extentOffset;
-        int extentEndOffset = m_extentOffset;
-        if (m_baseNode && (m_baseNode->nodeType() == Node::TEXT_NODE || m_baseNode->nodeType() == Node::CDATA_SECTION_NODE)) {
-            DOMString t = m_baseNode->nodeValue();
-            QChar *chars = t.unicode();
-            uint len = t.length();
-            KWQFindWordBoundary(chars, len, m_baseOffset, &baseStartOffset, &baseEndOffset);
-        }
-        if (m_extentNode && (m_extentNode->nodeType() == Node::TEXT_NODE || m_extentNode->nodeType() == Node::CDATA_SECTION_NODE)) {
-            DOMString t = m_extentNode->nodeValue();
-            QChar *chars = t.unicode();
-            uint len = t.length();
-            KWQFindWordBoundary(chars, len, m_extentOffset, &extentStartOffset, &extentEndOffset);
-        }
-        if (m_baseIsStart) {
-            setStartNode(m_baseNode);
-            setStartOffset(baseStartOffset);
-            setEndNode(m_extentNode);
-            setEndOffset(extentEndOffset);
-        }
-        else {
-            setStartNode(m_extentNode);
-            setStartOffset(extentStartOffset);
-            setEndNode(m_baseNode);
-            setEndOffset(baseEndOffset);
-        }
-    }
-    else {  // granularity == LINE
-        KHTMLSelection baseSelection = *this;
-        KHTMLSelection extentSelection = *this;
-        if (m_baseNode && (m_baseNode->nodeType() == Node::TEXT_NODE || m_baseNode->nodeType() == Node::CDATA_SECTION_NODE)) {
-            if (startAndEndLineNodesIncludingNode(m_baseNode, m_baseOffset, baseSelection)) {
-                setStartNode(baseSelection.baseNode());
-                setStartOffset(baseSelection.baseOffset());
-                setEndNode(baseSelection.extentNode());
-                setEndOffset(baseSelection.extentOffset());
-            }
-        }
-        if (m_extentNode && (m_extentNode->nodeType() == Node::TEXT_NODE || m_extentNode->nodeType() == Node::CDATA_SECTION_NODE)) {
-            if (startAndEndLineNodesIncludingNode(m_extentNode, m_extentOffset, extentSelection)) {
-                setStartNode(extentSelection.baseNode());
-                setStartOffset(extentSelection.baseOffset());
-                setEndNode(extentSelection.extentNode());
-                setEndOffset(extentSelection.extentOffset());
-            }
-        }
-        if (m_baseIsStart) {
-            setStartNode(baseSelection.startNode());
-            setStartOffset(baseSelection.startOffset());
-            setEndNode(extentSelection.endNode());
-            setEndOffset(extentSelection.endOffset());
-        }
-        else {
-            setStartNode(extentSelection.startNode());
-            setStartOffset(extentSelection.startOffset());
-            setEndNode(baseSelection.endNode());
-            setEndOffset(baseSelection.endOffset());
-        }
-    }
-#endif  // APPLE_CHANGES
-
-	// adjust the state
-	if (!m_startNode && !m_endNode)
-		m_state = NONE;
-	else if (m_startNode == m_endNode && m_startOffset == m_endOffset)
-		m_state = CARET;
-	else
-		m_state = RANGE;
-
-    m_needsCaretLayout = true;
-    
-#if EDIT_DEBUG
-    debugPosition();
-#endif
-}
-
-bool KHTMLSelection::moveToRenderedContent()
-{
-    if (isEmpty())
-        return false;
-        
-    if (m_state != CARET)
-        return false;
-
-    DOMPosition pos = DOMPosition(startNode(), startOffset());
-    if (pos.inRenderedContent())
-        return true;
-        
-    // not currently rendered, try moving to prev
-    DOMPosition prev = pos.previousCharacterPosition();
-    if (prev != pos && prev.node()->inSameContainingEditableBlock(pos.node())) {
-        moveTo(prev);
-        return true;
-    }
-
-    // could not be moved to prev, try next
-    DOMPosition next = pos.nextCharacterPosition();
-    if (next != pos && next.node()->inSameContainingEditableBlock(pos.node())) {
-        moveTo(next);
-        return true;
-    }
-    
-    return false;
-}
-
-DOMPosition KHTMLSelection::basePosition() const
-{
-    return DOMPosition(baseNode(), baseOffset());
-}
-
-DOMPosition KHTMLSelection::extentPosition() const
-{
-    return DOMPosition(extentNode(), extentOffset());
-}
-
-DOMPosition KHTMLSelection::startPosition() const
-{
-    return DOMPosition(startNode(), startOffset());
-}
-
-DOMPosition KHTMLSelection::endPosition() const
-{
-    return DOMPosition(endNode(), endOffset());
-}
-
-bool KHTMLSelection::nodeIsBeforeNode(NodeImpl *n1, NodeImpl *n2) 
-{
-	if (!n1 || !n2) 
-		return true;
- 
- 	if (n1 == n2)
- 		return true;
- 
- 	bool result = false;
-    int n1Depth = 0;
-    int n2Depth = 0;
-
-    // First we find the depths of the two nodes in the tree (n1Depth, n2Depth)
-    DOM::NodeImpl *n = n1;
-    while (n->parentNode()) {
-        n = n->parentNode();
-        n1Depth++;
-    }
-    n = n2;
-    while (n->parentNode()) {
-        n = n->parentNode();
-        n2Depth++;
-    }
-    // Climb up the tree with the deeper node, until both nodes have equal depth
-    while (n2Depth > n1Depth) {
-        n2 = n2->parentNode();
-        n2Depth--;
-    }
-    while (n1Depth > n2Depth) {
-        n1 = n1->parentNode();
-        n1Depth--;
-    }
-    // Climb the tree with both n1 and n2 until they have the same parent
-    while (n1->parentNode() != n2->parentNode()) {
-        n1 = n1->parentNode();
-        n2 = n2->parentNode();
-    }
-    // Iterate through the parent's children until n1 or n2 is found
-    n = n1->parentNode() ? n1->parentNode()->firstChild() : n1->firstChild();
-    while (n) {
-        if (n == n1) {
-            result = true;
-            break;
-        }
-        else if (n == n2) {
-            result = false;
-            break;
-        }
-        n = n->nextSibling();
-    }
-	return result;
-}
-
-#if APPLE_CHANGES
-
-static bool firstRunAt(RenderObject *renderNode, int y, NodeImpl *&startNode, long &startOffset)
-{
-    for (RenderObject *n = renderNode; n; n = n->nextSibling()) {
-        if (n->isText()) {
-            RenderText *textRenderer = static_cast<khtml::RenderText *>(n);
-            for (InlineTextBox* box = textRenderer->firstTextBox(); box; box = box->nextTextBox()) {
-                if (box->m_y == y) {
-                    startNode = textRenderer->element();
-                    startOffset = box->m_start;
-                    return true;
-                }
-            }
-        }
-        
-        if (firstRunAt(n->firstChild(), y, startNode, startOffset)) {
-            return true;
-        }
-    }
-    
-    return false;
-}
-
-static bool lastRunAt(RenderObject *renderNode, int y, NodeImpl *&endNode, long &endOffset)
-{
-    RenderObject *n = renderNode;
-    if (!n) {
-        return false;
-    }
-    RenderObject *next;
-    while ((next = n->nextSibling())) {
-        n = next;
-    }
-    
-    while (1) {
-        if (lastRunAt(n->firstChild(), y, endNode, endOffset)) {
-            return true;
-        }
-    
-        if (n->isText()) {
-            RenderText *textRenderer =  static_cast<khtml::RenderText *>(n);
-            for (InlineTextBox* box = textRenderer->lastTextBox(); box; box = box->prevTextBox()) {
-                if (box->m_y == y) {
-                    endNode = textRenderer->element();
-                    endOffset = box->m_start + box->m_len;
-                    return true;
-                }
-            }
-        }
-        
-        if (n == renderNode) {
-            return false;
-        }
-        
-        n = n->previousSibling();
-    }
-}
-
-static bool startAndEndLineNodesIncludingNode(DOM::NodeImpl *node, int offset, KHTMLSelection &selection)
-{
-    if (node && (node->nodeType() == Node::TEXT_NODE || node->nodeType() == Node::CDATA_SECTION_NODE)) {
-        int pos;
-        int selectionPointY;
-        RenderText *renderer = static_cast<RenderText *>(node->renderer());
-        InlineTextBox * run = renderer->findNextInlineTextBox( offset, pos );
-        DOMString t = node->nodeValue();
-        
-        if (!run)
-            return false;
-            
-        selectionPointY = run->m_y;
-        
-        // Go up to first non-inline element.
-        khtml::RenderObject *renderNode = renderer;
-        while (renderNode && renderNode->isInline())
-            renderNode = renderNode->parent();
-        
-        renderNode = renderNode->firstChild();
-        
-        DOM::NodeImpl *startNode = 0;
-        DOM::NodeImpl *endNode = 0;
-        long startOffset;
-        long endOffset;
-        
-        // Look for all the first child in the block that is on the same line
-        // as the selection point.
-        if (!firstRunAt (renderNode, selectionPointY, startNode, startOffset))
-            return false;
-    
-        // Look for all the last child in the block that is on the same line
-        // as the selection point.
-        if (!lastRunAt (renderNode, selectionPointY, endNode, endOffset))
-            return false;
-        
-        selection.moveTo(startNode, startOffset, endNode, endOffset);
-        
-        return true;
-    }
-    return false;
-}
-
-void KHTMLSelection::debugRenderer(RenderObject *r, bool selected) const
-{
-    if (r->node()->isElementNode()) {
-        ElementImpl *element = static_cast<ElementImpl *>(r->node());
-        fprintf(stderr, "%s%s\n", selected ? "==> " : "    ", element->tagName().string().latin1());
-    }
-    else if (r->isText()) {
-        RenderText *textRenderer = static_cast<RenderText *>(r);
-        if (textRenderer->stringLength() == 0 || !textRenderer->firstTextBox()) {
-            fprintf(stderr, "%s#text (empty)\n", selected ? "==> " : "    ");
-            return;
-        }
-        
-        static const int max = 36;
-        QString text = DOMString(textRenderer->string()).string();
-        int textLength = text.length();
-        if (selected) {
-            int offset = 0;
-            if (r->node() == startNode())
-                offset = startOffset();
-            else if (r->node() == endNode())
-                offset = endOffset();
-                
-            int pos;
-            InlineTextBox *box = textRenderer->findNextInlineTextBox(offset, pos);
-            text = text.mid(box->m_start, box->m_len);
-            
-            QString show;
-            int mid = max / 2;
-            int caret = 0;
-            
-            // text is shorter than max
-            if (textLength < max) {
-                show = text;
-                caret = pos;
-            }
-            
-            // too few characters to left
-            else if (pos - mid < 0) {
-                show = text.left(max - 3) + "...";
-                caret = pos;
-            }
-            
-            // enough characters on each side
-            else if (pos - mid >= 0 && pos + mid <= textLength) {
-                show = "..." + text.mid(pos - mid + 3, max - 6) + "...";
-                caret = mid;
-            }
-            
-            // too few characters on right
-            else {
-                show = "..." + text.right(max - 3);
-                caret = pos - (textLength - show.length());
-            }
-            
-            show = show.replace("\n", " ");
-            show = show.replace("\r", " ");
-            fprintf(stderr, "==> #text : \"%s\" at offset %d\n", show.latin1(), pos);
-            fprintf(stderr, "           ");
-            for (int i = 0; i < caret; i++)
-                fprintf(stderr, " ");
-            fprintf(stderr, "^\n");
-        }
-        else {
-            if ((int)text.length() > max)
-                text = text.left(max - 3) + "...";
-            else
-                text = text.left(max);
-            fprintf(stderr, "    #text : \"%s\"\n", text.latin1());
-        }
-    }
-}
-
-void KHTMLSelection::debugPosition() const
-{
-    if (!startNode())
-        return;
-
-    //static int context = 5;
-    
-    //RenderObject *r = 0;
-
-    fprintf(stderr, "KHTMLSelection =================\n");
-
-    if (startPosition() == endPosition()) {
-        DOMPosition pos = startPosition();
-        DOMPosition upstream = pos.equivalentUpstreamPosition();
-        DOMPosition downstream = pos.equivalentDownstreamPosition();
-        fprintf(stderr, "upstream:   %s %p:%d\n", getTagName(upstream.node()->id()).string().latin1(), upstream.node(), upstream.offset());
-        fprintf(stderr, "pos:        %s %p:%d\n", getTagName(pos.node()->id()).string().latin1(), pos.node(), pos.offset());
-        fprintf(stderr, "downstream: %s %p:%d\n", getTagName(downstream.node()->id()).string().latin1(), downstream.node(), downstream.offset());
-    }
-    else {
-        DOMPosition pos = startPosition();
-        DOMPosition upstream = pos.equivalentUpstreamPosition();
-        DOMPosition downstream = pos.equivalentDownstreamPosition();
-        fprintf(stderr, "upstream:   %s %p:%d\n", getTagName(upstream.node()->id()).string().latin1(), upstream.node(), upstream.offset());
-        fprintf(stderr, "start:      %s %p:%d\n", getTagName(pos.node()->id()).string().latin1(), pos.node(), pos.offset());
-        fprintf(stderr, "downstream: %s %p:%d\n", getTagName(downstream.node()->id()).string().latin1(), downstream.node(), downstream.offset());
-        fprintf(stderr, "-----------------------------------\n");
-        pos = endPosition();
-        upstream = pos.equivalentUpstreamPosition();
-        downstream = pos.equivalentDownstreamPosition();
-        fprintf(stderr, "upstream:   %s %p:%d\n", getTagName(upstream.node()->id()).string().latin1(), upstream.node(), upstream.offset());
-        fprintf(stderr, "end:        %s %p:%d\n", getTagName(pos.node()->id()).string().latin1(), pos.node(), pos.offset());
-        fprintf(stderr, "downstream: %s %p:%d\n", getTagName(downstream.node()->id()).string().latin1(), downstream.node(), downstream.offset());
-        fprintf(stderr, "-----------------------------------\n");
-    }
-          
-#if 0
-    int back = 0;
-    r = startNode()->renderer();
-    for (int i = 0; i < context; i++, back++) {
-        if (r->previousRenderer())
-            r = r->previousRenderer();
-        else
-            break;
-    }
-    for (int i = 0; i < back; i++) {
-        debugRenderer(r, false);
-        r = r->nextRenderer();
-    }
-
-
-    fprintf(stderr, "\n");
-
-    if (startNode() == endNode())
-        debugRenderer(startNode()->renderer(), true);
-    else
-        for (r = startNode()->renderer(); r && r != endNode()->renderer(); r = r->nextRenderer())
-            debugRenderer(r, true);
-    
-    fprintf(stderr, "\n");
-    
-    r = endNode()->renderer();
-    for (int i = 0; i < context; i++) {
-        if (r->nextRenderer()) {
-            r = r->nextRenderer();
-            debugRenderer(r, false);
-        }
-        else
-            break;
-    }
-#endif
-
-    fprintf(stderr, "================================\n");
-}
-
-#endif
diff --git a/WebCore/khtml/khtml_selection.h b/WebCore/khtml/khtml_selection.h
deleted file mode 100644
index 326a0ea..0000000
--- a/WebCore/khtml/khtml_selection.h
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * Copyright (C) 2003 Apple Computer, Inc.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
- */
-
-#ifndef __khtml_selection_h__
-#define __khtml_selection_h__
-
-class KHTMLPart;
-class QPainter;
-class QRect;
-
-namespace DOM {
-    class DOMPosition;
-    class NodeImpl;
-    class Range;
-};
-
-namespace khtml {
-    class RenderObject;
-}
-
-class KHTMLSelection
-{
-public:
-    KHTMLSelection();
-    KHTMLSelection(DOM::NodeImpl *node, long offset);
-    KHTMLSelection(const DOM::DOMPosition &);
-    KHTMLSelection(const DOM::DOMPosition &, const DOM::DOMPosition &);
-    KHTMLSelection(DOM::NodeImpl *startNode, long startOffset, DOM::NodeImpl *endNode, long endOffset);
-    KHTMLSelection(const KHTMLSelection &);
-    ~KHTMLSelection();
-
-	enum EState { NONE, CARET, RANGE };
-	enum EAlter { MOVE, EXTEND };
-	enum EDirection { FORWARD, BACKWARD, RIGHT, LEFT, UP, DOWN };
-	enum ETextGranularity { CHARACTER, WORD, LINE };
-
-	EState state() const { return m_state; }
-
-    void moveTo(DOM::NodeImpl *node, long offset);
-    void moveTo(const DOM::Range &);
-    void moveTo(const DOM::DOMPosition &);
-    void moveTo(const KHTMLSelection &);
-    void moveTo(DOM::NodeImpl *baseNode, long baseOffset, DOM::NodeImpl *extentNode, long extentOffset);
-    bool modify(EAlter, EDirection, ETextGranularity);
-    bool expandUsingGranularity(ETextGranularity);
-    void clear();
-
-    bool moveToRenderedContent();
-    
-    void setBase(DOM::NodeImpl *node, long offset);
-    void setExtent(DOM::NodeImpl *node, long offset);
-
-    DOM::NodeImpl *baseNode() const { return m_baseNode; }
-    long baseOffset() const { return m_baseOffset; }
-
-    DOM::NodeImpl *extentNode() const { return m_extentNode; }
-    long extentOffset() const { return m_extentOffset; }
-
-    DOM::NodeImpl *startNode() const { return m_startNode; }
-    long startOffset() const { return m_startOffset; }
-
-    DOM::NodeImpl *endNode() const { return m_endNode; }
-    long endOffset() const { return m_endOffset; }
-
-    DOM::DOMPosition basePosition() const;
-    DOM::DOMPosition extentPosition() const;
-    DOM::DOMPosition startPosition() const;
-    DOM::DOMPosition endPosition() const;
-
-    void setNeedsLayout(bool flag=true);
-    void clearModifyBias() { m_modifyBiasSet = false; }
-    
-    bool isEmpty() const { return state() == NONE; }
-    bool notEmpty() const { return !isEmpty(); }
-    DOM::Range toRange() const;
-
-    
-    void debugPosition() const;
-    void debugRenderer(khtml::RenderObject *r, bool selected) const;
-
-    KHTMLSelection &operator=(const KHTMLSelection &o);
-    
-    friend bool operator==(const KHTMLSelection &a, const KHTMLSelection &b);
-    friend bool operator!=(const KHTMLSelection &a, const KHTMLSelection &b);
-    
-    friend class KHTMLPart;
-
-private:
-	enum EPositionType { START, END, BASE, EXTENT };
-
-    void init();
-    void validate(ETextGranularity granularity=CHARACTER);
-
-    void layoutCaret();
-    void needsCaretRepaint();
-    QRect getRepaintRect();
-    void paintCaret(QPainter *p, const QRect &rect);
-
-	void setBaseNode(DOM::NodeImpl *);
-	void setBaseOffset(long);
-	void setExtentNode(DOM::NodeImpl *);
-	void setExtentOffset(long);
-
-	void setStartNode(DOM::NodeImpl *);
-	void setStartOffset(long);
-	void setEndNode(DOM::NodeImpl *);
-	void setEndOffset(long);
-
-    bool nodeIsBeforeNode(DOM::NodeImpl *n1, DOM::NodeImpl *n2);
-
-    void calculateStartAndEnd(ETextGranularity select=CHARACTER);
-    int xPosForVerticalArrowNavigation(EPositionType, bool recalc=false) const;
-    
-    DOM::NodeImpl *m_baseNode;    // base node for the selection
-    long m_baseOffset;            // offset into base node where selection is
-    DOM::NodeImpl *m_extentNode;  // extent node for the selection
-    long m_extentOffset;          // offset into extent node where selection is
-
-    DOM::NodeImpl *m_startNode;   // start node for the selection (read-only)
-    long m_startOffset;           // offset into start node where selection is (read-only)
-    DOM::NodeImpl *m_endNode;     // end node for the selection (read-only)
-    long m_endOffset;             // offset into end node where selection is (read-only)
-
-	EState m_state;               // the state of the selection
-
-	int m_caretX;
-	int m_caretY;
-	int m_caretSize;
-
-	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
-	bool m_modifyBiasSet : 1;     // true if the selection has been modified with EAlter::EXTEND
-};
-
-
-inline bool operator==(const KHTMLSelection &a, const KHTMLSelection &b)
-{
-    return a.startNode() == b.startNode() && a.startOffset() == b.startOffset() &&
-        a.endNode() == b.endNode() && a.endOffset() == b.endOffset();
-}
-
-inline bool operator!=(const KHTMLSelection &a, const KHTMLSelection &b)
-{
-    return !(a == b);
-}
-
-#endif
\ No newline at end of file
diff --git a/WebCore/khtml/khtmlpart_p.h b/WebCore/khtml/khtmlpart_p.h
index 8d11d37..5407e85 100644
--- a/WebCore/khtml/khtmlpart_p.h
+++ b/WebCore/khtml/khtmlpart_p.h
@@ -38,12 +38,12 @@
 #include "khtml_events.h"
 #include "khtml_ext.h"
 #include "khtml_iface.h"
-#include "khtml_selection.h"
 #include "khtml_settings.h"
 #include "misc/decoder.h"
 #include "java/kjavaappletcontext.h"
 #include "ecma/kjs_proxy.h"
 #include "dom/dom_misc.h"
+#include "xml/dom_selection.h"
 
 namespace KIO
 {
@@ -345,13 +345,13 @@ public:
   DOM::Node m_mousePressNode; //node under the mouse when the mouse was pressed (set in the mouse handler)
 
 #if APPLE_CHANGES
-  KHTMLSelection::ETextGranularity m_textElement;
+  DOM::Selection::ETextGranularity m_textElement;
   bool m_mouseMovedSinceLastMousePress:1;
 #endif
   QString m_overURL;
   QString m_overURLTarget;
 
-  KHTMLSelection m_selection;
+  DOM::Selection m_selection;
   int m_caretBlinkTimer;
 
   bool m_caretVisible:1;
diff --git a/WebCore/khtml/khtmlview.cpp b/WebCore/khtml/khtmlview.cpp
index 5678bf6..0815908 100644
--- a/WebCore/khtml/khtmlview.cpp
+++ b/WebCore/khtml/khtmlview.cpp
@@ -26,7 +26,6 @@
 #include "khtmlview.h"
 
 #include "khtml_part.h"
-#include "khtml_selection.h"
 #include "khtml_events.h"
 
 #include "html/html_documentimpl.h"
@@ -40,6 +39,7 @@
 #include "rendering/render_line.h"
 #include "rendering/render_text.h"
 #include "xml/dom_nodeimpl.h"
+#include "xml/dom_selection.h"
 #include "xml/dom2_eventsimpl.h"
 #include "css/cssstyleselector.h"
 #include "misc/htmlhashes.h"
diff --git a/WebCore/khtml/rendering/render_block.cpp b/WebCore/khtml/rendering/render_block.cpp
index f04a45b..8bef8bc 100644
--- a/WebCore/khtml/rendering/render_block.cpp
+++ b/WebCore/khtml/rendering/render_block.cpp
@@ -34,12 +34,12 @@
 #include "xml/dom_nodeimpl.h"
 #include "xml/dom_docimpl.h"
 #include "xml/dom_position.h"
+#include "xml/dom_selection.h"
 #include "html/html_formimpl.h"
 #include "render_block.h"
 
 #include "khtmlview.h"
 #include "khtml_part.h"
-#include "khtml_selection.h"
 #include "htmltags.h"
 
 using namespace DOM;
@@ -1285,7 +1285,7 @@ void RenderBlock::paintObject(PaintInfo& i, int _tx, int _ty)
         then paint the caret.
     */
     if (paintAction == PaintActionForeground) {
-        const KHTMLSelection &s = document()->part()->selection();
+        const Selection &s = document()->part()->selection();
         NodeImpl *baseNode = s.baseNode();
         RenderObject *renderer = baseNode ? baseNode->renderer() : 0;
         if (renderer && renderer->containingBlock() == this && baseNode->isContentEditable()) {
@@ -2019,32 +2019,32 @@ bool RenderBlock::nodeAtPoint(NodeInfo& info, int _x, int _y, int _tx, int _ty,
     return inBox;
 }
 
-DOMPosition RenderBlock::positionForBox(InlineBox *box, bool start) const
+Position RenderBlock::positionForBox(InlineBox *box, bool start) const
 {
     if (!box)
-        return DOMPosition();
+        return Position();
 
     if (!box->object()->element())
-        return DOMPosition(element(), start ? caretMinOffset() : caretMaxOffset());
+        return Position(element(), start ? caretMinOffset() : caretMaxOffset());
 
     if (!box->isInlineTextBox())
-        return DOMPosition(box->object()->element(), start ? box->object()->caretMinOffset() : box->object()->caretMaxOffset());
+        return Position(box->object()->element(), start ? box->object()->caretMinOffset() : box->object()->caretMaxOffset());
 
     InlineTextBox *textBox = static_cast<InlineTextBox *>(box);
-    return DOMPosition(box->object()->element(), start ? textBox->start() : textBox->start() + textBox->len());
+    return Position(box->object()->element(), start ? textBox->start() : textBox->start() + textBox->len());
 }
 
-DOMPosition RenderBlock::positionForRenderer(RenderObject *renderer, bool start) const
+Position RenderBlock::positionForRenderer(RenderObject *renderer, bool start) const
 {
     if (!renderer)
-        return DOMPosition();
+        return Position();
 
     NodeImpl *node = renderer->element() ? renderer->element() : element();
     long offset = start ? node->caretMinOffset() : node->caretMaxOffset();
-    return DOMPosition(node, offset);
+    return Position(node, offset);
 }
 
-DOMPosition RenderBlock::positionForCoordinates(int _x, int _y)
+Position RenderBlock::positionForCoordinates(int _x, int _y)
 {
     if (isTable())
         return RenderFlow::positionForCoordinates(_x, _y); 
@@ -2065,7 +2065,7 @@ DOMPosition RenderBlock::positionForCoordinates(int _x, int _y)
 
     if (childrenInline()) {
         if (!firstRootBox())
-            return DOMPosition(element(), 0);
+            return Position(element(), 0);
             
         if (_y >= top && _y < absy + firstRootBox()->topOverflow())
             // y coordinates is above first root line box
@@ -2090,7 +2090,7 @@ DOMPosition RenderBlock::positionForCoordinates(int _x, int _y)
                     return closestBox->object()->positionForCoordinates(_x, _y);
             }
         }
-        return DOMPosition(element(), 0);
+        return Position(element(), 0);
     }
     
     // see if any child blocks exist at this y coordinate
@@ -2116,7 +2116,7 @@ DOMPosition RenderBlock::positionForCoordinates(int _x, int _y)
         return firstChild()->positionForCoordinates(_x, _y);
     
     // still no luck...return this render object's element, if there isn't one, and offset 0
-    return DOMPosition(element(), 0);
+    return Position(element(), 0);
 }
 
 void RenderBlock::calcMinMaxWidth()
diff --git a/WebCore/khtml/rendering/render_block.h b/WebCore/khtml/rendering/render_block.h
index 061bb0a..6495f18 100644
--- a/WebCore/khtml/rendering/render_block.h
+++ b/WebCore/khtml/rendering/render_block.h
@@ -30,7 +30,7 @@
 #include "render_flow.h"
 
 namespace DOM {
-    class DOMPosition;
+    class Position;
 };
 
 namespace khtml {
@@ -172,7 +172,7 @@ public:
 
     bool isPointInScrollbar(int x, int y, int tx, int ty);
 
-    virtual DOM::DOMPosition positionForCoordinates(int x, int y);
+    virtual DOM::Position positionForCoordinates(int x, int y);
     
     virtual void calcMinMaxWidth();
     void calcInlineMinMaxWidth();
@@ -208,8 +208,8 @@ protected:
     void removeChildrenFromLineBoxes();
 
 private:
-    DOM::DOMPosition positionForBox(InlineBox *box, bool start=true) const;
-    DOM::DOMPosition positionForRenderer(RenderObject *renderer, bool start=true) const;
+    DOM::Position positionForBox(InlineBox *box, bool start=true) const;
+    DOM::Position positionForRenderer(RenderObject *renderer, bool start=true) const;
     
 protected:
     struct FloatingObject {
diff --git a/WebCore/khtml/rendering/render_br.cpp b/WebCore/khtml/rendering/render_br.cpp
index e77e6e5..7b57b7c 100644
--- a/WebCore/khtml/rendering/render_br.cpp
+++ b/WebCore/khtml/rendering/render_br.cpp
@@ -23,7 +23,7 @@
 #include "xml/dom_position.h"
 
 using namespace khtml;
-using DOM::DOMPosition;
+using DOM::Position;
 
 RenderBR::RenderBR(DOM::NodeImpl* node)
     : RenderText(node, new DOM::DOMStringImpl(QChar('\n'))), m_x(0), m_y(0), m_height(0),
@@ -98,9 +98,9 @@ unsigned long RenderBR::caretMaxRenderedOffset() const
     return 1;
 }
 
-DOMPosition RenderBR::positionForCoordinates(int _x, int _y)
+Position RenderBR::positionForCoordinates(int _x, int _y)
 {
-    return DOMPosition(element(), 0);
+    return Position(element(), 0);
 }
 
 void RenderBR::caretPos(int offset, bool override, int &_x, int &_y, int &_w, int &_h)
diff --git a/WebCore/khtml/rendering/render_br.h b/WebCore/khtml/rendering/render_br.h
index 70dbff0..3b71433 100644
--- a/WebCore/khtml/rendering/render_br.h
+++ b/WebCore/khtml/rendering/render_br.h
@@ -25,7 +25,7 @@
 #include "render_text.h"
 
 namespace DOM {
-    class DOMPosition;
+    class Position;
 };
 
 /*
@@ -67,7 +67,7 @@ public:
     virtual long caretMaxOffset() const;
     virtual unsigned long caretMaxRenderedOffset() const;
     
-    virtual DOM::DOMPosition positionForCoordinates(int _x, int _y);
+    virtual DOM::Position positionForCoordinates(int _x, int _y);
     virtual void caretPos(int offset, bool override, int &_x, int &_y, int &_w, int &_h);
 
 private:
diff --git a/WebCore/khtml/rendering/render_container.cpp b/WebCore/khtml/rendering/render_container.cpp
index d3f8dcf..08fea5c 100644
--- a/WebCore/khtml/rendering/render_container.cpp
+++ b/WebCore/khtml/rendering/render_container.cpp
@@ -41,7 +41,7 @@
 #include "KWQAccObjectCache.h" 
 #endif
 
-using DOM::DOMPosition;
+using DOM::Position;
 using namespace khtml;
 
 RenderContainer::RenderContainer(DOM::NodeImpl* node)
@@ -475,11 +475,11 @@ void RenderContainer::removeLeftoverAnonymousBoxes()
 	parent()->removeLeftoverAnonymousBoxes();
 }
 
-DOMPosition RenderContainer::positionForCoordinates(int _x, int _y)
+Position RenderContainer::positionForCoordinates(int _x, int _y)
 {
     // no children...return this render object's element, if there isn't one, and offset 0
     if (!firstChild())
-        return DOMPosition(element(), 0);
+        return Position(element(), 0);
 
     // look for the geometically-closest child and pass off to that child
     int min = INT_MAX;
diff --git a/WebCore/khtml/rendering/render_container.h b/WebCore/khtml/rendering/render_container.h
index 33869df..cb999a7 100644
--- a/WebCore/khtml/rendering/render_container.h
+++ b/WebCore/khtml/rendering/render_container.h
@@ -25,7 +25,7 @@
 #include "render_object.h"
 
 namespace DOM {
-    class DOMPosition;
+    class Position;
 };
 
 namespace khtml
@@ -61,7 +61,7 @@ public:
 
     void updatePseudoChild(RenderStyle::PseudoId type, RenderObject* child);
 
-    virtual DOM::DOMPosition positionForCoordinates(int x, int y);
+    virtual DOM::Position positionForCoordinates(int x, int y);
 
 private:
     void setFirstChild(RenderObject *first) { m_first = first; }
diff --git a/WebCore/khtml/rendering/render_object.cpp b/WebCore/khtml/rendering/render_object.cpp
index c654e47..b595914 100644
--- a/WebCore/khtml/rendering/render_object.cpp
+++ b/WebCore/khtml/rendering/render_object.cpp
@@ -1721,9 +1721,9 @@ void RenderObject::arenaDelete(RenderArena *arena)
     arenaDelete(arena, dynamic_cast<void *>(this));
 }
 
-DOMPosition RenderObject::positionForCoordinates(int x, int y)
+Position RenderObject::positionForCoordinates(int x, int y)
 {
-    return DOMPosition(element(), caretMinOffset());
+    return Position(element(), caretMinOffset());
 }
 
 bool RenderObject::mouseInside() const
diff --git a/WebCore/khtml/rendering/render_object.h b/WebCore/khtml/rendering/render_object.h
index 0b86fa6..92ff8e1 100644
--- a/WebCore/khtml/rendering/render_object.h
+++ b/WebCore/khtml/rendering/render_object.h
@@ -81,11 +81,11 @@ typedef enum {
 
 namespace DOM {
     class HTMLAreaElementImpl;
-    class DOMPosition;
     class DOMString;
     class DocumentImpl;
     class ElementImpl;
     class EventImpl;
+    class Position;
 };
 
 namespace khtml {
@@ -480,7 +480,7 @@ public:
     virtual bool nodeAtPoint(NodeInfo& info, int x, int y, int tx, int ty,
                              HitTestAction hitTestAction = HitTestAll, bool inside=false);
     
-    virtual DOM::DOMPosition positionForCoordinates(int x, int y);
+    virtual DOM::Position positionForCoordinates(int x, int y);
     
     virtual void dirtyLinesFromChangedChild(RenderObject* child);
     
diff --git a/WebCore/khtml/rendering/render_replaced.cpp b/WebCore/khtml/rendering/render_replaced.cpp
index b993a7e..f1193c7 100644
--- a/WebCore/khtml/rendering/render_replaced.cpp
+++ b/WebCore/khtml/rendering/render_replaced.cpp
@@ -128,11 +128,11 @@ unsigned long RenderReplaced::caretMaxRenderedOffset() const
     return 1; 
 }
 
-DOMPosition RenderReplaced::positionForCoordinates(int _x, int _y)
+Position RenderReplaced::positionForCoordinates(int _x, int _y)
 {
     InlineBox *box = inlineBoxWrapper();
     if (!box)
-        return DOMPosition(element(), 0);
+        return Position(element(), 0);
 
     RootInlineBox *root = box->root();
 
@@ -143,15 +143,15 @@ DOMPosition RenderReplaced::positionForCoordinates(int _x, int _y)
     int bottom = root->nextRootBox() ? absy + root->nextRootBox()->topOverflow() : absy + root->bottomOverflow();
 
     if (_y < top)
-        return DOMPosition(element(), caretMinOffset()); // coordinates are above
+        return Position(element(), caretMinOffset()); // coordinates are above
     
     if (_y >= bottom)
-        return DOMPosition(element(), caretMaxOffset()); // coordinates are below
+        return Position(element(), caretMaxOffset()); // coordinates are below
     
     if (element()) {
         if (_x <= absx + xPos() + (width() / 2))
-            return DOMPosition(element(), 0);
-        return DOMPosition(element(), 1);
+            return Position(element(), 0);
+        return Position(element(), 1);
     }
 
     return RenderBox::positionForCoordinates(_x, _y);
diff --git a/WebCore/khtml/rendering/render_replaced.h b/WebCore/khtml/rendering/render_replaced.h
index 7120ea2..1221498 100644
--- a/WebCore/khtml/rendering/render_replaced.h
+++ b/WebCore/khtml/rendering/render_replaced.h
@@ -28,7 +28,7 @@ class KHTMLView;
 class QWidget;
 
 namespace DOM {
-    class DOMPosition;
+    class Position;
 }
 
 namespace khtml {
@@ -59,7 +59,7 @@ public:
     virtual long caretMinOffset() const;
     virtual long caretMaxOffset() const;
     virtual unsigned long caretMaxRenderedOffset() const;
-    virtual DOM::DOMPosition positionForCoordinates(int x, int y);
+    virtual DOM::Position positionForCoordinates(int x, int y);
     
 private:
     int m_intrinsicWidth;
diff --git a/WebCore/khtml/rendering/render_text.cpp b/WebCore/khtml/rendering/render_text.cpp
index 68a73c4..addc895 100644
--- a/WebCore/khtml/rendering/render_text.cpp
+++ b/WebCore/khtml/rendering/render_text.cpp
@@ -439,10 +439,10 @@ bool RenderText::nodeAtPoint(NodeInfo& info, int _x, int _y, int _tx, int _ty,
     return inside;
 }
 
-DOMPosition RenderText::positionForCoordinates(int _x, int _y)
+Position RenderText::positionForCoordinates(int _x, int _y)
 {
     if (!firstTextBox() || stringLength() == 0)
-        return DOMPosition(element(), 0);
+        return Position(element(), 0);
 
     int absx, absy;
     containingBlock()->absolutePosition(absx, absy);
@@ -450,13 +450,13 @@ DOMPosition RenderText::positionForCoordinates(int _x, int _y)
     if (firstTextBox() && _y < absy + firstTextBox()->root()->bottomOverflow() && _x < absx + firstTextBox()->m_x) {
         // at the y coordinate of the first line or above
         // and the x coordinate is to the left than the first text box left edge
-        return DOMPosition(element(), firstTextBox()->m_start);
+        return Position(element(), firstTextBox()->m_start);
     }
 
     if (lastTextBox() && _y >= absy + lastTextBox()->root()->topOverflow() && _x >= absx + lastTextBox()->m_x + lastTextBox()->m_width) {
         // at the y coordinate of the last line or below
         // and the x coordinate is to the right than the last text box right edge
-        return DOMPosition(element(), lastTextBox()->m_start + lastTextBox()->m_len);
+        return Position(element(), lastTextBox()->m_start + lastTextBox()->m_len);
     }
 
     for (InlineTextBox *box = firstTextBox(); box; box = box->nextTextBox()) {
@@ -467,21 +467,21 @@ DOMPosition RenderText::positionForCoordinates(int _x, int _y)
                 const Font *f = htmlFont(box == firstTextBox());
                 int offset = box->offsetForPosition(_x, absx, f, this);
                 if (offset != -1) {
-                    return DOMPosition(element(), offset + box->m_start);
+                    return Position(element(), offset + box->m_start);
                 }
             }
             else if (!box->prevOnLine() && _x < absx + box->m_x)
                 // box is first on line
                 // and the x coordinate is to the left than the first text box left edge
-                return DOMPosition(element(), box->m_start);
+                return Position(element(), box->m_start);
             else if (!box->nextOnLine() && _x >= absx + box->m_x + box->m_width)
                 // box is last on line
                 // and the x coordinate is to the right than the last text box right edge
-                return DOMPosition(element(), box->m_start + box->m_len);
+                return Position(element(), box->m_start + box->m_len);
         }
     }
     
-    return DOMPosition(element(), 0);
+    return Position(element(), 0);
 }
 
 void RenderText::caretPos(int offset, bool override, int &_x, int &_y, int &width, int &height)
diff --git a/WebCore/khtml/rendering/render_text.h b/WebCore/khtml/rendering/render_text.h
index 64ba6ef..07bd50d 100644
--- a/WebCore/khtml/rendering/render_text.h
+++ b/WebCore/khtml/rendering/render_text.h
@@ -37,7 +37,7 @@ class QPainter;
 class QFontMetrics;
 
 namespace DOM {
-    class DOMPosition;
+    class Position;
 };
 
 // Define a constant for soft hyphen's unicode value.
@@ -154,7 +154,7 @@ public:
 
     virtual void absoluteRects(QValueList<QRect>& rects, int _tx, int _ty);
 
-    virtual DOM::DOMPosition positionForCoordinates(int _x, int _y);
+    virtual DOM::Position positionForCoordinates(int _x, int _y);
 
     unsigned int length() const { return str->l; }
     QChar *text() const { return str->s; }
diff --git a/WebCore/khtml/xml/dom_docimpl.cpp b/WebCore/khtml/xml/dom_docimpl.cpp
index c1204bd..2649775 100644
--- a/WebCore/khtml/xml/dom_docimpl.cpp
+++ b/WebCore/khtml/xml/dom_docimpl.cpp
@@ -28,6 +28,7 @@
 #include "xml/dom_textimpl.h"
 #include "xml/dom_xmlimpl.h"
 #include "xml/dom2_rangeimpl.h"
+#include "xml/dom_selection.h"
 #include "xml/dom2_eventsimpl.h"
 #include "xml/xml_tokenizer.h"
 
@@ -53,7 +54,6 @@
 
 #include "khtmlview.h"
 #include "khtml_part.h"
-#include "khtml_selection.h"
 
 #include <kglobalsettings.h>
 #include <kstringhandler.h>
@@ -1207,8 +1207,8 @@ void DocumentImpl::updateSelection()
         return;
     
     RenderCanvas *canvas = static_cast<RenderCanvas*>(m_render);
-    KHTMLSelection s = part()->selection();
-    if (s.isEmpty() || s.state() == KHTMLSelection::CARET) {
+    Selection s = part()->selection();
+    if (s.isEmpty() || s.state() == Selection::CARET) {
         canvas->clearSelection();
     }
     else {
@@ -2691,13 +2691,13 @@ bool DocumentImpl::execCommand(const DOMString &command, bool userInterface, con
         return true;
     }
     else if (atom == cutCommand) {
-        if (!part() || part()->selection().state() != KHTMLSelection::RANGE)
+        if (!part() || part()->selection().state() != Selection::RANGE)
             return false;
         KWQ(part())->issueCutCommand();
         return true;
     }
     else if (atom == copyCommand) {
-        if (!part() || part()->selection().state() != KHTMLSelection::RANGE)
+        if (!part() || part()->selection().state() != Selection::RANGE)
             return false;
         KWQ(part())->issueCopyCommand();
         return true;
diff --git a/WebCore/khtml/xml/dom_docimpl.h b/WebCore/khtml/xml/dom_docimpl.h
index c3db8ea..b75ec12 100644
--- a/WebCore/khtml/xml/dom_docimpl.h
+++ b/WebCore/khtml/xml/dom_docimpl.h
@@ -49,7 +49,6 @@ class QPaintDevice;
 class QPaintDeviceMetrics;
 class KHTMLView;
 class KHTMLPart;
-class KHTMLSelection;
 class RenderArena;
 
 #if APPLE_CHANGES
@@ -101,6 +100,7 @@ namespace DOM {
     class ProcessingInstructionImpl;
     class RangeImpl;
     class RegisteredEventListener;
+    class Selection;
     class StyleSheetImpl;
     class StyleSheetListImpl;
     class TextImpl;
diff --git a/WebCore/khtml/xml/dom_edititerator.cpp b/WebCore/khtml/xml/dom_edititerator.cpp
index 22f7668..1caed18 100644
--- a/WebCore/khtml/xml/dom_edititerator.cpp
+++ b/WebCore/khtml/xml/dom_edititerator.cpp
@@ -29,9 +29,9 @@
 
 namespace DOM {
 
-DOMPosition EditIterator::peekPrevious() const
+Position EditIterator::peekPrevious() const
 {
-    DOMPosition pos = m_current;
+    Position pos = m_current;
     
     if (pos.isEmpty())
         return pos;
@@ -39,18 +39,18 @@ DOMPosition EditIterator::peekPrevious() const
     if (pos.offset() <= 0) {
         NodeImpl *prevNode = pos.node()->previousEditable();
         if (prevNode)
-            pos = DOMPosition(prevNode, prevNode->maxOffset());
+            pos = Position(prevNode, prevNode->maxOffset());
     }
     else {
-        pos = DOMPosition(pos.node(), pos.offset() - 1);
+        pos = Position(pos.node(), pos.offset() - 1);
     }
     
     return pos;
 }
 
-DOMPosition EditIterator::peekNext() const
+Position EditIterator::peekNext() const
 {
-    DOMPosition pos = m_current;
+    Position pos = m_current;
     
     if (pos.isEmpty())
         return pos;
@@ -58,10 +58,10 @@ DOMPosition EditIterator::peekNext() const
     if (pos.offset() >= pos.node()->maxOffset()) {
         NodeImpl *nextNode = pos.node()->nextEditable();
         if (nextNode)
-            pos = DOMPosition(nextNode, 0);
+            pos = Position(nextNode, 0);
     }
     else {
-        pos = DOMPosition(pos.node(), pos.offset() + 1);
+        pos = Position(pos.node(), pos.offset() + 1);
     }
     
     return pos;
diff --git a/WebCore/khtml/xml/dom_edititerator.h b/WebCore/khtml/xml/dom_edititerator.h
index 60a3928..8e4aa0f 100644
--- a/WebCore/khtml/xml/dom_edititerator.h
+++ b/WebCore/khtml/xml/dom_edititerator.h
@@ -30,30 +30,30 @@
 
 namespace DOM {
 
-class DOMPosition;
 class NodeImpl;
+class Position;
 
 class EditIterator
 {
 public:
     EditIterator() : m_current() {}
     EditIterator(NodeImpl *node, long offset) : m_current(node, offset) {}
-    EditIterator(const DOMPosition &o) : m_current(o) {}
+    EditIterator(const Position &o) : m_current(o) {}
 
-    DOMPosition current() const { return m_current; }
-    DOMPosition previous() { return m_current = peekPrevious(); }
-    DOMPosition next() { return m_current = peekNext(); }
-    DOMPosition peekPrevious() const;
-    DOMPosition peekNext() const;
+    Position current() const { return m_current; }
+    Position previous() { return m_current = peekPrevious(); }
+    Position next() { return m_current = peekNext(); }
+    Position peekPrevious() const;
+    Position peekNext() const;
 
-    void setPosition(const DOMPosition &pos) { m_current = pos; }
+    void setPosition(const Position &pos) { m_current = pos; }
 
     bool atStart() const;
     bool atEnd() const;
     bool isEmpty() const { return m_current.isEmpty(); }
 
 private:
-    DOMPosition m_current;
+    Position m_current;
 };
 
 } // namespace DOM
diff --git a/WebCore/khtml/xml/dom_elementimpl.cpp b/WebCore/khtml/xml/dom_elementimpl.cpp
index bf34784..7d30e2a 100644
--- a/WebCore/khtml/xml/dom_elementimpl.cpp
+++ b/WebCore/khtml/xml/dom_elementimpl.cpp
@@ -31,7 +31,6 @@
 #include "xml/dom_elementimpl.h"
 
 #include "khtml_part.h"
-#include "khtml_selection.h"
 
 #include "html/dtd.h"
 #include "html/htmlparser.h"
@@ -41,6 +40,7 @@
 #include "css/css_valueimpl.h"
 #include "css/css_stylesheetimpl.h"
 #include "css/cssstyleselector.h"
+#include "xml/dom_selection.h"
 #include "xml/dom_xmlimpl.h"
 
 #include <qtextstream.h>
diff --git a/WebCore/khtml/xml/dom_nodeimpl.cpp b/WebCore/khtml/xml/dom_nodeimpl.cpp
index 8e67b47..83ff7db 100644
--- a/WebCore/khtml/xml/dom_nodeimpl.cpp
+++ b/WebCore/khtml/xml/dom_nodeimpl.cpp
@@ -31,6 +31,7 @@
 #include "xml/dom2_eventsimpl.h"
 #include "xml/dom_docimpl.h"
 #include "xml/dom_position.h"
+#include "xml/dom_selection.h"
 #include "xml/dom2_rangeimpl.h"
 #include "css/csshelper.h"
 #include "css/cssstyleselector.h"
@@ -45,7 +46,6 @@
 #include "ecma/kjs_proxy.h"
 #include "khtmlview.h"
 #include "khtml_part.h"
-#include "khtml_selection.h"
 
 #include "html/dtd.h"
 
@@ -1424,12 +1424,12 @@ NodeImpl::Id NodeImpl::identifier() const
 }
 #endif
 
-DOMPosition NodeImpl::positionForCoordinates(int x, int y)
+Position NodeImpl::positionForCoordinates(int x, int y)
 {
     if (renderer())
         return renderer()->positionForCoordinates(x, y);
     
-    return DOMPosition(this, 0);
+    return Position(this, 0);
 }
 
 //-------------------------------------------------------------------------
@@ -2068,7 +2068,7 @@ void NodeBaseImpl::setFocus(bool received)
 
     if (received && isEditableBlock() && !hasChildNodes()) {
         KHTMLPart *part = getDocument()->part();
-        part->setSelection(KHTMLSelection(this, 0));
+        part->setSelection(Selection(this, 0));
     }
 
     // note that we need to recalc the style
diff --git a/WebCore/khtml/xml/dom_nodeimpl.h b/WebCore/khtml/xml/dom_nodeimpl.h
index 635c2bb..110b50e 100644
--- a/WebCore/khtml/xml/dom_nodeimpl.h
+++ b/WebCore/khtml/xml/dom_nodeimpl.h
@@ -49,7 +49,6 @@ namespace khtml {
 
 namespace DOM {
 
-class DOMPosition;
 class NodeListImpl;
 class NamedNodeMapImpl;
 class DocumentImpl;
@@ -58,6 +57,7 @@ class Range;
 class RangeImpl;
 class RegisteredEventListener;
 class EventImpl;
+class Position;
 
 // The namespace used for XHTML elements
 #define XHTML_NAMESPACE "http://www.w3.org/1999/xhtml"
@@ -168,7 +168,7 @@ public:
     bool inSameRootEditableBlock(NodeImpl *);
     bool inSameContainingEditableBlock(NodeImpl *);
     
-    DOMPosition positionForCoordinates(int x, int y);
+    Position positionForCoordinates(int x, int y);
 
     // used by the parser. Doesn't do as many error checkings as
     // appendChild(), and returns the node into which will be parsed next.
diff --git a/WebCore/khtml/xml/dom_position.cpp b/WebCore/khtml/xml/dom_position.cpp
index f25cfa3..45a7935 100644
--- a/WebCore/khtml/xml/dom_position.cpp
+++ b/WebCore/khtml/xml/dom_position.cpp
@@ -41,9 +41,6 @@
 #include "KWQLogging.h"
 #endif
 
-using DOM::DOMPosition;
-using DOM::EditIterator;
-using DOM::NodeImpl;
 using khtml::InlineBox;
 using khtml::InlineFlowBox;
 using khtml::InlineTextBox;
@@ -60,6 +57,8 @@ using khtml::RootInlineBox;
 #define ERROR(formatAndArgs...) ((void)0)
 #endif
 
+namespace DOM {
+
 static InlineBox *inlineBoxForRenderer(RenderObject *renderer, long offset)
 {
     if (!renderer)
@@ -124,7 +123,7 @@ static NodeImpl *previousRenderedEditable(NodeImpl *node)
 }
 
 
-DOMPosition::DOMPosition(NodeImpl *node, long offset) 
+Position::Position(NodeImpl *node, long offset) 
     : m_node(0), m_offset(offset) 
 { 
     if (node) {
@@ -133,7 +132,7 @@ DOMPosition::DOMPosition(NodeImpl *node, long offset)
     }
 };
 
-DOMPosition::DOMPosition(const DOMPosition &o)
+Position::Position(const Position &o)
     : m_node(0), m_offset(o.offset()) 
 {
     if (o.node()) {
@@ -142,13 +141,13 @@ DOMPosition::DOMPosition(const DOMPosition &o)
     }
 }
 
-DOMPosition::~DOMPosition() {
+Position::~Position() {
     if (m_node) {
         m_node->deref();
     }
 }
 
-DOMPosition &DOMPosition::operator=(const DOMPosition &o)
+Position &Position::operator=(const Position &o)
 {
     if (m_node) {
         m_node->deref();
@@ -163,7 +162,7 @@ DOMPosition &DOMPosition::operator=(const DOMPosition &o)
     return *this;
 }
 
-long DOMPosition::renderedOffset() const
+long Position::renderedOffset() const
 {
     if (!node()->isTextNode())
         return offset();
@@ -187,7 +186,7 @@ long DOMPosition::renderedOffset() const
     return result;
 }
 
-DOMPosition DOMPosition::equivalentLeafPosition() const
+Position Position::equivalentLeafPosition() const
 {
     if (node()->hasChildNodes() == false)
         return *this;
@@ -204,13 +203,13 @@ DOMPosition DOMPosition::equivalentLeafPosition() const
         }
         count += n->maxOffset();
     }
-    return DOMPosition(n, count);
+    return Position(n, count);
 }
 
-DOMPosition DOMPosition::previousRenderedEditablePosition() const
+Position Position::previousRenderedEditablePosition() const
 {
     if (isEmpty())
-        return DOMPosition();
+        return Position();
 
     if (node()->isContentEditable() && node()->hasChildNodes() == false && inRenderedContent())
         return *this;
@@ -219,18 +218,18 @@ DOMPosition DOMPosition::previousRenderedEditablePosition() const
     while (1) {
         n = n->previousEditable();
         if (!n)
-            return DOMPosition();
+            return Position();
         if (n->renderer() && n->renderer()->style()->visibility() == khtml::VISIBLE)
             break;
     }
     
-    return DOMPosition(n, 0);
+    return Position(n, 0);
 }
 
-DOMPosition DOMPosition::nextRenderedEditablePosition() const
+Position Position::nextRenderedEditablePosition() const
 {
     if (isEmpty())
-        return DOMPosition();
+        return Position();
 
     if (node()->isContentEditable() && node()->hasChildNodes() == false && inRenderedContent())
         return *this;
@@ -239,18 +238,18 @@ DOMPosition DOMPosition::nextRenderedEditablePosition() const
     while (1) {
         n = n->nextEditable();
         if (!n)
-            return DOMPosition();
+            return Position();
         if (n->renderer() && n->renderer()->style()->visibility() == khtml::VISIBLE)
             break;
     }
     
-    return DOMPosition(n, 0);
+    return Position(n, 0);
 }
 
-DOMPosition DOMPosition::previousCharacterPosition() const
+Position Position::previousCharacterPosition() const
 {
     if (isEmpty())
-        return DOMPosition();
+        return Position();
 
     NodeImpl *fromRootEditableBlock = node()->rootEditableBlock();
     EditIterator it(*this);
@@ -258,7 +257,7 @@ DOMPosition DOMPosition::previousCharacterPosition() const
     bool atStartOfLine = isFirstRenderedPositionOnLine();
     
     while (!it.atStart()) {
-        DOMPosition pos = it.previous();
+        Position pos = it.previous();
 
         if (pos.node()->rootEditableBlock() != fromRootEditableBlock)
             return *this;
@@ -274,10 +273,10 @@ DOMPosition DOMPosition::previousCharacterPosition() const
     return *this;
 }
 
-DOMPosition DOMPosition::nextCharacterPosition() const
+Position Position::nextCharacterPosition() const
 {
     if (isEmpty())
-        return DOMPosition();
+        return Position();
 
     NodeImpl *fromRootEditableBlock = node()->rootEditableBlock();
     EditIterator it(*this);
@@ -285,7 +284,7 @@ DOMPosition DOMPosition::nextCharacterPosition() const
     bool atEndOfLine = isLastRenderedPositionOnLine();
     
     while (!it.atEnd()) {
-        DOMPosition pos = it.next();
+        Position pos = it.next();
 
         if (pos.node()->rootEditableBlock() != fromRootEditableBlock)
             return *this;
@@ -301,12 +300,12 @@ DOMPosition DOMPosition::nextCharacterPosition() const
     return *this;
 }
 
-DOMPosition DOMPosition::previousWordPosition() const
+Position Position::previousWordPosition() const
 {
     if (isEmpty())
-        return DOMPosition();
+        return Position();
 
-    DOMPosition pos = *this;
+    Position pos = *this;
     for (EditIterator it(*this); !it.atStart(); it.previous()) {
         if (it.current().node()->nodeType() == Node::TEXT_NODE || it.current().node()->nodeType() == Node::CDATA_SECTION_NODE) {
             DOMString t = it.current().node()->nodeValue();
@@ -314,10 +313,10 @@ DOMPosition DOMPosition::previousWordPosition() const
             uint len = t.length();
             int start, end;
             khtml::findWordBoundary(chars, len, it.current().offset(), &start, &end);
-            pos = DOMPosition(it.current().node(), start);
+            pos = Position(it.current().node(), start);
         }
         else {
-            pos = DOMPosition(it.current().node(), it.current().node()->caretMinOffset());
+            pos = Position(it.current().node(), it.current().node()->caretMinOffset());
         }
         if (pos != *this)
             return pos;
@@ -327,12 +326,12 @@ DOMPosition DOMPosition::previousWordPosition() const
     return *this;
 }
 
-DOMPosition DOMPosition::nextWordPosition() const
+Position Position::nextWordPosition() const
 {
     if (isEmpty())
-        return DOMPosition();
+        return Position();
 
-    DOMPosition pos = *this;
+    Position pos = *this;
     for (EditIterator it(*this); !it.atEnd(); it.next()) {
         if (it.current().node()->nodeType() == Node::TEXT_NODE || it.current().node()->nodeType() == Node::CDATA_SECTION_NODE) {
             DOMString t = it.current().node()->nodeValue();
@@ -340,10 +339,10 @@ DOMPosition DOMPosition::nextWordPosition() const
             uint len = t.length();
             int start, end;
             khtml::findWordBoundary(chars, len, it.current().offset(), &start, &end);
-            pos = DOMPosition(it.current().node(), end);
+            pos = Position(it.current().node(), end);
         }
         else {
-            pos = DOMPosition(it.current().node(), it.current().node()->caretMaxOffset());
+            pos = Position(it.current().node(), it.current().node()->caretMaxOffset());
         }
         if (pos != *this)
             return pos;
@@ -353,10 +352,10 @@ DOMPosition DOMPosition::nextWordPosition() const
     return *this;
 }
 
-DOMPosition DOMPosition::previousLinePosition(int x) const
+Position Position::previousLinePosition(int x) const
 {
     if (!node())
-        return DOMPosition();
+        return Position();
 
     if (!node()->renderer())
         return *this;
@@ -379,7 +378,7 @@ DOMPosition DOMPosition::previousLinePosition(int x) const
         while (n && startBlock == n->containingEditableBlock())
             n = n->previousEditable();
         if (n) {
-            while (n && !DOMPosition(n, n->caretMaxOffset()).inRenderedContent())
+            while (n && !Position(n, n->caretMaxOffset()).inRenderedContent())
                 n = n->previousEditable();
             if (n && n->inSameRootEditableBlock(node())) {
                 box = inlineBoxForRenderer(n->renderer(), n->caretMaxOffset());
@@ -401,10 +400,10 @@ DOMPosition DOMPosition::previousLinePosition(int x) const
     return *this;
 }
 
-DOMPosition DOMPosition::nextLinePosition(int x) const
+Position Position::nextLinePosition(int x) const
 {
     if (!node())
-        return DOMPosition();
+        return Position();
 
     if (!node()->renderer())
         return *this;
@@ -427,7 +426,7 @@ DOMPosition DOMPosition::nextLinePosition(int x) const
         while (n && startBlock == n->containingEditableBlock())
             n = n->nextEditable();
         if (n) {
-            while (n && !DOMPosition(n, n->caretMinOffset()).inRenderedContent())
+            while (n && !Position(n, n->caretMinOffset()).inRenderedContent())
                 n = n->nextEditable();
             if (n && n->inSameRootEditableBlock(node())) {
                 box = inlineBoxForRenderer(n->renderer(), n->caretMinOffset());
@@ -449,10 +448,10 @@ DOMPosition DOMPosition::nextLinePosition(int x) const
     return *this;
 }
 
-DOMPosition DOMPosition::equivalentUpstreamPosition() const
+Position Position::equivalentUpstreamPosition() const
 {
     if (!node())
-        return DOMPosition();
+        return Position();
 
     NodeImpl *block = node()->containingEditableBlock();
     
@@ -473,14 +472,14 @@ DOMPosition DOMPosition::equivalentUpstreamPosition() const
 
         if (renderer->isBlockFlow() || renderer->isReplaced() || renderer->isBR()) {
             if (it.current().offset() >= renderer->caretMaxOffset())
-                return DOMPosition(it.current().node(), renderer->caretMaxOffset());
+                return Position(it.current().node(), renderer->caretMaxOffset());
             else
                 continue;
         }
 
         if (renderer->isText() && static_cast<RenderText *>(renderer)->firstTextBox()) {
             if (it.current().node() != node())
-                return DOMPosition(it.current().node(), renderer->caretMaxOffset());
+                return Position(it.current().node(), renderer->caretMaxOffset());
 
             if (it.current().offset() < 0)
                 continue;
@@ -497,10 +496,10 @@ DOMPosition DOMPosition::equivalentUpstreamPosition() const
     return it.current();
 }
 
-DOMPosition DOMPosition::equivalentDownstreamPosition() const
+Position Position::equivalentDownstreamPosition() const
 {
     if (!node())
-        return DOMPosition();
+        return Position();
 
     NodeImpl *block = node()->containingEditableBlock();
     
@@ -521,14 +520,14 @@ DOMPosition DOMPosition::equivalentDownstreamPosition() const
 
         if (renderer->isBlockFlow() || renderer->isReplaced() || renderer->isBR()) {
             if (it.current().offset() <= renderer->caretMinOffset())
-                return DOMPosition(it.current().node(), renderer->caretMinOffset());
+                return Position(it.current().node(), renderer->caretMinOffset());
             else
                 continue;
         }
 
         if (renderer->isText() && static_cast<RenderText *>(renderer)->firstTextBox()) {
             if (it.current().node() != node())
-                return DOMPosition(it.current().node(), renderer->caretMinOffset());
+                return Position(it.current().node(), renderer->caretMinOffset());
 
             if (it.current().offset() < 0)
                 continue;
@@ -545,17 +544,17 @@ DOMPosition DOMPosition::equivalentDownstreamPosition() const
     return it.current();
 }
 
-bool DOMPosition::atStartOfContainingEditableBlock() const
+bool Position::atStartOfContainingEditableBlock() const
 {
     return renderedOffset() == 0 && inFirstEditableInContainingEditableBlock();
 }
 
-bool DOMPosition::atStartOfRootEditableBlock() const
+bool Position::atStartOfRootEditableBlock() const
 {
     return renderedOffset() == 0 && inFirstEditableInRootEditableBlock();
 }
 
-bool DOMPosition::inRenderedContent() const
+bool Position::inRenderedContent() const
 {
     if (isEmpty())
         return false;
@@ -594,7 +593,7 @@ bool DOMPosition::inRenderedContent() const
     return false;
 }
 
-bool DOMPosition::inRenderedText() const
+bool Position::inRenderedText() const
 {
     if (!node()->isTextNode())
         return false;
@@ -618,7 +617,7 @@ bool DOMPosition::inRenderedText() const
     return false;
 }
 
-bool DOMPosition::rendersOnSameLine(const DOMPosition &pos) const
+bool Position::rendersOnSameLine(const Position &pos) const
 {
     if (isEmpty() || pos.isEmpty())
         return false;
@@ -644,7 +643,7 @@ bool DOMPosition::rendersOnSameLine(const DOMPosition &pos) const
     return renderersOnDifferentLine(renderer, offset(), posRenderer, pos.offset());
 }
 
-bool DOMPosition::rendersInDifferentPosition(const DOMPosition &pos) const
+bool Position::rendersInDifferentPosition(const Position &pos) const
 {
     if (isEmpty() || pos.isEmpty())
         return false;
@@ -728,7 +727,7 @@ bool DOMPosition::rendersInDifferentPosition(const DOMPosition &pos) const
     return true;
 }
 
-bool DOMPosition::isFirstRenderedPositionOnLine() const
+bool Position::isFirstRenderedPositionOnLine() const
 {
     if (isEmpty())
         return false;
@@ -740,7 +739,7 @@ bool DOMPosition::isFirstRenderedPositionOnLine() const
     if (renderer->style()->visibility() != khtml::VISIBLE)
         return false;
     
-    DOMPosition pos(node(), offset());
+    Position pos(node(), offset());
     EditIterator it(pos);
     while (!it.atStart()) {
         it.previous();
@@ -751,7 +750,7 @@ bool DOMPosition::isFirstRenderedPositionOnLine() const
     return true;
 }
 
-bool DOMPosition::isLastRenderedPositionOnLine() const
+bool Position::isLastRenderedPositionOnLine() const
 {
     if (isEmpty())
         return false;
@@ -766,7 +765,7 @@ bool DOMPosition::isLastRenderedPositionOnLine() const
     if (node()->id() == ID_BR)
         return true;
     
-    DOMPosition pos(node(), offset());
+    Position pos(node(), offset());
     EditIterator it(pos);
     while (!it.atEnd()) {
         it.next();
@@ -777,7 +776,7 @@ bool DOMPosition::isLastRenderedPositionOnLine() const
     return true;
 }
 
-bool DOMPosition::isLastRenderedPositionInEditableBlock() const
+bool Position::isLastRenderedPositionInEditableBlock() const
 {
     if (isEmpty())
         return false;
@@ -792,7 +791,7 @@ bool DOMPosition::isLastRenderedPositionInEditableBlock() const
     if (renderedOffset() != (long)node()->caretMaxRenderedOffset())
         return false;
 
-    DOMPosition pos(node(), offset());
+    Position pos(node(), offset());
     EditIterator it(pos);
     while (!it.atEnd()) {
         it.next();
@@ -804,7 +803,7 @@ bool DOMPosition::isLastRenderedPositionInEditableBlock() const
     return true;
 }
 
-bool DOMPosition::inFirstEditableInRootEditableBlock() const
+bool Position::inFirstEditableInRootEditableBlock() const
 {
     if (isEmpty() || !inRenderedContent())
         return false;
@@ -818,7 +817,7 @@ bool DOMPosition::inFirstEditableInRootEditableBlock() const
     return true;
 }
 
-bool DOMPosition::inLastEditableInRootEditableBlock() const
+bool Position::inLastEditableInRootEditableBlock() const
 {
     if (isEmpty() || !inRenderedContent())
         return false;
@@ -832,7 +831,7 @@ bool DOMPosition::inLastEditableInRootEditableBlock() const
     return true;
 }
 
-bool DOMPosition::inFirstEditableInContainingEditableBlock() const
+bool Position::inFirstEditableInContainingEditableBlock() const
 {
     if (isEmpty() || !inRenderedContent())
         return false;
@@ -850,7 +849,7 @@ bool DOMPosition::inFirstEditableInContainingEditableBlock() const
     return true;
 }
 
-bool DOMPosition::inLastEditableInContainingEditableBlock() const
+bool Position::inLastEditableInContainingEditableBlock() const
 {
     if (isEmpty() || !inRenderedContent())
         return false;
@@ -867,3 +866,5 @@ bool DOMPosition::inLastEditableInContainingEditableBlock() const
 
     return true;
 }
+
+} // namespace DOM
\ No newline at end of file
diff --git a/WebCore/khtml/xml/dom_position.h b/WebCore/khtml/xml/dom_position.h
index 13310cf..09941e6 100644
--- a/WebCore/khtml/xml/dom_position.h
+++ b/WebCore/khtml/xml/dom_position.h
@@ -23,20 +23,20 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-#ifndef _DOM_Position_h_
-#define _DOM_Position_h_
+#ifndef __dom_position_h__
+#define __dom_position_h__
 
 namespace DOM {
 
 class NodeImpl;
 
-class DOMPosition
+class Position
 {
 public:
-    DOMPosition() : m_node(0), m_offset(0) {};
-    DOMPosition(NodeImpl *node, long offset);
-    DOMPosition(const DOMPosition &);
-    ~DOMPosition();
+    Position() : m_node(0), m_offset(0) {};
+    Position(NodeImpl *node, long offset);
+    Position(const Position &);
+    ~Position();
 
     NodeImpl *node() const { return m_node; }
     long offset() const { return m_offset; }
@@ -46,23 +46,23 @@ public:
     bool isEmpty() const { return m_node == 0; }
     bool notEmpty() const { return m_node != 0; }
     
-    DOMPosition equivalentLeafPosition() const;
-    DOMPosition previousRenderedEditablePosition() const;
-    DOMPosition nextRenderedEditablePosition() const;
-    DOMPosition previousCharacterPosition() const;
-    DOMPosition nextCharacterPosition() const;
-    DOMPosition previousWordPosition() const;
-    DOMPosition nextWordPosition() const;
-    DOMPosition previousLinePosition(int x) const;
-    DOMPosition nextLinePosition(int x) const;
-    DOMPosition equivalentUpstreamPosition() const;
-    DOMPosition equivalentDownstreamPosition() const;
+    Position equivalentLeafPosition() const;
+    Position previousRenderedEditablePosition() const;
+    Position nextRenderedEditablePosition() const;
+    Position previousCharacterPosition() const;
+    Position nextCharacterPosition() const;
+    Position previousWordPosition() const;
+    Position nextWordPosition() const;
+    Position previousLinePosition(int x) const;
+    Position nextLinePosition(int x) const;
+    Position equivalentUpstreamPosition() const;
+    Position equivalentDownstreamPosition() const;
     bool atStartOfContainingEditableBlock() const;
     bool atStartOfRootEditableBlock() const;
     bool inRenderedContent() const;
     bool inRenderedText() const;
-    bool rendersOnSameLine(const DOMPosition &pos) const;
-    bool rendersInDifferentPosition(const DOMPosition &pos) const;
+    bool rendersOnSameLine(const Position &pos) const;
+    bool rendersInDifferentPosition(const Position &pos) const;
     bool isFirstRenderedPositionOnLine() const;
     bool isLastRenderedPositionOnLine() const;
     bool isLastRenderedPositionInEditableBlock() const;
@@ -71,26 +71,26 @@ public:
     bool inFirstEditableInContainingEditableBlock() const;
     bool inLastEditableInContainingEditableBlock() const;
     
-    DOMPosition &operator=(const DOMPosition &o);
+    Position &operator=(const Position &o);
     
-    friend bool operator==(const DOMPosition &a, const DOMPosition &b);
-    friend bool operator!=(const DOMPosition &a, const DOMPosition &b);
+    friend bool operator==(const Position &a, const Position &b);
+    friend bool operator!=(const Position &a, const Position &b);
     
 private:
     NodeImpl *m_node;
     long m_offset;
 };
 
-inline bool operator==(const DOMPosition &a, const DOMPosition &b)
+inline bool operator==(const Position &a, const Position &b)
 {
     return a.node() == b.node() && a.offset() == b.offset();
 }
 
-inline bool operator!=(const DOMPosition &a, const DOMPosition &b)
+inline bool operator!=(const Position &a, const Position &b)
 {
     return !(a == b);
 }
 
-}; // namespace DOM
+} // namespace DOM
 
-#endif // _DOM_Position_h_
\ No newline at end of file
+#endif // __dom_position_h__
\ No newline at end of file
diff --git a/WebCore/khtml/xml/dom_positioniterator.cpp b/WebCore/khtml/xml/dom_positioniterator.cpp
index 22f7668..1caed18 100644
--- a/WebCore/khtml/xml/dom_positioniterator.cpp
+++ b/WebCore/khtml/xml/dom_positioniterator.cpp
@@ -29,9 +29,9 @@
 
 namespace DOM {
 
-DOMPosition EditIterator::peekPrevious() const
+Position EditIterator::peekPrevious() const
 {
-    DOMPosition pos = m_current;
+    Position pos = m_current;
     
     if (pos.isEmpty())
         return pos;
@@ -39,18 +39,18 @@ DOMPosition EditIterator::peekPrevious() const
     if (pos.offset() <= 0) {
         NodeImpl *prevNode = pos.node()->previousEditable();
         if (prevNode)
-            pos = DOMPosition(prevNode, prevNode->maxOffset());
+            pos = Position(prevNode, prevNode->maxOffset());
     }
     else {
-        pos = DOMPosition(pos.node(), pos.offset() - 1);
+        pos = Position(pos.node(), pos.offset() - 1);
     }
     
     return pos;
 }
 
-DOMPosition EditIterator::peekNext() const
+Position EditIterator::peekNext() const
 {
-    DOMPosition pos = m_current;
+    Position pos = m_current;
     
     if (pos.isEmpty())
         return pos;
@@ -58,10 +58,10 @@ DOMPosition EditIterator::peekNext() const
     if (pos.offset() >= pos.node()->maxOffset()) {
         NodeImpl *nextNode = pos.node()->nextEditable();
         if (nextNode)
-            pos = DOMPosition(nextNode, 0);
+            pos = Position(nextNode, 0);
     }
     else {
-        pos = DOMPosition(pos.node(), pos.offset() + 1);
+        pos = Position(pos.node(), pos.offset() + 1);
     }
     
     return pos;
diff --git a/WebCore/khtml/xml/dom_positioniterator.h b/WebCore/khtml/xml/dom_positioniterator.h
index 60a3928..8e4aa0f 100644
--- a/WebCore/khtml/xml/dom_positioniterator.h
+++ b/WebCore/khtml/xml/dom_positioniterator.h
@@ -30,30 +30,30 @@
 
 namespace DOM {
 
-class DOMPosition;
 class NodeImpl;
+class Position;
 
 class EditIterator
 {
 public:
     EditIterator() : m_current() {}
     EditIterator(NodeImpl *node, long offset) : m_current(node, offset) {}
-    EditIterator(const DOMPosition &o) : m_current(o) {}
+    EditIterator(const Position &o) : m_current(o) {}
 
-    DOMPosition current() const { return m_current; }
-    DOMPosition previous() { return m_current = peekPrevious(); }
-    DOMPosition next() { return m_current = peekNext(); }
-    DOMPosition peekPrevious() const;
-    DOMPosition peekNext() const;
+    Position current() const { return m_current; }
+    Position previous() { return m_current = peekPrevious(); }
+    Position next() { return m_current = peekNext(); }
+    Position peekPrevious() const;
+    Position peekNext() const;
 
-    void setPosition(const DOMPosition &pos) { m_current = pos; }
+    void setPosition(const Position &pos) { m_current = pos; }
 
     bool atStart() const;
     bool atEnd() const;
     bool isEmpty() const { return m_current.isEmpty(); }
 
 private:
-    DOMPosition m_current;
+    Position m_current;
 };
 
 } // namespace DOM
diff --git a/WebCore/khtml/xml/dom_selection.cpp b/WebCore/khtml/xml/dom_selection.cpp
index 82dc803..e59b11f 100644
--- a/WebCore/khtml/xml/dom_selection.cpp
+++ b/WebCore/khtml/xml/dom_selection.cpp
@@ -23,7 +23,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
   
-#include "khtml_selection.h"
+#include "dom_selection.h"
 
 #include "htmltags.h"
 #include "khtml_part.h"
@@ -52,15 +52,8 @@
 #define EDIT_DEBUG 0
 #endif
 
-using DOM::DocumentImpl;
-using DOM::DOMPosition;
-using DOM::DOMString;
-using DOM::EditIterator;
-using DOM::ElementImpl;
-using DOM::Node;
-using DOM::NodeImpl;
-using DOM::Range;
-using DOM::TextImpl;
+namespace DOM {
+
 using khtml::InlineTextBox;
 using khtml::RenderObject;
 using khtml::RenderText;
@@ -68,16 +61,16 @@ using khtml::RenderText;
 #if APPLE_CHANGES
 static bool firstRunAt(RenderObject *renderNode, int y, NodeImpl *&startNode, long &startOffset);
 static bool lastRunAt(RenderObject *renderNode, int y, NodeImpl *&endNode, long &endOffset);
-static bool startAndEndLineNodesIncludingNode(DOM::NodeImpl *node, int offset, KHTMLSelection &selection);
+static bool startAndEndLineNodesIncludingNode(DOM::NodeImpl *node, int offset, Selection &selection);
 #endif
 
 
-KHTMLSelection::KHTMLSelection()
+Selection::Selection()
 {
     init();
 }
 
-KHTMLSelection::KHTMLSelection(NodeImpl *node, long offset)
+Selection::Selection(NodeImpl *node, long offset)
 {
     init();
 
@@ -89,7 +82,7 @@ KHTMLSelection::KHTMLSelection(NodeImpl *node, long offset)
     validate();
 }
 
-KHTMLSelection::KHTMLSelection(const DOMPosition &pos)
+Selection::Selection(const Position &pos)
 {
     init();
 
@@ -101,7 +94,7 @@ KHTMLSelection::KHTMLSelection(const DOMPosition &pos)
     validate();
 }
 
-KHTMLSelection::KHTMLSelection(const DOMPosition &base, const DOMPosition &extent)
+Selection::Selection(const Position &base, const Position &extent)
 {
     init();
 
@@ -113,7 +106,7 @@ KHTMLSelection::KHTMLSelection(const DOMPosition &base, const DOMPosition &exten
     validate();
 }
 
-KHTMLSelection::KHTMLSelection(NodeImpl *baseNode, long baseOffset, NodeImpl *endNode, long endOffset)
+Selection::Selection(NodeImpl *baseNode, long baseOffset, NodeImpl *endNode, long endOffset)
 {
     init();
 
@@ -125,7 +118,7 @@ KHTMLSelection::KHTMLSelection(NodeImpl *baseNode, long baseOffset, NodeImpl *en
     validate();
 }
 
-KHTMLSelection::KHTMLSelection(const KHTMLSelection &o)
+Selection::Selection(const Selection &o)
 {
     init();
     
@@ -157,7 +150,7 @@ KHTMLSelection::KHTMLSelection(const KHTMLSelection &o)
     }
 }
 
-void KHTMLSelection::init()
+void Selection::init()
 {
     m_baseNode = 0;
     m_baseOffset = 0;
@@ -176,7 +169,7 @@ void KHTMLSelection::init()
     m_modifyBiasSet = false;
 }
 
-KHTMLSelection::~KHTMLSelection()
+Selection::~Selection()
 {
     if (m_baseNode)
         m_baseNode->deref();
@@ -188,7 +181,7 @@ KHTMLSelection::~KHTMLSelection()
         m_endNode->deref();
 }
 
-KHTMLSelection &KHTMLSelection::operator=(const KHTMLSelection &o)
+Selection &Selection::operator=(const Selection &o)
 {
 	setBaseNode(o.baseNode());
 	setExtentNode(o.extentNode());
@@ -220,28 +213,28 @@ KHTMLSelection &KHTMLSelection::operator=(const KHTMLSelection &o)
     return *this;
 }
 
-void KHTMLSelection::moveTo(DOM::NodeImpl *node, long offset)
+void Selection::moveTo(DOM::NodeImpl *node, long offset)
 {
     moveTo(node, offset, node, offset);
 }
 
-void KHTMLSelection::moveTo(const DOM::Range &r)
+void Selection::moveTo(const DOM::Range &r)
 {
 	moveTo(r.startContainer().handle(), r.startOffset(), 
 		r.endContainer().handle(), r.endOffset());
 }
 
-void KHTMLSelection::moveTo(const DOM::DOMPosition &pos)
+void Selection::moveTo(const DOM::Position &pos)
 {
 	moveTo(pos.node(), pos.offset());
 }
 
-void KHTMLSelection::moveTo(const KHTMLSelection &o)
+void Selection::moveTo(const Selection &o)
 {
 	moveTo(o.baseNode(), o.baseOffset(), o.extentNode(), o.extentOffset());
 }
 
-void KHTMLSelection::moveTo(DOM::NodeImpl *baseNode, long baseOffset, DOM::NodeImpl *extentNode, long extentOffset)
+void Selection::moveTo(DOM::NodeImpl *baseNode, long baseOffset, DOM::NodeImpl *extentNode, long extentOffset)
 {
 	setBaseNode(baseNode);
 	setExtentNode(extentNode);
@@ -250,9 +243,9 @@ void KHTMLSelection::moveTo(DOM::NodeImpl *baseNode, long baseOffset, DOM::NodeI
 	validate();
 }
 
-bool KHTMLSelection::modify(EAlter alter, EDirection dir, ETextGranularity granularity)
+bool Selection::modify(EAlter alter, EDirection dir, ETextGranularity granularity)
 {
-    DOMPosition pos;
+    Position pos;
     
     switch (dir) {
         // EDIT FIXME: This needs to handle bidi
@@ -364,7 +357,7 @@ bool KHTMLSelection::modify(EAlter alter, EDirection dir, ETextGranularity granu
     return true;
 }
 
-bool KHTMLSelection::expandUsingGranularity(ETextGranularity granularity)
+bool Selection::expandUsingGranularity(ETextGranularity granularity)
 {
     if (state() == NONE)
         return false;
@@ -373,14 +366,14 @@ bool KHTMLSelection::expandUsingGranularity(ETextGranularity granularity)
     return true;
 }
 
-int KHTMLSelection::xPosForVerticalArrowNavigation(EPositionType type, bool recalc) const
+int Selection::xPosForVerticalArrowNavigation(EPositionType type, bool recalc) const
 {
     int x = 0;
 
     if (state() == NONE)
         return x;
 
-    DOMPosition pos;
+    Position pos;
     switch (type) {
         case START:
             pos = startPosition();
@@ -412,7 +405,7 @@ int KHTMLSelection::xPosForVerticalArrowNavigation(EPositionType type, bool reca
     return x;
 }
 
-void KHTMLSelection::clear()
+void Selection::clear()
 {
 	setBaseNode(0);
 	setExtentNode(0);
@@ -421,26 +414,26 @@ void KHTMLSelection::clear()
 	validate();
 }
 
-void KHTMLSelection::setBase(DOM::NodeImpl *node, long offset)
+void Selection::setBase(DOM::NodeImpl *node, long offset)
 {
 	setBaseNode(node);
 	setBaseOffset(offset);
 	validate();
 }
 
-void KHTMLSelection::setExtent(DOM::NodeImpl *node, long offset)
+void Selection::setExtent(DOM::NodeImpl *node, long offset)
 {
 	setExtentNode(node);
 	setExtentOffset(offset);
 	validate();
 }
 
-void KHTMLSelection::setNeedsLayout(bool flag)
+void Selection::setNeedsLayout(bool flag)
 {
     m_needsCaretLayout = flag;
 }
 
-Range KHTMLSelection::toRange() const
+Range Selection::toRange() const
 {
     if (isEmpty())
         return Range();
@@ -448,7 +441,7 @@ Range KHTMLSelection::toRange() const
     return Range(Node(startNode()), startOffset(), Node(endNode()), endOffset());
 }
 
-void KHTMLSelection::layoutCaret()
+void Selection::layoutCaret()
 {
     if (isEmpty() || !startNode()->renderer()) {
         m_caretX = m_caretY = m_caretSize = 0;
@@ -461,13 +454,13 @@ void KHTMLSelection::layoutCaret()
     m_needsCaretLayout = false;
 }
 
-QRect KHTMLSelection::getRepaintRect()
+QRect Selection::getRepaintRect()
 {
     // EDIT FIXME: fudge a bit to make sure we don't leave behind artifacts
     return QRect(m_caretX - 1, m_caretY - 1, 3, m_caretSize + 2);
 }
 
-void KHTMLSelection::needsCaretRepaint()
+void Selection::needsCaretRepaint()
 {
     if (isEmpty())
         return;
@@ -500,7 +493,7 @@ void KHTMLSelection::needsCaretRepaint()
     v->updateContents(getRepaintRect(), false);
 }
 
-void KHTMLSelection::paintCaret(QPainter *p, const QRect &rect)
+void Selection::paintCaret(QPainter *p, const QRect &rect)
 {
     if (isEmpty())
         return;
@@ -509,7 +502,7 @@ void KHTMLSelection::paintCaret(QPainter *p, const QRect &rect)
         return;
 
     if (m_needsCaretLayout) {
-        DOMPosition pos = DOMPosition(startNode(), startOffset());
+        Position pos = Position(startNode(), startOffset());
         if (!pos.inRenderedContent()) {
             moveToRenderedContent();
         }
@@ -527,7 +520,7 @@ void KHTMLSelection::paintCaret(QPainter *p, const QRect &rect)
     }
 }
 
-void KHTMLSelection::setBaseNode(DOM::NodeImpl *node)
+void Selection::setBaseNode(DOM::NodeImpl *node)
 {
 	if (m_baseNode == node)
 		return;
@@ -541,12 +534,12 @@ void KHTMLSelection::setBaseNode(DOM::NodeImpl *node)
 		m_baseNode->ref();
 }
 
-void KHTMLSelection::setBaseOffset(long offset)
+void Selection::setBaseOffset(long offset)
 {
 	m_baseOffset = offset;
 }
 
-void KHTMLSelection::setExtentNode(DOM::NodeImpl *node)
+void Selection::setExtentNode(DOM::NodeImpl *node)
 {
 	if (m_extentNode == node)
 		return;
@@ -560,12 +553,12 @@ void KHTMLSelection::setExtentNode(DOM::NodeImpl *node)
 		m_extentNode->ref();
 }
 	
-void KHTMLSelection::setExtentOffset(long offset)
+void Selection::setExtentOffset(long offset)
 {
 	m_extentOffset = offset;
 }
 
-void KHTMLSelection::setStartNode(DOM::NodeImpl *node)
+void Selection::setStartNode(DOM::NodeImpl *node)
 {
 	if (m_startNode == node)
 		return;
@@ -579,12 +572,12 @@ void KHTMLSelection::setStartNode(DOM::NodeImpl *node)
 		m_startNode->ref();
 }
 
-void KHTMLSelection::setStartOffset(long offset)
+void Selection::setStartOffset(long offset)
 {
 	m_startOffset = offset;
 }
 
-void KHTMLSelection::setEndNode(DOM::NodeImpl *node)
+void Selection::setEndNode(DOM::NodeImpl *node)
 {
 	if (m_endNode == node)
 		return;
@@ -598,17 +591,17 @@ void KHTMLSelection::setEndNode(DOM::NodeImpl *node)
 		m_endNode->ref();
 }
 	
-void KHTMLSelection::setEndOffset(long offset)
+void Selection::setEndOffset(long offset)
 {
 	m_endOffset = offset;
 }
 
-void KHTMLSelection::validate(ETextGranularity granularity)
+void Selection::validate(ETextGranularity granularity)
 {
     // move the base and extent nodes to their equivalent leaf positions
     bool baseAndExtentEqual = m_baseNode == m_extentNode && m_baseOffset == m_extentOffset;
     if (m_baseNode) {
-        DOMPosition pos = basePosition().equivalentLeafPosition();
+        Position pos = basePosition().equivalentLeafPosition();
         m_baseNode = pos.node();
         m_baseOffset = pos.offset();
         if (baseAndExtentEqual) {
@@ -617,7 +610,7 @@ void KHTMLSelection::validate(ETextGranularity granularity)
         }
     }
     if (m_extentNode && !baseAndExtentEqual) {
-        DOMPosition pos = extentPosition().equivalentLeafPosition();
+        Position pos = extentPosition().equivalentLeafPosition();
         m_extentNode = pos.node();
         m_extentOffset = pos.offset();
     }
@@ -712,8 +705,8 @@ void KHTMLSelection::validate(ETextGranularity granularity)
         }
     }
     else {  // granularity == LINE
-        KHTMLSelection baseSelection = *this;
-        KHTMLSelection extentSelection = *this;
+        Selection baseSelection = *this;
+        Selection extentSelection = *this;
         if (m_baseNode && (m_baseNode->nodeType() == Node::TEXT_NODE || m_baseNode->nodeType() == Node::CDATA_SECTION_NODE)) {
             if (startAndEndLineNodesIncludingNode(m_baseNode, m_baseOffset, baseSelection)) {
                 setStartNode(baseSelection.baseNode());
@@ -760,7 +753,7 @@ void KHTMLSelection::validate(ETextGranularity granularity)
 #endif
 }
 
-bool KHTMLSelection::moveToRenderedContent()
+bool Selection::moveToRenderedContent()
 {
     if (isEmpty())
         return false;
@@ -768,19 +761,19 @@ bool KHTMLSelection::moveToRenderedContent()
     if (m_state != CARET)
         return false;
 
-    DOMPosition pos = DOMPosition(startNode(), startOffset());
+    Position pos = Position(startNode(), startOffset());
     if (pos.inRenderedContent())
         return true;
         
     // not currently rendered, try moving to prev
-    DOMPosition prev = pos.previousCharacterPosition();
+    Position prev = pos.previousCharacterPosition();
     if (prev != pos && prev.node()->inSameContainingEditableBlock(pos.node())) {
         moveTo(prev);
         return true;
     }
 
     // could not be moved to prev, try next
-    DOMPosition next = pos.nextCharacterPosition();
+    Position next = pos.nextCharacterPosition();
     if (next != pos && next.node()->inSameContainingEditableBlock(pos.node())) {
         moveTo(next);
         return true;
@@ -789,27 +782,27 @@ bool KHTMLSelection::moveToRenderedContent()
     return false;
 }
 
-DOMPosition KHTMLSelection::basePosition() const
+Position Selection::basePosition() const
 {
-    return DOMPosition(baseNode(), baseOffset());
+    return Position(baseNode(), baseOffset());
 }
 
-DOMPosition KHTMLSelection::extentPosition() const
+Position Selection::extentPosition() const
 {
-    return DOMPosition(extentNode(), extentOffset());
+    return Position(extentNode(), extentOffset());
 }
 
-DOMPosition KHTMLSelection::startPosition() const
+Position Selection::startPosition() const
 {
-    return DOMPosition(startNode(), startOffset());
+    return Position(startNode(), startOffset());
 }
 
-DOMPosition KHTMLSelection::endPosition() const
+Position Selection::endPosition() const
 {
-    return DOMPosition(endNode(), endOffset());
+    return Position(endNode(), endOffset());
 }
 
-bool KHTMLSelection::nodeIsBeforeNode(NodeImpl *n1, NodeImpl *n2) 
+bool Selection::nodeIsBeforeNode(NodeImpl *n1, NodeImpl *n2) 
 {
 	if (!n1 || !n2) 
 		return true;
@@ -921,7 +914,7 @@ static bool lastRunAt(RenderObject *renderNode, int y, NodeImpl *&endNode, long
     }
 }
 
-static bool startAndEndLineNodesIncludingNode(DOM::NodeImpl *node, int offset, KHTMLSelection &selection)
+static bool startAndEndLineNodesIncludingNode(DOM::NodeImpl *node, int offset, Selection &selection)
 {
     if (node && (node->nodeType() == Node::TEXT_NODE || node->nodeType() == Node::CDATA_SECTION_NODE)) {
         int pos;
@@ -964,7 +957,7 @@ static bool startAndEndLineNodesIncludingNode(DOM::NodeImpl *node, int offset, K
     return false;
 }
 
-void KHTMLSelection::debugRenderer(RenderObject *r, bool selected) const
+void Selection::debugRenderer(RenderObject *r, bool selected) const
 {
     if (r->node()->isElementNode()) {
         ElementImpl *element = static_cast<ElementImpl *>(r->node());
@@ -1037,7 +1030,7 @@ void KHTMLSelection::debugRenderer(RenderObject *r, bool selected) const
     }
 }
 
-void KHTMLSelection::debugPosition() const
+void Selection::debugPosition() const
 {
     if (!startNode())
         return;
@@ -1046,20 +1039,20 @@ void KHTMLSelection::debugPosition() const
     
     //RenderObject *r = 0;
 
-    fprintf(stderr, "KHTMLSelection =================\n");
+    fprintf(stderr, "Selection =================\n");
 
     if (startPosition() == endPosition()) {
-        DOMPosition pos = startPosition();
-        DOMPosition upstream = pos.equivalentUpstreamPosition();
-        DOMPosition downstream = pos.equivalentDownstreamPosition();
+        Position pos = startPosition();
+        Position upstream = pos.equivalentUpstreamPosition();
+        Position downstream = pos.equivalentDownstreamPosition();
         fprintf(stderr, "upstream:   %s %p:%d\n", getTagName(upstream.node()->id()).string().latin1(), upstream.node(), upstream.offset());
         fprintf(stderr, "pos:        %s %p:%d\n", getTagName(pos.node()->id()).string().latin1(), pos.node(), pos.offset());
         fprintf(stderr, "downstream: %s %p:%d\n", getTagName(downstream.node()->id()).string().latin1(), downstream.node(), downstream.offset());
     }
     else {
-        DOMPosition pos = startPosition();
-        DOMPosition upstream = pos.equivalentUpstreamPosition();
-        DOMPosition downstream = pos.equivalentDownstreamPosition();
+        Position pos = startPosition();
+        Position upstream = pos.equivalentUpstreamPosition();
+        Position downstream = pos.equivalentDownstreamPosition();
         fprintf(stderr, "upstream:   %s %p:%d\n", getTagName(upstream.node()->id()).string().latin1(), upstream.node(), upstream.offset());
         fprintf(stderr, "start:      %s %p:%d\n", getTagName(pos.node()->id()).string().latin1(), pos.node(), pos.offset());
         fprintf(stderr, "downstream: %s %p:%d\n", getTagName(downstream.node()->id()).string().latin1(), downstream.node(), downstream.offset());
@@ -1113,3 +1106,5 @@ void KHTMLSelection::debugPosition() const
 }
 
 #endif
+
+} // namespace DOM
diff --git a/WebCore/khtml/xml/dom_selection.h b/WebCore/khtml/xml/dom_selection.h
index 326a0ea..01fcb1b 100644
--- a/WebCore/khtml/xml/dom_selection.h
+++ b/WebCore/khtml/xml/dom_selection.h
@@ -23,33 +23,33 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-#ifndef __khtml_selection_h__
-#define __khtml_selection_h__
+#ifndef __dom_selection_h__
+#define __dom_selection_h__
 
 class KHTMLPart;
 class QPainter;
 class QRect;
 
-namespace DOM {
-    class DOMPosition;
-    class NodeImpl;
-    class Range;
-};
-
 namespace khtml {
     class RenderObject;
 }
 
-class KHTMLSelection
+namespace DOM {
+
+class NodeImpl;
+class Position;
+class Range;
+
+class Selection
 {
 public:
-    KHTMLSelection();
-    KHTMLSelection(DOM::NodeImpl *node, long offset);
-    KHTMLSelection(const DOM::DOMPosition &);
-    KHTMLSelection(const DOM::DOMPosition &, const DOM::DOMPosition &);
-    KHTMLSelection(DOM::NodeImpl *startNode, long startOffset, DOM::NodeImpl *endNode, long endOffset);
-    KHTMLSelection(const KHTMLSelection &);
-    ~KHTMLSelection();
+    Selection();
+    Selection(NodeImpl *node, long offset);
+    Selection(const Position &);
+    Selection(const Position &, const Position &);
+    Selection(NodeImpl *startNode, long startOffset, NodeImpl *endNode, long endOffset);
+    Selection(const Selection &);
+    ~Selection();
 
 	enum EState { NONE, CARET, RANGE };
 	enum EAlter { MOVE, EXTEND };
@@ -58,52 +58,52 @@ public:
 
 	EState state() const { return m_state; }
 
-    void moveTo(DOM::NodeImpl *node, long offset);
-    void moveTo(const DOM::Range &);
-    void moveTo(const DOM::DOMPosition &);
-    void moveTo(const KHTMLSelection &);
-    void moveTo(DOM::NodeImpl *baseNode, long baseOffset, DOM::NodeImpl *extentNode, long extentOffset);
+    void moveTo(NodeImpl *node, long offset);
+    void moveTo(const Range &);
+    void moveTo(const Position &);
+    void moveTo(const Selection &);
+    void moveTo(NodeImpl *baseNode, long baseOffset, NodeImpl *extentNode, long extentOffset);
     bool modify(EAlter, EDirection, ETextGranularity);
     bool expandUsingGranularity(ETextGranularity);
     void clear();
 
     bool moveToRenderedContent();
     
-    void setBase(DOM::NodeImpl *node, long offset);
-    void setExtent(DOM::NodeImpl *node, long offset);
+    void setBase(NodeImpl *node, long offset);
+    void setExtent(NodeImpl *node, long offset);
 
-    DOM::NodeImpl *baseNode() const { return m_baseNode; }
+    NodeImpl *baseNode() const { return m_baseNode; }
     long baseOffset() const { return m_baseOffset; }
 
-    DOM::NodeImpl *extentNode() const { return m_extentNode; }
+    NodeImpl *extentNode() const { return m_extentNode; }
     long extentOffset() const { return m_extentOffset; }
 
-    DOM::NodeImpl *startNode() const { return m_startNode; }
+    NodeImpl *startNode() const { return m_startNode; }
     long startOffset() const { return m_startOffset; }
 
-    DOM::NodeImpl *endNode() const { return m_endNode; }
+    NodeImpl *endNode() const { return m_endNode; }
     long endOffset() const { return m_endOffset; }
 
-    DOM::DOMPosition basePosition() const;
-    DOM::DOMPosition extentPosition() const;
-    DOM::DOMPosition startPosition() const;
-    DOM::DOMPosition endPosition() const;
+    Position basePosition() const;
+    Position extentPosition() const;
+    Position startPosition() const;
+    Position endPosition() const;
 
     void setNeedsLayout(bool flag=true);
     void clearModifyBias() { m_modifyBiasSet = false; }
     
     bool isEmpty() const { return state() == NONE; }
     bool notEmpty() const { return !isEmpty(); }
-    DOM::Range toRange() const;
+    Range toRange() const;
 
     
     void debugPosition() const;
     void debugRenderer(khtml::RenderObject *r, bool selected) const;
 
-    KHTMLSelection &operator=(const KHTMLSelection &o);
+    Selection &operator=(const Selection &o);
     
-    friend bool operator==(const KHTMLSelection &a, const KHTMLSelection &b);
-    friend bool operator!=(const KHTMLSelection &a, const KHTMLSelection &b);
+    friend bool operator==(const Selection &a, const Selection &b);
+    friend bool operator!=(const Selection &a, const Selection &b);
     
     friend class KHTMLPart;
 
@@ -118,29 +118,29 @@ private:
     QRect getRepaintRect();
     void paintCaret(QPainter *p, const QRect &rect);
 
-	void setBaseNode(DOM::NodeImpl *);
+	void setBaseNode(NodeImpl *);
 	void setBaseOffset(long);
-	void setExtentNode(DOM::NodeImpl *);
+	void setExtentNode(NodeImpl *);
 	void setExtentOffset(long);
 
-	void setStartNode(DOM::NodeImpl *);
+	void setStartNode(NodeImpl *);
 	void setStartOffset(long);
-	void setEndNode(DOM::NodeImpl *);
+	void setEndNode(NodeImpl *);
 	void setEndOffset(long);
 
-    bool nodeIsBeforeNode(DOM::NodeImpl *n1, DOM::NodeImpl *n2);
+    bool nodeIsBeforeNode(NodeImpl *n1, NodeImpl *n2);
 
     void calculateStartAndEnd(ETextGranularity select=CHARACTER);
     int xPosForVerticalArrowNavigation(EPositionType, bool recalc=false) const;
     
-    DOM::NodeImpl *m_baseNode;    // base node for the selection
+    NodeImpl *m_baseNode;    // base node for the selection
     long m_baseOffset;            // offset into base node where selection is
-    DOM::NodeImpl *m_extentNode;  // extent node for the selection
+    NodeImpl *m_extentNode;  // extent node for the selection
     long m_extentOffset;          // offset into extent node where selection is
 
-    DOM::NodeImpl *m_startNode;   // start node for the selection (read-only)
+    NodeImpl *m_startNode;   // start node for the selection (read-only)
     long m_startOffset;           // offset into start node where selection is (read-only)
-    DOM::NodeImpl *m_endNode;     // end node for the selection (read-only)
+    NodeImpl *m_endNode;     // end node for the selection (read-only)
     long m_endOffset;             // offset into end node where selection is (read-only)
 
 	EState m_state;               // the state of the selection
@@ -155,15 +155,17 @@ private:
 };
 
 
-inline bool operator==(const KHTMLSelection &a, const KHTMLSelection &b)
+inline bool operator==(const Selection &a, const Selection &b)
 {
     return a.startNode() == b.startNode() && a.startOffset() == b.startOffset() &&
         a.endNode() == b.endNode() && a.endOffset() == b.endOffset();
 }
 
-inline bool operator!=(const KHTMLSelection &a, const KHTMLSelection &b)
+inline bool operator!=(const Selection &a, const Selection &b)
 {
     return !(a == b);
 }
 
-#endif
\ No newline at end of file
+} // namespace DOM
+
+#endif  // __dom_selection_h__
\ No newline at end of file
diff --git a/WebCore/kwq/KWQKHTMLPart.mm b/WebCore/kwq/KWQKHTMLPart.mm
index 41cc5f7..e8ae832 100644
--- a/WebCore/kwq/KWQKHTMLPart.mm
+++ b/WebCore/kwq/KWQKHTMLPart.mm
@@ -43,7 +43,6 @@
 #import "htmltokenizer.h"
 #import "khtmlpart_p.h"
 #import "khtmlview.h"
-#import "khtml_selection.h"
 #import "kjs_binding.h"
 #import "kjs_window.h"
 #import "misc/htmlattrs.h"
@@ -55,6 +54,7 @@
 #import "render_style.h"
 #import "render_table.h"
 #import "render_text.h"
+#import "xml/dom_selection.h"
 #import "xml/dom2_eventsimpl.h"
 #import "xml/dom2_rangeimpl.h"
 #import <JavaScriptCore/identifier.h>
@@ -78,6 +78,7 @@ using DOM::HTMLTableCellElementImpl;
 using DOM::Node;
 using DOM::NodeImpl;
 using DOM::RangeImpl;
+using DOM::Selection;
 
 using khtml::Cache;
 using khtml::ChildFrame;
@@ -1847,7 +1848,7 @@ void KWQKHTMLPart::khtmlMouseMoveEvent(MouseMoveEvent *event)
         }
 
 	if (_mouseDownMayStartDrag && 
-        d->m_textElement == KHTMLSelection::CHARACTER &&
+        d->m_textElement == DOM::Selection::CHARACTER &&
         [_bridge mayStartDragWithMouseDragged:_currentEvent]) {
             // We are starting a text/image/url drag, so the cursor should be an arrow
             d->m_view->resetCursor();
diff --git a/WebCore/kwq/KWQRenderTreeDebug.cpp b/WebCore/kwq/KWQRenderTreeDebug.cpp
index 5a3e21d..aa038c6 100644
--- a/WebCore/kwq/KWQRenderTreeDebug.cpp
+++ b/WebCore/kwq/KWQRenderTreeDebug.cpp
@@ -27,7 +27,6 @@
 
 #include "htmltags.h"
 #include "khtmlview.h"
-#include "khtml_selection.h"
 #include "render_replaced.h"
 #include "render_table.h"
 #include "render_text.h"
@@ -35,13 +34,15 @@
 #include "xml/dom_docimpl.h"
 #include "xml/dom_nodeimpl.h"
 #include "xml/dom_position.h"
+#include "xml/dom_selection.h"
 
 #include "KWQKHTMLPart.h"
 #include "KWQTextStream.h"
 
 using DOM::DocumentImpl;
-using DOM::DOMPosition;
 using DOM::NodeImpl;
+using DOM::Position;
+using DOM::Selection;
 using khtml::RenderLayer;
 using khtml::RenderObject;
 using khtml::RenderTableCell;
@@ -354,24 +355,24 @@ static void writeSelection(QTextStream &ts, const RenderObject *o)
     if (!doc || !doc->part())
         return;
         
-    KHTMLSelection selection = doc->part()->selection();
-    if (selection.state() == KHTMLSelection::NONE)
+    Selection selection = doc->part()->selection();
+    if (selection.state() == Selection::NONE)
         return;
 
     if (!selection.startPosition().node()->isContentEditable() || !selection.endPosition().node()->isContentEditable())
         return;
 
-    DOMPosition startPosition = selection.startPosition();
-    DOMPosition endPosition = selection.endPosition();
+    Position startPosition = selection.startPosition();
+    Position endPosition = selection.endPosition();
 
     QString startNodeTagName(getTagName(startPosition.node()->id()).string());
     QString endNodeTagName(getTagName(endPosition.node()->id()).string());
     
     NodeImpl *rootNode = doc->getElementById("root");
     
-    if (selection.state() == KHTMLSelection::CARET) {
-        DOMPosition upstream = startPosition.equivalentUpstreamPosition();
-        DOMPosition downstream = startPosition.equivalentDownstreamPosition();
+    if (selection.state() == Selection::CARET) {
+        Position upstream = startPosition.equivalentUpstreamPosition();
+        Position downstream = startPosition.equivalentDownstreamPosition();
         QString positionString = nodePositionRelativeToRoot(startPosition.node(), rootNode);
         QString upstreamString = nodePositionRelativeToRoot(upstream.node(), rootNode);
         QString downstreamString = nodePositionRelativeToRoot(downstream.node(), rootNode);
@@ -380,16 +381,16 @@ static void writeSelection(QTextStream &ts, const RenderObject *o)
             "upstream:   position " << upstream.offset() << " of " << upstreamString << "\n"
             "downstream: position " << downstream.offset() << " of " << downstreamString << "\n"; 
     }
-    else if (selection.state() == KHTMLSelection::RANGE) {
+    else if (selection.state() == Selection::RANGE) {
         QString startString = nodePositionRelativeToRoot(startPosition.node(), rootNode);
-        DOMPosition upstreamStart = startPosition.equivalentUpstreamPosition();
+        Position upstreamStart = startPosition.equivalentUpstreamPosition();
         QString upstreamStartString = nodePositionRelativeToRoot(upstreamStart.node(), rootNode);
-        DOMPosition downstreamStart = startPosition.equivalentDownstreamPosition();
+        Position downstreamStart = startPosition.equivalentDownstreamPosition();
         QString downstreamStartString = nodePositionRelativeToRoot(downstreamStart.node(), rootNode);
         QString endString = nodePositionRelativeToRoot(endPosition.node(), rootNode);
-        DOMPosition upstreamEnd = endPosition.equivalentUpstreamPosition();
+        Position upstreamEnd = endPosition.equivalentUpstreamPosition();
         QString upstreamEndString = nodePositionRelativeToRoot(upstreamEnd.node(), rootNode);
-        DOMPosition downstreamEnd = endPosition.equivalentDownstreamPosition();
+        Position downstreamEnd = endPosition.equivalentDownstreamPosition();
         QString downstreamEndString = nodePositionRelativeToRoot(downstreamEnd.node(), rootNode);
         ts << "selection is RANGE:\n" <<
             "start:      position " << startPosition.offset() << " of " << startString << "\n" <<
diff --git a/WebCore/kwq/WebCoreBridge.mm b/WebCore/kwq/WebCoreBridge.mm
index 1317fb0..850a609 100644
--- a/WebCore/kwq/WebCoreBridge.mm
+++ b/WebCore/kwq/WebCoreBridge.mm
@@ -29,6 +29,7 @@
 #import "dom_node.h"
 #import "dom_docimpl.h"
 #import "dom_nodeimpl.h"
+#import "dom_selection.h"
 #import "dom2_rangeimpl.h"
 #import "htmlediting.h"
 #import "html_documentimpl.h"
@@ -37,7 +38,6 @@
 #import "htmlattrs.h"
 #import "htmltags.h"
 #import "khtml_part.h"
-#import "khtml_selection.h"
 #import "khtmlview.h"
 #import "kjs_proxy.h"
 #import "kjs_window.h"
@@ -89,6 +89,7 @@ using DOM::HTMLInputElementImpl;
 using DOM::Node;
 using DOM::NodeImpl;
 using DOM::Range;
+using DOM::Selection;
 
 using khtml::Decoder;
 using khtml::DeleteSelectionCommand;
@@ -406,7 +407,7 @@ static bool initializedKJS = FALSE;
         return NO;
     }
         
-    KHTMLSelection selection(node->positionForCoordinates((int)point.x, (int)point.y));
+    Selection selection(node->positionForCoordinates((int)point.x, (int)point.y));
     _part->setSelection(selection);
     
     return YES;
@@ -414,7 +415,7 @@ static bool initializedKJS = FALSE;
 
 - (BOOL)haveSelection
 {
-    return _part->selection().state() == KHTMLSelection::RANGE;
+    return _part->selection().state() == Selection::RANGE;
 }
 
 - (DOMRange *)selectedRange
@@ -1080,7 +1081,7 @@ static HTMLFormElementImpl *formElementFromDOMElement(DOMElement *element)
 {
     DOMNode *startNode = start;
     DOMNode *endNode = end;
-    KHTMLSelection selection([startNode _nodeImpl], startOffset, [endNode _nodeImpl], endOffset);
+    Selection selection([startNode _nodeImpl], startOffset, [endNode _nodeImpl], endOffset);
     _part->setSelection(selection);
 }
 
@@ -1322,10 +1323,10 @@ static HTMLFormElementImpl *formElementFromDOMElement(DOMElement *element)
         return nil;
         
     // NOTE: The enums *must* match the very similar ones declared in ktml_selection.h
-    KHTMLSelection selection(_part->selection());
-    selection.modify(static_cast<KHTMLSelection::EAlter>(alteration), 
-                     static_cast<KHTMLSelection::EDirection>(direction), 
-                     static_cast<KHTMLSelection::ETextGranularity>(granularity));
+    Selection selection(_part->selection());
+    selection.modify(static_cast<Selection::EAlter>(alteration), 
+                     static_cast<Selection::EDirection>(direction), 
+                     static_cast<Selection::ETextGranularity>(granularity));
     return [DOMRange _rangeWithImpl:selection.toRange().handle()];
 }
 
@@ -1335,10 +1336,10 @@ static HTMLFormElementImpl *formElementFromDOMElement(DOMElement *element)
         return;
         
     // NOTE: The enums *must* match the very similar ones declared in ktml_selection.h
-    KHTMLSelection selection(_part->selection());
-    selection.modify(static_cast<KHTMLSelection::EAlter>(alteration), 
-                     static_cast<KHTMLSelection::EDirection>(direction), 
-                     static_cast<KHTMLSelection::ETextGranularity>(granularity));
+    Selection selection(_part->selection());
+    selection.modify(static_cast<Selection::EAlter>(alteration), 
+                     static_cast<Selection::EDirection>(direction), 
+                     static_cast<Selection::ETextGranularity>(granularity));
 
     // save vertical navigation x position if necessary
     int xPos = _part->xPosForVerticalArrowNavigation();
@@ -1364,7 +1365,7 @@ static HTMLFormElementImpl *formElementFromDOMElement(DOMElement *element)
     
     DocumentImpl *doc = startContainer->getDocument();
     doc->updateLayout();
-    KHTMLSelection selection(startContainer, [range startOffset], endContainer, [range endOffset]);
+    Selection selection(startContainer, [range startOffset], endContainer, [range endOffset]);
     _part->setSelection(selection);
 }
 
@@ -1409,8 +1410,8 @@ static HTMLFormElementImpl *formElementFromDOMElement(DOMElement *element)
     if (!_part || !_part->xmlDocImpl())
         return;
     
-    KHTMLSelection selection(_part->selection());
-    if (selection.state() != KHTMLSelection::RANGE)
+    Selection selection(_part->selection());
+    if (selection.state() != Selection::RANGE)
         return;
     
     DeleteSelectionCommand cmd(_part->xmlDocImpl());

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list