Bug 618249: Default remote-browser to synchronous scrolling, and let users change that. r=tn sr=roc a=a

This commit is contained in:
Chris Jones 2011-01-11 15:34:31 -06:00
parent 7afafb885d
commit d9ba510227
8 changed files with 94 additions and 23 deletions

View File

@ -176,3 +176,25 @@ interface nsIFrameLoaderOwner : nsISupports
*/
void swapFrameLoaders(in nsIFrameLoaderOwner aOtherOwner);
};
/** Please merge me into something else after 2.0 branches. */
[scriptable, uuid(e3e2d3f8-1397-4984-abb3-435c29a1ca55)]
interface nsIFrameLoader_MOZILLA_2_0_BRANCH : nsISupports
{
/**
* The default rendering mode is synchronous scrolling. In this
* mode, it's an error to try to set a target viewport.
*/
const unsigned long RENDER_MODE_DEFAULT = 0x00000000;
/**
* When asynchronous scrolling is enabled, a target viewport can be
* set to transform content pixels wrt its CSS viewport.
*
* NB: when async scrolling is enabled, it's the *user's*
* responsibility to update the target scroll offset. In effect,
* the platform hands over control of scroll offset to the user.
*/
const unsigned long RENDER_MODE_ASYNC_SCROLL = 0x00000001;
attribute unsigned long renderMode;
};

View File

@ -171,12 +171,13 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsFrameLoader)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mChildMessageManager)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsFrameLoader)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsFrameLoader)
NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsFrameLoader, nsIFrameLoader)
NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsFrameLoader, nsIFrameLoader)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsFrameLoader)
NS_INTERFACE_MAP_ENTRY(nsIFrameLoader)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_ENTRY(nsIFrameLoader_MOZILLA_2_0_BRANCH)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIFrameLoader)
NS_INTERFACE_MAP_END
nsFrameLoader*
@ -1544,12 +1545,34 @@ nsFrameLoader::GetViewportScrollY(float* aViewportScrollY)
return NS_OK;
}
NS_IMETHODIMP
nsFrameLoader::GetRenderMode(PRUint32* aRenderMode)
{
*aRenderMode = mViewportConfig.mRenderMode;
return NS_OK;
}
NS_IMETHODIMP
nsFrameLoader::SetRenderMode(PRUint32 aRenderMode)
{
ViewportConfig config(mViewportConfig);
config.mRenderMode = aRenderMode;
return UpdateViewportConfig(config);
}
nsresult
nsFrameLoader::UpdateViewportConfig(const ViewportConfig& aNewConfig)
{
if (aNewConfig == mViewportConfig) {
return NS_OK;
} else if (!mViewportConfig.AsyncScrollEnabled() &&
!aNewConfig.AsyncScrollEnabled()) {
// The target viewport can't be set in synchronous mode
return NS_ERROR_NOT_AVAILABLE;
}
// XXX if we go from disabled->enabled, should we clear out the old
// config? Or what?
mViewportConfig = aNewConfig;
// Viewport changed. Try to locate our subdoc frame and invalidate

View File

@ -80,7 +80,8 @@ class QX11EmbedContainer;
#endif
#endif
class nsFrameLoader : public nsIFrameLoader
class nsFrameLoader : public nsIFrameLoader,
public nsIFrameLoader_MOZILLA_2_0_BRANCH
{
friend class AutoResetInShow;
#ifdef MOZ_IPC
@ -121,7 +122,8 @@ public:
*/
struct ViewportConfig {
ViewportConfig()
: mScrollOffset(0, 0)
: mRenderMode(nsIFrameLoader_MOZILLA_2_0_BRANCH::RENDER_MODE_DEFAULT)
, mScrollOffset(0, 0)
, mXScale(1.0)
, mYScale(1.0)
{}
@ -130,11 +132,21 @@ public:
PRBool operator==(const ViewportConfig& aOther) const
{
return (mScrollOffset == aOther.mScrollOffset &&
return (mRenderMode == aOther.mRenderMode &&
mScrollOffset == aOther.mScrollOffset &&
mXScale == aOther.mXScale &&
mYScale == aOther.mYScale);
}
PRBool AsyncScrollEnabled() const
{
return !!(mRenderMode & RENDER_MODE_ASYNC_SCROLL);
}
// See nsIFrameLoader.idl. Short story, if !(mRenderMode &
// RENDER_MODE_ASYNC_SCROLL), all the fields below are ignored in
// favor of what content tells.
PRUint32 mRenderMode;
// This is the scroll offset the <browser> user wishes or expects
// its enclosed content document to have. "Scroll offset" here
// means the document pixel at pixel (0,0) within the CSS
@ -162,8 +174,9 @@ public:
static nsFrameLoader* Create(nsIContent* aOwner, PRBool aNetworkCreated);
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS(nsFrameLoader)
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsFrameLoader, nsIFrameLoader)
NS_DECL_NSIFRAMELOADER
NS_DECL_NSIFRAMELOADER_MOZILLA_2_0_BRANCH
NS_HIDDEN_(nsresult) CheckForRecursiveLoad(nsIURI* aURI);
nsresult ReallyStartLoading();
void Finalize();

View File

@ -1524,7 +1524,7 @@ nsObjectLoadingContent::RemovedFromDocument()
void
nsObjectLoadingContent::Traverse(nsCycleCollectionTraversalCallback &cb)
{
cb.NoteXPCOMChild(mFrameLoader);
cb.NoteXPCOMChild(static_cast<nsIFrameLoader*>(mFrameLoader));
}
// <private>

View File

@ -3692,7 +3692,7 @@ nsCanvasRenderingContext2D::AsyncDrawXULElement(nsIDOMXULElement* aElem, float a
if (!loaderOwner)
return NS_ERROR_FAILURE;
nsCOMPtr<nsFrameLoader> frameloader = loaderOwner->GetFrameLoader();
nsRefPtr<nsFrameLoader> frameloader = loaderOwner->GetFrameLoader();
if (!frameloader)
return NS_ERROR_FAILURE;

View File

@ -3052,7 +3052,7 @@ nsGenericHTMLFrameElement::~nsGenericHTMLFrameElement()
NS_IMPL_CYCLE_COLLECTION_CLASS(nsGenericHTMLFrameElement)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsGenericHTMLFrameElement,
nsGenericHTMLElement)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFrameLoader)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mFrameLoader, nsIFrameLoader)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_INTERFACE_TABLE_HEAD(nsGenericHTMLFrameElement)

View File

@ -97,20 +97,26 @@ ComputeShadowTreeTransform(nsIFrame* aContainerFrame,
aContainerFrame->GetContentRect().TopLeft());
*aShadowTranslation = frameOffset.ToNearestPixels(auPerDevPixel);
// |aMetrics.mViewportScrollOffset| was the content document's
// scroll offset when it was painted (the document pixel at CSS
// viewport (0,0)). |aConfig.mScrollOffset| is what our user
// expects, or wants, the content-document scroll offset to be. So
// we set a compensating translation that moves the content document
// pixels to where the user wants them to be.
nsIntPoint scrollCompensation =
(aConfig.mScrollOffset.ToNearestPixels(auPerDevPixel));
scrollCompensation.x -= aMetrics.mViewportScrollOffset.x * aConfig.mXScale;
scrollCompensation.y -= aMetrics.mViewportScrollOffset.y * aConfig.mYScale;
*aShadowTranslation -= scrollCompensation;
if (aConfig.AsyncScrollEnabled()) {
// |aMetrics.mViewportScrollOffset| was the content document's
// scroll offset when it was painted (the document pixel at CSS
// viewport (0,0)). |aConfig.mScrollOffset| is what our user
// expects, or wants, the content-document scroll offset to be. So
// we set a compensating translation that moves the content document
// pixels to where the user wants them to be.
nsIntPoint scrollCompensation =
(aConfig.mScrollOffset.ToNearestPixels(auPerDevPixel));
scrollCompensation.x -= aMetrics.mViewportScrollOffset.x * aConfig.mXScale;
scrollCompensation.y -= aMetrics.mViewportScrollOffset.y * aConfig.mYScale;
*aShadowTranslation -= scrollCompensation;
*aShadowXScale = aConfig.mXScale;
*aShadowYScale = aConfig.mYScale;
*aShadowXScale = aConfig.mXScale;
*aShadowYScale = aConfig.mYScale;
} else {
*aShadowXScale = 1;
*aShadowYScale = 1;
}
}
static void

View File

@ -1,4 +1,5 @@
function init() {
enableAsyncScrolling();
messageManager.loadFrameScript(
"chrome://global/content/test-ipcbrowser-content.js", true
);
@ -13,6 +14,12 @@ function frameLoader() {
.frameLoader;
}
function enableAsyncScrolling() {
var i = Components.interfaces.nsIFrameLoader_MOZILLA_2_0_BRANCH;
var enabler = frameLoader().QueryInterface(i);
enabler.renderMode = i.RENDER_MODE_ASYNC_SCROLL;
}
// Functions affecting the content window.
function loadURL(url) {