Bug 1002632: Make an image document's refresh driver receive ticks from the image's clients, & disable its internal timer. r=bz
authorDaniel Holbert <dholbert@cs.stanford.edu>
Thu, 01 May 2014 09:31:54 -0700
changeset 181621 c5aae1b3dc3fadfdd5914fabf1a17c4f91452223
parent 181620 628dd71d10cae45c504179113a6121f74cc40ff1
child 181622 9a6b434b34bec675539d12ce7566bc76f01ceaf1
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersbz
bugs1002632
milestone32.0a1
Bug 1002632: Make an image document's refresh driver receive ticks from the image's clients, & disable its internal timer. r=bz
image/src/SVGDocumentWrapper.cpp
image/src/SVGDocumentWrapper.h
image/src/VectorImage.cpp
layout/base/nsRefreshDriver.cpp
--- a/image/src/SVGDocumentWrapper.cpp
+++ b/image/src/SVGDocumentWrapper.cpp
@@ -213,16 +213,29 @@ void
 SVGDocumentWrapper::SetCurrentTime(float aTime)
 {
   SVGSVGElement* svgElem = GetRootSVGElem();
   if (svgElem && svgElem->GetCurrentTime() != aTime) {
     svgElem->SetCurrentTime(aTime);
   }
 }
 
+void
+SVGDocumentWrapper::TickRefreshDriver()
+{
+  nsCOMPtr<nsIPresShell> presShell;
+  mViewer->GetPresShell(getter_AddRefs(presShell));
+  if (presShell) {
+    nsPresContext* presContext = presShell->GetPresContext();
+    if (presContext) {
+      presContext->RefreshDriver()->DoTick();
+    }
+  }
+}
+
 /** nsIStreamListener methods **/
 
 /* void onDataAvailable (in nsIRequest request, in nsISupports ctxt,
                          in nsIInputStream inStr, in unsigned long sourceOffset,
                          in unsigned long count); */
 NS_IMETHODIMP
 SVGDocumentWrapper::OnDataAvailable(nsIRequest* aRequest, nsISupports* ctxt,
                                     nsIInputStream* inStr,
--- a/image/src/SVGDocumentWrapper.h
+++ b/image/src/SVGDocumentWrapper.h
@@ -133,16 +133,17 @@ public:
   /**
    * Methods to control animation.
    */
   void StartAnimation();
   void StopAnimation();
   void ResetAnimation();
   float GetCurrentTime();
   void SetCurrentTime(float aTime);
+  void TickRefreshDriver();
 
   /**
    * Force a layout flush of the underlying SVG document.
    */
   void FlushLayout();
 
 private:
   nsresult SetupViewer(nsIRequest *aRequest,
--- a/image/src/VectorImage.cpp
+++ b/image/src/VectorImage.cpp
@@ -487,19 +487,20 @@ VectorImage::GetWidth(int32_t* aWidth)
   return NS_OK;
 }
 
 //******************************************************************************
 /* [notxpcom] void requestRefresh ([const] in TimeStamp aTime); */
 NS_IMETHODIMP_(void)
 VectorImage::RequestRefresh(const mozilla::TimeStamp& aTime)
 {
-  // TODO: Implement for b666446.
   EvaluateAnimation();
 
+  mSVGDocumentWrapper->TickRefreshDriver();
+
   if (mHasPendingInvalidation) {
     SendInvalidationNotifications();
     mHasPendingInvalidation = false;
   }
 }
 
 void
 VectorImage::SendInvalidationNotifications()
--- a/layout/base/nsRefreshDriver.cpp
+++ b/layout/base/nsRefreshDriver.cpp
@@ -827,16 +827,23 @@ nsRefreshDriver::EnsureTimerStarted(bool
     return;
 
   if (IsFrozen() || !mPresContext) {
     // If we don't want to start it now, or we've been disconnected.
     StopTimer();
     return;
   }
 
+  if (mPresContext->Document()->IsBeingUsedAsImage()) {
+    // Image documents receive ticks from clients' refresh drivers.
+    MOZ_ASSERT(!mActiveTimer,
+               "image document refresh driver should never have its own timer");
+    return;
+  }
+
   // We got here because we're either adjusting the time *or* we're
   // starting it for the first time.  Add to the right timer,
   // prehaps removing it from a previously-set one.
   RefreshDriverTimer *newTimer = ChooseTimer();
   if (newTimer != mActiveTimer) {
     if (mActiveTimer)
       mActiveTimer->RemoveRefreshDriver(this);
     mActiveTimer = newTimer;