diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-28 18:39:02 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-28 18:39:02 +0000 |
commit | 124646932219f4cd17a3dc80393485e923deb1ba (patch) | |
tree | 9e20a8428541fb543b21503ce76e7a71251a8722 /webkit | |
parent | 96c622f5a85c0a745b5f66856aea419032c934af (diff) | |
download | chromium_src-124646932219f4cd17a3dc80393485e923deb1ba.zip chromium_src-124646932219f4cd17a3dc80393485e923deb1ba.tar.gz chromium_src-124646932219f4cd17a3dc80393485e923deb1ba.tar.bz2 |
Context menus for text selections in editable boxes and links should include the Search menu item. Original patch by Brian Duff (see http://codereview.chromium.org/16510 ), r=me.
BUG=1925
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8815 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/context_menu_client_impl.cc | 69 | ||||
-rw-r--r-- | webkit/glue/context_node_types.h | 40 | ||||
-rw-r--r-- | webkit/glue/webview_delegate.h | 4 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_webview_delegate.cc | 4 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_webview_delegate.h | 8 |
5 files changed, 60 insertions, 65 deletions
diff --git a/webkit/glue/context_menu_client_impl.cc b/webkit/glue/context_menu_client_impl.cc index e2fbfcf..30f5e1a 100644 --- a/webkit/glue/context_menu_client_impl.cc +++ b/webkit/glue/context_menu_client_impl.cc @@ -108,23 +108,23 @@ void ContextMenuClientImpl::contextMenuDestroyed() { // Figure out the URL of a page or subframe. Returns |page_type| as the type, // which indicates page or subframe, or ContextNode::NONE if the URL could not // be determined for some reason. -static ContextNode::Type GetTypeAndURLFromFrame(WebCore::Frame* frame, - GURL* url, - ContextNode::Type page_type) { - ContextNode::Type type = ContextNode::NONE; +static ContextNode GetTypeAndURLFromFrame(WebCore::Frame* frame, + GURL* url, + ContextNode page_node) { + ContextNode node; if (frame) { WebCore::DocumentLoader* dl = frame->loader()->documentLoader(); if (dl) { WebDataSource* ds = static_cast<WebDocumentLoaderImpl*>(dl)-> GetDataSource(); if (ds) { - type = page_type; + node = page_node; *url = ds->HasUnreachableURL() ? ds->GetUnreachableURL() : ds->GetRequest().GetURL(); } } } - return type; + return node; } WebCore::PlatformMenuDescription @@ -144,19 +144,17 @@ WebCore::PlatformMenuDescription WebCore::IntPoint menu_point = selected_frame->view()->contentsToWindow(r.point()); - ContextNode::Type type = ContextNode::NONE; + ContextNode node; // Links, Images and Image-Links take preference over all else. WebCore::KURL link_url = r.absoluteLinkURL(); if (!link_url.isEmpty()) { - type = ContextNode::LINK; + node.type |= ContextNode::LINK; } WebCore::KURL image_url = r.absoluteImageURL(); if (!image_url.isEmpty()) { - type = ContextNode::IMAGE; + node.type |= ContextNode::IMAGE; } - if (!image_url.isEmpty() && !link_url.isEmpty()) - type = ContextNode::IMAGE_LINK; // If it's not a link, an image or an image link, show a selection menu or a // more generic page menu. @@ -168,37 +166,40 @@ WebCore::PlatformMenuDescription std::wstring frame_encoding; // Send the frame and page URLs in any case. - ContextNode::Type frame_type = ContextNode::NONE; - ContextNode::Type page_type = + ContextNode frame_node = ContextNode(ContextNode::NONE); + ContextNode page_node = GetTypeAndURLFromFrame(webview_->main_frame()->frame(), &page_url, - ContextNode::PAGE); + ContextNode(ContextNode::PAGE)); if (selected_frame != webview_->main_frame()->frame()) { - frame_type = GetTypeAndURLFromFrame(selected_frame, + frame_node = GetTypeAndURLFromFrame(selected_frame, &frame_url, - ContextNode::FRAME); + ContextNode(ContextNode::FRAME)); frame_encoding = webkit_glue::StringToStdWString( selected_frame->loader()->encoding()); } + + if (r.isSelected()) { + node.type |= ContextNode::SELECTION; + selection_text_string = CollapseWhitespace( + webkit_glue::StringToStdWString(selected_frame->selectedText()), + false); + } + + if (r.isContentEditable()) { + node.type |= ContextNode::EDITABLE; + if (webview_->GetFocusedWebCoreFrame()->editor()-> + isContinuousSpellCheckingEnabled()) { + misspelled_word_string = GetMisspelledWord(default_menu, + selected_frame); + } + } - if (type == ContextNode::NONE) { - if (r.isContentEditable()) { - type = ContextNode::EDITABLE; - if (webview_->GetFocusedWebCoreFrame()->editor()-> - isContinuousSpellCheckingEnabled()) { - misspelled_word_string = GetMisspelledWord(default_menu, - selected_frame); - } - } else if (r.isSelected()) { - type = ContextNode::SELECTION; - selection_text_string = - CollapseWhitespace( - webkit_glue::StringToStdWString(selected_frame->selectedText()), - false); - } else if (selected_frame != webview_->main_frame()->frame()) { - type = frame_type; + if (node.type == ContextNode::NONE) { + if (selected_frame != webview_->main_frame()->frame()) { + node = frame_node; } else { - type = page_type; + node = page_node; } } @@ -232,7 +233,7 @@ WebCore::PlatformMenuDescription WebViewDelegate* d = webview_->delegate(); if (d) { d->ShowContextMenu(webview_, - type, + node, menu_point.x(), menu_point.y(), webkit_glue::KURLToGURL(link_url), diff --git a/webkit/glue/context_node_types.h b/webkit/glue/context_node_types.h index 7bf22a8..b20814a 100644 --- a/webkit/glue/context_node_types.h +++ b/webkit/glue/context_node_types.h @@ -8,45 +8,35 @@ #include "base/basictypes.h" #include "base/logging.h" -// This class is for scoping only. -class ContextNode { - public: - // This enumeration defines the type of node that the user may perform a - // contextual action on in the WebView. - enum Type { - +// The type of node that the user may perform a contextual action on +// in the WebView. +struct ContextNode { + enum TypeBit { // No node is selected - NONE = 0, + NONE = 0x0, // The top page is selected - PAGE = 1, + PAGE = 0x1, // A subframe page is selected - FRAME = 2, + FRAME = 0x2, // A link is selected - LINK = 3, + LINK = 0x4, // An image is selected - IMAGE = 4, - - // An image that is also a link is selected - IMAGE_LINK = 5, + IMAGE = 0x8, // There is a textual or mixed selection that is selected - SELECTION = 6, + SELECTION = 0x10, - // An editiable element is selected - EDITABLE = 7, + // An editable element is selected + EDITABLE = 0x20, // A misspelled word is selected - MISPELLED_WORD = 8 + MISSPELLED_WORD = 0x40, }; - static Type FromInt(int32 type) { - return static_cast<Type>(type); - } - enum Capability { CAN_DO_NONE = 0x0, CAN_UNDO = 0x1, @@ -57,6 +47,10 @@ class ContextNode { CAN_DELETE = 0x20, CAN_SELECT_ALL = 0x40, }; + + int32 type; + ContextNode() : type(NONE) {} + explicit ContextNode(int32 t) : type(t) {} }; #endif // WEBKIT_GLUE_CONTEXT_NODE_TYPES_H__ diff --git a/webkit/glue/webview_delegate.h b/webkit/glue/webview_delegate.h index 09abc68..982ec49 100644 --- a/webkit/glue/webview_delegate.h +++ b/webkit/glue/webview_delegate.h @@ -549,7 +549,7 @@ class WebViewDelegate : virtual public WebWidgetDelegate { // @abstract Shows a context menu with commands relevant to a specific // element on the current page. // @param webview The WebView sending the delegate method. - // @param type The type of node(s) the context menu is being invoked on + // @param node The node(s) the context menu is being invoked on // @param x The x position of the mouse pointer (relative to the webview) // @param y The y position of the mouse pointer (relative to the webview) // @param link_url The absolute URL of the link that contains the node the @@ -566,7 +566,7 @@ class WebViewDelegate : virtual public WebWidgetDelegate { // @param frame_encoding Which indicates the encoding of current focused // sub frame. virtual void ShowContextMenu(WebView* webview, - ContextNode::Type type, + ContextNode node, int x, int y, const GURL& link_url, diff --git a/webkit/tools/test_shell/test_webview_delegate.cc b/webkit/tools/test_shell/test_webview_delegate.cc index 684b22a..f04eebe 100644 --- a/webkit/tools/test_shell/test_webview_delegate.cc +++ b/webkit/tools/test_shell/test_webview_delegate.cc @@ -471,7 +471,7 @@ void TestWebViewDelegate::StartDragging(WebView* webview, } void TestWebViewDelegate::ShowContextMenu(WebView* webview, - ContextNode::Type type, + ContextNode node, int x, int y, const GURL& link_url, @@ -482,7 +482,7 @@ void TestWebViewDelegate::ShowContextMenu(WebView* webview, const std::wstring& misspelled_word, int edit_flags, const std::string& security_info) { - CapturedContextMenuEvent context(type, x, y); + CapturedContextMenuEvent context(node, x, y); captured_context_menu_events_.push_back(context); } diff --git a/webkit/tools/test_shell/test_webview_delegate.h b/webkit/tools/test_shell/test_webview_delegate.h index 65d0723..bc3836f 100644 --- a/webkit/tools/test_shell/test_webview_delegate.h +++ b/webkit/tools/test_shell/test_webview_delegate.h @@ -40,15 +40,15 @@ class TestWebViewDelegate : public base::RefCounted<TestWebViewDelegate>, public WebViewDelegate { public: struct CapturedContextMenuEvent { - CapturedContextMenuEvent(ContextNode::Type in_type, + CapturedContextMenuEvent(ContextNode in_node, int in_x, int in_y) - : type(in_type), + : node(in_node), x(in_x), y(in_y) { } - ContextNode::Type type; + ContextNode node; int x; int y; }; @@ -102,7 +102,7 @@ class TestWebViewDelegate : public base::RefCounted<TestWebViewDelegate>, virtual void StartDragging(WebView* webview, const WebDropData& drop_data); virtual void ShowContextMenu(WebView* webview, - ContextNode::Type type, + ContextNode node, int x, int y, const GURL& link_url, |