forked from mirrors/gecko-dev
browserElement_ScrollEvent.js is affected by this change. Before this change the document for iframe mozbrowser was not considered as the root content document, but after this change, it's considered as the root content document. Given the nature of iframe mozbrowser, I believe it's the right behavior. The browser mochitest in this commit fails without this change since the minimum-scale size is used in the out-of-process iframe so that the visual viewport size gets 3x bigger than the expected size. Differential Revision: https://phabricator.services.mozilla.com/D36547 --HG-- extra : moz-landing-system : lando
181 lines
6.2 KiB
C++
181 lines
6.2 KiB
C++
/* 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 "GeckoMVMContext.h"
|
|
|
|
#include "mozilla/PresShell.h"
|
|
#include "mozilla/Services.h"
|
|
#include "mozilla/dom/Document.h"
|
|
#include "nsCOMPtr.h"
|
|
#include "nsIDOMEventListener.h"
|
|
#include "nsIFrame.h"
|
|
#include "nsIObserverService.h"
|
|
#include "nsLayoutUtils.h"
|
|
#include "nsPIDOMWindow.h"
|
|
#include "nsPresContext.h"
|
|
|
|
namespace mozilla {
|
|
|
|
GeckoMVMContext::GeckoMVMContext(dom::Document* aDocument,
|
|
PresShell* aPresShell)
|
|
: mDocument(aDocument), mPresShell(aPresShell) {
|
|
if (nsCOMPtr<nsPIDOMWindowOuter> window = mDocument->GetWindow()) {
|
|
mEventTarget = window->GetChromeEventHandler();
|
|
}
|
|
}
|
|
|
|
void GeckoMVMContext::AddEventListener(const nsAString& aType,
|
|
nsIDOMEventListener* aListener,
|
|
bool aUseCapture) {
|
|
if (mEventTarget) {
|
|
mEventTarget->AddEventListener(aType, aListener, aUseCapture);
|
|
}
|
|
}
|
|
|
|
void GeckoMVMContext::RemoveEventListener(const nsAString& aType,
|
|
nsIDOMEventListener* aListener,
|
|
bool aUseCapture) {
|
|
if (mEventTarget) {
|
|
mEventTarget->RemoveEventListener(aType, aListener, aUseCapture);
|
|
}
|
|
}
|
|
|
|
void GeckoMVMContext::AddObserver(nsIObserver* aObserver, const char* aTopic,
|
|
bool aOwnsWeak) {
|
|
if (nsCOMPtr<nsIObserverService> observerService =
|
|
services::GetObserverService()) {
|
|
observerService->AddObserver(aObserver, aTopic, aOwnsWeak);
|
|
}
|
|
}
|
|
|
|
void GeckoMVMContext::RemoveObserver(nsIObserver* aObserver,
|
|
const char* aTopic) {
|
|
if (nsCOMPtr<nsIObserverService> observerService =
|
|
services::GetObserverService()) {
|
|
observerService->RemoveObserver(aObserver, aTopic);
|
|
}
|
|
}
|
|
|
|
void GeckoMVMContext::Destroy() {
|
|
mEventTarget = nullptr;
|
|
mDocument = nullptr;
|
|
mPresShell = nullptr;
|
|
}
|
|
|
|
nsViewportInfo GeckoMVMContext::GetViewportInfo(
|
|
const ScreenIntSize& aDisplaySize) const {
|
|
MOZ_ASSERT(mDocument);
|
|
return mDocument->GetViewportInfo(aDisplaySize);
|
|
}
|
|
|
|
CSSToLayoutDeviceScale GeckoMVMContext::CSSToDevPixelScale() const {
|
|
MOZ_ASSERT(mPresShell);
|
|
return mPresShell->GetPresContext()->CSSToDevPixelScale();
|
|
}
|
|
|
|
float GeckoMVMContext::GetResolution() const {
|
|
MOZ_ASSERT(mPresShell);
|
|
return mPresShell->GetResolution();
|
|
}
|
|
|
|
bool GeckoMVMContext::SubjectMatchesDocument(nsISupports* aSubject) const {
|
|
MOZ_ASSERT(mDocument);
|
|
return SameCOMIdentity(aSubject, ToSupports(mDocument));
|
|
}
|
|
|
|
Maybe<CSSRect> GeckoMVMContext::CalculateScrollableRectForRSF() const {
|
|
MOZ_ASSERT(mPresShell);
|
|
if (nsIScrollableFrame* rootScrollableFrame =
|
|
mPresShell->GetRootScrollFrameAsScrollable()) {
|
|
return Some(
|
|
CSSRect::FromAppUnits(nsLayoutUtils::CalculateScrollableRectForFrame(
|
|
rootScrollableFrame, nullptr)));
|
|
}
|
|
return Nothing();
|
|
}
|
|
|
|
bool GeckoMVMContext::IsResolutionUpdatedByApz() const {
|
|
MOZ_ASSERT(mPresShell);
|
|
return mPresShell->IsResolutionUpdatedByApz();
|
|
}
|
|
|
|
LayoutDeviceMargin
|
|
GeckoMVMContext::ScrollbarAreaToExcludeFromCompositionBounds() const {
|
|
MOZ_ASSERT(mPresShell);
|
|
return LayoutDeviceMargin::FromAppUnits(
|
|
nsLayoutUtils::ScrollbarAreaToExcludeFromCompositionBoundsFor(
|
|
mPresShell->GetRootScrollFrame()),
|
|
mPresShell->GetPresContext()->AppUnitsPerDevPixel());
|
|
}
|
|
|
|
Maybe<LayoutDeviceIntSize> GeckoMVMContext::GetContentViewerSize() const {
|
|
MOZ_ASSERT(mPresShell);
|
|
LayoutDeviceIntSize result;
|
|
if (nsLayoutUtils::GetContentViewerSize(mPresShell->GetPresContext(),
|
|
result)) {
|
|
return Some(result);
|
|
}
|
|
return Nothing();
|
|
}
|
|
|
|
bool GeckoMVMContext::AllowZoomingForDocument() const {
|
|
MOZ_ASSERT(mDocument);
|
|
return nsLayoutUtils::AllowZoomingForDocument(mDocument);
|
|
}
|
|
|
|
void GeckoMVMContext::SetResolutionAndScaleTo(float aResolution) {
|
|
MOZ_ASSERT(mPresShell);
|
|
mPresShell->SetResolutionAndScaleTo(aResolution,
|
|
ResolutionChangeOrigin::MainThread);
|
|
}
|
|
|
|
void GeckoMVMContext::SetVisualViewportSize(const CSSSize& aSize) {
|
|
MOZ_ASSERT(mPresShell);
|
|
nsLayoutUtils::SetVisualViewportSize(mPresShell, aSize);
|
|
}
|
|
|
|
void GeckoMVMContext::UpdateDisplayPortMargins() {
|
|
MOZ_ASSERT(mPresShell);
|
|
if (nsIFrame* root = mPresShell->GetRootScrollFrame()) {
|
|
bool hasDisplayPort = nsLayoutUtils::HasDisplayPort(root->GetContent());
|
|
bool hasResolution = 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).
|
|
return;
|
|
}
|
|
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()->IsRootContentDocumentCrossProcess());
|
|
nsLayoutUtils::SetDisplayPortBaseIfNotSet(root->GetContent(),
|
|
displayportBase);
|
|
nsIScrollableFrame* scrollable = do_QueryFrame(root);
|
|
nsLayoutUtils::CalculateAndSetDisplayPortMargins(
|
|
scrollable, nsLayoutUtils::RepaintMode::Repaint);
|
|
}
|
|
}
|
|
|
|
void GeckoMVMContext::Reflow(const CSSSize& aNewSize, const CSSSize& aOldSize,
|
|
ResizeEventFlag aResizeEventFlag) {
|
|
MOZ_ASSERT(mPresShell);
|
|
|
|
ResizeReflowOptions reflowOptions = ResizeReflowOptions::NoOption;
|
|
if (aResizeEventFlag == ResizeEventFlag::Suppress) {
|
|
reflowOptions |= ResizeReflowOptions::SuppressResizeEvent;
|
|
}
|
|
|
|
RefPtr<PresShell> presShell = mPresShell;
|
|
presShell->ResizeReflowIgnoreOverride(
|
|
nsPresContext::CSSPixelsToAppUnits(aNewSize.width),
|
|
nsPresContext::CSSPixelsToAppUnits(aNewSize.height),
|
|
nsPresContext::CSSPixelsToAppUnits(aOldSize.width),
|
|
nsPresContext::CSSPixelsToAppUnits(aOldSize.height), reflowOptions);
|
|
}
|
|
|
|
} // namespace mozilla
|