summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-28 18:39:02 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-28 18:39:02 +0000
commit124646932219f4cd17a3dc80393485e923deb1ba (patch)
tree9e20a8428541fb543b21503ce76e7a71251a8722 /chrome
parent96c622f5a85c0a745b5f66856aea419032c934af (diff)
downloadchromium_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 'chrome')
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu.cc50
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu.h7
-rw-r--r--chrome/browser/tab_contents/web_contents_view_win.cc2
-rw-r--r--chrome/common/render_messages.h105
-rw-r--r--chrome/renderer/render_view.cc4
-rw-r--r--chrome/renderer/render_view.h2
6 files changed, 78 insertions, 92 deletions
diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc
index 4aecf00..9d36be5 100644
--- a/chrome/browser/tab_contents/render_view_context_menu.cc
+++ b/chrome/browser/tab_contents/render_view_context_menu.cc
@@ -18,7 +18,7 @@
RenderViewContextMenu::RenderViewContextMenu(
Menu::Delegate* delegate,
HWND owner,
- ContextNode::Type type,
+ ContextNode node,
const std::wstring& misspelled_word,
const std::vector<std::wstring>& misspelled_word_suggestions,
Profile* profile)
@@ -26,40 +26,34 @@ RenderViewContextMenu::RenderViewContextMenu(
misspelled_word_(misspelled_word),
misspelled_word_suggestions_(misspelled_word_suggestions),
profile_(profile) {
- InitMenu(type);
+ InitMenu(node);
}
RenderViewContextMenu::~RenderViewContextMenu() {
}
-void RenderViewContextMenu::InitMenu(ContextNode::Type type) {
- switch (type) {
- case ContextNode::PAGE:
+void RenderViewContextMenu::InitMenu(ContextNode node) {
+ if (node.type & ContextNode::PAGE)
AppendPageItems();
- break;
- case ContextNode::FRAME:
+ if (node.type & ContextNode::FRAME)
AppendFrameItems();
- break;
- case ContextNode::LINK:
+ if (node.type & ContextNode::LINK)
AppendLinkItems();
- break;
- case ContextNode::IMAGE:
- AppendImageItems();
- break;
- case ContextNode::IMAGE_LINK:
- AppendLinkItems();
- AppendSeparator();
+
+ if (node.type & ContextNode::IMAGE) {
+ if (node.type & ContextNode::LINK)
+ AppendSeparator();
AppendImageItems();
- break;
- case ContextNode::SELECTION:
- AppendSelectionItems();
- break;
- case ContextNode::EDITABLE:
- AppendEditableItems();
- break;
- default:
- NOTREACHED() << "Unknown ContextNode::Type";
}
+
+ if (node.type & ContextNode::EDITABLE)
+ AppendEditableItems();
+ else if (node.type & ContextNode::SELECTION ||
+ node.type & ContextNode::LINK)
+ AppendCopyItem();
+
+ if (node.type & ContextNode::SELECTION)
+ AppendSearchProvider();
AppendSeparator();
AppendDeveloperItems();
}
@@ -74,7 +68,6 @@ void RenderViewContextMenu::AppendLinkItems() {
AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_OPENLINKOFFTHERECORD);
AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_SAVELINKAS);
AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_COPYLINKLOCATION);
- AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_COPY);
}
void RenderViewContextMenu::AppendImageItems() {
@@ -109,8 +102,11 @@ void RenderViewContextMenu::AppendFrameItems() {
AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_VIEWFRAMEINFO);
}
-void RenderViewContextMenu::AppendSelectionItems() {
+void RenderViewContextMenu::AppendCopyItem() {
AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_COPY);
+}
+
+void RenderViewContextMenu::AppendSearchProvider() {
DCHECK(profile_);
if (profile_->GetTemplateURLModel()->GetDefaultSearchProvider() != NULL)
AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_SEARCHWEBFOR);
diff --git a/chrome/browser/tab_contents/render_view_context_menu.h b/chrome/browser/tab_contents/render_view_context_menu.h
index 6c95f57..6d55c03 100644
--- a/chrome/browser/tab_contents/render_view_context_menu.h
+++ b/chrome/browser/tab_contents/render_view_context_menu.h
@@ -15,7 +15,7 @@ class RenderViewContextMenu : public Menu {
RenderViewContextMenu(
Menu::Delegate* delegate,
HWND owner,
- ContextNode::Type type,
+ ContextNode node,
const std::wstring& misspelled_word,
const std::vector<std::wstring>& misspelled_word_suggestions,
Profile* profile);
@@ -23,14 +23,15 @@ class RenderViewContextMenu : public Menu {
virtual ~RenderViewContextMenu();
private:
- void InitMenu(ContextNode::Type type);
+ void InitMenu(ContextNode node);
void AppendDeveloperItems();
void AppendLinkItems();
void AppendImageItems();
void AppendPageItems();
void AppendFrameItems();
- void AppendSelectionItems();
+ void AppendCopyItem();
void AppendEditableItems();
+ void AppendSearchProvider();
std::wstring misspelled_word_;
std::vector<std::wstring> misspelled_word_suggestions_;
diff --git a/chrome/browser/tab_contents/web_contents_view_win.cc b/chrome/browser/tab_contents/web_contents_view_win.cc
index 0c7cbef..ee69af7 100644
--- a/chrome/browser/tab_contents/web_contents_view_win.cc
+++ b/chrome/browser/tab_contents/web_contents_view_win.cc
@@ -319,7 +319,7 @@ void WebContentsViewWin::ShowContextMenu(
RenderViewContextMenuController menu_controller(web_contents_, params);
RenderViewContextMenu menu(&menu_controller,
GetHWND(),
- params.type,
+ params.node,
params.misspelled_word,
params.dictionary_suggestions,
web_contents_->profile());
diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h
index 83dddb1..7d1273f 100644
--- a/chrome/common/render_messages.h
+++ b/chrome/common/render_messages.h
@@ -124,7 +124,7 @@ struct ViewHostMsg_FrameNavigate_Params {
// could be used for more contextual actions.
struct ViewHostMsg_ContextMenu_Params {
// This is the type of Context Node that the context menu was invoked on.
- ContextNode::Type type;
+ ContextNode node;
// These values represent the coordinates of the mouse when the context menu
// was invoked. Coords are relative to the associated RenderView's origin.
@@ -543,8 +543,49 @@ struct ParamTraits<FilterPolicy::Type> {
};
template <>
-struct ParamTraits<ContextNode::Type> {
- typedef ContextNode::Type param_type;
+struct ParamTraits<ContextNode> {
+ typedef ContextNode param_type;
+ static void Write(Message* m, const param_type& p) {
+ m->WriteInt(p.type);
+ }
+ static bool Read(const Message* m, void** iter, param_type* p) {
+ int type;
+ if (!m->ReadInt(iter, &type))
+ return false;
+ *p = ContextNode(type);
+ return true;
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ std::wstring event = L"";
+
+ if (!p.type)
+ event.append(L"NONE");
+ else {
+ event.append(L"(");
+ if (p.type & ContextNode::PAGE)
+ event.append(L"PAGE|");
+ if (p.type & ContextNode::FRAME)
+ event.append(L"FRAME|");
+ if (p.type & ContextNode::LINK)
+ event.append(L"LINK|");
+ if (p.type & ContextNode::IMAGE)
+ event.append(L"IMAGE|");
+ if (p.type & ContextNode::SELECTION)
+ event.append(L"SELECTION|");
+ if (p.type & ContextNode::EDITABLE)
+ event.append(L"EDITABLE|");
+ if (p.type & ContextNode::MISSPELLED_WORD)
+ event.append(L"MISSPELLED_WORD|");
+ event.append(L")");
+ }
+
+ LogParam(event, l);
+ }
+};
+
+template <>
+struct ParamTraits<WebInputEvent::Type> {
+ typedef WebInputEvent::Type param_type;
static void Write(Message* m, const param_type& p) {
m->WriteInt(p);
}
@@ -552,7 +593,7 @@ struct ParamTraits<ContextNode::Type> {
int type;
if (!m->ReadInt(iter, &type))
return false;
- *p = ContextNode::FromInt(type);
+ *p = static_cast<WebInputEvent::Type>(type);
return true;
}
static void Log(const param_type& p, std::wstring* l) {
@@ -591,58 +632,6 @@ struct ParamTraits<ContextNode::Type> {
}
};
-template <>
-struct ParamTraits<WebInputEvent::Type> {
- typedef WebInputEvent::Type param_type;
- static void Write(Message* m, const param_type& p) {
- m->WriteInt(p);
- }
- static bool Read(const Message* m, void** iter, param_type* p) {
- int type;
- if (!m->ReadInt(iter, &type))
- return false;
- *p = static_cast<WebInputEvent::Type>(type);
- return true;
- }
- static void Log(const param_type& p, std::wstring* l) {
- std::wstring event;
- switch (p) {
- case ContextNode::NONE:
- event = L"NONE";
- break;
- case ContextNode::PAGE:
- event = L"PAGE";
- break;
- case ContextNode::FRAME:
- event = L"FRAME";
- break;
- case ContextNode::LINK:
- event = L"LINK";
- break;
- case ContextNode::IMAGE:
- event = L"IMAGE";
- break;
- case ContextNode::IMAGE_LINK:
- event = L"IMAGE_LINK";
- break;
- case ContextNode::SELECTION:
- event = L"SELECTION";
- break;
- case ContextNode::EDITABLE:
- event = L"EDITABLE";
- break;
- case ContextNode::MISPELLED_WORD:
- event = L"MISPELLED_WORD";
- break;
- default:
- event = L"UNKNOWN";
- break;
- }
-
- LogParam(event, l);
- }
-};
-
// Traits for ViewMsg_Accessibility_In_Params structure to pack/unpack.
template <>
struct ParamTraits<ViewMsg_Accessibility_In_Params> {
@@ -943,7 +932,7 @@ template <>
struct ParamTraits<ViewHostMsg_ContextMenu_Params> {
typedef ViewHostMsg_ContextMenu_Params param_type;
static void Write(Message* m, const param_type& p) {
- WriteParam(m, p.type);
+ WriteParam(m, p.node);
WriteParam(m, p.x);
WriteParam(m, p.y);
WriteParam(m, p.link_url);
@@ -959,7 +948,7 @@ struct ParamTraits<ViewHostMsg_ContextMenu_Params> {
}
static bool Read(const Message* m, void** iter, param_type* p) {
return
- ReadParam(m, iter, &p->type) &&
+ ReadParam(m, iter, &p->node) &&
ReadParam(m, iter, &p->x) &&
ReadParam(m, iter, &p->y) &&
ReadParam(m, iter, &p->link_url) &&
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index 0eb16ee..b8d321a 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -2027,7 +2027,7 @@ void RenderView::SyncNavigationState() {
}
void RenderView::ShowContextMenu(WebView* webview,
- ContextNode::Type type,
+ ContextNode node,
int x,
int y,
const GURL& link_url,
@@ -2039,7 +2039,7 @@ void RenderView::ShowContextMenu(WebView* webview,
int edit_flags,
const std::string& security_info) {
ViewHostMsg_ContextMenu_Params params;
- params.type = type;
+ params.node = node;
params.x = x;
params.y = y;
params.image_url = image_url;
diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h
index 5aff4bd..c7f5384 100644
--- a/chrome/renderer/render_view.h
+++ b/chrome/renderer/render_view.h
@@ -234,7 +234,7 @@ class RenderView : public RenderWidget,
ErrorPageType error_type);
virtual void ShowContextMenu(WebView* webview,
- ContextNode::Type type,
+ ContextNode node,
int x,
int y,
const GURL& link_url,