Title: [120810] trunk/Source/WebKit/chromium
Revision
120810
Author
[email protected]
Date
2012-06-20 00:00:34 -0700 (Wed, 20 Jun 2012)

Log Message

[chromium] Select the marker range when right-clicking on a marker.
https://bugs.webkit.org/show_bug.cgi?id=89331

Reviewed by Hajime Morita.

Chromium always selects only one word when right-clicking on a spelling marker.
This prevents selecting whole region specified by a marker if the marker
consists of two or more words. This change retrieves a range coverted by a
marker and select the range. This emulates the behavior of Mac Chromium and it
does not need any workarounds for Mac.

* src/ContextMenuClientImpl.cpp:
(WebKit::ContextMenuClientImpl::getCustomMenuFromDefaultItems):

Modified Paths

Diff

Modified: trunk/Source/WebKit/chromium/ChangeLog (120809 => 120810)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-06-20 06:51:34 UTC (rev 120809)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-06-20 07:00:34 UTC (rev 120810)
@@ -1,3 +1,19 @@
+2012-06-20  Hironori Bono  <[email protected]>
+
+        [chromium] Select the marker range when right-clicking on a marker.
+        https://bugs.webkit.org/show_bug.cgi?id=89331
+
+        Reviewed by Hajime Morita.
+
+        Chromium always selects only one word when right-clicking on a spelling marker.
+        This prevents selecting whole region specified by a marker if the marker
+        consists of two or more words. This change retrieves a range coverted by a
+        marker and select the range. This emulates the behavior of Mac Chromium and it
+        does not need any workarounds for Mac.
+
+        * src/ContextMenuClientImpl.cpp:
+        (WebKit::ContextMenuClientImpl::getCustomMenuFromDefaultItems):
+
 2012-06-19  Kenneth Russell  <[email protected]>
 
         Unreviewed, rolling out r120772.

Modified: trunk/Source/WebKit/chromium/src/ContextMenuClientImpl.cpp (120809 => 120810)


--- trunk/Source/WebKit/chromium/src/ContextMenuClientImpl.cpp	2012-06-20 06:51:34 UTC (rev 120809)
+++ trunk/Source/WebKit/chromium/src/ContextMenuClientImpl.cpp	2012-06-20 07:00:34 UTC (rev 120810)
@@ -278,25 +278,27 @@
         // words and attaches suggestions to these markers in the background. Therefore, when a user right-clicks
         // a mouse on a word, Chrome just needs to find a spelling marker on the word instread of spellchecking it.
         if (selectedFrame->settings() && selectedFrame->settings()->asynchronousSpellCheckingEnabled()) {
-            RefPtr<Range> range = selectedFrame->selection()->toNormalizedRange();
-            if (range.get()) {
+            VisibleSelection selection = selectedFrame->selection()->selection();
+            if (selection.isCaretOrRange()) {
+                if (selection.isCaret())
+                    selection.expandUsingGranularity(WordGranularity);
+                RefPtr<Range> range = selection.toNormalizedRange();
                 Vector<DocumentMarker*> markers = selectedFrame->document()->markers()->markersInRange(range.get(), DocumentMarker::Spelling | DocumentMarker::Grammar);
-                if (!markers.isEmpty()) {
-                    Vector<String> suggestions;
-                    for (size_t i = 0; i < markers.size(); ++i) {
-                        if (!markers[i]->description().isEmpty()) {
-                            Vector<String> descriptions;
-                            markers[i]->description().split('\n', descriptions);
-                            suggestions.append(descriptions);
-                        }
-                    }
-                    data.misspelledWord = selectMisspelledWord(defaultMenu, selectedFrame);
-                    if (!suggestions.isEmpty())
+                if (markers.size() == 1) {
+                    range->setStart(range->startContainer(), markers[0]->startOffset());
+                    range->setEnd(range->endContainer(), markers[0]->endOffset());
+                    data.misspelledWord = range->text();
+                    if (markers[0]->description().length()) {
+                        Vector<String> suggestions;
+                        markers[0]->description().split('\n', suggestions);
                         data.dictionarySuggestions = suggestions;
-                    else if (m_webView->spellCheckClient()) {
+                    } else if (m_webView->spellCheckClient()) {
                         int misspelledOffset, misspelledLength;
                         m_webView->spellCheckClient()->spellCheck(data.misspelledWord, misspelledOffset, misspelledLength, &data.dictionarySuggestions);
                     }
+                    selection = VisibleSelection(range.get());
+                    if (selectedFrame->selection()->shouldChangeSelection(selection))
+                        selectedFrame->selection()->setSelection(selection, WordGranularity);
                 }
             }
         } else if (m_webView->focusedWebCoreFrame()->editor()->isContinuousSpellCheckingEnabled()) {
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to