+2013-02-11 Rouslan Solomakhin <rouslan@chromium.org>
+
+ [Chromium] Replace correct misspelled range in WebKit::WebFrameImpl::replaceMisspelledRange
+ https://bugs.webkit.org/show_bug.cgi?id=108513
+
+ 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.
+
2013-02-11 Alexei Filippov <alph@chromium.org>
Web Inspector: Split Profiler domain in protocol into Profiler and HeapProfiler
Vector<DocumentMarker*> markers = frame()->document()->markers()->markersInRange(caretRange.get(), DocumentMarker::Spelling | DocumentMarker::Grammar);
if (markers.size() < 1 || markers[0]->startOffset() >= markers[0]->endOffset())
return;
- RefPtr<Range> markerRange = TextIterator::rangeFromLocationAndLength(frame()->selection()->rootEditableElementOrDocumentElement(), markers[0]->startOffset(), markers[0]->endOffset() - markers[0]->startOffset());
- if (!markerRange.get() || !frame()->selection()->shouldChangeSelection(markerRange.get()))
+ RefPtr<Range> markerRange = Range::create(caretRange->ownerDocument(), caretRange->startContainer(), markers[0]->startOffset(), caretRange->endContainer(), markers[0]->endOffset());
+ if (!markerRange)
+ return;
+ if (!frame()->selection()->shouldChangeSelection(markerRange.get()))
return;
frame()->selection()->setSelection(markerRange.get(), CharacterGranularity);
- frame()->editor()->replaceSelectionWithText(text, false, true);
+ frame()->editor()->replaceSelectionWithText(text, false, false);
}
bool WebFrameImpl::hasSelection() const
#include "WebFrame.h"
+#include "DocumentMarkerController.h"
#include "FloatRect.h"
#include "Frame.h"
#include "FrameTestHelpers.h"
#include "WebSecurityOrigin.h"
#include "WebSecurityPolicy.h"
#include "WebSettings.h"
+#include "WebSpellCheckClient.h"
+#include "WebTextCheckingCompletion.h"
+#include "WebTextCheckingResult.h"
#include "WebViewClient.h"
#include "WebViewImpl.h"
#include "v8.h"
#include <wtf/Forward.h>
using namespace WebKit;
+using WebCore::Document;
+using WebCore::DocumentMarker;
+using WebCore::Element;
using WebCore::FloatRect;
using WebCore::Range;
using WebKit::URLTestHelpers::toKURL;
frame->moveCaretSelectionTowardsWindowPoint(WebPoint(0, 0));
}
+class SpellCheckClient : public WebSpellCheckClient {
+public:
+ SpellCheckClient() : m_numberOfTimesChecked(0) { }
+ virtual ~SpellCheckClient() { }
+ virtual void requestCheckingOfText(const WebKit::WebString&, WebKit::WebTextCheckingCompletion* completion) OVERRIDE
+ {
+ ++m_numberOfTimesChecked;
+ Vector<WebTextCheckingResult> results;
+ const int misspellingStartOffset = 1;
+ const int misspellingLength = 8;
+ results.append(WebTextCheckingResult(WebTextCheckingTypeSpelling, misspellingStartOffset, misspellingLength, WebString()));
+ completion->didFinishCheckingText(results);
+ }
+ int numberOfTimesChecked() const { return m_numberOfTimesChecked; }
+private:
+ int m_numberOfTimesChecked;
+};
+
+TEST_F(WebFrameTest, ReplaceMisspelledRange)
+{
+ m_webView = FrameTestHelpers::createWebViewAndLoad("data:text/html,<div id=\"data\" contentEditable></div>");
+ SpellCheckClient spellcheck;
+ m_webView->setSpellCheckClient(&spellcheck);
+
+ WebFrameImpl* frame = static_cast<WebFrameImpl*>(m_webView->mainFrame());
+ Document* document = frame->frame()->document();
+ Element* element = document->getElementById("data");
+
+ frame->frame()->settings()->setAsynchronousSpellCheckingEnabled(true);
+ frame->frame()->settings()->setUnifiedTextCheckerEnabled(true);
+ frame->frame()->settings()->setEditingBehaviorType(WebCore::EditingWindowsBehavior);
+
+ element->focus();
+ document->execCommand("InsertText", false, "_wellcome_.");
+
+ const int allTextBeginOffset = 0;
+ const int allTextLength = 11;
+ frame->selectRange(WebRange::fromDocumentRange(frame, allTextBeginOffset, allTextLength));
+ RefPtr<Range> selectionRange = frame->frame()->selection()->toNormalizedRange();
+
+ EXPECT_EQ(1, spellcheck.numberOfTimesChecked());
+ EXPECT_EQ(1U, document->markers()->markersInRange(selectionRange.get(), DocumentMarker::Spelling).size());
+
+ frame->replaceMisspelledRange("welcome");
+ EXPECT_EQ("_welcome_.", std::string(frame->contentAsText(std::numeric_limits<size_t>::max()).utf8().data()));
+
+ m_webView->close();
+ m_webView = 0;
+}
+
} // namespace