Bug 1503656 - Part 5. Get safe area insets from Gecko. r=emilio

Add binding to get safe area insets from Gecko.

Differential Revision: https://phabricator.services.mozilla.com/D52509

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Makoto Kato 2020-03-04 08:15:17 +00:00
parent 1df343ef04
commit 5e7416a046
5 changed files with 37 additions and 2 deletions

View File

@ -2580,6 +2580,10 @@ DynamicToolbarState nsPresContext::GetDynamicToolbarState() const {
return DynamicToolbarState::InTransition;
}
void nsPresContext::SetSafeAreaInsets(const ScreenIntMargin& aSafeAreaInsets) {
mSafeAreaInsets = aSafeAreaInsets;
}
#ifdef DEBUG
void nsPresContext::ValidatePresShellAndDocumentReleation() const {

View File

@ -494,6 +494,13 @@ class nsPresContext : public nsISupports,
UpdateEffectiveTextZoom();
}
/**
* Notify the pres context that the safe area insets have changed.
*/
void SetSafeAreaInsets(const mozilla::ScreenIntMargin& aInsets);
mozilla::ScreenIntMargin GetSafeAreaInsets() const { return mSafeAreaInsets; }
protected:
void UpdateEffectiveTextZoom();
@ -596,7 +603,7 @@ class nsPresContext : public nsISupports,
return AppUnitsToIntCSSPixels(DevPixelsToAppUnits(aPixels));
}
float DevPixelsToFloatCSSPixels(int32_t aPixels) {
float DevPixelsToFloatCSSPixels(int32_t aPixels) const {
return AppUnitsToFloatCSSPixels(DevPixelsToAppUnits(aPixels));
}
@ -1210,6 +1217,8 @@ class nsPresContext : public nsISupports,
// The maximum height of the dynamic toolbar on mobile.
mozilla::ScreenIntCoord mDynamicToolbarMaxHeight;
mozilla::ScreenIntCoord mDynamicToolbarHeight;
// Safe area insets support
mozilla::ScreenIntMargin mSafeAreaInsets;
nsSize mPageSize;
float mPageScale;
float mPPScale;

View File

@ -1744,6 +1744,16 @@ bool Gecko_AssertClassAttrValueIsSane(const nsAttrValue* aValue) {
return true;
}
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);
}
void Gecko_PrintfStderr(const nsCString* aStr) {
printf_stderr("%s", aStr->get());
}

View File

@ -633,6 +633,9 @@ bool Gecko_MediaFeatures_IsResourceDocument(const mozilla::dom::Document*);
nsAtom* Gecko_MediaFeatures_GetOperatingSystemVersion(
const mozilla::dom::Document*);
void Gecko_GetSafeAreaInsets(const nsPresContext*, float*, float*, float*,
float*);
void Gecko_PrintfStderr(const nsCString*);
} // extern "C"

View File

@ -310,6 +310,15 @@ impl Device {
/// Returns safe area insets
pub fn safe_area_insets(&self) -> SideOffsets2D<f32, CSSPixel> {
SideOffsets2D::zero()
let pc = match self.pres_context() {
Some(pc) => pc,
None => return SideOffsets2D::zero(),
};
let mut top = 0.0;
let mut right = 0.0;
let mut bottom = 0.0;
let mut left = 0.0;
unsafe { bindings::Gecko_GetSafeAreaInsets(pc, &mut top, &mut right, &mut bottom, &mut left) };
SideOffsets2D::new(top, right, bottom, left)
}
}