Changeset 141519 in webkit


Ignore:
Timestamp:
Jan 31, 2013 6:05:18 PM (11 years ago)
Author:
commit-queue@webkit.org
Message:

Source/WebKit/chromium: [Chromium] Select multi-word misspelling on context click
https://bugs.webkit.org/show_bug.cgi?id=108509

Patch by Rouslan Solomakhin <rouslan@chromium.org> on 2013-01-31
Reviewed by Tony Chang.

  • src/ContextMenuClientImpl.cpp:

(WebKit):
(WebKit::selectMisspellingAsync): Added utility function to get the misspelling for asynchronous spellcheck.
(WebKit::ContextMenuClientImpl::getCustomMenuFromDefaultItems): Select multi-word misspelling on context click.

Tools: [Chromium] Suggest 'uppercase' for multi-word misspelling 'upper case'
https://bugs.webkit.org/show_bug.cgi?id=108509

Patch by Rouslan Solomakhin <rouslan@chromium.org> on 2013-01-31
Reviewed by Tony Chang.

  • DumpRenderTree/chromium/TestRunner/src/MockSpellCheck.cpp:

(append): Added utility function to append WebString to WebVector.
(MockSpellCheck::fillSuggestionList): Suggest 'uppercase' for misspelling 'upper case'.

LayoutTests: [Chromium] Expect spellcheck to select multi-word misspelling on context click
https://bugs.webkit.org/show_bug.cgi?id=108509

Patch by Rouslan Solomakhin <rouslan@chromium.org> on 2013-01-31
Reviewed by Tony Chang.

  • editing/spelling/spelling-exactly-selected-multiple-words.html: Check spelling suggestion for multi-word misspelling.
  • editing/spelling/spelling-should-select-multiple-words.html: Check spelling suggestion for multi-word misspelling.
  • editing/spelling/spelling-exactly-selected-multiple-words-expected.txt:
  • editing/spelling/spelling-should-select-multiple-words-expected.txt:
  • platform/chromium/TestExpectations: Expect spellcheck to select multi-word misspelling on context click
Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r141514 r141519  
     12013-01-31  Rouslan Solomakhin  <rouslan@chromium.org>
     2
     3        [Chromium] Expect spellcheck to select multi-word misspelling on context click
     4        https://bugs.webkit.org/show_bug.cgi?id=108509
     5
     6        Reviewed by Tony Chang.
     7
     8        * editing/spelling/spelling-exactly-selected-multiple-words.html: Check spelling suggestion for multi-word misspelling.
     9        * editing/spelling/spelling-should-select-multiple-words.html: Check spelling suggestion for multi-word misspelling.
     10        * editing/spelling/spelling-exactly-selected-multiple-words-expected.txt:
     11        * editing/spelling/spelling-should-select-multiple-words-expected.txt:
     12        * platform/chromium/TestExpectations: Expect spellcheck to select multi-word misspelling on context click
     13
    1142013-01-31  Christopher Cameron  <ccameron@chromium.org>
    215
  • trunk/LayoutTests/editing/spelling/spelling-exactly-selected-multiple-words-expected.txt

    r141354 r141519  
    99PASS spellingMarkerRange.toString() is "upper case"
    1010PASS window.getSelection().toString() is "upper case"
     11PASS contextMenuElements[contextMenuElements.length - 1] is "uppercase"
    1112PASS successfullyParsed is true
    1213
  • trunk/LayoutTests/editing/spelling/spelling-exactly-selected-multiple-words.html

    r141354 r141519  
    4040    shouldBeEqualToString("spellingMarkerRange.toString()", "upper case");
    4141    shouldBeEqualToString("window.getSelection().toString()", "upper case");
     42    shouldBeEqualToString("contextMenuElements[contextMenuElements.length - 1]", "uppercase");
    4243});
    4344
  • trunk/LayoutTests/editing/spelling/spelling-should-select-multiple-words-expected.txt

    r141354 r141519  
    88PASS spellingMarkerRange.toString() is "upper case"
    99PASS window.getSelection().toString() is "upper case"
     10PASS contextMenuElements[contextMenuElements.length - 1] is "uppercase"
    1011PASS successfullyParsed is true
    1112
  • trunk/LayoutTests/editing/spelling/spelling-should-select-multiple-words.html

    r141354 r141519  
    3131    shouldBeEqualToString("spellingMarkerRange.toString()", "upper case");
    3232    shouldBeEqualToString("window.getSelection().toString()", "upper case");
     33    shouldBeEqualToString("contextMenuElements[contextMenuElements.length - 1]", "uppercase");
    3334});
    3435
  • trunk/LayoutTests/platform/chromium/TestExpectations

    r141479 r141519  
    43584358webkit.org/b/108370 editing/spelling/spelling-double-clicked-word.html [ Failure ]
    43594359webkit.org/b/108370 editing/spelling/spelling-double-clicked-word-with-underscores.html [ Failure ]
    4360 webkit.org/b/108370 editing/spelling/spelling-should-select-multiple-words.html [ Failure ]
    43614360webkit.org/b/108370 editing/spelling/spelling-with-punctuation-selection.html [ Failure ]
    43624361webkit.org/b/108370 editing/spelling/spelling-with-underscore-selection.html [ Failure ]
  • trunk/Source/WebKit/chromium/ChangeLog

    r141496 r141519  
     12013-01-31  Rouslan Solomakhin  <rouslan@chromium.org>
     2
     3        [Chromium] Select multi-word misspelling on context click
     4        https://bugs.webkit.org/show_bug.cgi?id=108509
     5
     6        Reviewed by Tony Chang.
     7
     8        * src/ContextMenuClientImpl.cpp:
     9        (WebKit):
     10        (WebKit::selectMisspellingAsync): Added utility function to get the misspelling for asynchronous spellcheck.
     11        (WebKit::ContextMenuClientImpl::getCustomMenuFromDefaultItems): Select multi-word misspelling on context click.
     12
    1132013-01-31  Florin Malita  <fmalita@chromium.org>
    214
  • trunk/Source/WebKit/chromium/src/ContextMenuClientImpl.cpp

    r138216 r141519  
    4141#include "Editor.h"
    4242#include "EventHandler.h"
     43#include "ExceptionCodePlaceholder.h"
    4344#include "FrameLoader.h"
    4445#include "FrameView.h"
     
    103104
    104105// Helper function to get misspelled word on which context menu
    105 // is to be evolked. This function also sets the word on which context menu
    106 // has been evoked to be the selected word, as required. This function changes
     106// is to be invoked. This function also sets the word on which context menu
     107// has been invoked to be the selected word, as required. This function changes
    107108// the selection only when there were no selected characters on OS X.
    108109static String selectMisspelledWord(const ContextMenu* defaultMenu, Frame* selectedFrame)
     
    142143#endif
    143144    return misspelledWord;
     145}
     146
     147static String selectMisspellingAsync(Frame* selectedFrame, Vector<DocumentMarker*>& markers)
     148{
     149    VisibleSelection selection = selectedFrame->selection()->selection();
     150    if (!selection.isCaretOrRange())
     151        return String();
     152
     153    // Caret and range selections always return valid normalized ranges.
     154    RefPtr<Range> selectionRange = selection.toNormalizedRange();
     155    markers.append(selectedFrame->document()->markers()->markersInRange(selectionRange.get(), DocumentMarker::Spelling | DocumentMarker::Grammar));
     156    if (markers.size() != 1)
     157        return String();
     158
     159    // Cloning a range fails only for invalid ranges.
     160    RefPtr<Range> markerRange = selectionRange->cloneRange(ASSERT_NO_EXCEPTION);
     161    markerRange->setStart(markerRange->startContainer(), markers[0]->startOffset());
     162    markerRange->setEnd(markerRange->endContainer(), markers[0]->endOffset());
     163    if (selection.isCaret()) {
     164        selection = VisibleSelection(markerRange.get());
     165        selectedFrame->selection()->setSelection(selection, WordGranularity);
     166        selectionRange = selection.toNormalizedRange();
     167    }
     168
     169    if (!WebCore::areRangesEqual(markerRange.get(), selectionRange.get()))
     170        return String();
     171
     172    return markerRange->text();
    144173}
    145174
     
    275304        // When Chrome enables asynchronous spellchecking, its spellchecker adds spelling markers to misspelled
    276305        // words and attaches suggestions to these markers in the background. Therefore, when a user right-clicks
    277         // a mouse on a word, Chrome just needs to find a spelling marker on the word instread of spellchecking it.
     306        // a mouse on a word, Chrome just needs to find a spelling marker on the word instead of spellchecking it.
    278307        if (selectedFrame->settings() && selectedFrame->settings()->asynchronousSpellCheckingEnabled()) {
    279             VisibleSelection selection = selectedFrame->selection()->selection();
    280             bool shouldUpdateSelection = false;
    281             if (selection.isCaretOrRange()) {
    282                 if (selection.isCaret()) {
    283                     selection.expandUsingGranularity(WordGranularity);
    284                     shouldUpdateSelection = true;
    285                 }
    286                 RefPtr<Range> range = selection.toNormalizedRange();
    287                 Vector<DocumentMarker*> markers = selectedFrame->document()->markers()->markersInRange(range.get(), DocumentMarker::Spelling | DocumentMarker::Grammar);
    288                 if (markers.size() == 1) {
    289                     if (markers[0]->startOffset() != static_cast<unsigned>(range->startOffset()) || markers[0]->endOffset() != static_cast<unsigned>(range->endOffset()))
    290                         markers.clear();
    291                 }
    292                 if (markers.size() == 1) {
    293                     range->setStart(range->startContainer(), markers[0]->startOffset());
    294                     range->setEnd(range->endContainer(), markers[0]->endOffset());
    295                     data.misspelledWord = range->text();
    296                     if (markers[0]->description().length()) {
    297                         Vector<String> suggestions;
    298                         markers[0]->description().split('\n', suggestions);
    299                         data.dictionarySuggestions = suggestions;
    300                     } else if (m_webView->spellCheckClient()) {
    301                         int misspelledOffset, misspelledLength;
    302                         m_webView->spellCheckClient()->spellCheck(data.misspelledWord, misspelledOffset, misspelledLength, &data.dictionarySuggestions);
    303                     }
    304                     selection = VisibleSelection(range.get());
    305                     if (shouldUpdateSelection && selectedFrame->selection()->shouldChangeSelection(selection))
    306                         selectedFrame->selection()->setSelection(selection, WordGranularity);
    307                 }
     308            Vector<DocumentMarker*> markers;
     309            data.misspelledWord = selectMisspellingAsync(selectedFrame, markers);
     310            if (markers.size() == 1 && markers[0]->description().length()) {
     311                Vector<String> suggestions;
     312                markers[0]->description().split('\n', suggestions);
     313                data.dictionarySuggestions = suggestions;
     314            } else if (m_webView->spellCheckClient()) {
     315                int misspelledOffset, misspelledLength;
     316                m_webView->spellCheckClient()->spellCheck(data.misspelledWord, misspelledOffset, misspelledLength, &data.dictionarySuggestions);
    308317            }
    309318        } else {
  • trunk/Tools/ChangeLog

    r141515 r141519  
     12013-01-31  Rouslan Solomakhin  <rouslan@chromium.org>
     2
     3        [Chromium] Suggest 'uppercase' for multi-word misspelling 'upper case'
     4        https://bugs.webkit.org/show_bug.cgi?id=108509
     5
     6        Reviewed by Tony Chang.
     7
     8        * DumpRenderTree/chromium/TestRunner/src/MockSpellCheck.cpp:
     9        (append): Added utility function to append WebString to WebVector.
     10        (MockSpellCheck::fillSuggestionList): Suggest 'uppercase' for misspelling 'upper case'.
     11
    1122013-01-31  David Farler  <dfarler@apple.com>
    213
  • trunk/Tools/DumpRenderTree/chromium/TestRunner/src/MockSpellCheck.cpp

    r141478 r141519  
    3737
    3838using namespace WebKit;
     39
     40static void append(WebVector<WebString>* data, const WebString& item)
     41{
     42    WebVector<WebString> result(data->size() + 1);
     43    for (size_t i = 0; i < data->size(); ++i)
     44        result[i] = (*data)[i];
     45    result[data->size()] = item;
     46    data->swap(result);
     47}
    3948
    4049MockSpellCheck::MockSpellCheck()
     
    108117void MockSpellCheck::fillSuggestionList(const WebString& word, WebVector<WebString>* suggestions)
    109118{
    110     if (word == WebString::fromUTF8("wellcome")) {
    111         WebVector<WebString> result(suggestions->size() + 1);
    112         for (size_t i = 0; i < suggestions->size(); ++i)
    113             result[i] = (*suggestions)[i];
    114         result[suggestions->size()] = WebString::fromUTF8("welcome");
    115         suggestions->swap(result);
    116     }
     119    if (word == WebString::fromUTF8("wellcome"))
     120        append(suggestions, WebString::fromUTF8("welcome"));
     121    else if (word == WebString::fromUTF8("upper case"))
     122        append(suggestions, WebString::fromUTF8("uppercase"));
    117123}
    118124
Note: See TracChangeset for help on using the changeset viewer.