[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677
cblu
cblu at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 08:41:29 UTC 2009
The following commit has been merged in the debian/unstable branch:
commit df60f9a413cd51b4c5a6325a28952c71af7b74d3
Author: cblu <cblu at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Mon May 24 21:55:47 2004 +0000
WebCore:
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: http://svn.webkit.org/repository/webkit/trunk@6675 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index 761f089..794126a 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,55 @@
+2004-05-24 Chris Blumenberg <cblu at 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 at apple.com>
Reviewed by John
diff --git a/WebCore/khtml/editing/htmlediting.cpp b/WebCore/khtml/editing/htmlediting.cpp
index f0f958a..8d78d67 100644
--- a/WebCore/khtml/editing/htmlediting.cpp
+++ b/WebCore/khtml/editing/htmlediting.cpp
@@ -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());
}
//------------------------------------------------------------------------------------------
diff --git a/WebCore/khtml/editing/htmlediting.h b/WebCore/khtml/editing/htmlediting.h
index d503964..8eb9955 100644
--- a/WebCore/khtml/editing/htmlediting.h
+++ b/WebCore/khtml/editing/htmlediting.h
@@ -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;
};
//------------------------------------------------------------------------------------------
diff --git a/WebCore/khtml/editing/htmlediting_impl.cpp b/WebCore/khtml/editing/htmlediting_impl.cpp
index d2156f7..2d128ff 100644
--- a/WebCore/khtml/editing/htmlediting_impl.cpp
+++ b/WebCore/khtml/editing/htmlediting_impl.cpp
@@ -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,21 +1976,67 @@ 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
RemoveCSSPropertyCommandImpl::RemoveCSSPropertyCommandImpl(DocumentImpl *document, CSSStyleDeclarationImpl *decl, int property)
diff --git a/WebCore/khtml/editing/htmlediting_impl.h b/WebCore/khtml/editing/htmlediting_impl.h
index 0279a97..f33ae3c 100644
--- a/WebCore/khtml/editing/htmlediting_impl.h
+++ b/WebCore/khtml/editing/htmlediting_impl.h
@@ -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;
};
//------------------------------------------------------------------------------------------
diff --git a/WebCore/khtml/khtml_part.cpp b/WebCore/khtml/khtml_part.cpp
index 0dfeec8..4374f61 100644
--- a/WebCore/khtml/khtml_part.cpp
+++ b/WebCore/khtml/khtml_part.cpp
@@ -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 )
diff --git a/WebCore/khtml/khtml_part.h b/WebCore/khtml/khtml_part.h
index e974f8d..71d90d1 100644
--- a/WebCore/khtml/khtml_part.h
+++ b/WebCore/khtml/khtml_part.h
@@ -570,11 +570,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.
*/
void clearSelection();
@@ -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
diff --git a/WebCore/khtml/khtmlpart_p.h b/WebCore/khtml/khtmlpart_p.h
index 13aacde..d9aaddf 100644
--- a/WebCore/khtml/khtmlpart_p.h
+++ b/WebCore/khtml/khtmlpart_p.h
@@ -352,6 +352,7 @@ public:
#endif
DOM::Selection m_selection;
+ DOM::Selection m_dragCaret;
int m_caretBlinkTimer;
bool m_caretVisible:1;
diff --git a/WebCore/khtml/rendering/render_block.cpp b/WebCore/khtml/rendering/render_block.cpp
index 780ffab..09a400a 100644
--- a/WebCore/khtml/rendering/render_block.cpp
+++ b/WebCore/khtml/rendering/render_block.cpp
@@ -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);
}
}
diff --git a/WebCore/kwq/DOM.mm b/WebCore/kwq/DOM.mm
index 6372431..f086cb1 100644
--- a/WebCore/kwq/DOM.mm
+++ b/WebCore/kwq/DOM.mm
@@ -91,10 +91,6 @@ using DOM::TreeWalkerImpl;
- (AttrImpl *)_attrImpl;
@end
- at interface DOMDocumentFragment (WebCoreInternal)
-+ (DOMDocumentFragment *)_documentFragmentWithImpl:(DocumentFragmentImpl *)impl;
- at 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
//------------------------------------------------------------------------------------------
diff --git a/WebCore/kwq/DOMInternal.h b/WebCore/kwq/DOMInternal.h
index 81f1a70..25fcb6b 100644
--- a/WebCore/kwq/DOMInternal.h
+++ b/WebCore/kwq/DOMInternal.h
@@ -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
+ at interface DOMDocumentFragment (WebCoreInternal)
++ (DOMDocumentFragment *)_documentFragmentWithImpl:(DOM::DocumentFragmentImpl *)impl;
+- (DOM::DocumentFragmentImpl *)_fragmentImpl;
+ at end
+
@interface DOMRange (WebCoreInternal)
+ (DOMRange *)_rangeWithImpl:(DOM::RangeImpl *)impl;
- (DOM::RangeImpl *)_rangeImpl;
diff --git a/WebCore/kwq/WebCoreBridge.h b/WebCore/kwq/WebCoreBridge.h
index b2ec943..05e8555 100644
--- a/WebCore/kwq/WebCoreBridge.h
+++ b/WebCore/kwq/WebCoreBridge.h
@@ -53,6 +53,7 @@ typedef khtml::RenderPart KHTMLRenderPart;
@class DOMCSSStyleDeclaration;
@class DOMDocument;
+ at 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;
diff --git a/WebCore/kwq/WebCoreBridge.mm b/WebCore/kwq/WebCoreBridge.mm
index 0f6fbf5..727c9dd 100644
--- a/WebCore/kwq/WebCoreBridge.mm
+++ b/WebCore/kwq/WebCoreBridge.mm
@@ -79,11 +79,13 @@
#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())
diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index 67dcc61..41c8f97 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,39 @@
+2004-05-24 Chris Blumenberg <cblu at 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 at apple.com>
Reviewed by Dave.
diff --git a/WebKit/WebView.subproj/WebDataSource.m b/WebKit/WebView.subproj/WebDataSource.m
index 65ca609..35f5b58 100644
--- a/WebKit/WebView.subproj/WebDataSource.m
+++ b/WebKit/WebView.subproj/WebDataSource.m
@@ -200,19 +200,15 @@
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];
@@ -222,15 +218,23 @@
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
diff --git a/WebKit/WebView.subproj/WebDataSourcePrivate.h b/WebKit/WebView.subproj/WebDataSourcePrivate.h
index 41ef331..0dbc668 100644
--- a/WebKit/WebView.subproj/WebDataSourcePrivate.h
+++ b/WebKit/WebView.subproj/WebDataSourcePrivate.h
@@ -8,6 +8,8 @@
#import <WebKit/WebDataSource.h>
+ at class DOMDocumentFragment;
+ at class DOMRange;
@class NSError;
@class NSURLRequest;
@class NSURLResponse;
@@ -126,9 +128,9 @@
- (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;
diff --git a/WebKit/WebView.subproj/WebDocumentInternal.h b/WebKit/WebView.subproj/WebDocumentInternal.h
index 055ce62..498f73d 100644
--- a/WebKit/WebView.subproj/WebDocumentInternal.h
+++ b/WebKit/WebView.subproj/WebDocumentInternal.h
@@ -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
diff --git a/WebKit/WebView.subproj/WebHTMLView.m b/WebKit/WebView.subproj/WebHTMLView.m
index 166d65b..7530b54 100644
--- a/WebKit/WebView.subproj/WebHTMLView.m
+++ b/WebKit/WebView.subproj/WebHTMLView.m
@@ -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
diff --git a/WebKit/WebView.subproj/WebHTMLViewPrivate.h b/WebKit/WebView.subproj/WebHTMLViewPrivate.h
index be9e00c..a1b2f5c 100644
--- a/WebKit/WebView.subproj/WebHTMLViewPrivate.h
+++ b/WebKit/WebView.subproj/WebHTMLViewPrivate.h
@@ -6,6 +6,8 @@
#import <WebKit/WebHTMLView.h>
+ at class DOMDocumentFragment;
+ at class DOMRange;
@class WebArchive;
@class WebBridge;
@class WebView;
@@ -71,12 +73,13 @@
+ (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;
diff --git a/WebKit/WebView.subproj/WebView.m b/WebKit/WebView.subproj/WebView.m
index 32477b3..7e7b740 100644
--- a/WebKit/WebView.subproj/WebView.m
+++ b/WebKit/WebView.subproj/WebView.m
@@ -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;
diff --git a/WebKit/WebView.subproj/WebViewPrivate.h b/WebKit/WebView.subproj/WebViewPrivate.h
index 52fdd39..ad49868 100644
--- a/WebKit/WebView.subproj/WebViewPrivate.h
+++ b/WebKit/WebView.subproj/WebViewPrivate.h
@@ -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;
+
+ at 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
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list