New issue
Advanced search Search tips

Issue 685768 link

Starred by 8 users

Issue metadata

Status: Available
Owner: ----
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Android
Pri: 3
Type: Bug



Sign in to add a comment

[AOSP] - WebViews incorrectly calculate css rem units

Project Member Reported by aluo@chromium.org, Jan 26 2017

Issue description

Filing crbug to fix this bug in webview:

b/34648550

which was opened for this bug:

https://code.google.com/p/android/issues/detail?id=232099

Orignal description from b/:

External developer has reported about : WebViews incorrectly calculate css rem units

Steps to reproduce:
  1) Create a simple project with a single webview
  2) Create an HTML page  that uses rem units for layout (width, height, absolute positioning, etc...)
  3) Make a <div> that has a width and height of 2rem on the page.
  4) Ensure the HTML element CSS has "font-size: 3px"
  5) Load the HTML page in the WebView
  6) Note the div has a width/height of 16px
Note : apk attached for reference

Expected behavior:
================================
The Divs should have had a width/height of 6px ( 3px (base) * 2 (rem) ) font size minimums should not be applied at all for element layout/sizing units.

The font size is never supposed to be any smaller than 8px since that's the default minimum font-size imposed on the Webview.  The "M" inside the red box is correctly being sized:

5px, 2rem = 10px
4px, 2rem = 8px
3px, 2rem = 8px (constrained by min font size)
2px, 2rem = 8px (constrained by min font size)
1px, 2rem = 8px ((constrained by min font size)

The red box itself is is also 2rem x 2rem.  This box sizing is what is being improperly calculated.  What you see is:

9px, 2rem = 18px (correct)
8px, 2rem = 16px (correct)
7px, 2rem = 16px (incorrect, being calculated as 8px, 2rem, should be 14px)
6px, 2rem = 16px (incorrect, being calculated as 8px, 2rem, should be 12px)
5px, 2rem = 16px (incorrect, being calculated as 8px, 2rem, should be 10px)
4px, 2rem = 16px (incorrect, being calculated as 8px, 2rem, should be 8px)
3px, 2rem = 16px (incorrect, being calculated as 8px, 2rem, should be 6px)
2px, 2rem = 16px (incorrect, being calculated as 8px, 2rem, should be 4px)
1px, 2rem = 16px (incorrect, being calculated as 8px, 2rem, should be 2px)


It seems that the REM calculations for css font-size attributes are doing the correct calculation:

  font-size-px = max of (html-element-font-size * rem-units) or webViewMinFontSize

Where any box sizing, positioning, padding, margin, etc... are all incorrectly using the following calculation:

  layout-px = (max of html-element-font-size or webViewMinFontSize) * rem-units

any non-font pixel calculations using REM units should be

  layout-px = htm-element-font-size * rem-units

since they are not actually being used for font sizing.
================================

Observed behavior:
================================
Android WebViews are incorrectly applying the https://developer.android.com/reference/android/webkit/WebSettings.html#setMinimumFontSize(int) default size (8px) to the base before doing REM -> px calculations.
The strange thing is that they seem to be doing the calculations properly when calculating actual font sizes but calculating layout or element sizing (where the minimum font size should not be applied at ALL) it is not only applying the minimumFontSize but also applying it incorrectly.

Sample project attached here loads a local html file that allows to decrease/increase the HTML font-size and you can observe the incorrect REM calculations in realtime.

The only workaround found is:

mWebView.getSettings().setMinimumFontSize(1);
mWebView.getSettings().setMinimumLogicalFontSize(1);
================================

Environment details:
As per the reporter this affects all version of android but he has only tested on 5.x +

May be the reporter would have used chrome dev tool to analyse the results. As I was not sure of using it, I could not test it on latest

Link to AOSP tracker: https://code.google.com/p/android/issues/detail?id=232099 

Attached apk, code, screenshot and video for reference
11:18PM


Attachments: go/chrome-androidlogs1/6/685768
 

Comment 1 by aluo@chromium.org, Jan 26 2017

Description: Show this description

Comment 2 by aluo@chromium.org, Jan 26 2017

Description: Show this description

Comment 3 by aluo@chromium.org, Jan 26 2017

Labels: -Restrict-View-Google

Comment 4 by aluo@chromium.org, Feb 6 2017

Cc: sgu...@chromium.org
Labels: -Pri-1 -Needs-Bisect -ReleaseBlock-Stable Pri-2
Status: Untriaged (was: Unconfirmed)
Tested this on older versions of WebView, it has been happening on all versions and not specific to AOSP.  I tried on Android L with WebView version 39, behavior is consistent with latest WebView 56.  I see the red bounding box does not shrink past 8px font size.  Removing the blocker label.  There is the difference between font sizing vs the box sizing, not sure if it is intentional.  But again this behavior has been around.
I originally reported this with the android team.  Please let me know if you need any further details.
Cc: ntfschr@chromium.org
Thanks for reporting. I will investigate.
Labels: -Pri-2 -M-57 Pri-3
Status: Available (was: Untriaged)
Since this behavior has been around for a while, and it's non-critical, I'm opening this up for any team member to take up.

Comment 8 by m...@fc.io, Sep 6 2017

@ntfschr since many apps use a webview it pretty much disallows any use of rems for any and all websites that wants to work on android

Comment 9 by sgu...@chromium.org, Sep 27 2017

Cc: -sgu...@chromium.org
Owner: ntfschr@chromium.org
Status: Assigned (was: Available)
I looked into this a little bit last week. I'll try more investigation this week, but will put this back in the queue if I don't have time to fix.
Owner: ----
Status: Available (was: Assigned)
Unfortunately won't have time to fix this.

Sign in to add a comment