| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "core/layout/TracedLayoutObject.h" | 6 #include "core/layout/TracedLayoutObject.h" |
| 7 | 7 |
| 8 #include "core/layout/LayoutInline.h" | 8 #include "core/layout/LayoutInline.h" |
| 9 #include "core/layout/LayoutTableCell.h" | 9 #include "core/layout/LayoutTableCell.h" |
| 10 #include "core/layout/LayoutText.h" | 10 #include "core/layout/LayoutText.h" |
| 11 #include "core/layout/LayoutView.h" | 11 #include "core/layout/LayoutView.h" |
| 12 #include "platform/JSONValues.h" | 12 #include "platform/JSONValues.h" |
| 13 | 13 |
| 14 namespace blink { | 14 namespace blink { |
| 15 | 15 |
| 16 PassRefPtr<TraceEvent::ConvertableToTraceFormat> TracedLayoutObject::create(cons
t LayoutView& view) | 16 PassRefPtr<TraceEvent::ConvertableToTraceFormat> TracedLayoutObject::create(cons
t LayoutView& view, bool traceGeometry) |
| 17 { | 17 { |
| 18 return adoptRef(new TracedLayoutObject(view)); | 18 return adoptRef(new TracedLayoutObject(view, traceGeometry)); |
| 19 } | 19 } |
| 20 | 20 |
| 21 String TracedLayoutObject::asTraceFormat() const | 21 String TracedLayoutObject::asTraceFormat() const |
| 22 { | 22 { |
| 23 StringBuilder builder; | 23 StringBuilder builder; |
| 24 RefPtr<JSONObject> json(toJSON()); | 24 RefPtr<JSONObject> json(toJSON()); |
| 25 json->writeJSON(&builder); | 25 json->writeJSON(&builder); |
| 26 return builder.toString(); | 26 return builder.toString(); |
| 27 } | 27 } |
| 28 | 28 |
| 29 TracedLayoutObject::TracedLayoutObject(const LayoutObject& object) | 29 TracedLayoutObject::TracedLayoutObject(const LayoutObject& object, bool traceGeo
metry) |
| 30 : m_address((unsigned long) &object) | 30 : m_address((unsigned long) &object) |
| 31 , m_isAnonymous(object.isAnonymous()) | 31 , m_isAnonymous(object.isAnonymous()) |
| 32 , m_isPositioned(object.isOutOfFlowPositioned()) | 32 , m_isPositioned(object.isOutOfFlowPositioned()) |
| 33 , m_isRelPositioned(object.isRelPositioned()) | 33 , m_isRelPositioned(object.isRelPositioned()) |
| 34 , m_isStickyPositioned(object.isStickyPositioned()) | 34 , m_isStickyPositioned(object.isStickyPositioned()) |
| 35 , m_isFloating(object.isFloating()) | 35 , m_isFloating(object.isFloating()) |
| 36 , m_selfNeeds(object.selfNeedsLayout()) | 36 , m_selfNeeds(object.selfNeedsLayout()) |
| 37 , m_positionedMovement(object.needsPositionedMovementLayout()) | 37 , m_positionedMovement(object.needsPositionedMovementLayout()) |
| 38 , m_childNeeds(object.normalChildNeedsLayout()) | 38 , m_childNeeds(object.normalChildNeedsLayout()) |
| 39 , m_posChildNeeds(object.posChildNeedsLayout()) | 39 , m_posChildNeeds(object.posChildNeedsLayout()) |
| 40 , m_isTableCell(object.isTableCell()) | 40 , m_isTableCell(object.isTableCell()) |
| 41 , m_name(String(object.name()).isolatedCopy()) | 41 , m_name(String(object.name()).isolatedCopy()) |
| 42 , m_absRect(object.absoluteBoundingBoxRect()) | 42 , m_absRect(traceGeometry ? object.absoluteBoundingBoxRect() : IntRect()) |
| 43 { | 43 { |
| 44 if (Node* node = object.node()) { | 44 if (Node* node = object.node()) { |
| 45 m_tag = String(node->nodeName()).isolatedCopy(); | 45 m_tag = String(node->nodeName()).isolatedCopy(); |
| 46 if (node->isElementNode()) { | 46 if (node->isElementNode()) { |
| 47 Element& element = toElement(*node); | 47 Element& element = toElement(*node); |
| 48 if (element.hasID()) | 48 if (element.hasID()) |
| 49 m_id = String(element.getIdAttribute()).isolatedCopy(); | 49 m_id = String(element.getIdAttribute()).isolatedCopy(); |
| 50 if (element.hasClass()) { | 50 if (element.hasClass()) { |
| 51 for (size_t i = 0; i < element.classNames().size(); ++i) { | 51 for (size_t i = 0; i < element.classNames().size(); ++i) { |
| 52 m_classNames.append( | 52 m_classNames.append( |
| 53 String(element.classNames()[i]).isolatedCopy()); | 53 String(element.classNames()[i]).isolatedCopy()); |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 | 58 |
| 59 // FIXME: When the fixmes in LayoutTreeAsText::writeLayoutObject() are | 59 // FIXME: When the fixmes in LayoutTreeAsText::writeLayoutObject() are |
| 60 // fixed, deduplicate it with this. | 60 // fixed, deduplicate it with this. |
| 61 if (object.isText()) { | 61 if (traceGeometry) { |
| 62 m_rect = LayoutRect(toLayoutText(object).linesBoundingBox()); | 62 if (object.isText()) { |
| 63 } else if (object.isLayoutInline()) { | 63 m_rect = LayoutRect(toLayoutText(object).linesBoundingBox()); |
| 64 m_rect = LayoutRect(toLayoutInline(object).linesBoundingBox()); | 64 } else if (object.isLayoutInline()) { |
| 65 } else if (object.isBox()) { | 65 m_rect = LayoutRect(toLayoutInline(object).linesBoundingBox()); |
| 66 m_rect = toLayoutBox(&object)->frameRect(); | 66 } else if (object.isBox()) { |
| 67 m_rect = toLayoutBox(&object)->frameRect(); |
| 68 } |
| 67 } | 69 } |
| 68 | 70 |
| 69 if (m_isTableCell) { | 71 if (m_isTableCell) { |
| 70 const LayoutTableCell& c = toLayoutTableCell(object); | 72 const LayoutTableCell& c = toLayoutTableCell(object); |
| 71 if (c.row() && c.row()->rowIndexWasSet() && c.hasCol() | 73 if (c.row() && c.row()->rowIndexWasSet() && c.hasCol() |
| 72 && (!c.row()->section() || !c.row()->section()->needsCellRecalc()))
{ | 74 && (!c.row()->section() || !c.row()->section()->needsCellRecalc()))
{ |
| 73 m_row = c.rowIndex(); | 75 m_row = c.rowIndex(); |
| 74 m_col = c.col(); | 76 m_col = c.col(); |
| 75 m_rowSpan = c.rowSpan(); | 77 m_rowSpan = c.rowSpan(); |
| 76 m_colSpan = c.colSpan(); | 78 m_colSpan = c.colSpan(); |
| 77 } | 79 } |
| 78 } | 80 } |
| 79 | 81 |
| 80 for (LayoutObject* child = object.slowFirstChild(); child; child = child->ne
xtSibling()) { | 82 for (LayoutObject* child = object.slowFirstChild(); child; child = child->ne
xtSibling()) { |
| 81 m_children.append(adoptRef(new TracedLayoutObject(*child))); | 83 m_children.append(adoptRef(new TracedLayoutObject(*child, traceGeometry)
)); |
| 82 } | 84 } |
| 83 } | 85 } |
| 84 | 86 |
| 85 PassRefPtr<JSONObject> TracedLayoutObject::toJSON() const | 87 PassRefPtr<JSONObject> TracedLayoutObject::toJSON() const |
| 86 { | 88 { |
| 87 RefPtr<JSONObject> json(JSONObject::create()); | 89 RefPtr<JSONObject> json(JSONObject::create()); |
| 88 json->setNumber("address", m_address); | 90 json->setNumber("address", m_address); |
| 89 json->setString("name", m_name); | 91 json->setString("name", m_name); |
| 90 if (!m_tag.isEmpty()) | 92 if (!m_tag.isEmpty()) |
| 91 json->setString("tag", m_tag); | 93 json->setString("tag", m_tag); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 RefPtr<JSONArray> children(JSONArray::create()); | 136 RefPtr<JSONArray> children(JSONArray::create()); |
| 135 for (const auto& child : m_children) { | 137 for (const auto& child : m_children) { |
| 136 children->pushObject(child->toJSON()); | 138 children->pushObject(child->toJSON()); |
| 137 } | 139 } |
| 138 json->setArray("children", children); | 140 json->setArray("children", children); |
| 139 } | 141 } |
| 140 return json.release(); | 142 return json.release(); |
| 141 } | 143 } |
| 142 | 144 |
| 143 } // namespace blink | 145 } // namespace blink |
| OLD | NEW |