1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 #include "core/layout/TracedLayoutObject.h"
8 #include "core/layout/LayoutInline.h"
9 #include "core/layout/LayoutTableCell.h"
10 #include "core/layout/LayoutText.h"
11 #include "core/layout/LayoutView.h"
12 #include "platform/JSONValues.h"
16 PassRefPtr
<TraceEvent::ConvertableToTraceFormat
> TracedLayoutObject::create(const LayoutView
& view
, bool traceGeometry
)
18 return adoptRef(new TracedLayoutObject(view
, traceGeometry
));
21 String
TracedLayoutObject::asTraceFormat() const
23 StringBuilder builder
;
24 RefPtr
<JSONObject
> json(toJSON());
25 json
->writeJSON(&builder
);
26 return builder
.toString();
29 TracedLayoutObject::TracedLayoutObject(const LayoutObject
& object
, bool traceGeometry
)
30 : m_address((unsigned long) &object
)
31 , m_isAnonymous(object
.isAnonymous())
32 , m_isPositioned(object
.isOutOfFlowPositioned())
33 , m_isRelPositioned(object
.isRelPositioned())
34 , m_isStickyPositioned(object
.isStickyPositioned())
35 , m_isFloating(object
.isFloating())
36 , m_selfNeeds(object
.selfNeedsLayout())
37 , m_positionedMovement(object
.needsPositionedMovementLayout())
38 , m_childNeeds(object
.normalChildNeedsLayout())
39 , m_posChildNeeds(object
.posChildNeedsLayout())
40 , m_isTableCell(object
.isTableCell())
41 , m_name(String(object
.name()).isolatedCopy())
42 , m_absRect(traceGeometry
? object
.absoluteBoundingBoxRect() : IntRect())
44 if (Node
* node
= object
.node()) {
45 m_tag
= String(node
->nodeName()).isolatedCopy();
46 if (node
->isElementNode()) {
47 Element
& element
= toElement(*node
);
49 m_id
= String(element
.getIdAttribute()).isolatedCopy();
50 if (element
.hasClass()) {
51 for (size_t i
= 0; i
< element
.classNames().size(); ++i
) {
53 String(element
.classNames()[i
]).isolatedCopy());
59 // FIXME: When the fixmes in LayoutTreeAsText::writeLayoutObject() are
60 // fixed, deduplicate it with this.
62 if (object
.isText()) {
63 m_rect
= LayoutRect(toLayoutText(object
).linesBoundingBox());
64 } else if (object
.isLayoutInline()) {
65 m_rect
= LayoutRect(toLayoutInline(object
).linesBoundingBox());
66 } else if (object
.isBox()) {
67 m_rect
= toLayoutBox(&object
)->frameRect();
72 const LayoutTableCell
& c
= toLayoutTableCell(object
);
73 if (c
.row() && c
.row()->rowIndexWasSet() && c
.hasCol()
74 && (!c
.row()->section() || !c
.row()->section()->needsCellRecalc())) {
77 m_rowSpan
= c
.rowSpan();
78 m_colSpan
= c
.colSpan();
82 for (LayoutObject
* child
= object
.slowFirstChild(); child
; child
= child
->nextSibling()) {
83 m_children
.append(adoptRef(new TracedLayoutObject(*child
, traceGeometry
)));
87 PassRefPtr
<JSONObject
> TracedLayoutObject::toJSON() const
89 RefPtr
<JSONObject
> json(JSONObject::create());
90 json
->setNumber("address", m_address
);
91 json
->setString("name", m_name
);
93 json
->setString("tag", m_tag
);
95 json
->setString("htmlId", m_id
);
96 if (m_classNames
.size()) {
97 RefPtr
<JSONArray
> classNames(JSONArray::create());
98 for (const auto& className
: m_classNames
) {
99 classNames
->pushString(className
);
101 json
->setArray("classNames", classNames
);
103 json
->setNumber("absX", m_absRect
.x());
104 json
->setNumber("absY", m_absRect
.y());
105 json
->setNumber("relX", m_rect
.x());
106 json
->setNumber("relY", m_rect
.y());
107 json
->setNumber("width", m_rect
.width());
108 json
->setNumber("height", m_rect
.height());
110 json
->setBoolean("positioned", m_isPositioned
);
112 json
->setBoolean("selfNeeds", m_selfNeeds
);
113 if (m_positionedMovement
)
114 json
->setBoolean("positionedMovement", m_positionedMovement
);
116 json
->setBoolean("childNeeds", m_childNeeds
);
118 json
->setBoolean("posChildNeeds", m_posChildNeeds
);
120 json
->setNumber("row", m_row
);
121 json
->setNumber("col", m_col
);
123 json
->setNumber("rowSpan", m_rowSpan
);
125 json
->setNumber("colSpan", m_colSpan
);
128 json
->setBoolean("anonymous", m_isAnonymous
);
129 if (m_isRelPositioned
)
130 json
->setBoolean("relativePositioned", m_isRelPositioned
);
131 if (m_isStickyPositioned
)
132 json
->setBoolean("stickyPositioned", m_isStickyPositioned
);
134 json
->setBoolean("float", m_isFloating
);
135 if (m_children
.size()) {
136 RefPtr
<JSONArray
> children(JSONArray::create());
137 for (const auto& child
: m_children
) {
138 children
->pushObject(child
->toJSON());
140 json
->setArray("children", children
);
142 return json
.release();