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

Unified Diff: Source/core/inspector/InspectorCSSAgent.cpp

Issue 22923010: DevTools: Add CSS.getPlatformFontsForNode in protocol.json (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: use HFONT instead of SKTypeface on Win Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/inspector/InspectorCSSAgent.h ('k') | Source/core/platform/graphics/FontPlatformData.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/inspector/InspectorCSSAgent.cpp
diff --git a/Source/core/inspector/InspectorCSSAgent.cpp b/Source/core/inspector/InspectorCSSAgent.cpp
index a12ad408b2044808e2aed3c58776af7eea60730a..031693af7d1b9daca0dd7995aafacd47a6cbb4ba 100644
--- a/Source/core/inspector/InspectorCSSAgent.cpp
+++ b/Source/core/inspector/InspectorCSSAgent.cpp
@@ -58,7 +58,15 @@
#include "core/loader/DocumentLoader.h"
#include "core/page/ContentSecurityPolicy.h"
#include "core/platform/JSONValues.h"
+#include "core/platform/graphics/Font.h"
+#include "core/platform/graphics/GlyphBuffer.h"
+#include "core/platform/graphics/TextRun.h"
+#include "core/platform/graphics/WidthIterator.h"
+#include "core/rendering/InlineTextBox.h"
+#include "core/rendering/RenderObject.h"
#include "core/rendering/RenderRegion.h"
+#include "core/rendering/RenderText.h"
+#include "core/rendering/RenderTextFragment.h"
#include "wtf/CurrentTime.h"
#include "wtf/HashSet.h"
#include "wtf/Vector.h"
@@ -1039,6 +1047,65 @@ void InspectorCSSAgent::getComputedStyleForNode(ErrorString* errorString, int no
style = inspectorStyle->buildArrayForComputedStyle();
}
+void InspectorCSSAgent::collectPlatformFontsForRenderer(RenderText* renderer, HashMap<String, int>* fontStats)
+{
+ for (InlineTextBox* box = renderer->firstTextBox(); box; box = box->nextTextBox()) {
+ RenderStyle* style = renderer->style(box->isFirstLineStyle());
+ const Font& font = style->font();
+ TextRun run = box->constructTextRunForInspector(style, font);
+ WidthIterator it(&font, run, 0, false);
+ GlyphBuffer glyphBuffer;
+ it.advance(run.length(), &glyphBuffer);
+ for (int i = 0; i < glyphBuffer.size(); ++i) {
+ String familyName = glyphBuffer.fontDataAt(i)->platformData().fontFamilyName();
+ int value = fontStats->contains(familyName) ? fontStats->get(familyName) : 0;
+ fontStats->set(familyName, value + 1);
+ }
+ }
+}
+
+void InspectorCSSAgent::getPlatformFontsForNode(ErrorString* errorString, int nodeId,
+ RefPtr<TypeBuilder::Array<TypeBuilder::CSS::PlatformFontUsage> >& platformFontUsage)
+{
+ Node* node = m_domAgent->assertNode(errorString, nodeId);
+ if (!node)
+ return;
+ Vector<Node*> textNodes;
+ if (node->nodeType() == Node::TEXT_NODE) {
+ if (node->renderer())
+ textNodes.append(node);
+ } else {
+ for (Node* child = node->firstChild(); child; child = child->nextSibling()) {
+ if (child->nodeType() == Node::TEXT_NODE && child->renderer())
+ textNodes.append(child);
+ }
+ }
+
+ HashMap<String, int> fontStats;
+ for (size_t i = 0; i < textNodes.size(); ++i) {
+ RenderText* renderer = toRenderText(textNodes[i]->renderer());
+ collectPlatformFontsForRenderer(renderer, &fontStats);
+ if (renderer->isTextFragment()) {
+ RenderTextFragment* textFragment = toRenderTextFragment(renderer);
+ if (textFragment->firstLetter()) {
+ RenderObject* firstLetter = textFragment->firstLetter();
+ for (RenderObject* current = firstLetter->firstChild(); current; current = current->nextSibling()) {
+ if (current->isText())
+ collectPlatformFontsForRenderer(toRenderText(current), &fontStats);
+ }
+ }
+ }
+ }
+
+ platformFontUsage = TypeBuilder::Array<TypeBuilder::CSS::PlatformFontUsage>::create();
+ for (HashMap<String, int>::iterator it = fontStats.begin(), end = fontStats.end(); it != end; ++it) {
+ RefPtr<TypeBuilder::CSS::PlatformFontUsage> platformFont = TypeBuilder::CSS::PlatformFontUsage::create()
+ .setFamilyName(it->key)
+ .setGlyphCount(it->value);
+ platformFontUsage->addItem(platformFont);
+ }
+}
+
void InspectorCSSAgent::getAllStyleSheets(ErrorString*, RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSStyleSheetHeader> >& styleInfos)
{
styleInfos = TypeBuilder::Array<TypeBuilder::CSS::CSSStyleSheetHeader>::create();
« no previous file with comments | « Source/core/inspector/InspectorCSSAgent.h ('k') | Source/core/platform/graphics/FontPlatformData.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698