Bug 1232181 - Notify plugins about scroll state. r=roc
authorJim Mathies <jmathies@mozilla.com>
Tue, 01 Mar 2016 12:48:26 -0600
changeset 322674 ccf462d9fd8531f60125724ea8821bdd5f56dc82
parent 322673 667a8c2d17d22de594030ee8665c03ec162e4b70
child 322675 c03393ef4f1a66a57e5c9021a81d4f2b3f741f46
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1232181
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1232181 - Notify plugins about scroll state. r=roc
dom/plugins/base/nsPluginInstanceOwner.cpp
dom/plugins/base/nsPluginInstanceOwner.h
layout/generic/nsGfxScrollFrame.cpp
layout/generic/nsGfxScrollFrame.h
layout/generic/nsPluginFrame.cpp
--- a/dom/plugins/base/nsPluginInstanceOwner.cpp
+++ b/dom/plugins/base/nsPluginInstanceOwner.cpp
@@ -322,16 +322,31 @@ nsPluginInstanceOwner::GetCurrentImageSi
 {
   nsIntSize size(0,0);
   if (mInstance) {
     mInstance->GetImageSize(&size);
   }
   return size;
 }
 
+bool
+nsPluginInstanceOwner::UpdateScrollState(bool aIsScrolling)
+{
+#if defined(XP_WIN)
+  if (!mInstance) {
+    return false;
+  }
+  mScrollState = aIsScrolling;
+  nsresult rv = mInstance->UpdateScrollState(aIsScrolling);
+  return NS_SUCCEEDED(rv);
+#else
+  return false;
+#endif
+}
+
 nsPluginInstanceOwner::nsPluginInstanceOwner()
 {
   // create nsPluginNativeWindow object, it is derived from NPWindow
   // struct and allows to manipulate native window procedure
   nsCOMPtr<nsIPluginHost> pluginHostCOM = do_GetService(MOZ_PLUGIN_HOST_CONTRACTID);
   mPluginHost = static_cast<nsPluginHost*>(pluginHostCOM.get());
   if (mPluginHost)
     mPluginHost->NewPluginNativeWindow(&mPluginWindow);
@@ -369,16 +384,17 @@ nsPluginInstanceOwner::nsPluginInstanceO
   mFullScreen = false;
   mJavaView = nullptr;
 #endif
 
 #ifdef XP_WIN
   mGotCompositionData = false;
   mSentStartComposition = false;
   mPluginDidNotHandleIMEComposition = false;
+  mScrollState = false;
 #endif
 }
 
 nsPluginInstanceOwner::~nsPluginInstanceOwner()
 {
   if (mWaitingForPaint) {
     nsCOMPtr<nsIContent> content = do_QueryReferent(mContent);
     if (content) {
--- a/dom/plugins/base/nsPluginInstanceOwner.h
+++ b/dom/plugins/base/nsPluginInstanceOwner.h
@@ -224,16 +224,19 @@ public:
     return strncmp(GetPluginName(), aPluginName, strlen(aPluginName)) == 0;
   }
   
   void NotifyPaintWaiter(nsDisplayListBuilder* aBuilder);
 
   // Returns the image container that has our currently displayed image.
   already_AddRefed<mozilla::layers::ImageContainer> GetImageContainer();
 
+  // Notification we receive from nsPluginFrame about scroll state.
+  bool UpdateScrollState(bool aIsScrolling);
+
   void DidComposite();
 
   /**
    * Returns the bounds of the current async-rendered surface. This can only
    * change in response to messages received by the event loop (i.e. not during
    * painting).
    */
   nsIntSize GetCurrentImageSize();
@@ -392,12 +395,15 @@ private:
     NPWindow* mWindow;
     nsPluginInstanceOwner* mInstanceOwner;
     const nsIntSize& mPluginSize;
     const nsIntRect& mDirtyRect;
   };
 #endif
 
   bool mWaitingForPaint;
+#if defined(XP_WIN)
+  bool mScrollState;
+#endif
 };
 
 #endif // nsPluginInstanceOwner_h_
 
--- a/layout/generic/nsGfxScrollFrame.cpp
+++ b/layout/generic/nsGfxScrollFrame.cpp
@@ -2039,19 +2039,23 @@ NotifyPluginSubframesCallback(nsIDocumen
 void
 ScrollFrameHelper::NotifyPluginFrames(AsyncScrollEventType aEvent)
 {
 #if defined(XP_WIN) || defined(MOZ_WIDGET_GTK)
   if (!gfxPrefs::HidePluginsForScroll()) {
     return;
   }
   if (XRE_IsContentProcess()) {
+    // Ignore 'inner' dom events triggered by apz transformations
+    if (mAsyncScrollEvent == BEGIN_APZ && aEvent != END_APZ) {
+      return;
+    }
     if (aEvent != mAsyncScrollEvent) {
       nsPresContext* presContext = mOuter->PresContext();
-      PluginSearchCtx ctx = { mOuter, (aEvent == BEGIN_DOM) };
+      PluginSearchCtx ctx = { mOuter, (aEvent == BEGIN_APZ || aEvent == BEGIN_DOM) };
       presContext->Document()->EnumerateActivityObservers(NotifyPluginFramesCallback,
                                                           (void*)&ctx);
       presContext->Document()->EnumerateSubDocuments(NotifyPluginSubframesCallback,
                                                      (void*)&ctx);
 
       mAsyncScrollEvent = aEvent;
     }
   }
--- a/layout/generic/nsGfxScrollFrame.h
+++ b/layout/generic/nsGfxScrollFrame.h
@@ -374,16 +374,17 @@ public:
 
   void SetTransformingByAPZ(bool aTransforming) {
     mTransformingByAPZ = aTransforming;
     if (!mozilla::css::TextOverflow::HasClippedOverflow(mOuter)) {
       // If the block has some text-overflow stuff we should kick off a paint
       // because we have special behaviour for it when APZ scrolling is active.
       mOuter->SchedulePaint();
     }
+    NotifyPluginFrames(aTransforming ? BEGIN_APZ : END_APZ);
   }
   bool IsTransformingByAPZ() const {
     return mTransformingByAPZ;
   }
   void SetZoomableByAPZ(bool aZoomable);
 
   bool UsesContainerScrolling() const;
 
@@ -581,17 +582,17 @@ protected:
                             = nsIScrollbarMediator::DISABLE_SNAP);
 
   void CompleteAsyncScroll(const nsRect &aRange, nsIAtom* aOrigin = nullptr);
 
   /*
    * Helper that notifies plugins about async smooth scroll operations managed
    * by nsGfxScrollFrame.
    */
-  enum AsyncScrollEventType { BEGIN_DOM, END_DOM };
+  enum AsyncScrollEventType { BEGIN_DOM, BEGIN_APZ, END_DOM, END_APZ };
   void NotifyPluginFrames(AsyncScrollEventType aEvent);
   AsyncScrollEventType mAsyncScrollEvent;
 
   static void EnsureImageVisPrefsCached();
   static bool sImageVisPrefsCached;
   // The number of scrollports wide/high to expand when looking for images.
   static uint32_t sHorzExpandScrollPort;
   static uint32_t sVertExpandScrollPort;
--- a/layout/generic/nsPluginFrame.cpp
+++ b/layout/generic/nsPluginFrame.cpp
@@ -774,17 +774,18 @@ void
 nsPluginFrame::SetScrollVisibility(bool aState)
 {
   // Limit this setting to windowed plugins by checking if we have a widget
   if (mWidget) {
     bool changed = mIsHiddenDueToScroll != aState;
     mIsHiddenDueToScroll = aState;
     // Force a paint so plugin window visibility gets flushed via
     // the compositor.
-    if (changed) {
+    if (changed && mInstanceOwner) {
+      mInstanceOwner->UpdateScrollState(mIsHiddenDueToScroll);
       SchedulePaint();
     }
   }
 }
 
 mozilla::LayoutDeviceIntPoint
 nsPluginFrame::GetRemoteTabChromeOffset()
 {