Bug 1930476 - Improve units in nsFrameLoader and related code. r=geckoview-reviewers,jwatt,ohall

Use LayoutDevice units for most these things, since it's what they are:

  ScreenIntSize(presContext->AppUnitsToDevPixels(size.width), ...

Is clearly a lie :)

Differential Revision: https://phabricator.services.mozilla.com/D228586
This commit is contained in:
Emilio Cobos Álvarez 2024-11-12 15:16:50 +00:00
parent a3b8ffea41
commit b985e29a3f
36 changed files with 168 additions and 198 deletions

View File

@ -11295,8 +11295,8 @@ bool nsContentUtils::IsURIInList(nsIURI* aURI, const nsCString& aList) {
}
/* static */
ScreenIntMargin nsContentUtils::GetWindowSafeAreaInsets(
nsIScreen* aScreen, const ScreenIntMargin& aSafeAreaInsets,
LayoutDeviceIntMargin nsContentUtils::GetWindowSafeAreaInsets(
nsIScreen* aScreen, const LayoutDeviceIntMargin& aSafeAreaInsets,
const LayoutDeviceIntRect& aWindowRect) {
// This calculates safe area insets of window from screen rectangle, window
// rectangle and safe area insets of screen.
@ -11312,36 +11312,23 @@ ScreenIntMargin nsContentUtils::GetWindowSafeAreaInsets(
// | +-------------------------------+ |
// +----------------------------------------+
//
ScreenIntMargin windowSafeAreaInsets;
LayoutDeviceIntMargin windowSafeAreaInsets;
if (windowSafeAreaInsets == aSafeAreaInsets) {
// no safe area insets.
return windowSafeAreaInsets;
}
int32_t screenLeft, screenTop, screenWidth, screenHeight;
nsresult rv =
aScreen->GetRect(&screenLeft, &screenTop, &screenWidth, &screenHeight);
if (NS_WARN_IF(NS_FAILED(rv))) {
return windowSafeAreaInsets;
}
const ScreenIntRect screenRect(screenLeft, screenTop, screenWidth,
screenHeight);
ScreenIntRect safeAreaRect = screenRect;
const LayoutDeviceIntRect screenRect = aScreen->GetRect();
LayoutDeviceIntRect safeAreaRect = screenRect;
safeAreaRect.Deflate(aSafeAreaInsets);
ScreenIntRect windowRect = ViewAs<ScreenPixel>(
aWindowRect, PixelCastJustification::LayoutDeviceIsScreenForTabDims);
// FIXME(bug 1754323): This can trigger because the screen rect is not
// orientation-aware.
// MOZ_ASSERT(screenRect.Contains(windowRect),
// "Screen doesn't contain window rect? Something seems off");
// window's rect of safe area
safeAreaRect = safeAreaRect.Intersect(windowRect);
safeAreaRect = safeAreaRect.Intersect(aWindowRect);
windowSafeAreaInsets.top = safeAreaRect.y - aWindowRect.y;
windowSafeAreaInsets.left = safeAreaRect.x - aWindowRect.x;
@ -11350,7 +11337,7 @@ ScreenIntMargin nsContentUtils::GetWindowSafeAreaInsets(
windowSafeAreaInsets.bottom = aWindowRect.y + aWindowRect.height -
(safeAreaRect.y + safeAreaRect.height);
windowSafeAreaInsets.EnsureAtLeast(ScreenIntMargin());
windowSafeAreaInsets.EnsureAtLeast(LayoutDeviceIntMargin());
// This shouldn't be needed, but it wallpapers orientation issues, see bug
// 1754323.
windowSafeAreaInsets.EnsureAtMost(aSafeAreaInsets);

View File

@ -3423,8 +3423,8 @@ class nsContentUtils {
* Return safe area insets of window that defines as
* https://drafts.csswg.org/css-env-1/#safe-area-insets.
*/
static mozilla::ScreenIntMargin GetWindowSafeAreaInsets(
nsIScreen* aScreen, const mozilla::ScreenIntMargin& aSafeareaInsets,
static mozilla::LayoutDeviceIntMargin GetWindowSafeAreaInsets(
nsIScreen* aScreen, const mozilla::LayoutDeviceIntMargin& aSafeareaInsets,
const mozilla::LayoutDeviceIntRect& aWindowRect);
struct SubresourceCacheValidationInfo {

View File

@ -956,7 +956,7 @@ bool nsFrameLoader::Show(nsSubDocumentFrame* aFrame) {
if (IsRemoteFrame()) {
return ShowRemoteFrame(aFrame);
}
const ScreenIntSize size = aFrame->GetSubdocumentSize();
const LayoutDeviceIntSize size = aFrame->GetSubdocumentSize();
nsresult rv = MaybeCreateDocShell();
if (NS_FAILED(rv)) {
return false;
@ -1123,7 +1123,8 @@ bool nsFrameLoader::ShowRemoteFrame(nsSubDocumentFrame* aFrame) {
baseWindow->GetMainWidget(getter_AddRefs(mainWidget));
nsSizeMode sizeMode =
mainWidget ? mainWidget->SizeMode() : nsSizeMode_Normal;
const auto size = hasSize ? aFrame->GetSubdocumentSize() : ScreenIntSize();
const auto size =
hasSize ? aFrame->GetSubdocumentSize() : LayoutDeviceIntSize();
OwnerShowInfo info(size, GetScrollbarPreference(mOwnerContent), sizeMode);
if (!mRemoteBrowser->Show(info)) {
return false;
@ -2364,7 +2365,7 @@ nsresult nsFrameLoader::CheckForRecursiveLoad(nsIURI* aURI) {
return NS_OK;
}
nsresult nsFrameLoader::GetWindowDimensions(nsIntRect& aRect) {
nsresult nsFrameLoader::GetWindowDimensions(LayoutDeviceIntRect& aRect) {
if (!mOwnerContent) {
return NS_ERROR_FAILURE;
}
@ -2394,8 +2395,8 @@ nsresult nsFrameLoader::GetWindowDimensions(nsIntRect& aRect) {
}
nsCOMPtr<nsIBaseWindow> treeOwnerAsWin(do_GetInterface(parentOwner));
treeOwnerAsWin->GetPosition(&aRect.x, &aRect.y);
treeOwnerAsWin->GetSize(&aRect.width, &aRect.height);
aRect.MoveTo(treeOwnerAsWin->GetPosition());
aRect.SizeTo(treeOwnerAsWin->GetSize());
return NS_OK;
}
@ -2410,8 +2411,8 @@ nsresult nsFrameLoader::UpdatePositionAndSize(nsSubDocumentFrame* aFrame) {
if (!mRemoteBrowserShown) {
ShowRemoteFrame(aFrame);
}
nsIntRect dimensions;
NS_ENSURE_SUCCESS(GetWindowDimensions(dimensions), NS_ERROR_FAILURE);
LayoutDeviceIntRect dimensions;
MOZ_TRY(GetWindowDimensions(dimensions));
mRemoteBrowser->UpdateDimensions(dimensions, size);
mRemoteBrowserSized = true;
}

View File

@ -390,7 +390,7 @@ class nsFrameLoader final : public nsStubMutationObserver,
nsIContentSecurityPolicy** aCsp);
// Properly retrieves documentSize of any subdocument type.
nsresult GetWindowDimensions(nsIntRect& aRect);
nsresult GetWindowDimensions(mozilla::LayoutDeviceIntRect& aRect);
virtual mozilla::dom::ProcessMessageManager* GetProcessMessageManager()
const override;
@ -523,7 +523,7 @@ class nsFrameLoader final : public nsStubMutationObserver,
RefPtr<nsDocShell> mDocShell;
// Holds the last known size of the frame.
mozilla::ScreenIntSize mLazySize;
mozilla::LayoutDeviceIntSize mLazySize;
// Actor for collecting session store data from content children. This will be
// cleared and set to null eagerly when taking down the frameloader to break

View File

@ -66,8 +66,8 @@ bool BrowserBridgeHost::Show(const OwnerShowInfo& aShowInfo) {
return true;
}
void BrowserBridgeHost::UpdateDimensions(const nsIntRect& aRect,
const ScreenIntSize& aSize) {
void BrowserBridgeHost::UpdateDimensions(const LayoutDeviceIntRect& aRect,
const LayoutDeviceIntSize& aSize) {
Unused << mBridge->SendUpdateDimensions(aRect, aSize);
}

View File

@ -21,7 +21,7 @@ namespace mozilla::dom {
* See `dom/docs/Fission-IPC-Diagram.svg` for an overview of the DOM IPC
* actors.
*/
class BrowserBridgeHost : public RemoteBrowser {
class BrowserBridgeHost final : public RemoteBrowser {
public:
typedef mozilla::layers::LayersId LayersId;
@ -48,8 +48,8 @@ class BrowserBridgeHost : public RemoteBrowser {
void DestroyComplete() override;
bool Show(const OwnerShowInfo&) override;
void UpdateDimensions(const nsIntRect& aRect,
const ScreenIntSize& aSize) override;
void UpdateDimensions(const LayoutDeviceIntRect& aRect,
const LayoutDeviceIntSize& aSize) override;
void UpdateEffects(EffectsInfo aInfo) override;

View File

@ -180,7 +180,7 @@ IPCResult BrowserBridgeParent::RecvResumeLoad(uint64_t aPendingSwitchID) {
}
IPCResult BrowserBridgeParent::RecvUpdateDimensions(
const nsIntRect& aRect, const ScreenIntSize& aSize) {
const LayoutDeviceIntRect& aRect, const LayoutDeviceIntSize& aSize) {
mBrowserParent->UpdateDimensions(aRect, aSize);
return IPC_OK();
}

View File

@ -76,8 +76,8 @@ class BrowserBridgeParent : public PBrowserBridgeParent {
mozilla::ipc::IPCResult RecvScrollbarPreferenceChanged(ScrollbarPreference);
mozilla::ipc::IPCResult RecvLoadURL(nsDocShellLoadState* aLoadState);
mozilla::ipc::IPCResult RecvResumeLoad(uint64_t aPendingSwitchID);
mozilla::ipc::IPCResult RecvUpdateDimensions(const nsIntRect& aRect,
const ScreenIntSize& aSize);
mozilla::ipc::IPCResult RecvUpdateDimensions(
const LayoutDeviceIntRect& aRect, const LayoutDeviceIntSize& aSize);
mozilla::ipc::IPCResult RecvUpdateEffects(const EffectsInfo& aEffects);
mozilla::ipc::IPCResult RecvUpdateRemotePrintSettings(
const embedding::PrintData&);

View File

@ -28,6 +28,7 @@
#include "mozilla/IMEStateManager.h"
#include "mozilla/LookAndFeel.h"
#include "mozilla/MouseEvents.h"
#include "mozilla/widget/ScreenManager.h"
#include "mozilla/NativeKeyBindingsType.h"
#include "mozilla/NullPrincipal.h"
#include "mozilla/PointerLockManager.h"
@ -604,7 +605,7 @@ BrowserChild::SetDimensions(DimensionRequest&& aRequest) {
NS_IMETHODIMP
BrowserChild::GetDimensions(DimensionKind aDimensionKind, int32_t* aX,
int32_t* aY, int32_t* aCx, int32_t* aCy) {
ScreenIntRect rect = GetOuterRect();
LayoutDeviceIntRect rect = GetOuterRect();
if (aDimensionKind == DimensionKind::Inner) {
if (aX || aY) {
return NS_ERROR_NOT_IMPLEMENTED;
@ -1007,7 +1008,7 @@ mozilla::ipc::IPCResult BrowserChild::RecvUpdateRemotePrintSettings(
}
void BrowserChild::DoFakeShow(const ParentShowInfo& aParentShowInfo) {
OwnerShowInfo ownerInfo{ScreenIntSize(), ScrollbarPreference::Auto,
OwnerShowInfo ownerInfo{LayoutDeviceIntSize(), ScrollbarPreference::Auto,
nsSizeMode_Normal};
RecvShow(aParentShowInfo, ownerInfo);
mDidFakeShow = true;
@ -1125,20 +1126,20 @@ mozilla::ipc::IPCResult BrowserChild::RecvUpdateDimensions(
mHasValidInnerSize = true;
}
ScreenIntSize screenSize = GetInnerSize();
ScreenIntRect screenRect = GetOuterRect();
const LayoutDeviceIntSize innerSize = GetInnerSize();
// Make sure to set the size on the document viewer first. The
// MobileViewportManager needs the content viewer size to be updated before
// the reflow, otherwise it gets a stale size when it computes a new CSS
// viewport.
nsCOMPtr<nsIBaseWindow> baseWin = do_QueryInterface(WebNavigation());
baseWin->SetPositionAndSize(0, 0, screenSize.width, screenSize.height,
baseWin->SetPositionAndSize(0, 0, innerSize.width, innerSize.height,
nsIBaseWindow::eRepaint);
mPuppetWidget->Resize(screenRect.x + mClientOffset.x + mChromeOffset.x,
screenRect.y + mClientOffset.y + mChromeOffset.y,
screenSize.width, screenSize.height, true);
const LayoutDeviceIntRect outerRect =
GetOuterRect() + mClientOffset + mChromeOffset;
mPuppetWidget->Resize(outerRect.x, outerRect.y, innerSize.width,
innerSize.height, true);
RecvSafeAreaInsetsChanged(mPuppetWidget->GetSafeAreaInsets());
@ -3345,23 +3346,22 @@ void BrowserChild::NotifyJankedAnimations(
mozilla::ipc::IPCResult BrowserChild::RecvUIResolutionChanged(
const float& aDpi, const int32_t& aRounding, const double& aScale) {
ScreenIntSize oldScreenSize = GetInnerSize();
const LayoutDeviceIntSize oldInnerSize = GetInnerSize();
if (aDpi > 0) {
mPuppetWidget->UpdateBackingScaleCache(aDpi, aRounding, aScale);
}
ScreenIntSize screenSize = GetInnerSize();
if (mHasValidInnerSize && oldScreenSize != screenSize) {
ScreenIntRect screenRect = GetOuterRect();
const LayoutDeviceIntSize innerSize = GetInnerSize();
if (mHasValidInnerSize && oldInnerSize != innerSize) {
// See RecvUpdateDimensions for the order of these operations.
nsCOMPtr<nsIBaseWindow> baseWin = do_QueryInterface(WebNavigation());
baseWin->SetPositionAndSize(0, 0, screenSize.width, screenSize.height,
baseWin->SetPositionAndSize(0, 0, innerSize.width, innerSize.height,
nsIBaseWindow::eRepaint);
mPuppetWidget->Resize(screenRect.x + mClientOffset.x + mChromeOffset.x,
screenRect.y + mClientOffset.y + mChromeOffset.y,
screenSize.width, screenSize.height, true);
const LayoutDeviceIntRect outerRect =
GetOuterRect() + mClientOffset + mChromeOffset;
mPuppetWidget->Resize(outerRect.x, outerRect.y, innerSize.width,
innerSize.height, true);
}
nsCOMPtr<Document> document(GetTopLevelDocument());
@ -3375,32 +3375,23 @@ mozilla::ipc::IPCResult BrowserChild::RecvUIResolutionChanged(
}
mozilla::ipc::IPCResult BrowserChild::RecvSafeAreaInsetsChanged(
const mozilla::ScreenIntMargin& aSafeAreaInsets) {
const mozilla::LayoutDeviceIntMargin& aSafeAreaInsets) {
mPuppetWidget->UpdateSafeAreaInsets(aSafeAreaInsets);
nsCOMPtr<nsIScreenManager> screenMgr =
do_GetService("@mozilla.org/gfx/screenmanager;1");
ScreenIntMargin currentSafeAreaInsets;
if (screenMgr) {
// aSafeAreaInsets is for current screen. But we have to calculate
// safe insets for content window.
int32_t x, y, cx, cy;
GetDimensions(DimensionKind::Outer, &x, &y, &cx, &cy);
nsCOMPtr<nsIScreen> screen;
screenMgr->ScreenForRect(x, y, cx, cy, getter_AddRefs(screen));
LayoutDeviceIntMargin currentSafeAreaInsets;
// aSafeAreaInsets is for current screen. But we have to calculate safe insets
// for content window.
LayoutDeviceIntRect outerRect = GetOuterRect();
RefPtr<Screen> screen = widget::ScreenManager::GetSingleton().ScreenForRect(
RoundedToInt(outerRect / mPuppetWidget->GetDesktopToDeviceScale()));
if (screen) {
LayoutDeviceIntRect windowRect(x + mClientOffset.x + mChromeOffset.x,
y + mClientOffset.y + mChromeOffset.y, cx,
cy);
LayoutDeviceIntRect windowRect = outerRect + mClientOffset + mChromeOffset;
currentSafeAreaInsets = nsContentUtils::GetWindowSafeAreaInsets(
screen, aSafeAreaInsets, windowRect);
}
}
if (nsCOMPtr<Document> document = GetTopLevelDocument()) {
nsPresContext* presContext = document->GetPresContext();
if (presContext) {
if (nsPresContext* presContext = document->GetPresContext()) {
presContext->SetSafeAreaInsets(currentSafeAreaInsets);
}
}
@ -3441,11 +3432,8 @@ bool BrowserChild::DeallocPPaymentRequestChild(PPaymentRequestChild* actor) {
return true;
}
ScreenIntSize BrowserChild::GetInnerSize() {
LayoutDeviceIntSize innerSize =
RoundedToInt(mUnscaledInnerSize * mPuppetWidget->GetDefaultScale());
return ViewAs<ScreenPixel>(
innerSize, PixelCastJustification::LayoutDeviceIsScreenForTabDims);
LayoutDeviceIntSize BrowserChild::GetInnerSize() {
return RoundedToInt(mUnscaledInnerSize * mPuppetWidget->GetDefaultScale());
};
Maybe<nsRect> BrowserChild::GetVisibleRect() const {
@ -3489,11 +3477,8 @@ BrowserChild::GetTopLevelViewportVisibleRectInSelfCoords() const {
return rect;
}
ScreenIntRect BrowserChild::GetOuterRect() {
LayoutDeviceIntRect outerRect =
RoundedToInt(mUnscaledOuterRect * mPuppetWidget->GetDefaultScale());
return ViewAs<ScreenPixel>(
outerRect, PixelCastJustification::LayoutDeviceIsScreenForTabDims);
LayoutDeviceIntRect BrowserChild::GetOuterRect() {
return RoundedToInt(mUnscaledOuterRect * mPuppetWidget->GetDefaultScale());
}
void BrowserChild::PaintWhileInterruptingJS() {

View File

@ -436,7 +436,7 @@ class BrowserChild final : public nsMessageManagerScriptExecutor,
const IPCTabContext& aContext);
mozilla::ipc::IPCResult RecvSafeAreaInsetsChanged(
const mozilla::ScreenIntMargin& aSafeAreaInsets);
const mozilla::LayoutDeviceIntMargin& aSafeAreaInsets);
#ifdef ACCESSIBILITY
PDocAccessibleChild* AllocPDocAccessibleChild(
@ -568,7 +568,7 @@ class BrowserChild final : public nsMessageManagerScriptExecutor,
const mozilla::layers::CompositorOptions& GetCompositorOptions() const;
bool AsyncPanZoomEnabled() const;
ScreenIntSize GetInnerSize();
LayoutDeviceIntSize GetInnerSize();
CSSSize GetUnscaledInnerSize() { return mUnscaledInnerSize; }
Maybe<nsRect> GetVisibleRect() const;
@ -758,7 +758,7 @@ class BrowserChild final : public nsMessageManagerScriptExecutor,
bool HasValidInnerSize();
ScreenIntRect GetOuterRect();
LayoutDeviceIntRect GetOuterRect();
void SetUnscaledInnerSize(const CSSSize& aSize) {
mUnscaledInnerSize = aSize;

View File

@ -90,8 +90,8 @@ bool BrowserHost::Show(const OwnerShowInfo& aShowInfo) {
return mRoot->Show(aShowInfo);
}
void BrowserHost::UpdateDimensions(const nsIntRect& aRect,
const ScreenIntSize& aSize) {
void BrowserHost::UpdateDimensions(const LayoutDeviceIntRect& aRect,
const LayoutDeviceIntSize& aSize) {
mRoot->UpdateDimensions(aRect, aSize);
}

View File

@ -87,8 +87,8 @@ class BrowserHost : public RemoteBrowser,
void DestroyComplete() override;
bool Show(const OwnerShowInfo&) override;
void UpdateDimensions(const nsIntRect& aRect,
const ScreenIntSize& aSize) override;
void UpdateDimensions(const LayoutDeviceIntRect& aRect,
const LayoutDeviceIntSize& aSize) override;
void UpdateEffects(EffectsInfo aInfo) override;

View File

@ -1027,8 +1027,7 @@ void BrowserParent::InitRendering() {
RefPtr<nsIWidget> widget = GetTopLevelWidget();
if (widget) {
ScreenIntMargin safeAreaInsets = widget->GetSafeAreaInsets();
Unused << SendSafeAreaInsetsChanged(safeAreaInsets);
Unused << SendSafeAreaInsetsChanged(widget->GetSafeAreaInsets());
}
#if defined(MOZ_WIDGET_ANDROID)
@ -1116,7 +1115,7 @@ nsresult BrowserParent::UpdatePosition() {
if (!frameLoader) {
return NS_OK;
}
nsIntRect windowDims;
LayoutDeviceIntRect windowDims;
NS_ENSURE_SUCCESS(frameLoader->GetWindowDimensions(windowDims),
NS_ERROR_FAILURE);
// Avoid updating sizes here.
@ -1139,8 +1138,8 @@ void BrowserParent::NotifyPositionUpdatedForContentsInPopup() {
}
}
void BrowserParent::UpdateDimensions(const nsIntRect& rect,
const ScreenIntSize& size) {
void BrowserParent::UpdateDimensions(const LayoutDeviceIntRect& rect,
const LayoutDeviceIntSize& size) {
if (mIsDestroyed) {
return;
}
@ -1169,26 +1168,18 @@ void BrowserParent::UpdateDimensions(const nsIntRect& rect,
}
DimensionInfo BrowserParent::GetDimensionInfo() {
LayoutDeviceIntRect devicePixelRect = ViewAs<LayoutDevicePixel>(
mRect, PixelCastJustification::LayoutDeviceIsScreenForTabDims);
LayoutDeviceIntSize devicePixelSize = ViewAs<LayoutDevicePixel>(
mDimensions, PixelCastJustification::LayoutDeviceIsScreenForTabDims);
CSSRect unscaledRect = devicePixelRect / mDefaultScale;
CSSSize unscaledSize = devicePixelSize / mDefaultScale;
DimensionInfo di(unscaledRect, unscaledSize, mClientOffset, mChromeOffset);
return di;
CSSRect unscaledRect = mRect / mDefaultScale;
CSSSize unscaledSize = mDimensions / mDefaultScale;
return DimensionInfo(unscaledRect, unscaledSize, mClientOffset,
mChromeOffset);
}
void BrowserParent::UpdateNativePointerLockCenter(nsIWidget* aWidget) {
if (!mLockedNativePointer) {
return;
}
LayoutDeviceIntRect dims(
{0, 0},
ViewAs<LayoutDevicePixel>(
mDimensions, PixelCastJustification::LayoutDeviceIsScreenForTabDims));
aWidget->SetNativePointerLockCenter((dims + mChromeOffset).Center());
aWidget->SetNativePointerLockCenter(
LayoutDeviceIntRect(mChromeOffset, mDimensions).Center());
}
void BrowserParent::SizeModeChanged(const nsSizeMode& aSizeMode) {

View File

@ -468,7 +468,8 @@ class BrowserParent final : public PBrowserParent,
bool Show(const OwnerShowInfo&);
void UpdateDimensions(const nsIntRect& aRect, const ScreenIntSize& aSize);
void UpdateDimensions(const LayoutDeviceIntRect& aRect,
const LayoutDeviceIntSize& aSize);
DimensionInfo GetDimensionInfo();
@ -922,8 +923,8 @@ class BrowserParent final : public PBrowserParent,
};
nsTArray<SentKeyEventData> mWaitingReplyKeyboardEvents;
nsIntRect mRect;
ScreenIntSize mDimensions;
LayoutDeviceIntRect mRect;
LayoutDeviceIntSize mDimensions;
float mDPI;
int32_t mRounding;
CSSToLayoutDeviceScale mDefaultScale;

View File

@ -39,7 +39,7 @@ using mozilla::DesktopToLayoutDeviceScale from "Units.h";
using mozilla::CSSToLayoutDeviceScale from "Units.h";
using mozilla::CSSRect from "Units.h";
using mozilla::CSSSize from "Units.h";
using mozilla::ScreenIntSize from "Units.h";
using mozilla::LayoutDeviceIntSize from "Units.h";
using mozilla::LayoutDeviceIntPoint from "Units.h";
using mozilla::ImageIntSize from "Units.h";
using nsSizeMode from "nsIWidgetListener.h";
@ -315,7 +315,7 @@ struct ParentShowInfo
struct OwnerShowInfo {
// This can be an IntSize rather than a Rect because content processes always
// render to a virtual <0, 0> top-left point.
ScreenIntSize size;
LayoutDeviceIntSize size;
// TODO(emilio): Margin preferences go here.
ScrollbarPreference scrollbarPreference;

View File

@ -48,9 +48,8 @@ using mozilla::gfx::Matrix4x4 from "mozilla/gfx/Matrix.h";
using mozilla::gfx::SurfaceFormat from "mozilla/gfx/Types.h";
using mozilla::LayoutDeviceIntPoint from "Units.h";
using mozilla::LayoutDevicePoint from "Units.h";
using mozilla::LayoutDeviceIntMargin from "Units.h";
using mozilla::ScreenIntCoord from "Units.h";
using mozilla::ScreenIntMargin from "Units.h";
using mozilla::ScreenIntPoint from "Units.h";
using mozilla::ScreenRect from "Units.h";
using struct mozilla::layers::ScrollableLayerGuid from "mozilla/layers/ScrollableLayerGuid.h";
using struct mozilla::layers::ZoomConstraints from "mozilla/layers/ZoomConstraints.h";
@ -936,7 +935,7 @@ child:
* Tell the child that the safe area of widget has changed.
*
*/
async SafeAreaInsetsChanged(ScreenIntMargin aSafeAreaInsets);
async SafeAreaInsetsChanged(LayoutDeviceIntMargin aSafeAreaInsets);
/**
* Tell the browser that its frame loader has been swapped

View File

@ -23,7 +23,6 @@ using mozilla::ScrollAxis from "mozilla/PresShellForwards.h";
using mozilla::ScrollFlags from "mozilla/PresShellForwards.h";
using struct nsRect from "nsRect.h";
using mozilla::dom::CallerType from "mozilla/dom/BindingDeclarations.h";
using nsIntRect from "nsRect.h";
using mozilla::dom::EmbedderElementEventType from "mozilla/dom/TabMessageTypes.h";
[RefCounted] using class nsDocShellLoadState from "nsDocShellLoadState.h";
using mozilla::IntrinsicSize from "nsIFrame.h";
@ -92,7 +91,7 @@ parent:
// Out of process rendering.
async Show(OwnerShowInfo info);
async ScrollbarPreferenceChanged(ScrollbarPreference pref);
[Compress=all] async UpdateDimensions(nsIntRect rect, ScreenIntSize size);
[Compress=all] async UpdateDimensions(LayoutDeviceIntRect rect, LayoutDeviceIntSize size);
async RenderLayers(bool aEnabled);
async UpdateEffects(EffectsInfo aEffects);

View File

@ -61,8 +61,8 @@ class RemoteBrowser : public nsISupports {
virtual void DestroyComplete() = 0;
virtual bool Show(const OwnerShowInfo&) = 0;
virtual void UpdateDimensions(const nsIntRect& aRect,
const ScreenIntSize& aSize) = 0;
virtual void UpdateDimensions(const LayoutDeviceIntRect& aRect,
const LayoutDeviceIntSize& aSize) = 0;
virtual void UpdateEffects(EffectsInfo aInfo) = 0;
};

View File

@ -44,9 +44,6 @@ enum class PixelCastJustification : uint8_t {
// reference point as a screen point. The reverse is useful when synthetically
// created WidgetEvents need to be converted back to InputData.
LayoutDeviceIsScreenForUntransformedEvent,
// Similar to LayoutDeviceIsScreenForUntransformedEvent, PBrowser handles
// some widget/tab dimension information as the OS does -- in screen units.
LayoutDeviceIsScreenForTabDims,
// A combination of LayoutDeviceIsScreenForBounds and
// ScreenIsParentLayerForRoot, which is how we're using it.
LayoutDeviceIsParentLayerForRCDRSF,

View File

@ -890,8 +890,8 @@ template <class Src, class Dst>
gfx::MarginTyped<Dst> operator/(const gfx::MarginTyped<Src>& aMargin,
const gfx::ScaleFactor<Dst, Src>& aScale) {
return gfx::MarginTyped<Dst>(
aMargin.top / aScale.scale, aMargin.right / aScale.scale,
aMargin.bottom / aScale.scale, aMargin.left / aScale.scale);
aMargin.top.value / aScale.scale, aMargin.right.value / aScale.scale,
aMargin.bottom.value / aScale.scale, aMargin.left.value / aScale.scale);
}
template <class Src, class Dst, class F>

View File

@ -740,14 +740,12 @@ nsresult nsDocumentViewer::InitPresentationStuff(bool aDoInitialReflow) {
if (mWindow && mDocument->IsTopLevelContentDocument()) {
// Set initial safe area insets
ScreenIntMargin windowSafeAreaInsets;
LayoutDeviceIntMargin windowSafeAreaInsets;
LayoutDeviceIntRect windowRect = mWindow->GetScreenBounds();
nsCOMPtr<nsIScreen> screen = mWindow->GetWidgetScreen();
if (screen) {
if (nsCOMPtr<nsIScreen> screen = mWindow->GetWidgetScreen()) {
windowSafeAreaInsets = nsContentUtils::GetWindowSafeAreaInsets(
screen, mWindow->GetSafeAreaInsets(), windowRect);
}
mPresContext->SetSafeAreaInsets(windowSafeAreaInsets);
}

View File

@ -3204,7 +3204,8 @@ nscoord nsPresContext::GetBimodalDynamicToolbarHeightInAppUnits() const {
: 0;
}
void nsPresContext::SetSafeAreaInsets(const ScreenIntMargin& aSafeAreaInsets) {
void nsPresContext::SetSafeAreaInsets(
const LayoutDeviceIntMargin& aSafeAreaInsets) {
if (mSafeAreaInsets == aSafeAreaInsets) {
return;
}

View File

@ -544,9 +544,11 @@ class nsPresContext : public nsISupports, public mozilla::SupportsWeakPtr {
/**
* Notify the pres context that the safe area insets have changed.
*/
void SetSafeAreaInsets(const mozilla::ScreenIntMargin& aInsets);
void SetSafeAreaInsets(const mozilla::LayoutDeviceIntMargin& aInsets);
mozilla::ScreenIntMargin GetSafeAreaInsets() const { return mSafeAreaInsets; }
const mozilla::LayoutDeviceIntMargin& GetSafeAreaInsets() const {
return mSafeAreaInsets;
}
void RegisterManagedPostRefreshObserver(mozilla::ManagedPostRefreshObserver*);
void UnregisterManagedPostRefreshObserver(
@ -1245,7 +1247,7 @@ class nsPresContext : public nsISupports, public mozilla::SupportsWeakPtr {
// The software keyboard height.
mozilla::ScreenIntCoord mKeyboardHeight;
// Safe area insets support
mozilla::ScreenIntMargin mSafeAreaInsets;
mozilla::LayoutDeviceIntMargin mSafeAreaInsets;
nsSize mPageSize;
// The computed page margins from the print settings.

View File

@ -283,25 +283,26 @@ nsRect nsSubDocumentFrame::GetDestRect(const nsRect& aConstraintRect) {
GetIntrinsicRatio(), StylePosition());
}
ScreenIntSize nsSubDocumentFrame::GetSubdocumentSize() {
LayoutDeviceIntSize nsSubDocumentFrame::GetSubdocumentSize() {
if (HasAnyStateBits(NS_FRAME_FIRST_REFLOW)) {
if (RefPtr<nsFrameLoader> frameloader = FrameLoader()) {
nsIFrame* detachedFrame = frameloader->GetDetachedSubdocFrame();
if (nsView* view = detachedFrame ? detachedFrame->GetView() : nullptr) {
nsSize size = view->GetBounds().Size();
nsPresContext* presContext = detachedFrame->PresContext();
return ScreenIntSize(presContext->AppUnitsToDevPixels(size.width),
return LayoutDeviceIntSize(
presContext->AppUnitsToDevPixels(size.width),
presContext->AppUnitsToDevPixels(size.height));
}
}
// Pick some default size for now. Using 10x10 because that's what the
// code used to do.
return ScreenIntSize(10, 10);
return LayoutDeviceIntSize(10, 10);
}
nsSize docSizeAppUnits = GetDestRect().Size();
nsPresContext* pc = PresContext();
return ScreenIntSize(pc->AppUnitsToDevPixels(docSizeAppUnits.width),
return LayoutDeviceIntSize(pc->AppUnitsToDevPixels(docSizeAppUnits.width),
pc->AppUnitsToDevPixels(docSizeAppUnits.height));
}

View File

@ -103,7 +103,7 @@ class nsSubDocumentFrame final : public nsAtomicContainerFrame,
mozilla::PresShell* GetSubdocumentPresShellForPainting(uint32_t aFlags);
nsRect GetDestRect();
nsRect GetDestRect(const nsRect& aConstraintRect);
mozilla::ScreenIntSize GetSubdocumentSize();
mozilla::LayoutDeviceIntSize GetSubdocumentSize();
bool ContentReactsToPointerEvents() const;

View File

@ -1664,11 +1664,13 @@ bool Gecko_AssertClassAttrValueIsSane(const nsAttrValue* aValue) {
void Gecko_GetSafeAreaInsets(const nsPresContext* aPresContext, float* aTop,
float* aRight, float* aBottom, float* aLeft) {
MOZ_ASSERT(aPresContext);
ScreenIntMargin safeAreaInsets = aPresContext->GetSafeAreaInsets();
*aTop = aPresContext->DevPixelsToFloatCSSPixels(safeAreaInsets.top);
*aRight = aPresContext->DevPixelsToFloatCSSPixels(safeAreaInsets.right);
*aBottom = aPresContext->DevPixelsToFloatCSSPixels(safeAreaInsets.bottom);
*aLeft = aPresContext->DevPixelsToFloatCSSPixels(safeAreaInsets.left);
const CSSMargin insets =
LayoutDeviceMargin(aPresContext->GetSafeAreaInsets()) /
aPresContext->CSSToDevPixelScale();
*aTop = insets.top;
*aRight = insets.right;
*aBottom = insets.bottom;
*aLeft = insets.left;
}
void Gecko_PrintfStderr(const nsCString* aStr) {

View File

@ -1013,7 +1013,8 @@ nsEventStatus nsView::HandleEvent(WidgetGUIEvent* aEvent,
return result;
}
void nsView::SafeAreaInsetsChanged(const ScreenIntMargin& aSafeAreaInsets) {
void nsView::SafeAreaInsetsChanged(
const LayoutDeviceIntMargin& aSafeAreaInsets) {
if (!IsRoot()) {
return;
}
@ -1023,10 +1024,9 @@ void nsView::SafeAreaInsetsChanged(const ScreenIntMargin& aSafeAreaInsets) {
return;
}
ScreenIntMargin windowSafeAreaInsets;
LayoutDeviceIntRect windowRect = mWindow->GetScreenBounds();
nsCOMPtr<nsIScreen> screen = mWindow->GetWidgetScreen();
if (screen) {
LayoutDeviceIntMargin windowSafeAreaInsets;
const LayoutDeviceIntRect windowRect = mWindow->GetScreenBounds();
if (nsCOMPtr<nsIScreen> screen = mWindow->GetWidgetScreen()) {
windowSafeAreaInsets = nsContentUtils::GetWindowSafeAreaInsets(
screen, aSafeAreaInsets, windowRect);
}

View File

@ -408,37 +408,33 @@ class nsView final : public nsIWidgetListener {
}
// nsIWidgetListener
virtual mozilla::PresShell* GetPresShell() override;
virtual nsView* GetView() override { return this; }
virtual bool WindowMoved(nsIWidget* aWidget, int32_t x, int32_t y,
mozilla::PresShell* GetPresShell() override;
nsView* GetView() override { return this; }
bool WindowMoved(nsIWidget* aWidget, int32_t x, int32_t y,
ByMoveToRect) override;
virtual bool WindowResized(nsIWidget* aWidget, int32_t aWidth,
bool WindowResized(nsIWidget* aWidget, int32_t aWidth,
int32_t aHeight) override;
#if defined(MOZ_WIDGET_ANDROID)
virtual void DynamicToolbarMaxHeightChanged(
mozilla::ScreenIntCoord aHeight) override;
virtual void DynamicToolbarOffsetChanged(
mozilla::ScreenIntCoord aOffset) override;
virtual void KeyboardHeightChanged(mozilla::ScreenIntCoord aHeight) override;
void DynamicToolbarMaxHeightChanged(mozilla::ScreenIntCoord aHeight) override;
void DynamicToolbarOffsetChanged(mozilla::ScreenIntCoord aOffset) override;
void KeyboardHeightChanged(mozilla::ScreenIntCoord aHeight) override;
#endif
virtual bool RequestWindowClose(nsIWidget* aWidget) override;
bool RequestWindowClose(nsIWidget* aWidget) override;
MOZ_CAN_RUN_SCRIPT_BOUNDARY
virtual void WillPaintWindow(nsIWidget* aWidget) override;
void WillPaintWindow(nsIWidget* aWidget) override;
MOZ_CAN_RUN_SCRIPT_BOUNDARY
virtual bool PaintWindow(nsIWidget* aWidget,
LayoutDeviceIntRegion aRegion) override;
bool PaintWindow(nsIWidget* aWidget, LayoutDeviceIntRegion aRegion) override;
MOZ_CAN_RUN_SCRIPT_BOUNDARY
virtual void DidPaintWindow() override;
virtual void DidCompositeWindow(
mozilla::layers::TransactionId aTransactionId,
void DidPaintWindow() override;
void DidCompositeWindow(mozilla::layers::TransactionId aTransactionId,
const mozilla::TimeStamp& aCompositeStart,
const mozilla::TimeStamp& aCompositeEnd) override;
virtual void RequestRepaint() override;
virtual bool ShouldNotBeVisible() override;
void RequestRepaint() override;
bool ShouldNotBeVisible() override;
MOZ_CAN_RUN_SCRIPT_BOUNDARY
virtual nsEventStatus HandleEvent(mozilla::WidgetGUIEvent* aEvent,
nsEventStatus HandleEvent(mozilla::WidgetGUIEvent* aEvent,
bool aUseAttachedEvents) override;
virtual void SafeAreaInsetsChanged(const mozilla::ScreenIntMargin&) override;
void SafeAreaInsetsChanged(const mozilla::LayoutDeviceIntMargin&) override;
virtual ~nsView();

View File

@ -988,12 +988,12 @@ void PuppetWidget::StartAsyncScrollbarDrag(
mBrowserChild->StartScrollbarDrag(aDragMetrics);
}
ScreenIntMargin PuppetWidget::GetSafeAreaInsets() const {
LayoutDeviceIntMargin PuppetWidget::GetSafeAreaInsets() const {
return mSafeAreaInsets;
}
void PuppetWidget::UpdateSafeAreaInsets(
const ScreenIntMargin& aSafeAreaInsets) {
const LayoutDeviceIntMargin& aSafeAreaInsets) {
mSafeAreaInsets = aSafeAreaInsets;
}

View File

@ -204,8 +204,8 @@ class PuppetWidget final : public nsBaseWidget,
}
// safe area insets support
ScreenIntMargin GetSafeAreaInsets() const override;
void UpdateSafeAreaInsets(const ScreenIntMargin& aSafeAreaInsets);
LayoutDeviceIntMargin GetSafeAreaInsets() const override;
void UpdateSafeAreaInsets(const LayoutDeviceIntMargin& aSafeAreaInsets);
// Get the offset to the chrome of the window that this tab belongs to.
//
@ -363,8 +363,7 @@ class PuppetWidget final : public nsBaseWidget,
int32_t mRounding = 1;
double mDefaultScale = GetFallbackDefaultScale().scale;
ScreenIntMargin mSafeAreaInsets;
LayoutDeviceIntMargin mSafeAreaInsets;
RefPtr<TextEventDispatcherListener> mNativeTextEventDispatcherListener;
protected:

View File

@ -1747,7 +1747,7 @@ class LayerViewSupport final
return;
}
ScreenIntMargin safeAreaInsets(aTop, aRight, aBottom, aLeft);
LayoutDeviceIntMargin safeAreaInsets(aTop, aRight, aBottom, aLeft);
gkWindow->UpdateSafeAreaInsets(safeAreaInsets);
}
};
@ -3275,9 +3275,12 @@ void nsWindow::KeyboardHeightChanged(ScreenIntCoord aHeight) {
}
}
ScreenIntMargin nsWindow::GetSafeAreaInsets() const { return mSafeAreaInsets; }
LayoutDeviceIntMargin nsWindow::GetSafeAreaInsets() const {
return mSafeAreaInsets;
}
void nsWindow::UpdateSafeAreaInsets(const ScreenIntMargin& aSafeAreaInsets) {
void nsWindow::UpdateSafeAreaInsets(
const LayoutDeviceIntMargin& aSafeAreaInsets) {
mSafeAreaInsets = aSafeAreaInsets;
if (mWidgetListener) {

View File

@ -73,7 +73,7 @@ class nsWindow final : public nsBaseWidget {
private:
nsCOMPtr<nsIUserIdleServiceInternal> mIdleService;
mozilla::ScreenIntCoord mDynamicToolbarMaxHeight{0};
mozilla::ScreenIntMargin mSafeAreaInsets;
mozilla::LayoutDeviceIntMargin mSafeAreaInsets;
mozilla::widget::PlatformCompositorWidgetDelegate* mCompositorWidgetDelegate =
nullptr;
mozilla::Mutex mDestroyMutex{"nsWindow::mDestroyMutex"};
@ -251,8 +251,8 @@ class nsWindow final : public nsBaseWidget {
void UpdateDynamicToolbarOffset(mozilla::ScreenIntCoord aOffset);
mozilla::ScreenIntMargin GetSafeAreaInsets() const override;
void UpdateSafeAreaInsets(const mozilla::ScreenIntMargin& aSafeAreaInsets);
mozilla::LayoutDeviceIntMargin GetSafeAreaInsets() const override;
void UpdateSafeAreaInsets(const mozilla::LayoutDeviceIntMargin&);
void KeyboardHeightChanged(mozilla::ScreenIntCoord aHeight);

View File

@ -173,6 +173,14 @@ interface nsIBaseWindow : nsISupports
*/
[noscript] void getDimensions(in DimensionKind aDimensionKind, out long aX, out long aY, out long aCX, out long aCY);
%{C++
mozilla::LayoutDeviceIntRect GetDimensions(mozilla::DimensionKind aDimensionKind) {
int32_t x = 0, y = 0, w = 0, h = 0;
GetDimensions(aDimensionKind, &x, &y, &w, &h);
return mozilla::LayoutDeviceIntRect(x, y, w, h);
}
%}
/**
* Tell the window to repaint itself
* @param aForce - if true, repaint immediately

View File

@ -1667,8 +1667,8 @@ class nsIWidget : public nsISupports {
* Get safe area insets except to cutout.
* See https://drafts.csswg.org/css-env-1/#safe-area-insets.
*/
virtual mozilla::ScreenIntMargin GetSafeAreaInsets() const {
return mozilla::ScreenIntMargin();
virtual mozilla::LayoutDeviceIntMargin GetSafeAreaInsets() const {
return mozilla::LayoutDeviceIntMargin();
}
private:

View File

@ -33,8 +33,8 @@ bool nsIWidgetListener::WindowResized(nsIWidget* aWidget, int32_t aWidth,
void nsIWidgetListener::SizeModeChanged(nsSizeMode aSizeMode) {}
void nsIWidgetListener::SafeAreaInsetsChanged(const mozilla::ScreenIntMargin&) {
}
void nsIWidgetListener::SafeAreaInsetsChanged(
const mozilla::LayoutDeviceIntMargin&) {}
#if defined(MOZ_WIDGET_ANDROID)
void nsIWidgetListener::DynamicToolbarMaxHeightChanged(ScreenIntCoord aHeight) {

View File

@ -176,7 +176,7 @@ class nsIWidgetListener {
* Called when safe area insets are changed.
*/
virtual void SafeAreaInsetsChanged(
const mozilla::ScreenIntMargin& aSafeAreaInsets);
const mozilla::LayoutDeviceIntMargin& aSafeAreaInsets);
};
#endif