Changeset 98448 in webkit
- Timestamp:
- Oct 26, 2011 1:29:00 AM (13 years ago)
- Location:
- trunk/Tools
- Files:
-
- 2 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r98447 r98448 1 2011-10-25 Zeno Albisser <zeno.albisser@nokia.com> 2 3 [Qt][WK2] Remove QtWidgets dependency in MiniBrowser 4 https://bugs.webkit.org/show_bug.cgi?id=70529 5 6 Remove obsolete code for a new QML based implementation 7 of MiniBrowser. 8 Change BrowserWindow to derive from QSGView instead of 9 QMainWindow. QSGView is used as a top level window that 10 provides the container for placing QML content. 11 Make MiniBrowserApplication derive from QGuiApplication 12 instead of QApplication. 13 14 Patch by Jocelyn Turcotte <jocelyn.turcotte@nokia.com>, 15 Zeno Albisser <zeno.albisser@nokia.com> 16 17 Reviewed by Simon Hausmann. 18 19 * MiniBrowser/qt/BrowserView.cpp: Removed. 20 * MiniBrowser/qt/BrowserView.h: Removed. 21 * MiniBrowser/qt/BrowserWindow.cpp: 22 (BrowserWindow::BrowserWindow): 23 (BrowserWindow::load): 24 (BrowserWindow::screenshot): 25 (BrowserWindow::loadURLListFromFile): 26 (BrowserWindow::updateUserAgentList): 27 (BrowserWindow::~BrowserWindow): 28 * MiniBrowser/qt/BrowserWindow.h: 29 * MiniBrowser/qt/MiniBrowser.pro: 30 * MiniBrowser/qt/MiniBrowserApplication.cpp: 31 (MiniBrowserApplication::MiniBrowserApplication): 32 (MiniBrowserApplication::notify): 33 * MiniBrowser/qt/MiniBrowserApplication.h: 34 * MiniBrowser/qt/UrlLoader.cpp: 35 (UrlLoader::UrlLoader): 36 * MiniBrowser/qt/main.cpp: 37 1 38 2011-10-25 Zeno Albisser <zeno.albisser@nokia.com> 2 39 -
trunk/Tools/MiniBrowser/qt/BrowserWindow.cpp
r98447 r98448 34 34 #include "qtouchwebpage.h" 35 35 36 #if 037 // FIXME38 static QWKPage* newPageFunction(QWKPage* page)39 {40 BrowserWindow* window = new BrowserWindow();41 return window->page();42 }43 #endif44 45 WindowWrapper::WindowWrapper(QWindow* window, QWidget* widget)46 : QWidget(widget)47 , m_window(window)48 {49 // Throttle resize events a bit50 m_resizeTimer.setInterval(16);51 m_resizeTimer.setSingleShot(true);52 connect(&m_resizeTimer, SIGNAL(timeout()), this, SLOT(doResize()));53 m_window->setWindowFlags(Qt::FramelessWindowHint);54 }55 56 void WindowWrapper::showEvent(QShowEvent* event)57 {58 QWidget::showEvent(event);59 m_window->setParent(window()->windowHandle());60 m_window->show();61 }62 63 void WindowWrapper::resizeEvent(QResizeEvent* event)64 {65 QWidget::resizeEvent(event);66 if (!m_resizeTimer.isActive())67 m_resizeTimer.start();68 }69 70 void WindowWrapper::doResize()71 {72 m_window->setGeometry(QRect(mapTo(window(), QPoint(0, 0)), size()));73 }74 36 75 37 BrowserWindow::BrowserWindow(WindowOptions* options) 76 38 : m_urlLoader(0) 77 , m_browser(0)78 39 { 79 40 if (options) … … 84 45 } 85 46 86 m_browser = new BrowserView(m_windowOptions.useTouchWebView);87 88 setAttribute(Qt::WA_DeleteOnClose);89 90 connect(webView(), SIGNAL(loadProgressChanged(int)), SLOT(onLoadProgressChanged(int)));91 connect(webView(), SIGNAL(titleChanged(QString)), SLOT(setWindowTitle(QString)));92 connect(webView(), SIGNAL(urlChanged(QUrl)), SLOT(urlChanged(QUrl)));93 94 if (m_windowOptions.printLoadedUrls)95 connect(webView(), SIGNAL(urlChanged(QUrl)), this, SLOT(printURL(QUrl)));96 97 if (QDesktopWebView* const desktopWebView = m_browser->desktopWebView()) {98 connect(desktopWebView, SIGNAL(statusBarMessageChanged(QString)), statusBar(), SLOT(showMessage(QString)));99 connect(desktopWebView, SIGNAL(linkHovered(QUrl, QString)), this, SLOT(onLinkHovered(QUrl, QString)));100 }101 102 setCentralWidget(new WindowWrapper(m_browser, this));103 centralWidget()->setFocus(Qt::OtherFocusReason);104 105 QMenu* fileMenu = menuBar()->addMenu("&File");106 fileMenu->addAction("New Window", this, SLOT(newWindow()), QKeySequence::New);107 fileMenu->addAction("Open File", this, SLOT(openFile()), QKeySequence::Open);108 fileMenu->addSeparator();109 fileMenu->addAction("Quit", this, SLOT(close()));110 111 #if 0112 QMenu* editMenu = menuBar()->addMenu("&Edit");113 QAction* undo = page()->action(QWKPage::Undo);114 undo->setShortcut(QKeySequence(QKeySequence::Undo));115 editMenu->addAction(undo);116 QAction* redo = page()->action(QWKPage::Redo);117 redo->setShortcut(QKeySequence(QKeySequence::Redo));118 editMenu->addAction(redo);119 editMenu->addSeparator();120 121 QMenu* viewMenu = menuBar()->addMenu("&View");122 viewMenu->addAction(page()->action(QWKPage::Stop));123 viewMenu->addAction(page()->action(QWKPage::Reload));124 viewMenu->addSeparator();125 viewMenu->addAction("Take Screen Shot...", this, SLOT(screenshot()));126 #endif127 128 QMenu* windowMenu = menuBar()->addMenu("&Window");129 QAction* toggleFullScreen = windowMenu->addAction("Toggle FullScreen", this, SIGNAL(enteredFullScreenMode(bool)));130 toggleFullScreen->setShortcut(Qt::Key_F11);131 toggleFullScreen->setCheckable(true);132 toggleFullScreen->setChecked(false);133 // When exit fullscreen mode by clicking on the exit area (bottom right corner) we must134 // uncheck the Toggle FullScreen action.135 toggleFullScreen->connect(this, SIGNAL(enteredFullScreenMode(bool)), SLOT(setChecked(bool)));136 connect(this, SIGNAL(enteredFullScreenMode(bool)), this, SLOT(toggleFullScreenMode(bool)));137 138 QMenu* toolsMenu = menuBar()->addMenu("&Develop");139 toolsMenu->addAction("Change User Agent", this, SLOT(showUserAgentDialog()));140 toolsMenu->addSeparator();141 toolsMenu->addAction("Load URLs from file", this, SLOT(loadURLListFromFile()));142 143 m_addressBar = new QLineEdit();144 connect(m_addressBar, SIGNAL(returnPressed()), SLOT(changeLocation()));145 146 QShortcut* selectAddressBar = new QShortcut(Qt::CTRL | Qt::Key_L, this);147 connect(selectAddressBar, SIGNAL(activated()), this, SLOT(openLocation()));148 149 #if 0150 // FIXME151 page()->setCreateNewPageFunction(newPageFunction);152 #endif153 154 47 if (m_windowOptions.startMaximized) 155 setWindowState( windowState() |Qt::WindowMaximized);48 setWindowState(Qt::WindowMaximized); 156 49 else 157 50 resize(800, 600); … … 161 54 void BrowserWindow::load(const QString& url) 162 55 { 163 m_addressBar->setText(url);164 m_browser->load(url);165 }166 167 QObject* BrowserWindow::webView() const168 {169 return m_browser->touchWebView() ? static_cast<QObject*>(m_browser->touchWebView()->page()) : static_cast<QObject*>(m_browser->desktopWebView());170 56 } 171 57 … … 177 63 } 178 64 179 void BrowserWindow::openLocation()180 {181 m_addressBar->selectAll();182 m_addressBar->setFocus();183 }184 185 void BrowserWindow::changeLocation()186 {187 QString string = m_addressBar->text();188 m_browser->load(string);189 }190 191 void BrowserWindow::onLoadProgressChanged(int progress)192 {193 QColor backgroundColor = QApplication::palette().color(QPalette::Base);194 QColor progressColor = QColor(120, 180, 240);195 QPalette pallete = m_addressBar->palette();196 197 if (progress <= 0 || progress >= 100)198 pallete.setBrush(QPalette::Base, backgroundColor);199 else {200 QLinearGradient gradient(0, 0, width(), 0);201 gradient.setColorAt(0, progressColor);202 gradient.setColorAt(((double) progress) / 100, progressColor);203 if (progress != 100)204 gradient.setColorAt((double) progress / 100 + 0.001, backgroundColor);205 pallete.setBrush(QPalette::Base, gradient);206 }207 m_addressBar->setPalette(pallete);208 }209 210 void BrowserWindow::urlChanged(const QUrl& url)211 {212 m_addressBar->setText(url.toString());213 m_browser->requestActivateWindow();214 m_browser->view()->setFocus(true);215 }216 217 void BrowserWindow::openFile()218 {219 static const QString filter("HTML Files (*.htm *.html *.xhtml);;Text Files (*.txt);;Image Files (*.gif *.jpg *.png);;SVG Files (*.svg);;All Files (*)");220 221 QFileDialog fileDialog(this, tr("Open"), QString(), filter);222 fileDialog.setAcceptMode(QFileDialog::AcceptOpen);223 fileDialog.setFileMode(QFileDialog::ExistingFile);224 fileDialog.setOptions(QFileDialog::ReadOnly);225 226 if (fileDialog.exec()) {227 QString selectedFile = fileDialog.selectedFiles()[0];228 if (!selectedFile.isEmpty())229 load(selectedFile);230 }231 }232 233 65 void BrowserWindow::screenshot() 234 66 { 235 QPixmap pixmap = QPixmap::grabWidget(m_browser);236 QLabel* label = 0;237 label = new QLabel;238 label->setAttribute(Qt::WA_DeleteOnClose);239 label->setWindowTitle("Screenshot - Preview");240 label->setPixmap(pixmap);241 label->show();242 243 QString fileName = QFileDialog::getSaveFileName(label, "Screenshot", QString(), QString("PNG File (.png)"));244 if (!fileName.isEmpty()) {245 QRegExp rx("*.png");246 rx.setCaseSensitivity(Qt::CaseInsensitive);247 rx.setPatternSyntax(QRegExp::Wildcard);248 249 if (!rx.exactMatch(fileName))250 fileName += ".png";251 252 pixmap.save(fileName, "png");253 if (label)254 label->setWindowTitle(QString("Screenshot - Saved at %1").arg(fileName));255 }256 }257 258 void BrowserWindow::toggleFullScreenMode(bool enable)259 {260 bool alreadyEnabled = windowState() & Qt::WindowFullScreen;261 if (enable ^ alreadyEnabled)262 setWindowState(windowState() ^ Qt::WindowFullScreen);263 }264 265 void BrowserWindow::showUserAgentDialog()266 {267 #if 0268 // FIXME269 updateUserAgentList();270 271 QDialog dialog(this);272 dialog.setWindowTitle("Change User Agent");273 dialog.resize(size().width() * 0.7, dialog.size().height());274 QVBoxLayout* layout = new QVBoxLayout(&dialog);275 dialog.setLayout(layout);276 277 QComboBox* combo = new QComboBox(&dialog);278 combo->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);279 combo->setEditable(true);280 combo->insertItems(0, m_userAgentList);281 layout->addWidget(combo);282 283 int index = combo->findText(page()->customUserAgent());284 combo->setCurrentIndex(index);285 286 QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel287 , Qt::Horizontal, &dialog);288 connect(buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept()));289 connect(buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject()));290 layout->addWidget(buttonBox);291 292 if (dialog.exec() && !combo->currentText().isEmpty())293 page()->setCustomUserAgent(combo->currentText());294 #endif295 67 } 296 68 297 69 void BrowserWindow::loadURLListFromFile() 298 70 { 299 QString selectedFile;300 selectedFile = QFileDialog::getOpenFileName(this, tr("Load URL list from file")301 , QString(), tr("Text Files (*.txt);;All Files (*)"));302 if (selectedFile.isEmpty())303 return;304 305 m_urlLoader = new UrlLoader(this, selectedFile, 0, 0);306 m_urlLoader->loadNext();307 }308 309 void BrowserWindow::printURL(const QUrl& url)310 {311 QTextStream output(stdout);312 output << "Loaded: " << url.toString() << endl;313 }314 315 void BrowserWindow::onLinkHovered(const QUrl& url, const QString&)316 {317 statusBar()->showMessage(url.toString());318 71 } 319 72 320 73 void BrowserWindow::updateUserAgentList() 321 74 { 322 #if 0323 // FIXME324 QFile file(":/useragentlist.txt");325 326 if (file.open(QIODevice::ReadOnly)) {327 while (!file.atEnd()) {328 QString agent = file.readLine().trimmed();329 if (!m_userAgentList.contains(agent))330 m_userAgentList << agent;331 }332 file.close();333 }334 335 Q_ASSERT(!m_userAgentList.isEmpty());336 QWKPage* wkPage = page();337 if (!(wkPage->customUserAgent().isEmpty() || m_userAgentList.contains(wkPage->customUserAgent())))338 m_userAgentList << wkPage->customUserAgent();339 #endif340 75 } 341 76 … … 343 78 { 344 79 delete m_urlLoader; 345 delete m_addressBar;346 80 } -
trunk/Tools/MiniBrowser/qt/BrowserWindow.h
r96345 r98448 30 30 #define BrowserWindow_h 31 31 32 #include "BrowserView.h"33 34 32 #include "MiniBrowserApplication.h" 35 33 #include <QStringList> 36 34 #include <QTimer> 35 #include <QtDeclarative/QSGView> 37 36 38 37 class UrlLoader; 39 38 40 class WindowWrapper : public QWidget 41 { 42 Q_OBJECT 43 44 public: 45 WindowWrapper(QWindow* window, QWidget* widget = 0); 46 47 protected: 48 void showEvent(QShowEvent* event); 49 void resizeEvent(QResizeEvent* event); 50 51 private slots: 52 void doResize(); 53 54 private: 55 QWindow* m_window; 56 QTimer m_resizeTimer; 57 }; 58 59 class BrowserWindow : public QMainWindow { 39 class BrowserWindow : public QSGView { 60 40 Q_OBJECT 61 41 … … 64 44 ~BrowserWindow(); 65 45 void load(const QString& url); 66 67 46 QObject* webView() const; 68 47 69 48 public slots: 70 49 BrowserWindow* newWindow(const QString& url = "about:blank"); 71 void openLocation();72 73 signals:74 void enteredFullScreenMode(bool on);75 50 76 51 protected slots: 77 void changeLocation();78 void onLoadProgressChanged(int progress);79 void urlChanged(const QUrl&);80 void openFile();81 82 52 void screenshot(); 83 53 84 void toggleFullScreenMode(bool enable);85 86 void showUserAgentDialog();87 88 54 void loadURLListFromFile(); 89 90 void printURL(const QUrl&);91 void onLinkHovered(const QUrl&, const QString&);92 55 93 56 private: … … 96 59 UrlLoader* m_urlLoader; 97 60 WindowOptions m_windowOptions; 98 BrowserView* m_browser;99 QLineEdit* m_addressBar;100 61 QStringList m_userAgentList; 101 62 }; -
trunk/Tools/MiniBrowser/qt/MiniBrowser.pro
r97139 r98448 3 3 4 4 SOURCES += \ 5 BrowserView.cpp \6 5 BrowserWindow.cpp \ 7 6 main.cpp \ … … 11 10 12 11 HEADERS += \ 13 BrowserView.h \14 12 BrowserWindow.h \ 15 13 MiniBrowserApplication.h \ … … 33 31 QT += network declarative 34 32 macx:QT+=xml 35 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets36 33 37 34 linux-* { … … 48 45 } 49 46 50 contains(QT_CONFIG, opengl) {51 QT += opengl52 DEFINES += QT_CONFIGURED_WITH_OPENGL53 }54 55 47 DEFINES -= QT_ASCII_CAST_WARNINGS 56 48 -
trunk/Tools/MiniBrowser/qt/MiniBrowserApplication.cpp
r96931 r98448 62 62 63 63 MiniBrowserApplication::MiniBrowserApplication(int& argc, char** argv) 64 : Q Application(argc, argv, QApplication::GuiServer)64 : QGuiApplication(argc, argv) 65 65 , m_windowOptions() 66 66 , m_realTouchEventReceived(false) … … 83 83 84 84 if (!event->spontaneous() || m_realTouchEventReceived) 85 return Q Application::notify(target, event);85 return QGuiApplication::notify(target, event); 86 86 87 87 if (isTouchEvent(event) && static_cast<QTouchEvent*>(event)->deviceType() == QTouchEvent::TouchScreen) { … … 90 90 else 91 91 m_realTouchEventReceived = true; 92 return Q Application::notify(target, event);92 return QGuiApplication::notify(target, event); 93 93 } 94 94 … … 112 112 case QEvent::MouseMove: 113 113 if (!mouseEvent->buttons() || !m_touchPoints.contains(mouseEvent->buttons())) 114 return Q Application::notify(target, event);114 return QGuiApplication::notify(target, event); 115 115 touchPoint.state = Qt::TouchPointMoved; 116 116 touchPoint.id = mouseEvent->buttons(); … … 118 118 case QEvent::MouseButtonRelease: 119 119 if (mouseEvent->modifiers().testFlag(Qt::ControlModifier)) 120 return Q Application::notify(target, event);120 return QGuiApplication::notify(target, event); 121 121 touchPoint.state = Qt::TouchPointReleased; 122 122 touchPoint.id = mouseEvent->button(); … … 149 149 case Qt::TouchPointStationary: 150 150 // Don't send the event if nothing changed. 151 return Q Application::notify(target, event);151 return QGuiApplication::notify(target, event); 152 152 default: 153 153 eventType = QEvent::TouchUpdate; … … 163 163 m_touchPoints.remove(touchPoint.id); 164 164 } 165 return true; 166 } 167 168 return QApplication::notify(target, event); 165 } 166 167 return QGuiApplication::notify(target, event); 169 168 } 170 169 … … 184 183 << "[-robot-timeout seconds]" 185 184 << "[-robot-extra-time seconds]" 186 << "[-chunked-drawing-area]"187 185 << "[-print-loaded-urls]" 188 #if defined(QT_CONFIGURED_WITH_OPENGL)189 << "[-gl-viewport]"190 #endif191 186 << "URLs"; 192 187 appQuit(0); … … 225 220 m_windowOptions.printLoadedUrls = true; 226 221 227 #if defined(QT_CONFIGURED_WITH_OPENGL) 228 if (args.contains("-gl-viewport")) 229 m_windowOptions.useQGLWidgetViewport = true; 230 #endif 231 } 222 } -
trunk/Tools/MiniBrowser/qt/MiniBrowserApplication.h
r96931 r98448 30 30 #define MiniBrowserApplication_h 31 31 32 #include <QApplication>33 #include <QFileDialog>34 32 #include <QHash> 35 #include <QLabel>36 #include <QLineEdit>37 #include <QMainWindow>38 #include <QMenu>39 #include <QMenuBar>40 #include <QShortcut>41 #include <QStatusBar>42 33 #include <QStringList> 43 #include <QToolBar> 34 #include <QtDeclarative> 35 #include <QtGui/QGuiApplication> 44 36 #include <QTouchEvent> 45 37 #include <QUrl> … … 60 52 bool useTouchWebView; 61 53 bool startMaximized; 62 #if defined(QT_CONFIGURED_WITH_OPENGL)63 bool useQGLWidgetViewport;64 #endif65 54 }; 66 55 67 class MiniBrowserApplication : public Q Application {56 class MiniBrowserApplication : public QGuiApplication { 68 57 Q_OBJECT 69 58 -
trunk/Tools/MiniBrowser/qt/UrlLoader.cpp
r90458 r98448 42 42 connect(&m_checkIfFinishedTimer, SIGNAL(timeout()), this, SLOT(checkIfFinished())); 43 43 // loadStarted and loadFinished on QWebPage is emitted for each frame/sub-frame 44 connect(m_browserWindow->webView(), SIGNAL(loadStarted()), this, SLOT(frameLoadStarted())); 45 connect(m_browserWindow->webView(), SIGNAL(loadFinished(bool)), this, SLOT(frameLoadFinished())); 44 45 // FIXME: Reconnect these signals after Qt5/QtQuick rewrite if necessary. 46 // connect(m_browserWindow->webView(), SIGNAL(loadStarted()), this, SLOT(frameLoadStarted())); 47 // connect(m_browserWindow->webView(), SIGNAL(loadFinished(bool)), this, SLOT(frameLoadFinished())); 46 48 47 49 if (timeoutSeconds) { 48 50 m_timeoutTimer.setInterval(timeoutSeconds * 1000); 49 51 m_timeoutTimer.setSingleShot(true); 50 connect(m_browserWindow->webView(), SIGNAL(loadStarted()), &m_timeoutTimer, SLOT(start())); 52 // FIXME: Reconnect this signal after Qt5/QtQuick rewrite if necessary. 53 // connect(m_browserWindow->webView(), SIGNAL(loadStarted()), &m_timeoutTimer, SLOT(start())); 51 54 connect(&m_timeoutTimer, SIGNAL(timeout()), this, SLOT(loadNext())); 52 55 } -
trunk/Tools/MiniBrowser/qt/main.cpp
r96345 r98448 31 31 #include "MiniBrowserApplication.h" 32 32 #include "UrlLoader.h" 33 #include <QDir> 33 34 #include <QLatin1String> 34 35 #include <QRegExp>
Note: See TracChangeset
for help on using the changeset viewer.