Bug 732016 Allow override of the scroll port size used for clamping scroll positions. r=roc

This commit is contained in:
Timothy Nikkel 2012-04-24 13:52:35 -05:00
parent 2efe920d28
commit 5fce132cd1
6 changed files with 80 additions and 5 deletions

View File

@ -2317,3 +2317,26 @@ nsDOMWindowUtils::GetPlugins(JSContext* cx, jsval* aPlugins)
*aPlugins = OBJECT_TO_JSVAL(jsPlugins);
return NS_OK;
}
NS_IMETHODIMP
nsDOMWindowUtils::SetScrollPositionClampingScrollPortSize(float aWidth, float aHeight)
{
if (!IsUniversalXPConnectCapable()) {
return NS_ERROR_DOM_SECURITY_ERR;
}
if (!(aWidth >= 0.0 && aHeight >= 0.0)) {
return NS_ERROR_ILLEGAL_VALUE;
}
nsIPresShell* presShell = GetPresShell();
if (!presShell) {
return NS_ERROR_FAILURE;
}
presShell->SetScrollPositionClampingScrollPortSize(
nsPresContext::CSSPixelsToAppUnits(aWidth),
nsPresContext::CSSPixelsToAppUnits(aHeight));
return NS_OK;
}

View File

@ -70,7 +70,7 @@ interface nsIDOMFile;
interface nsIFile;
interface nsIDOMTouch;
[scriptable, uuid(c7f303a1-4f7b-4d38-a192-c3f0e25dadb1)]
[scriptable, uuid(66a68858-df38-40e1-a792-fda04ebcc084)]
interface nsIDOMWindowUtils : nsISupports {
/**
@ -1110,4 +1110,12 @@ interface nsIDOMWindowUtils : nsISupports {
*/
[implicit_jscontext]
readonly attribute jsval plugins;
/**
* Set the scrollport size for the purposes of clamping scroll positions for
* the root scroll frame of this document to be (aWidth,aHeight) in CSS pixels.
*
* The caller of this method must have UniversalXPConnect privileges.
*/
void setScrollPositionClampingScrollPortSize(in float aWidth, in float aHeight);
};

View File

@ -1265,6 +1265,15 @@ public:
// clears that capture.
static void ClearMouseCapture(nsIFrame* aFrame);
void SetScrollPositionClampingScrollPortSize(nscoord aWidth, nscoord aHeight);
bool IsScrollPositionClampingScrollPortSizeSet() {
return mScrollPositionClampingScrollPortSizeSet;
}
nsSize GetScrollPositionClampingScrollPortSize() {
NS_ASSERTION(mScrollPositionClampingScrollPortSizeSet, "asking for scroll port when its not set?");
return mScrollPositionClampingScrollPortSize;
}
protected:
friend class nsRefreshDriver;
@ -1315,6 +1324,8 @@ protected:
bool mSuppressInterruptibleReflows;
bool mScrollPositionClampingScrollPortSizeSet;
// A list of weak frames. This is a pointer to the last item in the list.
nsWeakFrame* mWeakFrames;
@ -1333,6 +1344,8 @@ protected:
float mXResolution;
float mYResolution;
nsSize mScrollPositionClampingScrollPortSize;
static nsIContent* gKeyDownTarget;
};

View File

@ -831,6 +831,8 @@ PresShell::PresShell()
mYResolution = 1.0;
mViewportOverridden = false;
mScrollPositionClampingScrollPortSizeSet = false;
static bool addedSynthMouseMove = false;
if (!addedSynthMouseMove) {
Preferences::AddBoolVarCache(&sSynthMouseMove,
@ -9147,3 +9149,10 @@ PresShell::SizeOfTextRuns(nsMallocSizeOfFun aMallocSizeOf) const
/* clear = */false);
}
void
nsIPresShell::SetScrollPositionClampingScrollPortSize(nscoord aWidth, nscoord aHeight)
{
mScrollPositionClampingScrollPortSizeSet = true;
mScrollPositionClampingScrollPortSize.width = aWidth;
mScrollPositionClampingScrollPortSize.height = aHeight;
}

View File

@ -1645,7 +1645,7 @@ Clamp(nscoord aLower, nscoord aVal, nscoord aUpper)
nsPoint
nsGfxScrollFrameInner::ClampScrollPosition(const nsPoint& aPt) const
{
nsRect range = GetScrollRange();
nsRect range = GetScrollRangeForClamping();
return nsPoint(Clamp(range.x, aPt.x, range.XMost()),
Clamp(range.y, aPt.y, range.YMost()));
}
@ -1971,7 +1971,7 @@ nsGfxScrollFrameInner::RestrictToDevPixels(const nsPoint& aPt,
// pixels. But we also need to make sure that our position remains
// inside the allowed region.
if (aShouldClamp) {
nsRect scrollRange = GetScrollRange();
nsRect scrollRange = GetScrollRangeForClamping();
*aPtDevPx = nsIntPoint(ClampInt(scrollRange.x, aPt.x, scrollRange.XMost(), appUnitsPerDevPixel),
ClampInt(scrollRange.y, aPt.y, scrollRange.YMost(), appUnitsPerDevPixel));
} else {
@ -2326,10 +2326,16 @@ AlignToDevPixelRoundingToZero(nscoord aVal, PRInt32 aAppUnitsPerDevPixel)
nsRect
nsGfxScrollFrameInner::GetScrollRange() const
{
return GetScrollRange(mScrollPort.width, mScrollPort.height);
}
nsRect
nsGfxScrollFrameInner::GetScrollRange(nscoord aWidth, nscoord aHeight) const
{
nsRect range = GetScrolledRect();
range.width -= mScrollPort.width;
range.height -= mScrollPort.height;
range.width -= aWidth;
range.height -= aHeight;
nsPresContext* presContext = mOuter->PresContext();
PRInt32 appUnitsPerDevPixel = presContext->AppUnitsPerDevPixel();
@ -2342,6 +2348,17 @@ nsGfxScrollFrameInner::GetScrollRange() const
return range;
}
nsRect
nsGfxScrollFrameInner::GetScrollRangeForClamping() const
{
nsIPresShell* presShell = mOuter->PresContext()->PresShell();
if (mIsRoot && presShell->IsScrollPositionClampingScrollPortSizeSet()) {
nsSize size = presShell->GetScrollPositionClampingScrollPortSize();
return GetScrollRange(size.width, size.height);
}
return GetScrollRange();
}
static void
AdjustForWholeDelta(PRInt32 aDelta, nscoord* aCoord)
{

View File

@ -178,7 +178,12 @@ public:
return pt;
}
nsRect GetScrollRange() const;
// Get the scroll range assuming the scrollport has size (aWidth, aHeight).
nsRect GetScrollRange(nscoord aWidth, nscoord aHeight) const;
protected:
nsRect GetScrollRangeForClamping() const;
public:
nsPoint RestrictToDevPixels(const nsPoint& aPt, nsIntPoint* aPtDevPx, bool aShouldClamp) const;
nsPoint ClampScrollPosition(const nsPoint& aPt) const;
static void AsyncScrollCallback(nsITimer *aTimer, void* anInstance);