Changeset 54212 in webkit


Ignore:
Timestamp:
Feb 2, 2010 12:25:30 AM (14 years ago)
Author:
tkent@chromium.org
Message:

2010-02-02 Kent Tamura <tkent@chromium.org>

Reviewed by Darin Fisher.

[Chromium] Should not select a word on right-click.
https://bugs.webkit.org/show_bug.cgi?id=33364

For non-Mac platforms, do not select a word around the caret when
a context menu is opening. This behavior is not common in non-Mac
platforms, and it prevents pasting with a context menu.

In order that the spell checker works without the selection, we
introduce WebFrame::selectWordAroundCaret(). We can replace a word
around the caret with selectWordAroundCaret() + replaceSelection().

  • public/WebFrame.h: Add pure selectWordAroundCaret() declaration.
  • src/ContextMenuClientImpl.cpp: (WebKit::selectMisspelledWord): Move word-selection code to WebFrameImpl::selectWordAroundPosition(), and clear the selection on non-Mac.
  • src/WebFrameImpl.cpp: (WebKit::WebFrameImpl::selectWordAroundPosition): (WebKit::WebFrameImpl::selectWordAroundCaret):
  • src/WebFrameImpl.h: Add selectWordAroundCaret() declaration.
Location:
trunk/WebKit/chromium
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit/chromium/ChangeLog

    r54195 r54212  
     12010-02-02  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Darin Fisher.
     4
     5        [Chromium] Should not select a word on right-click.
     6        https://bugs.webkit.org/show_bug.cgi?id=33364
     7
     8        For non-Mac platforms, do not select a word around the caret when
     9        a context menu is opening. This behavior is not common in non-Mac
     10        platforms, and it prevents pasting with a context menu.
     11
     12        In order that the spell checker works without the selection, we
     13        introduce WebFrame::selectWordAroundCaret(). We can replace a word
     14        around the caret with selectWordAroundCaret() + replaceSelection().
     15
     16        * public/WebFrame.h: Add pure selectWordAroundCaret() declaration.
     17        * src/ContextMenuClientImpl.cpp:
     18        (WebKit::selectMisspelledWord): Move word-selection code to
     19        WebFrameImpl::selectWordAroundPosition(), and clear the selection
     20        on non-Mac.
     21        * src/WebFrameImpl.cpp:
     22        (WebKit::WebFrameImpl::selectWordAroundPosition):
     23        (WebKit::WebFrameImpl::selectWordAroundCaret):
     24        * src/WebFrameImpl.h: Add selectWordAroundCaret() declaration.
     25
    1262010-02-01  Shinichiro Hamaji  <hamaji@chromium.org>
    227
  • trunk/WebKit/chromium/public/WebFrame.h

    r52851 r54212  
    358358    virtual WebString selectionAsMarkup() const = 0;
    359359
     360    // Expands the selection to a word around the caret and returns
     361    // true. Does nothing and returns false if there is no caret or
     362    // there is ranged selection.
     363    virtual bool selectWordAroundCaret() = 0;
     364
    360365
    361366    // Printing ------------------------------------------------------------
  • trunk/WebKit/chromium/src/ContextMenuClientImpl.cpp

    r54119 r54212  
    9090// is to be evolked. This function also sets the word on which context menu
    9191// has been evoked to be the selected word, as required. This function changes
    92 // the selection only when there were no selected characters.
     92// the selection only when there were no selected characters on OS X.
    9393static String selectMisspelledWord(const ContextMenu* defaultMenu, Frame* selectedFrame)
    9494{
     
    111111        hitTestResult.localPoint()));
    112112
    113     VisibleSelection selection;
    114     if (pos.isNotNull()) {
    115         selection = VisibleSelection(pos);
    116         selection.expandUsingGranularity(WordGranularity);
    117     }
    118 
    119     if (selection.isRange())
    120         selectedFrame->setSelectionGranularity(WordGranularity);
    121 
    122     if (selectedFrame->shouldChangeSelection(selection))
    123         selectedFrame->selection()->setSelection(selection);
    124 
     113    if (pos.isNull())
     114        return misspelledWord; // It is empty.
     115
     116    WebFrameImpl::selectWordAroundPosition(selectedFrame, pos);
    125117    misspelledWord = selectedFrame->selectedText().stripWhiteSpace();
    126118
     119#if OS(DARWIN)
    127120    // If misspelled word is still empty, then that portion should not be
    128121    // selected. Set the selection to that position only, and do not expand.
    129     if (misspelledWord.isEmpty()) {
    130         selection = VisibleSelection(pos);
    131         selectedFrame->selection()->setSelection(selection);
    132     }
    133 
     122    if (misspelledWord.isEmpty())
     123        selectedFrame->selection()->setSelection(VisibleSelection(pos));
     124#else
     125    // On non-Mac, right-click should not make a range selection in any case.
     126    selectedFrame->selection()->setSelection(VisibleSelection(pos));
     127#endif
    134128    return misspelledWord;
    135129}
  • trunk/WebKit/chromium/src/WebFrameImpl.cpp

    r53527 r54212  
    10781078}
    10791079
     1080void WebFrameImpl::selectWordAroundPosition(Frame* frame, VisiblePosition pos)
     1081{
     1082    VisibleSelection selection(pos);
     1083    selection.expandUsingGranularity(WordGranularity);
     1084
     1085    if (selection.isRange())
     1086        frame->setSelectionGranularity(WordGranularity);
     1087
     1088    if (frame->shouldChangeSelection(selection))
     1089        frame->selection()->setSelection(selection);
     1090}
     1091
     1092bool WebFrameImpl::selectWordAroundCaret()
     1093{
     1094    SelectionController* controller = frame()->selection();
     1095    ASSERT(!controller->isNone());
     1096    if (controller->isNone() || controller->isRange())
     1097        return false;
     1098    selectWordAroundPosition(frame(), controller->selection().visibleStart());
     1099    return true;
     1100}
     1101
    10801102int WebFrameImpl::printBegin(const WebSize& pageSize)
    10811103{
  • trunk/WebKit/chromium/src/WebFrameImpl.h

    r52851 r54212  
    142142    virtual WebString selectionAsText() const;
    143143    virtual WebString selectionAsMarkup() const;
     144    virtual bool selectWordAroundCaret();
    144145    virtual int printBegin(const WebSize& pageSize);
    145146    virtual float printPage(int pageToPrint, WebCanvas*);
     
    220221    void dropClient() { m_client = 0; }
    221222
     223    static void selectWordAroundPosition(WebCore::Frame*, WebCore::VisiblePosition);
     224
    222225private:
    223226    class DeferredScopeStringMatches;
Note: See TracChangeset for help on using the changeset viewer.