Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / layout / LayoutAnalyzer.cpp
blobb1b510de7454f14564588947fc85825b2d74e097
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.
5 #include "config.h"
6 #include "core/layout/LayoutAnalyzer.h"
8 #include "core/frame/FrameView.h"
9 #include "core/layout/LayoutBlock.h"
10 #include "core/layout/LayoutObject.h"
11 #include "core/layout/LayoutText.h"
12 #include "platform/TracedValue.h"
14 namespace blink {
16 LayoutAnalyzer::Scope::Scope(const LayoutObject& o)
17 : m_layoutObject(o)
18 , m_analyzer(o.frameView()->layoutAnalyzer())
20 if (m_analyzer)
21 m_analyzer->push(o);
24 LayoutAnalyzer::Scope::~Scope()
26 if (m_analyzer)
27 m_analyzer->pop(m_layoutObject);
30 LayoutAnalyzer::BlockScope::BlockScope(const LayoutBlock& block)
31 : m_block(block)
32 , m_width(block.frameRect().width())
33 , m_height(block.frameRect().height())
37 LayoutAnalyzer::BlockScope::~BlockScope()
39 LayoutAnalyzer* analyzer = m_block.frameView()->layoutAnalyzer();
40 if (!analyzer)
41 return;
42 bool changed = false;
43 if (m_width != m_block.frameRect().width()) {
44 analyzer->increment(LayoutBlockWidthChanged);
45 changed = true;
47 if (m_height != m_block.frameRect().height()) {
48 analyzer->increment(LayoutBlockHeightChanged);
49 changed = true;
51 analyzer->increment(changed ? LayoutBlockSizeChanged : LayoutBlockSizeDidNotChange);
54 void LayoutAnalyzer::reset()
56 m_startMs = currentTimeMS();
57 m_depth = 0;
58 for (size_t i = 0; i < NumCounters; ++i) {
59 m_counters[i] = 0;
63 void LayoutAnalyzer::push(const LayoutObject& o)
65 increment(TotalLayoutObjectsThatWereLaidOut);
66 if (!o.everHadLayout())
67 increment(LayoutObjectsThatHadNeverHadLayout);
68 if (o.selfNeedsLayout())
69 increment(LayoutObjectsThatNeedLayoutForThemselves);
70 if (o.needsPositionedMovementLayout())
71 increment(LayoutObjectsThatNeedPositionedMovementLayout);
72 if (o.isOutOfFlowPositioned())
73 increment(LayoutObjectsThatAreOutOfFlowPositioned);
74 if (o.isTableCell())
75 increment(LayoutObjectsThatAreTableCells);
76 if (o.isFloating())
77 increment(LayoutObjectsThatAreFloating);
78 if (o.style()->specifiesColumns())
79 increment(LayoutObjectsThatSpecifyColumns);
80 if (o.hasLayer())
81 increment(LayoutObjectsThatHaveALayer);
82 if (o.isLayoutInline() && o.alwaysCreateLineBoxesForLayoutInline())
83 increment(LayoutInlineObjectsThatAlwaysCreateLineBoxes);
84 if (o.isText()) {
85 const LayoutText& t = *toLayoutText(&o);
86 if (t.canUseSimpleFontCodePath()) {
87 increment(LayoutObjectsThatAreTextAndCanUseTheSimpleFontCodePath);
88 increment(CharactersInLayoutObjectsThatAreTextAndCanUseTheSimpleFontCodePath, t.textLength());
89 } else {
90 increment(LayoutObjectsThatAreTextAndCanNotUseTheSimpleFontCodePath);
91 increment(CharactersInLayoutObjectsThatAreTextAndCanNotUseTheSimpleFontCodePath, t.textLength());
95 ++m_depth;
97 // This refers to LayoutAnalyzer depth, which is generally closer to C++
98 // stack recursion depth, not layout tree depth or DOM tree depth.
99 m_counters[LayoutAnalyzerStackMaximumDepth] = max(m_counters[LayoutAnalyzerStackMaximumDepth], m_depth);
102 void LayoutAnalyzer::pop(const LayoutObject& o)
104 ASSERT(m_depth > 0);
105 --m_depth;
108 PassRefPtr<TracedValue> LayoutAnalyzer::toTracedValue()
110 RefPtr<TracedValue> tracedValue(TracedValue::create());
111 for (size_t i = 0; i < NumCounters; ++i) {
112 if (m_counters[i] > 0)
113 tracedValue->setInteger(nameForCounter(static_cast<Counter>(i)), m_counters[i]);
115 return tracedValue.release();
118 const char* LayoutAnalyzer::nameForCounter(Counter counter) const
120 switch (counter) {
121 case LayoutBlockWidthChanged: return "LayoutBlockWidthChanged";
122 case LayoutBlockHeightChanged: return "LayoutBlockHeightChanged";
123 case LayoutBlockSizeChanged: return "LayoutBlockSizeChanged";
124 case LayoutBlockSizeDidNotChange: return "LayoutBlockSizeDidNotChange";
125 case LayoutObjectsThatSpecifyColumns: return "LayoutObjectsThatSpecifyColumns";
126 case LayoutAnalyzerStackMaximumDepth: return "LayoutAnalyzerStackMaximumDepth";
127 case LayoutObjectsThatAreFloating: return "LayoutObjectsThatAreFloating";
128 case LayoutObjectsThatHaveALayer: return "LayoutObjectsThatHaveALayer";
129 case LayoutInlineObjectsThatAlwaysCreateLineBoxes: return "LayoutInlineObjectsThatAlwaysCreateLineBoxes";
130 case LayoutObjectsThatHadNeverHadLayout: return "LayoutObjectsThatHadNeverHadLayout";
131 case LayoutObjectsThatAreOutOfFlowPositioned: return "LayoutObjectsThatAreOutOfFlowPositioned";
132 case LayoutObjectsThatNeedPositionedMovementLayout: return "LayoutObjectsThatNeedPositionedMovementLayout";
133 case PerformLayoutRootLayoutObjects: return "PerformLayoutRootLayoutObjects";
134 case LayoutObjectsThatNeedLayoutForThemselves: return "LayoutObjectsThatNeedLayoutForThemselves";
135 case LayoutObjectsThatNeedSimplifiedLayout: return "LayoutObjectsThatNeedSimplifiedLayout";
136 case LayoutObjectsThatAreTableCells: return "LayoutObjectsThatAreTableCells";
137 case LayoutObjectsThatAreTextAndCanNotUseTheSimpleFontCodePath: return "LayoutObjectsThatAreTextAndCanNotUseTheSimpleFontCodePath";
138 case CharactersInLayoutObjectsThatAreTextAndCanNotUseTheSimpleFontCodePath: return "CharactersInLayoutObjectsThatAreTextAndCanNotUseTheSimpleFontCodePath";
139 case LayoutObjectsThatAreTextAndCanUseTheSimpleFontCodePath: return "LayoutObjectsThatAreTextAndCanUseTheSimpleFontCodePath";
140 case CharactersInLayoutObjectsThatAreTextAndCanUseTheSimpleFontCodePath: return "CharactersInLayoutObjectsThatAreTextAndCanUseTheSimpleFontCodePath";
141 case TotalLayoutObjectsThatWereLaidOut: return "TotalLayoutObjectsThatWereLaidOut";
143 ASSERT_NOT_REACHED();
144 return "";
147 } // namespace blink