Changeset 100050 in webkit


Ignore:
Timestamp:
Nov 11, 2011 5:21:44 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Implement legacy text check emulation in unified text check interface.
https://bugs.webkit.org/show_bug.cgi?id=70299

Patch by Shinya Kawanaka <shinyak@google.com> on 2011-11-11
Reviewed by Hajime Morita.

.:

  • Source/autotools/symbols.filter:

Source/WebCore:

When UNIFIED_TEXT_CHECKING is off, WebCore::checkTextOfParagraph() emulates
TextCheckerClient::checkTextOfParagraph() using checkSpellingOfString and checkGrammarOfString.

This emulation can be used by setting the flag on.
This can be done by WebCore::Internals::setUnifiedTextCheckingEnabled.

Test: editing/spelling/spelling-unified-emulation.html

  • editing/TextCheckingHelper.cpp:

(WebCore::findBadGrammars): Added.
(WebCore::findMisspellings): Added.
(WebCore::checkTextOfParagraph):

Emulates TextCheckerClients::checkTextOfParagraph if UNIFIED_TEXT_CHECKING is off.

  • testing/Internals.cpp:

(WebCore::Internals::setUnifiedTextCheckingEnabled): flag setter.
(WebCore::Internals::unifiedTextCheckingEnabled): flag getter.

  • testing/Internals.h:
  • testing/Internals.idl:

Source/WebKit2:

  • win/WebKit2.def:
  • win/WebKit2CFLite.def:

LayoutTests:

Added tests for the case unified text checker is used when WebCore::checkTextOfParagraph() is not supported.

  • editing/spelling/spelling-unified-emulation-expected.txt: Added.
  • editing/spelling/spelling-unified-emulation.html: Added.
Location:
trunk
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r99961 r100050  
     12011-11-11  Shinya Kawanaka  <shinyak@google.com>
     2
     3        Implement legacy text check emulation in unified text check interface.
     4        https://bugs.webkit.org/show_bug.cgi?id=70299
     5
     6        Reviewed by Hajime Morita.
     7
     8        * Source/autotools/symbols.filter:
     9
    1102011-11-11  Alexis Menard  <alexis.menard@openbossa.org>
    211
  • trunk/LayoutTests/ChangeLog

    r100046 r100050  
     12011-11-11  Shinya Kawanaka  <shinyak@google.com>
     2
     3        Implement legacy text check emulation in unified text check interface.
     4        https://bugs.webkit.org/show_bug.cgi?id=70299
     5
     6        Reviewed by Hajime Morita.
     7
     8        Added tests for the case unified text checker is used when WebCore::checkTextOfParagraph() is not supported.
     9
     10        * editing/spelling/spelling-unified-emulation-expected.txt: Added.
     11        * editing/spelling/spelling-unified-emulation.html: Added.
     12
    1132011-11-11  Stephen Chenney  <schenney@chromium.org>
    214
  • trunk/Source/WebCore/ChangeLog

    r100049 r100050  
     12011-11-11  Shinya Kawanaka  <shinyak@google.com>
     2
     3        Implement legacy text check emulation in unified text check interface.
     4        https://bugs.webkit.org/show_bug.cgi?id=70299
     5
     6        Reviewed by Hajime Morita.
     7
     8        When UNIFIED_TEXT_CHECKING is off, WebCore::checkTextOfParagraph() emulates
     9        TextCheckerClient::checkTextOfParagraph() using checkSpellingOfString and checkGrammarOfString.
     10
     11        This emulation can be used by setting the flag on.
     12        This can be done by WebCore::Internals::setUnifiedTextCheckingEnabled.
     13
     14        Test: editing/spelling/spelling-unified-emulation.html
     15
     16        * editing/TextCheckingHelper.cpp:
     17        (WebCore::findBadGrammars): Added.
     18        (WebCore::findMisspellings): Added.
     19        (WebCore::checkTextOfParagraph):
     20          Emulates TextCheckerClients::checkTextOfParagraph if UNIFIED_TEXT_CHECKING is off.
     21        * testing/Internals.cpp:
     22        (WebCore::Internals::setUnifiedTextCheckingEnabled): flag setter.
     23        (WebCore::Internals::unifiedTextCheckingEnabled): flag getter.
     24        * testing/Internals.h:
     25        * testing/Internals.idl:
     26
    1272011-11-11  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
    228
  • trunk/Source/WebCore/editing/TextCheckingHelper.cpp

    r98598 r100050  
    3333#include "Range.h"
    3434#include "Settings.h"
     35#include "TextBreakIterator.h"
    3536#include "TextCheckerClient.h"
    3637#include "TextIterator.h"
     
    3940
    4041namespace WebCore {
     42
     43#if !USE(UNIFIED_TEXT_CHECKING)
     44static void findBadGrammars(TextCheckerClient* client, const UChar* text, int start, int length, Vector<TextCheckingResult>& results)
     45{
     46    ASSERT(WTF_USE_GRAMMAR_CHECKING);
     47
     48    int checkLocation = start;
     49    int checkLength = length;
     50
     51    while (0 < checkLength) {
     52        int badGrammarLocation = -1;
     53        int badGrammarLength = 0;
     54        Vector<GrammarDetail> badGrammarDetails;
     55        client->checkGrammarOfString(text + checkLocation, checkLength, badGrammarDetails, &badGrammarLocation, &badGrammarLength);
     56        if (!badGrammarLength)
     57            break;
     58        ASSERT(0 <= badGrammarLocation && badGrammarLocation <= checkLength);
     59        ASSERT(0 < badGrammarLength && badGrammarLocation + badGrammarLength <= checkLength);
     60        TextCheckingResult badGrammar;
     61        badGrammar.type = TextCheckingTypeGrammar;
     62        badGrammar.location = checkLocation + badGrammarLocation;
     63        badGrammar.length = badGrammarLength;
     64        badGrammar.details.swap(badGrammarDetails);
     65        results.append(badGrammar);
     66
     67        checkLocation += (badGrammarLocation + badGrammarLength);
     68        checkLength -= (badGrammarLocation + badGrammarLength);
     69    }
     70}
     71
     72static void findMisspellings(TextCheckerClient* client, const UChar* text, int start, int length, Vector<TextCheckingResult>& results)
     73{
     74    TextBreakIterator* iterator = wordBreakIterator(text + start, length);
     75    if (!iterator)
     76        return;
     77    int wordStart = textBreakCurrent(iterator);
     78    while (0 <= wordStart) {
     79        int wordEnd = textBreakNext(iterator);
     80        if (wordEnd < 0)
     81            break;
     82        int wordLength = wordEnd - wordStart;
     83        int misspellingLocation = -1;
     84        int misspellingLength = 0;
     85        client->checkSpellingOfString(text + start + wordStart, wordLength, &misspellingLocation, &misspellingLength);
     86        if (0 < misspellingLength) {
     87            ASSERT(0 <= misspellingLocation && misspellingLocation <= wordLength);
     88            ASSERT(0 < misspellingLength && misspellingLocation + misspellingLength <= wordLength);
     89            TextCheckingResult misspelling;
     90            misspelling.type = TextCheckingTypeSpelling;
     91            misspelling.location = start + wordStart + misspellingLocation;
     92            misspelling.length = misspellingLength;
     93            misspelling.replacement = client->getAutoCorrectSuggestionForMisspelledWord(String(text + misspelling.location, misspelling.length));
     94            results.append(misspelling);
     95        }
     96
     97        wordStart = wordEnd;
     98    }
     99}
     100#endif
    41101
    42102static PassRefPtr<Range> expandToParagraphBoundary(PassRefPtr<Range> range)
     
    600660    client->checkTextOfParagraph(text, length, checkingTypes, results);
    601661#else
    602     // Should implement later to unify unified spell-checking code path and
    603     // legacy spell-checking code path.
    604     ASSERT_NOT_REACHED();
    605     UNUSED_PARAM(client);
    606     UNUSED_PARAM(text);
    607     UNUSED_PARAM(length);
    608     UNUSED_PARAM(checkingTypes);
    609     UNUSED_PARAM(results);
     662    Vector<TextCheckingResult> spellingResult;
     663    if (checkingTypes & TextCheckingTypeSpelling)
     664        findMisspellings(client, text, 0, length, spellingResult);
     665
     666    Vector<TextCheckingResult> grammarResult;
     667    if (checkingTypes & TextCheckingTypeGrammar) {
     668        // Only checks grammartical error before the first misspellings
     669        int grammarCheckLength = length;
     670        for (size_t i = 0; i < spellingResult.size(); ++i) {
     671            if (spellingResult[i].location < grammarCheckLength)
     672                grammarCheckLength = spellingResult[i].location;
     673        }
     674
     675        findBadGrammars(client, text, 0, grammarCheckLength, grammarResult);
     676    }
     677
     678    if (grammarResult.size())
     679        results.swap(grammarResult);
     680
     681    if (spellingResult.size()) {
     682        if (results.isEmpty())
     683            results.swap(spellingResult);
     684        else
     685            results.append(spellingResult);
     686    }
    610687#endif
    611688}
  • trunk/Source/WebCore/testing/Internals.cpp

    r99814 r100050  
    568568}
    569569
    570 }
     570void Internals::setUnifiedTextCheckingEnabled(Document* document, bool enabled, ExceptionCode& ec)
     571{
     572    if (!document || !document->frame() || !document->frame()->settings()) {
     573        ec = INVALID_ACCESS_ERR;
     574        return;
     575    }
     576
     577    document->frame()->settings()->setUnifiedTextCheckerEnabled(enabled);
     578}
     579
     580bool Internals::unifiedTextCheckingEnabled(Document* document, ExceptionCode& ec)
     581{
     582    if (!document || !document->frame() || !document->frame()->settings()) {
     583        ec = INVALID_ACCESS_ERR;
     584        return false;
     585    }
     586
     587    return document->frame()->settings()->unifiedTextCheckerEnabled();
     588}
     589
     590}
  • trunk/Source/WebCore/testing/Internals.h

    r99814 r100050  
    104104    unsigned lengthFromRange(Element* scope, const Range*, ExceptionCode&);
    105105
     106    void setUnifiedTextCheckingEnabled(Document*, bool, ExceptionCode&);
     107    bool unifiedTextCheckingEnabled(Document*, ExceptionCode&);
     108
    106109    static const char* internalsId;
    107110
  • trunk/Source/WebCore/testing/Internals.idl

    r99814 r100050  
    7676        unsigned long locationFromRange(in Element scope, in Range range) raises (DOMException);
    7777        unsigned long lengthFromRange(in Element scope, in Range range) raises (DOMException);
     78
     79        void setUnifiedTextCheckingEnabled(in Document document, in boolean enabled) raises (DOMException);
     80        boolean unifiedTextCheckingEnabled(in Document document) raises (DOMException);
    7881    };
    7982}
  • trunk/Source/WebKit2/ChangeLog

    r100033 r100050  
     12011-11-11  Shinya Kawanaka  <shinyak@google.com>
     2
     3        Implement legacy text check emulation in unified text check interface.
     4        https://bugs.webkit.org/show_bug.cgi?id=70299
     5
     6        Reviewed by Hajime Morita.
     7
     8        * win/WebKit2.def:
     9        * win/WebKit2CFLite.def:
     10
    1112011-11-11  Alexey Proskuryakov  <ap@apple.com>
    212
  • trunk/Source/WebKit2/win/WebKit2.def

    r99814 r100050  
    177177        ?setSuggestedValue@HTMLInputElement@WebCore@@QAEXABVString@WTF@@@Z
    178178        ?settings@Document@WebCore@@QBEPAVSettings@2@XZ
     179        ?settings@Frame@WebCore@@QBEPAVSettings@2@XZ
    179180        ?shadowRoot@Element@WebCore@@QBEPAVShadowRoot@2@XZ
    180181        ?suggestedValue@HTMLInputElement@WebCore@@QBEABVString@WTF@@XZ
  • trunk/Source/WebKit2/win/WebKit2CFLite.def

    r99814 r100050  
    170170        ?setSuggestedValue@HTMLInputElement@WebCore@@QAEXABVString@WTF@@@Z
    171171        ?settings@Document@WebCore@@QBEPAVSettings@2@XZ
     172        ?settings@Frame@WebCore@@QBEPAVSettings@2@XZ
    172173        ?shadowRoot@Element@WebCore@@QBEPAVShadowRoot@2@XZ
    173174        ?suggestedValue@HTMLInputElement@WebCore@@QBEABVString@WTF@@XZ
  • trunk/Source/autotools/symbols.filter

    r99814 r100050  
    7272_ZNK7WebCore20CachedResourceLoader11isPreloadedERKN3WTF6StringE;
    7373_ZNK7WebCore26HTMLTextFormControlElement21lastChangeWasUserEditEv;
     74_ZNK7WebCore5Frame8settingsEv;
    7475_ZNK7WebCore6JSNode21pushEventHandlerScopeEPN3JSC9ExecStateEPNS1_14ScopeChainNodeE;
    7576_ZNK7WebCore7Element10shadowRootEv;
Note: See TracChangeset for help on using the changeset viewer.