Bug 1640223 - Expand the given size in ExpandHeightForViewportUnits by multiplying the 'vh value / visible area height'. r=botond
authorHiroyuki Ikezoe <hikezoe.birchill@mozilla.com>
Fri, 29 May 2020 17:18:21 +0000
changeset 533096 bc9732b590eb4c99c2aa1a76d0b2b91445069c69
parent 533095 d09bfaf77297fd3b9ac8e470fdba9c3ad86455c6
child 533097 be5b74fc5731a41c77572dc6acfcbc7a6be32241
push id117566
push userhikezoe.birchill@mozilla.com
push dateFri, 29 May 2020 22:30:20 +0000
treeherderautoland@bc9732b590eb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond
bugs1640223
milestone78.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1640223 - Expand the given size in ExpandHeightForViewportUnits by multiplying the 'vh value / visible area height'. r=botond The viewport units size doesn't match the aspect ratio of the screen size in some cases. For example, in the case of the reftest in this commit, the meta viewport is "width=1600, height=device-height" and the screen size during reftest is "800x1000". Thus the viewport units size will be "1600x1000". In such cases with the old way ExpandHeightForViewportUnits shrinks the given size "1600x1800" to "1600x1000" with 100px dynamic toolbar max height (and the MOZ_ASSERT in the function happens on debug builds). Differential Revision: https://phabricator.services.mozilla.com/D77176
layout/base/nsLayoutUtils.h
layout/base/nsPresContext.cpp
layout/reftests/meta-viewport/device-height-with-dynamic-toolbar-ref.html
layout/reftests/meta-viewport/device-height-with-dynamic-toolbar.html
layout/reftests/meta-viewport/reftest.list
modules/libpref/init/StaticPrefList.yaml
--- a/layout/base/nsLayoutUtils.h
+++ b/layout/base/nsLayoutUtils.h
@@ -3160,24 +3160,25 @@ template <typename PointType, typename R
 
 template <typename SizeType>
 /* static */ SizeType nsLayoutUtils::ExpandHeightForViewportUnits(
     nsPresContext* aPresContext, const SizeType& aSize) {
   nsSize sizeForViewportUnits = aPresContext->GetSizeForViewportUnits();
 
   // |aSize| might be the size expanded to the minimum-scale size whereas the
   // size for viewport units is not scaled so that we need to expand the |aSize|
-  // height with the aspect ratio of the size for viewport units instead of just
-  // expanding to the size for viewport units.
-  float ratio = (float)sizeForViewportUnits.height / sizeForViewportUnits.width;
-
-  MOZ_ASSERT(aSize.height <=
-             NSCoordSaturatingNonnegativeMultiply(aSize.width, ratio));
-  return SizeType(aSize.width,
-                  NSCoordSaturatingNonnegativeMultiply(aSize.width, ratio));
+  // height by multiplying by the ratio of the viewport units height to the
+  // visible area height.
+  float vhExpansionRatio = (float)sizeForViewportUnits.height /
+                           aPresContext->GetVisibleArea().height;
+
+  MOZ_ASSERT(aSize.height <= NSCoordSaturatingNonnegativeMultiply(
+                                 aSize.height, vhExpansionRatio));
+  return SizeType(aSize.width, NSCoordSaturatingNonnegativeMultiply(
+                                   aSize.height, vhExpansionRatio));
 }
 
 template <typename T>
 nsRect nsLayoutUtils::RoundGfxRectToAppRect(const T& aRect,
                                             const float aFactor) {
   // Get a new Rect whose units are app units by scaling by the specified
   // factor.
   T scaledRect = aRect;
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -247,16 +247,22 @@ nsPresContext::nsPresContext(dom::Docume
   if (Preferences::GetBool(GFX_MISSING_FONTS_NOTIFY_PREF)) {
     mMissingFonts = MakeUnique<gfxMissingFontRecorder>();
   }
 
   // TODO: check whether this is too expensive to do for all pages;
   // maybe we could throttle and only collect stats on 1% of page-loads,
   // or something like that.
   mFontStats = MakeUnique<FontMatchingStats>();
+
+  if (StaticPrefs::layout_dynamic_toolbar_max_height() > 0) {
+    // The pref for dynamic toolbar max height is only used in reftests so it's
+    // fine to set here.
+    mDynamicToolbarMaxHeight = StaticPrefs::layout_dynamic_toolbar_max_height();
+  }
 }
 
 static const char* gExactCallbackPrefs[] = {
     "browser.underline_anchors",
     "browser.anchor_color",
     "browser.active_color",
     "browser.visited_color",
     "image.animation_mode",
new file mode 100644
--- /dev/null
+++ b/layout/reftests/meta-viewport/device-height-with-dynamic-toolbar-ref.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<meta http-equiv="content-type" content="text/html; charset=UTF-8">
+<meta name="viewport" content="width=device-width,initial-scale=1">
+<style>
+html {
+  scrollbar-width: none;
+}
+body {
+  margin: 0px;
+  padding: 0px;
+}
+div {
+  width: 100vw;
+  height: 50vh;
+}
+</style>
+<div style="background-color: green;"></div>
+<div style="background-color: blue;"></div>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/meta-viewport/device-height-with-dynamic-toolbar.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<meta http-equiv="content-type" content="text/html; charset=UTF-8">
+<meta name="viewport" content="width=1600, height=device-height">
+<style>
+html {
+  scrollbar-width: none;
+}
+body {
+  margin: 0px;
+  padding: 0px;
+}
+div {
+  width: 100vw;
+}
+</style>
+<div style="height: 100vh; background-color: green;"></div>
+<div style="height: 500vh; background-color: blue;"></div>
--- a/layout/reftests/meta-viewport/reftest.list
+++ b/layout/reftests/meta-viewport/reftest.list
@@ -33,8 +33,9 @@ pref(layout.viewport_contains_no_content
 == scroll-to-unreachable-area.html scroll-to-unreachable-area-ref.html
 == wrapped-text-at-icb.html wrapped-text-at-icb-ref.html
 == overflow-hidden-region-dynamic-width-change.html overflow-region-ref.html
 == remove-overflow-hidden-region.html remove-overflow-hidden-region-ref.html
 pref(layout.viewport_contains_no_contents_area,true) == dynamic-grow-width.html horizontal-overflow-hidden-region-ref.html
 == dynamic-grow-width-and-height.html overflow-region-ref.html
 == not-able-to-scrollTo.html about:blank
 == min-scale-aspect-ratio.html about:blank
+pref(layout.dynamic-toolbar-max-height,100) == device-height-with-dynamic-toolbar.html device-height-with-dynamic-toolbar-ref.html
--- a/modules/libpref/init/StaticPrefList.yaml
+++ b/modules/libpref/init/StaticPrefList.yaml
@@ -6253,16 +6253,22 @@
 
 # Whether we expand the layout viewport even if the expanded viewport doesn't
 # contain any contents in the area.
 - name: layout.viewport_contains_no_contents_area
   type: bool
   value: true
   mirror: always
 
+# Test only.
+- name: layout.dynamic-toolbar-max-height
+  type: RelaxedAtomicInt32
+  value: 0
+  mirror: always
+
 #---------------------------------------------------------------------------
 # Prefs starting with "mathml."
 #---------------------------------------------------------------------------
 
 # Whether to disable deprecated style attributes background, color, fontfamily,
 # fontsize, fontstyle and fontweight.
 - name: mathml.deprecated_style_attributes.disabled
   type: bool