2015-07-21 17:51:55 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "MobileViewportManager.h"
|
|
|
|
|
2015-09-10 13:24:34 +03:00
|
|
|
#include "gfxPrefs.h"
|
2015-07-21 17:51:55 +03:00
|
|
|
#include "LayersLogging.h"
|
2016-11-30 06:14:28 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
2015-09-10 13:24:34 +03:00
|
|
|
#include "nsIDOMEvent.h"
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
2015-07-21 17:51:55 +03:00
|
|
|
#include "nsViewManager.h"
|
|
|
|
#include "nsViewportInfo.h"
|
2015-09-10 13:24:34 +03:00
|
|
|
#include "UnitTransforms.h"
|
2016-04-27 21:48:36 +03:00
|
|
|
#include "nsIDocument.h"
|
2015-07-21 17:51:55 +03:00
|
|
|
|
|
|
|
#define MVM_LOG(...)
|
|
|
|
// #define MVM_LOG(...) printf_stderr("MVM: " __VA_ARGS__)
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(MobileViewportManager, nsIDOMEventListener, nsIObserver)
|
|
|
|
|
|
|
|
static const nsLiteralString DOM_META_ADDED = NS_LITERAL_STRING("DOMMetaAdded");
|
2015-08-24 22:35:00 +03:00
|
|
|
static const nsLiteralString DOM_META_CHANGED = NS_LITERAL_STRING("DOMMetaChanged");
|
2015-07-21 17:51:55 +03:00
|
|
|
static const nsLiteralString FULL_ZOOM_CHANGE = NS_LITERAL_STRING("FullZoomChange");
|
2016-01-12 17:47:29 +03:00
|
|
|
static const nsLiteralString LOAD = NS_LITERAL_STRING("load");
|
2015-07-21 17:51:55 +03:00
|
|
|
static const nsLiteralCString BEFORE_FIRST_PAINT = NS_LITERAL_CSTRING("before-first-paint");
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::layers;
|
|
|
|
|
|
|
|
MobileViewportManager::MobileViewportManager(nsIPresShell* aPresShell,
|
|
|
|
nsIDocument* aDocument)
|
|
|
|
: mDocument(aDocument)
|
|
|
|
, mPresShell(aPresShell)
|
|
|
|
, mIsFirstPaint(false)
|
2015-08-03 05:50:54 +03:00
|
|
|
, mPainted(false)
|
2015-07-21 17:51:55 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mPresShell);
|
|
|
|
MOZ_ASSERT(mDocument);
|
|
|
|
|
|
|
|
MVM_LOG("%p: creating with presShell %p document %p\n", this, mPresShell, aDocument);
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
if (nsCOMPtr<nsPIDOMWindowOuter> window = mDocument->GetWindow()) {
|
2015-07-21 17:51:55 +03:00
|
|
|
mEventTarget = window->GetChromeEventHandler();
|
|
|
|
}
|
|
|
|
if (mEventTarget) {
|
|
|
|
mEventTarget->AddEventListener(DOM_META_ADDED, this, false);
|
2015-08-24 22:35:00 +03:00
|
|
|
mEventTarget->AddEventListener(DOM_META_CHANGED, this, false);
|
2015-07-21 17:51:55 +03:00
|
|
|
mEventTarget->AddEventListener(FULL_ZOOM_CHANGE, this, false);
|
2016-01-12 17:47:29 +03:00
|
|
|
mEventTarget->AddEventListener(LOAD, this, true);
|
2015-07-21 17:51:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
|
|
|
|
if (observerService) {
|
|
|
|
observerService->AddObserver(this, BEFORE_FIRST_PAINT.Data(), false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MobileViewportManager::~MobileViewportManager()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MobileViewportManager::Destroy()
|
|
|
|
{
|
|
|
|
MVM_LOG("%p: destroying\n", this);
|
|
|
|
|
|
|
|
if (mEventTarget) {
|
|
|
|
mEventTarget->RemoveEventListener(DOM_META_ADDED, this, false);
|
2015-08-24 22:35:00 +03:00
|
|
|
mEventTarget->RemoveEventListener(DOM_META_CHANGED, this, false);
|
2015-07-21 17:51:55 +03:00
|
|
|
mEventTarget->RemoveEventListener(FULL_ZOOM_CHANGE, this, false);
|
2016-01-12 17:47:29 +03:00
|
|
|
mEventTarget->RemoveEventListener(LOAD, this, true);
|
2015-07-21 17:51:55 +03:00
|
|
|
mEventTarget = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
|
|
|
|
if (observerService) {
|
|
|
|
observerService->RemoveObserver(this, BEFORE_FIRST_PAINT.Data());
|
|
|
|
}
|
|
|
|
|
|
|
|
mDocument = nullptr;
|
|
|
|
mPresShell = nullptr;
|
|
|
|
}
|
|
|
|
|
2016-05-17 21:50:08 +03:00
|
|
|
void
|
Bug 1282902 - Part 3 - Let the MobileViewportManager recalculate the saved resolution if the display width changed before restoring. r=kats
The mobile session store saves the current document resolution in order to restore the previous zoom level when restoring a page. If the display width has changed since the session data was captured (e.g. because the device was rotated), the resolution might have to be scaled appropriately.
Currently, the session store does this scaling by itself by comparing the stored and current window widths, however this implementation is slightly simplified and doesn't cover all use cases, which means some pages can be restored at a wrong zoom level after rotation. To correctly cover all cases, the session store would have to compare viewport widths, too.
Because the MobileViewportManager doesn't wait for the session store to set the restore resolution, the latter has to call setRestoreResolution() as early as possible in order to guarantee that the restore resolution is set before the first paint of the document. Therefore the session store currently calls this after receiving a LocationChange notification. However at that time, the correct viewport for the current document is not yet available, which means the resolution cannot be recalculated by the session store at that point.
Therefore, this patch changes the approach taken and lets the MVM handle all resolution calculations instead. The session store now simply passes the stored previous display dimensions along with the previous document resolution to the MVM, which can then compare them to the current display and viewport widths and scale the resolution appropriately before using it during first paint.
MozReview-Commit-ID: IGxWw87yftK
--HG--
extra : transplant_source : e%8D%BD%26%D2%C3%8E5%E3%2B%C0t%BA%DB%C1%BBs%3F%13%1F
2016-07-01 22:23:25 +03:00
|
|
|
MobileViewportManager::SetRestoreResolution(float aResolution,
|
|
|
|
LayoutDeviceIntSize aDisplaySize)
|
2016-05-17 21:50:08 +03:00
|
|
|
{
|
|
|
|
mRestoreResolution = Some(aResolution);
|
Bug 1282902 - Part 3 - Let the MobileViewportManager recalculate the saved resolution if the display width changed before restoring. r=kats
The mobile session store saves the current document resolution in order to restore the previous zoom level when restoring a page. If the display width has changed since the session data was captured (e.g. because the device was rotated), the resolution might have to be scaled appropriately.
Currently, the session store does this scaling by itself by comparing the stored and current window widths, however this implementation is slightly simplified and doesn't cover all use cases, which means some pages can be restored at a wrong zoom level after rotation. To correctly cover all cases, the session store would have to compare viewport widths, too.
Because the MobileViewportManager doesn't wait for the session store to set the restore resolution, the latter has to call setRestoreResolution() as early as possible in order to guarantee that the restore resolution is set before the first paint of the document. Therefore the session store currently calls this after receiving a LocationChange notification. However at that time, the correct viewport for the current document is not yet available, which means the resolution cannot be recalculated by the session store at that point.
Therefore, this patch changes the approach taken and lets the MVM handle all resolution calculations instead. The session store now simply passes the stored previous display dimensions along with the previous document resolution to the MVM, which can then compare them to the current display and viewport widths and scale the resolution appropriately before using it during first paint.
MozReview-Commit-ID: IGxWw87yftK
--HG--
extra : transplant_source : e%8D%BD%26%D2%C3%8E5%E3%2B%C0t%BA%DB%C1%BBs%3F%13%1F
2016-07-01 22:23:25 +03:00
|
|
|
ScreenIntSize restoreDisplaySize = ViewAs<ScreenPixel>(aDisplaySize,
|
|
|
|
PixelCastJustification::LayoutDeviceIsScreenForBounds);
|
|
|
|
mRestoreDisplaySize = Some(restoreDisplaySize);
|
2016-05-17 21:50:08 +03:00
|
|
|
}
|
|
|
|
|
2015-07-21 17:51:55 +03:00
|
|
|
void
|
|
|
|
MobileViewportManager::RequestReflow()
|
|
|
|
{
|
|
|
|
MVM_LOG("%p: got a reflow request\n", this);
|
|
|
|
RefreshViewportSize(false);
|
|
|
|
}
|
|
|
|
|
2015-11-18 21:53:14 +03:00
|
|
|
void
|
|
|
|
MobileViewportManager::ResolutionUpdated()
|
|
|
|
{
|
|
|
|
MVM_LOG("%p: resolution updated\n", this);
|
|
|
|
RefreshSPCSPS();
|
|
|
|
}
|
|
|
|
|
2015-07-21 17:51:55 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
MobileViewportManager::HandleEvent(nsIDOMEvent* event)
|
|
|
|
{
|
|
|
|
nsAutoString type;
|
|
|
|
event->GetType(type);
|
|
|
|
|
|
|
|
if (type.Equals(DOM_META_ADDED)) {
|
|
|
|
MVM_LOG("%p: got a dom-meta-added event\n", this);
|
2015-08-03 05:50:54 +03:00
|
|
|
RefreshViewportSize(mPainted);
|
2015-08-24 22:35:00 +03:00
|
|
|
} else if (type.Equals(DOM_META_CHANGED)) {
|
|
|
|
MVM_LOG("%p: got a dom-meta-changed event\n", this);
|
|
|
|
RefreshViewportSize(mPainted);
|
2015-07-21 17:51:55 +03:00
|
|
|
} else if (type.Equals(FULL_ZOOM_CHANGE)) {
|
|
|
|
MVM_LOG("%p: got a full-zoom-change event\n", this);
|
|
|
|
RefreshViewportSize(false);
|
2016-01-12 17:47:29 +03:00
|
|
|
} else if (type.Equals(LOAD)) {
|
|
|
|
MVM_LOG("%p: got a load event\n", this);
|
|
|
|
if (!mPainted) {
|
|
|
|
// Load event got fired before the before-first-paint message
|
|
|
|
SetInitialViewport();
|
|
|
|
}
|
2015-07-21 17:51:55 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MobileViewportManager::Observe(nsISupports* aSubject, const char* aTopic, const char16_t* aData)
|
|
|
|
{
|
|
|
|
if (SameCOMIdentity(aSubject, mDocument) && BEFORE_FIRST_PAINT.EqualsASCII(aTopic)) {
|
|
|
|
MVM_LOG("%p: got a before-first-paint event\n", this);
|
2016-01-12 17:47:29 +03:00
|
|
|
if (!mPainted) {
|
|
|
|
// before-first-paint message arrived before load event
|
|
|
|
SetInitialViewport();
|
|
|
|
}
|
2015-07-21 17:51:55 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-12 17:47:29 +03:00
|
|
|
void
|
|
|
|
MobileViewportManager::SetInitialViewport()
|
|
|
|
{
|
|
|
|
MVM_LOG("%p: setting initial viewport\n", this);
|
|
|
|
mIsFirstPaint = true;
|
|
|
|
mPainted = true;
|
|
|
|
RefreshViewportSize(false);
|
|
|
|
}
|
|
|
|
|
2016-05-17 21:50:08 +03:00
|
|
|
CSSToScreenScale
|
|
|
|
MobileViewportManager::ClampZoom(const CSSToScreenScale& aZoom,
|
|
|
|
const nsViewportInfo& aViewportInfo)
|
|
|
|
{
|
|
|
|
CSSToScreenScale zoom = aZoom;
|
|
|
|
if (zoom < aViewportInfo.GetMinZoom()) {
|
|
|
|
zoom = aViewportInfo.GetMinZoom();
|
|
|
|
MVM_LOG("%p: Clamped to %f\n", this, zoom.scale);
|
|
|
|
}
|
|
|
|
if (zoom > aViewportInfo.GetMaxZoom()) {
|
|
|
|
zoom = aViewportInfo.GetMaxZoom();
|
|
|
|
MVM_LOG("%p: Clamped to %f\n", this, zoom.scale);
|
|
|
|
}
|
|
|
|
return zoom;
|
|
|
|
}
|
|
|
|
|
2016-07-02 23:15:19 +03:00
|
|
|
LayoutDeviceToLayerScale
|
|
|
|
MobileViewportManager::ScaleResolutionWithDisplayWidth(const LayoutDeviceToLayerScale& aRes,
|
|
|
|
const float& aDisplayWidthChangeRatio,
|
|
|
|
const CSSSize& aNewViewport,
|
|
|
|
const CSSSize& aOldViewport)
|
|
|
|
{
|
|
|
|
float cssViewportChangeRatio = (aOldViewport.width == 0)
|
|
|
|
? 1.0f : aNewViewport.width / aOldViewport.width;
|
|
|
|
LayoutDeviceToLayerScale newRes(aRes.scale * aDisplayWidthChangeRatio
|
|
|
|
/ cssViewportChangeRatio);
|
|
|
|
MVM_LOG("%p: Old resolution was %f, changed by %f/%f to %f\n", this, aRes.scale,
|
|
|
|
aDisplayWidthChangeRatio, cssViewportChangeRatio, newRes.scale);
|
|
|
|
return newRes;
|
|
|
|
}
|
|
|
|
|
2015-07-21 17:51:55 +03:00
|
|
|
CSSToScreenScale
|
|
|
|
MobileViewportManager::UpdateResolution(const nsViewportInfo& aViewportInfo,
|
|
|
|
const ScreenIntSize& aDisplaySize,
|
|
|
|
const CSSSize& aViewport,
|
|
|
|
const Maybe<float>& aDisplayWidthChangeRatio)
|
|
|
|
{
|
2015-09-29 03:14:26 +03:00
|
|
|
CSSToLayoutDeviceScale cssToDev =
|
|
|
|
mPresShell->GetPresContext()->CSSToDevPixelScale();
|
2015-11-23 17:14:18 +03:00
|
|
|
LayoutDeviceToLayerScale res(mPresShell->GetResolution());
|
2015-07-21 17:51:55 +03:00
|
|
|
|
|
|
|
if (mIsFirstPaint) {
|
2016-05-17 21:50:08 +03:00
|
|
|
CSSToScreenScale defaultZoom;
|
|
|
|
if (mRestoreResolution) {
|
Bug 1282902 - Part 3 - Let the MobileViewportManager recalculate the saved resolution if the display width changed before restoring. r=kats
The mobile session store saves the current document resolution in order to restore the previous zoom level when restoring a page. If the display width has changed since the session data was captured (e.g. because the device was rotated), the resolution might have to be scaled appropriately.
Currently, the session store does this scaling by itself by comparing the stored and current window widths, however this implementation is slightly simplified and doesn't cover all use cases, which means some pages can be restored at a wrong zoom level after rotation. To correctly cover all cases, the session store would have to compare viewport widths, too.
Because the MobileViewportManager doesn't wait for the session store to set the restore resolution, the latter has to call setRestoreResolution() as early as possible in order to guarantee that the restore resolution is set before the first paint of the document. Therefore the session store currently calls this after receiving a LocationChange notification. However at that time, the correct viewport for the current document is not yet available, which means the resolution cannot be recalculated by the session store at that point.
Therefore, this patch changes the approach taken and lets the MVM handle all resolution calculations instead. The session store now simply passes the stored previous display dimensions along with the previous document resolution to the MVM, which can then compare them to the current display and viewport widths and scale the resolution appropriately before using it during first paint.
MozReview-Commit-ID: IGxWw87yftK
--HG--
extra : transplant_source : e%8D%BD%26%D2%C3%8E5%E3%2B%C0t%BA%DB%C1%BBs%3F%13%1F
2016-07-01 22:23:25 +03:00
|
|
|
LayoutDeviceToLayerScale restoreResolution(mRestoreResolution.value());
|
|
|
|
if (mRestoreDisplaySize) {
|
|
|
|
CSSSize prevViewport = mDocument->GetViewportInfo(mRestoreDisplaySize.value()).GetSize();
|
|
|
|
float restoreDisplayWidthChangeRatio = (mRestoreDisplaySize.value().width > 0)
|
|
|
|
? (float)aDisplaySize.width / (float)mRestoreDisplaySize.value().width : 1.0f;
|
|
|
|
|
|
|
|
restoreResolution =
|
|
|
|
ScaleResolutionWithDisplayWidth(restoreResolution,
|
|
|
|
restoreDisplayWidthChangeRatio,
|
|
|
|
aViewport,
|
|
|
|
prevViewport);
|
|
|
|
}
|
|
|
|
defaultZoom = CSSToScreenScale(restoreResolution.scale * cssToDev.scale);
|
2016-05-17 21:50:08 +03:00
|
|
|
MVM_LOG("%p: restored zoom is %f\n", this, defaultZoom.scale);
|
|
|
|
defaultZoom = ClampZoom(defaultZoom, aViewportInfo);
|
|
|
|
} else {
|
|
|
|
defaultZoom = aViewportInfo.GetDefaultZoom();
|
|
|
|
MVM_LOG("%p: default zoom from viewport is %f\n", this, defaultZoom.scale);
|
|
|
|
if (!aViewportInfo.IsDefaultZoomValid()) {
|
|
|
|
defaultZoom = MaxScaleRatio(ScreenSize(aDisplaySize), aViewport);
|
|
|
|
MVM_LOG("%p: Intrinsic computed zoom is %f\n", this, defaultZoom.scale);
|
|
|
|
defaultZoom = ClampZoom(defaultZoom, aViewportInfo);
|
2015-10-03 06:08:18 +03:00
|
|
|
}
|
2015-07-21 17:51:55 +03:00
|
|
|
}
|
|
|
|
MOZ_ASSERT(aViewportInfo.GetMinZoom() <= defaultZoom &&
|
|
|
|
defaultZoom <= aViewportInfo.GetMaxZoom());
|
|
|
|
|
|
|
|
CSSToParentLayerScale zoom = ViewTargetAs<ParentLayerPixel>(defaultZoom,
|
|
|
|
PixelCastJustification::ScreenIsParentLayerForRoot);
|
|
|
|
|
|
|
|
LayoutDeviceToLayerScale resolution = zoom / cssToDev * ParentLayerToLayerScale(1);
|
|
|
|
MVM_LOG("%p: setting resolution %f\n", this, resolution.scale);
|
2015-11-23 17:14:18 +03:00
|
|
|
mPresShell->SetResolutionAndScaleTo(resolution.scale);
|
2015-07-21 17:51:55 +03:00
|
|
|
|
|
|
|
return defaultZoom;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this is not a first paint, then in some cases we want to update the pre-
|
|
|
|
// existing resolution so as to maintain how much actual content is visible
|
|
|
|
// within the display width. Note that "actual content" may be different with
|
|
|
|
// respect to CSS pixels because of the CSS viewport size changing.
|
|
|
|
//
|
|
|
|
// aDisplayWidthChangeRatio is non-empty if:
|
|
|
|
// (a) The meta-viewport tag information changes, and so the CSS viewport
|
2015-08-03 05:50:54 +03:00
|
|
|
// might change as a result. If this happens after the content has been
|
|
|
|
// painted, we want to adjust the zoom to compensate. OR
|
2015-07-21 17:51:55 +03:00
|
|
|
// (b) The display size changed from a nonzero value to another nonzero value.
|
|
|
|
// This covers the case where e.g. the device was rotated, and again we
|
|
|
|
// want to adjust the zoom to compensate.
|
|
|
|
// Note in particular that aDisplayWidthChangeRatio will be None if all that
|
|
|
|
// happened was a change in the full-zoom. In this case, we still want to
|
|
|
|
// compute a new CSS viewport, but we don't want to update the resolution.
|
|
|
|
//
|
|
|
|
// Given the above, the algorithm below accounts for all types of changes I
|
|
|
|
// can conceive of:
|
|
|
|
// 1. screen size changes, CSS viewport does not (pages with no meta viewport
|
|
|
|
// or a fixed size viewport)
|
|
|
|
// 2. screen size changes, CSS viewport also does (pages with a device-width
|
|
|
|
// viewport)
|
|
|
|
// 3. screen size remains constant, but CSS viewport changes (meta viewport
|
|
|
|
// tag is added or removed)
|
|
|
|
// 4. neither screen size nor CSS viewport changes
|
|
|
|
if (aDisplayWidthChangeRatio) {
|
2016-07-02 23:15:19 +03:00
|
|
|
res = ScaleResolutionWithDisplayWidth(res, aDisplayWidthChangeRatio.value(),
|
|
|
|
aViewport, mMobileViewportSize);
|
|
|
|
mPresShell->SetResolutionAndScaleTo(res.scale);
|
2015-07-21 17:51:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return ViewTargetAs<ScreenPixel>(cssToDev * res / ParentLayerToLayerScale(1),
|
|
|
|
PixelCastJustification::ScreenIsParentLayerForRoot);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MobileViewportManager::UpdateSPCSPS(const ScreenIntSize& aDisplaySize,
|
|
|
|
const CSSToScreenScale& aZoom)
|
|
|
|
{
|
|
|
|
ScreenSize compositionSize(aDisplaySize);
|
|
|
|
ScreenMargin scrollbars =
|
2015-08-07 21:23:13 +03:00
|
|
|
LayoutDeviceMargin::FromAppUnits(
|
2015-07-21 17:51:55 +03:00
|
|
|
nsLayoutUtils::ScrollbarAreaToExcludeFromCompositionBoundsFor(
|
2015-08-07 21:23:13 +03:00
|
|
|
mPresShell->GetRootScrollFrame()),
|
|
|
|
mPresShell->GetPresContext()->AppUnitsPerDevPixel())
|
|
|
|
// Scrollbars are not subject to resolution scaling, so LD pixels =
|
|
|
|
// Screen pixels for them.
|
|
|
|
* LayoutDeviceToScreenScale(1.0f);
|
|
|
|
|
2015-07-21 17:51:55 +03:00
|
|
|
compositionSize.width -= scrollbars.LeftRight();
|
|
|
|
compositionSize.height -= scrollbars.TopBottom();
|
|
|
|
CSSSize compSize = compositionSize / aZoom;
|
|
|
|
MVM_LOG("%p: Setting SPCSPS %s\n", this, Stringify(compSize).c_str());
|
|
|
|
nsLayoutUtils::SetScrollPositionClampingScrollPortSize(mPresShell, compSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MobileViewportManager::UpdateDisplayPortMargins()
|
|
|
|
{
|
2015-08-27 15:26:00 +03:00
|
|
|
if (nsIFrame* root = mPresShell->GetRootScrollFrame()) {
|
2015-12-17 01:22:23 +03:00
|
|
|
bool hasDisplayPort = nsLayoutUtils::HasDisplayPort(root->GetContent());
|
2015-11-27 19:20:04 +03:00
|
|
|
bool hasResolution = mPresShell->ScaleToResolution() &&
|
|
|
|
mPresShell->GetResolution() != 1.0f;
|
|
|
|
if (!hasDisplayPort && !hasResolution) {
|
|
|
|
// We only want to update the displayport if there is one already, or
|
|
|
|
// add one if there's a resolution on the document (see bug 1225508
|
|
|
|
// comment 1).
|
2015-08-27 15:26:00 +03:00
|
|
|
return;
|
|
|
|
}
|
2017-03-21 08:16:41 +03:00
|
|
|
nsRect displayportBase =
|
|
|
|
nsRect(nsPoint(0, 0), nsLayoutUtils::CalculateCompositionSizeForFrame(root));
|
|
|
|
// We only create MobileViewportManager for root content documents. If that ever changes
|
|
|
|
// we'd need to limit the size of this displayport base rect because non-toplevel documents
|
|
|
|
// have no limit on their size.
|
|
|
|
MOZ_ASSERT(mPresShell->GetPresContext()->IsRootContentDocument());
|
|
|
|
nsLayoutUtils::SetDisplayPortBaseIfNotSet(root->GetContent(), displayportBase);
|
2015-08-27 15:26:00 +03:00
|
|
|
nsIScrollableFrame* scrollable = do_QueryFrame(root);
|
|
|
|
nsLayoutUtils::CalculateAndSetDisplayPortMargins(scrollable,
|
2015-07-21 17:51:55 +03:00
|
|
|
nsLayoutUtils::RepaintMode::DoNotRepaint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-18 21:53:14 +03:00
|
|
|
void
|
|
|
|
MobileViewportManager::RefreshSPCSPS()
|
|
|
|
{
|
|
|
|
// This function is a subset of RefreshViewportSize, and only updates the
|
|
|
|
// SPCSPS.
|
|
|
|
|
|
|
|
if (!gfxPrefs::APZAllowZooming()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScreenIntSize displaySize = ViewAs<ScreenPixel>(
|
|
|
|
mDisplaySize, PixelCastJustification::LayoutDeviceIsScreenForBounds);
|
|
|
|
|
|
|
|
CSSToLayoutDeviceScale cssToDev =
|
|
|
|
mPresShell->GetPresContext()->CSSToDevPixelScale();
|
2015-11-23 17:14:18 +03:00
|
|
|
LayoutDeviceToLayerScale res(mPresShell->GetResolution());
|
2015-11-18 21:53:14 +03:00
|
|
|
CSSToScreenScale zoom = ViewTargetAs<ScreenPixel>(cssToDev * res / ParentLayerToLayerScale(1),
|
|
|
|
PixelCastJustification::ScreenIsParentLayerForRoot);
|
|
|
|
|
|
|
|
UpdateSPCSPS(displaySize, zoom);
|
|
|
|
}
|
|
|
|
|
2015-07-21 17:51:55 +03:00
|
|
|
void
|
|
|
|
MobileViewportManager::RefreshViewportSize(bool aForceAdjustResolution)
|
|
|
|
{
|
|
|
|
// This function gets called by the various triggers that may result in a
|
|
|
|
// change of the CSS viewport. In some of these cases (e.g. the meta-viewport
|
|
|
|
// tag changes) we want to update the resolution and in others (e.g. the full
|
|
|
|
// zoom changing) we don't want to update the resolution. See the comment in
|
|
|
|
// UpdateResolution for some more detail on this. An important assumption we
|
|
|
|
// make here is that this RefreshViewportSize function will be called
|
|
|
|
// separately for each trigger that changes. For instance it should never get
|
|
|
|
// called such that both the full zoom and the meta-viewport tag have changed;
|
|
|
|
// instead it would get called twice - once after each trigger changes. This
|
|
|
|
// assumption is what allows the aForceAdjustResolution parameter to work as
|
|
|
|
// intended; if this assumption is violated then we will need to add extra
|
|
|
|
// complicated logic in UpdateResolution to ensure we only do the resolution
|
|
|
|
// update in the right scenarios.
|
|
|
|
|
|
|
|
Maybe<float> displayWidthChangeRatio;
|
|
|
|
LayoutDeviceIntSize newDisplaySize;
|
|
|
|
if (nsLayoutUtils::GetContentViewerSize(mPresShell->GetPresContext(), newDisplaySize)) {
|
|
|
|
// See the comment in UpdateResolution for why we're doing this.
|
|
|
|
if (mDisplaySize.width > 0) {
|
|
|
|
if (aForceAdjustResolution || mDisplaySize.width != newDisplaySize.width) {
|
|
|
|
displayWidthChangeRatio = Some((float)newDisplaySize.width / (float)mDisplaySize.width);
|
|
|
|
}
|
|
|
|
} else if (aForceAdjustResolution) {
|
|
|
|
displayWidthChangeRatio = Some(1.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
MVM_LOG("%p: Display width change ratio is %f\n", this, displayWidthChangeRatio.valueOr(0.0f));
|
|
|
|
mDisplaySize = newDisplaySize;
|
|
|
|
}
|
|
|
|
|
|
|
|
MVM_LOG("%p: Computing CSS viewport using %d,%d\n", this,
|
|
|
|
mDisplaySize.width, mDisplaySize.height);
|
|
|
|
if (mDisplaySize.width == 0 || mDisplaySize.height == 0) {
|
|
|
|
// We can't do anything useful here, we should just bail out
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScreenIntSize displaySize = ViewAs<ScreenPixel>(
|
|
|
|
mDisplaySize, PixelCastJustification::LayoutDeviceIsScreenForBounds);
|
2015-10-23 20:21:57 +03:00
|
|
|
nsViewportInfo viewportInfo = mDocument->GetViewportInfo(displaySize);
|
2015-07-21 17:51:55 +03:00
|
|
|
|
|
|
|
CSSSize viewport = viewportInfo.GetSize();
|
|
|
|
MVM_LOG("%p: Computed CSS viewport %s\n", this, Stringify(viewport).c_str());
|
|
|
|
|
|
|
|
if (!mIsFirstPaint && mMobileViewportSize == viewport) {
|
|
|
|
// Nothing changed, so no need to do a reflow
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If it's the first-paint or the viewport changed, we need to update
|
|
|
|
// various APZ properties (the zoom and some things that might depend on it)
|
|
|
|
MVM_LOG("%p: Updating properties because %d || %d\n", this,
|
|
|
|
mIsFirstPaint, mMobileViewportSize != viewport);
|
|
|
|
|
2015-08-24 20:45:44 +03:00
|
|
|
if (gfxPrefs::APZAllowZooming()) {
|
|
|
|
CSSToScreenScale zoom = UpdateResolution(viewportInfo, displaySize, viewport,
|
|
|
|
displayWidthChangeRatio);
|
|
|
|
MVM_LOG("%p: New zoom is %f\n", this, zoom.scale);
|
|
|
|
UpdateSPCSPS(displaySize, zoom);
|
|
|
|
}
|
2015-08-24 20:45:45 +03:00
|
|
|
if (gfxPlatform::AsyncPanZoomEnabled()) {
|
|
|
|
UpdateDisplayPortMargins();
|
|
|
|
}
|
2015-07-21 17:51:55 +03:00
|
|
|
|
2016-05-12 03:06:11 +03:00
|
|
|
CSSSize oldSize = mMobileViewportSize;
|
|
|
|
|
2015-07-21 17:51:55 +03:00
|
|
|
// Update internal state.
|
|
|
|
mIsFirstPaint = false;
|
|
|
|
mMobileViewportSize = viewport;
|
|
|
|
|
|
|
|
// Kick off a reflow.
|
|
|
|
mPresShell->ResizeReflowIgnoreOverride(
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(viewport.width),
|
2016-05-12 03:06:11 +03:00
|
|
|
nsPresContext::CSSPixelsToAppUnits(viewport.height),
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(oldSize.width),
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(oldSize.height));
|
2015-07-21 17:51:55 +03:00
|
|
|
}
|