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

Side by Side Diff: Source/web/ContextMenuClientImpl.cpp

Issue 270613004: Implement "Copy image" for canvas (blink side). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 7 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2009, 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 // We can always select all... 210 // We can always select all...
211 data.editFlags |= WebContextMenuData::CanSelectAll; 211 data.editFlags |= WebContextMenuData::CanSelectAll;
212 data.editFlags |= WebContextMenuData::CanTranslate; 212 data.editFlags |= WebContextMenuData::CanTranslate;
213 213
214 // Links, Images, Media tags, and Image/Media-Links take preference over 214 // Links, Images, Media tags, and Image/Media-Links take preference over
215 // all else. 215 // all else.
216 data.linkURL = r.absoluteLinkURL(); 216 data.linkURL = r.absoluteLinkURL();
217 217
218 if (isHTMLCanvasElement(r.innerNonSharedNode())) { 218 if (isHTMLCanvasElement(r.innerNonSharedNode())) {
219 data.mediaType = WebContextMenuData::MediaTypeCanvas; 219 data.mediaType = WebContextMenuData::MediaTypeCanvas;
220 data.hasImageContents = true;
220 } else if (!r.absoluteImageURL().isEmpty()) { 221 } else if (!r.absoluteImageURL().isEmpty()) {
221 data.srcURL = r.absoluteImageURL(); 222 data.srcURL = r.absoluteImageURL();
222 data.mediaType = WebContextMenuData::MediaTypeImage; 223 data.mediaType = WebContextMenuData::MediaTypeImage;
223 data.mediaFlags |= WebContextMenuData::MediaCanPrint; 224 data.mediaFlags |= WebContextMenuData::MediaCanPrint;
225
226 // An image can to be null for many reasons, like being blocked, no imag e
227 // data received from server yet.
228 data.hasImageContents = r.image() && !(r.image()->isNull());
224 } else if (!r.absoluteMediaURL().isEmpty()) { 229 } else if (!r.absoluteMediaURL().isEmpty()) {
225 data.srcURL = r.absoluteMediaURL(); 230 data.srcURL = r.absoluteMediaURL();
226 231
227 // We know that if absoluteMediaURL() is not empty, then this 232 // We know that if absoluteMediaURL() is not empty, then this
228 // is a media element. 233 // is a media element.
229 HTMLMediaElement* mediaElement = toHTMLMediaElement(r.innerNonSharedNode ()); 234 HTMLMediaElement* mediaElement = toHTMLMediaElement(r.innerNonSharedNode ());
230 if (isHTMLVideoElement(*mediaElement)) 235 if (isHTMLVideoElement(*mediaElement))
231 data.mediaType = WebContextMenuData::MediaTypeVideo; 236 data.mediaType = WebContextMenuData::MediaTypeVideo;
232 else if (isHTMLAudioElement(*mediaElement)) 237 else if (isHTMLAudioElement(*mediaElement))
233 data.mediaType = WebContextMenuData::MediaTypeAudio; 238 data.mediaType = WebContextMenuData::MediaTypeAudio;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 data.srcURL = pluginElement->document().completeURL(pluginElemen t->url()); 278 data.srcURL = pluginElement->document().completeURL(pluginElemen t->url());
274 data.mediaFlags |= WebContextMenuData::MediaCanSave; 279 data.mediaFlags |= WebContextMenuData::MediaCanSave;
275 280
276 // Add context menu commands that are supported by the plugin. 281 // Add context menu commands that are supported by the plugin.
277 if (plugin->plugin()->canRotateView()) 282 if (plugin->plugin()->canRotateView())
278 data.mediaFlags |= WebContextMenuData::MediaCanRotate; 283 data.mediaFlags |= WebContextMenuData::MediaCanRotate;
279 } 284 }
280 } 285 }
281 } 286 }
282 287
283 // An image can to be null for many reasons, like being blocked, no image
284 // data received from server yet.
285 data.hasImageContents =
286 (data.mediaType == WebContextMenuData::MediaTypeImage)
287 && r.image() && !(r.image()->isNull());
288
289 // If it's not a link, an image, a media element, or an image/media link, 288 // If it's not a link, an image, a media element, or an image/media link,
290 // show a selection menu or a more generic page menu. 289 // show a selection menu or a more generic page menu.
291 if (selectedFrame->document()->loader()) 290 if (selectedFrame->document()->loader())
292 data.frameEncoding = selectedFrame->document()->encodingName(); 291 data.frameEncoding = selectedFrame->document()->encodingName();
293 292
294 // Send the frame and page URLs in any case. 293 // Send the frame and page URLs in any case.
295 data.pageURL = urlFromFrame(m_webView->mainFrameImpl()->frame()); 294 data.pageURL = urlFromFrame(m_webView->mainFrameImpl()->frame());
296 if (selectedFrame != m_webView->mainFrameImpl()->frame()) { 295 if (selectedFrame != m_webView->mainFrameImpl()->frame()) {
297 data.frameURL = urlFromFrame(selectedFrame); 296 data.frameURL = urlFromFrame(selectedFrame);
298 RefPtr<HistoryItem> historyItem = selectedFrame->loader().currentItem(); 297 RefPtr<HistoryItem> historyItem = selectedFrame->loader().currentItem();
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 outputItems[i] = subItems[i]; 418 outputItems[i] = subItems[i];
420 subMenuItems.swap(outputItems); 419 subMenuItems.swap(outputItems);
421 } 420 }
422 421
423 void ContextMenuClientImpl::populateCustomMenuItems(const WebCore::ContextMenu* defaultMenu, WebContextMenuData* data) 422 void ContextMenuClientImpl::populateCustomMenuItems(const WebCore::ContextMenu* defaultMenu, WebContextMenuData* data)
424 { 423 {
425 populateSubMenuItems(defaultMenu->items(), data->customItems); 424 populateSubMenuItems(defaultMenu->items(), data->customItems);
426 } 425 }
427 426
428 } // namespace blink 427 } // namespace blink
OLDNEW
« Source/core/editing/Editor.cpp ('K') | « Source/core/editing/Editor.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698