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/. */
7 * implementation of interface that allows layout-debug extension access
8 * to some internals of layout
11 #include "nsILayoutDebugger.h"
13 #include "nsDisplayList.h"
14 #include "FrameLayerBuilder.h"
15 #include "nsPrintfCString.h"
19 using namespace mozilla
;
20 using namespace mozilla::layers
;
23 class nsLayoutDebugger
: public nsILayoutDebugger
{
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
;
47 virtual ~nsLayoutDebugger();
51 NS_NewLayoutDebugger(nsILayoutDebugger
** aResult
)
53 NS_PRECONDITION(aResult
, "null OUT ptr");
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
)
72 nsLayoutDebugger::SetShowFrameBorders(bool aEnable
)
74 nsFrame::ShowFrameBorders(aEnable
);
79 nsLayoutDebugger::GetShowFrameBorders(bool* aResult
)
81 *aResult
= nsFrame::GetShowFrameBorders();
86 nsLayoutDebugger::SetShowEventTargetFrameBorder(bool aEnable
)
88 nsFrame::ShowEventTargetFrameBorder(aEnable
);
93 nsLayoutDebugger::GetShowEventTargetFrameBorder(bool* aResult
)
95 *aResult
= nsFrame::GetShowEventTargetFrameBorder();
100 nsLayoutDebugger::GetContentSize(nsIDocument
* aDocument
,
101 int32_t* aSizeInBytesResult
)
103 *aSizeInBytesResult
= 0;
104 return NS_ERROR_FAILURE
;
108 nsLayoutDebugger::GetFrameSize(nsIPresShell
* aPresentation
,
109 int32_t* aSizeInBytesResult
)
111 *aSizeInBytesResult
= 0;
112 return NS_ERROR_FAILURE
;
116 nsLayoutDebugger::GetStyleSize(nsIPresShell
* aPresentation
,
117 int32_t* aSizeInBytesResult
)
119 *aSizeInBytesResult
= 0;
120 return NS_ERROR_FAILURE
;
124 #ifdef MOZ_DUMP_PAINTING
125 std::ostream
& operator<<(std::ostream
& os
, const nsPrintfCString
& rhs
) {
131 PrintDisplayListTo(nsDisplayListBuilder
* aBuilder
, const nsDisplayList
& aList
,
132 std::stringstream
& aStream
, uint32_t aIndent
, bool aDumpHtml
);
135 PrintDisplayItemTo(nsDisplayListBuilder
* aBuilder
, nsDisplayItem
* aItem
,
136 std::stringstream
& aStream
, uint32_t aIndent
, bool aDumpSublist
, bool aDumpHtml
)
138 std::stringstream ss
;
141 for (uint32_t indent
= 0; indent
< aIndent
; indent
++) {
145 nsIFrame
* f
= aItem
->Frame();
147 #ifdef DEBUG_FRAME_DUMP
148 f
->GetFrameName(fName
);
151 nsRect rect
= aItem
->GetBounds(aBuilder
, &snap
);
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());
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)) {
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
++) {
188 aStream
<< NS_LossyConvertUTF16toASCII(aItem
->Frame()->StyleDisplay()->mWillChange
[i
]).get();
193 // Display item specific debug info
195 aItem
->WriteDebugInfo(itemStr
);
196 aStream
<< itemStr
.get();
198 if (aDumpHtml
&& aItem
->Painted()) {
201 uint32_t key
= aItem
->GetPerFrameKey();
202 Layer
* layer
= mozilla::FrameLayerBuilder::GetDebugOldLayerFor(f
, key
);
205 aStream
<< nsPrintfCString(" <a href=\"#%p\">layer=%p</a>", layer
, layer
);
207 aStream
<< nsPrintfCString(" layer=0x%p", layer
);
210 if (aItem
->GetType() == nsDisplayItem::TYPE_SVG_EFFECTS
) {
212 (static_cast<nsDisplaySVGEffects
*>(aItem
))->PrintEffects(str
);
213 aStream
<< str
.get();
217 if (aDumpSublist
&& list
) {
218 PrintDisplayListTo(aBuilder
, *list
, aStream
, aIndent
+1, aDumpHtml
);
223 PrintDisplayListTo(nsDisplayListBuilder
* aBuilder
, const nsDisplayList
& aList
,
224 std::stringstream
& aStream
, uint32_t aIndent
, bool aDumpHtml
)
230 for (nsDisplayItem
* i
= aList
.GetBottom(); i
!= nullptr; i
= i
->GetAbove()) {
234 PrintDisplayItemTo(aBuilder
, i
, aStream
, aIndent
, true, aDumpHtml
);
246 nsFrame::PrintDisplayItem(nsDisplayListBuilder
* aBuilder
,
247 nsDisplayItem
* aItem
,
248 std::stringstream
& aStream
,
252 PrintDisplayItemTo(aBuilder
, aItem
, aStream
, 0, aDumpSublist
, aDumpHtml
);
256 nsFrame::PrintDisplayList(nsDisplayListBuilder
* aBuilder
,
257 const nsDisplayList
& aList
,
258 std::stringstream
& aStream
,
261 PrintDisplayListTo(aBuilder
, aList
, aStream
, 0, aDumpHtml
);
265 PrintDisplayListSetItem(nsDisplayListBuilder
* aBuilder
,
266 const char* aItemName
,
267 const nsDisplayList
& aList
,
268 std::stringstream
& aStream
,
274 aStream
<< aItemName
<< "\n";
275 PrintDisplayListTo(aBuilder
, aList
, aStream
, 0, aDumpHtml
);
282 nsFrame::PrintDisplayListSet(nsDisplayListBuilder
* aBuilder
,
283 const nsDisplayListSet
& aSet
,
284 std::stringstream
& aStream
,
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
);