Chromium Code Reviews| Index: Source/core/inspector/InspectorDOMAgent.cpp |
| diff --git a/Source/core/inspector/InspectorDOMAgent.cpp b/Source/core/inspector/InspectorDOMAgent.cpp |
| index 39976bdf5485d436e02522a607c575de526e17dc..30176c90064ace04d980aebd25d87a28b02a7da5 100644 |
| --- a/Source/core/inspector/InspectorDOMAgent.cpp |
| +++ b/Source/core/inspector/InspectorDOMAgent.cpp |
| @@ -33,6 +33,7 @@ |
| #include "HTMLNames.h" |
| #include "InspectorFrontend.h" |
| +#include "SkTypeface.h" |
| #include "bindings/v8/ExceptionState.h" |
| #include "bindings/v8/ScriptEventListener.h" |
| #include "core/dom/Attr.h" |
| @@ -73,8 +74,17 @@ |
| #include "core/platform/PlatformGestureEvent.h" |
| #include "core/platform/PlatformMouseEvent.h" |
| #include "core/platform/PlatformTouchEvent.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/HitTestResult.h" |
| +#include "core/rendering/InlineTextBox.h" |
| +#include "core/rendering/RenderObject.h" |
| +#include "core/rendering/RenderText.h" |
| +#include "core/rendering/RenderTextFragment.h" |
| #include "core/rendering/RenderView.h" |
| +#include "core/rendering/style/RenderStyle.h" |
| #include "core/xml/DocumentXPathEvaluator.h" |
| #include "core/xml/XPathResult.h" |
| #include "wtf/HashSet.h" |
| @@ -1225,6 +1235,74 @@ void InspectorDOMAgent::highlightFrame( |
| } |
| } |
| +String InspectorDOMAgent::familyNameFromSimpleFontData(const SimpleFontData* fontData) |
|
pfeldman
2013/08/16 08:16:48
make it static
|
| +{ |
| + FontPlatformData platformData = fontData->platformData(); |
| + SkTypeface::LocalizedStrings* fontFamilyIterator = platformData.typeface()->createFamilyNameIterator(); |
|
pfeldman
2013/08/16 08:16:48
No, you can't use Sk here.
|
| + SkTypeface::LocalizedString localizedString; |
| + while (fontFamilyIterator->next(&localizedString) && !localizedString.fString.size()) { } |
| + fontFamilyIterator->unref(); |
| + return String(localizedString.fString.c_str()); |
| +} |
| + |
| +void InspectorDOMAgent::platformFontsForRenderer(RenderText* renderer, StringBuilder& fontChars, RefPtr<TypeBuilder::Array<String> >& fonts) |
| +{ |
| + 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) { |
| + fonts->addItem(familyNameFromSimpleFontData(glyphBuffer.fontDataAt(i))); |
| + fontChars.append(run[i]); |
| + } |
| + } |
| +} |
| + |
| +void InspectorDOMAgent::getPlatformFontsForNode(WebCore::ErrorString* errorString, int nodeId, |
| + WTF::RefPtr<WebCore::TypeBuilder::Array<WebCore::TypeBuilder::DOM::TextNodePlatformFonts> >& textNodeList) |
| +{ |
| + Node* node = 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); |
| + } |
| + } |
| + |
| + textNodeList = TypeBuilder::Array<WebCore::TypeBuilder::DOM::TextNodePlatformFonts>::create(); |
| + for (int i = 0; i < textNodes.size(); ++i) { |
| + StringBuilder fontChars; |
| + RefPtr<TypeBuilder::Array<String> > fonts = TypeBuilder::Array<String>::create(); |
| + RenderText* renderer = static_cast<RenderText*>(textNodes[i]->renderer()); |
|
pfeldman
2013/08/16 08:16:48
toRenderText
|
| + if (renderer->isTextFragment()) { |
| + RenderTextFragment* textFragment = static_cast<RenderTextFragment*>(renderer); |
|
pfeldman
2013/08/16 08:16:48
ditto
|
| + if (textFragment->firstLetter()) { |
| + RenderObject* firstLetter = textFragment->firstLetter(); |
| + for (RenderObject* current = firstLetter->firstChild(); current; current = current->nextSibling()) { |
| + if (current->isText()) |
| + platformFontsForRenderer(static_cast<RenderText*>(current), fontChars, fonts); |
|
pfeldman
2013/08/16 08:16:48
collectFontsForRenderer
|
| + } |
| + } |
| + } |
| + platformFontsForRenderer(renderer, fontChars, fonts); |
|
pfeldman
2013/08/16 08:16:48
drop fontChars
|
| + if (!fonts->length()) |
| + continue; |
| + RefPtr<TypeBuilder::DOM::TextNodePlatformFonts> textNodePlatformFonts = TypeBuilder::DOM::TextNodePlatformFonts::create() |
| + .setText(fontChars.toString()) |
| + .setFonts(fonts); |
| + textNodeList->addItem(textNodePlatformFonts); |
| + } |
| +} |
| + |
| void InspectorDOMAgent::hideHighlight(ErrorString*) |
| { |
| m_overlay->hideHighlight(); |