2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * Copyright (C) 2013 Samsung Electronics. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include "core/rendering/GraphicsContextAnnotator.h"
35 #include "core/inspector/InspectorNodeIds.h"
36 #include "core/rendering/PaintInfo.h"
37 #include "core/rendering/RenderObject.h"
38 #include "platform/graphics/GraphicsContextAnnotation.h"
39 #include "wtf/text/StringBuilder.h"
43 const char AnnotationKeyRendererName[] = "RENDERER";
44 const char AnnotationKeyPaintPhase[] = "PHASE";
45 const char AnnotationKeyElementId[] = "ID";
46 const char AnnotationKeyElementClass[] = "CLASS";
47 const char AnnotationKeyElementTag[] = "TAG";
48 const char AnnotationKeyInspectorNodeId[] = "INSPECTOR_ID";
50 static const char* paintPhaseName(blink::PaintPhase phase)
53 case blink::PaintPhaseBlockBackground:
54 return "BlockBackground";
55 case blink::PaintPhaseChildBlockBackground:
56 return "ChildBlockBackground";
57 case blink::PaintPhaseChildBlockBackgrounds:
58 return "ChildBlockBackgrounds";
59 case blink::PaintPhaseFloat:
61 case blink::PaintPhaseForeground:
63 case blink::PaintPhaseOutline:
65 case blink::PaintPhaseChildOutlines:
66 return "ChildOutlines";
67 case blink::PaintPhaseSelfOutline:
69 case blink::PaintPhaseSelection:
71 case blink::PaintPhaseCollapsedTableBorders:
72 return "CollapsedTableBorders";
73 case blink::PaintPhaseTextClip:
75 case blink::PaintPhaseMask:
77 case blink::PaintPhaseClippingMask:
78 return "ClippingMask";
89 void GraphicsContextAnnotator::annotate(const PaintInfo& paintInfo, const RenderObject* object)
93 ASSERT(paintInfo.context);
96 AnnotationList annotations;
97 AnnotationModeFlags mode = paintInfo.context->annotationMode();
98 Element* element = object->node() && object->node()->isElementNode() ? toElement(object->node()) : 0;
100 if (mode & AnnotateRendererName)
101 annotations.append(std::make_pair(AnnotationKeyRendererName, object->renderName()));
103 if (mode & AnnotatePaintPhase)
104 annotations.append(std::make_pair(AnnotationKeyPaintPhase, paintPhaseName(paintInfo.phase)));
106 if ((mode & AnnotateElementId) && element && element->hasID())
107 annotations.append(std::make_pair(AnnotationKeyElementId, element->getIdAttribute().string()));
109 if ((mode & AnnotateElementClass) && element && element->hasClass()) {
110 SpaceSplitString classes = element->classNames();
111 if (!classes.isNull() && classes.size() > 0) {
112 StringBuilder classBuilder;
113 for (size_t i = 0; i < classes.size(); ++i) {
115 classBuilder.append(' ');
116 classBuilder.append(classes[i]);
119 annotations.append(std::make_pair(AnnotationKeyElementClass, classBuilder.toString()));
123 if ((mode & AnnotateElementTag) && element)
124 annotations.append(std::make_pair(AnnotationKeyElementTag, element->tagName()));
126 if (mode & AnnotateInspectorId) {
127 if (Node* ownerNode = object->generatingNode()) {
128 annotations.append(std::make_pair(AnnotationKeyInspectorNodeId,
129 String::number(InspectorNodeIds::idForNode(ownerNode))));
133 m_context = paintInfo.context;
134 m_context->beginAnnotation(annotations);
137 void GraphicsContextAnnotator::finishAnnotation()
140 m_context->endAnnotation();