Changeset 56450 in webkit


Ignore:
Timestamp:
Mar 24, 2010 12:05:25 PM (14 years ago)
Author:
kenneth@webkit.org
Message:

WebCore: Add a way to check if the page client is making use of
a QWidget.

Reviewed by Simon Hausmann.

  • platform/qt/QWebPageClient.h:

(QWebPageClient::isQWidgetClient):

WebKit/qt: Calling setView on a QWebPage being shown by a QGraphicsWebView,
would uninstall the page client, resulting in not expected
behaviour.

Reviewed by Simon Hausmann.

  • Api/qwebpage.cpp:

(QWebPageWidgetClient::QWebPageWidgetClient):
(QWebPageWidgetClient::isQWidgetClient):
(QWebPageWidgetClient::screenNumber):
(QWebPage::QWebPage):
(QWebPage::setView):

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r56449 r56450  
     12010-03-23  Kenneth Rohde Christiansen  <kenneth@webkit.org>
     2
     3        Reviewed by Simon Hausmann.
     4
     5        Add a way to check if the page client is making use of
     6        a QWidget.
     7
     8        * platform/qt/QWebPageClient.h:
     9        (QWebPageClient::isQWidgetClient):
     10
    1112010-03-24  Jay Campan  <jcampan@google.com>
    212
  • trunk/WebCore/platform/qt/QWebPageClient.h

    r53802 r56450  
    4141public:
    4242    virtual ~QWebPageClient() { }
    43        
     43
     44    virtual bool isQWidgetClient() const { return false; }
     45
    4446    virtual void scroll(int dx, int dy, const QRect&) = 0;
    4547    virtual void update(const QRect&) = 0;
  • trunk/WebKit/qt/Api/qgraphicswebview.cpp

    r56423 r56450  
    9696
    9797    virtual ~QGraphicsWebViewPrivate();
     98
    9899    virtual void scroll(int dx, int dy, const QRect&);
    99100    virtual void update(const QRect& dirtyRect);
     
    122123    void updateCompositingScrollPosition();
    123124#endif
    124    
     125
    125126    void updateResizesToContentsForPage();
    126127    QRectF graphicsItemVisibleRect() const;
     
    132133
    133134    void syncLayers();
     135
     136    void unsetPageIfExists();
     137
    134138    void _q_doLoadFinished(bool success);
    135139    void _q_contentsSizeChanged(const QSize&);
     
    688692}
    689693
     694void QGraphicsWebViewPrivate::unsetPageIfExists()
     695{
     696    if (!page)
     697        return;
     698
     699    // if the page client is the special client constructed for
     700    // delegating the responsibilities to a QWidget, we need
     701    // to destroy it.
     702
     703    if (page->d->client && page->d->client->isQWidgetClient())
     704        delete page->d->client;
     705
     706    page->d->client = 0;
     707
     708    // if the page was created by us, we own it and need to
     709    // destroy it as well.
     710
     711    if (page->parent() == q)
     712        delete page;
     713    else
     714        page->disconnect(q);
     715}
     716
    690717/*!
    691718    Makes \a page the new web page of the web graphicsitem.
     
    702729        return;
    703730
    704     if (d->page) {
    705         d->page->d->client = 0; // unset the page client
    706         if (d->page->parent() == this)
    707             delete d->page;
    708         else
    709             d->page->disconnect(this);
    710     }
    711 
     731    d->unsetPageIfExists();
    712732    d->page = page;
     733
    713734    if (!d->page)
    714735        return;
     736
     737    d->page->d->client = d; // set the page client
     738
    715739    if (d->overlay)
    716740        d->overlay->prepareGeometryChange();
    717     d->page->d->client = d; // set the page client
    718741
    719742    QSize size = geometry().size().toSize();
    720743    page->setViewportSize(size);
    721    
     744
    722745    if (d->resizesToContents)
    723746        d->updateResizesToContentsForPage();
  • trunk/WebKit/qt/Api/qwebpage.cpp

    r56386 r56450  
    209209    }
    210210
     211    virtual bool isQWidgetClient() const { return true; }
     212
    211213    virtual void scroll(int dx, int dy, const QRect&);
    212214    virtual void update(const QRect& dirtyRect);
     
    282284{
    283285#if defined(Q_WS_X11)
    284     if (view)
    285         return view->x11Info().screen();
    286 #endif
    287 
     286    return view->x11Info().screen();
     287#endif
    288288    return 0;
    289289}
     
    17811781    , d(new QWebPagePrivate(this))
    17821782{
    1783     setView(qobject_cast<QWidget *>(parent));
     1783    setView(qobject_cast<QWidget*>(parent));
    17841784
    17851785    connect(this, SIGNAL(loadProgress(int)), this, SLOT(_q_onLoadProgressChanged(int)));
     
    18651865    \sa view()
    18661866*/
    1867 void QWebPage::setView(QWidget *view)
    1868 {
    1869     if (this->view() != view) {
    1870         d->view = view;
    1871         if (!view) {
    1872             delete d->client;
    1873             d->client = 0;
    1874         } else {
    1875             if (!d->client)
    1876                 d->client = new QWebPageWidgetClient(view);
    1877             else
    1878                 static_cast<QWebPageWidgetClient*>(d->client)->view = view;
    1879         }
    1880         setViewportSize(view ? view->size() : QSize(0, 0));
    1881     }
     1867void QWebPage::setView(QWidget* view)
     1868{
     1869    if (this->view() == view)
     1870        return;
     1871
     1872    d->view = view;
     1873    setViewportSize(view ? view->size() : QSize(0, 0));
     1874
     1875    // If we have no client, we install a special client delegating
     1876    // the responsibility to the QWidget. This is the code path
     1877    // handling a.o. the "legacy" QWebView.
     1878    //
     1879    // If such a special delegate already exist, we substitute the view.
     1880
     1881    if (d->client) {
     1882        if (d->client->isQWidgetClient())
     1883            static_cast<QWebPageWidgetClient*>(d->client)->view = view;
     1884        return;
     1885    }
     1886
     1887    if (view)
     1888        d->client = new QWebPageWidgetClient(view);
    18821889}
    18831890
  • trunk/WebKit/qt/Api/qwebpage.h

    r56051 r56450  
    357357    friend class QWebPagePrivate;
    358358    friend class QWebView;
     359    friend class QWebViewPrivate;
    359360    friend class QGraphicsWebView;
     361    friend class QGraphicsWebViewPrivate;
    360362    friend class QWebInspector;
    361363    friend class WebCore::ChromeClientQt;
  • trunk/WebKit/qt/Api/qwebview.cpp

    r56060 r56450  
    4646
    4747    void _q_pageDestroyed();
     48    void unsetPageIfExists();
    4849
    4950    QWebView *view;
     
    348349}
    349350
     351void QWebViewPrivate::unsetPageIfExists()
     352{
     353    if (!page)
     354        return;
     355
     356    // if the page client is the special client constructed for
     357    // delegating the responsibilities to a QWidget, we need
     358    // to destroy it.
     359
     360    if (page->d->client && page->d->client->isQWidgetClient())
     361        delete page->d->client;
     362
     363    page->d->client = 0;
     364
     365    // if the page was created by us, we own it and need to
     366    // destroy it as well.
     367
     368    if (page->parent() == view)
     369        delete page;
     370    else
     371        page->disconnect(view);
     372}
     373
    350374/*!
    351375    Makes \a page the new web page of the web view.
     
    361385    if (d->page == page)
    362386        return;
    363     if (d->page) {
    364         d->page->d->client = 0; // unset the page client
    365         if (d->page->parent() == this)
    366             delete d->page;
    367         else
    368             d->page->disconnect(this);
    369     }
     387
     388    d->unsetPageIfExists();
    370389    d->page = page;
     390
    371391    if (d->page) {
    372392        d->page->setView(this);
  • trunk/WebKit/qt/ChangeLog

    r56439 r56450  
     12010-03-23  Kenneth Rohde Christiansen  <kenneth@webkit.org>
     2
     3        Reviewed by Simon Hausmann.
     4
     5        Calling setView(0) on a QWebPage being shown by a QGraphicsWebView,
     6        would uninstall the page client, deleting the QGraphicsWebViewPrivate
     7        instance. If called with an argument, it would do a wrong static_cast
     8        and crash.
     9
     10        * Api/qwebpage.cpp:
     11        (QWebPageWidgetClient::QWebPageWidgetClient):
     12        (QWebPageWidgetClient::isQWidgetClient):
     13        (QWebPageWidgetClient::screenNumber):
     14        (QWebPage::QWebPage):
     15        (QWebPage::setView):
     16        * Api/qgraphicswebview.cpp:
     17        (QGraphicsWebViewPrivate::unsetPageIfExists):
     18        (QGraphicsWebView::setPage):
     19        * Api/qwebpage.cpp:
     20        (QWebPageWidgetClient::isQWidgetClient):
     21        (QWebPageWidgetClient::screenNumber):
     22        (QWebPage::QWebPage):
     23        (QWebPage::setView):
     24        * Api/qwebpage.h:
     25        * Api/qwebview.cpp:
     26        (QWebViewPrivate::unsetPageIfExists):
     27        (QWebView::setPage):
     28
    1292010-03-24  Kent Tamura  <tkent@chromium.org>
    230
Note: See TracChangeset for help on using the changeset viewer.