Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: webkit/glue/context_menu_client_impl.cc

Issue 16510: Fixes bug 1925 (context menus for text selections in... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/render_view.cc ('k') | webkit/glue/context_node_types.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 8
9 MSVC_PUSH_WARNING_LEVEL(0); 9 MSVC_PUSH_WARNING_LEVEL(0);
10 #include "ContextMenu.h" 10 #include "ContextMenu.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 ContextMenuClientImpl::~ContextMenuClientImpl() { 101 ContextMenuClientImpl::~ContextMenuClientImpl() {
102 } 102 }
103 103
104 void ContextMenuClientImpl::contextMenuDestroyed() { 104 void ContextMenuClientImpl::contextMenuDestroyed() {
105 delete this; 105 delete this;
106 } 106 }
107 107
108 // Figure out the URL of a page or subframe. Returns |page_type| as the type, 108 // Figure out the URL of a page or subframe. Returns |page_type| as the type,
109 // which indicates page or subframe, or ContextNode::NONE if the URL could not 109 // which indicates page or subframe, or ContextNode::NONE if the URL could not
110 // be determined for some reason. 110 // be determined for some reason.
111 static ContextNode::Type GetTypeAndURLFromFrame(WebCore::Frame* frame, 111 static ContextNode GetTypeAndURLFromFrame(WebCore::Frame* frame,
112 GURL* url, 112 GURL* url,
113 ContextNode::Type page_type) { 113 ContextNode page_node) {
114 ContextNode::Type type = ContextNode::NONE; 114 ContextNode node;
115 if (frame) { 115 if (frame) {
116 WebCore::DocumentLoader* dl = frame->loader()->documentLoader(); 116 WebCore::DocumentLoader* dl = frame->loader()->documentLoader();
117 if (dl) { 117 if (dl) {
118 WebDataSource* ds = static_cast<WebDocumentLoaderImpl*>(dl)-> 118 WebDataSource* ds = static_cast<WebDocumentLoaderImpl*>(dl)->
119 GetDataSource(); 119 GetDataSource();
120 if (ds) { 120 if (ds) {
121 type = page_type; 121 node = page_node;
122 *url = ds->HasUnreachableURL() ? ds->GetUnreachableURL() 122 *url = ds->HasUnreachableURL() ? ds->GetUnreachableURL()
123 : ds->GetRequest().GetURL(); 123 : ds->GetRequest().GetURL();
124 } 124 }
125 } 125 }
126 } 126 }
127 return type; 127 return node;
128 } 128 }
129 129
130 WebCore::PlatformMenuDescription 130 WebCore::PlatformMenuDescription
131 ContextMenuClientImpl::getCustomMenuFromDefaultItems( 131 ContextMenuClientImpl::getCustomMenuFromDefaultItems(
132 WebCore::ContextMenu* default_menu) { 132 WebCore::ContextMenu* default_menu) {
133 // Displaying the context menu in this function is a big hack as we don't 133 // Displaying the context menu in this function is a big hack as we don't
134 // have context, i.e. whether this is being invoked via a script or in 134 // have context, i.e. whether this is being invoked via a script or in
135 // response to user input (Mouse event WM_RBUTTONDOWN, 135 // response to user input (Mouse event WM_RBUTTONDOWN,
136 // Keyboard events KeyVK_APPS, Shift+F10). Check if this is being invoked 136 // Keyboard events KeyVK_APPS, Shift+F10). Check if this is being invoked
137 // in response to the above input events before popping up the context menu. 137 // in response to the above input events before popping up the context menu.
138 if (!webview_->context_menu_allowed()) 138 if (!webview_->context_menu_allowed())
139 return NULL; 139 return NULL;
140 140
141 WebCore::HitTestResult r = default_menu->hitTestResult(); 141 WebCore::HitTestResult r = default_menu->hitTestResult();
142 WebCore::Frame* selected_frame = r.innerNonSharedNode()->document()->frame(); 142 WebCore::Frame* selected_frame = r.innerNonSharedNode()->document()->frame();
143 143
144 WebCore::IntPoint menu_point = 144 WebCore::IntPoint menu_point =
145 selected_frame->view()->contentsToWindow(r.point()); 145 selected_frame->view()->contentsToWindow(r.point());
146 146
147 ContextNode::Type type = ContextNode::NONE; 147 ContextNode node;
148 148
149 // Links, Images and Image-Links take preference over all else. 149 // Links, Images and Image-Links take preference over all else.
150 WebCore::KURL link_url = r.absoluteLinkURL(); 150 WebCore::KURL link_url = r.absoluteLinkURL();
151 if (!link_url.isEmpty()) { 151 if (!link_url.isEmpty()) {
152 type = ContextNode::LINK; 152 node.type |= ContextNode::LINK;
153 } 153 }
154 WebCore::KURL image_url = r.absoluteImageURL(); 154 WebCore::KURL image_url = r.absoluteImageURL();
155 if (!image_url.isEmpty()) { 155 if (!image_url.isEmpty()) {
156 type = ContextNode::IMAGE; 156 node.type |= ContextNode::IMAGE;
157 } 157 }
158 if (!image_url.isEmpty() && !link_url.isEmpty())
159 type = ContextNode::IMAGE_LINK;
160 158
161 // If it's not a link, an image or an image link, show a selection menu or a 159 // If it's not a link, an image or an image link, show a selection menu or a
162 // more generic page menu. 160 // more generic page menu.
163 std::wstring selection_text_string; 161 std::wstring selection_text_string;
164 std::wstring misspelled_word_string; 162 std::wstring misspelled_word_string;
165 GURL frame_url; 163 GURL frame_url;
166 GURL page_url; 164 GURL page_url;
167 std::string security_info; 165 std::string security_info;
168 166
169 std::wstring frame_encoding; 167 std::wstring frame_encoding;
170 // Send the frame and page URLs in any case. 168 // Send the frame and page URLs in any case.
171 ContextNode::Type frame_type = ContextNode::NONE; 169 ContextNode frame_node = ContextNode(ContextNode::NONE);
172 ContextNode::Type page_type = 170 ContextNode page_node =
173 GetTypeAndURLFromFrame(webview_->main_frame()->frame(), 171 GetTypeAndURLFromFrame(webview_->main_frame()->frame(),
174 &page_url, 172 &page_url,
175 ContextNode::PAGE); 173 ContextNode(ContextNode::PAGE));
176 if (selected_frame != webview_->main_frame()->frame()) { 174 if (selected_frame != webview_->main_frame()->frame()) {
177 frame_type = GetTypeAndURLFromFrame(selected_frame, 175 frame_node = GetTypeAndURLFromFrame(selected_frame,
178 &frame_url, 176 &frame_url,
179 ContextNode::FRAME); 177 ContextNode(ContextNode::FRAME));
180 frame_encoding = webkit_glue::StringToStdWString( 178 frame_encoding = webkit_glue::StringToStdWString(
181 selected_frame->loader()->encoding()); 179 selected_frame->loader()->encoding());
182 } 180 }
181
182 if (r.isSelected()) {
183 node.type |= ContextNode::SELECTION;
184 selection_text_string = CollapseWhitespace(
185 webkit_glue::StringToStdWString(selected_frame->selectedText()),
186 false);
187 }
188
189 if (r.isContentEditable()) {
190 node.type |= ContextNode::EDITABLE;
191 if (webview_->GetFocusedWebCoreFrame()->editor()->
192 isContinuousSpellCheckingEnabled()) {
193 misspelled_word_string = GetMisspelledWord(default_menu,
194 selected_frame);
195 }
196 }
183 197
184 if (type == ContextNode::NONE) { 198 if (node.type == ContextNode::NONE) {
185 if (r.isContentEditable()) { 199 if (selected_frame != webview_->main_frame()->frame()) {
186 type = ContextNode::EDITABLE; 200 node = frame_node;
187 if (webview_->GetFocusedWebCoreFrame()->editor()->
188 isContinuousSpellCheckingEnabled()) {
189 misspelled_word_string = GetMisspelledWord(default_menu,
190 selected_frame);
191 }
192 } else if (r.isSelected()) {
193 type = ContextNode::SELECTION;
194 selection_text_string =
195 CollapseWhitespace(
196 webkit_glue::StringToStdWString(selected_frame->selectedText()),
197 false);
198 } else if (selected_frame != webview_->main_frame()->frame()) {
199 type = frame_type;
200 } else { 201 } else {
201 type = page_type; 202 node = page_node;
202 } 203 }
203 } 204 }
204 205
205 // Now retrieve the security info. 206 // Now retrieve the security info.
206 WebCore::DocumentLoader* dl = selected_frame->loader()->documentLoader(); 207 WebCore::DocumentLoader* dl = selected_frame->loader()->documentLoader();
207 if (dl) { 208 if (dl) {
208 WebDataSource* ds = static_cast<WebDocumentLoaderImpl*>(dl)-> 209 WebDataSource* ds = static_cast<WebDocumentLoaderImpl*>(dl)->
209 GetDataSource(); 210 GetDataSource();
210 if (ds) { 211 if (ds) {
211 const WebResponse& response = ds->GetResponse(); 212 const WebResponse& response = ds->GetResponse();
(...skipping 13 matching lines...) Expand all
225 if (webview_->GetFocusedWebCoreFrame()->editor()->canPaste()) 226 if (webview_->GetFocusedWebCoreFrame()->editor()->canPaste())
226 edit_flags |= ContextNode::CAN_PASTE; 227 edit_flags |= ContextNode::CAN_PASTE;
227 if (webview_->GetFocusedWebCoreFrame()->editor()->canDelete()) 228 if (webview_->GetFocusedWebCoreFrame()->editor()->canDelete())
228 edit_flags |= ContextNode::CAN_DELETE; 229 edit_flags |= ContextNode::CAN_DELETE;
229 // We can always select all... 230 // We can always select all...
230 edit_flags |= ContextNode::CAN_SELECT_ALL; 231 edit_flags |= ContextNode::CAN_SELECT_ALL;
231 232
232 WebViewDelegate* d = webview_->delegate(); 233 WebViewDelegate* d = webview_->delegate();
233 if (d) { 234 if (d) {
234 d->ShowContextMenu(webview_, 235 d->ShowContextMenu(webview_,
235 type, 236 node,
236 menu_point.x(), 237 menu_point.x(),
237 menu_point.y(), 238 menu_point.y(),
238 webkit_glue::KURLToGURL(link_url), 239 webkit_glue::KURLToGURL(link_url),
239 webkit_glue::KURLToGURL(image_url), 240 webkit_glue::KURLToGURL(image_url),
240 page_url, 241 page_url,
241 frame_url, 242 frame_url,
242 selection_text_string, 243 selection_text_string,
243 misspelled_word_string, 244 misspelled_word_string,
244 edit_flags, 245 edit_flags,
245 security_info); 246 security_info);
(...skipping 25 matching lines...) Expand all
271 272
272 bool ContextMenuClientImpl::shouldIncludeInspectElementItem() { 273 bool ContextMenuClientImpl::shouldIncludeInspectElementItem() {
273 return false; // TODO(jackson): Eventually include the inspector context me nu item 274 return false; // TODO(jackson): Eventually include the inspector context me nu item
274 } 275 }
275 276
276 #if defined(OS_MACOSX) 277 #if defined(OS_MACOSX)
277 void ContextMenuClientImpl::searchWithSpotlight() { 278 void ContextMenuClientImpl::searchWithSpotlight() {
278 // TODO(pinkerton): write this 279 // TODO(pinkerton): write this
279 } 280 }
280 #endif 281 #endif
OLDNEW
« no previous file with comments | « chrome/renderer/render_view.cc ('k') | webkit/glue/context_node_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698