summaryrefslogtreecommitdiffstats
path: root/WebKit/chromium/src/ContextMenuClientImpl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebKit/chromium/src/ContextMenuClientImpl.cpp')
-rw-r--r--WebKit/chromium/src/ContextMenuClientImpl.cpp85
1 files changed, 53 insertions, 32 deletions
diff --git a/WebKit/chromium/src/ContextMenuClientImpl.cpp b/WebKit/chromium/src/ContextMenuClientImpl.cpp
index 8472082..d33a06b 100644
--- a/WebKit/chromium/src/ContextMenuClientImpl.cpp
+++ b/WebKit/chromium/src/ContextMenuClientImpl.cpp
@@ -46,6 +46,7 @@
#include "KURL.h"
#include "MediaError.h"
#include "PlatformString.h"
+#include "RenderWidget.h"
#include "TextBreakIterator.h"
#include "Widget.h"
@@ -53,6 +54,8 @@
#include "WebDataSourceImpl.h"
#include "WebFrameImpl.h"
#include "WebMenuItemInfo.h"
+#include "WebPlugin.h"
+#include "WebPluginContainerImpl.h"
#include "WebPoint.h"
#include "WebString.h"
#include "WebURL.h"
@@ -95,7 +98,7 @@ static bool isASingleWord(const String& text)
static String selectMisspelledWord(const ContextMenu* defaultMenu, Frame* selectedFrame)
{
// First select from selectedText to check for multiple word selection.
- String misspelledWord = selectedFrame->selectedText().stripWhiteSpace();
+ String misspelledWord = selectedFrame->editor()->selectedText().stripWhiteSpace();
// If some texts were already selected, we don't change the selection.
if (!misspelledWord.isEmpty()) {
@@ -116,7 +119,7 @@ static String selectMisspelledWord(const ContextMenu* defaultMenu, Frame* select
return misspelledWord; // It is empty.
WebFrameImpl::selectWordAroundPosition(selectedFrame, pos);
- misspelledWord = selectedFrame->selectedText().stripWhiteSpace();
+ misspelledWord = selectedFrame->editor()->selectedText().stripWhiteSpace();
#if OS(DARWIN)
// If misspelled word is still empty, then that portion should not be
@@ -147,13 +150,28 @@ PlatformMenuDescription ContextMenuClientImpl::getCustomMenuFromDefaultItems(
WebContextMenuData data;
data.mousePosition = selectedFrame->view()->contentsToWindow(r.point());
+ // Compute edit flags.
+ data.editFlags = WebContextMenuData::CanDoNone;
+ if (m_webView->focusedWebCoreFrame()->editor()->canUndo())
+ data.editFlags |= WebContextMenuData::CanUndo;
+ if (m_webView->focusedWebCoreFrame()->editor()->canRedo())
+ data.editFlags |= WebContextMenuData::CanRedo;
+ if (m_webView->focusedWebCoreFrame()->editor()->canCut())
+ data.editFlags |= WebContextMenuData::CanCut;
+ if (m_webView->focusedWebCoreFrame()->editor()->canCopy())
+ data.editFlags |= WebContextMenuData::CanCopy;
+ if (m_webView->focusedWebCoreFrame()->editor()->canPaste())
+ data.editFlags |= WebContextMenuData::CanPaste;
+ if (m_webView->focusedWebCoreFrame()->editor()->canDelete())
+ data.editFlags |= WebContextMenuData::CanDelete;
+ // We can always select all...
+ data.editFlags |= WebContextMenuData::CanSelectAll;
+ data.editFlags |= WebContextMenuData::CanTranslate;
+
// Links, Images, Media tags, and Image/Media-Links take preference over
// all else.
data.linkURL = r.absoluteLinkURL();
- data.mediaType = WebContextMenuData::MediaTypeNone;
- data.mediaFlags = WebContextMenuData::MediaNone;
-
if (!r.absoluteImageURL().isEmpty()) {
data.srcURL = r.absoluteImageURL();
data.mediaType = WebContextMenuData::MediaTypeImage;
@@ -181,10 +199,34 @@ PlatformMenuDescription ContextMenuClientImpl::getCustomMenuFromDefaultItems(
data.mediaFlags |= WebContextMenuData::MediaCanSave;
if (mediaElement->hasAudio())
data.mediaFlags |= WebContextMenuData::MediaHasAudio;
+ if (mediaElement->hasVideo())
+ data.mediaFlags |= WebContextMenuData::MediaHasVideo;
+ if (mediaElement->controls())
+ data.mediaFlags |= WebContextMenuData::MediaControls;
+ } else if (r.innerNonSharedNode()->hasTagName(HTMLNames::objectTag)
+ || r.innerNonSharedNode()->hasTagName(HTMLNames::embedTag)) {
+ RenderObject* object = r.innerNonSharedNode()->renderer();
+ if (object && object->isWidget()) {
+ Widget* widget = toRenderWidget(object)->widget();
+ if (widget && widget->isPluginContainer()) {
+ WebPluginContainerImpl* plugin = static_cast<WebPluginContainerImpl*>(widget);
+ WebString text = plugin->plugin()->selectionAsText();
+ if (!text.isEmpty()) {
+ data.selectedText = text;
+ data.editFlags |= WebContextMenuData::CanCopy;
+ }
+ data.editFlags &= ~WebContextMenuData::CanTranslate;
+ data.linkURL = plugin->plugin()->linkAtPosition(data.mousePosition);
+ }
+ }
}
+
+ data.isImageBlocked =
+ (data.mediaType == WebContextMenuData::MediaTypeImage) && !r.image();
+
// If it's not a link, an image, a media element, or an image/media link,
// show a selection menu or a more generic page menu.
- data.frameEncoding = selectedFrame->loader()->encoding();
+ data.frameEncoding = selectedFrame->loader()->writer()->encoding();
// Send the frame and page URLs in any case.
data.pageURL = urlFromFrame(m_webView->mainFrameImpl()->frame());
@@ -192,23 +234,19 @@ PlatformMenuDescription ContextMenuClientImpl::getCustomMenuFromDefaultItems(
data.frameURL = urlFromFrame(selectedFrame);
if (r.isSelected())
- data.selectedText = selectedFrame->selectedText().stripWhiteSpace();
+ data.selectedText = selectedFrame->editor()->selectedText().stripWhiteSpace();
- data.isEditable = false;
if (r.isContentEditable()) {
data.isEditable = true;
if (m_webView->focusedWebCoreFrame()->editor()->isContinuousSpellCheckingEnabled()) {
data.isSpellCheckingEnabled = true;
- data.misspelledWord = selectMisspelledWord(defaultMenu, selectedFrame);
+ // Spellchecking might be enabled for the field, but could be disabled on the node.
+ if (m_webView->focusedWebCoreFrame()->editor()->isSpellCheckingEnabledInFocusedNode())
+ data.misspelledWord = selectMisspelledWord(defaultMenu, selectedFrame);
}
}
#if OS(DARWIN)
- // Writing direction context menu.
- data.writingDirectionDefault = WebContextMenuData::CheckableMenuItemDisabled;
- data.writingDirectionLeftToRight = WebContextMenuData::CheckableMenuItemEnabled;
- data.writingDirectionRightToLeft = WebContextMenuData::CheckableMenuItemEnabled;
-
ExceptionCode ec = 0;
RefPtr<CSSStyleDeclaration> style = selectedFrame->document()->createCSSStyleDeclaration();
style->setProperty(CSSPropertyDirection, "ltr", false, ec);
@@ -225,23 +263,6 @@ PlatformMenuDescription ContextMenuClientImpl::getCustomMenuFromDefaultItems(
if (ds)
data.securityInfo = ds->response().securityInfo();
- // Compute edit flags.
- data.editFlags = WebContextMenuData::CanDoNone;
- if (m_webView->focusedWebCoreFrame()->editor()->canUndo())
- data.editFlags |= WebContextMenuData::CanUndo;
- if (m_webView->focusedWebCoreFrame()->editor()->canRedo())
- data.editFlags |= WebContextMenuData::CanRedo;
- if (m_webView->focusedWebCoreFrame()->editor()->canCut())
- data.editFlags |= WebContextMenuData::CanCut;
- if (m_webView->focusedWebCoreFrame()->editor()->canCopy())
- data.editFlags |= WebContextMenuData::CanCopy;
- if (m_webView->focusedWebCoreFrame()->editor()->canPaste())
- data.editFlags |= WebContextMenuData::CanPaste;
- if (m_webView->focusedWebCoreFrame()->editor()->canDelete())
- data.editFlags |= WebContextMenuData::CanDelete;
- // We can always select all...
- data.editFlags |= WebContextMenuData::CanSelectAll;
-
// Filter out custom menu elements and add them into the data.
populateCustomMenuItems(defaultMenu, &data);
@@ -257,7 +278,7 @@ void ContextMenuClientImpl::populateCustomMenuItems(WebCore::ContextMenu* defaul
Vector<WebMenuItemInfo> customItems;
for (size_t i = 0; i < defaultMenu->itemCount(); ++i) {
ContextMenuItem* inputItem = defaultMenu->itemAtIndex(i, defaultMenu->platformDescription());
- if (inputItem->action() < ContextMenuItemBaseCustomTag || inputItem->action() >= ContextMenuItemBaseApplicationTag)
+ if (inputItem->action() < ContextMenuItemBaseCustomTag || inputItem->action() > ContextMenuItemLastCustomTag)
continue;
WebMenuItemInfo outputItem;