2012-03-04 14:25:52 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
|
|
|
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
2012-01-21 20:29:33 +01:00
|
|
|
#include "popupwebview.h"
|
|
|
|
#include "popupwebpage.h"
|
|
|
|
#include "mainapplication.h"
|
2012-01-22 11:49:58 +01:00
|
|
|
#include "qupzilla.h"
|
|
|
|
#include "tabwidget.h"
|
2012-01-21 20:29:33 +01:00
|
|
|
#include "iconprovider.h"
|
2012-01-24 23:28:18 +01:00
|
|
|
#include "enhancedmenu.h"
|
2012-01-21 20:29:33 +01:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QWebFrame>
|
|
|
|
|
2012-01-21 20:29:33 +01:00
|
|
|
PopupWebView::PopupWebView(QWidget* parent)
|
|
|
|
: WebView(parent)
|
|
|
|
, m_page(0)
|
2012-01-24 23:28:18 +01:00
|
|
|
, m_menu(new Menu(this))
|
2012-01-21 20:29:33 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupWebView::setWebPage(PopupWebPage* page)
|
|
|
|
{
|
|
|
|
if (m_page == page) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_page) {
|
|
|
|
delete m_page;
|
|
|
|
m_page = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_page = page;
|
|
|
|
m_page->setParent(this);
|
|
|
|
setPage(m_page);
|
|
|
|
}
|
|
|
|
|
|
|
|
PopupWebPage* PopupWebView::webPage()
|
|
|
|
{
|
|
|
|
return m_page;
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget* PopupWebView::overlayForJsAlert()
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2012-03-10 13:57:50 +01:00
|
|
|
void PopupWebView::openUrlInNewTab(const QUrl &urla, Qz::NewTabPositionFlag position)
|
2012-01-21 20:29:33 +01:00
|
|
|
{
|
2012-01-22 15:15:43 +01:00
|
|
|
Q_UNUSED(position)
|
2012-01-21 20:29:33 +01:00
|
|
|
|
2012-01-22 11:49:58 +01:00
|
|
|
QupZilla* window = mApp->getWindow();
|
2012-01-21 20:29:33 +01:00
|
|
|
|
2012-01-22 11:49:58 +01:00
|
|
|
if (window) {
|
2012-03-10 13:57:50 +01:00
|
|
|
QNetworkRequest req(urla);
|
|
|
|
req.setRawHeader("Referer", url().toEncoded());
|
|
|
|
|
|
|
|
window->tabWidget()->addView(req, Qz::NT_SelectedTab);
|
2012-01-22 15:15:43 +01:00
|
|
|
window->raise();
|
2012-01-21 20:29:33 +01:00
|
|
|
}
|
2012-01-22 11:49:58 +01:00
|
|
|
}
|
2012-01-21 20:29:33 +01:00
|
|
|
|
2012-01-22 15:15:43 +01:00
|
|
|
void PopupWebView::closeView()
|
|
|
|
{
|
|
|
|
parentWidget()->close();
|
|
|
|
}
|
|
|
|
|
2012-01-22 11:49:58 +01:00
|
|
|
void PopupWebView::contextMenuEvent(QContextMenuEvent* event)
|
|
|
|
{
|
|
|
|
m_menu->clear();
|
2012-01-21 20:29:33 +01:00
|
|
|
|
2012-02-04 19:43:43 +01:00
|
|
|
const QWebHitTestResult &hitTest = page()->mainFrame()->hitTestContent(event->pos());
|
2012-01-21 20:29:33 +01:00
|
|
|
|
2012-01-22 11:49:58 +01:00
|
|
|
createContextMenu(m_menu, hitTest, event->pos());
|
2012-01-21 20:29:33 +01:00
|
|
|
|
|
|
|
if (!m_menu->isEmpty()) {
|
|
|
|
//Prevent choosing first option with double rightclick
|
2012-03-23 17:29:12 +01:00
|
|
|
const QPoint &pos = event->globalPos();
|
2012-01-21 20:29:33 +01:00
|
|
|
QPoint p(pos.x(), pos.y() + 1);
|
|
|
|
m_menu->popup(p);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebView::contextMenuEvent(event);
|
|
|
|
}
|