Bug 1152479 - Do not use layout-related nsIDOMWindowUtils APIs from C++ APZ code. r=kats

--HG--
extra : rebase_source : 8fb4f75e5e50a1e29424d03b5c18236846a698df
extra : source : d017af70470603f970fde91c1515757e57e2d8ba
This commit is contained in:
Botond Ballo 2015-04-14 16:44:59 -04:00
parent 148a784118
commit 80b5170af7
5 changed files with 72 additions and 110 deletions

View File

@ -219,8 +219,9 @@ TabChildBase::SetCSSViewport(const CSSSize& aSize)
TABC_LOG("Setting CSS viewport to %s\n", Stringify(aSize).c_str());
if (mContentDocumentIsDisplayed) {
nsCOMPtr<nsIDOMWindowUtils> utils(GetDOMWindowUtils());
utils->SetCSSViewport(aSize.width, aSize.height);
if (nsCOMPtr<nsIPresShell> shell = GetPresShell()) {
nsLayoutUtils::SetCSSViewport(shell, aSize);
}
}
}
@ -274,7 +275,6 @@ TabChildBase::HandlePossibleViewportChange(const ScreenIntSize& aOldScreenSize)
Stringify(aOldScreenSize).c_str(), Stringify(mInnerSize).c_str());
nsCOMPtr<nsIDocument> document(GetDocument());
nsCOMPtr<nsIDOMWindowUtils> utils(GetDOMWindowUtils());
nsViewportInfo viewportInfo = nsContentUtils::GetViewportInfo(document, mInnerSize);
uint32_t presShellId = 0;
@ -358,9 +358,12 @@ TabChildBase::HandlePossibleViewportChange(const ScreenIntSize& aOldScreenSize)
// Changing the zoom when we're not doing a first paint will get ignored
// by AsyncPanZoomController and causes a blurry flash.
bool isFirstPaint;
nsresult rv = utils->GetIsFirstPaint(&isFirstPaint);
if (NS_FAILED(rv) || isFirstPaint) {
nsCOMPtr<nsIPresShell> shell = GetPresShell();
bool isFirstPaint = true;
if (shell) {
isFirstPaint = shell->GetIsFirstPaint();
}
if (isFirstPaint) {
// FIXME/bug 799585(?): GetViewportInfo() returns a defaultZoom of
// 0.0 to mean "did not calculate a zoom". In that case, we default
// it to the intrinsic scale.
@ -376,7 +379,6 @@ TabChildBase::HandlePossibleViewportChange(const ScreenIntSize& aOldScreenSize)
metrics.SetScrollId(viewId);
}
nsIPresShell* shell = document->GetShell();
if (shell) {
if (nsPresContext* context = shell->GetPresContext()) {
metrics.SetDevPixelsPerCSSPixel(CSSToLayoutDeviceScale(
@ -392,11 +394,10 @@ TabChildBase::HandlePossibleViewportChange(const ScreenIntSize& aOldScreenSize)
metrics.SetPresShellResolution(metrics.GetCumulativeResolution().ToScaleFactor().scale);
if (shell) {
nsLayoutUtils::SetResolutionAndScaleTo(shell, metrics.GetPresShellResolution());
nsLayoutUtils::SetScrollPositionClampingScrollPortSize(shell,
metrics.CalculateCompositedSizeInCssPixels());
}
CSSSize scrollPort = metrics.CalculateCompositedSizeInCssPixels();
utils->SetScrollPositionClampingScrollPortSize(scrollPort.width, scrollPort.height);
// The call to GetPageSize forces a resize event to content, so we need to
// make sure that we have the right CSS viewport and
// scrollPositionClampingScrollPortSize set up before that happens.
@ -460,6 +461,16 @@ TabChildBase::GetDocument() const
return doc.forget();
}
already_AddRefed<nsIPresShell>
TabChildBase::GetPresShell() const
{
nsCOMPtr<nsIPresShell> result;
if (nsCOMPtr<nsIDocument> doc = GetDocument()) {
result = doc->GetShell();
}
return result.forget();
}
void
TabChildBase::DispatchMessageManagerMessage(const nsAString& aMessageName,
const nsAString& aJSONData)
@ -492,10 +503,13 @@ TabChildBase::UpdateFrameHandler(const FrameMetrics& aFrameMetrics)
MOZ_ASSERT(aFrameMetrics.GetScrollId() != FrameMetrics::NULL_SCROLL_ID);
if (aFrameMetrics.GetIsRoot()) {
nsCOMPtr<nsIDOMWindowUtils> utils(GetDOMWindowUtils());
if (APZCCallbackHelper::HasValidPresShellId(utils, aFrameMetrics)) {
mLastRootMetrics = ProcessUpdateFrame(aFrameMetrics);
return true;
if (nsCOMPtr<nsIPresShell> shell = GetPresShell()) {
// Guard against stale updates (updates meant for a pres shell which
// has since been torn down and destroyed).
if (aFrameMetrics.GetPresShellId() == shell->GetPresShellId()) {
mLastRootMetrics = ProcessUpdateFrame(aFrameMetrics);
return true;
}
}
} else {
// aFrameMetrics.mIsRoot is false, so we are trying to update a subframe.
@ -518,12 +532,9 @@ TabChildBase::ProcessUpdateFrame(const FrameMetrics& aFrameMetrics)
return aFrameMetrics;
}
nsCOMPtr<nsIDOMWindowUtils> utils(GetDOMWindowUtils());
FrameMetrics newMetrics = aFrameMetrics;
nsCOMPtr<nsIDocument> doc = GetDocument();
if (doc && doc->GetShell()) {
APZCCallbackHelper::UpdateRootFrame(utils, doc->GetShell(), newMetrics);
if (nsCOMPtr<nsIPresShell> presShell = GetPresShell()) {
APZCCallbackHelper::UpdateRootFrame(presShell, newMetrics);
}
CSSSize cssCompositedSize = newMetrics.CalculateCompositedSizeInCssPixels();
@ -911,8 +922,10 @@ TabChild::Observe(nsISupports *aSubject,
nsCOMPtr<nsIDocument> doc(GetDocument());
if (SameCOMIdentity(subject, doc)) {
nsCOMPtr<nsIDOMWindowUtils> utils(GetDOMWindowUtils());
utils->SetIsFirstPaint(true);
nsCOMPtr<nsIPresShell> shell(doc->GetShell());
if (shell) {
shell->SetIsFirstPaint(true);
}
mContentDocumentIsDisplayed = true;
@ -922,7 +935,7 @@ TabChild::Observe(nsISupports *aSubject,
// until we we get an inner size.
if (HasValidInnerSize()) {
InitializeRootMetrics();
if (nsIPresShell* shell = doc->GetShell()) {
if (shell) {
nsLayoutUtils::SetResolutionAndScaleTo(shell, mLastRootMetrics.GetPresShellResolution());
}
HandlePossibleViewportChange(mInnerSize);

View File

@ -197,6 +197,8 @@ protected:
already_AddRefed<nsIDOMWindowUtils> GetDOMWindowUtils();
// Get the Document for the top-level window in this tab.
already_AddRefed<nsIDocument> GetDocument() const;
// Get the pres-shell of the document for the top-level window in this tab.
already_AddRefed<nsIPresShell> GetPresShell() const;
// Wrapper for nsIDOMWindowUtils.setCSSViewport(). This updates some state
// variables local to this class before setting it.

View File

@ -26,18 +26,6 @@ namespace layers {
using dom::TabParent;
bool
APZCCallbackHelper::HasValidPresShellId(nsIDOMWindowUtils* aUtils,
const FrameMetrics& aMetrics)
{
MOZ_ASSERT(aUtils);
uint32_t presShellId;
nsresult rv = aUtils->GetPresShellId(&presShellId);
MOZ_ASSERT(NS_SUCCEEDED(rv));
return NS_SUCCEEDED(rv) && aMetrics.GetPresShellId() == presShellId;
}
static void
AdjustDisplayPortForScrollDelta(mozilla::layers::FrameMetrics& aFrameMetrics,
const CSSPoint& aActualScrollOffset)
@ -156,24 +144,16 @@ ScrollFrame(nsIContent* aContent,
}
static void
SetDisplayPortMargins(nsIDOMWindowUtils* aUtils,
SetDisplayPortMargins(nsIPresShell* aPresShell,
nsIContent* aContent,
FrameMetrics& aMetrics)
const FrameMetrics& aMetrics)
{
if (!aContent) {
return;
}
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(aContent);
if (!element) {
return;
}
ScreenMargin margins = aMetrics.GetDisplayPortMargins();
aUtils->SetDisplayPortMarginsForElement(margins.left,
margins.top,
margins.right,
margins.bottom,
element, 0);
nsLayoutUtils::SetDisplayPortMargins(aContent, aPresShell, margins, 0);
CSSRect baseCSS = aMetrics.CalculateCompositedRectInCssPixels();
nsRect base(0, 0,
baseCSS.width * nsPresContext::AppUnitsPerCSSPixel(),
@ -182,12 +162,10 @@ SetDisplayPortMargins(nsIDOMWindowUtils* aUtils,
}
void
APZCCallbackHelper::UpdateRootFrame(nsIDOMWindowUtils* aUtils,
nsIPresShell* aPresShell,
APZCCallbackHelper::UpdateRootFrame(nsIPresShell* aPresShell,
FrameMetrics& aMetrics)
{
// Precondition checks
MOZ_ASSERT(aUtils);
MOZ_ASSERT(aPresShell);
MOZ_ASSERT(aMetrics.GetUseDisplayPortMargins());
if (aMetrics.GetScrollId() == FrameMetrics::NULL_SCROLL_ID) {
@ -214,7 +192,7 @@ APZCCallbackHelper::UpdateRootFrame(nsIDOMWindowUtils* aUtils,
// Note that this needs to happen before scrolling the frame (in UpdateFrameCommon),
// otherwise the scroll position may get clamped incorrectly.
CSSSize scrollPort = aMetrics.CalculateCompositedSizeInCssPixels();
aUtils->SetScrollPositionClampingScrollPortSize(scrollPort.width, scrollPort.height);
nsLayoutUtils::SetScrollPositionClampingScrollPortSize(aPresShell, scrollPort);
nsIContent* content = nsLayoutUtils::FindContentFor(aMetrics.GetScrollId());
ScrollFrame(content, aMetrics);
@ -225,7 +203,17 @@ APZCCallbackHelper::UpdateRootFrame(nsIDOMWindowUtils* aUtils,
* aMetrics.GetAsyncZoom().scale;
nsLayoutUtils::SetResolutionAndScaleTo(aPresShell, presShellResolution);
SetDisplayPortMargins(aUtils, content, aMetrics);
SetDisplayPortMargins(aPresShell, content, aMetrics);
}
static already_AddRefed<nsIPresShell>
GetPresShell(const nsIContent* aContent)
{
nsCOMPtr<nsIPresShell> result;
if (nsIDocument* doc = aContent->GetComposedDoc()) {
result = doc->GetShell();
}
return result.forget();
}
void
@ -239,33 +227,11 @@ APZCCallbackHelper::UpdateSubFrame(nsIContent* aContent,
// We don't currently support zooming for subframes, so nothing extra
// needs to be done beyond the tasks common to this and UpdateRootFrame.
ScrollFrame(aContent, aMetrics);
if (nsCOMPtr<nsIDOMWindowUtils> utils = GetDOMWindowUtils(aContent)) {
SetDisplayPortMargins(utils, aContent, aMetrics);
if (nsCOMPtr<nsIPresShell> shell = GetPresShell(aContent)) {
SetDisplayPortMargins(shell, aContent, aMetrics);
}
}
already_AddRefed<nsIDOMWindowUtils>
APZCCallbackHelper::GetDOMWindowUtils(const nsIDocument* aDoc)
{
nsCOMPtr<nsIDOMWindowUtils> utils;
nsCOMPtr<nsIDOMWindow> window = aDoc->GetDefaultView();
if (window) {
utils = do_GetInterface(window);
}
return utils.forget();
}
already_AddRefed<nsIDOMWindowUtils>
APZCCallbackHelper::GetDOMWindowUtils(const nsIContent* aContent)
{
nsCOMPtr<nsIDOMWindowUtils> utils;
nsIDocument* doc = aContent->GetComposedDoc();
if (doc) {
utils = GetDOMWindowUtils(doc);
}
return utils.forget();
}
bool
APZCCallbackHelper::GetOrCreateScrollIdentifiers(nsIContent* aContent,
uint32_t* aPresShellIdOut,
@ -275,8 +241,11 @@ APZCCallbackHelper::GetOrCreateScrollIdentifiers(nsIContent* aContent,
return false;
}
*aViewIdOut = nsLayoutUtils::FindOrCreateIDFor(aContent);
nsCOMPtr<nsIDOMWindowUtils> utils = GetDOMWindowUtils(aContent);
return utils && (utils->GetPresShellId(aPresShellIdOut) == NS_OK);
if (nsCOMPtr<nsIPresShell> shell = GetPresShell(aContent)) {
*aPresShellIdOut = shell->GetPresShellId();
return true;
}
return false;
}
class FlingSnapEvent : public nsRunnable

View File

@ -41,21 +41,13 @@ class APZCCallbackHelper
typedef mozilla::layers::ScrollableLayerGuid ScrollableLayerGuid;
public:
/* Checks to see if the pres shell that the given FrameMetrics object refers
to is still the valid pres shell for the DOMWindowUtils. This can help
guard against apply stale updates (updates meant for a pres shell that has
since been torn down and replaced). */
static bool HasValidPresShellId(nsIDOMWindowUtils* aUtils,
const FrameMetrics& aMetrics);
/* Applies the scroll and zoom parameters from the given FrameMetrics object to
the root frame corresponding to the given DOMWindowUtils. If tiled thebes
the root frame corresponding to the given pres shell. If tiled thebes
layers are enabled, this will align the displayport to tile boundaries.
Setting the scroll position can cause some small adjustments to be made
to the actual scroll position. aMetrics' display port and scroll position
will be updated with any modifications made. */
static void UpdateRootFrame(nsIDOMWindowUtils* aUtils,
nsIPresShell* aPresShell,
static void UpdateRootFrame(nsIPresShell* aPresShell,
FrameMetrics& aMetrics);
/* Applies the scroll parameters from the given FrameMetrics object to the subframe
@ -67,13 +59,6 @@ public:
static void UpdateSubFrame(nsIContent* aContent,
FrameMetrics& aMetrics);
/* Get the DOMWindowUtils for the window corresponding to the given document. */
static already_AddRefed<nsIDOMWindowUtils> GetDOMWindowUtils(const nsIDocument* aDoc);
/* Get the DOMWindowUtils for the window corresponding to the givent content
element. This might be an iframe inside the tab, for instance. */
static already_AddRefed<nsIDOMWindowUtils> GetDOMWindowUtils(const nsIContent* aContent);
/* Get the presShellId and view ID for the given content element.
* If the view ID does not exist, one is created.
* The pres shell ID should generally already exist; if it doesn't for some

View File

@ -167,26 +167,19 @@ APZController::RequestContentRepaint(const FrameMetrics& aFrameMetrics)
#endif
// We're dealing with a tab, call UpdateRootFrame.
nsCOMPtr<nsIDOMWindowUtils> utils;
nsCOMPtr<nsIDOMWindow> window = subDocument->GetDefaultView();
if (window) {
utils = do_GetInterface(window);
if (utils) {
FrameMetrics metrics = aFrameMetrics;
if (subDocument->GetShell()) {
mozilla::layers::APZCCallbackHelper::UpdateRootFrame(utils, subDocument->GetShell(), metrics);
}
FrameMetrics metrics = aFrameMetrics;
if (subDocument->GetShell()) {
mozilla::layers::APZCCallbackHelper::UpdateRootFrame(subDocument->GetShell(), metrics);
}
#ifdef DEBUG_CONTROLLER
WinUtils::Log("APZController: %I64d mDisplayPortMargins: %0.2f %0.2f %0.2f %0.2f",
metrics.GetScrollId(),
metrics.GetDisplayPortMargins().left,
metrics.GetDisplayPortMargins().top,
metrics.GetDisplayPortMargins().right,
metrics.GetDisplayPortMargins().bottom);
WinUtils::Log("APZController: %I64d mDisplayPortMargins: %0.2f %0.2f %0.2f %0.2f",
metrics.GetScrollId(),
metrics.GetDisplayPortMargins().left,
metrics.GetDisplayPortMargins().top,
metrics.GetDisplayPortMargins().right,
metrics.GetDisplayPortMargins().bottom);
#endif
}
}
}
void