summaryrefslogtreecommitdiffstats
path: root/webkit/glue/context_menu_client_impl.cc
diff options
context:
space:
mode:
authortc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-29 01:05:08 +0000
committertc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-29 01:05:08 +0000
commit985f0e6ba8533b63f508eecdaa0d205c91a8e776 (patch)
tree3adffebcd61dd24a673ffd97bea63965178e808a /webkit/glue/context_menu_client_impl.cc
parentba4e52f352826c33876ab2c0ce0686bbe280af4a (diff)
downloadchromium_src-985f0e6ba8533b63f508eecdaa0d205c91a8e776.zip
chromium_src-985f0e6ba8533b63f508eecdaa0d205c91a8e776.tar.gz
chromium_src-985f0e6ba8533b63f508eecdaa0d205c91a8e776.tar.bz2
When right clicking in a text area that is scrolled, the wrong
word is selected. This is because we use the wrong node when getting the selection. We want to use the shadow inner node, but the hit test result provided to the ContextMenu is not the shadow node. To work around this, we recompute the hit test result. BUG=613 TEST=Go to a page with a text area, add text until a scroll bar appears, scroll the text area and right click on a word. The word under the cursor should be highlighted. Review URL: http://codereview.chromium.org/8853 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4118 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/context_menu_client_impl.cc')
-rw-r--r--webkit/glue/context_menu_client_impl.cc27
1 files changed, 19 insertions, 8 deletions
diff --git a/webkit/glue/context_menu_client_impl.cc b/webkit/glue/context_menu_client_impl.cc
index ddde662..37323b0 100644
--- a/webkit/glue/context_menu_client_impl.cc
+++ b/webkit/glue/context_menu_client_impl.cc
@@ -11,6 +11,7 @@ MSVC_PUSH_WARNING_LEVEL(0);
#include "Document.h"
#include "DocumentLoader.h"
#include "Editor.h"
+#include "EventHandler.h"
#include "FrameLoader.h"
#include "FrameView.h"
#include "HitTestResult.h"
@@ -29,8 +30,10 @@ MSVC_POP_WARNING();
#include "base/word_iterator.h"
+namespace {
+
// Helper function to determine whether text is a single word or a sentence.
-static bool IsASingleWord(const std::wstring& text) {
+bool IsASingleWord(const std::wstring& text) {
WordIterator iter(text, WordIterator::BREAK_WORD);
int word_count = 0;
if (!iter.Init()) return false;
@@ -53,8 +56,8 @@ static bool IsASingleWord(const std::wstring& 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.
-static std::wstring GetMisspelledWord(WebCore::ContextMenu* default_menu,
- WebCore::Frame* selected_frame) {
+std::wstring GetMisspelledWord(const WebCore::ContextMenu* default_menu,
+ WebCore::Frame* selected_frame) {
std::wstring misspelled_word_string;
// First select from selectedText to check for multiple word selection.
@@ -68,11 +71,17 @@ static std::wstring GetMisspelledWord(WebCore::ContextMenu* default_menu,
return L"";
// Expand around the click to see if we clicked a word.
- WebCore::Selection selection;
- WebCore::VisiblePosition pos(default_menu->hitTestResult().innerNode()->
- renderer()->positionForPoint(default_menu->hitTestResult().
- localPoint()));
+ WebCore::Node* inner_node = default_menu->hitTestResult().innerNode();
+ if (inner_node->renderer()->isTextArea()) {
+ WebCore::HitTestResult real_result = selected_frame->eventHandler()->
+ hitTestResultAtPoint(default_menu->hitTestResult().localPoint(), true);
+ inner_node = real_result.innerNode();
+ }
+ WebCore::VisiblePosition pos(inner_node->renderer()->
+ positionForPoint(default_menu->hitTestResult().localPoint()));
+
+ WebCore::Selection selection;
if (pos.isNotNull()) {
selection = WebCore::Selection(pos);
selection.expandUsingGranularity(WebCore::WordGranularity);
@@ -92,6 +101,8 @@ static std::wstring GetMisspelledWord(WebCore::ContextMenu* default_menu,
return misspelled_word_string;
}
+} // namespace
+
ContextMenuClientImpl::~ContextMenuClientImpl() {
}
@@ -179,7 +190,7 @@ WebCore::PlatformMenuDescription
if (r.isContentEditable()) {
type = ContextNode::EDITABLE;
if (webview_->FocusedFrameNeedsSpellchecking()) {
- misspelled_word_string = GetMisspelledWord(default_menu,
+ misspelled_word_string = GetMisspelledWord(default_menu,
selected_frame);
}
} else if (r.isSelected()) {