Changeset 61342 in webkit


Ignore:
Timestamp:
Jun 17, 2010 1:02:22 PM (14 years ago)
Author:
jesus@webkit.org
Message:

Add viewport meta tag support to QtWebKit API layer

[Qt] QtWebKit does not support viewport meta tag
https://bugs.webkit.org/show_bug.cgi?id=39902

Patch by Jesus Sanchez-Palencia <jesus@webkit.org>, Kenneth Rohde Christiansen <kenneth@webkit.org> on 2010-06-01
Reviewed by Simon Hausmann.

WebCore:

Add windowRect() to page client.

  • platform/qt/QWebPageClient.h:

WebKit/qt:

This implements didReceiveViewportArguments in our ChromeClientQt
which is hooked up with QWebPage::viewportChangeRequested().
This signal does not affect the current default behavior.
The documentation of the signal explains how to make use of this new feature.

  • Api/qwebframe_p.h:

(QWebFramePrivate::QWebFramePrivate):
Store information about whether the page has been laid out or not.

  • Api/qwebpage.cpp:

(QWebPage::viewportChangeRequested):

  • Api/qwebpage_p.h:

Added class QtViewportHintsPrivate.

  • Api/qwebpage.h:

(QWebPage::setPreferredContentsSize):
Improved documentation and now only layout if the page had already
passed layout phase.
Added class QWebPage::ViewportHints.

  • WebCoreSupport/ChromeClientQt.cpp:

(WebCore::ChromeClientQt::windowRect):
Modified to work as intended by the DOM, for both QWebView
and QGraphicsWebView.
(WebCore::ChromeClientQt::didReceiveViewportArguments):
Emits the signal QWebPage::viewportChangeRequested.

  • WebCoreSupport/ChromeClientQt.h:
  • WebCoreSupport/FrameLoaderClientQt.cpp:

(WebCore::FrameLoaderClientQt::dispatchDidCommitLoad):
(WebCore::FrameLoaderClientQt::dispatchDidFirstLayout):
Update information about whether the page has been laid out or not.
If the page has been laid out we ignore any further viewport meta data.

  • WebCoreSupport/PageClientQt.cpp:

(WebCore::PageClientQWidget::windowRect):
(WebCore::PageClientQGraphicsWidget::windowRect):
(WebCore::PageClientQGraphicsWidget::graphicsItemVisibleRect):

  • WebCoreSupport/PageClientQt.h:

The PageClient is now responsible for providing the right window rect.

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r61341 r61342  
     12010-06-17  Jesus Sanchez-Palencia  <jesus@webkit.org>, Kenneth Rohde Christiansen  <kenneth@webkit.org>
     2
     3        Reviewed by Simon Hausmann.
     4
     5        [Qt] QtWebKit does not support viewport meta tag
     6        https://bugs.webkit.org/show_bug.cgi?id=39902
     7
     8        Add windowRect() to page client.
     9
     10        * platform/qt/QWebPageClient.h:
     11
    1122010-06-17  Stephen White  <senorblanco@chromium.org>
    213
  • trunk/WebCore/platform/qt/QWebPageClient.h

    r59765 r61342  
    8888
    8989    virtual QStyle* style() const = 0;
    90    
     90
    9191    virtual QRectF graphicsItemVisibleRect() const { return QRectF(); }
    92    
     92
    9393    virtual bool viewResizesToContentsEnabled() const = 0;
     94
     95    virtual QRectF windowRect() const = 0;
    9496
    9597protected:
  • trunk/WebKit/qt/Api/qwebframe_p.h

    r56208 r61342  
    7272        , marginWidth(-1)
    7373        , marginHeight(-1)
     74        , initialLayoutComplete(false)
    7475        {}
    7576    void init(QWebFrame* qframe, QWebFrameData* frameData);
     
    99100    int marginWidth;
    100101    int marginHeight;
     102    bool initialLayoutComplete;
    101103};
    102104
  • trunk/WebKit/qt/Api/qwebpage.cpp

    r61312 r61342  
    16991699*/
    17001700
     1701
     1702/*!
     1703    \class QWebPage::ViewportHints
     1704    \since 4.7
     1705    \brief The QWebPage::ViewportHints class describes hints that can be applied to a viewport.
     1706
     1707    QWebPage::ViewportHints provides a description of a viewport, such as viewport geometry,
     1708    initial scale factor with limits, plus information about whether a user should be able
     1709    to scale the contents in the viewport or not, ie. by zooming.
     1710
     1711    ViewportHints can be set by a web author using the viewport meta tag extension, documented
     1712    at \l{http://developer.apple.com/safari/library/documentation/appleapplications/reference/safariwebcontent/usingtheviewport/usingtheviewport.html}{Safari Reference Library: Using the Viewport Meta Tag}.
     1713
     1714    All values might not be set, as such when dealing with the hints, the developer needs to
     1715    check whether the values are valid. Negative values denote an invalid qreal value.
     1716
     1717    \inmodule QtWebKit
     1718*/
     1719
     1720/*!
     1721    Constructs an empty QWebPage::ViewportHints.
     1722*/
     1723QWebPage::ViewportHints::ViewportHints()
     1724    : d(0)
     1725    , m_initialScaleFactor(-1.0)
     1726    , m_minimumScaleFactor(-1.0)
     1727    , m_maximumScaleFactor(-1.0)
     1728    , m_isUserScalable(true)
     1729    , m_isValid(false)
     1730{
     1731
     1732}
     1733
     1734/*!
     1735    Constructs a QWebPage::ViewportHints which is a copy from \a other .
     1736*/
     1737QWebPage::ViewportHints::ViewportHints(const QWebPage::ViewportHints& other)
     1738    : d(other.d)
     1739    , m_initialScaleFactor(other.m_initialScaleFactor)
     1740    , m_minimumScaleFactor(other.m_minimumScaleFactor)
     1741    , m_maximumScaleFactor(other.m_maximumScaleFactor)
     1742    , m_isUserScalable(other.m_isUserScalable)
     1743    , m_isValid(other.m_isValid)
     1744    , m_size(other.m_size)
     1745{
     1746
     1747}
     1748
     1749/*!
     1750    Destroys the QWebPage::ViewportHints.
     1751*/
     1752QWebPage::ViewportHints::~ViewportHints()
     1753{
     1754
     1755}
     1756
     1757/*!
     1758    Assigns the given QWebPage::ViewportHints to this viewport hints and returns a
     1759    reference to this.
     1760*/
     1761QWebPage::ViewportHints& QWebPage::ViewportHints::operator=(const QWebPage::ViewportHints& other)
     1762{
     1763    if (this != &other) {
     1764        d = other.d;
     1765        m_initialScaleFactor = other.m_initialScaleFactor;
     1766        m_minimumScaleFactor = other.m_minimumScaleFactor;
     1767        m_maximumScaleFactor = other.m_maximumScaleFactor;
     1768        m_isUserScalable = other.m_isUserScalable;
     1769        m_isValid = other.m_isValid;
     1770        m_size = other.m_size;
     1771    }
     1772
     1773    return *this;
     1774}
     1775
     1776/*! \fn inline bool QWebPage::ViewportHints::isValid() const
     1777    Returns whether this is a valid ViewportHints or not.
     1778
     1779    An invalid ViewportHints will have an empty QSize, negative values for scale factors and
     1780    true for the boolean isUserScalable.
     1781*/
     1782
     1783/*! \fn inline QSize QWebPage::ViewportHints::size() const
     1784    Returns the size of the viewport.
     1785*/
     1786
     1787/*! \fn inline qreal QWebPage::ViewportHints::initialScaleFactor() const
     1788    Returns the initial scale of the viewport as a multiplier.
     1789*/
     1790
     1791/*! \fn inline qreal QWebPage::ViewportHints::minimumScaleFactor() const
     1792    Returns the minimum scale value of the viewport as a multiplier.
     1793*/
     1794
     1795/*! \fn inline qreal QWebPage::ViewportHints::maximumScaleFactor() const
     1796    Returns the maximum scale value of the viewport as a multiplier.
     1797*/
     1798
     1799/*! \fn inline bool QWebPage::ViewportHints::isUserScalable() const
     1800    Determines whether or not the scale can be modified by the user.
     1801*/
     1802
     1803
    17011804/*!
    17021805    \class QWebPage
     
    22282331    \property QWebPage::preferredContentsSize
    22292332    \since 4.6
    2230     \brief the preferred size of the contents
    2231 
    2232     If this property is set to a valid size, it is used to lay out the page.
    2233     If it is not set (the default), the viewport size is used instead.
     2333    \brief a custom size used for laying out the page contents.
     2334
     2335    By default all pages are laid out using the viewport of the page as the base.
     2336
     2337    As pages mostly are designed for desktop usage, they often do not layout properly
     2338    on small devices as the contents require a certain view width. For this reason
     2339    it is common to use a different layout size and then scale the contents to fit
     2340    within the actual view.
     2341
     2342    If this property is set to a valid size, this size is used for all layout needs
     2343    instead of the size of the viewport.
     2344
     2345    Setting an invalid size, makes the page fall back to using the viewport size for layout.
    22342346
    22352347    \sa viewportSize
    22362348*/
    2237 void QWebPage::setPreferredContentsSize(const QSize &size) const
    2238 {
     2349void QWebPage::setPreferredContentsSize(const QSize& size) const
     2350{
     2351    // FIXME: Rename this method to setCustomLayoutSize
     2352
    22392353    d->fixedLayoutSize = size;
    22402354
    2241     QWebFrame *frame = mainFrame();
    2242     if (frame->d->frame && frame->d->frame->view()) {
    2243         WebCore::FrameView* view = frame->d->frame->view();
    2244 
    2245         if (size.isValid()) {
    2246             view->setUseFixedLayout(true);
    2247             view->setFixedLayoutSize(size);
    2248             view->layout();
    2249         } else if (view->useFixedLayout()) {
    2250             view->setUseFixedLayout(false);
    2251             view->layout();
    2252         }
    2253     }
     2355    QWebFrame* frame = mainFrame();
     2356    if (!frame->d->frame || !frame->d->frame->view())
     2357        return;
     2358
     2359    WebCore::FrameView* view = frame->d->frame->view();
     2360
     2361    if (size.isValid()) {
     2362        view->setUseFixedLayout(true);
     2363        view->setFixedLayoutSize(size);
     2364    } else if (view->useFixedLayout())
     2365        view->setUseFixedLayout(false);
     2366
     2367    if (frame->d->initialLayoutComplete)
     2368        view->layout();
    22542369}
    22552370
     
    35823697
    35833698/*!
     3699    \since 4.7
     3700    \fn void QWebPage::viewportChangeRequested(const QWebPage::ViewportHints& hints)
     3701
     3702    This signal is emitted before any layout of the contents, giving you the viewport \a arguments
     3703    the web page would like you to use when laying out its contents, including elements fixed to the
     3704    viewport. This viewport might be larger that your actual viewport, meaning that a initialScaleFactor
     3705    should be applied. When no scale is given, it is assumed that the contents should be scaled
     3706    such that the width of the scaled contents fits within the actual viewport.
     3707
     3708    The minimum and maximum allowed scale represents the min and max values that the page
     3709    allows for scaling, and thus, affects the ability to zoom in on the page.
     3710
     3711    Invalid values are supplied for the values not explicitly set by the web author; thus an
     3712    invalid viewport size, and negative values for scale factor and limits. The boolean
     3713    ViewportHints::isUserScalable is set to true.
     3714
     3715    Page authors can provide the supplied values by using the viewport meta tag. More information
     3716    about this can be found at \l{http://developer.apple.com/safari/library/documentation/appleapplications/reference/safariwebcontent/usingtheviewport/usingtheviewport.html}{Safari Reference Library: Using the Viewport Meta Tag}.
     3717
     3718    \sa QWebPage::ViewportHints, setPreferredContentsSize(), QGraphicsWebView::setScale()
     3719*/
     3720
     3721/*!
    35843722    \fn void QWebPage::loadStarted()
    35853723
  • trunk/WebKit/qt/Api/qwebpage.h

    r61117 r61342  
    4343class QWebHistory;
    4444
     45class QWebFrameData;
     46class QWebHistoryItem;
     47class QWebHitTestResult;
     48class QWebNetworkInterface;
    4549class QWebPagePrivate;
    46 class QWebFrameData;
    47 class QWebNetworkInterface;
    4850class QWebPluginFactory;
    49 class QWebHitTestResult;
    50 class QWebHistoryItem;
     51class QtViewportHintsPrivate;
    5152
    5253namespace WebCore {
     
    195196    };
    196197
     198    class ViewportHints {
     199    public:
     200        ViewportHints();
     201        ViewportHints(const QWebPage::ViewportHints& other);
     202
     203        ~ViewportHints();
     204
     205        QWebPage::ViewportHints& operator=(const QWebPage::ViewportHints& other);
     206
     207        inline qreal initialScaleFactor() const { return m_initialScaleFactor; };
     208        inline qreal minimumScaleFactor() const { return m_minimumScaleFactor; };
     209        inline qreal maximumScaleFactor() const { return m_maximumScaleFactor; };
     210        inline bool isUserScalable() const { return m_isUserScalable; };
     211        inline bool isValid() const { return m_isValid; };
     212        inline QSize size() const { return m_size; };
     213
     214    private:
     215        QSharedDataPointer<QtViewportHintsPrivate> d;
     216        qreal m_initialScaleFactor;
     217        qreal m_minimumScaleFactor;
     218        qreal m_maximumScaleFactor;
     219        bool m_isUserScalable;
     220        bool m_isValid;
     221        QSize m_size;
     222
     223        friend class WebCore::ChromeClientQt;
     224    };
     225
     226
    197227    explicit QWebPage(QObject *parent = 0);
    198228    ~QWebPage();
     
    339369    void saveFrameStateRequested(QWebFrame* frame, QWebHistoryItem* item);
    340370    void restoreFrameStateRequested(QWebFrame* frame);
     371
     372    void viewportChangeRequested(const QWebPage::ViewportHints& hints);
    341373
    342374protected:
  • trunk/WebKit/qt/Api/qwebpage_p.h

    r60609 r61342  
    5959class QWebPageClient;
    6060
     61class QtViewportHintsPrivate : public QSharedData {
     62public:
     63    QtViewportHintsPrivate(QWebPage::ViewportHints* qq)
     64        : q(qq)
     65    { }
     66
     67    QWebPage::ViewportHints* q;
     68};
     69
    6170class QWebPagePrivate {
    6271public:
  • trunk/WebKit/qt/ChangeLog

    r61325 r61342  
     12010-06-17  Jesus Sanchez-Palencia  <jesus@webkit.org>, Kenneth Rohde Christiansen  <kenneth@webkit.org>
     2
     3        Reviewed by Simon Hausmann.
     4
     5        [Qt] QtWebKit does not support viewport meta tag
     6        https://bugs.webkit.org/show_bug.cgi?id=39902
     7
     8        Add viewport meta tag support to QtWebKit API layer.
     9
     10        This implements didReceiveViewportArguments in our ChromeClientQt
     11        which is hooked up with QWebPage::viewportChangeRequested().
     12        This signal does not affect the current default behavior.
     13        The documentation of the signal explains how to make use of this new feature.
     14
     15        * Api/qwebframe_p.h:
     16        (QWebFramePrivate::QWebFramePrivate):
     17        Store information about whether the page has been laid out or not.
     18        * Api/qwebpage.cpp:
     19        (QWebPage::viewportChangeRequested):
     20        * Api/qwebpage_p.h:
     21        Added class QtViewportHintsPrivate.
     22        * Api/qwebpage.h:
     23        (QWebPage::setPreferredContentsSize):
     24        Improved documentation and now only layout if the page had already
     25        passed layout phase.
     26        Added class QWebPage::ViewportHints.
     27        * WebCoreSupport/ChromeClientQt.cpp:
     28        (WebCore::ChromeClientQt::windowRect):
     29        Modified to work as intended by the DOM, for both QWebView
     30        and QGraphicsWebView.
     31        (WebCore::ChromeClientQt::didReceiveViewportArguments):
     32        Emits the signal QWebPage::viewportChangeRequested.
     33        * WebCoreSupport/ChromeClientQt.h:
     34        * WebCoreSupport/FrameLoaderClientQt.cpp:
     35        (WebCore::FrameLoaderClientQt::dispatchDidCommitLoad):
     36        (WebCore::FrameLoaderClientQt::dispatchDidFirstLayout):
     37        Update information about whether the page has been laid out or not.
     38        If the page has been laid out we ignore any further viewport meta data.
     39        * WebCoreSupport/PageClientQt.cpp:
     40        (WebCore::PageClientQWidget::windowRect):
     41        (WebCore::PageClientQGraphicsWidget::windowRect):
     42        (WebCore::PageClientQGraphicsWidget::graphicsItemVisibleRect):
     43        * WebCoreSupport/PageClientQt.h:
     44        The PageClient is now responsible for providing the right window rect.
     45
    1462010-06-17  Alexis Menard  <alexis.menard@nokia.com>
    247
  • trunk/WebKit/qt/WebCoreSupport/ChromeClientQt.cpp

    r61117 r61342  
    3838#include "FrameView.h"
    3939#include "Geolocation.h"
     40#if USE(ACCELERATED_COMPOSITING)
     41#include "GraphicsLayerQt.h"
     42#endif
    4043#include "HitTestResult.h"
    4144#include "Icon.h"
    4245#include "NotImplemented.h"
    4346#include "NotificationPresenterClientQt.h"
    44 #include "ScrollbarTheme.h"
    45 #include "WindowFeatures.h"
     47#include "PageClientQt.h"
    4648#if defined(Q_WS_MAEMO_5)
    4749#include "QtMaemoWebPopup.h"
     
    5052#endif
    5153#include "QWebPageClient.h"
     54#include "ScrollbarTheme.h"
    5255#include "SecurityOrigin.h"
    53 
     56#include "ViewportArguments.h"
     57#include "WindowFeatures.h"
     58
     59#include "qgraphicswebview.h"
    5460#include "qwebframe_p.h"
    5561#include "qwebpage.h"
     
    5864#include "qwebsecurityorigin_p.h"
    5965#include "qwebview.h"
    60 
    6166#include <qdebug.h>
    6267#include <qeventloop.h>
     
    6469#include <qtooltip.h>
    6570
    66 #if USE(ACCELERATED_COMPOSITING)
    67 #include "GraphicsLayerQt.h"
    68 #endif
    69 
    7071namespace WebCore {
    7172
     
    9192}
    9293
    93 
     94/*!
     95    windowRect represents the rect of the Window, including all interface elements
     96    like toolbars/scrollbars etc. It is used by the viewport meta tag as well as
     97    by the DOM Window object: outerHeight(), outerWidth(), screenX(), screenY().
     98*/
    9499FloatRect ChromeClientQt::windowRect()
    95100{
    96     if (!m_webPage)
     101    if (!platformPageClient())
    97102        return FloatRect();
    98 
    99     QWidget* view = m_webPage->view();
    100     if (!view)
    101         return FloatRect();
    102     return IntRect(view->window()->geometry());
    103 }
    104 
     103    return platformPageClient()->windowRect();
     104}
    105105
    106106FloatRect ChromeClientQt::pageRect()
     
    627627#endif
    628628
    629 }
     629void ChromeClientQt::didReceiveViewportArguments(Frame* frame, const ViewportArguments& arguments) const
     630{
     631    if (m_webPage->mainFrame()->d->initialLayoutComplete)
     632        return;
     633
     634    QSize viewportSize(arguments.width, arguments.height);
     635    bool isUserScalable = arguments.userScalable == 1;
     636
     637    QWebPage::ViewportHints hints;
     638    hints.m_isValid = true;
     639    hints.m_size = viewportSize;
     640    hints.m_initialScaleFactor = arguments.initialScale;
     641    hints.m_minimumScaleFactor = arguments.minimumScale;
     642    hints.m_maximumScaleFactor = arguments.maximumScale;
     643    hints.m_isUserScalable = isUserScalable;
     644
     645    emit m_webPage->viewportChangeRequested(hints);
     646}
     647
     648} // namespace WebCore
  • trunk/WebKit/qt/WebCoreSupport/ChromeClientQt.h

    r59611 r61342  
    4949    struct FrameLoadRequest;
    5050    class QtAbstractWebPopup;
     51    struct ViewportArguments;
    5152
    5253    class ChromeClientQt : public ChromeClient
     
    178179        QtAbstractWebPopup* createSelectPopup();
    179180
     181        virtual void didReceiveViewportArguments(Frame*, const ViewportArguments&) const;
     182
    180183        QWebPage* m_webPage;
    181184        WebCore::KURL lastHoverURL;
  • trunk/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp

    r61110 r61342  
    381381        return;
    382382
     383    m_webFrame->d->initialLayoutComplete = false;
     384
    383385    emit m_webFrame->urlChanged(m_webFrame->url());
    384386    m_webFrame->page()->d->updateNavigationActions();
     
    388390    // This properly resets the title when we navigate to a URI without a title.
    389391    emit titleChanged(String());
     392
     393    bool isMainFrame = (m_frame == m_frame->page()->mainFrame());
     394    if (!isMainFrame)
     395        return;
     396
     397    emit m_webFrame->page()->viewportChangeRequested(QWebPage::ViewportHints());
    390398}
    391399
     
    425433void FrameLoaderClientQt::dispatchDidFirstLayout()
    426434{
    427     notImplemented();
     435    m_webFrame->d->initialLayoutComplete = true;
    428436}
    429437
  • trunk/WebKit/qt/WebCoreSupport/PageClientQt.cpp

    r60041 r61342  
    104104}
    105105
     106QRectF PageClientQWidget::windowRect() const
     107{
     108    return QRectF(view->window()->geometry());
     109}
     110
    106111PageClientQGraphicsWidget::~PageClientQGraphicsWidget()
    107112{
     
    293298#if ENABLE(TILED_BACKING_STORE)
    294299QRectF PageClientQGraphicsWidget::graphicsItemVisibleRect() const
    295 { 
     300{
    296301    if (!view->scene())
    297302        return QRectF();
     
    300305    if (views.isEmpty())
    301306        return QRectF();
    302    
     307
    303308    QGraphicsView* graphicsView = views.at(0);
    304309    int xOffset = graphicsView->horizontalScrollBar()->value();
     
    318323}
    319324
    320 
    321 
    322 }
     325QRectF PageClientQGraphicsWidget::windowRect() const
     326{
     327    if (!view->scene())
     328        return QRectF();
     329
     330    // The sceneRect is a good approximation of the size of the application, independent of the view.
     331    return view->scene()->sceneRect();
     332}
     333
     334} // namespace WebCore
  • trunk/WebKit/qt/WebCoreSupport/PageClientQt.h

    r60929 r61342  
    7777
    7878    virtual QStyle* style() const;
    79    
     79
    8080    virtual bool viewResizesToContentsEnabled() const { return false; }
     81
     82    virtual QRectF windowRect() const;
    8183
    8284    QWidget* view;
     
    183185#endif
    184186
     187    virtual QRectF windowRect() const;
     188
    185189    QGraphicsWidget* view;
    186190    QWebPage* page;
Note: See TracChangeset for help on using the changeset viewer.