diff --git a/content/base/public/nsIFrameLoader.idl b/content/base/public/nsIFrameLoader.idl index ec54aad9d23..f17c97658de 100644 --- a/content/base/public/nsIFrameLoader.idl +++ b/content/base/public/nsIFrameLoader.idl @@ -92,6 +92,18 @@ interface nsIContentView : nsISupports 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. diff --git a/content/base/src/nsFrameLoader.cpp b/content/base/src/nsFrameLoader.cpp index 9b9d8fdddd7..6a0ddef9c2a 100644 --- a/content/base/src/nsFrameLoader.cpp +++ b/content/base/src/nsFrameLoader.cpp @@ -236,6 +236,34 @@ nsContentView::GetScrollY(float* aViewScrollY) 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) { diff --git a/content/base/src/nsFrameLoader.h b/content/base/src/nsFrameLoader.h index 7aceff60310..c34655a9e52 100644 --- a/content/base/src/nsFrameLoader.h +++ b/content/base/src/nsFrameLoader.h @@ -131,7 +131,9 @@ public: nsContentView(nsIContent* aOwnerContent, ViewID aScrollId, ViewConfig aConfig = ViewConfig()) - : mOwnerContent(aOwnerContent) + : mViewportSize(0, 0) + , mContentSize(0, 0) + , mOwnerContent(aOwnerContent) , mScrollId(aScrollId) , mConfig(aConfig) {} @@ -148,6 +150,9 @@ public: return mConfig; } + nsSize mViewportSize; + nsSize mContentSize; + nsIContent *mOwnerContent; // WEAK private: diff --git a/gfx/layers/Layers.h b/gfx/layers/Layers.h index d85ddf7c40c..1bd8786dc46 100644 --- a/gfx/layers/Layers.h +++ b/gfx/layers/Layers.h @@ -97,6 +97,7 @@ public: FrameMetrics() : mViewport(0, 0, 0, 0) + , mContentSize(0, 0) , mViewportScrollOffset(0, 0) , mScrollId(NULL_SCROLL_ID) {} @@ -127,6 +128,7 @@ public: } nsIntRect mViewport; + nsIntSize mContentSize; nsIntPoint mViewportScrollOffset; nsIntRect mDisplayPort; ViewID mScrollId; diff --git a/gfx/layers/ipc/ShadowLayerUtils.h b/gfx/layers/ipc/ShadowLayerUtils.h index 4fff40cfe2b..baf2eb8f4c2 100644 --- a/gfx/layers/ipc/ShadowLayerUtils.h +++ b/gfx/layers/ipc/ShadowLayerUtils.h @@ -64,6 +64,7 @@ struct ParamTraits 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); @@ -72,6 +73,7 @@ struct ParamTraits 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)); diff --git a/layout/base/nsDisplayList.cpp b/layout/base/nsDisplayList.cpp index 861bbde571b..cfcb3647a20 100644 --- a/layout/base/nsDisplayList.cpp +++ b/layout/base/nsDisplayList.cpp @@ -173,6 +173,12 @@ static void RecordFrameMetrics(nsIFrame* aForFrame, 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); diff --git a/layout/ipc/RenderFrameParent.cpp b/layout/ipc/RenderFrameParent.cpp index b071051ebd9..da61fcff4a7 100644 --- a/layout/ipc/RenderFrameParent.cpp +++ b/layout/ipc/RenderFrameParent.cpp @@ -372,6 +372,13 @@ BuildViewMap(ViewMap& oldContentViews, ViewMap& newContentViews, 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();