Changeset 109548 in webkit


Ignore:
Timestamp:
Mar 2, 2012 3:40:03 AM (12 years ago)
Author:
zoltan@webkit.org
Message:

Suspend/Resume API for pausing timers and animations.
https://bugs.webkit.org/show_bug.cgi?id=76063

Source/WebCore:

Patch by Allan Sandfeld Jensen <allan.jensen@nokia.com> on 2012-03-02
Reviewed by Kenneth Rohde Christiansen.

  • dom/ActiveDOMObject.h:

New ReasonForSuspension: PageWillBePaused.

  • html/HTMLMediaElement.cpp:

(WebCore::HTMLMediaElement::suspend): Handle new ReasonForSuspension.

  • page/Frame.cpp:

(WebCore::Frame::Frame):
(WebCore::Frame::setDocument):
(WebCore::Frame::suspendActiveDOMObjectsAndAnimations):
(WebCore::Frame::resumeActiveDOMObjectsAndAnimations):

  • page/Frame.h:

(WebCore::Frame::activeDOMObjectsAndAnimationsSuspended):

Frame now maintains a state of suspending animation and ActiveDOMObjects,
which is inherited to all child-frames.

  • page/Page.cpp:

(WebCore::Page::suspendActiveDOMObjectsAndAnimations):
(WebCore::Page::resumeActiveDOMObjectsAndAnimations):

  • page/Page.h:

Functions for suspending and resuming active DOM objects and animations in all frames.

  • rendering/RenderObject.cpp:

(WebCore::RenderObject::willRenderImage):

WillRenderImage now checks for suspension. This causes animated images to pause
together with all other types of animations.

Source/WebKit2:

Based on the initial work of Zalan Bujtas <zalan.bujtas@nokia.com>,

Adds suspend and resume API for WebKit2 and uses it in Qt to
suspend animations and DOM timers during panning and zoom.

Patch by Allan Sandfeld Jensen <allan.jensen@nokia.com> on 2012-03-02
Reviewed by Kenneth Rohde Christiansen.

  • UIProcess/API/qt/qquickwebview.cpp:

(QQuickWebViewFlickablePrivate::_q_suspend):
(QQuickWebViewFlickablePrivate::_q_resume):

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::WebPageProxy):
(WebKit::WebPageProxy::resumeActiveDOMObjectsAndAnimations):
(WebKit::WebPageProxy::suspendActiveDOMObjectsAndAnimations):
(WebKit::WebPageProxy::processDidCrash):

  • UIProcess/WebPageProxy.h:
  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::suspendActiveDOMObjectsAndAnimations):
(WebKit::WebPage::resumeActiveDOMObjectsAndAnimations):

  • WebProcess/WebPage/WebPage.h:
  • WebProcess/WebPage/WebPage.messages.in:
Location:
trunk/Source
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r109547 r109548  
     12012-03-02  Allan Sandfeld Jensen  <allan.jensen@nokia.com>
     2
     3        Suspend/Resume API for pausing timers and animations.
     4        https://bugs.webkit.org/show_bug.cgi?id=76063
     5
     6        Reviewed by Kenneth Rohde Christiansen.
     7
     8        * dom/ActiveDOMObject.h:
     9            New ReasonForSuspension: PageWillBePaused.
     10        * html/HTMLMediaElement.cpp:
     11        (WebCore::HTMLMediaElement::suspend): Handle new ReasonForSuspension.
     12        * page/Frame.cpp:
     13        (WebCore::Frame::Frame):
     14        (WebCore::Frame::setDocument):
     15        (WebCore::Frame::suspendActiveDOMObjectsAndAnimations):
     16        (WebCore::Frame::resumeActiveDOMObjectsAndAnimations):
     17        * page/Frame.h:
     18        (WebCore::Frame::activeDOMObjectsAndAnimationsSuspended):
     19            Frame now maintains a state of suspending animation and ActiveDOMObjects,
     20            which is inherited to all child-frames.
     21        * page/Page.cpp:
     22        (WebCore::Page::suspendActiveDOMObjectsAndAnimations):
     23        (WebCore::Page::resumeActiveDOMObjectsAndAnimations):
     24        * page/Page.h:
     25            Functions for suspending and resuming active DOM objects and animations in all frames.
     26        * rendering/RenderObject.cpp:
     27        (WebCore::RenderObject::willRenderImage):
     28            WillRenderImage now checks for suspension. This causes animated images to pause
     29            together with all other types of animations.
     30
    1312012-03-02  Yoshifumi Inoue  <yosin@chromium.org>
    232
  • trunk/Source/WebCore/dom/ActiveDOMObject.h

    r108954 r109548  
    5555        JavaScriptDebuggerPaused,
    5656        WillShowDialog,
    57         DocumentWillBecomeInactive
     57        DocumentWillBecomeInactive,
     58        PageWillBeSuspended
    5859    };
    5960    virtual bool canSuspend() const;
  • trunk/Source/WebCore/html/HTMLMediaElement.cpp

    r109298 r109548  
    34093409{
    34103410    LOG(Media, "HTMLMediaElement::suspend");
    3411    
     3411
    34123412    switch (why)
    34133413    {
     
    34153415            stop();
    34163416            break;
     3417        case PageWillBeSuspended:
    34173418        case JavaScriptDebuggerPaused:
    34183419        case WillShowDialog:
  • trunk/Source/WebCore/page/Frame.cpp

    r109016 r109548  
    167167    , m_isDisconnected(false)
    168168    , m_excludeFromTextSearch(false)
     169    , m_activeDOMObjectsAndAnimationsSuspendedCount(0)
    169170{
    170171    ASSERT(page);
     
    197198    frameCounter.increment();
    198199#endif
     200
     201    // Pause future ActiveDOMObjects if this frame is being created while the page is in a paused state.
     202    Frame* parent = parentFromOwnerElement(ownerElement);
     203    if (parent && parent->activeDOMObjectsAndAnimationsSuspended())
     204        suspendActiveDOMObjectsAndAnimations();
    199205}
    200206
     
    306312        notifyChromeClientWheelEventHandlerCountChanged();
    307313        notifyChromeClientTouchEventHandlerCountChanged();
     314    }
     315
     316    // Suspend document if this frame was created in suspended state.
     317    if (activeDOMObjectsAndAnimationsSuspended()) {
     318        document()->suspendScriptedAnimationControllerCallbacks();
     319        animation()->suspendAnimationsForDocument(document());
     320        document()->suspendActiveDOMObjects(ActiveDOMObject::PageWillBeSuspended);
    308321    }
    309322}
     
    10121025}
    10131026
     1027void Frame::suspendActiveDOMObjectsAndAnimations()
     1028{
     1029    bool wasSuspended = activeDOMObjectsAndAnimationsSuspended();
     1030
     1031    m_activeDOMObjectsAndAnimationsSuspendedCount++;
     1032
     1033    if (wasSuspended)
     1034        return;
     1035
     1036    if (document()) {
     1037        document()->suspendScriptedAnimationControllerCallbacks();
     1038        animation()->suspendAnimationsForDocument(document());
     1039        document()->suspendActiveDOMObjects(ActiveDOMObject::PageWillBeSuspended);
     1040    }
     1041}
     1042
     1043void Frame::resumeActiveDOMObjectsAndAnimations()
     1044{
     1045    ASSERT(activeDOMObjectsAndAnimationsSuspended());
     1046
     1047    m_activeDOMObjectsAndAnimationsSuspendedCount--;
     1048
     1049    if (activeDOMObjectsAndAnimationsSuspended())
     1050        return;
     1051
     1052    if (document()) {
     1053        document()->resumeActiveDOMObjects();
     1054        animation()->resumeAnimationsForDocument(document());
     1055        document()->resumeScriptedAnimationControllerCallbacks();
     1056    }
     1057}
     1058
    10141059#if USE(ACCELERATED_COMPOSITING)
    10151060void Frame::deviceOrPageScaleFactorChanged()
  • trunk/Source/WebCore/page/Frame.h

    r108700 r109548  
    189189        String searchForLabelsBeforeElement(const Vector<String>& labels, Element*, size_t* resultDistance, bool* resultIsInCellAbove);
    190190        String matchLabelsAgainstElement(const Vector<String>& labels, Element*);
    191        
     191
    192192#if PLATFORM(MAC)
    193193        NSImage* selectionImage(bool forceBlackText = false) const;
     
    196196        NSImage* imageFromRect(NSRect) const;
    197197#endif
     198        void suspendActiveDOMObjectsAndAnimations();
     199        void resumeActiveDOMObjectsAndAnimations();
     200        bool activeDOMObjectsAndAnimationsSuspended() const { return m_activeDOMObjectsAndAnimationsSuspendedCount > 0; }
    198201
    199202        // Should only be called on the main frame of a page.
     
    258261#endif
    259262
     263        int m_activeDOMObjectsAndAnimationsSuspendedCount;
    260264    };
    261265
  • trunk/Source/WebCore/page/Page.cpp

    r109379 r109548  
    10971097}
    10981098
     1099void Page::suspendActiveDOMObjectsAndAnimations()
     1100{
     1101    for (Frame* frame = mainFrame(); frame; frame = frame->tree()->traverseNext())
     1102        frame->suspendActiveDOMObjectsAndAnimations();
     1103}
     1104
     1105void Page::resumeActiveDOMObjectsAndAnimations()
     1106{
     1107    for (Frame* frame = mainFrame(); frame; frame = frame->tree()->traverseNext())
     1108        frame->resumeActiveDOMObjectsAndAnimations();
     1109}
     1110
    10991111Page::PageClients::PageClients()
    11001112    : chromeClient(0)
  • trunk/Source/WebCore/page/Page.h

    r109273 r109548  
    329329        void addRelevantUnpaintedObject(RenderObject*, const IntRect& objectPaintRect);
    330330
     331        void suspendActiveDOMObjectsAndAnimations();
     332        void resumeActiveDOMObjectsAndAnimations();
     333
    331334    private:
    332335        void initGroup();
  • trunk/Source/WebCore/rendering/RenderObject.cpp

    r109406 r109548  
    26632663        return false;
    26642664
     2665    // We will not render a new image when Active DOM is suspended
     2666    if (document()->activeDOMObjectsAreSuspended())
     2667        return false;
     2668
    26652669    // If we're not in a window (i.e., we're dormant from being put in the b/f cache or in a background tab)
    26662670    // then we don't want to render either.
  • trunk/Source/WebKit2/ChangeLog

    r109533 r109548  
     12012-03-02  Allan Sandfeld Jensen  <allan.jensen@nokia.com>
     2
     3        Suspend/Resume API for pausing timers and animations.
     4        https://bugs.webkit.org/show_bug.cgi?id=76063
     5
     6        Based on the initial work of Zalan Bujtas <zalan.bujtas@nokia.com>,
     7
     8        Adds suspend and resume API for WebKit2 and uses it in Qt to
     9        suspend animations and DOM timers during panning and zoom.
     10
     11        Reviewed by Kenneth Rohde Christiansen.
     12
     13        * UIProcess/API/qt/qquickwebview.cpp:
     14        (QQuickWebViewFlickablePrivate::_q_suspend):
     15        (QQuickWebViewFlickablePrivate::_q_resume):
     16        * UIProcess/WebPageProxy.cpp:
     17        (WebKit::WebPageProxy::WebPageProxy):
     18        (WebKit::WebPageProxy::resumeActiveDOMObjectsAndAnimations):
     19        (WebKit::WebPageProxy::suspendActiveDOMObjectsAndAnimations):
     20        (WebKit::WebPageProxy::processDidCrash):
     21        * UIProcess/WebPageProxy.h:
     22        * WebProcess/WebPage/WebPage.cpp:
     23        (WebKit::WebPage::suspendActiveDOMObjectsAndAnimations):
     24        (WebKit::WebPage::resumeActiveDOMObjectsAndAnimations):
     25        * WebProcess/WebPage/WebPage.h:
     26        * WebProcess/WebPage/WebPage.messages.in:
     27
    1282012-03-02  Joone Hur  <joone.hur@collabora.co.uk>
    229
  • trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp

    r109326 r109548  
    670670{
    671671    pageIsSuspended = true;
     672    webPageProxy->suspendActiveDOMObjectsAndAnimations();
    672673}
    673674
     
    678679
    679680    pageIsSuspended = false;
     681    webPageProxy->resumeActiveDOMObjectsAndAnimations();
    680682
    681683    if (isTransitioningToNewPage) {
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp

    r109302 r109548  
    187187#endif
    188188    , m_pageID(pageID)
     189    , m_isPageSuspended(false)
    189190#if PLATFORM(MAC)
    190191    , m_isSmartInsertDeleteEnabled(TextChecker::isSmartInsertDeleteEnabled())
     
    11271128}
    11281129
     1130void WebPageProxy::resumeActiveDOMObjectsAndAnimations()
     1131{
     1132    if (!isValid() || !m_isPageSuspended)
     1133        return;
     1134
     1135    m_isPageSuspended = false;
     1136
     1137    process()->send(Messages::WebPage::ResumeActiveDOMObjectsAndAnimations(), m_pageID);
     1138}
     1139
     1140void WebPageProxy::suspendActiveDOMObjectsAndAnimations()
     1141{
     1142    if (!isValid() || m_isPageSuspended)
     1143        return;
     1144
     1145    m_isPageSuspended = true;
     1146
     1147    process()->send(Messages::WebPage::SuspendActiveDOMObjectsAndAnimations(), m_pageID);
     1148}
     1149
    11291150bool WebPageProxy::supportsTextEncoding() const
    11301151{
     
    31923213
    31933214    m_isValid = false;
     3215    m_isPageSuspended = false;
    31943216
    31953217    if (m_mainFrame) {
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.h

    r108570 r109548  
    407407    void setCustomTextEncodingName(const String&);
    408408    String customTextEncodingName() const { return m_customTextEncodingName; }
     409
     410    void resumeActiveDOMObjectsAndAnimations();
     411    void suspendActiveDOMObjectsAndAnimations();
    409412
    410413    double estimatedProgress() const;
     
    993996    uint64_t m_pageID;
    994997
     998    bool m_isPageSuspended;
     999
    9951000#if PLATFORM(MAC)
    9961001    bool m_isSmartInsertDeleteEnabled;
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp

    r109169 r109548  
    16551655    m_userAgent = userAgent;
    16561656}
    1657  
     1657
     1658void WebPage::suspendActiveDOMObjectsAndAnimations()
     1659{
     1660    m_page->suspendActiveDOMObjectsAndAnimations();
     1661}
     1662
     1663void WebPage::resumeActiveDOMObjectsAndAnimations()
     1664{
     1665    m_page->resumeActiveDOMObjectsAndAnimations();
     1666
     1667    // We need to repaint on resume to kickstart animated painting again.
     1668    m_drawingArea->setNeedsDisplay(IntRect(IntPoint(0, 0), m_viewSize));
     1669}
     1670
    16581671IntPoint WebPage::screenToWindow(const IntPoint& point)
    16591672{
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h

    r108570 r109548  
    599599    void setUserAgent(const String&);
    600600    void setCustomTextEncodingName(const String&);
     601    void suspendActiveDOMObjectsAndAnimations();
     602    void resumeActiveDOMObjectsAndAnimations();
    601603
    602604#if PLATFORM(MAC)
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in

    r108570 r109548  
    102102    SetCustomTextEncodingName(WTF::String encodingName)
    103103
     104    SuspendActiveDOMObjectsAndAnimations()
     105    ResumeActiveDOMObjectsAndAnimations()
     106
    104107#if USE(TILED_BACKING_STORE)
    105108    SetFixedVisibleContentRect(WebCore::IntRect rect)
Note: See TracChangeset for help on using the changeset viewer.