Bug 563327 part 1. Expose an nsIPresShell API for refresh observers. r=roc
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 14 Jun 2010 16:06:49 -0400
changeset 43799 f5054d64d01d3e7612d489505c5074c643f28e3c
parent 43798 391f93244331d0aef74a71ea5c646efd6ab71e97
child 43800 d4156799e66a97931dc6360a42ce795cf5d44801
push idunknown
push userunknown
push dateunknown
reviewersroc
bugs563327
milestone1.9.3a6pre
Bug 563327 part 1. Expose an nsIPresShell API for refresh observers. r=roc
layout/base/nsCSSFrameConstructor.cpp
layout/base/nsIPresShell.h
layout/base/nsPresShell.cpp
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -11743,31 +11743,29 @@ nsCSSFrameConstructor::PostRestyleEventC
 void
 nsCSSFrameConstructor::PostRestyleEventInternal(PRBool aForLazyConstruction)
 {
   // Make sure we're not in a style refresh; if we are, we still have
   // a call to ProcessPendingRestyles coming and there's no need to
   // add ourselves as a refresh observer until then.
   PRBool inRefresh = aForLazyConstruction ? mInLazyFCRefresh : mInStyleRefresh;
   if (!mObservingRefreshDriver && !inRefresh) {
-    mObservingRefreshDriver = mPresShell->GetPresContext()->
-      RefreshDriver()->AddRefreshObserver(this, Flush_Style);
+    mObservingRefreshDriver = mPresShell->AddRefreshObserver(this, Flush_Style);
   }
 }
 
 void
 nsCSSFrameConstructor::WillRefresh(mozilla::TimeStamp aTime)
 {
   NS_ASSERTION(mObservingRefreshDriver, "How did we get here?");
   // Stop observing the refresh driver and flag ourselves as being in
   // a refresh so we don't restart due to animation-triggered
   // restyles.  The actual work of processing our restyles will get
   // done when the refresh driver flushes styles.
-  mPresShell->GetPresContext()->RefreshDriver()->
-    RemoveRefreshObserver(this, Flush_Style);
+  mPresShell->RemoveRefreshObserver(this, Flush_Style);
   mObservingRefreshDriver = PR_FALSE;
   mInLazyFCRefresh = PR_TRUE;
   mInStyleRefresh = PR_TRUE;
 }
 
 void
 nsCSSFrameConstructor::PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint)
 {
--- a/layout/base/nsIPresShell.h
+++ b/layout/base/nsIPresShell.h
@@ -62,16 +62,17 @@
 #include "nsRect.h"
 #include "nsColor.h"
 #include "nsEvent.h"
 #include "nsCompatibility.h"
 #include "nsFrameManagerBase.h"
 #include "mozFlushType.h"
 #include "nsWeakReference.h"
 #include <stdio.h> // for FILE definition
+#include "nsRefreshDriver.h"
 
 class nsIContent;
 class nsIDocument;
 class nsIFrame;
 class nsPresContext;
 class nsStyleSet;
 class nsIViewManager;
 class nsIRenderingContext;
@@ -995,16 +996,47 @@ public:
   /**
    * Keep track of how many times this presshell has been rendered to
    * a window.
    */
   PRUint64 GetPaintCount() { return mPaintCount; }
   void IncrementPaintCount() { ++mPaintCount; }
 
   /**
+   * Refresh observer management.
+   */
+protected:
+  virtual PRBool AddRefreshObserverExternal(nsARefreshObserver* aObserver,
+                                            mozFlushType aFlushType);
+  PRBool AddRefreshObserverInternal(nsARefreshObserver* aObserver,
+                                    mozFlushType aFlushType);
+  virtual PRBool RemoveRefreshObserverExternal(nsARefreshObserver* aObserver,
+                                               mozFlushType aFlushType);
+  PRBool RemoveRefreshObserverInternal(nsARefreshObserver* aObserver,
+                                       mozFlushType aFlushType);
+public:
+  PRBool AddRefreshObserver(nsARefreshObserver* aObserver,
+                            mozFlushType aFlushType) {
+#ifdef _IMPL_NS_LAYOUT
+    return AddRefreshObserverInternal(aObserver, aFlushType);
+#else
+    return AddRefreshObserverExternal(aObserver, aFlushType);
+#endif
+  }
+
+  PRBool RemoveRefreshObserver(nsARefreshObserver* aObserver,
+                               mozFlushType aFlushType) {
+#ifdef _IMPL_NS_LAYOUT
+    return RemoveRefreshObserverInternal(aObserver, aFlushType);
+#else
+    return RemoveRefreshObserverExternal(aObserver, aFlushType);
+#endif
+  }
+
+  /**
    * Initialize and shut down static variables.
    */
   static void InitializeStatics();
   static void ReleaseStatics();
 
 protected:
   // IMPORTANT: The ownership implicit in the following member variables
   // has been explicitly checked.  If you add any members to this class,
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -7744,16 +7744,46 @@ PresShell::Observe(nsISupports* aSubject
   if (!nsCRT::strcmp(aTopic, "a11y-init-or-shutdown")) {
     gIsAccessibilityActive = aData && *aData == '1';
   }
 #endif
   NS_WARNING("unrecognized topic in PresShell::Observe");
   return NS_ERROR_FAILURE;
 }
 
+PRBool
+nsIPresShell::AddRefreshObserverInternal(nsARefreshObserver* aObserver,
+                                         mozFlushType aFlushType)
+{
+  return GetPresContext()->RefreshDriver()->
+    AddRefreshObserver(aObserver, aFlushType);
+}
+
+/* virtual */ PRBool
+nsIPresShell::AddRefreshObserverExternal(nsARefreshObserver* aObserver,
+                                         mozFlushType aFlushType)
+{
+  return AddRefreshObserverInternal(aObserver, aFlushType);
+}
+
+PRBool
+nsIPresShell::RemoveRefreshObserverInternal(nsARefreshObserver* aObserver,
+                                            mozFlushType aFlushType)
+{
+  return GetPresContext()->RefreshDriver()->
+    RemoveRefreshObserver(aObserver, aFlushType);
+}
+
+/* virtual */ PRBool
+nsIPresShell::RemoveRefreshObserverExternal(nsARefreshObserver* aObserver,
+                                            mozFlushType aFlushType)
+{
+  return RemoveRefreshObserverInternal(aObserver, aFlushType);
+}
+
 //------------------------------------------------------
 // End of protected and private methods on the PresShell
 //------------------------------------------------------
 
 // Start of DEBUG only code
 
 #ifdef NS_DEBUG
 #include "nsViewsCID.h"