File indexing completed on 2024-05-12 04:58:18
0001 /* ============================================================ 0002 * Falkon - Qt web browser 0003 * Copyright (C) 2010-2017 David Rosca <nowrep@gmail.com> 0004 * 0005 * This program is free software: you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation, either version 3 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 * ============================================================ */ 0018 #include "popupwebview.h" 0019 #include "mainapplication.h" 0020 #include "browserwindow.h" 0021 #include "tabwidget.h" 0022 #include "tabbedwebview.h" 0023 #include "iconprovider.h" 0024 #include "enhancedmenu.h" 0025 #include "loadrequest.h" 0026 #include "webpage.h" 0027 #include "webhittestresult.h" 0028 #include "webinspector.h" 0029 0030 #include <QContextMenuEvent> 0031 0032 PopupWebView::PopupWebView(QWidget* parent) 0033 : WebView(parent) 0034 , m_menu(new Menu(this)) 0035 { 0036 m_menu->setCloseOnMiddleClick(true); 0037 } 0038 0039 QWidget* PopupWebView::overlayWidget() 0040 { 0041 return parentWidget(); 0042 } 0043 0044 void PopupWebView::loadInNewTab(const LoadRequest &req, Qz::NewTabPositionFlags position) 0045 { 0046 Q_UNUSED(position) 0047 0048 BrowserWindow* window = mApp->getWindow(); 0049 0050 if (window) { 0051 int index = window->tabWidget()->addView(QUrl(), Qz::NT_SelectedTab); 0052 window->weView(index)->load(req); 0053 window->raise(); 0054 } 0055 } 0056 0057 void PopupWebView::closeView() 0058 { 0059 window()->close(); 0060 } 0061 0062 bool PopupWebView::isFullScreen() 0063 { 0064 return parentWidget()->isFullScreen(); 0065 } 0066 0067 void PopupWebView::requestFullScreen(bool enable) 0068 { 0069 if (enable) 0070 parentWidget()->showFullScreen(); 0071 else 0072 parentWidget()->showNormal(); 0073 } 0074 0075 void PopupWebView::inspectElement() 0076 { 0077 if (!WebInspector::isEnabled()) 0078 return; 0079 0080 if (m_inspector) { 0081 triggerPageAction(QWebEnginePage::InspectElement); 0082 return; 0083 } 0084 0085 m_inspector = new WebInspector; 0086 m_inspector->setView(this); 0087 m_inspector->inspectElement(); 0088 m_inspector->show(); 0089 } 0090 0091 void PopupWebView::_contextMenuEvent(QContextMenuEvent *event) 0092 { 0093 m_menu->clear(); 0094 0095 WebHitTestResult hitTest = page()->hitTestContent(event->pos()); 0096 createContextMenu(m_menu, hitTest); 0097 0098 if (WebInspector::isEnabled()) { 0099 m_menu->addSeparator(); 0100 m_menu->addAction(tr("Inspect Element"), this, &PopupWebView::inspectElement); 0101 } 0102 0103 if (!m_menu->isEmpty()) { 0104 // Prevent choosing first option with double rightclick 0105 const QPoint pos = event->globalPos(); 0106 QPoint p(pos.x(), pos.y() + 1); 0107 0108 m_menu->popup(p); 0109 return; 0110 } 0111 0112 WebView::_contextMenuEvent(event); 0113 }