WebCore:
authorcblu <cblu@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 24 May 2004 21:55:47 +0000 (21:55 +0000)
committercblu <cblu@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 24 May 2004 21:55:47 +0000 (21:55 +0000)
Improved editing via drag.

        Reviewed by kocienda.

        * khtml/editing/htmlediting.cpp: Renamed PasteMarkupCommand to ReplaceSelectionCommand
        (khtml::ReplaceSelectionCommand::ReplaceSelectionCommand):
        (khtml::ReplaceSelectionCommand::~ReplaceSelectionCommand):
        (khtml::ReplaceSelectionCommand::impl):
        (khtml::MoveSelectionCommand::MoveSelectionCommand):
        (khtml::MoveSelectionCommand::~MoveSelectionCommand):
        (khtml::MoveSelectionCommand::impl):
        * khtml/editing/htmlediting.h:
        (khtml::):
        * khtml/editing/htmlediting_impl.cpp:
        (khtml::ReplaceSelectionCommandImpl::ReplaceSelectionCommandImpl):
        (khtml::ReplaceSelectionCommandImpl::~ReplaceSelectionCommandImpl):
        (khtml::ReplaceSelectionCommandImpl::commandID):
        (khtml::ReplaceSelectionCommandImpl::doApply):
        (khtml::MoveSelectionCommandImpl::MoveSelectionCommandImpl): new command
        (khtml::MoveSelectionCommandImpl::~MoveSelectionCommandImpl):
        (khtml::MoveSelectionCommandImpl::commandID):
        (khtml::MoveSelectionCommandImpl::doApply):
        * khtml/editing/htmlediting_impl.h:
        * khtml/khtml_part.cpp:
        (KHTMLPart::dragCaret): new
        (KHTMLPart::setDragCaret): new
        (KHTMLPart::notifyDragCaretChanged): new
        (KHTMLPart::paintDragCaret): new
        * khtml/khtml_part.h:
        * khtml/khtmlpart_p.h:
        * khtml/rendering/render_block.cpp:
        (khtml::RenderBlock::paintObject): paint the drag caret
        * kwq/DOM.mm:
        (+[DOMDocumentFragment _documentFragmentWithImpl:]): made internally available
        (-[DOMDocumentFragment _fragmentImpl]):
        * kwq/DOMInternal.h:
        * kwq/WebCoreBridge.h:
        * kwq/WebCoreBridge.mm:
        (-[WebCoreBridge documentFragmentWithMarkupString:baseURLString:]): new
        (-[WebCoreBridge documentFragmentWithText:]): new
        (-[WebCoreBridge replaceSelectionWithFragment:selectReplacement:]): new
        (-[WebCoreBridge replaceSelectionWithNode:selectReplacement:]): renamed to take the selectReplacement BOOL
        (-[WebCoreBridge replaceSelectionWithMarkupString:baseURLString:selectReplacement:]): ditto
        (-[WebCoreBridge replaceSelectionWithText:selectReplacement:]): ditto
        (-[WebCoreBridge replaceSelectionWithNewline]): moved
        (-[WebCoreBridge setSelectionToDragCaret]): new
        (-[WebCoreBridge moveSelectionToDragCaret:]): new
        (-[WebCoreBridge moveDragCaretToPoint:]): set the drag caret, not the selection
        (-[WebCoreBridge removeDragCaret]): new

WebKit:

Improved editing via drag

        Reviewed by kocienda.

        * WebView.subproj/WebDataSource.m:
        (-[WebDataSource _documentFragmentWithImageResource:]): made this method return a fragment instead of replace the selection so that the caller do other things with the fragment
        (-[WebDataSource _documentFragmentWithArchive:]): ditto
        (-[WebDataSource _replaceSelectionWithArchive:selectReplacement:]): call renamed methods
        * WebView.subproj/WebDataSourcePrivate.h:
        * WebView.subproj/WebDocumentInternal.h:
        * WebView.subproj/WebHTMLView.m:
        (-[WebHTMLView _documentFragmentFromPasteboard:]): made this method return a fragment instead of replace the selection so that the caller do other things with the fragment
        (-[WebHTMLView _replaceSelectionWithPasteboard:selectReplacement:]): new
        (-[WebHTMLView paste:]): call _replaceSelectionWithPasteboard:selectReplacement:
        (-[WebHTMLView dragOperationForDraggingInfo:]): handle the case where the destination is editable, but the source is not
        (-[WebHTMLView draggingCancelledWithDraggingInfo:]): new, removes drag caret
        (-[WebHTMLView draggingUpdatedWithDraggingInfo:]): remove drag caret when we can't handle the drag
        (-[WebHTMLView concludeDragForDraggingInfo:]): instead of calling paste, move the selection when doing a move and replace the drag caret when doing a copy
        * WebView.subproj/WebHTMLViewPrivate.h:
        * WebView.subproj/WebView.m:
        (-[WebViewPrivate dealloc]):
        (-[WebView _setDraggingDocumentView:]): new
        (-[WebView _dragOperationForDraggingInfo:]): if the current dragging document view changes, tell the previous dragging document view that dragging cancelled
        (-[WebView draggingExited:]): new, tell the previous dragging document view that dragging cancelled
        (-[WebView concludeDragOperation:]): release the dragging document view
        (-[WebView replaceSelectionWithNode:]): pass the selectReplacement BOOL to the bridge
        (-[WebView replaceSelectionWithText:]): ditto
        (-[WebView replaceSelectionWithMarkupString:]): ditto
        (-[WebView replaceSelectionWithArchive:]): ditto
        (-[WebView pasteAsPlainText:]): ditto
        (-[WebView insertTab:]): ditto
        (-[WebView insertText:]): ditto
        * WebView.subproj/WebViewPrivate.h:

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

21 files changed:
WebCore/ChangeLog-2005-08-23
WebCore/khtml/editing/htmlediting.cpp
WebCore/khtml/editing/htmlediting.h
WebCore/khtml/editing/htmlediting_impl.cpp
WebCore/khtml/editing/htmlediting_impl.h
WebCore/khtml/khtml_part.cpp
WebCore/khtml/khtml_part.h
WebCore/khtml/khtmlpart_p.h
WebCore/khtml/rendering/render_block.cpp
WebCore/kwq/DOM.mm
WebCore/kwq/DOMInternal.h
WebCore/kwq/WebCoreBridge.h
WebCore/kwq/WebCoreBridge.mm
WebKit/ChangeLog
WebKit/WebView.subproj/WebDataSource.m
WebKit/WebView.subproj/WebDataSourcePrivate.h
WebKit/WebView.subproj/WebDocumentInternal.h
WebKit/WebView.subproj/WebHTMLView.m
WebKit/WebView.subproj/WebHTMLViewPrivate.h
WebKit/WebView.subproj/WebView.m
WebKit/WebView.subproj/WebViewPrivate.h

index 761f0895f9867667bca4d490545fc795d9a99d3f..794126abef0f0b143712ba0502b7e226deadcda2 100644 (file)
@@ -1,3 +1,55 @@
+2004-05-24  Chris Blumenberg  <cblu@apple.com>
+
+       Improved editing via drag.
+
+        Reviewed by kocienda.
+
+        * khtml/editing/htmlediting.cpp: Renamed PasteMarkupCommand to ReplaceSelectionCommand
+        (khtml::ReplaceSelectionCommand::ReplaceSelectionCommand):
+        (khtml::ReplaceSelectionCommand::~ReplaceSelectionCommand):
+        (khtml::ReplaceSelectionCommand::impl):
+        (khtml::MoveSelectionCommand::MoveSelectionCommand):
+        (khtml::MoveSelectionCommand::~MoveSelectionCommand):
+        (khtml::MoveSelectionCommand::impl):
+        * khtml/editing/htmlediting.h:
+        (khtml::):
+        * khtml/editing/htmlediting_impl.cpp:
+        (khtml::ReplaceSelectionCommandImpl::ReplaceSelectionCommandImpl):
+        (khtml::ReplaceSelectionCommandImpl::~ReplaceSelectionCommandImpl):
+        (khtml::ReplaceSelectionCommandImpl::commandID):
+        (khtml::ReplaceSelectionCommandImpl::doApply):
+        (khtml::MoveSelectionCommandImpl::MoveSelectionCommandImpl): new command
+        (khtml::MoveSelectionCommandImpl::~MoveSelectionCommandImpl):
+        (khtml::MoveSelectionCommandImpl::commandID):
+        (khtml::MoveSelectionCommandImpl::doApply):
+        * khtml/editing/htmlediting_impl.h:
+        * khtml/khtml_part.cpp:
+        (KHTMLPart::dragCaret): new
+        (KHTMLPart::setDragCaret): new
+        (KHTMLPart::notifyDragCaretChanged): new
+        (KHTMLPart::paintDragCaret): new
+        * khtml/khtml_part.h:
+        * khtml/khtmlpart_p.h:
+        * khtml/rendering/render_block.cpp:
+        (khtml::RenderBlock::paintObject): paint the drag caret
+        * kwq/DOM.mm:
+        (+[DOMDocumentFragment _documentFragmentWithImpl:]): made internally available
+        (-[DOMDocumentFragment _fragmentImpl]):
+        * kwq/DOMInternal.h:
+        * kwq/WebCoreBridge.h:
+        * kwq/WebCoreBridge.mm:
+        (-[WebCoreBridge documentFragmentWithMarkupString:baseURLString:]): new
+        (-[WebCoreBridge documentFragmentWithText:]): new
+        (-[WebCoreBridge replaceSelectionWithFragment:selectReplacement:]): new
+        (-[WebCoreBridge replaceSelectionWithNode:selectReplacement:]): renamed to take the selectReplacement BOOL
+        (-[WebCoreBridge replaceSelectionWithMarkupString:baseURLString:selectReplacement:]): ditto
+        (-[WebCoreBridge replaceSelectionWithText:selectReplacement:]): ditto
+        (-[WebCoreBridge replaceSelectionWithNewline]): moved
+        (-[WebCoreBridge setSelectionToDragCaret]): new
+        (-[WebCoreBridge moveSelectionToDragCaret:]): new
+        (-[WebCoreBridge moveDragCaretToPoint:]): set the drag caret, not the selection
+        (-[WebCoreBridge removeDragCaret]): new
+
 2004-05-24  Ken Kocienda  <kocienda@apple.com>
 
         Reviewed by John
index f0f958ae6beed391c8c443936cad8545dc23ce40..8d78d67e13c5604ba94018f3a096787ad00b0e00 100644 (file)
@@ -492,26 +492,37 @@ TextImpl *JoinTextNodesCommand::secondNode() const
 }
 
 //------------------------------------------------------------------------------------------
-// PasteMarkupCommand
+// ReplaceSelectionCommand
 
-PasteMarkupCommand::PasteMarkupCommand(DocumentImpl *document, const DOMString &markupString, const DOM::DOMString &baseURL
-    : CompositeEditCommand(new PasteMarkupCommandImpl(document, markupString, baseURL))
+ReplaceSelectionCommand::ReplaceSelectionCommand(DocumentImpl *document, DOM::DocumentFragmentImpl *fragment, bool selectReplacement
+    : CompositeEditCommand(new ReplaceSelectionCommandImpl(document, fragment, selectReplacement))
 {
 }
 
-PasteMarkupCommand::~PasteMarkupCommand() 
+ReplaceSelectionCommand::~ReplaceSelectionCommand() 
 {
 }
 
-PasteMarkupCommandImpl *PasteMarkupCommand::impl() const
+ReplaceSelectionCommandImpl *ReplaceSelectionCommand::impl() const
 {
-    return static_cast<PasteMarkupCommandImpl *>(get());
+    return static_cast<ReplaceSelectionCommandImpl *>(get());
 }
 
-DOMString PasteMarkupCommand::markupString() const
+//------------------------------------------------------------------------------------------
+// MoveSelectionCommand
+
+MoveSelectionCommand::MoveSelectionCommand(DocumentImpl *document, DOM::DocumentFragmentImpl *fragment, DOM::Position &position) 
+: CompositeEditCommand(new MoveSelectionCommandImpl(document, fragment, position))
 {
-    IF_IMPL_NULL_RETURN_ARG(DOMString());
-    return impl()->markupString();
+}
+
+MoveSelectionCommand::~MoveSelectionCommand() 
+{
+}
+
+MoveSelectionCommandImpl *MoveSelectionCommand::impl() const
+{
+    return static_cast<MoveSelectionCommandImpl *>(get());
 }
 
 //------------------------------------------------------------------------------------------
index d503964af5a28539698bed006856236d39e43e3d..8eb995541a9b6770423b4dcf742e48a9574ce0ad 100644 (file)
@@ -34,6 +34,7 @@
 
 namespace DOM {
     class CSSStyleDeclarationImpl;
+    class DocumentFragmentImpl;
     class DocumentImpl;
     class DOMString;
     class ElementImpl;
@@ -58,7 +59,8 @@ class InputTextCommandImpl;
 class InsertNodeBeforeCommandImpl;
 class InsertTextCommandImpl;
 class JoinTextNodesCommandImpl;
-class PasteMarkupCommandImpl;
+class MoveSelectionCommandImpl;
+class ReplaceSelectionCommandImpl;
 class RemoveCSSPropertyCommandImpl;
 class RemoveNodeAttributeCommandImpl;
 class RemoveNodeCommandImpl;
@@ -84,7 +86,8 @@ enum ECommandID {
     InsertNodeBeforeCommandID,
     InsertTextCommandID,
     JoinTextNodesCommandID,
-    PasteMarkupCommandID,
+    MoveSelectionCommandID,
+    ReplaceSelectionCommandID,
     RemoveCSSPropertyCommandID,
     RemoveNodeAttributeCommandID,
     RemoveNodeCommandID,
@@ -338,18 +341,29 @@ private:
 };
 
 //------------------------------------------------------------------------------------------
-// PasteMarkupCommand
+// ReplaceSelectionCommand
 
-class PasteMarkupCommand : public CompositeEditCommand
+class ReplaceSelectionCommand : public CompositeEditCommand
 {
 public:
-    PasteMarkupCommand(DOM::DocumentImpl *document, const DOM::DOMString &markupString, const DOM::DOMString &baseURL);
-    virtual ~PasteMarkupCommand();
+    ReplaceSelectionCommand(DOM::DocumentImpl *document, DOM::DocumentFragmentImpl *fragment, bool selectReplacement=true);
+    virtual ~ReplaceSelectionCommand();
 
-    DOM::DOMString markupString() const;
+private:
+    inline ReplaceSelectionCommandImpl *impl() const;
+};
+
+//------------------------------------------------------------------------------------------
+// MoveSelectionCommand
 
+class MoveSelectionCommand : public CompositeEditCommand
+{
+public:
+    MoveSelectionCommand(DOM::DocumentImpl *document, DOM::DocumentFragmentImpl *fragment, DOM::Position &position);
+    virtual ~MoveSelectionCommand();
+    
 private:
-    inline PasteMarkupCommandImpl *impl() const;
+        inline MoveSelectionCommandImpl *impl() const;
 };
 
 //------------------------------------------------------------------------------------------
index d2156f70f368a36f681070a684026ed938cf73e1..2d128ffb750d8907deee0fe00bec8c6afd4956fb 100644 (file)
@@ -1918,35 +1918,27 @@ void JoinTextNodesCommandImpl::doUnapply()
 }
 
 //------------------------------------------------------------------------------------------
-// PasteMarkupCommandImpl
+// ReplaceSelectionCommandImpl
 
-PasteMarkupCommandImpl::PasteMarkupCommandImpl(DocumentImpl *document, const DOMString &markupString, const DOMString &baseURL
-    : CompositeEditCommandImpl(document), m_markupString(markupString), m_baseURL(baseURL)
+ReplaceSelectionCommandImpl::ReplaceSelectionCommandImpl(DocumentImpl *document, DOM::DocumentFragmentImpl *fragment, bool selectReplacement
+    : CompositeEditCommandImpl(document), m_fragment(fragment), m_selectReplacement(selectReplacement)
 {
-    ASSERT(!m_markupString.isEmpty());
 }
 
-PasteMarkupCommandImpl::~PasteMarkupCommandImpl()
+ReplaceSelectionCommandImpl::~ReplaceSelectionCommandImpl()
 {
 }
 
-int PasteMarkupCommandImpl::commandID() const
+int ReplaceSelectionCommandImpl::commandID() const
 {
-    return PasteMarkupCommandID;
+    return ReplaceSelectionCommandID;
 }
 
-void PasteMarkupCommandImpl::doApply()
+void ReplaceSelectionCommandImpl::doApply()
 {
-    DocumentFragmentImpl *root = static_cast<HTMLElementImpl *>(document()->documentElement())->createContextualFragment(m_markupString);
-    ASSERT(root);
-    
-    if (!m_baseURL.isEmpty() && m_baseURL != document()->baseURL()) {
-        root->recursive_completeURLs(m_baseURL.string());
-    }
-    
-    NodeImpl *firstChild = root->firstChild();
-    NodeImpl *lastChild = root->lastChild();
-    
+    NodeImpl *firstChild = m_fragment->firstChild();
+    NodeImpl *lastChild = m_fragment->lastChild();
+
     Selection selection = endingSelection();
 
     // Delete the current selection, or collapse whitespace, as needed
@@ -1963,7 +1955,11 @@ void PasteMarkupCommandImpl::doApply()
         ASSERT(!lastChild);
     } else if (firstChild == lastChild && firstChild->isTextNode()) {
         // Simple text paste. Treat as if the text were typed.
+        Position base = selection.base();
         inputText(static_cast<TextImpl *>(firstChild)->data());
+        if (m_selectReplacement) {
+            setEndingSelection(Selection(base, endingSelection().extent()));
+        }
     } 
     else {
         // HTML fragment paste.
@@ -1980,20 +1976,66 @@ void PasteMarkupCommandImpl::doApply()
             node = next;
         }
         ASSERT(beforeNode);
-               
-               // Find the last leaf and place the caret after it.
-        NodeImpl *leaf = lastChild;
+       
+        // Find the last leaf.
+        NodeImpl *lastLeaf = lastChild;
         while (1) {
-            NodeImpl *nextChild = leaf->lastChild();
+            NodeImpl *nextChild = lastLeaf->lastChild();
             if (!nextChild)
                 break;
-            leaf = nextChild;
+            lastLeaf = nextChild;
         }
         
-        setEndingSelection(Position(leaf, leaf->caretMaxOffset()));
+       if (m_selectReplacement) {            
+            // Find the first leaf.
+            NodeImpl *firstLeaf = firstChild;
+            while (1) {
+                NodeImpl *nextChild = firstLeaf->firstChild();
+                if (!nextChild)
+                    break;
+                firstLeaf = nextChild;
+            }
+            // Select what was inserted.
+            setEndingSelection(Selection(Position(firstLeaf, firstLeaf->caretMinOffset()), Position(lastLeaf, lastLeaf->caretMaxOffset())));
+        } else {
+            // Place the cursor after what was inserted.
+            setEndingSelection(Position(lastLeaf, lastLeaf->caretMaxOffset()));
+        }
     }
 }
 
+//------------------------------------------------------------------------------------------
+// MoveSelectionCommandImpl
+
+MoveSelectionCommandImpl::MoveSelectionCommandImpl(DocumentImpl *document, DOM::DocumentFragmentImpl *fragment, DOM::Position &position) 
+: CompositeEditCommandImpl(document), m_fragment(fragment), m_position(position)
+{
+}
+
+MoveSelectionCommandImpl::~MoveSelectionCommandImpl()
+{
+}
+
+int MoveSelectionCommandImpl::commandID() const
+{
+    return MoveSelectionCommandID;
+}
+
+void MoveSelectionCommandImpl::doApply()
+{
+    Selection originalSelection = endingSelection();
+    ASSERT(originalSelection.state() == Selection::RANGE);
+
+    // FIXME: Inserting the fragment by calling ReplaceSelectionCommand is not working for some reason.
+    /*
+    setEndingSelection(m_position);
+    ReplaceSelectionCommand cmd(document(), m_fragment, true);
+    applyCommandToComposite(cmd);
+    */
+    // FIXME: Need to delete the selection here.
+}
+
+
 //------------------------------------------------------------------------------------------
 // RemoveCSSPropertyCommandImpl
 
index 0279a976ef0b73cd330028ba8de5ab24cfcb6c3c..f33ae3c666b5d0e595b28cd45162d299b01be10b 100644 (file)
@@ -400,23 +400,39 @@ private:
 };
 
 //------------------------------------------------------------------------------------------
-// PasteMarkupCommandImpl
+// ReplaceSelectionCommandImpl
 
-class PasteMarkupCommandImpl : public CompositeEditCommandImpl
+class ReplaceSelectionCommandImpl : public CompositeEditCommandImpl
 {
 public:
-    PasteMarkupCommandImpl(DOM::DocumentImpl *document, const DOM::DOMString &markupString, const DOM::DOMString &baseURL);
-    virtual ~PasteMarkupCommandImpl();
+    ReplaceSelectionCommandImpl(DOM::DocumentImpl *document, DOM::DocumentFragmentImpl *fragment, bool selectReplacement=true);
+    virtual ~ReplaceSelectionCommandImpl();
     
     virtual int commandID() const;
 
     virtual void doApply();
 
-    DOM::DOMString markupString() const { return m_markupString; }
+private:
+    DOM::DocumentFragmentImpl *m_fragment;
+    bool m_selectReplacement;
+};
+
+//------------------------------------------------------------------------------------------
+// MoveSelectionCommandImpl
 
+class MoveSelectionCommandImpl : public CompositeEditCommandImpl
+{
+public:
+    MoveSelectionCommandImpl(DOM::DocumentImpl *document, DOM::DocumentFragmentImpl *fragment, DOM::Position &position);
+    virtual ~MoveSelectionCommandImpl();
+    
+    virtual int commandID() const;
+    
+    virtual void doApply();
+    
 private:
-    DOM::DOMString m_markupString;
-    DOM::DOMString m_baseURL;
+    DOM::DocumentFragmentImpl *m_fragment;
+    DOM::Position m_position;
 };
 
 //------------------------------------------------------------------------------------------
index 0dfeec81f6fe3ef2d9678148b153fb5b92dae649..4374f61219218e1960bfc2091c0d682fd25b659c 100644 (file)
@@ -105,7 +105,6 @@ using khtml::Decoder;
 using khtml::DeleteSelectionCommand;
 using khtml::EditCommand;
 using khtml::InlineTextBox;
-using khtml::PasteMarkupCommand;
 using khtml::plainText;
 using khtml::RenderObject;
 using khtml::RenderText;
@@ -2275,6 +2274,11 @@ const Selection &KHTMLPart::selection() const
     return d->m_selection;
 }
 
+const Selection &KHTMLPart::dragCaret() const
+{
+    return d->m_dragCaret;
+}
+
 void KHTMLPart::setSelection(const Selection &s, bool closeTyping)
 {
     if (d->m_selection != s) {
@@ -2285,6 +2289,14 @@ void KHTMLPart::setSelection(const Selection &s, bool closeTyping)
     }
 }
 
+void KHTMLPart::setDragCaret(const DOM::Selection &dragCaret)
+{
+    if (d->m_dragCaret != dragCaret) {
+        d->m_dragCaret = dragCaret;
+        notifyDragCaretChanged();
+    }
+}
+
 void KHTMLPart::clearSelection()
 {
     clearCaretRectIfNeeded();
@@ -2393,6 +2405,11 @@ void KHTMLPart::notifySelectionChanged(bool closeTyping)
 #endif
 }
 
+void KHTMLPart::notifyDragCaretChanged()
+{
+    d->m_dragCaret.needsCaretRepaint();
+}
+
 void KHTMLPart::setXPosForVerticalArrowNavigation(int x)
 {
     d->m_xPosForVerticalArrowNavigation = x;
@@ -2420,6 +2437,11 @@ void KHTMLPart::paintCaret(QPainter *p, const QRect &rect) const
         d->m_selection.paintCaret(p, rect);
 }
 
+void KHTMLPart::paintDragCaret(QPainter *p, const QRect &rect) const
+{
+    d->m_dragCaret.paintCaret(p, rect);
+}
+
 #if !APPLE_CHANGES
 
 void KHTMLPart::overURL( const QString &url, const QString &target, bool shiftPressed )
index e974f8d40201a9ca60794e577d6a1875a5006d16..71d90d13275ed64602314f6e330c7938052518ef 100644 (file)
@@ -569,11 +569,21 @@ public:
    */
   const DOM::Selection &selection() const;
 
+  /**
+   * Returns the drag caret of the HTML.
+   */
+  const DOM::Selection &dragCaret() const;
+
   /**
    * Sets the current selection.
    */
   void setSelection(const DOM::Selection &, bool closeTyping=true);
 
+  /**
+      * Sets the current drag cart.
+   */
+  void setDragCaret(const DOM::Selection &);
+  
   /**
    * Clears the current selection.
    */
@@ -593,6 +603,11 @@ public:
    * Paints the caret.
    */
   void paintCaret(QPainter *p, const QRect &rect) const;
+  
+ /**
+   * Paints the drag caret.
+   */
+  void paintDragCaret(QPainter *p, const QRect &rect) const;
 
   /**
    * Set info for vertical arrow navigation.
@@ -1112,6 +1127,11 @@ private:
    * @internal
    */
   void notifySelectionChanged(bool closeTyping=true);
+  
+  /**
+   * @internal
+   */
+  void notifyDragCaretChanged();
 
   /**
    * @internal
index 13aacdea3ad11caaa572d572a8ed224d643fa220..d9aaddfebfff2b9e0022a6676c3bee7854b7e6d3 100644 (file)
@@ -352,6 +352,7 @@ public:
 #endif
 
   DOM::Selection m_selection;
+  DOM::Selection m_dragCaret;
   int m_caretBlinkTimer;
 
   bool m_caretVisible:1;
index 780ffab2f6201201cb9d5ec8484f0f2ec345cb8e..09a400a97f16d52100a22fee157f221b6d428b21 100644 (file)
@@ -1306,6 +1306,7 @@ void RenderBlock::paintObject(PaintInfo& i, int _tx, int _ty)
         RenderObject *renderer = baseNode ? baseNode->renderer() : 0;
         if (renderer && renderer->containingBlock() == this && baseNode->isContentEditable()) {
             document()->part()->paintCaret(i.p, i.r);
+            document()->part()->paintDragCaret(i.p, i.r);
         }
     }
     
index 63724314d5d30974f932599734ec7e1961c3cdb5..f086cb1c988b7f04378f360ef1e260095fde98c6 100644 (file)
@@ -91,10 +91,6 @@ using DOM::TreeWalkerImpl;
 - (AttrImpl *)_attrImpl;
 @end
 
-@interface DOMDocumentFragment (WebCoreInternal)
-+ (DOMDocumentFragment *)_documentFragmentWithImpl:(DocumentFragmentImpl *)impl;
-@end
-
 @interface DOMImplementation (WebCoreInternal)
 + (DOMImplementation *)_DOMImplementationWithImpl:(DOMImplementationImpl *)impl;
 - (DOMImplementationImpl *)_DOMImplementationImpl;
@@ -913,6 +909,11 @@ inline Document DocumentImpl::createInstance(DocumentImpl *impl)
     return static_cast<DOMDocumentFragment *>([DOMNode _nodeWithImpl:impl]);
 }
 
+- (DocumentFragmentImpl *)_fragmentImpl
+{
+    return static_cast<DocumentFragmentImpl *>(DOM_cast<NodeImpl *>(_internal));
+}
+
 @end
 
 //------------------------------------------------------------------------------------------
index 81f1a7090a6719fe053a0b88fa64002a43eefd9f..25fcb6b4dd1365831232df891110efee2fb233af 100644 (file)
@@ -28,6 +28,7 @@
 namespace DOM {
     class CSSStyleDeclarationImpl;
     class CSSStyleSheetImpl;
+    class DocumentFragmentImpl;
     class DocumentImpl;
     class ElementImpl;
     class NodeFilterImpl;
@@ -59,6 +60,11 @@ namespace DOM {
 - (DOMElement *)_ownerElement;
 @end
 
+@interface DOMDocumentFragment (WebCoreInternal)
++ (DOMDocumentFragment *)_documentFragmentWithImpl:(DOM::DocumentFragmentImpl *)impl;
+- (DOM::DocumentFragmentImpl *)_fragmentImpl;
+@end
+
 @interface DOMRange (WebCoreInternal)
 + (DOMRange *)_rangeWithImpl:(DOM::RangeImpl *)impl;
 - (DOM::RangeImpl *)_rangeImpl;
index b2ec943ee4178ced192d32bfddd35a0645091473..05e85559153b5858b4372806366c3612f757bf9d 100644 (file)
@@ -53,6 +53,7 @@ typedef khtml::RenderPart KHTMLRenderPart;
 
 @class DOMCSSStyleDeclaration;
 @class DOMDocument;
+@class DOMDocumentFragment;
 @class DOMElement;
 @class DOMHTMLElement;
 @class DOMNode;
@@ -233,7 +234,6 @@ typedef enum {
 - (void)setSelectionFrom:(DOMNode *)start startOffset:(int)startOffset to:(DOMNode *)end endOffset:(int) endOffset;
 
 - (BOOL)isSelectionEditable;
-- (void)moveDragCaretToPoint:(NSPoint)point;
 
 - (BOOL)haveSelection;
 
@@ -287,10 +287,21 @@ typedef enum {
 - (void)redoEditing:(id)arg;
 - (DOMRange *)rangeByAlteringCurrentSelection:(WebSelectionAlteration)alteration direction:(WebSelectionDirection)direction granularity:(WebSelectionGranularity)granularity;
 - (void)alterCurrentSelection:(WebSelectionAlteration)alteration direction:(WebSelectionDirection)direction granularity:(WebSelectionGranularity)granularity;
-- (void)replaceSelectionWithText:(NSString *)text;
-- (void)replaceSelectionWithNode:(DOMNode *)node;
-- (void)replaceSelectionWithMarkupString:(NSString *)markupString baseURLString:(NSString *)baseURLString;
+
+- (DOMDocumentFragment *)documentFragmentWithMarkupString:(NSString *)markupString baseURLString:(NSString *)baseURLString;
+- (DOMDocumentFragment *)documentFragmentWithText:(NSString *)text;
+
+- (void)replaceSelectionWithFragment:(DOMDocumentFragment *)fragment selectReplacement:(BOOL)selectReplacement;
+- (void)replaceSelectionWithNode:(DOMNode *)node selectReplacement:(BOOL)selectReplacement;
+- (void)replaceSelectionWithMarkupString:(NSString *)markupString baseURLString:(NSString *)baseURLString selectReplacement:(BOOL)selectReplacement;
+- (void)replaceSelectionWithText:(NSString *)text selectReplacement:(BOOL)selectReplacement;
 - (void)replaceSelectionWithNewline;
+
+- (void)setSelectionToDragCaret;
+- (void)moveSelectionToDragCaret:(DOMDocumentFragment *)selectionFragment;
+- (void)moveDragCaretToPoint:(NSPoint)point;
+- (void)removeDragCaret;
+
 - (void)deleteSelection;
 - (void)deleteKeyPressed;
 - (void)applyStyle:(DOMCSSStyleDeclaration *)style;
index 0f6fbf5604aabac2d83e6599de30c676200cd013..727c9dd4cf69a82688ff810a2183cfb63148438a 100644 (file)
 #import <AppKit/NSView.h>
 
 using DOM::AtomicString;
+using DOM::DocumentFragmentImpl;
 using DOM::DocumentImpl;
 using DOM::DocumentTypeImpl;
 using DOM::DOMString;
 using DOM::Element;
 using DOM::ElementImpl;
+using DOM::HTMLElementImpl;
 using DOM::HTMLFormElementImpl;
 using DOM::HTMLGenericFormElementImpl;
 using DOM::HTMLImageElementImpl;
@@ -98,7 +100,8 @@ using khtml::Decoder;
 using khtml::DeleteSelectionCommand;
 using khtml::EditCommand;
 using khtml::EditCommandImpl;
-using khtml::PasteMarkupCommand;
+using khtml::MoveSelectionCommand;
+using khtml::ReplaceSelectionCommand;
 using khtml::parseURL;
 using khtml::ApplyStyleCommand;
 using khtml::RenderCanvas;
@@ -420,31 +423,11 @@ static bool initializedKJS = FALSE;
        return startNode ? startNode->isContentEditable() : NO;
 }
 
-- (void)moveDragCaretToPoint:(NSPoint)point
-{
-    RenderObject *renderer = _part->renderer();
-    if (!renderer) {
-        return;
-    }
-    
-    RenderObject::NodeInfo nodeInfo(true, true);
-    renderer->layer()->nodeAtPoint(nodeInfo, (int)point.x, (int)point.y);
-    NodeImpl *node = nodeInfo.innerNode();
-        
-    Selection selection(node->positionForCoordinates((int)point.x, (int)point.y));
-    _part->setSelection(selection);
-}
-
 - (BOOL)haveSelection
 {
     return _part->selection().state() == Selection::RANGE;
 }
 
-- (DOMRange *)selectedRange
-{
-    return [DOMRange _rangeWithImpl:_part->selection().toRange().handle()];
-}
-
 - (NSString *)_documentTypeString
 {
     NSString *documentTypeString = nil;
@@ -1413,29 +1396,55 @@ static HTMLFormElementImpl *formElementFromDOMElement(DOMElement *element)
     return static_cast<NSSelectionAffinity>(_part->selection().affinity());
 }
 
-- (void)replaceSelectionWithNode:(DOMNode *)node
+- (DOMDocumentFragment *)documentFragmentWithMarkupString:(NSString *)markupString baseURLString:(NSString *)baseURLString 
 {
-    ERROR("unimplemented");
+    DOM::DocumentImpl *document = _part->xmlDocImpl();
+    DOM::DocumentFragmentImpl *fragment = static_cast<HTMLElementImpl *>(document->documentElement())->createContextualFragment(markupString);
+    ASSERT(fragment);
+    
+    if ([baseURLString length] > 0) {
+        DOM::DOMString baseURL = baseURLString;
+        if (baseURL != document->baseURL()) {
+            fragment->recursive_completeURLs(baseURL.string());
+        }
+    }
+    return [DOMDocumentFragment _documentFragmentWithImpl:fragment];
 }
 
-- (void)replaceSelectionWithText:(NSString *)text
+- (DOMDocumentFragment *)documentFragmentWithText:(NSString *)text
 {
-    if (!_part || !_part->xmlDocImpl())
-        return;
-    
-    DOMString s(text);
-    TypingCommand::insertText(_part->xmlDocImpl(), s);
+    DOMDocument *document = [self DOMDocument];
+    DOMDocumentFragment *fragment = [document createDocumentFragment];
+    [fragment appendChild:[document createTextNode:text]];
+    return fragment;
 }
-
-- (void)replaceSelectionWithMarkupString:(NSString *)markupString baseURLString:(NSString *)baseURLString
+- (void)replaceSelectionWithFragment:(DOMDocumentFragment *)fragment selectReplacement:(BOOL)selectReplacement
 {
-    if (!_part || !_part->xmlDocImpl() || !markupString)
+    if (!_part || !_part->xmlDocImpl() || !fragment)
         return;
     
-    PasteMarkupCommand cmd(_part->xmlDocImpl(), markupString, baseURLString ? baseURLString : @"");
+    ReplaceSelectionCommand cmd(_part->xmlDocImpl(), [fragment _fragmentImpl], selectReplacement);
     cmd.apply();
 }
 
+- (void)replaceSelectionWithNode:(DOMNode *)node selectReplacement:(BOOL)selectReplacement
+{
+    DOMDocumentFragment *fragment = [[self DOMDocument] createDocumentFragment];
+    [fragment appendChild:node];
+    [self replaceSelectionWithFragment:fragment selectReplacement:selectReplacement];
+}
+
+- (void)replaceSelectionWithMarkupString:(NSString *)markupString baseURLString:(NSString *)baseURLString selectReplacement:(BOOL)selectReplacement
+{
+    DOMDocumentFragment *fragment = [self documentFragmentWithMarkupString:markupString baseURLString:baseURLString];
+    [self replaceSelectionWithFragment:fragment selectReplacement:selectReplacement];
+}
+
+- (void)replaceSelectionWithText:(NSString *)text selectReplacement:(BOOL)selectReplacement
+{
+    [self replaceSelectionWithFragment:[self documentFragmentWithText:text] selectReplacement:selectReplacement];
+}
+
 - (void)replaceSelectionWithNewline
 {
     if (!_part || !_part->xmlDocImpl())
@@ -1444,6 +1453,38 @@ static HTMLFormElementImpl *formElementFromDOMElement(DOMElement *element)
     TypingCommand::insertNewline(_part->xmlDocImpl());
 }
 
+- (void)setSelectionToDragCaret
+{
+    _part->setSelection(_part->dragCaret());
+}
+
+- (void)moveSelectionToDragCaret:(DOMDocumentFragment *)selectionFragment
+{
+    Position base = _part->dragCaret().base();
+    MoveSelectionCommand cmd(_part->xmlDocImpl(), [selectionFragment _fragmentImpl], base);
+    cmd.apply();
+}
+
+- (void)moveDragCaretToPoint:(NSPoint)point
+{
+    RenderObject *renderer = _part->renderer();
+    if (!renderer) {
+        return;
+    }
+    
+    RenderObject::NodeInfo nodeInfo(true, true);
+    renderer->layer()->nodeAtPoint(nodeInfo, (int)point.x, (int)point.y);
+    NodeImpl *node = nodeInfo.innerNode();
+    
+    Selection dragCaret(node->positionForCoordinates((int)point.x, (int)point.y));
+    _part->setDragCaret(dragCaret);
+}
+
+- (void)removeDragCaret
+{
+    _part->setDragCaret(Selection());
+}
+
 - (void)deleteSelection
 {
     if (!_part || !_part->xmlDocImpl())
index 67dcc61368289cf4cb89aa1517a1ce1df95bced9..41c8f9716148ef89e700d19aefb98a607d3ab93f 100644 (file)
@@ -1,3 +1,39 @@
+2004-05-24  Chris Blumenberg  <cblu@apple.com>
+
+       Improved editing via drag
+               Reviewed by kocienda.
+
+        * WebView.subproj/WebDataSource.m: 
+        (-[WebDataSource _documentFragmentWithImageResource:]): made this method return a fragment instead of replace the selection so that the caller do other things with the fragment
+        (-[WebDataSource _documentFragmentWithArchive:]): ditto
+        (-[WebDataSource _replaceSelectionWithArchive:selectReplacement:]): call renamed methods
+        * WebView.subproj/WebDataSourcePrivate.h:
+        * WebView.subproj/WebDocumentInternal.h:
+        * WebView.subproj/WebHTMLView.m:
+        (-[WebHTMLView _documentFragmentFromPasteboard:]): made this method return a fragment instead of replace the selection so that the caller do other things with the fragment
+        (-[WebHTMLView _replaceSelectionWithPasteboard:selectReplacement:]): new
+        (-[WebHTMLView paste:]): call _replaceSelectionWithPasteboard:selectReplacement:
+        (-[WebHTMLView dragOperationForDraggingInfo:]): handle the case where the destination is editable, but the source is not
+        (-[WebHTMLView draggingCancelledWithDraggingInfo:]): new, removes drag caret
+        (-[WebHTMLView draggingUpdatedWithDraggingInfo:]): remove drag caret when we can't handle the drag
+        (-[WebHTMLView concludeDragForDraggingInfo:]): instead of calling paste, move the selection when doing a move and replace the drag caret when doing a copy
+        * WebView.subproj/WebHTMLViewPrivate.h:
+        * WebView.subproj/WebView.m:
+        (-[WebViewPrivate dealloc]):
+        (-[WebView _setDraggingDocumentView:]): new
+        (-[WebView _dragOperationForDraggingInfo:]): if the current dragging document view changes, tell the previous dragging document view that dragging cancelled 
+        (-[WebView draggingExited:]): new, tell the previous dragging document view that dragging cancelled
+        (-[WebView concludeDragOperation:]): release the dragging document view
+        (-[WebView replaceSelectionWithNode:]): pass the selectReplacement BOOL to the bridge
+        (-[WebView replaceSelectionWithText:]): ditto
+        (-[WebView replaceSelectionWithMarkupString:]): ditto
+        (-[WebView replaceSelectionWithArchive:]): ditto
+        (-[WebView pasteAsPlainText:]): ditto
+        (-[WebView insertTab:]): ditto
+        (-[WebView insertText:]): ditto
+        * WebView.subproj/WebViewPrivate.h: 
+
 2004-05-24  John Sullivan  <sullivan@apple.com>
 
         Reviewed by Dave.
index 65ca609847ae311b0e184ec03e6de7569c1fd578..35f5b58351470862dfe0fd7cce5a3720950d767c 100644 (file)
     return archive;
 }
 
-- (void)_replaceSelectionWithMarkupString:(NSString *)markupString baseURL:(NSURL *)baseURL
-{
-    [[self _bridge] replaceSelectionWithMarkupString:markupString baseURLString:[baseURL _web_originalDataAsString]];
-}
-
-- (void)_replaceSelectionWithImageResource:(WebResource *)resource
+- (DOMDocumentFragment *)_documentFragmentWithImageResource:(WebResource *)resource
 {
     ASSERT(resource);
     [self addSubresource:resource];
-    [self _replaceSelectionWithMarkupString:[NSString stringWithFormat:@"<IMG SRC=\"%@\">", [[resource URL] _web_originalDataAsString]] baseURL:nil];
+    NSString *markupString = [NSString stringWithFormat:@"<IMG SRC=\"%@\">", [[resource URL] _web_originalDataAsString]];
+    return [[self _bridge] documentFragmentWithMarkupString:markupString baseURLString:nil];
 }
 
-- (BOOL)_replaceSelectionWithArchive:(WebArchive *)archive
+- (DOMDocumentFragment *)_documentFragmentWithArchive:(WebArchive *)archive
 {
     ASSERT(archive);
     WebResource *mainResource = [archive mainResource];
             NSString *markupString = [[NSString alloc] initWithData:[mainResource data] encoding:NSUTF8StringEncoding];
             [self _addSubresources:[archive subresources]];
             [self _addSubframeArchives:[archive subframeArchives]];
-            [self _replaceSelectionWithMarkupString:markupString baseURL:[mainResource URL]];
+            DOMDocumentFragment *fragment = [[self _bridge] documentFragmentWithMarkupString:markupString baseURLString:[[mainResource URL] _web_originalDataAsString]];
             [markupString release];
-            return YES;
+            return fragment;
         } else if ([[[WebImageRendererFactory sharedFactory] supportedMIMETypes] containsObject:MIMEType]) {
-            [self _replaceSelectionWithImageResource:mainResource];
-            return YES;
+            return [self _documentFragmentWithImageResource:mainResource];
+
         }
     }
-    return NO;
+    return nil;
+}
+
+- (void)_replaceSelectionWithArchive:(WebArchive *)archive selectReplacement:(BOOL)selectReplacement
+{
+    DOMDocumentFragment *fragment = [self _documentFragmentWithArchive:archive];
+    if (fragment) {
+        [[self _bridge] replaceSelectionWithFragment:fragment selectReplacement:selectReplacement];
+    }
 }
 
 - (WebView *)_webView
index 41ef33103aea8526b75c8b01c7ccb7c11fb7e884..0dbc6688abf4e3df488d1b93779932f0dc99d7f2 100644 (file)
@@ -8,6 +8,8 @@
 
 #import <WebKit/WebDataSource.h>
 
+@class DOMDocumentFragment;
+@class DOMRange;
 @class NSError;
 @class NSURLRequest;
 @class NSURLResponse;
 - (void)_addSubframeArchives:(NSArray *)subframeArchives;
 - (WebArchive *)_popSubframeArchiveWithName:(NSString *)frameName;
 
-- (void)_replaceSelectionWithMarkupString:(NSString *)markupString baseURL:(NSURL *)baseURL;
-- (BOOL)_replaceSelectionWithArchive:(WebArchive *)archive;
-- (void)_replaceSelectionWithImageResource:(WebResource *)resource;
+- (DOMDocumentFragment *)_documentFragmentWithImageResource:(WebResource *)resource;
+- (DOMDocumentFragment *)_documentFragmentWithArchive:(WebArchive *)archive;
+- (void)_replaceSelectionWithArchive:(WebArchive *)archive selectReplacement:(BOOL)selectReplacement;
 
 - (NSError *)_mainDocumentError;
 - (NSString *)_stringWithData:(NSData *)data;
index 055ce62f28bedbc9018d471359a3c1a102ec9480..498f73d54af5a9f9aaa72a70ea7e30cefa47370c 100644 (file)
@@ -20,6 +20,7 @@
 
 @protocol WebDocumentDragging <NSObject>
 - (NSDragOperation)dragOperationForDraggingInfo:(id <NSDraggingInfo>)draggingInfo;
+- (void)draggingCancelledWithDraggingInfo:(id <NSDraggingInfo>)draggingInfo;
 - (void)draggingUpdatedWithDraggingInfo:(id <NSDraggingInfo>)draggingInfo;
 - (BOOL)concludeDragForDraggingInfo:(id <NSDraggingInfo>)draggingInfo;
 @end
index 166d65ba727bb347ad43efb3c72f0bb7aa823844..7530b54f5cdbd57a00cb771a93830e9ae9426cd8 100644 (file)
@@ -544,22 +544,17 @@ static WebHTMLView *lastHitView = nil;
     return [[self _bridge] isSelectionEditable];
 }
 
-- (void)_replaceSelectionWithMarkupString:(NSString *)markupString
-{
-    [[self _dataSource] _replaceSelectionWithMarkupString:markupString baseURL:nil];
-}
-
-- (void)_pasteFromPasteboard:(NSPasteboard *)pasteboard
+- (DOMDocumentFragment *)_documentFragmentFromPasteboard:(NSPasteboard *)pasteboard
 {
     NSArray *types = [pasteboard types];
 
     if ([types containsObject:WebArchivePboardType]) {
         WebArchive *archive = [[WebArchive alloc] initWithData:[pasteboard dataForType:WebArchivePboardType]];
         if (archive) {
-            BOOL didPaste = [[self _dataSource] _replaceSelectionWithArchive:archive];
+            DOMDocumentFragment *fragment = [[self _dataSource] _documentFragmentWithArchive:archive];
             [archive release];
-            if (didPaste) {
-                return;
+            if (fragment) {
+                return fragment;
             }
         }
     }
@@ -567,23 +562,25 @@ static WebHTMLView *lastHitView = nil;
     NSURL *URL;
     
     if ([types containsObject:NSHTMLPboardType]) {
-        [self _replaceSelectionWithMarkupString:[pasteboard stringForType:NSHTMLPboardType]];
+        return [[self _bridge] documentFragmentWithMarkupString:[pasteboard stringForType:NSHTMLPboardType] baseURLString:nil];
     } else if ([types containsObject:NSTIFFPboardType]) {
         WebResource *resource = [[WebResource alloc] initWithData:[pasteboard dataForType:NSTIFFPboardType]
                                                               URL:[NSURL _web_uniqueWebDataURLWithRelativeString:@"/image.tiff"]
                                                          MIMEType:@"image/tiff" 
                                                  textEncodingName:nil
                                                         frameName:nil];
-        [[self _dataSource] _replaceSelectionWithImageResource:resource];
+        DOMDocumentFragment *fragment = [[self _dataSource] _documentFragmentWithImageResource:resource];
         [resource release];
+        return fragment;
     } else if ([types containsObject:NSPICTPboardType]) {
         WebResource *resource = [[WebResource alloc] initWithData:[pasteboard dataForType:NSPICTPboardType]
                                                               URL:[NSURL _web_uniqueWebDataURLWithRelativeString:@"/image.pict"]
                                                          MIMEType:@"image/pict" 
                                                  textEncodingName:nil
                                                         frameName:nil];
-        [[self _dataSource] _replaceSelectionWithImageResource:resource];
+        DOMDocumentFragment *fragment = [[self _dataSource] _documentFragmentWithImageResource:resource];
         [resource release];
+        return fragment;
     } else if ((URL = [pasteboard _web_bestURL])) {
         NSString *URLString = [URL _web_originalDataAsString];
         NSString *linkLabel = [pasteboard stringForType:WebURLNamePboardType];
@@ -592,17 +589,27 @@ static WebHTMLView *lastHitView = nil;
         // An even better solution would be to make a DOM node with the DOM API rather than creating
         // a markup string here.
         NSString *markupString = [NSString stringWithFormat:@"<A HREF=\"%@\">%@</A>", URLString, linkLabel];
-        [self _replaceSelectionWithMarkupString:markupString];
+        return [[self _bridge] documentFragmentWithMarkupString:markupString baseURLString:nil];
     } else if ([types containsObject:NSRTFDPboardType]) {
         // FIXME: Support RTFD to HTML (or DOM) conversion.
         ERROR("RTFD to HTML conversion not yet supported.");
-        [self _replaceSelectionWithMarkupString:[pasteboard stringForType:NSStringPboardType]]; 
+        return [[self _bridge] documentFragmentWithMarkupString:[pasteboard stringForType:NSStringPboardType] baseURLString:nil];
     } else if ([types containsObject:NSRTFPboardType]) {
         // FIXME: Support RTF to HTML (or DOM) conversion.
         ERROR("RTF to HTML conversion not yet supported.");
-        [self _replaceSelectionWithMarkupString:[pasteboard stringForType:NSStringPboardType]];      
+        return [[self _bridge] documentFragmentWithMarkupString:[pasteboard stringForType:NSStringPboardType] baseURLString:nil];
     } else if ([types containsObject:NSStringPboardType]) {
-        [[self _bridge] replaceSelectionWithText:[pasteboard stringForType:NSStringPboardType]];
+        return [[self _bridge] documentFragmentWithText:[pasteboard stringForType:NSStringPboardType]];
+    }
+    
+    return nil;
+}
+
+- (void)_replaceSelectionWithPasteboard:(NSPasteboard *)pasteboard selectReplacement:(BOOL)selectReplacement
+{
+    DOMDocumentFragment *fragment = [self _documentFragmentFromPasteboard:pasteboard];
+    if (fragment) {
+        [[self _bridge] replaceSelectionWithFragment:fragment selectReplacement:selectReplacement];
     }
 }
 
@@ -915,7 +922,7 @@ static WebHTMLView *lastHitView = nil;
 
 - (void)paste:(id)sender
 {
-    [self _pasteFromPasteboard:[NSPasteboard generalPasteboard]];
+    [self _replaceSelectionWithPasteboard:[NSPasteboard generalPasteboard] selectReplacement:NO];
 }
 
 @end
@@ -1718,25 +1725,41 @@ static WebHTMLView *lastHitView = nil;
 - (NSDragOperation)dragOperationForDraggingInfo:(id <NSDraggingInfo>)draggingInfo
 {
     if ([self _canProcessDragWithDraggingInfo:draggingInfo]) {
-        return _private->initiatedDrag ? NSDragOperationMove : NSDragOperationCopy;
+        return (_private->initiatedDrag && [[self _bridge] isSelectionEditable]) ? NSDragOperationMove : NSDragOperationCopy;
     }
     return NSDragOperationNone;
 }
 
+- (void)draggingCancelledWithDraggingInfo:(id <NSDraggingInfo>)draggingInfo
+{
+    [[self _bridge] removeDragCaret];
+}
+
 - (void)draggingUpdatedWithDraggingInfo:(id <NSDraggingInfo>)draggingInfo
 {
     if ([self _canProcessDragWithDraggingInfo:draggingInfo]) {
         [[self _bridge] moveDragCaretToPoint:[self convertPoint:[draggingInfo draggingLocation] fromView:nil]];
+    } else {
+        [[self _bridge] removeDragCaret];
     }
 }
 
 - (BOOL)concludeDragForDraggingInfo:(id <NSDraggingInfo>)draggingInfo
 {
+    WebBridge *bridge = [self _bridge];
+    BOOL didInsert = NO;
     if ([self _canProcessDragWithDraggingInfo:draggingInfo]) {
-        [self _pasteFromPasteboard:[draggingInfo draggingPasteboard]];
-        return YES;
+        if (_private->initiatedDrag && [[self _bridge] isSelectionEditable]) {
+            DOMDocumentFragment *fragment = [self _documentFragmentFromPasteboard:[draggingInfo draggingPasteboard]];
+            [bridge moveSelectionToDragCaret:fragment];
+        } else {
+            [bridge setSelectionToDragCaret];
+            [self _replaceSelectionWithPasteboard:[draggingInfo draggingPasteboard] selectReplacement:YES];
+        }
+        didInsert = YES;
     }
-    return NO;
+    [bridge removeDragCaret];
+    return didInsert;
 }
 
 - (NSDictionary *)elementAtPoint:(NSPoint)point
index be9e00c202d96570b81f0e8157cc999fce152017..a1b2f5cba2f8149b97745e97d3350369a856c2e9 100644 (file)
@@ -6,6 +6,8 @@
 
 #import <WebKit/WebHTMLView.h>
 
+@class DOMDocumentFragment;
+@class DOMRange;
 @class WebArchive;
 @class WebBridge;
 @class WebView;
 + (NSArray *)_insertablePasteboardTypes;
 + (NSArray *)_selectionPasteboardTypes;
 - (void)_writeSelectionToPasteboard:(NSPasteboard *)pasteboard;
+- (DOMDocumentFragment *)_documentFragmentFromPasteboard:(NSPasteboard *)pasteboard;
 - (WebArchive *)_selectedArchive:(NSString **)markupString;
 - (NSData *)_selectedRTFData;
 - (BOOL)_canDelete;
 - (BOOL)_canPaste;
 - (BOOL)_haveSelection;
-- (void)_pasteFromPasteboard:(NSPasteboard *)pasteboard;
+- (void)_replaceSelectionWithPasteboard:(NSPasteboard *)pasteboard selectReplacement:(BOOL)selectReplacement;
 
 - (void)_frameOrBoundsChanged;
 
@@ -92,8 +95,9 @@
 - (void)_startAutoscrollTimer:(NSEvent *)event;
 - (void)_stopAutoscrollTimer;
 
-- (void)cut:(id)sender;
 - (void)copy:(id)sender;
+- (void)cut:(id)sender;
+- (void)delete:(id)sender;
 - (void)paste:(id)sender;
 - (void)delete:(id)sender;
 
index 32477b3fcdcdec4224f703f61c2498df5b141baf..7e7b74097433686cd60658b6103ee007478f7634 100644 (file)
@@ -136,7 +136,8 @@ NSString *_WebMainFrameURLKey =         @"mainFrameURL";
 
 - (void)dealloc
 {
-    ASSERT(!mainFrame);
+    ASSERT(mainFrame == nil);
+    ASSERT(draggingDocumentView == nil);
     
     [backForwardList release];
     [applicationNameForUserAgent release];
@@ -1708,14 +1709,30 @@ NS_ENDHANDLER
     return NSDragOperationNone;
 }
 
+- (void)_setDraggingDocumentView:(NSView <WebDocumentDragging> *)newDraggingView
+{
+    if (_private->draggingDocumentView != newDraggingView) {
+        [_private->draggingDocumentView release];
+        _private->draggingDocumentView = [newDraggingView retain];
+    }
+}
+
 - (NSDragOperation)_dragOperationForDraggingInfo:(id <NSDraggingInfo>)draggingInfo
 {
     NSPoint windowPoint = [draggingInfo draggingLocation];
+    NSView <WebDocumentDragging> *newDraggingView = [self _draggingDocumentViewAtWindowPoint:windowPoint];
+    if (_private->draggingDocumentView != newDraggingView) {
+        [_private->draggingDocumentView draggingCancelledWithDraggingInfo:draggingInfo];
+        [self _setDraggingDocumentView:newDraggingView];
+    }
+    
     NSDragOperation operation = [[self _UIDelegateForwarder] webView:self 
                                         dragOperationForDraggingInfo:draggingInfo 
                                                          overElement:[self _elementAtWindowPoint:windowPoint]];
-    if (operation != NSDragOperationNone) {
-        [[self _draggingDocumentViewAtWindowPoint:windowPoint] draggingUpdatedWithDraggingInfo:draggingInfo];
+    if (operation == NSDragOperationNone) {
+        [_private->draggingDocumentView draggingCancelledWithDraggingInfo:draggingInfo];
+    } else {
+        [_private->draggingDocumentView draggingUpdatedWithDraggingInfo:draggingInfo];
     }
     return operation;
 }
@@ -1730,6 +1747,12 @@ NS_ENDHANDLER
     return [self _dragOperationForDraggingInfo:draggingInfo];
 }
 
+- (void)draggingExited:(id <NSDraggingInfo>)draggingInfo
+{
+    [_private->draggingDocumentView draggingCancelledWithDraggingInfo:draggingInfo];
+    [self _setDraggingDocumentView:nil];
+}
+
 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)draggingInfo
 {
     return YES;
@@ -1743,16 +1766,22 @@ NS_ENDHANDLER
 - (void)concludeDragOperation:(id <NSDraggingInfo>)draggingInfo
 {
     NSPoint windowPoint = [draggingInfo draggingLocation];
+    ASSERT(_private->draggingDocumentView == [self _draggingDocumentViewAtWindowPoint:windowPoint]);
+    
     if (![[self _UIDelegateForwarder] webView:self 
             shouldProcessDragWithDraggingInfo:draggingInfo 
                                   overElement:[self _elementAtWindowPoint:windowPoint]]) {
+        [self _setDraggingDocumentView:nil];
         return;
     }
     
-    if ([[self _draggingDocumentViewAtWindowPoint:windowPoint] concludeDragForDraggingInfo:draggingInfo]) {
+    if ([_private->draggingDocumentView concludeDragForDraggingInfo:draggingInfo]) {
+        [self _setDraggingDocumentView:nil];
         return;
     }
     
+    [self _setDraggingDocumentView:nil];
+    
     if (!_private->editable && !_private->initiatedDrag) {
         NSURL *URL = [[self class] URLFromPasteboard:[draggingInfo draggingPasteboard]];
         if (URL) {
@@ -2530,23 +2559,22 @@ static NSFont *_fontFromStyle(DOMCSSStyleDeclaration *style)
 
 - (void)replaceSelectionWithNode:(DOMNode *)node
 {
-    [[self _bridgeForCurrentSelection] replaceSelectionWithNode:node];
+    [[self _bridgeForCurrentSelection] replaceSelectionWithNode:node selectReplacement:YES];
 }    
 
 - (void)replaceSelectionWithText:(NSString *)text
 {
-    [[self _bridgeForCurrentSelection] replaceSelectionWithText:text];
+    [[self _bridgeForCurrentSelection] replaceSelectionWithText:text selectReplacement:YES];
 }
 
 - (void)replaceSelectionWithMarkupString:(NSString *)markupString
 {
-    [[self _bridgeForCurrentSelection] replaceSelectionWithMarkupString:markupString baseURLString:nil];
+    [[self _bridgeForCurrentSelection] replaceSelectionWithMarkupString:markupString baseURLString:nil selectReplacement:YES];
 }
 
 - (void)replaceSelectionWithArchive:(WebArchive *)archive
 {
-    WebBridge *bridge = [self _bridgeForCurrentSelection];
-    [[[bridge webFrame] dataSource] _replaceSelectionWithArchive:archive];
+    [[[[self _bridgeForCurrentSelection] webFrame] dataSource] _replaceSelectionWithArchive:archive selectReplacement:YES];
 }
 
 - (void)deleteSelection
@@ -2984,7 +3012,7 @@ static NSFont *_fontFromStyle(DOMCSSStyleDeclaration *style)
         if ([view isKindOfClass:[WebHTMLView class]]) {
             NSString *text = [[NSPasteboard generalPasteboard] stringForType:NSStringPboardType];
             if ([[self _editingDelegateForwarder] webView:self shouldInsertText:text replacingDOMRange:[self selectedDOMRange] givenAction:WebViewInsertActionPasted]) {
-                [[self _bridgeForCurrentSelection] replaceSelectionWithText:text];
+                [[self _bridgeForCurrentSelection] replaceSelectionWithText:text selectReplacement:NO];
             }
         }
         return;
@@ -3100,7 +3128,7 @@ static NSFont *_fontFromStyle(DOMCSSStyleDeclaration *style)
         id <WebDocumentView> view = [[[self mainFrame] frameView] documentView];
         if ([view isKindOfClass:[WebHTMLView class]]) {
             if ([[self _editingDelegateForwarder] webView:self shouldInsertText:@"\t" replacingDOMRange:[self selectedDOMRange] givenAction:WebViewInsertActionPasted]) {
-                [[self _bridgeForCurrentSelection] replaceSelectionWithText:@"\t"];
+                [[self _bridgeForCurrentSelection] replaceSelectionWithText:@"\t" selectReplacement:NO];
             }
         }
         return;
@@ -3340,7 +3368,7 @@ static NSFont *_fontFromStyle(DOMCSSStyleDeclaration *style)
     if ([self _currentSelectionIsEditable]) {
         if ([[self _editingDelegateForwarder] webView:self shouldInsertText:text replacingDOMRange:[self selectedDOMRange] givenAction:WebViewInsertActionTyped]) {
             WebBridge *bridge = [self _bridgeForCurrentSelection];
-            [bridge replaceSelectionWithText:text];
+            [bridge replaceSelectionWithText:text selectReplacement:NO];
             [bridge ensureCaretVisible];
         }
         return;
index 52fdd39bba3e3348c67cbff8a618950782a642af..ad498682c8e53e505ad6c6d513f201b63c0a3d79 100644 (file)
@@ -3,7 +3,6 @@
     Copyright 2001, Apple, Inc. All rights reserved.
 */
 
-#import <WebKit/WebPolicyDelegate.h>
 #import <WebKit/WebView.h>
 #import <WebKit/WebFramePrivate.h>
 
@@ -12,6 +11,8 @@
 @class WebFrame;
 @class WebPreferences;
 @class WebCoreSettings;
+
+@protocol WebDocumentDragging;
 @protocol WebFormDelegate;
 
 #define NUM_LOCATION_CHANGE_DELEGATE_SELECTORS 10
@@ -94,8 +95,10 @@ extern NSString *_WebMainFrameURLKey;
     BOOL drawsBackground;
     BOOL editable;
     BOOL initiatedDrag;
-    
+        
     NSString *mediaStyle;
+    
+    NSView <WebDocumentDragging> *draggingDocumentView;
 }
 @end