summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-17 03:23:46 +0000
committerajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-17 03:23:46 +0000
commit574a1d691c71e833638ccb1ca395dfa20c6835a4 (patch)
tree1d5f63a520c6b87fd74a19d57e9eaf4737bdd4fc /webkit
parent91cea0e774541297a46197d87e486cf8a4199775 (diff)
downloadchromium_src-574a1d691c71e833638ccb1ca395dfa20c6835a4.zip
chromium_src-574a1d691c71e833638ccb1ca395dfa20c6835a4.tar.gz
chromium_src-574a1d691c71e833638ccb1ca395dfa20c6835a4.tar.bz2
Begin implementation of the context menu for Video and Audio tags.
This code should enable the creation of a basic context menu for the Video and Audio tags. The actions for fullscreen, save screenshot, loop, and set playback rate are not yet implemented. BUG=15686 TEST=None Review URL: http://codereview.chromium.org/149604 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20931 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/api/public/WebMediaPlayer.h2
-rw-r--r--webkit/api/src/WebMediaPlayerClientImpl.cpp14
-rw-r--r--webkit/api/src/WebMediaPlayerClientImpl.h2
-rw-r--r--webkit/glue/context_menu.h47
-rw-r--r--webkit/glue/context_menu_client_impl.cc50
-rw-r--r--webkit/glue/webmediaplayer_impl.cc10
-rw-r--r--webkit/glue/webmediaplayer_impl.h2
-rw-r--r--webkit/glue/webview_delegate.h7
-rw-r--r--webkit/tools/test_shell/test_webview_delegate.cc28
-rw-r--r--webkit/tools/test_shell/test_webview_delegate.h2
10 files changed, 140 insertions, 24 deletions
diff --git a/webkit/api/public/WebMediaPlayer.h b/webkit/api/public/WebMediaPlayer.h
index 740b894..8b60c77 100644
--- a/webkit/api/public/WebMediaPlayer.h
+++ b/webkit/api/public/WebMediaPlayer.h
@@ -67,6 +67,8 @@ namespace WebKit {
// Playback controls.
virtual void play() = 0;
virtual void pause() = 0;
+ virtual bool supportsFullscreen() const = 0;
+ virtual bool supportsSave() const = 0;
virtual void seek(float seconds) = 0;
virtual void setEndTime(float seconds) = 0;
virtual void setRate(float) = 0;
diff --git a/webkit/api/src/WebMediaPlayerClientImpl.cpp b/webkit/api/src/WebMediaPlayerClientImpl.cpp
index ca666e9..0451ad8 100644
--- a/webkit/api/src/WebMediaPlayerClientImpl.cpp
+++ b/webkit/api/src/WebMediaPlayerClientImpl.cpp
@@ -201,6 +201,20 @@ bool WebMediaPlayerClientImpl::paused() const
return false;
}
+bool WebMediaPlayerClientImpl::supportsFullscreen() const
+{
+ if (m_webMediaPlayer.get())
+ return m_webMediaPlayer->supportsFullscreen();
+ return false;
+}
+
+bool WebMediaPlayerClientImpl::supportsSave() const
+{
+ if (m_webMediaPlayer.get())
+ return m_webMediaPlayer->supportsSave();
+ return false;
+}
+
void WebMediaPlayerClientImpl::setVolume(float volume)
{
if (m_webMediaPlayer.get())
diff --git a/webkit/api/src/WebMediaPlayerClientImpl.h b/webkit/api/src/WebMediaPlayerClientImpl.h
index 9f5cd5d..d758276 100644
--- a/webkit/api/src/WebMediaPlayerClientImpl.h
+++ b/webkit/api/src/WebMediaPlayerClientImpl.h
@@ -66,6 +66,8 @@ namespace WebKit {
virtual void cancelLoad();
virtual void play();
virtual void pause();
+ virtual bool supportsFullscreen() const;
+ virtual bool supportsSave() const;
virtual WebCore::IntSize naturalSize() const;
virtual bool hasVideo() const;
virtual void setVisible(bool);
diff --git a/webkit/glue/context_menu.h b/webkit/glue/context_menu.h
index 69ea22f..e6c4660 100644
--- a/webkit/glue/context_menu.h
+++ b/webkit/glue/context_menu.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// 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.
@@ -37,6 +37,12 @@ struct ContextNode {
// A misspelled word is selected
MISSPELLED_WORD = 0x40,
+
+ // A video node is selected
+ VIDEO = 0x80,
+
+ // A video node is selected
+ AUDIO = 0x100,
};
enum Capability {
@@ -55,6 +61,35 @@ struct ContextNode {
explicit ContextNode(int32 t) : type(t) {}
};
+// Parameters structure used in ContextMenuParams with attributes needed to
+// render the context menu for media elements.
+//
+// TODO(ajwong): Add support for multiple audio tracks and subtitles.
+struct ContextMenuMediaParams {
+ // Values for the bitfield representing the state of the media player.
+ // If the state is in ERROR, most media controls should disable
+ // themselves.
+ enum PlayerState {
+ PLAYER_NO_STATE = 0x0,
+ PLAYER_ERROR = 0x1,
+ PLAYER_PAUSED = 0x2,
+ PLAYER_MUTED = 0x4,
+ PLAYER_LOOP = 0x8,
+ PLAYER_CAN_SAVE = 0x10,
+ };
+
+ // A bitfield representing the current state of the player, such as
+ // playing, muted, etc.
+ int32 player_state;
+
+ // The current playback rate for this media element.
+ double playback_rate;
+
+ ContextMenuMediaParams()
+ : player_state(PLAYER_NO_STATE), playback_rate(1.0f) {
+ }
+};
+
// Parameters structure for ViewHostMsg_ContextMenu.
// FIXME(beng): This would be more useful in the future and more efficient
// if the parameters here weren't so literally mapped to what
@@ -78,8 +113,10 @@ struct ContextMenuParams {
// this field in the frontend process.
GURL unfiltered_link_url;
- // This is the URL of the image the context menu was invoked on.
- GURL image_url;
+ // This is the source URL for the element that the context menu was
+ // invoked on. Example of elements with source URLs are img, audio, and
+ // video.
+ GURL src_url;
// This is the URL of the top level page that the context menu was invoked
// on.
@@ -88,6 +125,10 @@ struct ContextMenuParams {
// This is the URL of the subframe that the context menu was invoked on.
GURL frame_url;
+ // These are the parameters for the media element that the context menu
+ // was invoked on.
+ ContextMenuMediaParams media_params;
+
// This is the text of the selection that the context menu was invoked on.
std::wstring selection_text;
diff --git a/webkit/glue/context_menu_client_impl.cc b/webkit/glue/context_menu_client_impl.cc
index 35c9b30..ec57257 100644
--- a/webkit/glue/context_menu_client_impl.cc
+++ b/webkit/glue/context_menu_client_impl.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// 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.
@@ -15,6 +15,8 @@ MSVC_PUSH_WARNING_LEVEL(0);
#include "FrameLoader.h"
#include "FrameView.h"
#include "HitTestResult.h"
+#include "HTMLMediaElement.h"
+#include "HTMLNames.h"
#include "KURL.h"
#include "Widget.h"
MSVC_POP_WARNING();
@@ -161,18 +163,51 @@ WebCore::PlatformMenuDescription
ContextNode node;
- // Links, Images and Image-Links take preference over all else.
+ // Links, Images, Media tags, and Image/Media-Links take preference over
+ // all else.
WebCore::KURL link_url = r.absoluteLinkURL();
if (!link_url.isEmpty()) {
node.type |= ContextNode::LINK;
}
- WebCore::KURL image_url = r.absoluteImageURL();
- if (!image_url.isEmpty()) {
+
+ WebCore::KURL src_url;
+
+ ContextMenuMediaParams media_params;
+
+ if (!r.absoluteImageURL().isEmpty()) {
+ src_url = r.absoluteImageURL();
node.type |= ContextNode::IMAGE;
+ } else if (!r.absoluteMediaURL().isEmpty()) {
+ src_url = 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)) {
+ node.type |= ContextNode::VIDEO;
+ } else if (media_element->hasTagName(WebCore::HTMLNames::audioTag)) {
+ node.type |= ContextNode::AUDIO;
+ }
+
+ media_params.playback_rate = media_element->playbackRate();
+
+ if (media_element->paused()) {
+ media_params.player_state |= ContextMenuMediaParams::PLAYER_PAUSED;
+ }
+ if (media_element->muted()) {
+ media_params.player_state |= ContextMenuMediaParams::PLAYER_MUTED;
+ }
+ if (media_element->loop()) {
+ media_params.player_state |= ContextMenuMediaParams::PLAYER_LOOP;
+ }
+ if (media_element->supportsSave()) {
+ media_params.player_state |= ContextMenuMediaParams::PLAYER_CAN_SAVE;
+ }
}
- // If it's not a link, an image or an image link, show a selection menu or a
- // more generic page menu.
+ // 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.
std::wstring selection_text_string;
std::wstring misspelled_word_string;
GURL frame_url;
@@ -246,9 +281,10 @@ WebCore::PlatformMenuDescription
menu_point.x(),
menu_point.y(),
webkit_glue::KURLToGURL(link_url),
- webkit_glue::KURLToGURL(image_url),
+ webkit_glue::KURLToGURL(src_url),
page_url,
frame_url,
+ media_params,
selection_text_string,
misspelled_word_string,
edit_flags,
diff --git a/webkit/glue/webmediaplayer_impl.cc b/webkit/glue/webmediaplayer_impl.cc
index 051e7d4..b817239 100644
--- a/webkit/glue/webmediaplayer_impl.cc
+++ b/webkit/glue/webmediaplayer_impl.cc
@@ -198,6 +198,16 @@ void WebMediaPlayerImpl::pause() {
pipeline_->SetPlaybackRate(0.0f);
}
+bool WebMediaPlayerImpl::supportsFullscreen() const {
+ DCHECK(MessageLoop::current() == main_loop_);
+ return true;
+}
+
+bool WebMediaPlayerImpl::supportsSave() const {
+ DCHECK(MessageLoop::current() == main_loop_);
+ return true;
+}
+
void WebMediaPlayerImpl::seek(float seconds) {
DCHECK(MessageLoop::current() == main_loop_);
diff --git a/webkit/glue/webmediaplayer_impl.h b/webkit/glue/webmediaplayer_impl.h
index 9e9522e..5904023 100644
--- a/webkit/glue/webmediaplayer_impl.h
+++ b/webkit/glue/webmediaplayer_impl.h
@@ -156,6 +156,8 @@ class WebMediaPlayerImpl : public WebKit::WebMediaPlayer,
// Playback controls.
virtual void play();
virtual void pause();
+ virtual bool supportsFullscreen() const;
+ virtual bool supportsSave() const;
virtual void seek(float seconds);
virtual void setEndTime(float seconds);
virtual void setRate(float rate);
diff --git a/webkit/glue/webview_delegate.h b/webkit/glue/webview_delegate.h
index e41a7bf..640dc53 100644
--- a/webkit/glue/webview_delegate.h
+++ b/webkit/glue/webview_delegate.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// 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.
@@ -66,6 +66,8 @@ class WebFrame;
class WebMediaPlayerDelegate;
class WebPluginDelegate;
class WebView;
+class WebWidget;
+struct ContextMenuMediaParams;
struct WebPluginGeometry;
struct WebPreferences;
@@ -623,6 +625,8 @@ class WebViewDelegate : virtual public WebKit::WebWidgetClient {
// clicked on
// @param page_url The URL of the page the mouse right clicked on
// @param frame_url The URL of the subframe the mouse right clicked on
+ // @param media_params Extra attributed needed by the context menu for
+ // media elements.
// @param selection_text The raw text of the selection that the mouse right
// clicked on
// @param misspelled_word The editable (possibily) misspelled word
@@ -639,6 +643,7 @@ class WebViewDelegate : virtual public WebKit::WebWidgetClient {
const GURL& image_url,
const GURL& page_url,
const GURL& frame_url,
+ const ContextMenuMediaParams& media_params,
const std::wstring& selection_text,
const std::wstring& misspelled_word,
int edit_flags,
diff --git a/webkit/tools/test_shell/test_webview_delegate.cc b/webkit/tools/test_shell/test_webview_delegate.cc
index 2fdf392..6fbaa1f 100644
--- a/webkit/tools/test_shell/test_webview_delegate.cc
+++ b/webkit/tools/test_shell/test_webview_delegate.cc
@@ -570,19 +570,21 @@ void TestWebViewDelegate::StartDragging(WebView* webview,
webview->DragSourceSystemDragEnded();
}
-void TestWebViewDelegate::ShowContextMenu(WebView* webview,
- ContextNode node,
- int x,
- int y,
- const GURL& link_url,
- const GURL& image_url,
- const GURL& page_url,
- const GURL& frame_url,
- const std::wstring& selection_text,
- const std::wstring& misspelled_word,
- int edit_flags,
- const std::string& security_info,
- const std::string& frame_charset) {
+void TestWebViewDelegate::ShowContextMenu(
+ WebView* webview,
+ ContextNode node,
+ int x,
+ int y,
+ const GURL& link_url,
+ const GURL& image_url,
+ const GURL& page_url,
+ const GURL& frame_url,
+ const ContextMenuMediaParams& media_params,
+ const std::wstring& selection_text,
+ const std::wstring& misspelled_word,
+ int edit_flags,
+ const std::string& security_info,
+ const std::string& frame_charset) {
CapturedContextMenuEvent context(node, x, y);
captured_context_menu_events_.push_back(context);
}
diff --git a/webkit/tools/test_shell/test_webview_delegate.h b/webkit/tools/test_shell/test_webview_delegate.h
index e70ede9..f86bc56 100644
--- a/webkit/tools/test_shell/test_webview_delegate.h
+++ b/webkit/tools/test_shell/test_webview_delegate.h
@@ -35,6 +35,7 @@
#endif
#include "webkit/tools/test_shell/test_navigation_controller.h"
+struct ContextMenuMediaParams;
struct WebPreferences;
class GURL;
class TestShell;
@@ -136,6 +137,7 @@ class TestWebViewDelegate : public base::RefCounted<TestWebViewDelegate>,
const GURL& image_url,
const GURL& page_url,
const GURL& frame_url,
+ const ContextMenuMediaParams& media_params,
const std::wstring& selection_text,
const std::wstring& misspelled_word,
int edit_flags,