Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: Source/core/inspector/InspectorCSSAgent.cpp

Issue 1187073016: DevTools: generalize getPlatformFonts code (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/inspector/InspectorCSSAgent.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010, Google Inc. All rights reserved. 2 * Copyright (C) 2010, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 { 813 {
814 Node* node = m_domAgent->assertNode(errorString, nodeId); 814 Node* node = m_domAgent->assertNode(errorString, nodeId);
815 if (!node) 815 if (!node)
816 return; 816 return;
817 817
818 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> computedStyleInfo = CSSCompu tedStyleDeclaration::create(node, true); 818 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> computedStyleInfo = CSSCompu tedStyleDeclaration::create(node, true);
819 RefPtrWillBeRawPtr<InspectorStyle> inspectorStyle = InspectorStyle::create(0 , computedStyleInfo, 0); 819 RefPtrWillBeRawPtr<InspectorStyle> inspectorStyle = InspectorStyle::create(0 , computedStyleInfo, 0);
820 style = inspectorStyle->buildArrayForComputedStyle(); 820 style = inspectorStyle->buildArrayForComputedStyle();
821 } 821 }
822 822
823 void InspectorCSSAgent::collectPlatformFontsForLayoutObject(LayoutText* layoutOb ject, HashCountedSet<String>* fontStats) 823 void InspectorCSSAgent::collectPlatformFontsForLayoutObject(LayoutObject* layout Object, HashCountedSet<String>* fontStats)
824 { 824 {
825 for (InlineTextBox* box = layoutObject->firstTextBox(); box; box = box->next TextBox()) { 825 if (!layoutObject->isText())
826 const ComputedStyle& style = layoutObject->styleRef(box->isFirstLineStyl e()); 826 return;
827 LayoutText* layoutText = toLayoutText(layoutObject);
828 for (InlineTextBox* box = layoutText->firstTextBox(); box; box = box->nextTe xtBox()) {
829 const ComputedStyle& style = layoutText->styleRef(box->isFirstLineStyle( ));
827 const Font& font = style.font(); 830 const Font& font = style.font();
828 TextRun run = box->constructTextRunForInspector(style, font); 831 TextRun run = box->constructTextRunForInspector(style, font);
829 SimpleShaper shaper(&font, run); 832 SimpleShaper shaper(&font, run);
830 GlyphBuffer glyphBuffer; 833 GlyphBuffer glyphBuffer;
831 shaper.advance(run.length(), &glyphBuffer); 834 shaper.advance(run.length(), &glyphBuffer);
832 for (unsigned i = 0; i < glyphBuffer.size(); ++i) { 835 for (unsigned i = 0; i < glyphBuffer.size(); ++i) {
833 String familyName = glyphBuffer.fontDataAt(i)->platformData().fontFa milyName(); 836 String familyName = glyphBuffer.fontDataAt(i)->platformData().fontFa milyName();
834 if (familyName.isNull()) 837 if (familyName.isNull())
835 familyName = ""; 838 familyName = "";
836 fontStats->add(familyName); 839 fontStats->add(familyName);
837 } 840 }
838 } 841 }
839 } 842 }
840 843
841 void InspectorCSSAgent::getPlatformFontsForNode(ErrorString* errorString, int no deId, 844 void InspectorCSSAgent::getPlatformFontsForNode(ErrorString* errorString, int no deId,
842 String* cssFamilyName, RefPtr<TypeBuilder::Array<TypeBuilder::CSS::PlatformF ontUsage> >& platformFonts) 845 String* cssFamilyName, RefPtr<TypeBuilder::Array<TypeBuilder::CSS::PlatformF ontUsage> >& platformFonts)
843 { 846 {
844 Node* node = m_domAgent->assertNode(errorString, nodeId); 847 Node* node = m_domAgent->assertNode(errorString, nodeId);
845 if (!node) 848 if (!node)
846 return; 849 return;
847 850
848 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> computedStyleInfo = CSSCompu tedStyleDeclaration::create(node, true); 851 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> computedStyleInfo = CSSCompu tedStyleDeclaration::create(node, true);
849 *cssFamilyName = computedStyleInfo->getPropertyValue(CSSPropertyFontFamily); 852 *cssFamilyName = computedStyleInfo->getPropertyValue(CSSPropertyFontFamily);
850 853
851 WillBeHeapVector<RawPtrWillBeMember<Text> > textNodes; 854 HashCountedSet<String> fontStats;
852 if (node->nodeType() == Node::TEXT_NODE) { 855 LayoutObject* root = node->layoutObject();
853 if (node->layoutObject()) 856 if (root) {
854 textNodes.append(toText(node)); 857 collectPlatformFontsForLayoutObject(root, &fontStats);
855 } else { 858 // Iterate upto two layers deep.
pfeldman 2015/06/18 06:48:09 Why not N levels?
lushnikov 2015/06/18 10:29:14 In order to preserve current behavior.
856 for (Node* child = node->firstChild(); child; child = child->nextSibling ()) { 859 for (LayoutObject* child = root->slowFirstChild(); child; child = child- >nextSibling()) {
857 if (child->nodeType() == Node::TEXT_NODE && child->layoutObject()) 860 collectPlatformFontsForLayoutObject(child, &fontStats);
858 textNodes.append(toText(child)); 861 for (LayoutObject* child2 = child->slowFirstChild(); child2; child2 = child2->nextSibling())
862 collectPlatformFontsForLayoutObject(child2, &fontStats);
859 } 863 }
860 } 864 }
861
862 HashCountedSet<String> fontStats;
863 for (size_t i = 0; i < textNodes.size(); ++i) {
864 LayoutText* layoutObject = textNodes[i]->layoutObject();
865 collectPlatformFontsForLayoutObject(layoutObject, &fontStats);
866
867 if (!layoutObject->isTextFragment())
868 continue;
869
870 // If we're the remaining text from a first-letter then our previous
871 // sibling has to be the first-letter layoutObject.
872 LayoutObject* previous = layoutObject->previousSibling();
873 if (!previous)
874 continue;
875
876 if (!previous->isPseudoElement() || !previous->node()->isFirstLetterPseu doElement())
877 continue;
878
879 // The first-letter pseudoElement only has one child, which is the
880 // first-letter layoutObject.
881 collectPlatformFontsForLayoutObject(toLayoutText(previous->slowFirstChil d()), &fontStats);
882 }
883
884 platformFonts = TypeBuilder::Array<TypeBuilder::CSS::PlatformFontUsage>::cre ate(); 865 platformFonts = TypeBuilder::Array<TypeBuilder::CSS::PlatformFontUsage>::cre ate();
885 for (auto& font : fontStats) { 866 for (auto& font : fontStats) {
886 RefPtr<TypeBuilder::CSS::PlatformFontUsage> platformFont = TypeBuilder:: CSS::PlatformFontUsage::create() 867 RefPtr<TypeBuilder::CSS::PlatformFontUsage> platformFont = TypeBuilder:: CSS::PlatformFontUsage::create()
887 .setFamilyName(font.key) 868 .setFamilyName(font.key)
888 .setGlyphCount(font.value); 869 .setGlyphCount(font.value);
889 platformFonts->addItem(platformFont); 870 platformFonts->addItem(platformFont);
890 } 871 }
891 } 872 }
892 873
893 void InspectorCSSAgent::getStyleSheetText(ErrorString* errorString, const String & styleSheetId, String* result) 874 void InspectorCSSAgent::getStyleSheetText(ErrorString* errorString, const String & styleSheetId, String* result)
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after
1589 visitor->trace(m_invalidatedDocuments); 1570 visitor->trace(m_invalidatedDocuments);
1590 visitor->trace(m_nodeToInspectorStyleSheet); 1571 visitor->trace(m_nodeToInspectorStyleSheet);
1591 visitor->trace(m_documentToViaInspectorStyleSheet); 1572 visitor->trace(m_documentToViaInspectorStyleSheet);
1592 #endif 1573 #endif
1593 visitor->trace(m_inspectorUserAgentStyleSheet); 1574 visitor->trace(m_inspectorUserAgentStyleSheet);
1594 InspectorBaseAgent::trace(visitor); 1575 InspectorBaseAgent::trace(visitor);
1595 } 1576 }
1596 1577
1597 } // namespace blink 1578 } // namespace blink
1598 1579
OLDNEW
« no previous file with comments | « Source/core/inspector/InspectorCSSAgent.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698