Bug 959847. Part 10. Implement GetBounds, GetOpaqueRegion, and ShouldBuildLayerEvenIfInvisible for nsDisplaySubDocument items that are being used as scrollable layers like scroll layer items. r=roc
authorTimothy Nikkel <tnikkel@gmail.com>
Thu, 27 Feb 2014 16:01:54 -0600
changeset 171562 4432a2475f491e3784b7076f4ded2fe149b9247a
parent 171561 33a413a575e614a8d8bfaf95204c392d80da77a0
child 171563 d5595e7a7a3ce3732a287c202eabeffd6913ad72
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersroc
bugs959847
milestone30.0a1
Bug 959847. Part 10. Implement GetBounds, GetOpaqueRegion, and ShouldBuildLayerEvenIfInvisible for nsDisplaySubDocument items that are being used as scrollable layers like scroll layer items. r=roc
layout/base/nsDisplayList.cpp
layout/base/nsDisplayList.h
--- a/layout/base/nsDisplayList.cpp
+++ b/layout/base/nsDisplayList.cpp
@@ -3486,16 +3486,30 @@ nsDisplaySubDocument::BuildLayer(nsDispl
                        (usingDisplayport ? &displayport : nullptr),
                        (usingCriticalDisplayport ? &criticalDisplayport : nullptr),
                        scrollId, isRootContentDocument, aContainerParameters);
   }
 
   return layer.forget();
 }
 
+nsRect
+nsDisplaySubDocument::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap)
+{
+  nsIFrame* rootScrollFrame = mFrame->PresContext()->PresShell()->GetRootScrollFrame();
+  nsIContent* content = rootScrollFrame ? rootScrollFrame->GetContent() : nullptr;
+  bool usingDisplayPort = content && nsLayoutUtils::GetDisplayPort(content);
+  if ((mFlags & GENERATE_SCROLLABLE_LAYER) && usingDisplayPort) {
+    *aSnap = false;
+    return mFrame->GetRect() + aBuilder->ToReferenceFrame(mFrame);
+  }
+
+  return nsDisplayOwnLayer::GetBounds(aBuilder, aSnap);
+}
+
 bool
 nsDisplaySubDocument::ComputeVisibility(nsDisplayListBuilder* aBuilder,
                                         nsRegion* aVisibleRegion,
                                         const nsRect& aAllowVisibleRegionExpansion)
 {
   nsIFrame* rootScrollFrame = mFrame->PresContext()->PresShell()->GetRootScrollFrame();
   nsIContent* content = rootScrollFrame ? rootScrollFrame->GetContent() : nullptr;
   nsRect displayport;
@@ -3520,16 +3534,43 @@ nsDisplaySubDocument::ComputeVisibility(
     aBuilder, &childVisibleRegion, boundedRect, allowExpansion);
   // We don't allow this computation to influence aVisibleRegion, on the
   // assumption that the layer can be asynchronously scrolled so we'll
   // definitely need all the content under it.
 
   return visible;
 }
 
+bool
+nsDisplaySubDocument::ShouldBuildLayerEvenIfInvisible(nsDisplayListBuilder* aBuilder)
+{
+  nsIFrame* rootScrollFrame = mFrame->PresContext()->PresShell()->GetRootScrollFrame();
+  nsIContent* content = rootScrollFrame ? rootScrollFrame->GetContent() : nullptr;
+  bool usingDisplayPort = content && nsLayoutUtils::GetDisplayPort(content);
+  if ((mFlags & GENERATE_SCROLLABLE_LAYER) && usingDisplayPort) {
+    return true;
+  }
+
+  return nsDisplayOwnLayer::ShouldBuildLayerEvenIfInvisible(aBuilder);
+}
+
+nsRegion
+nsDisplaySubDocument::GetOpaqueRegion(nsDisplayListBuilder* aBuilder, bool* aSnap)
+{
+  nsIFrame* rootScrollFrame = mFrame->PresContext()->PresShell()->GetRootScrollFrame();
+  nsIContent* content = rootScrollFrame ? rootScrollFrame->GetContent() : nullptr;
+  bool usingDisplayPort = content && nsLayoutUtils::GetDisplayPort(content);
+  if ((mFlags & GENERATE_SCROLLABLE_LAYER) && usingDisplayPort) {
+    *aSnap = false;
+    return nsRegion();
+  }
+
+  return nsDisplayOwnLayer::GetOpaqueRegion(aBuilder, aSnap);
+}
+
 nsDisplayResolution::nsDisplayResolution(nsDisplayListBuilder* aBuilder,
                                          nsIFrame* aFrame, nsDisplayList* aList,
                                          uint32_t aFlags)
     : nsDisplaySubDocument(aBuilder, aFrame, aList, aFlags) {
   MOZ_COUNT_CTOR(nsDisplayResolution);
 }
 
 #ifdef NS_BUILD_REFCNT_LOGGING
--- a/layout/base/nsDisplayList.h
+++ b/layout/base/nsDisplayList.h
@@ -2716,22 +2716,28 @@ public:
 #ifdef NS_BUILD_REFCNT_LOGGING
   virtual ~nsDisplaySubDocument();
 #endif
 
   virtual already_AddRefed<Layer> BuildLayer(nsDisplayListBuilder* aBuilder,
                                              LayerManager* aManager,
                                              const ContainerLayerParameters& aContainerParameters) MOZ_OVERRIDE;
 
+  virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) MOZ_OVERRIDE;
+
   virtual bool ComputeVisibility(nsDisplayListBuilder* aBuilder,
                                  nsRegion* aVisibleRegion,
                                  const nsRect& aAllowVisibleRegionExpansion) MOZ_OVERRIDE;
 
   virtual bool SetVisibleRegionOnLayer() MOZ_OVERRIDE { return !(mFlags & GENERATE_SCROLLABLE_LAYER); }
 
+  virtual bool ShouldBuildLayerEvenIfInvisible(nsDisplayListBuilder* aBuilder) MOZ_OVERRIDE;
+
+  virtual nsRegion GetOpaqueRegion(nsDisplayListBuilder* aBuilder, bool* aSnap) MOZ_OVERRIDE;
+
   NS_DISPLAY_DECL_NAME("SubDocument", TYPE_SUBDOCUMENT)
 };
 
 /**
  * A display item for subdocuments to capture the resolution from the presShell
  * and ensure that it gets applied to all the right elements. This item creates
  * a container layer.
  */