diff --git a/src/webview/tabbedwebview.cpp b/src/webview/tabbedwebview.cpp index 11f857088..a8d5b7e35 100644 --- a/src/webview/tabbedwebview.cpp +++ b/src/webview/tabbedwebview.cpp @@ -344,14 +344,20 @@ void TabbedWebView::contextMenuEvent(QContextMenuEvent* event) } QWebElement element = r.element(); - if (!element.isNull() && (element.tagName().toLower() == "input" || element.tagName().toLower() == "textarea" || - element.tagName().toLower() == "video" || element.tagName().toLower() == "audio")) { + if (!element.isNull() && (element.tagName().toLower() == "input" || element.tagName().toLower() == "textarea")) { if (m_menu->isEmpty()) { page()->createStandardContextMenu()->popup(QCursor::pos()); return; } } + if (isMediaElement(element)) { + if (m_menu->isEmpty()) { + createMediaContextMenu(r)->popup(QCursor::pos()); + return; + } + } + if (m_menu->isEmpty() && selectedText().isEmpty()) { QAction* action = m_menu->addAction(tr("&Back"), this, SLOT(back())); action->setIcon(IconProvider::standardIcon(QStyle::SP_ArrowBack)); diff --git a/src/webview/tabwidget.cpp b/src/webview/tabwidget.cpp index d5431795f..0e96becbe 100644 --- a/src/webview/tabwidget.cpp +++ b/src/webview/tabwidget.cpp @@ -515,7 +515,7 @@ void TabWidget::restoreAllClosedTabs() QList closedTabs = m_closedTabsManager->allClosedTabs(); foreach(ClosedTabsManager::Tab tab, closedTabs) { - int index = addView(QUrl(), tab.title, Qz::NT_CleanNotSelectedTab); + int index = addView(QUrl(), tab.title, Qz::NT_CleanSelectedTab); QDataStream historyStream(tab.history); historyStream >> *weView(index)->history(); @@ -608,7 +608,7 @@ void TabWidget::restorePinnedTabs() QByteArray historyState = tabHistory.value(i); int addedIndex; if (!historyState.isEmpty()) { - addedIndex = addView(QUrl(), Qz::NT_CleanNotSelectedTab); + addedIndex = addView(QUrl(), Qz::NT_CleanSelectedTab); QDataStream historyStream(historyState); historyStream >> *weView(addedIndex)->history(); weView(addedIndex)->load(url); @@ -684,7 +684,7 @@ bool TabWidget::restoreState(const QByteArray &state) QByteArray historyState = tabHistory.value(i); if (!historyState.isEmpty()) { - int index = addView(QUrl(), Qz::NT_CleanNotSelectedTab); + int index = addView(QUrl(), Qz::NT_CleanSelectedTab); QDataStream historyStream(historyState); historyStream >> *weView(index)->history(); weView(index)->load(url); diff --git a/src/webview/webview.cpp b/src/webview/webview.cpp index 36f92b927..5f22994aa 100644 --- a/src/webview/webview.cpp +++ b/src/webview/webview.cpp @@ -366,6 +366,65 @@ QUrl WebView::lastUrl() return m_lastUrl; } +bool WebView::isMediaElement(const QWebElement &element) +{ + return (element.tagName().toLower() == "video" || element.tagName().toLower() == "audio"); +} + +QMenu *WebView::createMediaContextMenu(const QWebHitTestResult &hitTest) +{ + QMenu* menu = new QMenu(this); + m_mediaElement = hitTest.element(); + + bool paused = m_mediaElement.evaluateJavaScript("this.paused").toBool(); + bool muted = m_mediaElement.evaluateJavaScript("this.muted").toBool(); + QUrl videoUrl = m_mediaElement.evaluateJavaScript("this.currentSrc").toUrl(); + + menu->addAction(paused ? tr("Un&pause") : tr("&Pause"), this, SLOT(pauseMedia())); + menu->addAction(muted ? tr("Un&mute") : tr("&Mute"), this, SLOT(muteMedia())); + menu->addSeparator(); + menu->addAction(tr("Copy Media &Address"), this, SLOT(copyLinkToClipboard()))->setData(videoUrl); + menu->addAction(tr("&Download Media To Disk"), this, SLOT(downloadLinkToDisk()))->setData(videoUrl); + + return menu; +} + +void WebView::pauseMedia() +{ + bool paused = m_mediaElement.evaluateJavaScript("this.paused").toBool(); + + if (paused) { + m_mediaElement.evaluateJavaScript("this.play()"); + } + else { + m_mediaElement.evaluateJavaScript("this.pause()"); + } +} + +void WebView::muteMedia() +{ + bool muted = m_mediaElement.evaluateJavaScript("this.muted").toBool(); + + if (muted) { + m_mediaElement.evaluateJavaScript("this.muted = false"); + } + else { + m_mediaElement.evaluateJavaScript("this.muted = true"); + } +} + +void WebView::controlsMedia() +{ + bool controls= m_mediaElement.evaluateJavaScript("this.controls").toBool(); + + if (controls) { + m_mediaElement.evaluateJavaScript("this.controls = false"); + } + else { + m_mediaElement.evaluateJavaScript("this.controls = true"); + } +} + void WebView::wheelEvent(QWheelEvent* event) { if (event->modifiers() & Qt::ControlModifier) { diff --git a/src/webview/webview.h b/src/webview/webview.h index 872eec4d9..76cd3babe 100644 --- a/src/webview/webview.h +++ b/src/webview/webview.h @@ -95,6 +95,15 @@ protected: void copyText(); QUrl lastUrl(); + bool isMediaElement(const QWebElement &element); + + QMenu* createMediaContextMenu(const QWebHitTestResult &hitTest); + +private slots: + void pauseMedia(); + void muteMedia(); + void controlsMedia(); + private: QList m_zoomLevels; int m_currentZoom; @@ -107,6 +116,8 @@ private: QUrl m_aboutToLoadUrl; QUrl m_lastUrl; + QWebElement m_mediaElement; + QList m_touchPoints; };