Redo spellchecking of a field if the layout has changed
[WebKit-https.git] / Source / WebKit / blackberry / WebCoreSupport / EditorClientBlackBerry.cpp
index d1ed4f4..cf0cccb 100644 (file)
@@ -33,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"
 
@@ -67,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)
@@ -110,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;
     }
@@ -191,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()))
@@ -253,6 +256,16 @@ 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();
@@ -393,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[] = {
@@ -464,9 +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.
-        m_webPagePrivate->m_inputHandler->setProcessingChange(false);
+        if (commandName != "DeleteBackward")
+            m_webPagePrivate->m_inputHandler->setProcessingChange(false);
+
         if (frame->editor()->command(commandName).execute())
             event->setDefaultHandled();
         return;
@@ -507,15 +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* element)
 {
-    if (HTMLInputElement* inputElement = element->toInputElement())
-        m_webPagePrivate->m_autofillManager->didChangeInTextField(inputElement);
+    if (m_webPagePrivate->m_webSettings->isFormAutofillEnabled()) {
+        if (HTMLInputElement* inputElement = element->toInputElement())
+            m_webPagePrivate->m_autofillManager->didChangeInTextField(inputElement);
+    }
 }
 
 bool EditorClientBlackBerry::doTextFieldCommandFromEvent(Element*, KeyboardEvent*)
@@ -551,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)
@@ -565,7 +579,13 @@ void EditorClientBlackBerry::checkGrammarOfString(const UChar*, int, WTF::Vector
     notImplemented();
 }
 
-void EditorClientBlackBerry::requestCheckingOfString(WTF::PassRefPtr<WebCore::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();
 }