summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authoryaar@chromium.org <yaar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-22 20:51:55 +0000
committeryaar@chromium.org <yaar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-22 20:51:55 +0000
commit14e66f1c33488f4683337b5424170d2a27c98c07 (patch)
tree37f9790e92a9a6348c44a6e8af312d9acdc3cd6f /webkit
parentd7907b48ead5556706846120288a4d1f9ff73dd2 (diff)
downloadchromium_src-14e66f1c33488f4683337b5424170d2a27c98c07.zip
chromium_src-14e66f1c33488f4683337b5424170d2a27c98c07.tar.gz
chromium_src-14e66f1c33488f4683337b5424170d2a27c98c07.tar.bz2
Move ContextMenuClientImpl to api/src
ISSUE: http://code.google.com/p/chromium/issues/detail?id=24611 Review URL: http://codereview.chromium.org/295054 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29814 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/api/src/WebContextMenuClientImpl.cpp240
-rw-r--r--webkit/api/src/WebContextMenuClientImpl.h61
-rw-r--r--webkit/glue/context_menu_client_impl.cc295
-rw-r--r--webkit/glue/context_menu_client_impl.h39
-rw-r--r--webkit/glue/webview_impl.h5
-rw-r--r--webkit/webkit.gyp4
6 files changed, 306 insertions, 338 deletions
diff --git a/webkit/api/src/WebContextMenuClientImpl.cpp b/webkit/api/src/WebContextMenuClientImpl.cpp
new file mode 100644
index 0000000..e8c36c3
--- /dev/null
+++ b/webkit/api/src/WebContextMenuClientImpl.cpp
@@ -0,0 +1,240 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebContextMenuClientImpl.h"
+
+#include "ContextMenu.h"
+#include "Document.h"
+#include "DocumentLoader.h"
+#include "Editor.h"
+#include "EventHandler.h"
+#include "FrameLoader.h"
+#include "FrameView.h"
+#include "HitTestResult.h"
+#include "HTMLMediaElement.h"
+#include "HTMLNames.h"
+#include "KURL.h"
+#include "MediaError.h"
+#include "PlatformString.h"
+#include "TextBreakIterator.h"
+#include "Widget.h"
+
+#include "WebContextMenuData.h"
+#include "WebFrame.h"
+#include "WebPoint.h"
+#include "WebString.h"
+#include "WebURL.h"
+#include "WebURLResponse.h"
+#include "WebViewClient.h"
+#include "WebDataSourceImpl.h"
+#undef LOG
+
+// FIXME: Temporary hack until WebViewImpl is in api/src.
+#include "webkit/glue/webview_impl.h"
+
+using namespace WebCore;
+
+namespace WebKit {
+
+// Figure out the URL of a page or subframe. Returns |page_type| as the type,
+// which indicates page or subframe, or ContextNodeType::NONE if the URL could not
+// be determined for some reason.
+static WebURL urlFromFrame(Frame* frame)
+{
+ if (frame) {
+ DocumentLoader* dl = frame->loader()->documentLoader();
+ if (dl) {
+ WebDataSource* ds = WebDataSourceImpl::fromDocumentLoader(dl);
+ if (ds)
+ return ds->hasUnreachableURL() ? ds->unreachableURL() : ds->request().url();
+ }
+ }
+ return WebURL();
+}
+
+// Helper function to determine whether text is a single word or a sentence.
+static bool isASingleWord(const String& text)
+{
+ TextBreakIterator* it = characterBreakIterator(text.characters(), text.length());
+ return it && textBreakNext(it) == TextBreakDone;
+}
+
+// Helper function to get misspelled word on which context menu
+// is to be evolked. This function also sets the word on which context menu
+// has been evoked to be the selected word, as required. This function changes
+// the selection only when there were no selected characters.
+static String selectMisspelledWord(const ContextMenu* defaultMenu, Frame* selectedFrame)
+{
+ // First select from selectedText to check for multiple word selection.
+ String misspelledWord = selectedFrame->selectedText().stripWhiteSpace();
+
+ // If some texts were already selected, we don't change the selection.
+ if (!misspelledWord.isEmpty()) {
+ // Don't provide suggestions for multiple words.
+ if (!isASingleWord(misspelledWord))
+ return String();
+ return misspelledWord;
+ }
+
+ // Selection is empty, so change the selection to the word under the cursor.
+ HitTestResult hitTestResult = selectedFrame->eventHandler()->
+ hitTestResultAtPoint(defaultMenu->hitTestResult().point(), true);
+ Node* innerNode = hitTestResult.innerNode();
+ VisiblePosition pos(innerNode->renderer()->positionForPoint(
+ hitTestResult.localPoint()));
+
+ VisibleSelection selection;
+ if (pos.isNotNull()) {
+ selection = VisibleSelection(pos);
+ selection.expandUsingGranularity(WordGranularity);
+ }
+
+ if (selection.isRange())
+ selectedFrame->setSelectionGranularity(WordGranularity);
+
+ if (selectedFrame->shouldChangeSelection(selection))
+ selectedFrame->selection()->setSelection(selection);
+
+ misspelledWord = selectedFrame->selectedText().stripWhiteSpace();
+
+ // If misspelled word is still empty, then that portion should not be
+ // selected. Set the selection to that position only, and do not expand.
+ if (misspelledWord.isEmpty()) {
+ selection = VisibleSelection(pos);
+ selectedFrame->selection()->setSelection(selection);
+ }
+
+ return misspelledWord;
+}
+
+PlatformMenuDescription WebContextMenuClientImpl::getCustomMenuFromDefaultItems(
+ ContextMenu* defaultMenu)
+{
+ // Displaying the context menu in this function is a big hack as we don't
+ // have context, i.e. whether this is being invoked via a script or in
+ // response to user input (Mouse event WM_RBUTTONDOWN,
+ // Keyboard events KeyVK_APPS, Shift+F10). Check if this is being invoked
+ // in response to the above input events before popping up the context menu.
+ if (!m_webView->context_menu_allowed())
+ return 0;
+
+ HitTestResult r = defaultMenu->hitTestResult();
+ Frame* selectedFrame = r.innerNonSharedNode()->document()->frame();
+
+ WebContextMenuData data;
+ data.mousePosition = selectedFrame->view()->contentsToWindow(r.point());
+
+ // Links, Images, Media tags, and Image/Media-Links take preference over
+ // all else.
+ data.linkURL = r.absoluteLinkURL();
+
+ data.mediaType = WebContextMenuData::MediaTypeNone;
+
+ if (!r.absoluteImageURL().isEmpty()) {
+ data.srcURL = r.absoluteImageURL();
+ data.mediaType = WebContextMenuData::MediaTypeImage;
+ } else if (!r.absoluteMediaURL().isEmpty()) {
+ data.srcURL = r.absoluteMediaURL();
+
+ // We know that if absoluteMediaURL() is not empty, then this
+ // is a media element.
+ HTMLMediaElement* mediaElement =
+ static_cast<HTMLMediaElement*>(r.innerNonSharedNode());
+ if (mediaElement->hasTagName(HTMLNames::videoTag))
+ data.mediaType = WebContextMenuData::MediaTypeVideo;
+ else if (mediaElement->hasTagName(HTMLNames::audioTag))
+ data.mediaType = WebContextMenuData::MediaTypeAudio;
+
+ if (mediaElement->error())
+ data.mediaFlags |= WebContextMenuData::MediaInError;
+ if (mediaElement->paused())
+ data.mediaFlags |= WebContextMenuData::MediaPaused;
+ if (mediaElement->muted())
+ data.mediaFlags |= WebContextMenuData::MediaMuted;
+ if (mediaElement->loop())
+ data.mediaFlags |= WebContextMenuData::MediaLoop;
+ if (mediaElement->supportsSave())
+ data.mediaFlags |= WebContextMenuData::MediaCanSave;
+ if (mediaElement->hasAudio())
+ data.mediaFlags |= WebContextMenuData::MediaHasAudio;
+ }
+ // 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();
+
+ // Send the frame and page URLs in any case.
+ data.pageURL = urlFromFrame(m_webView->main_frame()->frame());
+ if (selectedFrame != m_webView->main_frame()->frame())
+ data.frameURL = urlFromFrame(selectedFrame);
+
+ if (r.isSelected())
+ data.selectedText = selectedFrame->selectedText().stripWhiteSpace();
+
+ data.isEditable = false;
+ if (r.isContentEditable()) {
+ data.isEditable = true;
+ if (m_webView->GetFocusedWebCoreFrame()->editor()->isContinuousSpellCheckingEnabled()) {
+ data.isSpellCheckingEnabled = true;
+ data.misspelledWord = selectMisspelledWord(defaultMenu, selectedFrame);
+ }
+ }
+
+ // Now retrieve the security info.
+ DocumentLoader* dl = selectedFrame->loader()->documentLoader();
+ WebDataSource* ds = WebDataSourceImpl::fromDocumentLoader(dl);
+ if (ds)
+ data.securityInfo = ds->response().securityInfo();
+
+ // Compute edit flags.
+ data.editFlags = WebContextMenuData::CanDoNone;
+ if (m_webView->GetFocusedWebCoreFrame()->editor()->canUndo())
+ data.editFlags |= WebContextMenuData::CanUndo;
+ if (m_webView->GetFocusedWebCoreFrame()->editor()->canRedo())
+ data.editFlags |= WebContextMenuData::CanRedo;
+ if (m_webView->GetFocusedWebCoreFrame()->editor()->canCut())
+ data.editFlags |= WebContextMenuData::CanCut;
+ if (m_webView->GetFocusedWebCoreFrame()->editor()->canCopy())
+ data.editFlags |= WebContextMenuData::CanCopy;
+ if (m_webView->GetFocusedWebCoreFrame()->editor()->canPaste())
+ data.editFlags |= WebContextMenuData::CanPaste;
+ if (m_webView->GetFocusedWebCoreFrame()->editor()->canDelete())
+ data.editFlags |= WebContextMenuData::CanDelete;
+ // We can always select all...
+ data.editFlags |= WebContextMenuData::CanSelectAll;
+
+ WebFrame* selected_web_frame = WebFrameImpl::FromFrame(selectedFrame);
+ if (m_webView->client())
+ m_webView->client()->showContextMenu(selected_web_frame, data);
+
+ return 0;
+}
+
+} // namespace WebKit
diff --git a/webkit/api/src/WebContextMenuClientImpl.h b/webkit/api/src/WebContextMenuClientImpl.h
new file mode 100644
index 0000000..bf14ae8
--- /dev/null
+++ b/webkit/api/src/WebContextMenuClientImpl.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebContextMenuClientImpl_h
+#define WebContextMenuClientImpl_h
+
+#include "ContextMenuClient.h"
+
+class WebViewImpl;
+
+namespace WebKit {
+
+ class WebContextMenuClientImpl : public WebCore::ContextMenuClient {
+ public:
+ WebContextMenuClientImpl(WebViewImpl* webView) : m_webView(webView) {}
+ virtual ~WebContextMenuClientImpl() {}
+ virtual void copyImageToClipboard(const WebCore::HitTestResult&) {}
+ virtual void contextMenuDestroyed() {}
+ virtual void contextMenuItemSelected(WebCore::ContextMenuItem*, const WebCore::ContextMenu*) {}
+ virtual void downloadURL(const WebCore::KURL&) {}
+ virtual WebCore::PlatformMenuDescription getCustomMenuFromDefaultItems(WebCore::ContextMenu*);
+ virtual bool isSpeaking() { return false; }
+ virtual void lookUpInDictionary(WebCore::Frame*) {}
+ virtual void searchWithGoogle(const WebCore::Frame*) {}
+ virtual bool shouldIncludeInspectElementItem() { return false; }
+ virtual void speak(const WebCore::String&) {}
+ virtual void stopSpeaking() {}
+ private:
+ WebViewImpl* m_webView;
+ };
+
+} // namespace WebKit
+
+#endif // WebContextMenuClientImpl_h
diff --git a/webkit/glue/context_menu_client_impl.cc b/webkit/glue/context_menu_client_impl.cc
deleted file mode 100644
index 15187fe..0000000
--- a/webkit/glue/context_menu_client_impl.cc
+++ /dev/null
@@ -1,295 +0,0 @@
-// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "config.h"
-
-#include "ContextMenu.h"
-#include "Document.h"
-#include "DocumentLoader.h"
-#include "Editor.h"
-#include "EventHandler.h"
-#include "FrameLoader.h"
-#include "FrameView.h"
-#include "HitTestResult.h"
-#include "HTMLMediaElement.h"
-#include "HTMLNames.h"
-#include "KURL.h"
-#include "MediaError.h"
-#include "PlatformString.h"
-#include "Widget.h"
-#undef LOG
-
-#include "base/i18n/word_iterator.h"
-#include "base/string_util.h"
-#include "webkit/api/public/WebContextMenuData.h"
-#include "webkit/api/public/WebFrame.h"
-#include "webkit/api/public/WebPoint.h"
-#include "webkit/api/public/WebString.h"
-#include "webkit/api/public/WebURL.h"
-#include "webkit/api/public/WebURLResponse.h"
-#include "webkit/api/public/WebViewClient.h"
-#include "webkit/api/src/WebDataSourceImpl.h"
-#include "webkit/glue/context_menu.h"
-#include "webkit/glue/context_menu_client_impl.h"
-#include "webkit/glue/glue_util.h"
-#include "webkit/glue/webview_impl.h"
-
-using WebKit::WebContextMenuData;
-using WebKit::WebDataSource;
-using WebKit::WebDataSourceImpl;
-using WebKit::WebFrame;
-using WebKit::WebPoint;
-using WebKit::WebString;
-using WebKit::WebURL;
-
-namespace {
-// Helper function to determine whether text is a single word or a sentence.
-bool IsASingleWord(const std::wstring& text) {
- WordIterator iter(text, WordIterator::BREAK_WORD);
- int word_count = 0;
- if (!iter.Init()) return false;
- while (iter.Advance()) {
- if (iter.IsWord()) {
- word_count++;
- if (word_count > 1) // More than one word.
- return false;
- }
- }
-
- // Check for 0 words.
- if (!word_count)
- return false;
-
- // Has a single word.
- return true;
-}
-
-// Helper function to get misspelled word on which context menu
-// is to be evolked. This function also sets the word on which context menu
-// has been evoked to be the selected word, as required. This function changes
-// the selection only when there were no selected characters.
-std::wstring GetMisspelledWord(const WebCore::ContextMenu* default_menu,
- WebCore::Frame* selected_frame) {
- std::wstring misspelled_word_string;
-
- // First select from selectedText to check for multiple word selection.
- misspelled_word_string = CollapseWhitespace(
- webkit_glue::StringToStdWString(selected_frame->selectedText()),
- false);
-
- // If some texts were already selected, we don't change the selection.
- if (!misspelled_word_string.empty()) {
- // Don't provide suggestions for multiple words.
- if (!IsASingleWord(misspelled_word_string))
- return L"";
- return misspelled_word_string;
- }
-
- WebCore::HitTestResult hit_test_result = selected_frame->eventHandler()->
- hitTestResultAtPoint(default_menu->hitTestResult().point(), true);
- WebCore::Node* inner_node = hit_test_result.innerNode();
- WebCore::VisiblePosition pos(inner_node->renderer()->positionForPoint(
- hit_test_result.localPoint()));
-
- WebCore::VisibleSelection selection;
- if (pos.isNotNull()) {
- selection = WebCore::VisibleSelection(pos);
- selection.expandUsingGranularity(WebCore::WordGranularity);
- }
-
- if (selection.isRange()) {
- selected_frame->setSelectionGranularity(WebCore::WordGranularity);
- }
-
- if (selected_frame->shouldChangeSelection(selection))
- selected_frame->selection()->setSelection(selection);
-
- misspelled_word_string = CollapseWhitespace(
- webkit_glue::StringToStdWString(selected_frame->selectedText()),
- false);
-
- // If misspelled word is empty, then that portion should not be selected.
- // Set the selection to that position only, and do not expand.
- if (misspelled_word_string.empty()) {
- selection = WebCore::VisibleSelection(pos);
- selected_frame->selection()->setSelection(selection);
- }
-
- return misspelled_word_string;
-}
-
-} // namespace
-
-ContextMenuClientImpl::~ContextMenuClientImpl() {
-}
-
-void ContextMenuClientImpl::contextMenuDestroyed() {
- // Our lifetime is bound to the WebViewImpl.
-}
-
-// Figure out the URL of a page or subframe. Returns |page_type| as the type,
-// which indicates page or subframe, or ContextNodeType::NONE if the URL could not
-// be determined for some reason.
-static WebURL GetURLFromFrame(WebCore::Frame* frame) {
- if (frame) {
- WebCore::DocumentLoader* dl = frame->loader()->documentLoader();
- if (dl) {
- WebDataSource* ds = WebDataSourceImpl::fromDocumentLoader(dl);
- if (ds) {
- return ds->hasUnreachableURL() ? ds->unreachableURL()
- : ds->request().url();
- }
- }
- }
- return WebURL();
-}
-
-WebCore::PlatformMenuDescription
- ContextMenuClientImpl::getCustomMenuFromDefaultItems(
- WebCore::ContextMenu* default_menu) {
- // Displaying the context menu in this function is a big hack as we don't
- // have context, i.e. whether this is being invoked via a script or in
- // response to user input (Mouse event WM_RBUTTONDOWN,
- // Keyboard events KeyVK_APPS, Shift+F10). Check if this is being invoked
- // in response to the above input events before popping up the context menu.
- if (!webview_->context_menu_allowed())
- return NULL;
-
- WebCore::HitTestResult r = default_menu->hitTestResult();
- WebCore::Frame* selected_frame = r.innerNonSharedNode()->document()->frame();
-
- WebContextMenuData data;
- WebCore::IntPoint mouse_position = selected_frame->view()->contentsToWindow(
- r.point());
- data.mousePosition = webkit_glue::IntPointToWebPoint(mouse_position);
-
- // Links, Images, Media tags, and Image/Media-Links take preference over
- // all else.
- data.linkURL = webkit_glue::KURLToWebURL(r.absoluteLinkURL());
-
- data.mediaType = WebContextMenuData::MediaTypeNone;
-
- if (!r.absoluteImageURL().isEmpty()) {
- data.srcURL = webkit_glue::KURLToWebURL(r.absoluteImageURL());
- data.mediaType = WebContextMenuData::MediaTypeImage;
- } else if (!r.absoluteMediaURL().isEmpty()) {
- data.srcURL = webkit_glue::KURLToWebURL(r.absoluteMediaURL());
-
- // We know that if absoluteMediaURL() is not empty, then this is a media
- // element.
- WebCore::HTMLMediaElement* media_element =
- static_cast<WebCore::HTMLMediaElement*>(r.innerNonSharedNode());
- if (media_element->hasTagName(WebCore::HTMLNames::videoTag)) {
- data.mediaType = WebContextMenuData::MediaTypeVideo;
- } else if (media_element->hasTagName(WebCore::HTMLNames::audioTag)) {
- data.mediaType = WebContextMenuData::MediaTypeAudio;
- }
-
- if (media_element->error()) {
- data.mediaFlags |= WebContextMenuData::MediaInError;
- }
- if (media_element->paused()) {
- data.mediaFlags |= WebContextMenuData::MediaPaused;
- }
- if (media_element->muted()) {
- data.mediaFlags |= WebContextMenuData::MediaMuted;
- }
- if (media_element->loop()) {
- data.mediaFlags |= WebContextMenuData::MediaLoop;
- }
- if (media_element->supportsSave()) {
- data.mediaFlags |= WebContextMenuData::MediaCanSave;
- }
- if (media_element->hasAudio()) {
- data.mediaFlags |= WebContextMenuData::MediaHasAudio;
- }
- }
- // 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 = webkit_glue::StringToWebString(
- selected_frame->loader()->encoding());
-
- // Send the frame and page URLs in any case.
- data.pageURL = GetURLFromFrame(webview_->main_frame()->frame());
- if (selected_frame != webview_->main_frame()->frame()) {
- data.frameURL = GetURLFromFrame(selected_frame);
- }
-
- if (r.isSelected()) {
- data.selectedText = WideToUTF16Hack(CollapseWhitespace(
- webkit_glue::StringToStdWString(selected_frame->selectedText()),
- false));
- }
-
- data.isEditable = false;
- if (r.isContentEditable()) {
- data.isEditable = true;
- if (webview_->GetFocusedWebCoreFrame()->editor()->
- isContinuousSpellCheckingEnabled()) {
- data.isSpellCheckingEnabled = true;
- // TODO: GetMisspelledWord should move downstream to RenderView.
- data.misspelledWord = WideToUTF16Hack(
- GetMisspelledWord(default_menu, selected_frame));
- }
- }
-
- // Now retrieve the security info.
- WebCore::DocumentLoader* dl = selected_frame->loader()->documentLoader();
- WebDataSource* ds = WebDataSourceImpl::fromDocumentLoader(dl);
- if (ds)
- data.securityInfo = ds->response().securityInfo();
-
- // Compute edit flags.
- data.editFlags = WebContextMenuData::CanDoNone;
- if (webview_->GetFocusedWebCoreFrame()->editor()->canUndo())
- data.editFlags |= WebContextMenuData::CanUndo;
- if (webview_->GetFocusedWebCoreFrame()->editor()->canRedo())
- data.editFlags |= WebContextMenuData::CanRedo;
- if (webview_->GetFocusedWebCoreFrame()->editor()->canCut())
- data.editFlags |= WebContextMenuData::CanCut;
- if (webview_->GetFocusedWebCoreFrame()->editor()->canCopy())
- data.editFlags |= WebContextMenuData::CanCopy;
- if (webview_->GetFocusedWebCoreFrame()->editor()->canPaste())
- data.editFlags |= WebContextMenuData::CanPaste;
- if (webview_->GetFocusedWebCoreFrame()->editor()->canDelete())
- data.editFlags |= WebContextMenuData::CanDelete;
- // We can always select all...
- data.editFlags |= WebContextMenuData::CanSelectAll;
-
- WebFrame* selected_web_frame = WebFrameImpl::FromFrame(selected_frame);
- if (webview_->client())
- webview_->client()->showContextMenu(selected_web_frame, data);
-
- return NULL;
-}
-
-void ContextMenuClientImpl::contextMenuItemSelected(
- WebCore::ContextMenuItem*, const WebCore::ContextMenu*) {
-}
-
-void ContextMenuClientImpl::downloadURL(const WebCore::KURL&) {
-}
-
-void ContextMenuClientImpl::copyImageToClipboard(const WebCore::HitTestResult&) {
-}
-
-void ContextMenuClientImpl::searchWithGoogle(const WebCore::Frame*) {
-}
-
-void ContextMenuClientImpl::lookUpInDictionary(WebCore::Frame*) {
-}
-
-void ContextMenuClientImpl::speak(const WebCore::String&) {
-}
-
-bool ContextMenuClientImpl::isSpeaking() {
- return false;
-}
-
-void ContextMenuClientImpl::stopSpeaking() {
-}
-
-bool ContextMenuClientImpl::shouldIncludeInspectElementItem() {
- return false;
-}
diff --git a/webkit/glue/context_menu_client_impl.h b/webkit/glue/context_menu_client_impl.h
deleted file mode 100644
index 00d373b..0000000
--- a/webkit/glue/context_menu_client_impl.h
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef WEBKIT_GLUE_CONTEXT_MENU_CLIENT_IMPL_H_
-#define WEBKIT_GLUE_CONTEXT_MENU_CLIENT_IMPL_H_
-
-#include "ContextMenuClient.h"
-
-class WebViewImpl;
-
-// Handles window-level notifications from WebCore on behalf of a WebView.
-class ContextMenuClientImpl : public WebCore::ContextMenuClient {
- public:
- ContextMenuClientImpl(WebViewImpl* webview) : webview_(webview) {
- }
-
- virtual ~ContextMenuClientImpl();
- virtual void contextMenuDestroyed();
-
- virtual WebCore::PlatformMenuDescription getCustomMenuFromDefaultItems(
- WebCore::ContextMenu*);
- virtual void contextMenuItemSelected(WebCore::ContextMenuItem*,
- const WebCore::ContextMenu*);
-
- virtual void downloadURL(const WebCore::KURL&);
- virtual void copyImageToClipboard(const WebCore::HitTestResult&);
- virtual void searchWithGoogle(const WebCore::Frame*);
- virtual void lookUpInDictionary(WebCore::Frame*);
- virtual void speak(const WebCore::String&);
- virtual bool isSpeaking();
- virtual void stopSpeaking();
- virtual bool shouldIncludeInspectElementItem();
-
- private:
- WebViewImpl* webview_; // weak pointer
-};
-
-#endif // WEBKIT_GLUE_CONTEXT_MENU_CLIENT_IMPL_H_
diff --git a/webkit/glue/webview_impl.h b/webkit/glue/webview_impl.h
index 750192f..3f1ec50 100644
--- a/webkit/glue/webview_impl.h
+++ b/webkit/glue/webview_impl.h
@@ -13,9 +13,9 @@
#include "webkit/api/public/WebString.h"
#include "webkit/api/public/WebView.h"
#include "webkit/api/src/NotificationPresenterImpl.h"
+#include "webkit/api/src/WebContextMenuClientImpl.h"
#include "webkit/glue/back_forward_list_client_impl.h"
#include "webkit/glue/chrome_client_impl.h"
-#include "webkit/glue/context_menu_client_impl.h"
#include "webkit/glue/dragclient_impl.h"
#include "webkit/glue/editor_client_impl.h"
#include "webkit/glue/inspector_client_impl.h"
@@ -37,6 +37,7 @@ class Widget;
namespace WebKit {
class WebAccessibilityObject;
+class WebContextMenuClientImpl;
class WebKeyboardEvent;
class WebMouseEvent;
class WebMouseWheelEvent;
@@ -257,7 +258,7 @@ class WebViewImpl : public WebKit::WebView, public RefCounted<WebViewImpl> {
webkit_glue::BackForwardListClientImpl back_forward_list_client_impl_;
ChromeClientImpl chrome_client_impl_;
- ContextMenuClientImpl context_menu_client_impl_;
+ WebKit::WebContextMenuClientImpl context_menu_client_impl_;
DragClientImpl drag_client_impl_;
EditorClientImpl editor_client_impl_;
InspectorClientImpl inspector_client_impl_;
diff --git a/webkit/webkit.gyp b/webkit/webkit.gyp
index c505680..82a713f 100644
--- a/webkit/webkit.gyp
+++ b/webkit/webkit.gyp
@@ -199,6 +199,8 @@
'api/src/WebBindings.cpp',
'api/src/WebCache.cpp',
'api/src/WebColor.cpp',
+ 'api/src/WebContextMenuClientImpl.cpp',
+ 'api/src/WebContextMenuClientImpl.h',
'api/src/WebCrossOriginPreflightResultCache.cpp',
'api/src/WebCString.cpp',
'api/src/WebCursorInfo.cpp',
@@ -553,8 +555,6 @@
'glue/chrome_client_impl.cc',
'glue/chrome_client_impl.h',
'glue/context_menu.h',
- 'glue/context_menu_client_impl.cc',
- 'glue/context_menu_client_impl.h',
'glue/cpp_binding_example.cc',
'glue/cpp_binding_example.h',
'glue/cpp_bound_class.cc',