This commit is contained in:
Timothy Nikkel 2019-01-08 14:26:08 -06:00
Родитель 86e161e8f7
Коммит ffd12d481b
1 изменённых файлов: 43 добавлений и 0 удалений

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

@ -97,6 +97,10 @@ void MobileViewportManager::SetRestoreResolution(float aResolution) {
} }
float MobileViewportManager::ComputeIntrinsicResolution() const { float MobileViewportManager::ComputeIntrinsicResolution() const {
if (!mDocument || !mPresShell) {
return 1.f;
}
ScreenIntSize displaySize = ViewAs<ScreenPixel>( ScreenIntSize displaySize = ViewAs<ScreenPixel>(
mDisplaySize, PixelCastJustification::LayoutDeviceIsScreenForBounds); mDisplaySize, PixelCastJustification::LayoutDeviceIsScreenForBounds);
CSSToScreenScale intrinsicScale = CSSToScreenScale intrinsicScale =
@ -124,6 +128,11 @@ void MobileViewportManager::RequestReflow() {
void MobileViewportManager::ResolutionUpdated() { void MobileViewportManager::ResolutionUpdated() {
MVM_LOG("%p: resolution updated\n", this); MVM_LOG("%p: resolution updated\n", this);
if (!mPresShell) {
return;
}
if (!mPainted) { if (!mPainted) {
// Save the value, so our default zoom calculation // Save the value, so our default zoom calculation
// can take it into account later on. // can take it into account later on.
@ -159,6 +168,10 @@ MobileViewportManager::HandleEvent(dom::Event* event) {
NS_IMETHODIMP NS_IMETHODIMP
MobileViewportManager::Observe(nsISupports* aSubject, const char* aTopic, MobileViewportManager::Observe(nsISupports* aSubject, const char* aTopic,
const char16_t* aData) { const char16_t* aData) {
if (!mDocument) {
return;
}
if (SameCOMIdentity(aSubject, ToSupports(mDocument)) && if (SameCOMIdentity(aSubject, ToSupports(mDocument)) &&
BEFORE_FIRST_PAINT.EqualsASCII(aTopic)) { BEFORE_FIRST_PAINT.EqualsASCII(aTopic)) {
MVM_LOG("%p: got a before-first-paint event\n", this); MVM_LOG("%p: got a before-first-paint event\n", this);
@ -222,6 +235,10 @@ void MobileViewportManager::UpdateResolution(
const nsViewportInfo& aViewportInfo, const ScreenIntSize& aDisplaySize, const nsViewportInfo& aViewportInfo, const ScreenIntSize& aDisplaySize,
const CSSSize& aViewportOrContentSize, const CSSSize& aViewportOrContentSize,
const Maybe<float>& aDisplayWidthChangeRatio, UpdateType aType) { const Maybe<float>& aDisplayWidthChangeRatio, UpdateType aType) {
if (!mPresShell || !mDocument) {
return;
}
CSSToLayoutDeviceScale cssToDev = CSSToLayoutDeviceScale cssToDev =
mPresShell->GetPresContext()->CSSToDevPixelScale(); mPresShell->GetPresContext()->CSSToDevPixelScale();
LayoutDeviceToLayerScale res(mPresShell->GetResolution()); LayoutDeviceToLayerScale res(mPresShell->GetResolution());
@ -344,6 +361,10 @@ void MobileViewportManager::UpdateResolution(
ScreenIntSize MobileViewportManager::GetCompositionSize( ScreenIntSize MobileViewportManager::GetCompositionSize(
const ScreenIntSize& aDisplaySize) const { const ScreenIntSize& aDisplaySize) const {
if (!mPresShell) {
return ScreenIntSize();
}
ScreenIntSize compositionSize(aDisplaySize); ScreenIntSize compositionSize(aDisplaySize);
ScreenMargin scrollbars = ScreenMargin scrollbars =
LayoutDeviceMargin::FromAppUnits( LayoutDeviceMargin::FromAppUnits(
@ -362,6 +383,10 @@ ScreenIntSize MobileViewportManager::GetCompositionSize(
void MobileViewportManager::UpdateVisualViewportSize( void MobileViewportManager::UpdateVisualViewportSize(
const ScreenIntSize& aDisplaySize, const CSSToScreenScale& aZoom) { const ScreenIntSize& aDisplaySize, const CSSToScreenScale& aZoom) {
if (!mPresShell) {
return;
}
ScreenSize compositionSize = ScreenSize(GetCompositionSize(aDisplaySize)); ScreenSize compositionSize = ScreenSize(GetCompositionSize(aDisplaySize));
CSSSize compSize = compositionSize / aZoom; CSSSize compSize = compositionSize / aZoom;
@ -370,6 +395,10 @@ void MobileViewportManager::UpdateVisualViewportSize(
} }
void MobileViewportManager::UpdateDisplayPortMargins() { void MobileViewportManager::UpdateDisplayPortMargins() {
if (!mPresShell) {
return;
}
if (nsIFrame* root = mPresShell->GetRootScrollFrame()) { if (nsIFrame* root = mPresShell->GetRootScrollFrame()) {
bool hasDisplayPort = nsLayoutUtils::HasDisplayPort(root->GetContent()); bool hasDisplayPort = nsLayoutUtils::HasDisplayPort(root->GetContent());
bool hasResolution = mPresShell->GetResolution() != 1.0f; bool hasResolution = mPresShell->GetResolution() != 1.0f;
@ -397,6 +426,10 @@ void MobileViewportManager::RefreshVisualViewportSize() {
// This function is a subset of RefreshViewportSize, and only updates the // This function is a subset of RefreshViewportSize, and only updates the
// visual viewport size. // visual viewport size.
if (!mPresShell) {
return;
}
if (!gfxPrefs::APZAllowZooming()) { if (!gfxPrefs::APZAllowZooming()) {
return; return;
} }
@ -429,6 +462,10 @@ void MobileViewportManager::RefreshViewportSize(bool aForceAdjustResolution) {
// complicated logic in UpdateResolution to ensure we only do the resolution // complicated logic in UpdateResolution to ensure we only do the resolution
// update in the right scenarios. // update in the right scenarios.
if (!mPresShell || !mDocument) {
return;
}
Maybe<float> displayWidthChangeRatio; Maybe<float> displayWidthChangeRatio;
LayoutDeviceIntSize newDisplaySize; LayoutDeviceIntSize newDisplaySize;
if (nsLayoutUtils::GetContentViewerSize(mPresShell->GetPresContext(), if (nsLayoutUtils::GetContentViewerSize(mPresShell->GetPresContext(),
@ -486,6 +523,8 @@ void MobileViewportManager::RefreshViewportSize(bool aForceAdjustResolution) {
// Update internal state. // Update internal state.
mMobileViewportSize = viewport; mMobileViewportSize = viewport;
RefPtr<MobileViewportManager> strongThis(this);
// Kick off a reflow. // Kick off a reflow.
mPresShell->ResizeReflowIgnoreOverride( mPresShell->ResizeReflowIgnoreOverride(
nsPresContext::CSSPixelsToAppUnits(viewport.width), nsPresContext::CSSPixelsToAppUnits(viewport.width),
@ -502,6 +541,10 @@ void MobileViewportManager::RefreshViewportSize(bool aForceAdjustResolution) {
void MobileViewportManager::ShrinkToDisplaySizeIfNeeded( void MobileViewportManager::ShrinkToDisplaySizeIfNeeded(
nsViewportInfo& aViewportInfo, const ScreenIntSize& aDisplaySize) { nsViewportInfo& aViewportInfo, const ScreenIntSize& aDisplaySize) {
if (!mPresShell) {
return;
}
if (!gfxPrefs::APZAllowZooming()) { if (!gfxPrefs::APZAllowZooming()) {
// If the APZ is disabled, we don't scale down wider contents to fit them // If the APZ is disabled, we don't scale down wider contents to fit them
// into device screen because users won't be able to zoom out the tiny // into device screen because users won't be able to zoom out the tiny