Respect default font size preference from browsers

We encountered an issue where PolyGerrit was not respecting browser
font preferences. Browser font preferences include both a default font
size and a minimum font size.

In the event that a font declared in px is smaller than the minimum font
size, the size is increased to equal the minimum font size. However,
if the font is declared in px and greater than the minimum, the
preferred font size is not taken into account.

Browsers' default font size is 16px [1], So instead of declaring the
base font in px (previously 13px), this change makes it a percentage
of the default font size. If the user has changed their default, this
is taken into account.

From this point, all other fonts will be declared in rems, which makes
it easier to base the new size off of the base font size of the <html>
tag, rather than ems which bases it on the container[2]. This allows us
to declare font sizes in a way more similar to pixels, yet relative.

A follow-up change will change all font size declaration to use rem from
em for consistency.

[1] https://stackoverflow.com/questions/29511983/is-the-default-font-size-of-every-browser-16px-why
[2] https://webdesign.tutsplus.com/tutorials/comprehensive-guide-when-to-use-em-vs-rem--cms-23984

Bug: Issue 8157
Change-Id: I04ec2c861b2fb288ec7556dfb655d7feea9c9157
diff --git a/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header.html b/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header.html
index 9493a61..1728d46 100644
--- a/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header.html
+++ b/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header.html
@@ -35,7 +35,7 @@
       }
       .bigTitle {
         color: var(--primary-text-color);
-        font-size: 1.75em;
+        font-size: 1.75rem;
         text-decoration: none;
       }
       .bigTitle:hover {
@@ -125,7 +125,7 @@
       }
       @media screen and (max-width: 50em) {
         .bigTitle {
-          font-size: 14px;
+          font-size: var(--font-size-large);
           font-family: var(--font-family-bold);
         }
         gr-search-bar,
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment.html b/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment.html
index 66f9feb..f302e3a 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment.html
+++ b/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment.html
@@ -164,7 +164,7 @@
         color: #000;
         cursor: pointer;
         display: block;
-        font-size: .8em;
+        font-size: .8rem;
         height: 1.1em;
         margin-top: .1em;
       }
@@ -195,7 +195,7 @@
       }
       .resolve label {
         color: #333;
-        font-size: 12px;
+        font-size: var(--font-size-small);
       }
       gr-confirm-dialog .main {
         background-color: #fef;
diff --git a/polygerrit-ui/app/elements/diff/gr-diff/gr-diff.html b/polygerrit-ui/app/elements/diff/gr-diff/gr-diff.html
index 6c72bcd..59acafe 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff/gr-diff.html
+++ b/polygerrit-ui/app/elements/diff/gr-diff/gr-diff.html
@@ -48,7 +48,7 @@
       }
       .diffContainer {
         display: flex;
-        font: 12px var(--monospace-font-family);
+        font: var(--font-size-small) var(--monospace-font-family);
         @apply --diff-container-styles;
       }
       .diffContainer.hiddenscroll {
@@ -101,7 +101,7 @@
       .lineNum,
       .content {
         /* Set font size based the user's diff preference. */
-        font-size: var(--font-size, 12px);
+        font-size: var(--font-size, var(--font-size-small));
         vertical-align: top;
         white-space: pre;
       }
@@ -196,7 +196,7 @@
         background-color: #F9F9F9;
         color: #2A00FF;
         font-family: var(--monospace-font-family);
-        font-size: var(--font-size, 12px);
+        font-size: var(--font-size, var(--font-size-small));
         padding: 0.5em 0 0.5em 4em;
       }
       #sizeWarning {
@@ -220,7 +220,7 @@
       td.blame {
         display: none;
         font-family: var(--font-family);
-        font-size: var(--font-size, 12px);
+        font-size: var(--font-size, var(--font-size-small));
         padding: 0 .5em;
         white-space: pre;
       }
diff --git a/polygerrit-ui/app/elements/shared/gr-button/gr-button.html b/polygerrit-ui/app/elements/shared/gr-button/gr-button.html
index a065f7a..579bc50 100644
--- a/polygerrit-ui/app/elements/shared/gr-button/gr-button.html
+++ b/polygerrit-ui/app/elements/shared/gr-button/gr-button.html
@@ -30,7 +30,7 @@
         --button-color: var(--gr-button-color, var(--color-link));
         display: inline-block;
         font-family: var(--font-family-bold);
-        font-size: 12px;
+        font-size: var(--font-size-small);
         position: relative;
       }
       :host([hidden]) {
diff --git a/polygerrit-ui/app/styles/app-theme.html b/polygerrit-ui/app/styles/app-theme.html
index 2d89272..e8db312 100644
--- a/polygerrit-ui/app/styles/app-theme.html
+++ b/polygerrit-ui/app/styles/app-theme.html
@@ -36,6 +36,11 @@
     transition: none;
   }
 
+  /* Font sizes */
+  --font-size-normal: 1rem;
+  --font-size-small: .92rem;
+  --font-size-large: 1.076rem;
+
   /* Follow are a part of the design refresh */
   --color-link: #2a66d9;
   --color-link-tertiary: #000;
diff --git a/polygerrit-ui/app/styles/gr-change-list-styles.html b/polygerrit-ui/app/styles/gr-change-list-styles.html
index e082aab..de591d1 100644
--- a/polygerrit-ui/app/styles/gr-change-list-styles.html
+++ b/polygerrit-ui/app/styles/gr-change-list-styles.html
@@ -17,7 +17,7 @@
   <template>
     <style>
       :host {
-        font-size: 13px;
+        font-size: var(--font-size-normal);
       }
       .topHeader,
       .groupHeader {
@@ -64,7 +64,7 @@
       }
       @media only screen and (max-width: 50em) {
         :host {
-          font-size: 14px;
+          font-size: var(--font-size-large);
         }
         gr-change-list-item {
           flex-wrap: wrap;
diff --git a/polygerrit-ui/app/styles/main.css b/polygerrit-ui/app/styles/main.css
index 045821c..618a2d71 100644
--- a/polygerrit-ui/app/styles/main.css
+++ b/polygerrit-ui/app/styles/main.css
@@ -24,6 +24,12 @@
 
 html {
   -webkit-text-size-adjust: none;
+  /*
+   * Default browser fonts are 16px. We want users with default settings to see
+   * a base font of 13px. 13/16 = .8125. This needs to be in html because
+   * can use rems based on this font-size throughout the app.
+   */
+  font-size: .8125em;
 }
 html,
 body {
@@ -36,7 +42,6 @@
    * Work around this using font-size and font-family.
    */
   -webkit-text-size-adjust: none;
-  font-size: 13px;
   font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
   line-height: 1.4;
 }