Bug 596969: Allow a document's CSS viewport to be permanently overridden by chrome script. sr=dbaron a=blocking-fennec

This commit is contained in:
Chris Jones 2010-09-24 17:41:31 -05:00
parent f8b4169a1c
commit dfe1b316b7
3 changed files with 34 additions and 3 deletions

View File

@ -250,7 +250,7 @@ nsDOMWindowUtils::SetCSSViewport(float aWidthPx, float aHeightPx)
nscoord width = nsPresContext::CSSPixelsToAppUnits(aWidthPx);
nscoord height = nsPresContext::CSSPixelsToAppUnits(aHeightPx);
presShell->ResizeReflow(width, height);
presShell->ResizeReflowOverride(width, height);
return NS_OK;
}

View File

@ -139,8 +139,8 @@ typedef struct CapturingContentInfo {
} CapturingContentInfo;
#define NS_IPRESSHELL_IID \
{ 0x34f80395, 0xff82, 0x49fa, \
{ 0x9c, 0x83, 0xa6, 0xba, 0x49, 0xa8, 0x55, 0x4a } }
{ 0xb79574cd, 0x2555, 0x4b57, \
{ 0xb3, 0xf8, 0x27, 0x57, 0x3e, 0x60, 0x74, 0x01 } }
// Constants for ScrollContentIntoView() function
#define NS_PRESSHELL_SCROLL_TOP 0
@ -350,6 +350,12 @@ public:
* coordinates for aWidth and aHeight must be in standard nscoord's.
*/
virtual NS_HIDDEN_(nsresult) ResizeReflow(nscoord aWidth, nscoord aHeight) = 0;
/**
* Reflow, and also change presshell state so as to only permit
* reflowing off calls to ResizeReflowOverride() in the future.
* ResizeReflow() calls are ignored after ResizeReflowOverride().
*/
virtual NS_HIDDEN_(nsresult) ResizeReflowOverride(nscoord aWidth, nscoord aHeight) = 0;
/**
* Reflow the frame model with a reflow reason of eReflowReason_StyleChange

View File

@ -741,6 +741,7 @@ public:
virtual NS_HIDDEN_(void) EndObservingDocument();
virtual NS_HIDDEN_(nsresult) InitialReflow(nscoord aWidth, nscoord aHeight);
virtual NS_HIDDEN_(nsresult) ResizeReflow(nscoord aWidth, nscoord aHeight);
virtual NS_HIDDEN_(nsresult) ResizeReflowOverride(nscoord aWidth, nscoord aHeight);
virtual NS_HIDDEN_(void) StyleChangeReflow();
virtual NS_HIDDEN_(nsIPageSequenceFrame*) GetPageSequenceFrame() const;
virtual NS_HIDDEN_(nsIFrame*) GetRealPrimaryFrameFor(nsIContent* aContent) const;
@ -1007,6 +1008,9 @@ protected:
// sets up.
void ScheduleReflow();
// Reflow regardless of whether the override bit has been set.
nsresult ResizeReflowIgnoreOverride(nscoord aWidth, nscoord aHeight);
// DoReflow returns whether the reflow finished without interruption
PRBool DoReflow(nsIFrame* aFrame, PRBool aInterruptible);
#ifdef DEBUG
@ -1147,6 +1151,8 @@ protected:
PRPackedBool mIgnoreFrameDestruction;
PRPackedBool mHaveShutDown;
PRPackedBool mViewportOverridden;
// This is used to protect ourselves from triggering reflow while in the
// middle of frame construction and the like... it really shouldn't be
// needed, one hopes, but it is for now.
@ -1662,6 +1668,7 @@ PresShell::PresShell()
mRenderFlags = 0;
mXResolution = 1.0;
mYResolution = 1.0;
mViewportOverridden = PR_FALSE;
static bool registeredReporter = false;
if (!registeredReporter) {
@ -2797,8 +2804,26 @@ PresShell::AsyncResizeEventCallback(nsITimer* aTimer, void* aPresShell)
static_cast<PresShell*>(aPresShell)->FireResizeEvent();
}
nsresult
PresShell::ResizeReflowOverride(nscoord aWidth, nscoord aHeight)
{
mViewportOverridden = PR_TRUE;
return ResizeReflowIgnoreOverride(aWidth, aHeight);
}
nsresult
PresShell::ResizeReflow(nscoord aWidth, nscoord aHeight)
{
if (mViewportOverridden) {
// The viewport has been overridden, and this reflow request
// didn't ask to ignore the override. Pretend it didn't happen.
return NS_OK;
}
return ResizeReflowIgnoreOverride(aWidth, aHeight);
}
nsresult
PresShell::ResizeReflowIgnoreOverride(nscoord aWidth, nscoord aHeight)
{
NS_PRECONDITION(!mIsReflowing, "Shouldn't be in reflow here!");
NS_PRECONDITION(aWidth != NS_UNCONSTRAINEDSIZE,