Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Clone element to just get the fonts used in it and not its descendants

as far as possible (default fonts will still be highlighted even when
they are not directly used inside an element due to the use of
textContent)
  • Loading branch information...
commit 6cef601efa7c13a4f9225f58f849b1cc3433d2de 1 parent 6d9afe3
Sebastian Zartner authored April 30, 2012
9  extension/content/firebug/css/cssElementPanel.js
@@ -720,7 +720,14 @@ function getFontPropValueParts(element, value)
720 720
         fonts = matches[1].split(",");
721 721
     }
722 722
 
723  
-    var usedFonts = Fonts.getFonts(element);
  723
+    // Clone the element to just get the fonts used in it and not its descendants
  724
+    var clonedElement = element.cloneNode(false);
  725
+    clonedElement.textContent = element.textContent;
  726
+    Firebug.setIgnored(clonedElement);
  727
+    element.parentNode.appendChild(clonedElement);
  728
+    var usedFonts = Fonts.getFonts(clonedElement);
  729
+    clonedElement.parentNode.removeChild(clonedElement);
  730
+
724 731
     var genericFontUsed = false;
725 732
     for (; i < fonts.length; ++i)
726 733
     {
14  extension/content/firebug/lib/fonts.js
@@ -30,12 +30,24 @@ Fonts.getFonts = function(node)
30 30
         return [];
31 31
 
32 32
     var range = node.ownerDocument.createRange();
33  
-    range.selectNode(node);
  33
+    try
  34
+    {
  35
+        range.selectNode(node);
  36
+    }
  37
+    catch(err)
  38
+    {
  39
+        if (FBTrace.DBG_FONTS || FBTrace.DBG_ERRORS)
  40
+            FBTrace.sysout("Fonts.getFonts; node couldn't be selected", err);
  41
+    }
  42
+
34 43
     var fontFaces = Dom.domUtils.getUsedFontFaces(range);
35 44
     var fonts = [];
36 45
     for (var i=0; i<fontFaces.length; i++)
37 46
         fonts.push(fontFaces.item(i));
38 47
 
  48
+    if (FBTrace.DBG_FONTS)
  49
+        FBTrace.sysout("Fonts.getFonts; used fonts", fonts);
  50
+
39 51
     return fonts;
40 52
 }
41 53
 

0 notes on commit 6cef601

Please sign in to comment.
Something went wrong with that request. Please try again.