OLD | NEW |
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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 if (!r.absoluteImageURL().isEmpty()) { | 218 if (!r.absoluteImageURL().isEmpty()) { |
219 data.srcURL = r.absoluteImageURL(); | 219 data.srcURL = r.absoluteImageURL(); |
220 data.mediaType = WebContextMenuData::MediaTypeImage; | 220 data.mediaType = WebContextMenuData::MediaTypeImage; |
221 data.mediaFlags |= WebContextMenuData::MediaCanPrint; | 221 data.mediaFlags |= WebContextMenuData::MediaCanPrint; |
222 } else if (!r.absoluteMediaURL().isEmpty()) { | 222 } else if (!r.absoluteMediaURL().isEmpty()) { |
223 data.srcURL = r.absoluteMediaURL(); | 223 data.srcURL = r.absoluteMediaURL(); |
224 | 224 |
225 // We know that if absoluteMediaURL() is not empty, then this | 225 // We know that if absoluteMediaURL() is not empty, then this |
226 // is a media element. | 226 // is a media element. |
227 HTMLMediaElement* mediaElement = toHTMLMediaElement(r.innerNonSharedNode
()); | 227 HTMLMediaElement* mediaElement = toHTMLMediaElement(r.innerNonSharedNode
()); |
228 if (mediaElement->hasTagName(HTMLNames::videoTag)) | 228 if (isHTMLVideoElement(*mediaElement)) |
229 data.mediaType = WebContextMenuData::MediaTypeVideo; | 229 data.mediaType = WebContextMenuData::MediaTypeVideo; |
230 else if (mediaElement->hasTagName(HTMLNames::audioTag)) | 230 else if (isHTMLAudioElement(*mediaElement)) |
231 data.mediaType = WebContextMenuData::MediaTypeAudio; | 231 data.mediaType = WebContextMenuData::MediaTypeAudio; |
232 | 232 |
233 if (mediaElement->error()) | 233 if (mediaElement->error()) |
234 data.mediaFlags |= WebContextMenuData::MediaInError; | 234 data.mediaFlags |= WebContextMenuData::MediaInError; |
235 if (mediaElement->paused()) | 235 if (mediaElement->paused()) |
236 data.mediaFlags |= WebContextMenuData::MediaPaused; | 236 data.mediaFlags |= WebContextMenuData::MediaPaused; |
237 if (mediaElement->muted()) | 237 if (mediaElement->muted()) |
238 data.mediaFlags |= WebContextMenuData::MediaMuted; | 238 data.mediaFlags |= WebContextMenuData::MediaMuted; |
239 if (mediaElement->loop()) | 239 if (mediaElement->loop()) |
240 data.mediaFlags |= WebContextMenuData::MediaLoop; | 240 data.mediaFlags |= WebContextMenuData::MediaLoop; |
241 if (mediaElement->supportsSave()) | 241 if (mediaElement->supportsSave()) |
242 data.mediaFlags |= WebContextMenuData::MediaCanSave; | 242 data.mediaFlags |= WebContextMenuData::MediaCanSave; |
243 if (mediaElement->hasAudio()) | 243 if (mediaElement->hasAudio()) |
244 data.mediaFlags |= WebContextMenuData::MediaHasAudio; | 244 data.mediaFlags |= WebContextMenuData::MediaHasAudio; |
245 if (mediaElement->hasVideo()) | 245 if (mediaElement->hasVideo()) |
246 data.mediaFlags |= WebContextMenuData::MediaHasVideo; | 246 data.mediaFlags |= WebContextMenuData::MediaHasVideo; |
247 if (mediaElement->controls()) | 247 if (mediaElement->controls()) |
248 data.mediaFlags |= WebContextMenuData::MediaControls; | 248 data.mediaFlags |= WebContextMenuData::MediaControls; |
249 } else if (r.innerNonSharedNode()->hasTagName(HTMLNames::objectTag) | 249 } else if (isHTMLObjectElement(*r.innerNonSharedNode()) || isHTMLEmbedElemen
t(*r.innerNonSharedNode())) { |
250 || r.innerNonSharedNode()->hasTagName(HTMLNames::embedTag)) { | |
251 RenderObject* object = r.innerNonSharedNode()->renderer(); | 250 RenderObject* object = r.innerNonSharedNode()->renderer(); |
252 if (object && object->isWidget()) { | 251 if (object && object->isWidget()) { |
253 Widget* widget = toRenderWidget(object)->widget(); | 252 Widget* widget = toRenderWidget(object)->widget(); |
254 if (widget && widget->isPluginContainer()) { | 253 if (widget && widget->isPluginContainer()) { |
255 data.mediaType = WebContextMenuData::MediaTypePlugin; | 254 data.mediaType = WebContextMenuData::MediaTypePlugin; |
256 WebPluginContainerImpl* plugin = toWebPluginContainerImpl(widget
); | 255 WebPluginContainerImpl* plugin = toWebPluginContainerImpl(widget
); |
257 WebString text = plugin->plugin()->selectionAsText(); | 256 WebString text = plugin->plugin()->selectionAsText(); |
258 if (!text.isEmpty()) { | 257 if (!text.isEmpty()) { |
259 data.selectedText = text; | 258 data.selectedText = text; |
260 data.editFlags |= WebContextMenuData::CanCopy; | 259 data.editFlags |= WebContextMenuData::CanCopy; |
(...skipping 28 matching lines...) Expand all Loading... |
289 // Send the frame and page URLs in any case. | 288 // Send the frame and page URLs in any case. |
290 data.pageURL = urlFromFrame(m_webView->mainFrameImpl()->frame()); | 289 data.pageURL = urlFromFrame(m_webView->mainFrameImpl()->frame()); |
291 if (selectedFrame != m_webView->mainFrameImpl()->frame()) { | 290 if (selectedFrame != m_webView->mainFrameImpl()->frame()) { |
292 data.frameURL = urlFromFrame(selectedFrame); | 291 data.frameURL = urlFromFrame(selectedFrame); |
293 RefPtr<HistoryItem> historyItem = selectedFrame->loader().currentItem(); | 292 RefPtr<HistoryItem> historyItem = selectedFrame->loader().currentItem(); |
294 if (historyItem) | 293 if (historyItem) |
295 data.frameHistoryItem = WebHistoryItem(historyItem); | 294 data.frameHistoryItem = WebHistoryItem(historyItem); |
296 } | 295 } |
297 | 296 |
298 if (r.isSelected()) { | 297 if (r.isSelected()) { |
299 if (!r.innerNonSharedNode()->hasTagName(HTMLNames::inputTag) || !toHTMLI
nputElement(r.innerNonSharedNode())->isPasswordField()) | 298 if (!isHTMLInputElement(*r.innerNonSharedNode()) || !toHTMLInputElement(
r.innerNonSharedNode())->isPasswordField()) |
300 data.selectedText = selectedFrame->selectedText().stripWhiteSpace(); | 299 data.selectedText = selectedFrame->selectedText().stripWhiteSpace(); |
301 } | 300 } |
302 | 301 |
303 if (r.isContentEditable()) { | 302 if (r.isContentEditable()) { |
304 data.isEditable = true; | 303 data.isEditable = true; |
305 #if ENABLE(INPUT_SPEECH) | 304 #if ENABLE(INPUT_SPEECH) |
306 if (r.innerNonSharedNode()->hasTagName(HTMLNames::inputTag)) | 305 if (isHTMLInputElement(*r.innerNonSharedNode())) |
307 data.isSpeechInputEnabled = toHTMLInputElement(r.innerNonSharedNode(
))->isSpeechEnabled(); | 306 data.isSpeechInputEnabled = toHTMLInputElement(r.innerNonSharedNode(
))->isSpeechEnabled(); |
308 #endif | 307 #endif |
309 // When Chrome enables asynchronous spellchecking, its spellchecker adds
spelling markers to misspelled | 308 // When Chrome enables asynchronous spellchecking, its spellchecker adds
spelling markers to misspelled |
310 // words and attaches suggestions to these markers in the background. Th
erefore, when a user right-clicks | 309 // words and attaches suggestions to these markers in the background. Th
erefore, when a user right-clicks |
311 // a mouse on a word, Chrome just needs to find a spelling marker on the
word instead of spellchecking it. | 310 // a mouse on a word, Chrome just needs to find a spelling marker on the
word instead of spellchecking it. |
312 if (selectedFrame->settings() && selectedFrame->settings()->asynchronous
SpellCheckingEnabled()) { | 311 if (selectedFrame->settings() && selectedFrame->settings()->asynchronous
SpellCheckingEnabled()) { |
313 DocumentMarker marker; | 312 DocumentMarker marker; |
314 data.misspelledWord = selectMisspellingAsync(selectedFrame, marker); | 313 data.misspelledWord = selectMisspellingAsync(selectedFrame, marker); |
315 data.misspellingHash = marker.hash(); | 314 data.misspellingHash = marker.hash(); |
316 if (marker.description().length()) { | 315 if (marker.description().length()) { |
(...skipping 14 matching lines...) Expand all Loading... |
331 int misspelledOffset, misspelledLength; | 330 int misspelledOffset, misspelledLength; |
332 m_webView->spellCheckClient()->spellCheck( | 331 m_webView->spellCheckClient()->spellCheck( |
333 data.misspelledWord, misspelledOffset, misspelledLength, | 332 data.misspelledWord, misspelledOffset, misspelledLength, |
334 &data.dictionarySuggestions); | 333 &data.dictionarySuggestions); |
335 if (!misspelledLength) | 334 if (!misspelledLength) |
336 data.misspelledWord.reset(); | 335 data.misspelledWord.reset(); |
337 } | 336 } |
338 } | 337 } |
339 } | 338 } |
340 HTMLFormElement* form = selectedFrame->selection().currentForm(); | 339 HTMLFormElement* form = selectedFrame->selection().currentForm(); |
341 if (form && r.innerNonSharedNode()->hasTagName(HTMLNames::inputTag)) { | 340 if (form && isHTMLInputElement(*r.innerNonSharedNode())) { |
342 HTMLInputElement* selectedElement = toHTMLInputElement(r.innerNonSha
redNode()); | 341 HTMLInputElement& selectedElement = toHTMLInputElement(*r.innerNonSh
aredNode()); |
343 if (selectedElement) { | 342 WebSearchableFormData ws = WebSearchableFormData(WebFormElement(form
), WebInputElement(&selectedElement)); |
344 WebSearchableFormData ws = WebSearchableFormData(WebFormElement(
form), WebInputElement(selectedElement)); | 343 if (ws.url().isValid()) |
345 if (ws.url().isValid()) | 344 data.keywordURL = ws.url(); |
346 data.keywordURL = ws.url(); | |
347 } | |
348 } | 345 } |
349 } | 346 } |
350 | 347 |
351 if (selectedFrame->editor().selectionHasStyle(CSSPropertyDirection, "ltr") !
= FalseTriState) | 348 if (selectedFrame->editor().selectionHasStyle(CSSPropertyDirection, "ltr") !
= FalseTriState) |
352 data.writingDirectionLeftToRight |= WebContextMenuData::CheckableMenuIte
mChecked; | 349 data.writingDirectionLeftToRight |= WebContextMenuData::CheckableMenuIte
mChecked; |
353 if (selectedFrame->editor().selectionHasStyle(CSSPropertyDirection, "rtl") !
= FalseTriState) | 350 if (selectedFrame->editor().selectionHasStyle(CSSPropertyDirection, "rtl") !
= FalseTriState) |
354 data.writingDirectionRightToLeft |= WebContextMenuData::CheckableMenuIte
mChecked; | 351 data.writingDirectionRightToLeft |= WebContextMenuData::CheckableMenuIte
mChecked; |
355 | 352 |
356 // Now retrieve the security info. | 353 // Now retrieve the security info. |
357 DocumentLoader* dl = selectedFrame->loader().documentLoader(); | 354 DocumentLoader* dl = selectedFrame->loader().documentLoader(); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 outputItems[i] = subItems[i]; | 416 outputItems[i] = subItems[i]; |
420 subMenuItems.swap(outputItems); | 417 subMenuItems.swap(outputItems); |
421 } | 418 } |
422 | 419 |
423 void ContextMenuClientImpl::populateCustomMenuItems(const WebCore::ContextMenu*
defaultMenu, WebContextMenuData* data) | 420 void ContextMenuClientImpl::populateCustomMenuItems(const WebCore::ContextMenu*
defaultMenu, WebContextMenuData* data) |
424 { | 421 { |
425 populateSubMenuItems(defaultMenu->items(), data->customItems); | 422 populateSubMenuItems(defaultMenu->items(), data->customItems); |
426 } | 423 } |
427 | 424 |
428 } // namespace blink | 425 } // namespace blink |
OLD | NEW |