Changeset 142494 in webkit


Ignore:
Timestamp:
Feb 11, 2013 12:23:48 PM (11 years ago)
Author:
commit-queue@webkit.org
Message:

[Chromium] Replace correct misspelled range in WebKit::WebFrameImpl::replaceMisspelledRange
https://bugs.webkit.org/show_bug.cgi?id=108513

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

WebKit::WebFrameImpl::replaceMisspelledRange is going to be used by Chromium instead of
WebKit::WebFrameImpl::replaceSelection for correcting misspellings. The current implementation
of WebKit::WebFrameImpl::replaceMisspelledRange sometimes replaces the wrong range. This change
uses Range::create instead of TextIterator::rangeFromLocationAndLength to select the correct
range. This change also disables smart replace in WebKit::WebFrameImpl::replaceMisspelledRange
to avoid introducing spaces around misspellings.

  • src/WebFrameImpl.cpp:

(WebKit::WebFrameImpl::replaceMisspelledRange): Replace correct misspelled range.

  • tests/WebFrameTest.cpp: Add unit test for WebKit::WebFrameImpl::replaceMisspelledRange method.
Location:
trunk/Source/WebKit/chromium
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/chromium/ChangeLog

    r142460 r142494  
     12013-02-11  Rouslan Solomakhin  <rouslan@chromium.org>
     2
     3        [Chromium] Replace correct misspelled range in WebKit::WebFrameImpl::replaceMisspelledRange
     4        https://bugs.webkit.org/show_bug.cgi?id=108513
     5
     6        Reviewed by Tony Chang.
     7
     8        WebKit::WebFrameImpl::replaceMisspelledRange is going to be used by Chromium instead of
     9        WebKit::WebFrameImpl::replaceSelection for correcting misspellings. The current implementation
     10        of WebKit::WebFrameImpl::replaceMisspelledRange sometimes replaces the wrong range. This change
     11        uses Range::create instead of TextIterator::rangeFromLocationAndLength to select the correct
     12        range. This change also disables smart replace in WebKit::WebFrameImpl::replaceMisspelledRange
     13        to avoid introducing spaces around misspellings.
     14
     15        * src/WebFrameImpl.cpp:
     16        (WebKit::WebFrameImpl::replaceMisspelledRange): Replace correct misspelled range.
     17        * tests/WebFrameTest.cpp: Add unit test for WebKit::WebFrameImpl::replaceMisspelledRange method.
     18
    1192013-02-11  Alexei Filippov  <alph@chromium.org>
    220
  • trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp

    r142093 r142494  
    13111311    if (markers.size() < 1 || markers[0]->startOffset() >= markers[0]->endOffset())
    13121312        return;
    1313     RefPtr<Range> markerRange = TextIterator::rangeFromLocationAndLength(frame()->selection()->rootEditableElementOrDocumentElement(), markers[0]->startOffset(), markers[0]->endOffset() - markers[0]->startOffset());
    1314     if (!markerRange.get() || !frame()->selection()->shouldChangeSelection(markerRange.get()))
     1313    RefPtr<Range> markerRange = Range::create(caretRange->ownerDocument(), caretRange->startContainer(), markers[0]->startOffset(), caretRange->endContainer(), markers[0]->endOffset());
     1314    if (!markerRange)
     1315        return;
     1316    if (!frame()->selection()->shouldChangeSelection(markerRange.get()))
    13151317        return;
    13161318    frame()->selection()->setSelection(markerRange.get(), CharacterGranularity);
    1317     frame()->editor()->replaceSelectionWithText(text, false, true);
     1319    frame()->editor()->replaceSelectionWithText(text, false, false);
    13181320}
    13191321
  • trunk/Source/WebKit/chromium/tests/WebFrameTest.cpp

    r142422 r142494  
    3333#include "WebFrame.h"
    3434
     35#include "DocumentMarkerController.h"
    3536#include "FloatRect.h"
    3637#include "Frame.h"
     
    5859#include "WebSecurityPolicy.h"
    5960#include "WebSettings.h"
     61#include "WebSpellCheckClient.h"
     62#include "WebTextCheckingCompletion.h"
     63#include "WebTextCheckingResult.h"
    6064#include "WebViewClient.h"
    6165#include "WebViewImpl.h"
     
    7074
    7175using namespace WebKit;
     76using WebCore::Document;
     77using WebCore::DocumentMarker;
     78using WebCore::Element;
    7279using WebCore::FloatRect;
    7380using WebCore::Range;
     
    22342241}
    22352242
     2243class SpellCheckClient : public WebSpellCheckClient {
     2244public:
     2245    SpellCheckClient() : m_numberOfTimesChecked(0) { }
     2246    virtual ~SpellCheckClient() { }
     2247    virtual void requestCheckingOfText(const WebKit::WebString&, WebKit::WebTextCheckingCompletion* completion) OVERRIDE
     2248    {
     2249        ++m_numberOfTimesChecked;
     2250        Vector<WebTextCheckingResult> results;
     2251        const int misspellingStartOffset = 1;
     2252        const int misspellingLength = 8;
     2253        results.append(WebTextCheckingResult(WebTextCheckingTypeSpelling, misspellingStartOffset, misspellingLength, WebString()));
     2254        completion->didFinishCheckingText(results);
     2255    }
     2256    int numberOfTimesChecked() const { return m_numberOfTimesChecked; }
     2257private:
     2258    int m_numberOfTimesChecked;
     2259};
     2260
     2261TEST_F(WebFrameTest, ReplaceMisspelledRange)
     2262{
     2263    m_webView = FrameTestHelpers::createWebViewAndLoad("data:text/html,<div id=\"data\" contentEditable></div>");
     2264    SpellCheckClient spellcheck;
     2265    m_webView->setSpellCheckClient(&spellcheck);
     2266
     2267    WebFrameImpl* frame = static_cast<WebFrameImpl*>(m_webView->mainFrame());
     2268    Document* document = frame->frame()->document();
     2269    Element* element = document->getElementById("data");
     2270
     2271    frame->frame()->settings()->setAsynchronousSpellCheckingEnabled(true);
     2272    frame->frame()->settings()->setUnifiedTextCheckerEnabled(true);
     2273    frame->frame()->settings()->setEditingBehaviorType(WebCore::EditingWindowsBehavior);
     2274
     2275    element->focus();
     2276    document->execCommand("InsertText", false, "_wellcome_.");
     2277
     2278    const int allTextBeginOffset = 0;
     2279    const int allTextLength = 11;
     2280    frame->selectRange(WebRange::fromDocumentRange(frame, allTextBeginOffset, allTextLength));
     2281    RefPtr<Range> selectionRange = frame->frame()->selection()->toNormalizedRange();
     2282
     2283    EXPECT_EQ(1, spellcheck.numberOfTimesChecked());
     2284    EXPECT_EQ(1U, document->markers()->markersInRange(selectionRange.get(), DocumentMarker::Spelling).size());
     2285
     2286    frame->replaceMisspelledRange("welcome");
     2287    EXPECT_EQ("_welcome_.", std::string(frame->contentAsText(std::numeric_limits<size_t>::max()).utf8().data()));
     2288
     2289    m_webView->close();
     2290    m_webView = 0;
     2291}
     2292
    22362293} // namespace
Note: See TracChangeset for help on using the changeset viewer.