1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is Mozilla Communicator client code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
39 * implementation of interface that allows layout-debug extension access
40 * to some internals of layout
43 #include "nsILayoutDebugger.h"
45 #include "nsDisplayList.h"
50 class nsLayoutDebugger
: public nsILayoutDebugger
{
53 virtual ~nsLayoutDebugger();
57 NS_IMETHOD
SetShowFrameBorders(PRBool aEnable
);
59 NS_IMETHOD
GetShowFrameBorders(PRBool
* aResult
);
61 NS_IMETHOD
SetShowEventTargetFrameBorder(PRBool aEnable
);
63 NS_IMETHOD
GetShowEventTargetFrameBorder(PRBool
* aResult
);
65 NS_IMETHOD
GetContentSize(nsIDocument
* aDocument
,
66 PRInt32
* aSizeInBytesResult
);
68 NS_IMETHOD
GetFrameSize(nsIPresShell
* aPresentation
,
69 PRInt32
* aSizeInBytesResult
);
71 NS_IMETHOD
GetStyleSize(nsIPresShell
* aPresentation
,
72 PRInt32
* aSizeInBytesResult
);
77 NS_NewLayoutDebugger(nsILayoutDebugger
** aResult
)
79 NS_PRECONDITION(aResult
, "null OUT ptr");
81 return NS_ERROR_NULL_POINTER
;
83 nsLayoutDebugger
* it
= new nsLayoutDebugger();
85 return NS_ERROR_OUT_OF_MEMORY
;
87 return it
->QueryInterface(NS_GET_IID(nsILayoutDebugger
), (void**)aResult
);
90 nsLayoutDebugger::nsLayoutDebugger()
94 nsLayoutDebugger::~nsLayoutDebugger()
98 NS_IMPL_ISUPPORTS1(nsLayoutDebugger
, nsILayoutDebugger
)
101 nsLayoutDebugger::SetShowFrameBorders(PRBool aEnable
)
103 nsFrame::ShowFrameBorders(aEnable
);
108 nsLayoutDebugger::GetShowFrameBorders(PRBool
* aResult
)
110 *aResult
= nsFrame::GetShowFrameBorders();
115 nsLayoutDebugger::SetShowEventTargetFrameBorder(PRBool aEnable
)
117 nsFrame::ShowEventTargetFrameBorder(aEnable
);
122 nsLayoutDebugger::GetShowEventTargetFrameBorder(PRBool
* aResult
)
124 *aResult
= nsFrame::GetShowEventTargetFrameBorder();
129 nsLayoutDebugger::GetContentSize(nsIDocument
* aDocument
,
130 PRInt32
* aSizeInBytesResult
)
132 *aSizeInBytesResult
= 0;
133 return NS_ERROR_FAILURE
;
137 nsLayoutDebugger::GetFrameSize(nsIPresShell
* aPresentation
,
138 PRInt32
* aSizeInBytesResult
)
140 *aSizeInBytesResult
= 0;
141 return NS_ERROR_FAILURE
;
145 nsLayoutDebugger::GetStyleSize(nsIPresShell
* aPresentation
,
146 PRInt32
* aSizeInBytesResult
)
148 *aSizeInBytesResult
= 0;
149 return NS_ERROR_FAILURE
;
153 PrintDisplayListTo(nsDisplayListBuilder
* aBuilder
, const nsDisplayList
& aList
,
154 PRInt32 aIndent
, FILE* aOutput
)
156 for (nsDisplayItem
* i
= aList
.GetBottom(); i
!= nsnull
; i
= i
->GetAbove()) {
157 if (aList
.DidComputeVisibility() && i
->GetVisibleRect().IsEmpty())
159 for (PRInt32 j
= 0; j
< aIndent
; ++j
) {
162 nsIFrame
* f
= i
->GetUnderlyingFrame();
165 f
->GetFrameName(fName
);
167 nsRect rect
= i
->GetBounds(aBuilder
);
168 switch (i
->GetType()) {
169 case nsDisplayItem::TYPE_CLIP
:
170 case nsDisplayItem::TYPE_CLIP_ROUNDED_RECT
: {
171 nsDisplayClip
* c
= static_cast<nsDisplayClip
*>(i
);
172 rect
= c
->GetClipRect();
179 nsRect vis
= i
->GetVisibleRect();
180 nsDisplayList
* list
= i
->GetList();
181 fprintf(aOutput
, "%s %p(%s) (%d,%d,%d,%d)(%d,%d,%d,%d)%s%s\n",
182 i
->Name(), (void*)f
, NS_ConvertUTF16toUTF8(fName
).get(),
183 rect
.x
, rect
.y
, rect
.width
, rect
.height
,
184 vis
.x
, vis
.y
, vis
.width
, vis
.height
,
185 ((!list
|| list
->DidComputeVisibility()) && i
->IsOpaque(aBuilder
)) ? " opaque" : "",
186 i
->IsUniform(aBuilder
, &color
) ? " uniform" : "");
188 PrintDisplayListTo(aBuilder
, *list
, aIndent
+ 4, aOutput
);
190 if (i
->GetType() == nsDisplayItem::TYPE_TRANSFORM
) {
191 nsDisplayTransform
* t
= static_cast<nsDisplayTransform
*>(i
);
192 PrintDisplayListTo(aBuilder
, *(t
->GetStoredList()->GetList()), aIndent
+ 4, aOutput
);
198 nsFrame::PrintDisplayList(nsDisplayListBuilder
* aBuilder
,
199 const nsDisplayList
& aList
)
201 PrintDisplayListTo(aBuilder
, aList
, 0, stderr
);