OLD | NEW |
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 #include "core/dom/NodeList.h" | 51 #include "core/dom/NodeList.h" |
52 #include "core/html/HTMLHeadElement.h" | 52 #include "core/html/HTMLHeadElement.h" |
53 #include "core/inspector/InspectorDOMAgent.h" | 53 #include "core/inspector/InspectorDOMAgent.h" |
54 #include "core/inspector/InspectorHistory.h" | 54 #include "core/inspector/InspectorHistory.h" |
55 #include "core/inspector/InspectorPageAgent.h" | 55 #include "core/inspector/InspectorPageAgent.h" |
56 #include "core/inspector/InspectorState.h" | 56 #include "core/inspector/InspectorState.h" |
57 #include "core/inspector/InstrumentingAgents.h" | 57 #include "core/inspector/InstrumentingAgents.h" |
58 #include "core/loader/DocumentLoader.h" | 58 #include "core/loader/DocumentLoader.h" |
59 #include "core/page/ContentSecurityPolicy.h" | 59 #include "core/page/ContentSecurityPolicy.h" |
60 #include "core/platform/JSONValues.h" | 60 #include "core/platform/JSONValues.h" |
| 61 #include "core/platform/graphics/Font.h" |
| 62 #include "core/platform/graphics/GlyphBuffer.h" |
| 63 #include "core/platform/graphics/TextRun.h" |
| 64 #include "core/platform/graphics/WidthIterator.h" |
| 65 #include "core/rendering/InlineTextBox.h" |
| 66 #include "core/rendering/RenderObject.h" |
61 #include "core/rendering/RenderRegion.h" | 67 #include "core/rendering/RenderRegion.h" |
| 68 #include "core/rendering/RenderText.h" |
| 69 #include "core/rendering/RenderTextFragment.h" |
62 #include "wtf/CurrentTime.h" | 70 #include "wtf/CurrentTime.h" |
63 #include "wtf/HashSet.h" | 71 #include "wtf/HashSet.h" |
64 #include "wtf/Vector.h" | 72 #include "wtf/Vector.h" |
65 #include "wtf/text/CString.h" | 73 #include "wtf/text/CString.h" |
66 #include "wtf/text/StringConcatenate.h" | 74 #include "wtf/text/StringConcatenate.h" |
67 | 75 |
68 namespace CSSAgentState { | 76 namespace CSSAgentState { |
69 static const char cssAgentEnabled[] = "cssAgentEnabled"; | 77 static const char cssAgentEnabled[] = "cssAgentEnabled"; |
70 } | 78 } |
71 | 79 |
(...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1032 { | 1040 { |
1033 Node* node = m_domAgent->assertNode(errorString, nodeId); | 1041 Node* node = m_domAgent->assertNode(errorString, nodeId); |
1034 if (!node) | 1042 if (!node) |
1035 return; | 1043 return; |
1036 | 1044 |
1037 RefPtr<CSSComputedStyleDeclaration> computedStyleInfo = CSSComputedStyleDecl
aration::create(node, true); | 1045 RefPtr<CSSComputedStyleDeclaration> computedStyleInfo = CSSComputedStyleDecl
aration::create(node, true); |
1038 RefPtr<InspectorStyle> inspectorStyle = InspectorStyle::create(InspectorCSSI
d(), computedStyleInfo, 0); | 1046 RefPtr<InspectorStyle> inspectorStyle = InspectorStyle::create(InspectorCSSI
d(), computedStyleInfo, 0); |
1039 style = inspectorStyle->buildArrayForComputedStyle(); | 1047 style = inspectorStyle->buildArrayForComputedStyle(); |
1040 } | 1048 } |
1041 | 1049 |
| 1050 void InspectorCSSAgent::collectPlatformFontsForRenderer(RenderText* renderer, Ha
shMap<String, int>* fontStats) |
| 1051 { |
| 1052 for (InlineTextBox* box = renderer->firstTextBox(); box; box = box->nextText
Box()) { |
| 1053 RenderStyle* style = renderer->style(box->isFirstLineStyle()); |
| 1054 const Font& font = style->font(); |
| 1055 TextRun run = box->constructTextRunForInspector(style, font); |
| 1056 WidthIterator it(&font, run, 0, false); |
| 1057 GlyphBuffer glyphBuffer; |
| 1058 it.advance(run.length(), &glyphBuffer); |
| 1059 for (int i = 0; i < glyphBuffer.size(); ++i) { |
| 1060 String familyName = glyphBuffer.fontDataAt(i)->platformData().fontFa
milyName(); |
| 1061 int value = fontStats->contains(familyName) ? fontStats->get(familyN
ame) : 0; |
| 1062 fontStats->set(familyName, value + 1); |
| 1063 } |
| 1064 } |
| 1065 } |
| 1066 |
| 1067 void InspectorCSSAgent::getPlatformFontsForNode(ErrorString* errorString, int no
deId, |
| 1068 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::PlatformFontUsage> >& platformFo
ntUsage) |
| 1069 { |
| 1070 Node* node = m_domAgent->assertNode(errorString, nodeId); |
| 1071 if (!node) |
| 1072 return; |
| 1073 Vector<Node*> textNodes; |
| 1074 if (node->nodeType() == Node::TEXT_NODE) { |
| 1075 if (node->renderer()) |
| 1076 textNodes.append(node); |
| 1077 } else { |
| 1078 for (Node* child = node->firstChild(); child; child = child->nextSibling
()) { |
| 1079 if (child->nodeType() == Node::TEXT_NODE && child->renderer()) |
| 1080 textNodes.append(child); |
| 1081 } |
| 1082 } |
| 1083 |
| 1084 HashMap<String, int> fontStats; |
| 1085 for (size_t i = 0; i < textNodes.size(); ++i) { |
| 1086 RenderText* renderer = toRenderText(textNodes[i]->renderer()); |
| 1087 collectPlatformFontsForRenderer(renderer, &fontStats); |
| 1088 if (renderer->isTextFragment()) { |
| 1089 RenderTextFragment* textFragment = toRenderTextFragment(renderer); |
| 1090 if (textFragment->firstLetter()) { |
| 1091 RenderObject* firstLetter = textFragment->firstLetter(); |
| 1092 for (RenderObject* current = firstLetter->firstChild(); current;
current = current->nextSibling()) { |
| 1093 if (current->isText()) |
| 1094 collectPlatformFontsForRenderer(toRenderText(current), &
fontStats); |
| 1095 } |
| 1096 } |
| 1097 } |
| 1098 } |
| 1099 |
| 1100 platformFontUsage = TypeBuilder::Array<TypeBuilder::CSS::PlatformFontUsage>:
:create(); |
| 1101 for (HashMap<String, int>::iterator it = fontStats.begin(), end = fontStats.
end(); it != end; ++it) { |
| 1102 RefPtr<TypeBuilder::CSS::PlatformFontUsage> platformFont = TypeBuilder::
CSS::PlatformFontUsage::create() |
| 1103 .setFamilyName(it->key) |
| 1104 .setGlyphCount(it->value); |
| 1105 platformFontUsage->addItem(platformFont); |
| 1106 } |
| 1107 } |
| 1108 |
1042 void InspectorCSSAgent::getAllStyleSheets(ErrorString*, RefPtr<TypeBuilder::Arra
y<TypeBuilder::CSS::CSSStyleSheetHeader> >& styleInfos) | 1109 void InspectorCSSAgent::getAllStyleSheets(ErrorString*, RefPtr<TypeBuilder::Arra
y<TypeBuilder::CSS::CSSStyleSheetHeader> >& styleInfos) |
1043 { | 1110 { |
1044 styleInfos = TypeBuilder::Array<TypeBuilder::CSS::CSSStyleSheetHeader>::crea
te(); | 1111 styleInfos = TypeBuilder::Array<TypeBuilder::CSS::CSSStyleSheetHeader>::crea
te(); |
1045 Vector<InspectorStyleSheet*> styleSheets; | 1112 Vector<InspectorStyleSheet*> styleSheets; |
1046 collectAllStyleSheets(styleSheets); | 1113 collectAllStyleSheets(styleSheets); |
1047 for (size_t i = 0; i < styleSheets.size(); ++i) | 1114 for (size_t i = 0; i < styleSheets.size(); ++i) |
1048 styleInfos->addItem(styleSheets.at(i)->buildObjectForStyleSheetInfo()); | 1115 styleInfos->addItem(styleSheets.at(i)->buildObjectForStyleSheetInfo()); |
1049 } | 1116 } |
1050 | 1117 |
1051 void InspectorCSSAgent::getStyleSheet(ErrorString* errorString, const String& st
yleSheetId, RefPtr<TypeBuilder::CSS::CSSStyleSheetBody>& styleSheetObject) | 1118 void InspectorCSSAgent::getStyleSheet(ErrorString* errorString, const String& st
yleSheetId, RefPtr<TypeBuilder::CSS::CSSStyleSheetBody>& styleSheetObject) |
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1706 documentsToChange.add(element->ownerDocument()); | 1773 documentsToChange.add(element->ownerDocument()); |
1707 } | 1774 } |
1708 | 1775 |
1709 m_nodeIdToForcedPseudoState.clear(); | 1776 m_nodeIdToForcedPseudoState.clear(); |
1710 for (HashSet<Document*>::iterator it = documentsToChange.begin(), end = docu
mentsToChange.end(); it != end; ++it) | 1777 for (HashSet<Document*>::iterator it = documentsToChange.begin(), end = docu
mentsToChange.end(); it != end; ++it) |
1711 (*it)->setNeedsStyleRecalc(); | 1778 (*it)->setNeedsStyleRecalc(); |
1712 } | 1779 } |
1713 | 1780 |
1714 } // namespace WebCore | 1781 } // namespace WebCore |
1715 | 1782 |
OLD | NEW |