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

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

Issue 164279: View Background Image Feature (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 11 years, 4 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 | « webkit/glue/context_menu.h ('k') | webkit/glue/webview_delegate.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-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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"
11 #include "Document.h" 11 #include "Document.h"
12 #include "DocumentLoader.h" 12 #include "DocumentLoader.h"
13 #include "Editor.h" 13 #include "Editor.h"
14 #include "EventHandler.h" 14 #include "EventHandler.h"
15 #include "FrameLoader.h" 15 #include "FrameLoader.h"
16 #include "FrameView.h" 16 #include "FrameView.h"
17 #include "CSSMutableStyleDeclaration.h"
18 #include "CSSPrimitiveValue.h"
19 #include "CSSProperty.h"
20 #include "CSSStyleSelector.h"
21 #include "CSSValue.h"
22 #include "CSSValueKeywords.h"
23 #include "CSSImageValue.h"
17 #include "HitTestResult.h" 24 #include "HitTestResult.h"
18 #include "HTMLMediaElement.h" 25 #include "HTMLMediaElement.h"
19 #include "HTMLNames.h" 26 #include "HTMLNames.h"
20 #include "KURL.h" 27 #include "KURL.h"
21 #include "Widget.h" 28 #include "Widget.h"
22 MSVC_POP_WARNING(); 29 MSVC_POP_WARNING();
23 #undef LOG 30 #undef LOG
24 31
25 #include "webkit/glue/context_menu_client_impl.h" 32 #include "webkit/glue/context_menu_client_impl.h"
26 33
27 #include "base/string_util.h" 34 #include "base/string_util.h"
28 #include "webkit/api/public/WebURL.h" 35 #include "webkit/api/public/WebURL.h"
29 #include "webkit/api/public/WebURLResponse.h" 36 #include "webkit/api/public/WebURLResponse.h"
30 #include "webkit/glue/context_menu.h" 37 #include "webkit/glue/context_menu.h"
31 #include "webkit/glue/glue_util.h" 38 #include "webkit/glue/glue_util.h"
32 #include "webkit/glue/webdatasource_impl.h" 39 #include "webkit/glue/webdatasource_impl.h"
33 #include "webkit/glue/webview_impl.h" 40 #include "webkit/glue/webview_impl.h"
34 41
35 #include "base/word_iterator.h" 42 #include "base/word_iterator.h"
36 43
44 using namespace WebCore;
37 using WebKit::WebDataSource; 45 using WebKit::WebDataSource;
38 46
39 namespace { 47 namespace {
40 48
41 // Helper function to determine whether text is a single word or a sentence. 49 // Helper function to determine whether text is a single word or a sentence.
42 bool IsASingleWord(const std::wstring& text) { 50 bool IsASingleWord(const std::wstring& text) {
43 WordIterator iter(text, WordIterator::BREAK_WORD); 51 WordIterator iter(text, WordIterator::BREAK_WORD);
44 int word_count = 0; 52 int word_count = 0;
45 if (!iter.Init()) return false; 53 if (!iter.Init()) return false;
46 while (iter.Advance()) { 54 while (iter.Advance()) {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 selected_frame->view()->contentsToWindow(r.point()); 171 selected_frame->view()->contentsToWindow(r.point());
164 172
165 ContextNodeType node_type; 173 ContextNodeType node_type;
166 174
167 // Links, Images, Media tags, and Image/Media-Links take preference over 175 // Links, Images, Media tags, and Image/Media-Links take preference over
168 // all else. 176 // all else.
169 WebCore::KURL link_url = r.absoluteLinkURL(); 177 WebCore::KURL link_url = r.absoluteLinkURL();
170 if (!link_url.isEmpty()) { 178 if (!link_url.isEmpty()) {
171 node_type.type |= ContextNodeType::LINK; 179 node_type.type |= ContextNodeType::LINK;
172 } 180 }
173
174 WebCore::KURL src_url; 181 WebCore::KURL src_url;
175 182
176 ContextMenuMediaParams media_params; 183 ContextMenuMediaParams media_params;
184 GURL bkg_url;
177 185
178 if (!r.absoluteImageURL().isEmpty()) { 186 if (!r.absoluteImageURL().isEmpty()) {
179 src_url = r.absoluteImageURL(); 187 src_url = r.absoluteImageURL();
180 node_type.type |= ContextNodeType::IMAGE; 188 node_type.type |= ContextNodeType::IMAGE;
181 } else if (!r.absoluteMediaURL().isEmpty()) { 189 } else if (!r.absoluteMediaURL().isEmpty()) {
182 src_url = r.absoluteMediaURL(); 190 src_url = r.absoluteMediaURL();
183 191
184 // We know that if absoluteMediaURL() is not empty, then this is a media 192 // We know that if absoluteMediaURL() is not empty, then this is a media
185 // element. 193 // element.
186 WebCore::HTMLMediaElement* media_element = 194 WebCore::HTMLMediaElement* media_element =
187 static_cast<WebCore::HTMLMediaElement*>(r.innerNonSharedNode()); 195 static_cast<WebCore::HTMLMediaElement*>(r.innerNonSharedNode());
188 if (media_element->hasTagName(WebCore::HTMLNames::videoTag)) { 196 if (media_element->hasTagName(WebCore::HTMLNames::videoTag)) {
189 node_type.type |= ContextNodeType::VIDEO; 197 node_type.type |= ContextNodeType::VIDEO;
190 } else if (media_element->hasTagName(WebCore::HTMLNames::audioTag)) { 198 } else if (media_element->hasTagName(WebCore::HTMLNames::audioTag)) {
191 node_type.type |= ContextNodeType::AUDIO; 199 node_type.type |= ContextNodeType::AUDIO;
192 } 200 }
193 201
194 media_params.playback_rate = media_element->playbackRate(); 202 media_params.playback_rate = media_element->playbackRate();
195 203
196 if (media_element->paused()) { 204 if (media_element->paused()) {
197 media_params.player_state |= ContextMenuMediaParams::PAUSED; 205 media_params.player_state |= ContextMenuMediaParams::PAUSED;
198 } 206 }
199 if (media_element->muted()) { 207 if (media_element->muted()) {
200 media_params.player_state |= ContextMenuMediaParams::MUTED; 208 media_params.player_state |= ContextMenuMediaParams::MUTED;
201 } 209 }
202 if (media_element->loop()) { 210 if (media_element->loop()) {
203 media_params.player_state |= ContextMenuMediaParams::LOOP; 211 media_params.player_state |= ContextMenuMediaParams::LOOP;
204 } 212 }
205 if (media_element->supportsSave()) { 213 if (media_element->supportsSave()) {
206 media_params.player_state |= ContextMenuMediaParams::CAN_SAVE; 214 media_params.player_state |= ContextMenuMediaParams::CAN_SAVE;
207 } 215 }
208 // TODO(ajwong): Report error states in the media player. 216 // TODO(ajwong): Report error states in the media player.
209 } 217 }
218 else {
219 //looks to see if the node we're clicking on contains a background image
220 //since the media inspection was done I figured we could
221 //apply that to the background image
222 WebCore::HTMLElement* gen_element =
223 static_cast<WebCore::HTMLElement*>(r.innerNonSharedNode());
224
225 //for now just take the inline style. The end solution will merge with the e lement in the css doc.
226 RefPtr<WebCore::CSSMutableStyleDeclaration> decl = gen_element->getInlineSty leDecl()->copy();
227 WebCore::CSSMutableStyleDeclarationConstIterator end = decl->end();
228
229 //this is a dumb loop in the sense that I'm just looking for any property th at
230 //supports an image value.
231 //
232 //Will need to make this better going forward
233 for(WebCore::CSSMutableStyleDeclarationConstIterator it = decl->begin(); it != end; ++it) {
234 const WebCore::CSSProperty& prop = *it;
235 WebCore::CSSValue* val = prop.value();
236
237 //wasn't sure the difference between isImageGeneratorValue or isImageValue
238 //appears isImageValue returns true for what we need, but I'm lumping the
239 //other in here for now.
240 if ((val->isImageGeneratorValue()) || (val->isImageValue())) {
241 WebCore::CSSImageValue* imgVal =
242 static_cast<WebCore::CSSImageValue*>(val);
243
244 //this is nice. well done.
245 bkg_url = webkit_glue::StringToGURL(imgVal->getStringValue());
246 }
247 }
248 }
210 249
211 // If it's not a link, an image, a media element, or an image/media link, 250 // If it's not a link, an image, a media element, or an image/media link,
212 // show a selection menu or a more generic page menu. 251 // show a selection menu or a more generic page menu.
213 std::wstring selection_text_string; 252 std::wstring selection_text_string;
214 std::wstring misspelled_word_string; 253 std::wstring misspelled_word_string;
215 GURL frame_url; 254 GURL frame_url;
216 GURL page_url; 255 GURL page_url;
217 std::string security_info; 256 std::string security_info;
218 257
219 std::string frame_charset = WideToASCII( 258 std::string frame_charset = WideToASCII(
220 webkit_glue::StringToStdWString(selected_frame->loader()->encoding())); 259 webkit_glue::StringToStdWString(selected_frame->loader()->encoding()));
260
261
221 // Send the frame and page URLs in any case. 262 // Send the frame and page URLs in any case.
222 ContextNodeType frame_node = ContextNodeType(ContextNodeType::NONE); 263 ContextNodeType frame_node = ContextNodeType(ContextNodeType::NONE);
223 ContextNodeType page_node = 264 ContextNodeType page_node =
224 GetTypeAndURLFromFrame(webview_->main_frame()->frame(), 265 GetTypeAndURLFromFrame(webview_->main_frame()->frame(),
225 &page_url, 266 &page_url,
226 ContextNodeType(ContextNodeType::PAGE)); 267 ContextNodeType(ContextNodeType::PAGE));
268
269
227 if (selected_frame != webview_->main_frame()->frame()) { 270 if (selected_frame != webview_->main_frame()->frame()) {
228 frame_node = 271 frame_node =
229 GetTypeAndURLFromFrame(selected_frame, 272 GetTypeAndURLFromFrame(selected_frame,
230 &frame_url, 273 &frame_url,
231 ContextNodeType(ContextNodeType::FRAME)); 274 ContextNodeType(ContextNodeType::FRAME));
232 } 275 }
233 276
234 if (r.isSelected()) { 277 if (r.isSelected()) {
235 node_type.type |= ContextNodeType::SELECTION; 278 node_type.type |= ContextNodeType::SELECTION;
236 selection_text_string = CollapseWhitespace( 279 selection_text_string = CollapseWhitespace(
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 WebViewDelegate* d = webview_->delegate(); 323 WebViewDelegate* d = webview_->delegate();
281 if (d) { 324 if (d) {
282 d->ShowContextMenu(webview_, 325 d->ShowContextMenu(webview_,
283 node_type, 326 node_type,
284 menu_point.x(), 327 menu_point.x(),
285 menu_point.y(), 328 menu_point.y(),
286 webkit_glue::KURLToGURL(link_url), 329 webkit_glue::KURLToGURL(link_url),
287 webkit_glue::KURLToGURL(src_url), 330 webkit_glue::KURLToGURL(src_url),
288 page_url, 331 page_url,
289 frame_url, 332 frame_url,
333 bkg_url,
290 media_params, 334 media_params,
291 selection_text_string, 335 selection_text_string,
292 misspelled_word_string, 336 misspelled_word_string,
293 edit_flags, 337 edit_flags,
294 security_info, 338 security_info,
295 frame_charset); 339 frame_charset);
296 } 340 }
297 return NULL; 341 return NULL;
298 } 342 }
299 343
(...skipping 20 matching lines...) Expand all
320 return false; 364 return false;
321 } 365 }
322 366
323 void ContextMenuClientImpl::stopSpeaking() { 367 void ContextMenuClientImpl::stopSpeaking() {
324 } 368 }
325 369
326 bool ContextMenuClientImpl::shouldIncludeInspectElementItem() { 370 bool ContextMenuClientImpl::shouldIncludeInspectElementItem() {
327 return false; // TODO(jackson): Eventually include the inspector context me nu item 371 return false; // TODO(jackson): Eventually include the inspector context me nu item
328 } 372 }
329 373
374
375
330 #if defined(OS_MACOSX) 376 #if defined(OS_MACOSX)
331 void ContextMenuClientImpl::searchWithSpotlight() { 377 void ContextMenuClientImpl::searchWithSpotlight() {
332 // TODO(pinkerton): write this 378 // TODO(pinkerton): write this
333 } 379 }
334 #endif 380 #endif
381
382
OLDNEW
« no previous file with comments | « webkit/glue/context_menu.h ('k') | webkit/glue/webview_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698