Bug 1465397 - Font Editor: read font properties from computed style and overwrite with ones explicitly declared. r=pbro. draft
authorRazvan Caliman <rcaliman@mozilla.com>
Mon, 04 Jun 2018 15:07:00 +0200
changeset 804087 c59f4c475a8e5f2e5f9ad8eeffe355cabbf14977
parent 804003 a358755643e92f8fc55a23e3ab1fbf88695b8bf3
push id112310
push userbmo:rcaliman@mozilla.com
push dateTue, 05 Jun 2018 15:58:40 +0000
reviewerspbro
bugs1465397
milestone62.0a1
Bug 1465397 - Font Editor: read font properties from computed style and overwrite with ones explicitly declared. r=pbro. - Read all expected font properties from computed style. - Overwrite with properties explicitly declared in rules which apply. - Skip explicit keywords, CSS Custom Properties and calc() expressions. MozReview-Commit-ID: JAKHundvV5w
devtools/client/inspector/fonts/fonts.js
--- a/devtools/client/inspector/fonts/fonts.js
+++ b/devtools/client/inspector/fonts/fonts.js
@@ -153,27 +153,44 @@ class FontInspector {
     this.store = null;
     this.textProperties.clear();
     this.textProperties = null;
     this.writers.clear();
     this.writers = null;
   }
 
   /**
-   * Get all expected CSS font properties and values from the node's computed style.
+   * Get all expected CSS font properties and values from the node's matching rules and
+   * fallback to computed style.
    *
    * @return {Object}
    */
   getFontProperties() {
+    const KEYWORD_VALUES = ["initial", "inherit", "unset", "none"];
     const properties = {};
 
+    // First, get all expected font properties from computed styles.
     for (const prop of FONT_PROPERTIES) {
       properties[prop] = this.nodeComputedStyle[prop].value;
     }
 
+    // Then, replace with enabled font properties found on any of the rules that apply.
+    for (const rule of this.ruleView.rules) {
+      for (const textProp of rule.textProps) {
+        if (FONT_PROPERTIES.includes(textProp.name) &&
+            !KEYWORD_VALUES.includes(textProp.value) &&
+            !textProp.value.includes("calc(") &&
+            !textProp.value.includes("var(") &&
+            !textProp.overridden &&
+            textProp.enabled) {
+          properties[textProp.name] = textProp.value;
+        }
+      }
+    }
+
     return properties;
   }
 
   async getFontsForNode(node, options) {
     // In case we've been destroyed in the meantime
     if (!this.document) {
       return [];
     }