diff options
author | Ben Murdoch <benm@google.com> | 2010-08-11 14:44:44 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2010-08-12 19:15:41 +0100 |
commit | dd8bb3de4f353a81954234999f1fea748aee2ea9 (patch) | |
tree | 729b52bf09294f0d6c67cd5ea80aee1b727b7bd8 /WebCore/editing/Editor.cpp | |
parent | f3d41ba51d86bf719c7a65ab5297aea3c17e2d98 (diff) | |
download | external_webkit-dd8bb3de4f353a81954234999f1fea748aee2ea9.zip external_webkit-dd8bb3de4f353a81954234999f1fea748aee2ea9.tar.gz external_webkit-dd8bb3de4f353a81954234999f1fea748aee2ea9.tar.bz2 |
Merge WebKit at r65072 : Initial merge by git.
Change-Id: Ibcf418498376b2660aacb7f8d46ea7085ef91585
Diffstat (limited to 'WebCore/editing/Editor.cpp')
-rw-r--r-- | WebCore/editing/Editor.cpp | 60 |
1 files changed, 53 insertions, 7 deletions
diff --git a/WebCore/editing/Editor.cpp b/WebCore/editing/Editor.cpp index 44d8d5f..7a1ad4d 100644 --- a/WebCore/editing/Editor.cpp +++ b/WebCore/editing/Editor.cpp @@ -66,6 +66,7 @@ #include "Settings.h" #include "Sound.h" #include "Text.h" +#include "TextEvent.h" #include "TextIterator.h" #include "TypingCommand.h" #include "UserTypingGestureIndicator.h" @@ -127,6 +128,26 @@ void Editor::handleInputMethodKeydown(KeyboardEvent* event) c->handleInputMethodKeydown(event); } +bool Editor::handleTextEvent(TextEvent* event) +{ + if (event->isPaste()) { + if (event->pastingFragment()) + replaceSelectionWithFragment(event->pastingFragment(), false, event->shouldSmartReplace(), event->shouldMatchStyle()); + else + replaceSelectionWithText(event->data(), false, event->shouldSmartReplace()); + return true; + } + + String data = event->data(); + if (data == "\n") { + if (event->isLineBreak()) + return insertLineBreak(); + return insertParagraphSeparator(); + } + + return insertTextWithoutSendingTextEvent(data, false, event); +} + bool Editor::canEdit() const { return m_frame->selection()->isContentEditable(); @@ -282,11 +303,29 @@ void Editor::deleteSelectionWithSmartDelete(bool smartDelete) applyCommand(DeleteSelectionCommand::create(m_frame->document(), smartDelete)); } +void Editor::pasteAsPlainText(const String& pastingText, bool smartReplace) +{ + Node* target = findEventTargetFromSelection(); + if (!target) + return; + ExceptionCode ec = 0; + target->dispatchEvent(TextEvent::createForPlainTextPaste(m_frame->domWindow(), pastingText, smartReplace), ec); +} + +void Editor::pasteAsFragment(PassRefPtr<DocumentFragment> pastingFragment, bool smartReplace, bool matchStyle) +{ + Node* target = findEventTargetFromSelection(); + if (!target) + return; + ExceptionCode ec = 0; + target->dispatchEvent(TextEvent::createForFragmentPaste(m_frame->domWindow(), pastingFragment, smartReplace, matchStyle), ec); +} + void Editor::pasteAsPlainTextWithPasteboard(Pasteboard* pasteboard) { String text = pasteboard->plainText(m_frame); if (client() && client()->shouldInsertText(text, selectedRange().get(), EditorInsertActionPasted)) - replaceSelectionWithText(text, false, canSmartReplaceWithPasteboard(pasteboard)); + pasteAsPlainText(text, canSmartReplaceWithPasteboard(pasteboard)); } void Editor::pasteWithPasteboard(Pasteboard* pasteboard, bool allowPlainText) @@ -295,7 +334,7 @@ void Editor::pasteWithPasteboard(Pasteboard* pasteboard, bool allowPlainText) bool chosePlainText; RefPtr<DocumentFragment> fragment = pasteboard->documentFragment(m_frame, range, allowPlainText, chosePlainText); if (fragment && shouldInsertFragment(fragment, range, EditorInsertActionPasted)) - replaceSelectionWithFragment(fragment, false, canSmartReplaceWithPasteboard(pasteboard), chosePlainText); + pasteAsFragment(fragment, canSmartReplaceWithPasteboard(pasteboard), chosePlainText); } bool Editor::canSmartReplaceWithPasteboard(Pasteboard* pasteboard) @@ -706,12 +745,9 @@ void Editor::clearLastEditCommand() // the event handler NOT setting the return value to false bool Editor::dispatchCPPEvent(const AtomicString &eventType, ClipboardAccessPolicy policy) { - Node* target = m_frame->selection()->start().element(); - if (!target) - target = m_frame->document()->body(); + Node* target = findEventTargetFromSelection(); if (!target) return true; - target = target->shadowAncestorNode(); RefPtr<Clipboard> clipboard = newGeneralClipboard(policy, m_frame); @@ -726,6 +762,16 @@ bool Editor::dispatchCPPEvent(const AtomicString &eventType, ClipboardAccessPoli return !noDefaultProcessing; } +Node* Editor::findEventTargetFromSelection() const +{ + Node* target = m_frame->selection()->start().element(); + if (!target) + target = m_frame->document()->body(); + if (!target) + return 0; + return target->shadowAncestorNode(); +} + void Editor::applyStyle(CSSStyleDeclaration* style, EditAction editingAction) { switch (m_frame->selection()->selectionType()) { @@ -2359,7 +2405,7 @@ bool Editor::spellCheckingEnabledInFocusedNode() const const Node* node = frame()->document()->focusedNode(); while (node) { if (node->isElementNode()) { - const WebCore::AtomicString& value = static_cast<const Element*>(node)->getAttribute(spellcheckAttr); + const WTF::AtomicString& value = static_cast<const Element*>(node)->getAttribute(spellcheckAttr); if (equalIgnoringCase(value, "true")) return true; if (equalIgnoringCase(value, "false")) |