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

Side by Side Diff: Source/core/platform/graphics/GraphicsContextAnnotation.cpp

Issue 55223002: Remove rendering dependency in GraphicsContextAnnotation (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Move GraphicsContextAnnotator to its own file Created 7 years, 1 month 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 14 matching lines...) Expand all
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (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. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "core/platform/graphics/GraphicsContextAnnotation.h" 32 #include "core/platform/graphics/GraphicsContextAnnotation.h"
33 33
34 #include "core/platform/graphics/GraphicsContext.h" 34 #include "core/platform/graphics/GraphicsContext.h"
35 #include "core/rendering/PaintInfo.h"
36 #include "core/rendering/PaintPhase.h"
37 #include "core/rendering/RenderObject.h"
38 #include "wtf/text/StringBuilder.h"
39 35
40 namespace { 36 namespace {
41 37
42 const char* AnnotationKeyRendererName = "RENDERER"; 38 const char* AnnotationKeyRendererName = "RENDERER";
43 const char* AnnotationKeyPaintPhase = "PHASE"; 39 const char* AnnotationKeyPaintPhase = "PHASE";
44 const char* AnnotationKeyElementId = "ID"; 40 const char* AnnotationKeyElementId = "ID";
45 const char* AnnotationKeyElementClass = "CLASS"; 41 const char* AnnotationKeyElementClass = "CLASS";
46 const char* AnnotationKeyElementTag = "TAG"; 42 const char* AnnotationKeyElementTag = "TAG";
47 43
48 static const char* paintPhaseName(WebCore::PaintPhase phase)
49 {
50 switch (phase) {
51 case WebCore::PaintPhaseBlockBackground:
52 return "BlockBackground";
53 case WebCore::PaintPhaseChildBlockBackground:
54 return "ChildBlockBackground";
55 case WebCore::PaintPhaseChildBlockBackgrounds:
56 return "ChildBlockBackgrounds";
57 case WebCore::PaintPhaseFloat:
58 return "Float";
59 case WebCore::PaintPhaseForeground:
60 return "Foreground";
61 case WebCore::PaintPhaseOutline:
62 return "Outline";
63 case WebCore::PaintPhaseChildOutlines:
64 return "ChildOutlines";
65 case WebCore::PaintPhaseSelfOutline:
66 return "SelfOutline";
67 case WebCore::PaintPhaseSelection:
68 return "Selection";
69 case WebCore::PaintPhaseCollapsedTableBorders:
70 return "CollapsedTableBorders";
71 case WebCore::PaintPhaseTextClip:
72 return "TextClip";
73 case WebCore::PaintPhaseMask:
74 return "Mask";
75 case WebCore::PaintPhaseClippingMask:
76 return "ClippingMask";
77 default:
78 ASSERT_NOT_REACHED();
79 return "<unknown>";
80 }
81 }
82
83 } 44 }
84 45
85 namespace WebCore { 46 namespace WebCore {
86 47
87 GraphicsContextAnnotation::GraphicsContextAnnotation(const PaintInfo& paintInfo, const RenderObject* object) 48 GraphicsContextAnnotation::GraphicsContextAnnotation(const char* rendererName, c onst char* paintPhase, const String& elementId, const String& elementClass, cons t String& elementTag)
88 : m_rendererName(0) 49 : m_rendererName(rendererName)
89 , m_paintPhase(0) 50 , m_paintPhase(paintPhase)
51 , m_elementId(elementId)
52 , m_elementClass(elementClass)
53 , m_elementTag(elementTag)
90 { 54 {
91 ASSERT(paintInfo.context);
92 ASSERT(object);
93
94 AnnotationModeFlags mode = paintInfo.context->annotationMode();
95 Element* element = object->node() && object->node()->isElementNode() ? toEle ment(object->node()) : 0;
96
97 if (mode & AnnotateRendererName)
98 m_rendererName = object->renderName();
99
100 if (mode & AnnotatePaintPhase)
101 m_paintPhase = paintPhaseName(paintInfo.phase);
102
103 if ((mode & AnnotateElementId) && element) {
104 const AtomicString id = element->getIdAttribute();
105 if (!id.isNull() && !id.isEmpty())
106 m_elementId = id.string();
107 }
108
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) {
114 if (i > 0)
115 classBuilder.append(" ");
116 classBuilder.append(classes[i]);
117 }
118
119 m_elementClass = classBuilder.toString();
120 }
121 }
122
123 if ((mode & AnnotateElementTag) && element)
124 m_elementTag = element->tagName();
125 } 55 }
126 56
127 void GraphicsContextAnnotation::asAnnotationList(AnnotationList &list) const 57 void GraphicsContextAnnotation::asAnnotationList(AnnotationList &list) const
128 { 58 {
129 list.clear(); 59 list.clear();
130 60
131 if (m_rendererName) 61 if (m_rendererName)
132 list.append(std::make_pair(AnnotationKeyRendererName, m_rendererName)); 62 list.append(std::make_pair(AnnotationKeyRendererName, m_rendererName));
133 63
134 if (m_paintPhase) 64 if (m_paintPhase)
135 list.append(std::make_pair(AnnotationKeyPaintPhase, m_paintPhase)); 65 list.append(std::make_pair(AnnotationKeyPaintPhase, m_paintPhase));
136 66
137 if (!m_elementId.isEmpty()) 67 if (!m_elementId.isEmpty())
138 list.append(std::make_pair(AnnotationKeyElementId, m_elementId)); 68 list.append(std::make_pair(AnnotationKeyElementId, m_elementId));
139 69
140 if (!m_elementClass.isEmpty()) 70 if (!m_elementClass.isEmpty())
141 list.append(std::make_pair(AnnotationKeyElementClass, m_elementClass)); 71 list.append(std::make_pair(AnnotationKeyElementClass, m_elementClass));
142 72
143 if (!m_elementTag.isEmpty()) 73 if (!m_elementTag.isEmpty())
144 list.append(std::make_pair(AnnotationKeyElementTag, m_elementTag)); 74 list.append(std::make_pair(AnnotationKeyElementTag, m_elementTag));
145 } 75 }
146 76
147 void GraphicsContextAnnotator::annotate(const PaintInfo& paintInfo, const Render Object* object)
148 {
149 ASSERT(!m_context);
150
151 m_context = paintInfo.context;
152 m_context->beginAnnotation(GraphicsContextAnnotation(paintInfo, object));
153 } 77 }
154
155 void GraphicsContextAnnotator::finishAnnotation()
156 {
157 ASSERT(m_context);
158 m_context->endAnnotation();
159 }
160
161 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698