WinCairo build fails to link.
[WebKit-https.git] / Source / WebKit / chromium / src / EditorClientImpl.cpp
index 8b04515..1d13c8e 100644 (file)
@@ -36,8 +36,9 @@
 #include "HTMLNames.h"
 #include "KeyboardCodes.h"
 #include "KeyboardEvent.h"
+#include "NotImplemented.h"
+#include "Page.h"
 #include "PlatformKeyboardEvent.h"
-#include "PlatformString.h"
 #include "RenderObject.h"
 #include "Settings.h"
 #include "SpellChecker.h"
@@ -49,9 +50,9 @@
 #include "WebElement.h"
 #include "WebFrameClient.h"
 #include "WebFrameImpl.h"
-#include "WebKit.h"
 #include "WebInputElement.h"
 #include "WebInputEventConversion.h"
+#include "WebKit.h"
 #include "WebNode.h"
 #include "WebPermissionClient.h"
 #include "WebRange.h"
@@ -61,6 +62,7 @@
 #include "WebTextCheckingResult.h"
 #include "WebViewClient.h"
 #include "WebViewImpl.h"
+#include <wtf/text/WTFString.h>
 
 using namespace WebCore;
 
@@ -90,44 +92,20 @@ void EditorClientImpl::pageDestroyed()
 
 void EditorClientImpl::frameWillDetachPage(WebCore::Frame* frame)
 {
-    HashSet<WebTextCheckingCompletionImpl*> validRequests;
-
-    for (HashSet<WebTextCheckingCompletionImpl*>::iterator i = m_pendingTextChecks.begin();
-         i != m_pendingTextChecks.end(); ++i) {
-        if (frame->editor()->spellChecker() == (*i)->spellChecker())
-            (*i)->invalidate();
-        else
-            validRequests.add(*i);
-    }
-
-    m_pendingTextChecks.swap(validRequests);
-}
-
-bool EditorClientImpl::shouldShowDeleteInterface(HTMLElement* elem)
-{
-    // Normally, we don't care to show WebCore's deletion UI, so we only enable
-    // it if in testing mode and the test specifically requests it by using this
-    // magic class name.
-    return layoutTestMode()
-           && elem->getAttribute(HTMLNames::classAttr) == "needsDeletionUI";
 }
 
 bool EditorClientImpl::smartInsertDeleteEnabled()
 {
-    if (m_webView->client())
-        return m_webView->client()->isSmartInsertDeleteEnabled();
-    return true;
+    if (m_webView->page())
+        return m_webView->page()->settings()->smartInsertDeleteEnabled();
+    return false;
 }
 
 bool EditorClientImpl::isSelectTrailingWhitespaceEnabled()
 {
-    if (m_webView->client())
-        return m_webView->client()->isSelectTrailingWhitespaceEnabled();
-#if OS(WINDOWS)
-    return true;
-#else
+    if (m_webView->page())
+        return m_webView->page()->settings()->selectTrailingWhitespaceEnabled();
     return false;
-#endif
 }
 
 bool EditorClientImpl::shouldSpellcheckByDefault()
@@ -181,7 +159,7 @@ void EditorClientImpl::toggleContinuousSpellChecking()
 bool EditorClientImpl::isGrammarCheckingEnabled()
 {
     const Frame* frame = m_webView->focusedWebCoreFrame();
-    return frame && frame->settings() && frame->settings()->asynchronousSpellCheckingEnabled();
+    return frame && frame->settings() && (frame->settings()->asynchronousSpellCheckingEnabled() || frame->settings()->unifiedTextCheckerEnabled());
 }
 
 void EditorClientImpl::toggleGrammarChecking()
@@ -279,8 +257,11 @@ void EditorClientImpl::didBeginEditing()
 void EditorClientImpl::respondToChangedSelection(Frame* frame)
 {
     if (m_webView->client()) {
-        if (frame)
+        if (frame) {
             m_webView->client()->didChangeSelection(!frame->selection()->isRange());
+            if (frame->editor()->cancelCompositionIfSelectionIsInvalid())
+                m_webView->client()->didCancelCompositionOnSelectionChange();
+        }
     }
 }
 
@@ -300,6 +281,14 @@ void EditorClientImpl::didWriteSelectionToPasteboard()
 {
 }
 
+void EditorClientImpl::willWriteSelectionToPasteboard(WebCore::Range*)
+{
+}
+
+void EditorClientImpl::getClientPasteboardDataForRange(WebCore::Range*, Vector<String>&, Vector<RefPtr<WebCore::SharedBuffer> >&)
+{
+}
+
 void EditorClientImpl::didSetSelectionTypesForPasteboard()
 {
 }
@@ -714,7 +703,7 @@ void EditorClientImpl::textDidChangeInTextArea(Element*)
 bool EditorClientImpl::shouldEraseMarkersAfterChangeSelection(TextCheckingType type) const
 {
     const Frame* frame = m_webView->focusedWebCoreFrame();
-    return !frame || !frame->settings() || !frame->settings()->asynchronousSpellCheckingEnabled();
+    return !frame || !frame->settings() || (!frame->settings()->asynchronousSpellCheckingEnabled() && !frame->settings()->unifiedTextCheckerEnabled());
 }
 
 void EditorClientImpl::ignoreWordInSpellDocument(const String&)
@@ -737,7 +726,7 @@ void EditorClientImpl::checkSpellingOfString(const UChar* text, int length,
     int spellLength = 0;
 
     // Check to see if the provided text is spelled correctly.
-    if (isContinuousSpellCheckingEnabled() && m_webView->spellCheckClient())
+    if (m_webView->spellCheckClient())
         m_webView->spellCheckClient()->spellCheck(WebString(text, length), spellLocation, spellLength, 0);
     else {
         spellLocation = 0;
@@ -752,19 +741,12 @@ void EditorClientImpl::checkSpellingOfString(const UChar* text, int length,
         *misspellingLength = spellLength;
 }
 
-void EditorClientImpl::requestCheckingOfString(SpellChecker* sender, const WebCore::TextCheckingRequest& request)
+void EditorClientImpl::requestCheckingOfString(WTF::PassRefPtr<WebCore::TextCheckingRequest> request)
 {
-    if (!m_webView->spellCheckClient())
-        return;
-
-    WebTextCheckingCompletionImpl* completion = new WebTextCheckingCompletionImpl(request.sequence(), sender, this);
-    m_pendingTextChecks.add(completion);
-    m_webView->spellCheckClient()->requestCheckingOfText(request.text(), completion);
-}
-
-void EditorClientImpl::didCheckString(WebTextCheckingCompletionImpl* completion)
-{
-    m_pendingTextChecks.remove(completion);
+    if (m_webView->spellCheckClient()) {
+        String text = request->data().text();
+        m_webView->spellCheckClient()->requestCheckingOfText(text, new WebTextCheckingCompletionImpl(request));
+    }
 }
 
 String EditorClientImpl::getAutoCorrectSuggestionForMisspelledWord(const String& misspelledWord)
@@ -784,16 +766,39 @@ String EditorClientImpl::getAutoCorrectSuggestionForMisspelledWord(const String&
     return String();
 }
 
-void EditorClientImpl::checkGrammarOfString(const UChar*, int length,
-                                            WTF::Vector<GrammarDetail>&,
-                                            int* badGrammarLocation,
-                                            int* badGrammarLength)
+void EditorClientImpl::checkGrammarOfString(const UChar* text, int length, WTF::Vector<GrammarDetail>& details, int* badGrammarLocation, int* badGrammarLength)
 {
-    notImplemented();
     if (badGrammarLocation)
-        *badGrammarLocation = 0;
+        *badGrammarLocation = -1;
     if (badGrammarLength)
         *badGrammarLength = 0;
+
+    if (!m_webView->spellCheckClient())
+        return;
+    WebVector<WebTextCheckingResult> webResults;
+    m_webView->spellCheckClient()->checkTextOfParagraph(WebString(text, length), WebTextCheckingTypeGrammar, &webResults);
+    if (!webResults.size())
+        return;
+
+    // Convert a list of WebTextCheckingResults to a list of GrammarDetails. If
+    // the converted vector of GrammarDetails has grammar errors, we set
+    // badGrammarLocation and badGrammarLength to tell WebKit that the input
+    // text has grammar errors.
+    for (size_t i = 0; i < webResults.size(); ++i) {
+        if (webResults[i].type == WebTextCheckingTypeGrammar) {
+            GrammarDetail detail;
+            detail.location = webResults[i].location;
+            detail.length = webResults[i].length;
+            detail.userDescription = webResults[i].replacement;
+            details.append(detail);
+        }
+    }
+    if (!details.size())
+        return;
+    if (badGrammarLocation)
+        *badGrammarLocation = 0;
+    if (badGrammarLength)
+        *badGrammarLength = length;
 }
 
 void EditorClientImpl::checkTextOfParagraph(const UChar* text, int length,
@@ -844,6 +849,15 @@ void EditorClientImpl::getGuessesForWord(const String& word,
     notImplemented();
 }
 
+bool EditorClientImpl::supportsGlobalSelection()
+{
+#if OS(UNIX) && !OS(DARWIN)
+    return true;
+#else
+    return false;
+#endif
+}
+
 void EditorClientImpl::willSetInputMethodState()
 {
     if (m_webView->client())