Changeset 120423 in webkit


Ignore:
Timestamp:
Jun 15, 2012 1:41:30 AM (12 years ago)
Author:
hbono@chromium.org
Message:

Allow platforms to choose whether to remove markers on editing
https://bugs.webkit.org/show_bug.cgi?id=88838

Reviewed by Hajime Morita.

Source/WebCore:

This change allows platforms to choose whether to remove markers on a word being
edited. WebKit does not remove markers when we move a selection to a markered
word on platforms that shouldEraseMarkersAfterChangeSelection returns false.
On such platforms, WebKit expects to set WTF_USE_MARKER_REMOVAL_UPON_EDITING to
1 so Editor::updateMarkersForWordsAffectedByEditing can remove markers. This
change also checks the return value of shouldEraseMarkersAfterChangeSelection so
platform can choose it. This change also adds grammar markers so it can also
remove grammar markers.

Test: editing/spelling/grammar-edit-word.html

  • editing/Editor.cpp:

(WebCore::Editor::updateMarkersForWordsAffectedByEditing):

Source/WebKit/chromium:

This change implements EditorClientImpl::checkGrammarOfString so
DumpRenderTree can run grammar tests.

  • src/EditorClientImpl.cpp:

(WebKit::EditorClientImpl::isGrammarCheckingEnabled): Return true also when unified text-checking is enabled.
(WebKit::EditorClientImpl::shouldEraseMarkersAfterChangeSelection): ditto.
(WebKit::EditorClientImpl::checkGrammarOfString): Implement this function with our unified text-checker.

Tools:

This change implements WebViewHost::checkTextOfParagraph so DumpRenderTree can
run grammar tests.

  • DumpRenderTree/chromium/WebViewHost.cpp:

(WebViewHost::checkTextOfParagraph): Implement this function with our mock spell checker and grammar checker.

  • DumpRenderTree/chromium/WebViewHost.h:

(WebViewHost): Override WebSpellCheckClient::checkTextOfParagraph.

LayoutTests:

This change adds a test that verifies WebKit removes a grammar marker from a
grammatically-incorrect word when editing the word.

  • editing/spelling/grammar-edit-word-expected.txt: Added.
  • editing/spelling/grammar-edit-word.html: Added.
Location:
trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r120422 r120423  
     12012-06-15  Hironori Bono  <hbono@chromium.org>
     2
     3        Allow platforms to choose whether to remove markers on editing
     4        https://bugs.webkit.org/show_bug.cgi?id=88838
     5
     6        Reviewed by Hajime Morita.
     7
     8        This change adds a test that verifies WebKit removes a grammar marker from a
     9        grammatically-incorrect word when editing the word.
     10
     11        * editing/spelling/grammar-edit-word-expected.txt: Added.
     12        * editing/spelling/grammar-edit-word.html: Added.
     13
    1142012-06-15  Zan Dobersek  <zandobersek@gmail.com>
    215
  • trunk/Source/WebCore/ChangeLog

    r120421 r120423  
     12012-06-15  Hironori Bono  <hbono@chromium.org>
     2
     3        Allow platforms to choose whether to remove markers on editing
     4        https://bugs.webkit.org/show_bug.cgi?id=88838
     5
     6        Reviewed by Hajime Morita.
     7
     8        This change allows platforms to choose whether to remove markers on a word being
     9        edited. WebKit does not remove markers when we move a selection to a markered
     10        word on platforms that shouldEraseMarkersAfterChangeSelection returns false.
     11        On such platforms, WebKit expects to set WTF_USE_MARKER_REMOVAL_UPON_EDITING to
     12        1 so Editor::updateMarkersForWordsAffectedByEditing can remove markers. This
     13        change also checks the return value of shouldEraseMarkersAfterChangeSelection so
     14        platform can choose it. This change also adds grammar markers so it can also
     15        remove grammar markers.
     16
     17        Test: editing/spelling/grammar-edit-word.html
     18
     19        * editing/Editor.cpp:
     20        (WebCore::Editor::updateMarkersForWordsAffectedByEditing):
     21
    1222012-06-15  Andrey Adaikin  <aandrey@chromium.org>
    223
  • trunk/Source/WebCore/editing/Editor.cpp

    r120357 r120423  
    22042204void Editor::updateMarkersForWordsAffectedByEditing(bool doNotRemoveIfSelectionAtWordBoundary)
    22052205{
    2206     if (!m_alternativeTextController->shouldRemoveMarkersUponEditing())
     2206    if (!m_alternativeTextController->shouldRemoveMarkersUponEditing() && (!textChecker() || textChecker()->shouldEraseMarkersAfterChangeSelection(TextCheckingTypeSpelling)))
    22072207        return;
    22082208
     
    22722272        m_alternativeTextController->removeDictationAlternativesForMarker(markers[i]);
    22732273
    2274     document->markers()->removeMarkers(wordRange.get(), DocumentMarker::Spelling | DocumentMarker::CorrectionIndicator | DocumentMarker::SpellCheckingExemption | DocumentMarker::DictationAlternatives, DocumentMarkerController::RemovePartiallyOverlappingMarker);
     2274    document->markers()->removeMarkers(wordRange.get(), DocumentMarker::Spelling | DocumentMarker::Grammar | DocumentMarker::CorrectionIndicator | DocumentMarker::SpellCheckingExemption | DocumentMarker::DictationAlternatives, DocumentMarkerController::RemovePartiallyOverlappingMarker);
    22752275    document->markers()->clearDescriptionOnMarkersIntersectingRange(wordRange.get(), DocumentMarker::Replacement);
    22762276}
  • trunk/Source/WebKit/chromium/ChangeLog

    r120410 r120423  
     12012-06-15  Hironori Bono  <hbono@chromium.org>
     2
     3        Allow platforms to choose whether to remove markers on editing
     4        https://bugs.webkit.org/show_bug.cgi?id=88838
     5
     6        Reviewed by Hajime Morita.
     7
     8        This change implements EditorClientImpl::checkGrammarOfString so
     9        DumpRenderTree can run grammar tests.
     10
     11        * src/EditorClientImpl.cpp:
     12        (WebKit::EditorClientImpl::isGrammarCheckingEnabled): Return true also when unified text-checking is enabled.
     13        (WebKit::EditorClientImpl::shouldEraseMarkersAfterChangeSelection): ditto.
     14        (WebKit::EditorClientImpl::checkGrammarOfString): Implement this function with our unified text-checker.
     15
    1162012-06-14  Kent Tamura  <tkent@chromium.org>
    217
  • trunk/Source/WebKit/chromium/src/EditorClientImpl.cpp

    r119192 r120423  
    171171{
    172172    const Frame* frame = m_webView->focusedWebCoreFrame();
    173     return frame && frame->settings() && frame->settings()->asynchronousSpellCheckingEnabled();
     173    return frame && frame->settings() && (frame->settings()->asynchronousSpellCheckingEnabled() || frame->settings()->unifiedTextCheckerEnabled());
    174174}
    175175
     
    704704{
    705705    const Frame* frame = m_webView->focusedWebCoreFrame();
    706     return !frame || !frame->settings() || !frame->settings()->asynchronousSpellCheckingEnabled();
     706    return !frame || !frame->settings() || (!frame->settings()->asynchronousSpellCheckingEnabled() && !frame->settings()->unifiedTextCheckerEnabled());
    707707}
    708708
     
    767767}
    768768
    769 void EditorClientImpl::checkGrammarOfString(const UChar*, int length,
    770                                             WTF::Vector<GrammarDetail>&,
    771                                             int* badGrammarLocation,
    772                                             int* badGrammarLength)
    773 {
    774     notImplemented();
     769void EditorClientImpl::checkGrammarOfString(const UChar* text, int length, WTF::Vector<GrammarDetail>& details, int* badGrammarLocation, int* badGrammarLength)
     770{
    775771    if (badGrammarLocation)
    776772        *badGrammarLocation = -1;
    777773    if (badGrammarLength)
    778774        *badGrammarLength = 0;
     775
     776    if (!m_webView->spellCheckClient())
     777        return;
     778    WebVector<WebTextCheckingResult> webResults;
     779    m_webView->spellCheckClient()->checkTextOfParagraph(WebString(text, length), WebTextCheckingTypeGrammar, &webResults);
     780    if (!webResults.size())
     781        return;
     782
     783    // Convert a list of WebTextCheckingResults to a list of GrammarDetails. If
     784    // the converted vector of GrammarDetails has grammar errors, we set
     785    // badGrammarLocation and badGrammarLength to tell WebKit that the input
     786    // text has grammar errors.
     787    for (size_t i = 0; i < webResults.size(); ++i) {
     788        if (webResults[i].type == WebTextCheckingTypeGrammar) {
     789            GrammarDetail detail;
     790            detail.location = webResults[i].location;
     791            detail.length = webResults[i].length;
     792            detail.userDescription = webResults[i].replacement;
     793            details.append(detail);
     794        }
     795    }
     796    if (!details.size())
     797        return;
     798    if (badGrammarLocation)
     799        *badGrammarLocation = 0;
     800    if (badGrammarLength)
     801        *badGrammarLength = length;
    779802}
    780803
  • trunk/Tools/ChangeLog

    r120419 r120423  
     12012-06-15  Hironori Bono  <hbono@chromium.org>
     2
     3        Allow platforms to choose whether to remove markers on editing
     4        https://bugs.webkit.org/show_bug.cgi?id=88838
     5
     6        Reviewed by Hajime Morita.
     7
     8        This change implements WebViewHost::checkTextOfParagraph so DumpRenderTree can
     9        run grammar tests.
     10
     11        * DumpRenderTree/chromium/WebViewHost.cpp:
     12        (WebViewHost::checkTextOfParagraph): Implement this function with our mock spell checker and grammar checker.
     13        * DumpRenderTree/chromium/WebViewHost.h:
     14        (WebViewHost): Override WebSpellCheckClient::checkTextOfParagraph.
     15
    1162012-06-15  Sheriff Bot  <webkit.review.bot@gmail.com>
    217
  • trunk/Tools/DumpRenderTree/chromium/WebViewHost.cpp

    r120031 r120423  
    466466    // Check the spelling of the given text.
    467467    m_spellcheck.spellCheckWord(text, &misspelledOffset, &misspelledLength);
     468}
     469
     470void WebViewHost::checkTextOfParagraph(const WebString& text, WebTextCheckingTypeMask mask, WebVector<WebTextCheckingResult>* webResults)
     471{
     472    Vector<WebTextCheckingResult> results;
     473    if (mask & WebTextCheckingTypeSpelling) {
     474        size_t offset = 0;
     475        size_t length = text.length();
     476        const WebUChar* data = text.data();
     477        while (offset < length) {
     478            int misspelledPosition = 0;
     479            int misspelledLength = 0;
     480            m_spellcheck.spellCheckWord(WebString(&data[offset], length - offset), &misspelledPosition, &misspelledLength);
     481            if (!misspelledLength)
     482                break;
     483            WebTextCheckingResult result;
     484            result.type = WebTextCheckingTypeSpelling;
     485            result.location = offset + misspelledPosition;
     486            result.length = misspelledLength;
     487            results.append(result);
     488            offset += misspelledPosition + misspelledLength;
     489        }
     490    }
     491    if (mask & WebTextCheckingTypeGrammar)
     492        MockGrammarCheck::checkGrammarOfString(text, &results);
     493    webResults->assign(results);
    468494}
    469495
  • trunk/Tools/DumpRenderTree/chromium/WebViewHost.h

    r119818 r120423  
    137137    // WebKit::WebSpellCheckClient
    138138    virtual void spellCheck(const WebKit::WebString&, int& offset, int& length, WebKit::WebVector<WebKit::WebString>* optionalSuggestions);
     139    virtual void checkTextOfParagraph(const WebKit::WebString&, WebKit::WebTextCheckingTypeMask, WebKit::WebVector<WebKit::WebTextCheckingResult>*);
    139140    virtual void requestCheckingOfText(const WebKit::WebString&, WebKit::WebTextCheckingCompletion*);
    140141    virtual WebKit::WebString autoCorrectWord(const WebKit::WebString&);
Note: See TracChangeset for help on using the changeset viewer.