Commit 1d3b1ae4 authored by tkent@chromium.org's avatar tkent@chromium.org

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.

git-svn-id: svn://svn.chromium.org/blink/trunk@54212 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent c2614338
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.
2010-02-01 Shinichiro Hamaji <hamaji@chromium.org>
Unreviewed attempt to fix the broken build.
......
......@@ -357,6 +357,11 @@ public:
virtual WebString selectionAsText() const = 0;
virtual WebString selectionAsMarkup() const = 0;
// Expands the selection to a word around the caret and returns
// true. Does nothing and returns false if there is no caret or
// there is ranged selection.
virtual bool selectWordAroundCaret() = 0;
// Printing ------------------------------------------------------------
......
......@@ -89,7 +89,7 @@ static bool isASingleWord(const String& text)
// Helper function to get misspelled word on which context menu
// is to be evolked. This function also sets the word on which context menu
// has been evoked to be the selected word, as required. This function changes
// the selection only when there were no selected characters.
// the selection only when there were no selected characters on OS X.
static String selectMisspelledWord(const ContextMenu* defaultMenu, Frame* selectedFrame)
{
// First select from selectedText to check for multiple word selection.
......@@ -110,27 +110,21 @@ static String selectMisspelledWord(const ContextMenu* defaultMenu, Frame* select
VisiblePosition pos(innerNode->renderer()->positionForPoint(
hitTestResult.localPoint()));
VisibleSelection selection;
if (pos.isNotNull()) {
selection = VisibleSelection(pos);
selection.expandUsingGranularity(WordGranularity);
}
if (selection.isRange())
selectedFrame->setSelectionGranularity(WordGranularity);
if (selectedFrame->shouldChangeSelection(selection))
selectedFrame->selection()->setSelection(selection);
if (pos.isNull())
return misspelledWord; // It is empty.
WebFrameImpl::selectWordAroundPosition(selectedFrame, pos);
misspelledWord = selectedFrame->selectedText().stripWhiteSpace();
#if OS(DARWIN)
// If misspelled word is still empty, then that portion should not be
// selected. Set the selection to that position only, and do not expand.
if (misspelledWord.isEmpty()) {
selection = VisibleSelection(pos);
selectedFrame->selection()->setSelection(selection);
}
if (misspelledWord.isEmpty())
selectedFrame->selection()->setSelection(VisibleSelection(pos));
#else
// On non-Mac, right-click should not make a range selection in any case.
selectedFrame->selection()->setSelection(VisibleSelection(pos));
#endif
return misspelledWord;
}
......
......@@ -1077,6 +1077,28 @@ WebString WebFrameImpl::selectionAsMarkup() const
return createMarkup(range.get(), 0);
}
void WebFrameImpl::selectWordAroundPosition(Frame* frame, VisiblePosition pos)
{
VisibleSelection selection(pos);
selection.expandUsingGranularity(WordGranularity);
if (selection.isRange())
frame->setSelectionGranularity(WordGranularity);
if (frame->shouldChangeSelection(selection))
frame->selection()->setSelection(selection);
}
bool WebFrameImpl::selectWordAroundCaret()
{
SelectionController* controller = frame()->selection();
ASSERT(!controller->isNone());
if (controller->isNone() || controller->isRange())
return false;
selectWordAroundPosition(frame(), controller->selection().visibleStart());
return true;
}
int WebFrameImpl::printBegin(const WebSize& pageSize)
{
ASSERT(!frame()->document()->isFrameSet());
......
......@@ -141,6 +141,7 @@ public:
virtual WebRange selectionRange() const;
virtual WebString selectionAsText() const;
virtual WebString selectionAsMarkup() const;
virtual bool selectWordAroundCaret();
virtual int printBegin(const WebSize& pageSize);
virtual float printPage(int pageToPrint, WebCanvas*);
virtual float getPrintPageShrink(int page);
......@@ -219,6 +220,8 @@ public:
WebFrameClient* client() const { return m_client; }
void dropClient() { m_client = 0; }
static void selectWordAroundPosition(WebCore::Frame*, WebCore::VisiblePosition);
private:
class DeferredScopeStringMatches;
friend class DeferredScopeStringMatches;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment