summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/clipboard_qt.cpp2
-rw-r--r--src/core/type_conversion.h5
-rw-r--r--src/core/web_contents_adapter.cpp19
-rw-r--r--src/core/web_contents_adapter.h12
-rw-r--r--src/core/web_contents_adapter_client.h44
-rw-r--r--src/core/web_contents_view_qt.cpp24
6 files changed, 105 insertions, 1 deletions
diff --git a/src/core/clipboard_qt.cpp b/src/core/clipboard_qt.cpp
index f7ca9764d..027a93bac 100644
--- a/src/core/clipboard_qt.cpp
+++ b/src/core/clipboard_qt.cpp
@@ -331,7 +331,7 @@ SkBitmap ClipboardQt::ReadImage(ui::ClipboardType type) const
const QMimeData *mimeData = QGuiApplication::clipboard()->mimeData(type == ui::CLIPBOARD_TYPE_COPY_PASTE ? QClipboard::Clipboard : QClipboard::Selection);
QImage image = qvariant_cast<QImage>(mimeData->imageData());
- Q_ASSERT(image.format() == QImage::Format_ARGB32);
+ image = image.convertToFormat(QImage::Format_ARGB32);
SkBitmap bitmap;
bitmap.setInfo(SkImageInfo::MakeN32(image.width(), image.height(), kOpaque_SkAlphaType));
bitmap.setPixels(const_cast<uchar*>(image.constBits()));
diff --git a/src/core/type_conversion.h b/src/core/type_conversion.h
index 66fcd4dd0..3f5575a47 100644
--- a/src/core/type_conversion.h
+++ b/src/core/type_conversion.h
@@ -92,6 +92,11 @@ inline QPoint toQt(const gfx::Point &point)
return QPoint(point.x(), point.y());
}
+inline gfx::Point toGfx(const QPoint& point)
+{
+ return gfx::Point(point.x(), point.y());
+}
+
inline QRect toQt(const gfx::Rect &rect)
{
return QRect(rect.x(), rect.y(), rect.width(), rect.height());
diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp
index f0b0a0d94..ec7928c71 100644
--- a/src/core/web_contents_adapter.cpp
+++ b/src/core/web_contents_adapter.cpp
@@ -758,6 +758,25 @@ void WebContentsAdapter::updateWebPreferences(const content::WebPreferences & we
d->webContents->GetRenderViewHost()->UpdateWebkitPreferences(webPreferences);
}
+void WebContentsAdapter::copyImageAt(const QPoint &location)
+{
+ Q_D(WebContentsAdapter);
+ d->webContents->GetRenderViewHost()->CopyImageAt(location.x(), location.y());
+}
+
+ASSERT_ENUMS_MATCH(WebContentsAdapter::MediaPlayerNoAction, blink::WebMediaPlayerAction::Unknown)
+ASSERT_ENUMS_MATCH(WebContentsAdapter::MediaPlayerPlay, blink::WebMediaPlayerAction::Play)
+ASSERT_ENUMS_MATCH(WebContentsAdapter::MediaPlayerMute, blink::WebMediaPlayerAction::Mute)
+ASSERT_ENUMS_MATCH(WebContentsAdapter::MediaPlayerLoop, blink::WebMediaPlayerAction::Loop)
+ASSERT_ENUMS_MATCH(WebContentsAdapter::MediaPlayerControls, blink::WebMediaPlayerAction::Controls)
+
+void WebContentsAdapter::executeMediaPlayerActionAt(const QPoint &location, MediaPlayerAction action, bool enable)
+{
+ Q_D(WebContentsAdapter);
+ blink::WebMediaPlayerAction blinkAction((blink::WebMediaPlayerAction::Type)action, enable);
+ d->webContents->GetRenderViewHost()->ExecuteMediaPlayerActionAtLocation(toGfx(location), blinkAction);
+}
+
void WebContentsAdapter::wasShown()
{
Q_D(WebContentsAdapter);
diff --git a/src/core/web_contents_adapter.h b/src/core/web_contents_adapter.h
index 7f644cdd2..2e65b86c1 100644
--- a/src/core/web_contents_adapter.h
+++ b/src/core/web_contents_adapter.h
@@ -112,6 +112,18 @@ public:
void stopFinding();
void updateWebPreferences(const content::WebPreferences &webPreferences);
+ // Must match blink::WebMediaPlayerAction::Type.
+ enum MediaPlayerAction {
+ MediaPlayerNoAction,
+ MediaPlayerPlay,
+ MediaPlayerMute,
+ MediaPlayerLoop,
+ MediaPlayerControls,
+ MediaPlayerTypeLast = MediaPlayerControls
+ };
+ void copyImageAt(const QPoint &location);
+ void executeMediaPlayerActionAt(const QPoint &location, MediaPlayerAction action, bool enable);
+
void wasShown();
void wasHidden();
void grantMediaAccessPermission(const QUrl &securityOrigin, WebContentsAdapterClient::MediaRequestFlags flags);
diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h
index 886f8bcc6..05a31c0cd 100644
--- a/src/core/web_contents_adapter_client.h
+++ b/src/core/web_contents_adapter_client.h
@@ -66,10 +66,54 @@ class WebEngineSettings;
class WebEngineContextMenuData {
public:
+ WebEngineContextMenuData()
+ : mediaType(MediaTypeNone)
+ , hasImageContent(false)
+ , mediaFlags(0)
+ {
+ }
+
+ // Must match blink::WebContextMenuData::MediaType:
+ enum MediaType {
+ // No special node is in context.
+ MediaTypeNone,
+ // An image node is selected.
+ MediaTypeImage,
+ // A video node is selected.
+ MediaTypeVideo,
+ // An audio node is selected.
+ MediaTypeAudio,
+ // A canvas node is selected.
+ MediaTypeCanvas,
+ // A file node is selected.
+ MediaTypeFile,
+ // A plugin node is selected.
+ MediaTypePlugin,
+ MediaTypeLast = MediaTypePlugin
+ };
+ // Must match blink::WebContextMenuData::MediaFlags:
+ enum MediaFlags {
+ MediaNone = 0x0,
+ MediaInError = 0x1,
+ MediaPaused = 0x2,
+ MediaMuted = 0x4,
+ MediaLoop = 0x8,
+ MediaCanSave = 0x10,
+ MediaHasAudio = 0x20,
+ MediaCanToggleControls = 0x40,
+ MediaControls = 0x80,
+ MediaCanPrint = 0x100,
+ MediaCanRotate = 0x200,
+ };
+
QPoint pos;
QUrl linkUrl;
QString linkText;
QString selectedText;
+ QUrl mediaUrl;
+ MediaType mediaType;
+ bool hasImageContent;
+ uint mediaFlags;
// Some likely candidates for future additions as we add support for the related actions:
// bool isImageBlocked;
// bool isEditable;
diff --git a/src/core/web_contents_view_qt.cpp b/src/core/web_contents_view_qt.cpp
index 932170634..e7764fbcb 100644
--- a/src/core/web_contents_view_qt.cpp
+++ b/src/core/web_contents_view_qt.cpp
@@ -110,6 +110,26 @@ void WebContentsViewQt::SetInitialFocus()
Focus();
}
+ASSERT_ENUMS_MATCH(WebEngineContextMenuData::MediaTypeNone, blink::WebContextMenuData::MediaTypeNone)
+ASSERT_ENUMS_MATCH(WebEngineContextMenuData::MediaTypeImage, blink::WebContextMenuData::MediaTypeImage)
+ASSERT_ENUMS_MATCH(WebEngineContextMenuData::MediaTypeVideo, blink::WebContextMenuData::MediaTypeVideo)
+ASSERT_ENUMS_MATCH(WebEngineContextMenuData::MediaTypeAudio, blink::WebContextMenuData::MediaTypeAudio)
+ASSERT_ENUMS_MATCH(WebEngineContextMenuData::MediaTypeCanvas, blink::WebContextMenuData::MediaTypeCanvas)
+ASSERT_ENUMS_MATCH(WebEngineContextMenuData::MediaTypeFile, blink::WebContextMenuData::MediaTypeFile)
+ASSERT_ENUMS_MATCH(WebEngineContextMenuData::MediaTypePlugin, blink::WebContextMenuData::MediaTypePlugin)
+
+ASSERT_ENUMS_MATCH(WebEngineContextMenuData::MediaNone, blink::WebContextMenuData::MediaNone)
+ASSERT_ENUMS_MATCH(WebEngineContextMenuData::MediaInError, blink::WebContextMenuData::MediaInError)
+ASSERT_ENUMS_MATCH(WebEngineContextMenuData::MediaPaused, blink::WebContextMenuData::MediaPaused)
+ASSERT_ENUMS_MATCH(WebEngineContextMenuData::MediaMuted, blink::WebContextMenuData::MediaMuted)
+ASSERT_ENUMS_MATCH(WebEngineContextMenuData::MediaLoop, blink::WebContextMenuData::MediaLoop)
+ASSERT_ENUMS_MATCH(WebEngineContextMenuData::MediaCanSave, blink::WebContextMenuData::MediaCanSave)
+ASSERT_ENUMS_MATCH(WebEngineContextMenuData::MediaHasAudio, blink::WebContextMenuData::MediaHasAudio)
+ASSERT_ENUMS_MATCH(WebEngineContextMenuData::MediaCanToggleControls, blink::WebContextMenuData::MediaCanToggleControls)
+ASSERT_ENUMS_MATCH(WebEngineContextMenuData::MediaControls, blink::WebContextMenuData::MediaControls)
+ASSERT_ENUMS_MATCH(WebEngineContextMenuData::MediaCanPrint, blink::WebContextMenuData::MediaCanPrint)
+ASSERT_ENUMS_MATCH(WebEngineContextMenuData::MediaCanRotate, blink::WebContextMenuData::MediaCanRotate)
+
static WebEngineContextMenuData fromParams(const content::ContextMenuParams &params)
{
WebEngineContextMenuData ret;
@@ -117,6 +137,10 @@ static WebEngineContextMenuData fromParams(const content::ContextMenuParams &par
ret.linkUrl = toQt(params.link_url);
ret.linkText = toQt(params.link_text.data());
ret.selectedText = toQt(params.selection_text.data());
+ ret.mediaUrl = toQt(params.src_url);
+ ret.mediaType = (WebEngineContextMenuData::MediaType)params.media_type;
+ ret.hasImageContent = params.has_image_contents;
+ ret.mediaFlags = params.media_flags;
return ret;
}