void HelpBrowser::onContextMenuRequest( const QPoint & pos ) { QMenu menu; QWebHitTestResult hitTest = mWebView->page()->mainFrame()->hitTestContent( pos ); if (!hitTest.linkElement().isNull()) { menu.addAction( mWebView->pageAction(QWebPage::CopyLinkToClipboard) ); } menu.addSeparator(); if (hitTest.isContentEditable() || hitTest.isContentSelected()) menu.addAction( mWebView->pageAction(QWebPage::Copy) ); if (hitTest.isContentEditable()) menu.addAction( mWebView->pageAction(QWebPage::Paste) ); if (hitTest.isContentSelected()) menu.addAction( mActions[Evaluate] ); menu.addSeparator(); menu.addAction( mWebView->pageAction(QWebPage::Back) ); menu.addAction( mWebView->pageAction(QWebPage::Forward) ); menu.addAction( mWebView->pageAction(QWebPage::Reload) ); menu.addSeparator(); menu.addAction( mActions[ZoomIn] ); menu.addAction( mActions[ZoomOut] ); menu.addAction( mActions[ResetZoom] ); menu.exec( mWebView->mapToGlobal(pos) ); }
void WebView::contextMenuEvent ( QContextMenuEvent * event ) { QMenu menu; QPoint pos = event->pos(); QWebHitTestResult hitTest = page()->mainFrame()->hitTestContent( pos ); if (!hitTest.linkElement().isNull()) { menu.addAction( pageAction(QWebPage::CopyLinkToClipboard) ); menu.addSeparator(); } if (hitTest.isContentEditable() || hitTest.isContentSelected()) { menu.addAction( pageAction(QWebPage::Copy) ); if (hitTest.isContentEditable()) menu.addAction( pageAction(QWebPage::Paste) ); menu.addSeparator(); } menu.addAction( pageAction(QWebPage::Back) ); menu.addAction( pageAction(QWebPage::Forward) ); menu.addAction( pageAction(QWebPage::Reload) ); menu.exec( event->globalPos() ); }
bool LLWebPage::acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest& request, NavigationType type) { if (!window) return false; if (request.url().scheme() == window->d->mNoFollowScheme) { QString encodedUrl = request.url().toEncoded(); // QUrl is turning foo:///home/bar into foo:/home/bar for some reason while Firefox does not // http://bugs.webkit.org/show_bug.cgi?id=24695 if (!encodedUrl.startsWith(window->d->mNoFollowScheme + "://")) { encodedUrl = encodedUrl.mid(window->d->mNoFollowScheme.length() + 1); encodedUrl = window->d->mNoFollowScheme + "://" + encodedUrl; } std::string rawUri = encodedUrl.toStdString(); LLEmbeddedBrowserWindowEvent event(window->getWindowId(), rawUri, rawUri); window->d->mEventEmitter.update(&LLEmbeddedBrowserWindowObserver::onClickLinkNoFollow, event); return false; } bool accepted = QWebPage::acceptNavigationRequest(frame, request, type); if (accepted && type == QWebPage::NavigationTypeLinkClicked) { // save URL QUrl url = request.url(); window->d->mClickHref = QString(url.toEncoded()).toStdString(); // save target attribute QWebHitTestResult hitTest = mainFrame()->hitTestContent(currentPoint); QString linkTarget = hitTest.linkElement().attribute("target"); window->d->mClickTarget = linkTarget.toStdString(); // start off with no target specified int link_target_type = LLQtWebKit::LTT_TARGET_UNKNOWN; // user clicks on a link with a target that matches the one set as "External" if ( window->d->mClickTarget.empty() ) { link_target_type = LLQtWebKit::LTT_TARGET_NONE; } else if ( window->d->mClickTarget == window->d->mExternalTargetName ) { link_target_type = LLQtWebKit::LTT_TARGET_EXTERNAL; } else // user clicks on a link with a target that matches the one set as "Blank" if ( window->d->mClickTarget == window->d->mBlankTargetName ) { link_target_type = LLQtWebKit::LTT_TARGET_BLANK; } else { // default action for a target we haven't specified is to open in current window // and fire an event as if it was a normal click window->navigateTo( window->d->mClickHref ); link_target_type = LLQtWebKit::LTT_TARGET_OTHER; }; // build event based on the data we have and emit it LLEmbeddedBrowserWindowEvent event( window->getWindowId(), window->getCurrentUri(), window->d->mClickHref, window->d->mClickTarget, link_target_type ); window->d->mEventEmitter.update( &LLEmbeddedBrowserWindowObserver::onClickLinkHref, event ); }; return accepted; }