Title: [105491] trunk/Source/WebKit/chromium
Revision
105491
Author
[email protected]
Date
2012-01-20 00:59:14 -0800 (Fri, 20 Jan 2012)

Log Message

[chromium] Chromium should have EditorClientImpl::checkTextOfParagraph.
https://bugs.webkit.org/show_bug.cgi?id=74071

Patch by Shinya Kawanaka <[email protected]> on 2012-01-20
Reviewed by Darin Fisher.

Spellchecker on Mac has more sophisticated interface for spellchecking (checkTextOfParagraph).
If the other ports have the same interface, code can be clearer and easy to extend.
This patch introduces such an interface. The implementation will be done not in WebKit but in Chromium.

Also, currently WebKit::WebTextCheckingResult and WebCore::TextCheckingResult have different forms.
They should be corresponding apparently. This patch introduces such correspondence.

* WebKit.gyp:
* public/WebSpellCheckClient.h:
(WebKit::WebSpellCheckClient::checkTextOfParagraph):
  A new interface for spellchecking.
* public/WebTextCheckingResult.h:
(WebKit::WebTextCheckingResult::WebTextCheckingResult):
  Changed so that WebTextCheckingResult corresponds to WebCore::TextCheckingResult.
* public/WebTextCheckingType.h: Copied from Source/WebKit/chromium/public/WebTextCheckingResult.h.
* src/AssertMatchingEnums.cpp:
* src/EditorClientImpl.cpp:
(WebKit::EditorClientImpl::checkTextOfParagraph):
* src/EditorClientImpl.h:
* src/WebTextCheckingResult.cpp: Copied from Source/WebKit/chromium/public/WebTextCheckingResult.h.
(WebKit::WebTextCheckingResult::operator TextCheckingResult):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/chromium/ChangeLog (105490 => 105491)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-01-20 08:47:22 UTC (rev 105490)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-01-20 08:59:14 UTC (rev 105491)
@@ -1,5 +1,34 @@
 2012-01-20  Shinya Kawanaka  <[email protected]>
 
+        [chromium] Chromium should have EditorClientImpl::checkTextOfParagraph.
+        https://bugs.webkit.org/show_bug.cgi?id=74071
+
+        Reviewed by Darin Fisher.
+
+        Spellchecker on Mac has more sophisticated interface for spellchecking (checkTextOfParagraph).
+        If the other ports have the same interface, code can be clearer and easy to extend.
+        This patch introduces such an interface. The implementation will be done not in WebKit but in Chromium.
+
+        Also, currently WebKit::WebTextCheckingResult and WebCore::TextCheckingResult have different forms.
+        They should be corresponding apparently. This patch introduces such correspondence.
+
+        * WebKit.gyp:
+        * public/WebSpellCheckClient.h:
+        (WebKit::WebSpellCheckClient::checkTextOfParagraph):
+          A new interface for spellchecking.
+        * public/WebTextCheckingResult.h:
+        (WebKit::WebTextCheckingResult::WebTextCheckingResult):
+          Changed so that WebTextCheckingResult corresponds to WebCore::TextCheckingResult.
+        * public/WebTextCheckingType.h: Copied from Source/WebKit/chromium/public/WebTextCheckingResult.h.
+        * src/AssertMatchingEnums.cpp:
+        * src/EditorClientImpl.cpp:
+        (WebKit::EditorClientImpl::checkTextOfParagraph):
+        * src/EditorClientImpl.h:
+        * src/WebTextCheckingResult.cpp: Copied from Source/WebKit/chromium/public/WebTextCheckingResult.h.
+        (WebKit::WebTextCheckingResult::operator TextCheckingResult):
+
+2012-01-20  Shinya Kawanaka  <[email protected]>
+
         [chromium] WebFrame should have an interface to invoke spellchecking in arbitrarily.
         https://bugs.webkit.org/show_bug.cgi?id=73971
 

Modified: trunk/Source/WebKit/chromium/WebKit.gyp (105490 => 105491)


--- trunk/Source/WebKit/chromium/WebKit.gyp	2012-01-20 08:47:22 UTC (rev 105490)
+++ trunk/Source/WebKit/chromium/WebKit.gyp	2012-01-20 08:59:14 UTC (rev 105491)
@@ -470,6 +470,7 @@
                 'src/UserMediaClientImpl.cpp',
                 'src/WebTextCheckingCompletionImpl.h',
                 'src/WebTextCheckingCompletionImpl.cpp',
+                'src/WebTextCheckingResult.cpp',
                 'src/VideoFrameChromiumImpl.cpp',
                 'src/VideoFrameChromiumImpl.h',
                 'src/WebAccessibilityObject.cpp',

Modified: trunk/Source/WebKit/chromium/public/WebSpellCheckClient.h (105490 => 105491)


--- trunk/Source/WebKit/chromium/public/WebSpellCheckClient.h	2012-01-20 08:47:22 UTC (rev 105490)
+++ trunk/Source/WebKit/chromium/public/WebSpellCheckClient.h	2012-01-20 08:59:14 UTC (rev 105491)
@@ -31,6 +31,7 @@
 #ifndef WebSpellCheckClient_h
 #define WebSpellCheckClient_h
 
+#include "WebTextCheckingType.h"
 #include "platform/WebString.h"
 #include "platform/WebVector.h"
 
@@ -38,6 +39,7 @@
 
 class WebString;
 class WebTextCheckingCompletion;
+struct WebTextCheckingResult;
 
 class WebSpellCheckClient {
 public:
@@ -51,6 +53,13 @@
                             int& misspelledOffset,
                             int& misspelledLength,
                             WebVector<WebString>* optionalSuggestions) { }
+
+    // The client should perform spell-checking on the given text. This function will
+    // enumerate all misspellings at once.
+    virtual void checkTextOfParagraph(const WebString&,
+                                      WebTextCheckingTypeMask mask,
+                                      WebVector<WebTextCheckingResult>* results) { }
+
     // Requests asynchronous spelling and grammar checking, whose result should be
     // returned by passed completion object.
     virtual void requestCheckingOfText(const WebString&, WebTextCheckingCompletion*) { }

Modified: trunk/Source/WebKit/chromium/public/WebTextCheckingResult.h (105490 => 105491)


--- trunk/Source/WebKit/chromium/public/WebTextCheckingResult.h	2012-01-20 08:47:22 UTC (rev 105490)
+++ trunk/Source/WebKit/chromium/public/WebTextCheckingResult.h	2012-01-20 08:59:14 UTC (rev 105491)
@@ -31,27 +31,66 @@
 #ifndef WebTextCheckingResult_h
 #define WebTextCheckingResult_h
 
+#include "WebTextCheckingType.h"
 #include "platform/WebCommon.h"
+#include "platform/WebString.h"
+#include "platform/WebVector.h"
 
+namespace WebCore {
+struct TextCheckingResult;
+}
+
 namespace WebKit {
 
 // A checked entry of text checking.
 struct WebTextCheckingResult {
+    // FIXME: Should be removed after we confirm Chromium does not use it.
     enum Error {
         ErrorSpelling = 1 << 0,
         ErrorGrammar = 1 << 1
     };
 
-    explicit WebTextCheckingResult(Error e = ErrorSpelling, int p = 0, int l = 0) 
-        : error(e)
+    explicit WebTextCheckingResult(Error e = ErrorSpelling, int p = 0, int l = 0)
+        : type(WebTextCheckingTypeSpelling)
+        , error(e)
         , position(p)
+        , location(p)
         , length(l)
     {
+        if (e & ErrorSpelling)
+            type = WebTextCheckingTypeSpelling;
+        else if (e & ErrorGrammar)
+            type = WebTextCheckingTypeGrammar;
+        else
+            WEBKIT_ASSERT_NOT_REACHED();
     }
 
-    Error error;
-    int position;
+    WebTextCheckingResult(WebTextCheckingType type, int location, int length, const WebString& replacement = WebString())
+        : type(type)
+        , error(ErrorSpelling)
+        , position(location)
+        , location(location)
+        , length(length)
+        , replacement(replacement)
+    {
+        if (type & WebTextCheckingTypeSpelling)
+            error = ErrorSpelling;
+        else if (type & WebTextCheckingTypeGrammar)
+            error = ErrorGrammar;
+        else
+            WEBKIT_ASSERT_NOT_REACHED();
+    }
+
+#if WEBKIT_IMPLEMENTATION
+    operator WebCore::TextCheckingResult() const;
+#endif
+
+    WebTextCheckingType type;
+    Error error; // FIXME: Should be removed after we confirm Chromium does not use it.
+    int position; // FIXME: Should be removed after we confirm Chromium does not use it.
+    int location;
     int length;
+    WebString replacement;
 };
 
 } // namespace WebKit

Copied: trunk/Source/WebKit/chromium/public/WebTextCheckingType.h (from rev 105490, trunk/Source/WebKit/chromium/public/WebTextCheckingResult.h) (0 => 105491)


--- trunk/Source/WebKit/chromium/public/WebTextCheckingType.h	                        (rev 0)
+++ trunk/Source/WebKit/chromium/public/WebTextCheckingType.h	2012-01-20 08:59:14 UTC (rev 105491)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebTextCheckingType_h
+#define WebTextCheckingType_h
+
+namespace WebKit {
+
+enum WebTextCheckingType {
+    WebTextCheckingTypeSpelling = 1 << 1,
+    WebTextCheckingTypeGrammar  = 1 << 2,
+    WebTextCheckingTypeLink = 1 << 5,
+    WebTextCheckingTypeQuote = 1 << 6,
+    WebTextCheckingTypeDash = 1 << 7,
+    WebTextCheckingTypeReplacement = 1 << 8,
+    WebTextCheckingTypeCorrection = 1 << 9,
+    WebTextCheckingTypeShowCorrectionPanel = 1 << 10
+};
+
+typedef unsigned WebTextCheckingTypeMask;
+
+} // namespace WebKit
+
+#endif

Modified: trunk/Source/WebKit/chromium/src/AssertMatchingEnums.cpp (105490 => 105491)


--- trunk/Source/WebKit/chromium/src/AssertMatchingEnums.cpp	2012-01-20 08:47:22 UTC (rev 105490)
+++ trunk/Source/WebKit/chromium/src/AssertMatchingEnums.cpp	2012-01-20 08:59:14 UTC (rev 105491)
@@ -61,6 +61,7 @@
 #include "Settings.h"
 #include "StorageInfo.h"
 #include "TextAffinity.h"
+#include "TextChecking.h"
 #include "TextControlInnerElements.h"
 #include "UserContentTypes.h"
 #include "UserScriptTypes.h"
@@ -91,6 +92,7 @@
 #include "WebStorageQuotaType.h"
 #include "WebTextAffinity.h"
 #include "WebTextCaseSensitivity.h"
+#include "WebTextCheckingType.h"
 #include "WebTextCheckingResult.h"
 #include "WebVideoFrame.h"
 #include "WebView.h"
@@ -455,6 +457,15 @@
 COMPILE_ASSERT_MATCHING_ENUM(WebTextCheckingResult::ErrorSpelling, DocumentMarker::Spelling);
 COMPILE_ASSERT_MATCHING_ENUM(WebTextCheckingResult::ErrorGrammar, DocumentMarker::Grammar);
 
+COMPILE_ASSERT_MATCHING_ENUM(WebTextCheckingTypeSpelling, TextCheckingTypeSpelling);
+COMPILE_ASSERT_MATCHING_ENUM(WebTextCheckingTypeGrammar, TextCheckingTypeGrammar);
+COMPILE_ASSERT_MATCHING_ENUM(WebTextCheckingTypeLink, TextCheckingTypeLink);
+COMPILE_ASSERT_MATCHING_ENUM(WebTextCheckingTypeQuote, TextCheckingTypeQuote);
+COMPILE_ASSERT_MATCHING_ENUM(WebTextCheckingTypeDash, TextCheckingTypeDash);
+COMPILE_ASSERT_MATCHING_ENUM(WebTextCheckingTypeReplacement, TextCheckingTypeReplacement);
+COMPILE_ASSERT_MATCHING_ENUM(WebTextCheckingTypeCorrection, TextCheckingTypeCorrection);
+COMPILE_ASSERT_MATCHING_ENUM(WebTextCheckingTypeShowCorrectionPanel, TextCheckingTypeShowCorrectionPanel);
+
 #if ENABLE(QUOTA)
 COMPILE_ASSERT_MATCHING_ENUM(WebStorageQuotaErrorNotSupported, NOT_SUPPORTED_ERR);
 COMPILE_ASSERT_MATCHING_ENUM(WebStorageQuotaErrorAbort, ABORT_ERR);

Modified: trunk/Source/WebKit/chromium/src/EditorClientImpl.cpp (105490 => 105491)


--- trunk/Source/WebKit/chromium/src/EditorClientImpl.cpp	2012-01-20 08:47:22 UTC (rev 105490)
+++ trunk/Source/WebKit/chromium/src/EditorClientImpl.cpp	2012-01-20 08:59:14 UTC (rev 105491)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2006, 2007 Apple, Inc.  All rights reserved.
- * Copyright (C) 2010 Google, Inc.  All rights reserved.
+ * Copyright (C) 2012 Google, Inc.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -57,6 +57,7 @@
 #include "WebSpellCheckClient.h"
 #include "WebTextAffinity.h"
 #include "WebTextCheckingCompletionImpl.h"
+#include "WebTextCheckingResult.h"
 #include "WebViewClient.h"
 #include "WebViewImpl.h"
 
@@ -765,6 +766,22 @@
         *badGrammarLength = 0;
 }
 
+void EditorClientImpl::checkTextOfParagraph(const UChar* text, int length,
+                                            TextCheckingTypeMask mask,
+                                            WTF::Vector<TextCheckingResult>& results)
+{
+    if (!m_webView->spellCheckClient())
+        return;
+
+    WebTextCheckingTypeMask webMask = static_cast<WebTextCheckingTypeMask>(mask);
+    WebVector<WebTextCheckingResult> webResults;
+    m_webView->spellCheckClient()->checkTextOfParagraph(WebString(text, length), webMask, &webResults);
+
+    results.resize(webResults.size());
+    for (size_t i = 0; i < webResults.size(); ++i)
+        results[i] = webResults[i];
+}
+
 void EditorClientImpl::updateSpellingUIWithGrammarString(const String&,
                                                          const GrammarDetail& detail)
 {

Modified: trunk/Source/WebKit/chromium/src/EditorClientImpl.h (105490 => 105491)


--- trunk/Source/WebKit/chromium/src/EditorClientImpl.h	2012-01-20 08:47:22 UTC (rev 105490)
+++ trunk/Source/WebKit/chromium/src/EditorClientImpl.h	2012-01-20 08:59:14 UTC (rev 105491)
@@ -99,6 +99,8 @@
     virtual void checkSpellingOfString(const UChar*, int length, int* misspellingLocation, int* misspellingLength);
     virtual void checkGrammarOfString(const UChar*, int length, WTF::Vector<WebCore::GrammarDetail>&,
         int* badGrammarLocation, int* badGrammarLength);
+    virtual void checkTextOfParagraph(const UChar*, int length, WebCore::TextCheckingTypeMask checkingTypes,
+        WTF::Vector<WebCore::TextCheckingResult>& results);
     virtual WTF::String getAutoCorrectSuggestionForMisspelledWord(const WTF::String&);
     virtual void updateSpellingUIWithGrammarString(const WTF::String&, const WebCore::GrammarDetail&);
     virtual void updateSpellingUIWithMisspelledWord(const WTF::String&);

Copied: trunk/Source/WebKit/chromium/src/WebTextCheckingResult.cpp (from rev 105490, trunk/Source/WebKit/chromium/public/WebTextCheckingResult.h) (0 => 105491)


--- trunk/Source/WebKit/chromium/src/WebTextCheckingResult.cpp	                        (rev 0)
+++ trunk/Source/WebKit/chromium/src/WebTextCheckingResult.cpp	2012-01-20 08:59:14 UTC (rev 105491)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebTextCheckingResult.h"
+
+#include "TextCheckerClient.h"
+
+using namespace WebCore;
+
+namespace WebKit {
+
+WebTextCheckingResult::operator TextCheckingResult() const
+{
+    TextCheckingResult result;
+    result.type = static_cast<TextCheckingType>(type);
+    result.location = location;
+    result.length = length;
+    result.replacement = replacement;
+
+    return result;
+}
+
+} // namespace WebKit
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to