Title: [114900] trunk
Revision
114900
Author
kbal...@webkit.org
Date
2012-04-23 07:56:40 -0700 (Mon, 23 Apr 2012)

Log Message

[Qt] Add desktop zooming support for QQuickWebView
https://bugs.webkit.org/show_bug.cgi?id=82337

Reviewed by Simon Hausmann.

Source/WebKit2:

Add private C++ API for programmatic zooming.
This is important on desktop where we don't
have any way to zoom currently.

* UIProcess/API/qt/qquickwebview.cpp:
(QQuickWebViewLegacyPrivate::zoomFactor):
(QQuickWebViewLegacyPrivate::setZoomFactor):
(QQuickWebView::zoomFactor):
(QQuickWebView::setZoomFactor):
* UIProcess/API/qt/qquickwebview_p.h:
* UIProcess/API/qt/qquickwebview_p_p.h:
(QQuickWebViewPrivate::zoomFactor):
(QQuickWebViewPrivate::setZoomFactor):
(QQuickWebViewPrivate):
(QQuickWebViewLegacyPrivate):

Tools:

Add zooming support for MiniBrowser to
test the new API.

* MiniBrowser/qt/BrowserWindow.cpp:
(BrowserWindow::BrowserWindow):
(BrowserWindow::zoomIn):
(BrowserWindow::zoomOut):
(BrowserWindow::keyPressEvent):
(BrowserWindow::wheelEvent):
* MiniBrowser/qt/BrowserWindow.h:
(BrowserWindow):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (114899 => 114900)


--- trunk/Source/WebKit2/ChangeLog	2012-04-23 14:55:31 UTC (rev 114899)
+++ trunk/Source/WebKit2/ChangeLog	2012-04-23 14:56:40 UTC (rev 114900)
@@ -1,3 +1,26 @@
+2012-04-23  Balazs Kelemen  <kbal...@webkit.org>
+
+        [Qt] Add desktop zooming support for QQuickWebView
+        https://bugs.webkit.org/show_bug.cgi?id=82337
+
+        Reviewed by Simon Hausmann.
+
+        Add private C++ API for programmatic zooming.
+        This is important on desktop where we don't
+        have any way to zoom currently.
+
+        * UIProcess/API/qt/qquickwebview.cpp:
+        (QQuickWebViewLegacyPrivate::zoomFactor):
+        (QQuickWebViewLegacyPrivate::setZoomFactor):
+        (QQuickWebView::zoomFactor):
+        (QQuickWebView::setZoomFactor):
+        * UIProcess/API/qt/qquickwebview_p.h:
+        * UIProcess/API/qt/qquickwebview_p_p.h:
+        (QQuickWebViewPrivate::zoomFactor):
+        (QQuickWebViewPrivate::setZoomFactor):
+        (QQuickWebViewPrivate):
+        (QQuickWebViewLegacyPrivate):
+
 2012-04-23  Zalan Bujtas  <zbuj...@gmail.com>
 
         [Qt][WK2] Move non-api classes to WebKit namespace at WebKit2/UiProcess/qt

Modified: trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp (114899 => 114900)


--- trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp	2012-04-23 14:55:31 UTC (rev 114899)
+++ trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp	2012-04-23 14:56:40 UTC (rev 114900)
@@ -529,6 +529,16 @@
     q->setAcceptHoverEvents(false);
 }
 
+qreal QQuickWebViewLegacyPrivate::zoomFactor() const
+{
+    return webPageProxy->pageZoomFactor();
+}
+
+void QQuickWebViewLegacyPrivate::setZoomFactor(qreal factor)
+{
+    webPageProxy->setPageZoomFactor(factor);
+}
+
 QQuickWebViewFlickablePrivate::QQuickWebViewFlickablePrivate(QQuickWebView* viewport)
     : QQuickWebViewPrivate(viewport)
     , pageIsSuspended(true)
@@ -1452,4 +1462,17 @@
     d->updateContentsSize(size);
 }
 
+qreal QQuickWebView::zoomFactor() const
+{
+    Q_D(const QQuickWebView);
+    return d->zoomFactor();
+}
+
+void QQuickWebView::setZoomFactor(qreal factor)
+{
+
+    Q_D(QQuickWebView);
+    d->setZoomFactor(factor);
+}
+
 #include "moc_qquickwebview_p.cpp"

Modified: trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h (114899 => 114900)


--- trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h	2012-04-23 14:55:31 UTC (rev 114899)
+++ trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h	2012-04-23 14:56:40 UTC (rev 114900)
@@ -144,6 +144,10 @@
     void updateContentsSize(const QSizeF&);
     QPointF pageItemPos();
 
+    // Private C++-only API.
+    qreal zoomFactor() const;
+    void setZoomFactor(qreal);
+
 public Q_SLOTS:
     void loadHtml(const QString& html, const QUrl& baseUrl = QUrl());
 

Modified: trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h (114899 => 114900)


--- trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h	2012-04-23 14:55:31 UTC (rev 114899)
+++ trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h	2012-04-23 14:56:40 UTC (rev 114900)
@@ -90,6 +90,9 @@
     virtual void _q_resume() { }
     virtual void _q_contentViewportChanged(const QPointF& trajectory) { };
 
+    virtual qreal zoomFactor() const { return 1; }
+    virtual void setZoomFactor(qreal) { }
+
     void _q_onVisibleChanged();
     void _q_onUrlChanged();
     void _q_onReceivedResponseFromDownload(QWebDownloadItem*);
@@ -181,6 +184,9 @@
     virtual void updateViewportSize();
     virtual void enableMouseEvents();
     virtual void disableMouseEvents();
+
+    qreal zoomFactor() const;
+    void setZoomFactor(qreal);
 };
 
 class QQuickWebViewFlickablePrivate : public QQuickWebViewPrivate {

Modified: trunk/Tools/ChangeLog (114899 => 114900)


--- trunk/Tools/ChangeLog	2012-04-23 14:55:31 UTC (rev 114899)
+++ trunk/Tools/ChangeLog	2012-04-23 14:56:40 UTC (rev 114900)
@@ -1,3 +1,22 @@
+2012-04-23  Balazs Kelemen  <kbal...@webkit.org>
+
+        [Qt] Add desktop zooming support for QQuickWebView
+        https://bugs.webkit.org/show_bug.cgi?id=82337
+
+        Reviewed by Simon Hausmann.
+
+        Add zooming support for MiniBrowser to
+        test the new API.
+
+        * MiniBrowser/qt/BrowserWindow.cpp:
+        (BrowserWindow::BrowserWindow):
+        (BrowserWindow::zoomIn):
+        (BrowserWindow::zoomOut):
+        (BrowserWindow::keyPressEvent):
+        (BrowserWindow::wheelEvent):
+        * MiniBrowser/qt/BrowserWindow.h:
+        (BrowserWindow):
+
 2012-04-23  Csaba Osztrogonác  <o...@webkit.org>
 
         Unreviewed rolling out r114881, because it broke upload buildstep.

Modified: trunk/Tools/MiniBrowser/qt/BrowserWindow.cpp (114899 => 114900)


--- trunk/Tools/MiniBrowser/qt/BrowserWindow.cpp	2012-04-23 14:55:31 UTC (rev 114899)
+++ trunk/Tools/MiniBrowser/qt/BrowserWindow.cpp	2012-04-23 14:56:40 UTC (rev 114900)
@@ -66,6 +66,13 @@
 
     if (!options->userAgent().isNull())
         webViewExperimental()->setUserAgent(options->userAgent());
+
+    // Zoom values are chosen to be like in Mozilla Firefox 3.
+    m_zoomLevels << 0.3 << 0.5 << 0.67 << 0.8 << 0.9
+                 << 1
+                 << 1.11 << 1.12 << 1.33 << 1.5 << 1.7 << 2 << 2.4 << 3;
+
+    m_currentZoomLevel = m_zoomLevels.indexOf(1);
 }
 
 QQuickWebView* BrowserWindow::webView() const
@@ -139,3 +146,49 @@
         title = QLatin1String("MiniBrowser");
     setWindowTitle(title);
 }
+
+void BrowserWindow::zoomIn()
+{
+    if (m_currentZoomLevel < m_zoomLevels.size() - 1)
+        ++m_currentZoomLevel;
+    webView()->setZoomFactor(m_zoomLevels[m_currentZoomLevel]);
+}
+
+void BrowserWindow::zoomOut()
+{
+    if (m_currentZoomLevel > 0)
+        --m_currentZoomLevel;
+    webView()->setZoomFactor(m_zoomLevels[m_currentZoomLevel]);
+}
+
+void BrowserWindow::keyPressEvent(QKeyEvent* event)
+{
+
+    if (event->modifiers() & Qt::ControlModifier) {
+        bool handled;
+        if ((handled = event->key() == Qt::Key_Plus))
+            zoomIn();
+        else if ((handled = event->key() == Qt::Key_Minus))
+            zoomOut();
+
+        if (handled) {
+            event->accept();
+            return;
+        }
+    }
+    QQuickView::keyPressEvent(event);
+}
+
+void BrowserWindow::wheelEvent(QWheelEvent* event)
+{
+    if (event->modifiers() & Qt::ControlModifier && event->orientation() == Qt::Vertical) {
+        if (event->delta() > 0)
+            zoomIn();
+        else
+            zoomOut();
+
+        event->accept();
+        return;
+    }
+    QQuickView::wheelEvent(event);
+}

Modified: trunk/Tools/MiniBrowser/qt/BrowserWindow.h (114899 => 114900)


--- trunk/Tools/MiniBrowser/qt/BrowserWindow.h	2012-04-23 14:55:31 UTC (rev 114899)
+++ trunk/Tools/MiniBrowser/qt/BrowserWindow.h	2012-04-23 14:56:40 UTC (rev 114900)
@@ -60,7 +60,15 @@
     void onTitleChanged(QString);
 
 private:
+    void zoomIn();
+    void zoomOut();
+
+    virtual void keyPressEvent(QKeyEvent*);
+    virtual void wheelEvent(QWheelEvent*);
+
     WindowOptions* m_windowOptions;
+    QVector<qreal> m_zoomLevels;
+    unsigned m_currentZoomLevel;
 };
 
 #endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to