Browse files

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...
1 parent 6d9afe3 commit 6cef601efa7c13a4f9225f58f849b1cc3433d2de @SebastianZ SebastianZ committed Apr 30, 2012
Showing with 21 additions and 2 deletions.
  1. +8 −1 extension/content/firebug/css/cssElementPanel.js
  2. +13 −1 extension/content/firebug/lib/fonts.js
View
9 extension/content/firebug/css/cssElementPanel.js
@@ -720,7 +720,14 @@ function getFontPropValueParts(element, value)
fonts = matches[1].split(",");
}
- var usedFonts = Fonts.getFonts(element);
+ // Clone the element to just get the fonts used in it and not its descendants
+ var clonedElement = element.cloneNode(false);
+ clonedElement.textContent = element.textContent;
+ Firebug.setIgnored(clonedElement);
+ element.parentNode.appendChild(clonedElement);
+ var usedFonts = Fonts.getFonts(clonedElement);
+ clonedElement.parentNode.removeChild(clonedElement);
+
var genericFontUsed = false;
for (; i < fonts.length; ++i)
{
View
14 extension/content/firebug/lib/fonts.js
@@ -30,12 +30,24 @@ Fonts.getFonts = function(node)
return [];
var range = node.ownerDocument.createRange();
- range.selectNode(node);
+ try
+ {
+ range.selectNode(node);
+ }
+ catch(err)
+ {
+ if (FBTrace.DBG_FONTS || FBTrace.DBG_ERRORS)
+ FBTrace.sysout("Fonts.getFonts; node couldn't be selected", err);
+ }
+
var fontFaces = Dom.domUtils.getUsedFontFaces(range);
var fonts = [];
for (var i=0; i<fontFaces.length; i++)
fonts.push(fontFaces.item(i));
+ if (FBTrace.DBG_FONTS)
+ FBTrace.sysout("Fonts.getFonts; used fonts", fonts);
+
return fonts;
}

0 comments on commit 6cef601

Please sign in to comment.