Bug 605618 Part 7: Include viewport and content size in API r=cjones sr=roc
authorBenjamin Stover <bstover@mozilla.com>
Thu, 13 Jan 2011 09:45:14 -0800
changeset 60449 c6fc0670d20e014aa4fe6e92e21934229f2725c1
parent 60448 de3d3de254de6dca4bd1a086e1cbea84e24c5aca
child 60450 ac1db442474583464da0e729db9c51547c11ac63
push id17995
push userbstover@mozilla.com
push dateThu, 13 Jan 2011 17:45:35 +0000
treeherdermozilla-central@b0c723496180 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscjones, roc
bugs605618
milestone2.0b10pre
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 605618 Part 7: Include viewport and content size in API r=cjones sr=roc
content/base/public/nsIFrameLoader.idl
content/base/src/nsFrameLoader.cpp
content/base/src/nsFrameLoader.h
gfx/layers/Layers.h
gfx/layers/ipc/ShadowLayerUtils.h
layout/base/nsDisplayList.cpp
layout/ipc/RenderFrameParent.cpp
--- a/content/base/public/nsIFrameLoader.idl
+++ b/content/base/public/nsIFrameLoader.idl
@@ -88,16 +88,28 @@ interface nsIContentView : nsISupports
    *
    * Note that when this view becomes inactive, the new content view will have
    * scroll values that are reset to the default!
    */
   readonly attribute float scrollX;
   readonly attribute float scrollY;
 
   /**
+   * Dimensions of the viewport in chrome-document CSS pixels.
+   */
+  readonly attribute float viewportWidth;
+  readonly attribute float viewportHeight;
+
+  /**
+   * Dimensions of scrolled content in chrome-document CSS pixels.
+   */
+  readonly attribute float contentWidth;
+  readonly attribute float contentHeight;
+
+  /**
    * ID that can be used in conjunction with nsIDOMWindowUtils to change
    * the actual document, instead of just how it is transformed.
    */
   readonly attribute nsContentViewId id;
 };
 
 [scriptable, uuid(ba5af90d-ece5-40b2-9a1d-a0154128db1c)]
 interface nsIContentViewManager : nsISupports
--- a/content/base/src/nsFrameLoader.cpp
+++ b/content/base/src/nsFrameLoader.cpp
@@ -232,16 +232,44 @@ NS_IMETHODIMP
 nsContentView::GetScrollY(float* aViewScrollY)
 {
   *aViewScrollY = nsPresContext::AppUnitsToFloatCSSPixels(
     mConfig.mScrollOffset.y);
   return NS_OK;
 }
 
 NS_IMETHODIMP
+nsContentView::GetViewportWidth(float* aWidth)
+{
+  *aWidth = nsPresContext::AppUnitsToFloatCSSPixels(mViewportSize.width);
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsContentView::GetViewportHeight(float* aHeight)
+{
+  *aHeight = nsPresContext::AppUnitsToFloatCSSPixels(mViewportSize.height);
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsContentView::GetContentWidth(float* aWidth)
+{
+  *aWidth = nsPresContext::AppUnitsToFloatCSSPixels(mContentSize.width);
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsContentView::GetContentHeight(float* aHeight)
+{
+  *aHeight = nsPresContext::AppUnitsToFloatCSSPixels(mContentSize.height);
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 nsContentView::GetId(nsContentViewId* aId)
 {
   NS_ASSERTION(sizeof(nsContentViewId) == sizeof(ViewID),
                "ID size for XPCOM ID and internal ID type are not the same!");
   *aId = mScrollId;
   return NS_OK;
 }
 
--- a/content/base/src/nsFrameLoader.h
+++ b/content/base/src/nsFrameLoader.h
@@ -126,33 +126,38 @@ public:
     // ratio is used to define a scale transform when painting the
     // content document.
     float mXScale;
     float mYScale;
   };
 
   nsContentView(nsIContent* aOwnerContent, ViewID aScrollId,
                 ViewConfig aConfig = ViewConfig())
-    : mOwnerContent(aOwnerContent)
+    : mViewportSize(0, 0)
+    , mContentSize(0, 0)
+    , mOwnerContent(aOwnerContent)
     , mScrollId(aScrollId)
     , mConfig(aConfig)
   {}
 
   bool IsRoot() const;
 
   ViewID GetId() const
   {
     return mScrollId;
   }
 
   ViewConfig GetViewConfig() const
   {
     return mConfig;
   }
 
+  nsSize mViewportSize;
+  nsSize mContentSize;
+
   nsIContent *mOwnerContent; // WEAK
 
 private:
   nsresult Update(const ViewConfig& aConfig);
 
   ViewID mScrollId;
   ViewConfig mConfig;
 };
--- a/gfx/layers/Layers.h
+++ b/gfx/layers/Layers.h
@@ -92,16 +92,17 @@ public:
   typedef PRUint64 ViewID;
   static const ViewID NULL_SCROLL_ID;   // This container layer does not scroll.
   static const ViewID ROOT_SCROLL_ID;   // This is the root scroll frame.
   static const ViewID START_SCROLL_ID;  // This is the ID that scrolling subframes
                                         // will begin at.
 
   FrameMetrics()
     : mViewport(0, 0, 0, 0)
+    , mContentSize(0, 0)
     , mViewportScrollOffset(0, 0)
     , mScrollId(NULL_SCROLL_ID)
   {}
 
   // Default copy ctor and operator= are fine
 
   PRBool operator==(const FrameMetrics& aOther) const
   {
@@ -122,16 +123,17 @@ public:
   }
 
   PRBool IsScrollable() const
   {
     return mScrollId != NULL_SCROLL_ID;
   }
 
   nsIntRect mViewport;
+  nsIntSize mContentSize;
   nsIntPoint mViewportScrollOffset;
   nsIntRect mDisplayPort;
   ViewID mScrollId;
 };
 
 #define MOZ_LAYER_DECL_NAME(n, e)                           \
   virtual const char* Name() const { return n; }            \
   virtual LayerType GetType() const { return e; }
--- a/gfx/layers/ipc/ShadowLayerUtils.h
+++ b/gfx/layers/ipc/ShadowLayerUtils.h
@@ -59,24 +59,26 @@ namespace IPC {
 template <>
 struct ParamTraits<mozilla::layers::FrameMetrics>
 {
   typedef mozilla::layers::FrameMetrics paramType;
 
   static void Write(Message* aMsg, const paramType& aParam)
   {
     WriteParam(aMsg, aParam.mViewport);
+    WriteParam(aMsg, aParam.mContentSize);
     WriteParam(aMsg, aParam.mViewportScrollOffset);
     WriteParam(aMsg, aParam.mDisplayPort);
     WriteParam(aMsg, aParam.mScrollId);
   }
 
   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
   {
     return (ReadParam(aMsg, aIter, &aResult->mViewport) &&
+            ReadParam(aMsg, aIter, &aResult->mContentSize) &&
             ReadParam(aMsg, aIter, &aResult->mViewportScrollOffset) &&
             ReadParam(aMsg, aIter, &aResult->mDisplayPort) &&
             ReadParam(aMsg, aIter, &aResult->mScrollId));
   }
 };
 
 #if !defined(MOZ_HAVE_SURFACEDESCRIPTORX11)
 template <>
--- a/layout/base/nsDisplayList.cpp
+++ b/layout/base/nsDisplayList.cpp
@@ -168,16 +168,22 @@ static void RecordFrameMetrics(nsIFrame*
   if (presShell->UsingDisplayPort()) {
     metrics.mDisplayPort =
       presShell->GetDisplayPort().ToNearestPixels(auPerDevPixel);
   }
 
   nsIScrollableFrame* rootScrollableFrame =
     presShell->GetRootScrollFrameAsScrollable();
   if (rootScrollableFrame) {
+    nsSize contentSize = 
+      rootScrollableFrame->GetScrollRange().Size() +
+      rootScrollableFrame->GetScrollPortRect().Size();
+    metrics.mContentSize = nsIntSize(NSAppUnitsToIntPixels(contentSize.width, auPerDevPixel),
+                                     NSAppUnitsToIntPixels(contentSize.height, auPerDevPixel));
+
     metrics.mViewportScrollOffset =
       rootScrollableFrame->GetScrollPosition().ToNearestPixels(auPerDevPixel);
     
     metrics.mScrollId = aScrollId;
   }
 
   aRoot->SetFrameMetrics(metrics);
 }
--- a/layout/ipc/RenderFrameParent.cpp
+++ b/layout/ipc/RenderFrameParent.cpp
@@ -367,16 +367,23 @@ BuildViewMap(ViewMap& oldContentViews, V
     // The default scale is 1, so no need to propagate scale down.
     ViewConfig config;
     config.mScrollOffset = nsPoint(
       NSIntPixelsToAppUnits(metrics.mViewportScrollOffset.x, auPerDevPixel) * aXScale,
       NSIntPixelsToAppUnits(metrics.mViewportScrollOffset.y, auPerDevPixel) * aYScale);
     view = new nsContentView(aFrameLoader->GetOwnerContent(), scrollId, config);
   }
 
+  view->mViewportSize = nsSize(
+    NSIntPixelsToAppUnits(metrics.mViewport.width, auPerDevPixel) * aXScale,
+    NSIntPixelsToAppUnits(metrics.mViewport.height, auPerDevPixel) * aYScale);
+  view->mContentSize = nsSize(
+    NSIntPixelsToAppUnits(metrics.mContentSize.width, auPerDevPixel) * aXScale,
+    NSIntPixelsToAppUnits(metrics.mContentSize.height, auPerDevPixel) * aYScale);
+
   newContentViews.insert(ViewMap::value_type(scrollId, view));
 
   for (Layer* child = aLayer->GetFirstChild();
        child; child = child->GetNextSibling()) {
     const gfx3DMatrix transform = aLayer->GetTransform();
     aXScale *= GetXScale(transform);
     aYScale *= GetYScale(transform);
     BuildViewMap(oldContentViews, newContentViews, aFrameLoader, child,