Skip to content

Commit

Permalink
Bug 1503656 - Part 5. Get safe area insets from Gecko. r=emilio
Browse files Browse the repository at this point in the history
Add binding to get safe area insets from Gecko.

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

--HG--
extra : moz-landing-system : lando
  • Loading branch information
makotokato committed Mar 4, 2020
1 parent 1df343e commit 5e7416a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
4 changes: 4 additions & 0 deletions layout/base/nsPresContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 10 additions & 1 deletion layout/base/nsPresContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions layout/style/GeckoBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
3 changes: 3 additions & 0 deletions layout/style/GeckoBindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 10 additions & 1 deletion servo/components/style/gecko/media_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 5e7416a

Please sign in to comment.