Bug 1152479 - Extract the implementations of layout-related nsIDOMWindowUtils APIs used by APZ into nsLayoutUtils. r=ehsan

--HG--
extra : rebase_source : 175254c3f78cd06bf72e2a25da12eff7a174f87e
extra : source : 0bf92001a2f715b5c20aefc039c30e926b9789c0
This commit is contained in:
Botond Ballo 2015-04-14 13:19:10 -04:00
Родитель e84765d2dc
Коммит 148a784118
5 изменённых файлов: 117 добавлений и 66 удалений

Просмотреть файл

@ -303,10 +303,7 @@ nsDOMWindowUtils::SetCSSViewport(float aWidthPx, float aHeightPx)
return NS_ERROR_FAILURE;
}
nscoord width = nsPresContext::CSSPixelsToAppUnits(aWidthPx);
nscoord height = nsPresContext::CSSPixelsToAppUnits(aHeightPx);
presShell->ResizeReflowOverride(width, height);
nsLayoutUtils::SetCSSViewport(presShell, CSSSize(aWidthPx, aHeightPx));
return NS_OK;
}
@ -522,11 +519,7 @@ nsDOMWindowUtils::SetResolutionAndScaleTo(float aResolution)
return NS_ERROR_FAILURE;
}
nsIScrollableFrame* sf = presShell->GetRootScrollFrameAsScrollable();
if (sf) {
sf->SetResolutionAndScaleTo(aResolution);
presShell->SetResolutionAndScaleTo(aResolution);
}
nsLayoutUtils::SetResolutionAndScaleTo(presShell, aResolution);
return NS_OK;
}
@ -3270,48 +3263,6 @@ nsDOMWindowUtils::GetPlugins(JSContext* cx, JS::MutableHandle<JS::Value> aPlugin
return NS_OK;
}
static void
MaybeReflowForInflationScreenSizeChange(nsPresContext *aPresContext)
{
if (aPresContext) {
nsIPresShell* presShell = aPresContext->GetPresShell();
bool fontInflationWasEnabled = presShell->FontSizeInflationEnabled();
presShell->NotifyFontSizeInflationEnabledIsDirty();
bool changed = false;
if (presShell && presShell->FontSizeInflationEnabled() &&
presShell->FontSizeInflationMinTwips() != 0) {
aPresContext->ScreenSizeInchesForFontInflation(&changed);
}
changed = changed ||
(fontInflationWasEnabled != presShell->FontSizeInflationEnabled());
if (changed) {
nsCOMPtr<nsIDocShell> docShell = aPresContext->GetDocShell();
if (docShell) {
nsCOMPtr<nsIContentViewer> cv;
docShell->GetContentViewer(getter_AddRefs(cv));
if (cv) {
nsTArray<nsCOMPtr<nsIContentViewer> > array;
cv->AppendSubtree(array);
for (uint32_t i = 0, iEnd = array.Length(); i < iEnd; ++i) {
nsCOMPtr<nsIPresShell> shell;
nsCOMPtr<nsIContentViewer> cv = array[i];
cv->GetPresShell(getter_AddRefs(shell));
if (shell) {
nsIFrame *rootFrame = shell->GetRootFrame();
if (rootFrame) {
shell->FrameNeedsReflow(rootFrame,
nsIPresShell::eStyleChange,
NS_FRAME_IS_DIRTY);
}
}
}
}
}
}
}
}
NS_IMETHODIMP
nsDOMWindowUtils::SetScrollPositionClampingScrollPortSize(float aWidth, float aHeight)
{
@ -3328,17 +3279,7 @@ nsDOMWindowUtils::SetScrollPositionClampingScrollPortSize(float aWidth, float aH
return NS_ERROR_FAILURE;
}
presShell->SetScrollPositionClampingScrollPortSize(
nsPresContext::CSSPixelsToAppUnits(aWidth),
nsPresContext::CSSPixelsToAppUnits(aHeight));
// When the "font.size.inflation.minTwips" preference is set, the
// layout depends on the size of the screen. Since when the size
// of the screen changes, the scroll position clamping scroll port
// size also changes, we hook in the needed updates here rather
// than adding a separate notification just for this change.
nsPresContext* presContext = GetPresContext();
MaybeReflowForInflationScreenSizeChange(presContext);
nsLayoutUtils::SetScrollPositionClampingScrollPortSize(presShell, CSSSize(aWidth, aHeight));
return NS_OK;
}

Просмотреть файл

@ -376,7 +376,8 @@ TabChildBase::HandlePossibleViewportChange(const ScreenIntSize& aOldScreenSize)
metrics.SetScrollId(viewId);
}
if (nsIPresShell* shell = document->GetShell()) {
nsIPresShell* shell = document->GetShell();
if (shell) {
if (nsPresContext* context = shell->GetPresContext()) {
metrics.SetDevPixelsPerCSSPixel(CSSToLayoutDeviceScale(
(float)nsPresContext::AppUnitsPerCSSPixel() / context->AppUnitsPerDevPixel()));
@ -389,7 +390,9 @@ TabChildBase::HandlePossibleViewportChange(const ScreenIntSize& aOldScreenSize)
// This is the root layer, so the cumulative resolution is the same
// as the resolution.
metrics.SetPresShellResolution(metrics.GetCumulativeResolution().ToScaleFactor().scale);
utils->SetResolutionAndScaleTo(metrics.GetPresShellResolution());
if (shell) {
nsLayoutUtils::SetResolutionAndScaleTo(shell, metrics.GetPresShellResolution());
}
CSSSize scrollPort = metrics.CalculateCompositedSizeInCssPixels();
utils->SetScrollPositionClampingScrollPortSize(scrollPort.width, scrollPort.height);
@ -919,7 +922,9 @@ TabChild::Observe(nsISupports *aSubject,
// until we we get an inner size.
if (HasValidInnerSize()) {
InitializeRootMetrics();
utils->SetResolutionAndScaleTo(mLastRootMetrics.GetPresShellResolution());
if (nsIPresShell* shell = doc->GetShell()) {
nsLayoutUtils::SetResolutionAndScaleTo(shell, mLastRootMetrics.GetPresShellResolution());
}
HandlePossibleViewportChange(mInnerSize);
}
}

Просмотреть файл

@ -223,7 +223,7 @@ APZCCallbackHelper::UpdateRootFrame(nsIDOMWindowUtils* aUtils,
// last paint.
presShellResolution = aMetrics.GetPresShellResolution()
* aMetrics.GetAsyncZoom().scale;
aUtils->SetResolutionAndScaleTo(presShellResolution);
nsLayoutUtils::SetResolutionAndScaleTo(aPresShell, presShellResolution);
SetDisplayPortMargins(aUtils, content, aMetrics);
}

Просмотреть файл

@ -1068,6 +1068,9 @@ nsLayoutUtils::SetDisplayPortMargins(nsIContent* aContent,
uint32_t aPriority,
RepaintMode aRepaintMode)
{
MOZ_ASSERT(aContent);
MOZ_ASSERT(aContent->GetCurrentDoc() == aPresShell->GetDocument());
DisplayPortMarginsPropertyData* currentData =
static_cast<DisplayPortMarginsPropertyData*>(aContent->GetProperty(nsGkAtoms::DisplayPortMargins));
if (currentData && currentData->mPriority > aPriority) {
@ -8000,6 +8003,87 @@ nsLayoutUtils::GetResolution(nsIPresShell* aPresShell)
return aPresShell->GetResolution();
}
/* static */ void
nsLayoutUtils::SetResolutionAndScaleTo(nsIPresShell* aPresShell, float aResolution)
{
nsIScrollableFrame* sf = aPresShell->GetRootScrollFrameAsScrollable();
if (sf) {
sf->SetResolutionAndScaleTo(aResolution);
aPresShell->SetResolutionAndScaleTo(aResolution);
}
}
static void
MaybeReflowForInflationScreenSizeChange(nsPresContext *aPresContext)
{
if (aPresContext) {
nsIPresShell* presShell = aPresContext->GetPresShell();
bool fontInflationWasEnabled = presShell->FontSizeInflationEnabled();
presShell->NotifyFontSizeInflationEnabledIsDirty();
bool changed = false;
if (presShell && presShell->FontSizeInflationEnabled() &&
presShell->FontSizeInflationMinTwips() != 0) {
aPresContext->ScreenSizeInchesForFontInflation(&changed);
}
changed = changed ||
(fontInflationWasEnabled != presShell->FontSizeInflationEnabled());
if (changed) {
nsCOMPtr<nsIDocShell> docShell = aPresContext->GetDocShell();
if (docShell) {
nsCOMPtr<nsIContentViewer> cv;
docShell->GetContentViewer(getter_AddRefs(cv));
if (cv) {
nsTArray<nsCOMPtr<nsIContentViewer> > array;
cv->AppendSubtree(array);
for (uint32_t i = 0, iEnd = array.Length(); i < iEnd; ++i) {
nsCOMPtr<nsIPresShell> shell;
nsCOMPtr<nsIContentViewer> cv = array[i];
cv->GetPresShell(getter_AddRefs(shell));
if (shell) {
nsIFrame *rootFrame = shell->GetRootFrame();
if (rootFrame) {
shell->FrameNeedsReflow(rootFrame,
nsIPresShell::eStyleChange,
NS_FRAME_IS_DIRTY);
}
}
}
}
}
}
}
}
/* static */ void
nsLayoutUtils::SetScrollPositionClampingScrollPortSize(nsIPresShell* aPresShell, CSSSize aSize)
{
MOZ_ASSERT(aSize.width >= 0.0 && aSize.height >= 0.0);
aPresShell->SetScrollPositionClampingScrollPortSize(
nsPresContext::CSSPixelsToAppUnits(aSize.width),
nsPresContext::CSSPixelsToAppUnits(aSize.height));
// When the "font.size.inflation.minTwips" preference is set, the
// layout depends on the size of the screen. Since when the size
// of the screen changes, the scroll position clamping scroll port
// size also changes, we hook in the needed updates here rather
// than adding a separate notification just for this change.
nsPresContext* presContext = aPresShell->GetPresContext();
MaybeReflowForInflationScreenSizeChange(presContext);
}
/* static */ void
nsLayoutUtils::SetCSSViewport(nsIPresShell* aPresShell, CSSSize aSize)
{
MOZ_ASSERT(aSize.width >= 0.0 && aSize.height >= 0.0);
nscoord width = nsPresContext::CSSPixelsToAppUnits(aSize.width);
nscoord height = nsPresContext::CSSPixelsToAppUnits(aSize.height);
aPresShell->ResizeReflowOverride(width, height);
}
/* static */ uint32_t
nsLayoutUtils::GetTouchActionFromFrame(nsIFrame* aFrame)
{

Просмотреть файл

@ -2583,6 +2583,27 @@ public:
*/
static float GetResolution(nsIPresShell* aPresShell);
/**
* Set the resolution at which rescalable web content is drawn,
* and scales the content by the amount of the resolution
* (see nsIDOMWindowUtils.setResolutionAndScaleTo).
*/
static void SetResolutionAndScaleTo(nsIPresShell* aPresShell, float aResolution);
/**
* Set the scroll port size for the purpose of clamping the scroll position
* for the root scroll frame of this document
* (see nsIDOMWindowUtils.setScrollPositionClampingScrollPortSize).
*/
static void SetScrollPositionClampingScrollPortSize(nsIPresShell* aPresShell,
CSSSize aSize);
/**
* Set the CSS viewport to the given size
* (see nsIDOMWindowUtils.setCSSViewport).
*/
static void SetCSSViewport(nsIPresShell* aPresShell, CSSSize aSize);
private:
static uint32_t sFontSizeInflationEmPerLine;
static uint32_t sFontSizeInflationMinTwips;