OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2013 Samsung Electronics. All rights reserved. |
3 * | 4 * |
4 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
6 * met: | 7 * met: |
7 * | 8 * |
8 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 11 * * Redistributions in binary form must reproduce the above |
11 * copyright notice, this list of conditions and the following disclaimer | 12 * copyright notice, this list of conditions and the following disclaimer |
12 * in the documentation and/or other materials provided with the | 13 * in the documentation and/or other materials provided with the |
13 * distribution. | 14 * distribution. |
14 * * Neither the name of Google Inc. nor the names of its | 15 * * Neither the name of Google Inc. nor the names of its |
15 * contributors may be used to endorse or promote products derived from | 16 * contributors may be used to endorse or promote products derived from |
16 * this software without specific prior written permission. | 17 * this software without specific prior written permission. |
17 * | 18 * |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 30 */ |
30 | 31 |
31 #include "config.h" | 32 #include "config.h" |
| 33 #include "core/rendering/GraphicsContextAnnotator.h" |
| 34 |
32 #include "core/platform/graphics/GraphicsContextAnnotation.h" | 35 #include "core/platform/graphics/GraphicsContextAnnotation.h" |
33 | |
34 #include "core/platform/graphics/GraphicsContext.h" | |
35 #include "core/rendering/PaintInfo.h" | 36 #include "core/rendering/PaintInfo.h" |
36 #include "core/rendering/PaintPhase.h" | |
37 #include "core/rendering/RenderObject.h" | 37 #include "core/rendering/RenderObject.h" |
38 #include "wtf/text/StringBuilder.h" | 38 #include "wtf/text/StringBuilder.h" |
39 | 39 |
40 namespace { | 40 namespace { |
41 | 41 |
42 const char* AnnotationKeyRendererName = "RENDERER"; | |
43 const char* AnnotationKeyPaintPhase = "PHASE"; | |
44 const char* AnnotationKeyElementId = "ID"; | |
45 const char* AnnotationKeyElementClass = "CLASS"; | |
46 const char* AnnotationKeyElementTag = "TAG"; | |
47 | |
48 static const char* paintPhaseName(WebCore::PaintPhase phase) | 42 static const char* paintPhaseName(WebCore::PaintPhase phase) |
49 { | 43 { |
50 switch (phase) { | 44 switch (phase) { |
51 case WebCore::PaintPhaseBlockBackground: | 45 case WebCore::PaintPhaseBlockBackground: |
52 return "BlockBackground"; | 46 return "BlockBackground"; |
53 case WebCore::PaintPhaseChildBlockBackground: | 47 case WebCore::PaintPhaseChildBlockBackground: |
54 return "ChildBlockBackground"; | 48 return "ChildBlockBackground"; |
55 case WebCore::PaintPhaseChildBlockBackgrounds: | 49 case WebCore::PaintPhaseChildBlockBackgrounds: |
56 return "ChildBlockBackgrounds"; | 50 return "ChildBlockBackgrounds"; |
57 case WebCore::PaintPhaseFloat: | 51 case WebCore::PaintPhaseFloat: |
(...skipping 19 matching lines...) Expand all Loading... |
77 default: | 71 default: |
78 ASSERT_NOT_REACHED(); | 72 ASSERT_NOT_REACHED(); |
79 return "<unknown>"; | 73 return "<unknown>"; |
80 } | 74 } |
81 } | 75 } |
82 | 76 |
83 } | 77 } |
84 | 78 |
85 namespace WebCore { | 79 namespace WebCore { |
86 | 80 |
87 GraphicsContextAnnotation::GraphicsContextAnnotation(const PaintInfo& paintInfo,
const RenderObject* object) | 81 void GraphicsContextAnnotator::annotate(const PaintInfo& paintInfo, const Render
Object* object) |
88 : m_rendererName(0) | |
89 , m_paintPhase(0) | |
90 { | 82 { |
| 83 ASSERT(!m_context); |
| 84 |
91 ASSERT(paintInfo.context); | 85 ASSERT(paintInfo.context); |
92 ASSERT(object); | 86 ASSERT(object); |
93 | 87 |
94 AnnotationModeFlags mode = paintInfo.context->annotationMode(); | 88 AnnotationModeFlags mode = paintInfo.context->annotationMode(); |
95 Element* element = object->node() && object->node()->isElementNode() ? toEle
ment(object->node()) : 0; | 89 Element* element = object->node() && object->node()->isElementNode() ? toEle
ment(object->node()) : 0; |
96 | 90 |
| 91 const char* rendererName = 0; |
| 92 const char* paintPhase = 0; |
| 93 String elementId, elementClass, elementTag; |
| 94 |
97 if (mode & AnnotateRendererName) | 95 if (mode & AnnotateRendererName) |
98 m_rendererName = object->renderName(); | 96 rendererName = object->renderName(); |
99 | 97 |
100 if (mode & AnnotatePaintPhase) | 98 if (mode & AnnotatePaintPhase) |
101 m_paintPhase = paintPhaseName(paintInfo.phase); | 99 paintPhase = paintPhaseName(paintInfo.phase); |
102 | 100 |
103 if ((mode & AnnotateElementId) && element) { | 101 if ((mode & AnnotateElementId) && element) { |
104 const AtomicString id = element->getIdAttribute(); | 102 const AtomicString id = element->getIdAttribute(); |
105 if (!id.isNull() && !id.isEmpty()) | 103 if (!id.isNull() && !id.isEmpty()) |
106 m_elementId = id.string(); | 104 elementId = id.string(); |
107 } | 105 } |
108 | 106 |
109 if ((mode & AnnotateElementClass) && element && element->hasClass()) { | 107 if ((mode & AnnotateElementClass) && element && element->hasClass()) { |
110 SpaceSplitString classes = element->classNames(); | 108 SpaceSplitString classes = element->classNames(); |
111 if (!classes.isNull() && classes.size() > 0) { | 109 if (!classes.isNull() && classes.size() > 0) { |
112 StringBuilder classBuilder; | 110 StringBuilder classBuilder; |
113 for (size_t i = 0; i < classes.size(); ++i) { | 111 for (size_t i = 0; i < classes.size(); ++i) { |
114 if (i > 0) | 112 if (i > 0) |
115 classBuilder.append(" "); | 113 classBuilder.append(" "); |
116 classBuilder.append(classes[i]); | 114 classBuilder.append(classes[i]); |
117 } | 115 } |
118 | 116 |
119 m_elementClass = classBuilder.toString(); | 117 elementClass = classBuilder.toString(); |
120 } | 118 } |
121 } | 119 } |
122 | 120 |
123 if ((mode & AnnotateElementTag) && element) | 121 if ((mode & AnnotateElementTag) && element) |
124 m_elementTag = element->tagName(); | 122 elementTag = element->tagName(); |
125 } | |
126 | |
127 void GraphicsContextAnnotation::asAnnotationList(AnnotationList &list) const | |
128 { | |
129 list.clear(); | |
130 | |
131 if (m_rendererName) | |
132 list.append(std::make_pair(AnnotationKeyRendererName, m_rendererName)); | |
133 | |
134 if (m_paintPhase) | |
135 list.append(std::make_pair(AnnotationKeyPaintPhase, m_paintPhase)); | |
136 | |
137 if (!m_elementId.isEmpty()) | |
138 list.append(std::make_pair(AnnotationKeyElementId, m_elementId)); | |
139 | |
140 if (!m_elementClass.isEmpty()) | |
141 list.append(std::make_pair(AnnotationKeyElementClass, m_elementClass)); | |
142 | |
143 if (!m_elementTag.isEmpty()) | |
144 list.append(std::make_pair(AnnotationKeyElementTag, m_elementTag)); | |
145 } | |
146 | |
147 void GraphicsContextAnnotator::annotate(const PaintInfo& paintInfo, const Render
Object* object) | |
148 { | |
149 ASSERT(!m_context); | |
150 | 123 |
151 m_context = paintInfo.context; | 124 m_context = paintInfo.context; |
152 m_context->beginAnnotation(GraphicsContextAnnotation(paintInfo, object)); | 125 m_context->beginAnnotation(GraphicsContextAnnotation(rendererName, paintPhas
e, elementId, elementClass, elementTag)); |
153 } | 126 } |
154 | 127 |
155 void GraphicsContextAnnotator::finishAnnotation() | 128 void GraphicsContextAnnotator::finishAnnotation() |
156 { | 129 { |
157 ASSERT(m_context); | 130 ASSERT(m_context); |
158 m_context->endAnnotation(); | 131 m_context->endAnnotation(); |
159 } | 132 } |
160 | 133 |
161 } | 134 } |
OLD | NEW |