Redo spellchecking of a field if the layout has changed
[WebKit-https.git] / Source / WebKit / blackberry / WebCoreSupport / EditorClientBlackBerry.cpp
index ff92bd9..cf0cccb 100644 (file)
@@ -20,6 +20,7 @@
 #include "config.h"
 #include "EditorClientBlackBerry.h"
 
+#include "AutofillManager.h"
 #include "DOMSupport.h"
 #include "DumpRenderTreeClient.h"
 #include "EditCommand.h"
@@ -32,6 +33,8 @@
 #include "Page.h"
 #include "PlatformKeyboardEvent.h"
 #include "SelectionHandler.h"
+#include "Settings.h"
+#include "SpellChecker.h"
 #include "WebPage_p.h"
 #include "WindowsKeyboardCodes.h"
 
@@ -66,23 +69,20 @@ bool EditorClientBlackBerry::shouldDeleteRange(Range* range)
     return true;
 }
 
-bool EditorClientBlackBerry::shouldShowDeleteInterface(HTMLElement*)
-{
-    notImplemented();
-    return false;
-}
-
 bool EditorClientBlackBerry::smartInsertDeleteEnabled()
 {
-    notImplemented();
-    return false;
+    Page* page = WebPagePrivate::core(m_webPagePrivate->m_webPage);
+    if (!page)
+        return false;
+    return page->settings()->smartInsertDeleteEnabled();
 }
 
 bool EditorClientBlackBerry::isSelectTrailingWhitespaceEnabled()
 {
-    if (m_webPagePrivate->m_dumpRenderTree)
-        return m_webPagePrivate->m_dumpRenderTree->isSelectTrailingWhitespaceEnabled();
-    return false;
+    Page* page = WebPagePrivate::core(m_webPagePrivate->m_webPage);
+    if (!page)
+        return false;
+    return page->settings()->selectTrailingWhitespaceEnabled();
 }
 
 void EditorClientBlackBerry::enableSpellChecking(bool enable)
@@ -109,7 +109,7 @@ bool EditorClientBlackBerry::shouldSpellCheckFocusedField()
 
     // If the field does not support autocomplete, do not do spellchecking.
     if (node->isElementNode()) {
-        const Element* element = static_cast<const Element*>(node);
+        const Element* element = toElement(node);
         if (element->hasTagName(HTMLNames::inputTag) && !DOMSupport::elementSupportsAutocomplete(element))
             return false;
     }
@@ -190,8 +190,12 @@ bool EditorClientBlackBerry::shouldChangeSelectedRange(Range* fromRange, Range*
 
     Frame* frame = m_webPagePrivate->focusedOrMainFrame();
     if (frame && frame->document()) {
-        if (frame->document()->focusedNode() && frame->document()->focusedNode()->hasTagName(HTMLNames::selectTag))
-            return false;
+        if (Node* focusedNode = frame->document()->focusedNode()) {
+            if (focusedNode->hasTagName(HTMLNames::selectTag))
+                return false;
+            if (focusedNode->isElementNode() && DOMSupport::isPopupInputField(toElement(focusedNode)))
+                return false;
+        }
 
         // Check if this change does not represent a focus change and input is active and if so ensure the keyboard is visible.
         if (m_webPagePrivate->m_inputHandler->isInputMode() && fromRange && toRange && (fromRange->startContainer() == toRange->startContainer()))
@@ -252,12 +256,22 @@ void EditorClientBlackBerry::didWriteSelectionToPasteboard()
     notImplemented();
 }
 
+void EditorClientBlackBerry::willWriteSelectionToPasteboard(WebCore::Range*)
+{
+    notImplemented();
+}
+
+void EditorClientBlackBerry::getClientPasteboardDataForRange(WebCore::Range*, Vector<String>&, Vector<RefPtr<WebCore::SharedBuffer> >&)
+{
+    notImplemented();
+}
+
 void EditorClientBlackBerry::didSetSelectionTypesForPasteboard()
 {
     notImplemented();
 }
 
-void EditorClientBlackBerry::registerCommandForUndo(PassRefPtr<EditCommand> command)
+void EditorClientBlackBerry::registerUndoStep(PassRefPtr<UndoStep> step)
 {
     // Remove the oldest item if we've reached the maximum capacity for the stack.
     if (m_undoStack.size() == maximumUndoStackDepth)
@@ -266,12 +280,12 @@ void EditorClientBlackBerry::registerCommandForUndo(PassRefPtr<EditCommand> comm
     if (!m_inRedo)
         m_redoStack.clear();
 
-    m_undoStack.append(command);
+    m_undoStack.append(step);
 }
 
-void EditorClientBlackBerry::registerCommandForRedo(PassRefPtr<EditCommand> command)
+void EditorClientBlackBerry::registerRedoStep(PassRefPtr<UndoStep> step)
 {
-    m_redoStack.append(command);
+    m_redoStack.append(step);
 }
 
 void EditorClientBlackBerry::clearUndoRedoOperations()
@@ -304,7 +318,7 @@ void EditorClientBlackBerry::undo()
 {
     if (canUndo()) {
         EditCommandStack::iterator back = --m_undoStack.end();
-        RefPtr<EditCommand> command(*back);
+        RefPtr<UndoStep> command(*back);
         m_undoStack.remove(back);
 
         // Unapply will call us back to push this command onto the redo stack.
@@ -316,7 +330,7 @@ void EditorClientBlackBerry::redo()
 {
     if (canRedo()) {
         EditCommandStack::iterator back = --m_redoStack.end();
-        RefPtr<EditCommand> command(*back);
+        RefPtr<UndoStep> command(*back);
         m_redoStack.remove(back);
 
         ASSERT(!m_inRedo);
@@ -392,15 +406,6 @@ static const KeyDownEntry keyDownEntries[] = {
     { 'Z',       CtrlKey,            "Undo"                                        },
     { 'Z',       CtrlKey | ShiftKey, "Redo"                                        },
     { 'Y',       CtrlKey,            "Redo"                                        },
-
-    { VK_TAB,    0,                  "InsertTab"                                   },
-    { VK_TAB,    ShiftKey,           "InsertBacktab"                               },
-    { VK_RETURN, 0,                  "InsertNewline"                               },
-    { VK_RETURN, CtrlKey,            "InsertNewline"                               },
-    { VK_RETURN, AltKey,             "InsertNewline"                               },
-    { VK_RETURN, ShiftKey,           "InsertLineBreak"                             },
-    { VK_RETURN, AltKey | ShiftKey,  "InsertNewline"                               },
-
 };
 
 static const KeyPressEntry keyPressEntries[] = {
@@ -463,7 +468,14 @@ void EditorClientBlackBerry::handleKeyboardEvent(KeyboardEvent* event)
 
     String commandName = interpretKeyEvent(event);
 
+    // Check to see we are not trying to insert text on key down.
+    ASSERT(!(event->type() == eventNames().keydownEvent && frame->editor()->command(commandName).isTextInsertion()));
+
     if (!commandName.isEmpty()) {
+        // Hot key handling. Cancel processing mode.
+        if (commandName != "DeleteBackward")
+            m_webPagePrivate->m_inputHandler->setProcessingChange(false);
+
         if (frame->editor()->command(commandName).execute())
             event->setDefaultHandled();
         return;
@@ -504,14 +516,20 @@ void EditorClientBlackBerry::textFieldDidBeginEditing(Element*)
     notImplemented();
 }
 
-void EditorClientBlackBerry::textFieldDidEndEditing(Element*)
+void EditorClientBlackBerry::textFieldDidEndEditing(Element* element)
 {
-    notImplemented();
+    if (m_webPagePrivate->m_webSettings->isFormAutofillEnabled()) {
+        if (HTMLInputElement* inputElement = element->toInputElement())
+            m_webPagePrivate->m_autofillManager->textFieldDidEndEditing(inputElement);
+    }
 }
 
-void EditorClientBlackBerry::textDidChangeInTextField(Element*)
+void EditorClientBlackBerry::textDidChangeInTextField(Element* element)
 {
-    notImplemented();
+    if (m_webPagePrivate->m_webSettings->isFormAutofillEnabled()) {
+        if (HTMLInputElement* inputElement = element->toInputElement())
+            m_webPagePrivate->m_autofillManager->didChangeInTextField(inputElement);
+    }
 }
 
 bool EditorClientBlackBerry::doTextFieldCommandFromEvent(Element*, KeyboardEvent*)
@@ -530,6 +548,11 @@ void EditorClientBlackBerry::textDidChangeInTextArea(Element*)
     notImplemented();
 }
 
+bool EditorClientBlackBerry::shouldEraseMarkersAfterChangeSelection(TextCheckingType) const
+{
+    return true;
+}
+
 void EditorClientBlackBerry::ignoreWordInSpellDocument(const WTF::String&)
 {
     notImplemented();
@@ -542,7 +565,7 @@ void EditorClientBlackBerry::learnWord(const WTF::String&)
 
 void EditorClientBlackBerry::checkSpellingOfString(const UChar* text, int textLength, int* misspellLocation, int* misspellLength)
 {
-    m_webPagePrivate->m_client->checkSpellingOfString(text, textLength, *misspellLocation, *misspellLength);
+    notImplemented();
 }
 
 WTF::String EditorClientBlackBerry::getAutoCorrectSuggestionForMisspelledWord(const WTF::String& misspelledWord)
@@ -556,7 +579,13 @@ void EditorClientBlackBerry::checkGrammarOfString(const UChar*, int, WTF::Vector
     notImplemented();
 }
 
-void EditorClientBlackBerry::requestCheckingOfString(SpellChecker*, const TextCheckingRequest&)
+void EditorClientBlackBerry::requestCheckingOfString(PassRefPtr<TextCheckingRequest> testCheckingRequest)
+{
+    RefPtr<SpellCheckRequest> spellCheckRequest = static_cast<SpellCheckRequest*>(textCheckingRequest.get());
+    m_webPagePrivate->m_inputHandler->requestCheckingOfString(spellCheckRequest);
+}
+
+void EditorClientBlackBerry::checkTextOfParagraph(const UChar*, int, TextCheckingTypeMask, Vector<TextCheckingResult>&)
 {
     notImplemented();
 }