Bumping manifests a=b2g-bump
[gecko.git] / layout / base / nsLayoutDebugger.cpp
blobedffbe3fbd8dd52beee82ffe5a85d4ac166523ea
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /*
7 * implementation of interface that allows layout-debug extension access
8 * to some internals of layout
9 */
11 #include "nsILayoutDebugger.h"
12 #include "nsFrame.h"
13 #include "nsDisplayList.h"
14 #include "FrameLayerBuilder.h"
15 #include "nsPrintfCString.h"
17 #include <stdio.h>
19 using namespace mozilla;
20 using namespace mozilla::layers;
22 #ifdef DEBUG
23 class nsLayoutDebugger : public nsILayoutDebugger {
24 public:
25 nsLayoutDebugger();
27 NS_DECL_ISUPPORTS
29 NS_IMETHOD SetShowFrameBorders(bool aEnable) MOZ_OVERRIDE;
31 NS_IMETHOD GetShowFrameBorders(bool* aResult) MOZ_OVERRIDE;
33 NS_IMETHOD SetShowEventTargetFrameBorder(bool aEnable) MOZ_OVERRIDE;
35 NS_IMETHOD GetShowEventTargetFrameBorder(bool* aResult) MOZ_OVERRIDE;
37 NS_IMETHOD GetContentSize(nsIDocument* aDocument,
38 int32_t* aSizeInBytesResult) MOZ_OVERRIDE;
40 NS_IMETHOD GetFrameSize(nsIPresShell* aPresentation,
41 int32_t* aSizeInBytesResult) MOZ_OVERRIDE;
43 NS_IMETHOD GetStyleSize(nsIPresShell* aPresentation,
44 int32_t* aSizeInBytesResult) MOZ_OVERRIDE;
46 protected:
47 virtual ~nsLayoutDebugger();
50 nsresult
51 NS_NewLayoutDebugger(nsILayoutDebugger** aResult)
53 NS_PRECONDITION(aResult, "null OUT ptr");
54 if (!aResult) {
55 return NS_ERROR_NULL_POINTER;
57 nsLayoutDebugger* it = new nsLayoutDebugger();
58 return it->QueryInterface(NS_GET_IID(nsILayoutDebugger), (void**)aResult);
61 nsLayoutDebugger::nsLayoutDebugger()
65 nsLayoutDebugger::~nsLayoutDebugger()
69 NS_IMPL_ISUPPORTS(nsLayoutDebugger, nsILayoutDebugger)
71 NS_IMETHODIMP
72 nsLayoutDebugger::SetShowFrameBorders(bool aEnable)
74 nsFrame::ShowFrameBorders(aEnable);
75 return NS_OK;
78 NS_IMETHODIMP
79 nsLayoutDebugger::GetShowFrameBorders(bool* aResult)
81 *aResult = nsFrame::GetShowFrameBorders();
82 return NS_OK;
85 NS_IMETHODIMP
86 nsLayoutDebugger::SetShowEventTargetFrameBorder(bool aEnable)
88 nsFrame::ShowEventTargetFrameBorder(aEnable);
89 return NS_OK;
92 NS_IMETHODIMP
93 nsLayoutDebugger::GetShowEventTargetFrameBorder(bool* aResult)
95 *aResult = nsFrame::GetShowEventTargetFrameBorder();
96 return NS_OK;
99 NS_IMETHODIMP
100 nsLayoutDebugger::GetContentSize(nsIDocument* aDocument,
101 int32_t* aSizeInBytesResult)
103 *aSizeInBytesResult = 0;
104 return NS_ERROR_FAILURE;
107 NS_IMETHODIMP
108 nsLayoutDebugger::GetFrameSize(nsIPresShell* aPresentation,
109 int32_t* aSizeInBytesResult)
111 *aSizeInBytesResult = 0;
112 return NS_ERROR_FAILURE;
115 NS_IMETHODIMP
116 nsLayoutDebugger::GetStyleSize(nsIPresShell* aPresentation,
117 int32_t* aSizeInBytesResult)
119 *aSizeInBytesResult = 0;
120 return NS_ERROR_FAILURE;
122 #endif
124 #ifdef MOZ_DUMP_PAINTING
125 std::ostream& operator<<(std::ostream& os, const nsPrintfCString& rhs) {
126 os << rhs.get();
127 return os;
130 static void
131 PrintDisplayListTo(nsDisplayListBuilder* aBuilder, const nsDisplayList& aList,
132 std::stringstream& aStream, uint32_t aIndent, bool aDumpHtml);
134 static void
135 PrintDisplayItemTo(nsDisplayListBuilder* aBuilder, nsDisplayItem* aItem,
136 std::stringstream& aStream, uint32_t aIndent, bool aDumpSublist, bool aDumpHtml)
138 std::stringstream ss;
140 if (!aDumpHtml) {
141 for (uint32_t indent = 0; indent < aIndent; indent++) {
142 aStream << " ";
145 nsIFrame* f = aItem->Frame();
146 nsAutoString fName;
147 #ifdef DEBUG_FRAME_DUMP
148 f->GetFrameName(fName);
149 #endif
150 bool snap;
151 nsRect rect = aItem->GetBounds(aBuilder, &snap);
152 nscolor color;
153 nsRect vis = aItem->GetVisibleRect();
154 nsRect component = aItem->GetComponentAlphaBounds(aBuilder);
155 nsDisplayList* list = aItem->GetChildren();
156 const DisplayItemClip& clip = aItem->GetClip();
157 nsRegion opaque = aItem->GetOpaqueRegion(aBuilder, &snap);
158 if (aDumpHtml && aItem->Painted()) {
159 nsCString string(aItem->Name());
160 string.Append('-');
161 string.AppendInt((uint64_t)aItem);
162 aStream << nsPrintfCString("<a href=\"javascript:ViewImage('%s')\">", string.BeginReading());
164 aStream << nsPrintfCString("%s p=0x%p f=0x%p(%s) %sbounds(%d,%d,%d,%d) visible(%d,%d,%d,%d) componentAlpha(%d,%d,%d,%d) clip(%s) %s",
165 aItem->Name(), aItem, (void*)f, NS_ConvertUTF16toUTF8(fName).get(),
166 (aItem->ZIndex() ? nsPrintfCString("z=%d ", aItem->ZIndex()).get() : ""),
167 rect.x, rect.y, rect.width, rect.height,
168 vis.x, vis.y, vis.width, vis.height,
169 component.x, component.y, component.width, component.height,
170 clip.ToString().get(),
171 aItem->IsUniform(aBuilder, &color) ? " uniform" : "");
173 nsRegionRectIterator iter(opaque);
174 for (const nsRect* r = iter.Next(); r; r = iter.Next()) {
175 aStream << nsPrintfCString(" (opaque %d,%d,%d,%d)", r->x, r->y, r->width, r->height);
178 if (aItem->ShouldFixToViewport(nullptr)) {
179 aStream << " fixed";
182 if (aItem->Frame()->StyleDisplay()->mWillChange.Length() > 0) {
183 aStream << " (will-change=";
184 for (size_t i = 0; i < aItem->Frame()->StyleDisplay()->mWillChange.Length(); i++) {
185 if (i > 0) {
186 aStream << ",";
188 aStream << NS_LossyConvertUTF16toASCII(aItem->Frame()->StyleDisplay()->mWillChange[i]).get();
190 aStream << ")";
193 // Display item specific debug info
194 nsCString itemStr;
195 aItem->WriteDebugInfo(itemStr);
196 aStream << itemStr.get();
198 if (aDumpHtml && aItem->Painted()) {
199 aStream << "</a>";
201 uint32_t key = aItem->GetPerFrameKey();
202 Layer* layer = mozilla::FrameLayerBuilder::GetDebugOldLayerFor(f, key);
203 if (layer) {
204 if (aDumpHtml) {
205 aStream << nsPrintfCString(" <a href=\"#%p\">layer=%p</a>", layer, layer);
206 } else {
207 aStream << nsPrintfCString(" layer=0x%p", layer);
210 if (aItem->GetType() == nsDisplayItem::TYPE_SVG_EFFECTS) {
211 nsCString str;
212 (static_cast<nsDisplaySVGEffects*>(aItem))->PrintEffects(str);
213 aStream << str.get();
215 aStream << "\n";
217 if (aDumpSublist && list) {
218 PrintDisplayListTo(aBuilder, *list, aStream, aIndent+1, aDumpHtml);
222 static void
223 PrintDisplayListTo(nsDisplayListBuilder* aBuilder, const nsDisplayList& aList,
224 std::stringstream& aStream, uint32_t aIndent, bool aDumpHtml)
226 if (aDumpHtml) {
227 aStream << "<ul>";
230 for (nsDisplayItem* i = aList.GetBottom(); i != nullptr; i = i->GetAbove()) {
231 if (aDumpHtml) {
232 aStream << "<li>";
234 PrintDisplayItemTo(aBuilder, i, aStream, aIndent, true, aDumpHtml);
235 if (aDumpHtml) {
236 aStream << "</li>";
240 if (aDumpHtml) {
241 aStream << "</ul>";
245 void
246 nsFrame::PrintDisplayItem(nsDisplayListBuilder* aBuilder,
247 nsDisplayItem* aItem,
248 std::stringstream& aStream,
249 bool aDumpSublist,
250 bool aDumpHtml)
252 PrintDisplayItemTo(aBuilder, aItem, aStream, 0, aDumpSublist, aDumpHtml);
255 void
256 nsFrame::PrintDisplayList(nsDisplayListBuilder* aBuilder,
257 const nsDisplayList& aList,
258 std::stringstream& aStream,
259 bool aDumpHtml)
261 PrintDisplayListTo(aBuilder, aList, aStream, 0, aDumpHtml);
264 static void
265 PrintDisplayListSetItem(nsDisplayListBuilder* aBuilder,
266 const char* aItemName,
267 const nsDisplayList& aList,
268 std::stringstream& aStream,
269 bool aDumpHtml)
271 if (aDumpHtml) {
272 aStream << "<li>";
274 aStream << aItemName << "\n";
275 PrintDisplayListTo(aBuilder, aList, aStream, 0, aDumpHtml);
276 if (aDumpHtml) {
277 aStream << "</li>";
281 void
282 nsFrame::PrintDisplayListSet(nsDisplayListBuilder* aBuilder,
283 const nsDisplayListSet& aSet,
284 std::stringstream& aStream,
285 bool aDumpHtml)
287 if (aDumpHtml) {
288 aStream << "<ul>";
290 PrintDisplayListSetItem(aBuilder, "[BorderBackground]", *(aSet.BorderBackground()), aStream, aDumpHtml);
291 PrintDisplayListSetItem(aBuilder, "[BlockBorderBackgrounds]", *(aSet.BlockBorderBackgrounds()), aStream, aDumpHtml);
292 PrintDisplayListSetItem(aBuilder, "[Floats]", *(aSet.Floats()), aStream, aDumpHtml);
293 PrintDisplayListSetItem(aBuilder, "[PositionedDescendants]", *(aSet.PositionedDescendants()), aStream, aDumpHtml);
294 PrintDisplayListSetItem(aBuilder, "[Outlines]", *(aSet.Outlines()), aStream, aDumpHtml);
295 PrintDisplayListSetItem(aBuilder, "[Content]", *(aSet.Content()), aStream, aDumpHtml);
296 if (aDumpHtml) {
297 aStream << "</ul>";
301 #endif