Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | /* |
michael@0 | 7 | * implementation of interface that allows layout-debug extension access |
michael@0 | 8 | * to some internals of layout |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | #include "nsILayoutDebugger.h" |
michael@0 | 12 | #include "nsFrame.h" |
michael@0 | 13 | #include "nsDisplayList.h" |
michael@0 | 14 | #include "FrameLayerBuilder.h" |
michael@0 | 15 | #include "nsPrintfCString.h" |
michael@0 | 16 | |
michael@0 | 17 | #include <stdio.h> |
michael@0 | 18 | |
michael@0 | 19 | using namespace mozilla; |
michael@0 | 20 | using namespace mozilla::layers; |
michael@0 | 21 | |
michael@0 | 22 | #ifdef DEBUG |
michael@0 | 23 | class nsLayoutDebugger : public nsILayoutDebugger { |
michael@0 | 24 | public: |
michael@0 | 25 | nsLayoutDebugger(); |
michael@0 | 26 | virtual ~nsLayoutDebugger(); |
michael@0 | 27 | |
michael@0 | 28 | NS_DECL_ISUPPORTS |
michael@0 | 29 | |
michael@0 | 30 | NS_IMETHOD SetShowFrameBorders(bool aEnable) MOZ_OVERRIDE; |
michael@0 | 31 | |
michael@0 | 32 | NS_IMETHOD GetShowFrameBorders(bool* aResult) MOZ_OVERRIDE; |
michael@0 | 33 | |
michael@0 | 34 | NS_IMETHOD SetShowEventTargetFrameBorder(bool aEnable) MOZ_OVERRIDE; |
michael@0 | 35 | |
michael@0 | 36 | NS_IMETHOD GetShowEventTargetFrameBorder(bool* aResult) MOZ_OVERRIDE; |
michael@0 | 37 | |
michael@0 | 38 | NS_IMETHOD GetContentSize(nsIDocument* aDocument, |
michael@0 | 39 | int32_t* aSizeInBytesResult) MOZ_OVERRIDE; |
michael@0 | 40 | |
michael@0 | 41 | NS_IMETHOD GetFrameSize(nsIPresShell* aPresentation, |
michael@0 | 42 | int32_t* aSizeInBytesResult) MOZ_OVERRIDE; |
michael@0 | 43 | |
michael@0 | 44 | NS_IMETHOD GetStyleSize(nsIPresShell* aPresentation, |
michael@0 | 45 | int32_t* aSizeInBytesResult) MOZ_OVERRIDE; |
michael@0 | 46 | |
michael@0 | 47 | }; |
michael@0 | 48 | |
michael@0 | 49 | nsresult |
michael@0 | 50 | NS_NewLayoutDebugger(nsILayoutDebugger** aResult) |
michael@0 | 51 | { |
michael@0 | 52 | NS_PRECONDITION(aResult, "null OUT ptr"); |
michael@0 | 53 | if (!aResult) { |
michael@0 | 54 | return NS_ERROR_NULL_POINTER; |
michael@0 | 55 | } |
michael@0 | 56 | nsLayoutDebugger* it = new nsLayoutDebugger(); |
michael@0 | 57 | return it->QueryInterface(NS_GET_IID(nsILayoutDebugger), (void**)aResult); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | nsLayoutDebugger::nsLayoutDebugger() |
michael@0 | 61 | { |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | nsLayoutDebugger::~nsLayoutDebugger() |
michael@0 | 65 | { |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | NS_IMPL_ISUPPORTS(nsLayoutDebugger, nsILayoutDebugger) |
michael@0 | 69 | |
michael@0 | 70 | NS_IMETHODIMP |
michael@0 | 71 | nsLayoutDebugger::SetShowFrameBorders(bool aEnable) |
michael@0 | 72 | { |
michael@0 | 73 | nsFrame::ShowFrameBorders(aEnable); |
michael@0 | 74 | return NS_OK; |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | NS_IMETHODIMP |
michael@0 | 78 | nsLayoutDebugger::GetShowFrameBorders(bool* aResult) |
michael@0 | 79 | { |
michael@0 | 80 | *aResult = nsFrame::GetShowFrameBorders(); |
michael@0 | 81 | return NS_OK; |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | NS_IMETHODIMP |
michael@0 | 85 | nsLayoutDebugger::SetShowEventTargetFrameBorder(bool aEnable) |
michael@0 | 86 | { |
michael@0 | 87 | nsFrame::ShowEventTargetFrameBorder(aEnable); |
michael@0 | 88 | return NS_OK; |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | NS_IMETHODIMP |
michael@0 | 92 | nsLayoutDebugger::GetShowEventTargetFrameBorder(bool* aResult) |
michael@0 | 93 | { |
michael@0 | 94 | *aResult = nsFrame::GetShowEventTargetFrameBorder(); |
michael@0 | 95 | return NS_OK; |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | NS_IMETHODIMP |
michael@0 | 99 | nsLayoutDebugger::GetContentSize(nsIDocument* aDocument, |
michael@0 | 100 | int32_t* aSizeInBytesResult) |
michael@0 | 101 | { |
michael@0 | 102 | *aSizeInBytesResult = 0; |
michael@0 | 103 | return NS_ERROR_FAILURE; |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | NS_IMETHODIMP |
michael@0 | 107 | nsLayoutDebugger::GetFrameSize(nsIPresShell* aPresentation, |
michael@0 | 108 | int32_t* aSizeInBytesResult) |
michael@0 | 109 | { |
michael@0 | 110 | *aSizeInBytesResult = 0; |
michael@0 | 111 | return NS_ERROR_FAILURE; |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | NS_IMETHODIMP |
michael@0 | 115 | nsLayoutDebugger::GetStyleSize(nsIPresShell* aPresentation, |
michael@0 | 116 | int32_t* aSizeInBytesResult) |
michael@0 | 117 | { |
michael@0 | 118 | *aSizeInBytesResult = 0; |
michael@0 | 119 | return NS_ERROR_FAILURE; |
michael@0 | 120 | } |
michael@0 | 121 | #endif |
michael@0 | 122 | |
michael@0 | 123 | #ifdef MOZ_DUMP_PAINTING |
michael@0 | 124 | static void |
michael@0 | 125 | PrintDisplayListTo(nsDisplayListBuilder* aBuilder, const nsDisplayList& aList, |
michael@0 | 126 | FILE* aOutput, uint32_t aIndent, bool aDumpHtml); |
michael@0 | 127 | |
michael@0 | 128 | static void |
michael@0 | 129 | PrintDisplayItemTo(nsDisplayListBuilder* aBuilder, nsDisplayItem* aItem, |
michael@0 | 130 | FILE* aOutput, uint32_t aIndent, bool aDumpSublist, bool aDumpHtml) |
michael@0 | 131 | { |
michael@0 | 132 | nsCString str; |
michael@0 | 133 | if (!aDumpHtml) { |
michael@0 | 134 | for (uint32_t indent = 0; indent < aIndent; indent++) { |
michael@0 | 135 | str += " "; |
michael@0 | 136 | } |
michael@0 | 137 | } |
michael@0 | 138 | nsIFrame* f = aItem->Frame(); |
michael@0 | 139 | nsAutoString fName; |
michael@0 | 140 | #ifdef DEBUG_FRAME_DUMP |
michael@0 | 141 | f->GetFrameName(fName); |
michael@0 | 142 | #endif |
michael@0 | 143 | bool snap; |
michael@0 | 144 | nsRect rect = aItem->GetBounds(aBuilder, &snap); |
michael@0 | 145 | nscolor color; |
michael@0 | 146 | nsRect vis = aItem->GetVisibleRect(); |
michael@0 | 147 | nsRect component = aItem->GetComponentAlphaBounds(aBuilder); |
michael@0 | 148 | nsDisplayList* list = aItem->GetChildren(); |
michael@0 | 149 | const DisplayItemClip& clip = aItem->GetClip(); |
michael@0 | 150 | nsRegion opaque; |
michael@0 | 151 | if (!list || list->DidComputeVisibility()) { |
michael@0 | 152 | opaque = aItem->GetOpaqueRegion(aBuilder, &snap); |
michael@0 | 153 | } |
michael@0 | 154 | if (aDumpHtml && aItem->Painted()) { |
michael@0 | 155 | nsCString string(aItem->Name()); |
michael@0 | 156 | string.Append("-"); |
michael@0 | 157 | string.AppendInt((uint64_t)aItem); |
michael@0 | 158 | str += nsPrintfCString("<a href=\"javascript:ViewImage('%s')\">", string.BeginReading()); |
michael@0 | 159 | } |
michael@0 | 160 | str += nsPrintfCString("%s %p(%s) bounds(%d,%d,%d,%d) visible(%d,%d,%d,%d) componentAlpha(%d,%d,%d,%d) clip(%s) %s", |
michael@0 | 161 | aItem->Name(), (void*)f, NS_ConvertUTF16toUTF8(fName).get(), |
michael@0 | 162 | rect.x, rect.y, rect.width, rect.height, |
michael@0 | 163 | vis.x, vis.y, vis.width, vis.height, |
michael@0 | 164 | component.x, component.y, component.width, component.height, |
michael@0 | 165 | clip.ToString().get(), |
michael@0 | 166 | aItem->IsUniform(aBuilder, &color) ? " uniform" : ""); |
michael@0 | 167 | nsRegionRectIterator iter(opaque); |
michael@0 | 168 | for (const nsRect* r = iter.Next(); r; r = iter.Next()) { |
michael@0 | 169 | str += nsPrintfCString(" (opaque %d,%d,%d,%d)", r->x, r->y, r->width, r->height); |
michael@0 | 170 | } |
michael@0 | 171 | aItem->WriteDebugInfo(str); |
michael@0 | 172 | if (aDumpHtml && aItem->Painted()) { |
michael@0 | 173 | str += "</a>"; |
michael@0 | 174 | } |
michael@0 | 175 | uint32_t key = aItem->GetPerFrameKey(); |
michael@0 | 176 | Layer* layer = mozilla::FrameLayerBuilder::GetDebugOldLayerFor(f, key); |
michael@0 | 177 | if (layer) { |
michael@0 | 178 | if (aDumpHtml) { |
michael@0 | 179 | str += nsPrintfCString(" <a href=\"#%p\">layer=%p</a>", layer, layer); |
michael@0 | 180 | } else { |
michael@0 | 181 | str += nsPrintfCString(" layer=%p", layer); |
michael@0 | 182 | } |
michael@0 | 183 | } |
michael@0 | 184 | if (aItem->GetType() == nsDisplayItem::TYPE_SVG_EFFECTS) { |
michael@0 | 185 | (static_cast<nsDisplaySVGEffects*>(aItem))->PrintEffects(str); |
michael@0 | 186 | } |
michael@0 | 187 | fprintf_stderr(aOutput, "%s\n", str.get()); |
michael@0 | 188 | if (aDumpSublist && list) { |
michael@0 | 189 | PrintDisplayListTo(aBuilder, *list, aOutput, aIndent+1, aDumpHtml); |
michael@0 | 190 | } |
michael@0 | 191 | } |
michael@0 | 192 | |
michael@0 | 193 | static void |
michael@0 | 194 | PrintDisplayListTo(nsDisplayListBuilder* aBuilder, const nsDisplayList& aList, |
michael@0 | 195 | FILE* aOutput, uint32_t aIndent, bool aDumpHtml) |
michael@0 | 196 | { |
michael@0 | 197 | if (aDumpHtml) { |
michael@0 | 198 | fprintf_stderr(aOutput, "<ul>"); |
michael@0 | 199 | } |
michael@0 | 200 | |
michael@0 | 201 | for (nsDisplayItem* i = aList.GetBottom(); i != nullptr; i = i->GetAbove()) { |
michael@0 | 202 | if (aDumpHtml) { |
michael@0 | 203 | fprintf_stderr(aOutput, "<li>"); |
michael@0 | 204 | } |
michael@0 | 205 | PrintDisplayItemTo(aBuilder, i, aOutput, aIndent, true, aDumpHtml); |
michael@0 | 206 | if (aDumpHtml) { |
michael@0 | 207 | fprintf_stderr(aOutput, "</li>"); |
michael@0 | 208 | } |
michael@0 | 209 | } |
michael@0 | 210 | |
michael@0 | 211 | if (aDumpHtml) { |
michael@0 | 212 | fprintf_stderr(aOutput, "</ul>"); |
michael@0 | 213 | } |
michael@0 | 214 | } |
michael@0 | 215 | |
michael@0 | 216 | void |
michael@0 | 217 | nsFrame::PrintDisplayItem(nsDisplayListBuilder* aBuilder, |
michael@0 | 218 | nsDisplayItem* aItem, |
michael@0 | 219 | FILE* aFile, |
michael@0 | 220 | bool aDumpSublist, |
michael@0 | 221 | bool aDumpHtml) |
michael@0 | 222 | { |
michael@0 | 223 | PrintDisplayItemTo(aBuilder, aItem, aFile, 0, aDumpSublist, aDumpHtml); |
michael@0 | 224 | } |
michael@0 | 225 | |
michael@0 | 226 | void |
michael@0 | 227 | nsFrame::PrintDisplayList(nsDisplayListBuilder* aBuilder, |
michael@0 | 228 | const nsDisplayList& aList, |
michael@0 | 229 | FILE* aFile, |
michael@0 | 230 | bool aDumpHtml) |
michael@0 | 231 | { |
michael@0 | 232 | PrintDisplayListTo(aBuilder, aList, aFile, 0, aDumpHtml); |
michael@0 | 233 | } |
michael@0 | 234 | |
michael@0 | 235 | static void |
michael@0 | 236 | PrintDisplayListSetItem(nsDisplayListBuilder* aBuilder, |
michael@0 | 237 | const char* aItemName, |
michael@0 | 238 | const nsDisplayList& aList, |
michael@0 | 239 | FILE* aFile, |
michael@0 | 240 | bool aDumpHtml) |
michael@0 | 241 | { |
michael@0 | 242 | if (aDumpHtml) { |
michael@0 | 243 | fprintf_stderr(aFile, "<li>"); |
michael@0 | 244 | } |
michael@0 | 245 | fprintf_stderr(aFile, "%s", aItemName); |
michael@0 | 246 | PrintDisplayListTo(aBuilder, aList, aFile, 0, aDumpHtml); |
michael@0 | 247 | if (aDumpHtml) { |
michael@0 | 248 | fprintf_stderr(aFile, "</li>"); |
michael@0 | 249 | } |
michael@0 | 250 | } |
michael@0 | 251 | |
michael@0 | 252 | void |
michael@0 | 253 | nsFrame::PrintDisplayListSet(nsDisplayListBuilder* aBuilder, |
michael@0 | 254 | const nsDisplayListSet& aSet, |
michael@0 | 255 | FILE *aFile, |
michael@0 | 256 | bool aDumpHtml) |
michael@0 | 257 | { |
michael@0 | 258 | if (aDumpHtml) { |
michael@0 | 259 | fprintf_stderr(aFile, "<ul>"); |
michael@0 | 260 | } |
michael@0 | 261 | PrintDisplayListSetItem(aBuilder, "[BorderBackground]", *(aSet.BorderBackground()), aFile, aDumpHtml); |
michael@0 | 262 | PrintDisplayListSetItem(aBuilder, "[BlockBorderBackgrounds]", *(aSet.BlockBorderBackgrounds()), aFile, aDumpHtml); |
michael@0 | 263 | PrintDisplayListSetItem(aBuilder, "[Floats]", *(aSet.Floats()), aFile, aDumpHtml); |
michael@0 | 264 | PrintDisplayListSetItem(aBuilder, "[PositionedDescendants]", *(aSet.PositionedDescendants()), aFile, aDumpHtml); |
michael@0 | 265 | PrintDisplayListSetItem(aBuilder, "[Outlines]", *(aSet.Outlines()), aFile, aDumpHtml); |
michael@0 | 266 | PrintDisplayListSetItem(aBuilder, "[Content]", *(aSet.Content()), aFile, aDumpHtml); |
michael@0 | 267 | if (aDumpHtml) { |
michael@0 | 268 | fprintf_stderr(aFile, "</ul>"); |
michael@0 | 269 | } |
michael@0 | 270 | } |
michael@0 | 271 | |
michael@0 | 272 | #endif |