layout/base/nsLayoutDebugger.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/base/nsLayoutDebugger.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,272 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/*
    1.10 + * implementation of interface that allows layout-debug extension access
    1.11 + * to some internals of layout
    1.12 + */
    1.13 +
    1.14 +#include "nsILayoutDebugger.h"
    1.15 +#include "nsFrame.h"
    1.16 +#include "nsDisplayList.h"
    1.17 +#include "FrameLayerBuilder.h"
    1.18 +#include "nsPrintfCString.h"
    1.19 +
    1.20 +#include <stdio.h>
    1.21 +
    1.22 +using namespace mozilla;
    1.23 +using namespace mozilla::layers;
    1.24 +
    1.25 +#ifdef DEBUG
    1.26 +class nsLayoutDebugger : public nsILayoutDebugger {
    1.27 +public:
    1.28 +  nsLayoutDebugger();
    1.29 +  virtual ~nsLayoutDebugger();
    1.30 +
    1.31 +  NS_DECL_ISUPPORTS
    1.32 +
    1.33 +  NS_IMETHOD SetShowFrameBorders(bool aEnable) MOZ_OVERRIDE;
    1.34 +
    1.35 +  NS_IMETHOD GetShowFrameBorders(bool* aResult) MOZ_OVERRIDE;
    1.36 +
    1.37 +  NS_IMETHOD SetShowEventTargetFrameBorder(bool aEnable) MOZ_OVERRIDE;
    1.38 +
    1.39 +  NS_IMETHOD GetShowEventTargetFrameBorder(bool* aResult) MOZ_OVERRIDE;
    1.40 +
    1.41 +  NS_IMETHOD GetContentSize(nsIDocument* aDocument,
    1.42 +                            int32_t* aSizeInBytesResult) MOZ_OVERRIDE;
    1.43 +
    1.44 +  NS_IMETHOD GetFrameSize(nsIPresShell* aPresentation,
    1.45 +                          int32_t* aSizeInBytesResult) MOZ_OVERRIDE;
    1.46 +
    1.47 +  NS_IMETHOD GetStyleSize(nsIPresShell* aPresentation,
    1.48 +                          int32_t* aSizeInBytesResult) MOZ_OVERRIDE;
    1.49 +
    1.50 +};
    1.51 +
    1.52 +nsresult
    1.53 +NS_NewLayoutDebugger(nsILayoutDebugger** aResult)
    1.54 +{
    1.55 +  NS_PRECONDITION(aResult, "null OUT ptr");
    1.56 +  if (!aResult) {
    1.57 +    return NS_ERROR_NULL_POINTER;
    1.58 +  }
    1.59 +  nsLayoutDebugger* it = new nsLayoutDebugger();
    1.60 +  return it->QueryInterface(NS_GET_IID(nsILayoutDebugger), (void**)aResult);
    1.61 +}
    1.62 +
    1.63 +nsLayoutDebugger::nsLayoutDebugger()
    1.64 +{
    1.65 +}
    1.66 +
    1.67 +nsLayoutDebugger::~nsLayoutDebugger()
    1.68 +{
    1.69 +}
    1.70 +
    1.71 +NS_IMPL_ISUPPORTS(nsLayoutDebugger, nsILayoutDebugger)
    1.72 +
    1.73 +NS_IMETHODIMP
    1.74 +nsLayoutDebugger::SetShowFrameBorders(bool aEnable)
    1.75 +{
    1.76 +  nsFrame::ShowFrameBorders(aEnable);
    1.77 +  return NS_OK;
    1.78 +}
    1.79 +
    1.80 +NS_IMETHODIMP
    1.81 +nsLayoutDebugger::GetShowFrameBorders(bool* aResult)
    1.82 +{
    1.83 +  *aResult = nsFrame::GetShowFrameBorders();
    1.84 +  return NS_OK;
    1.85 +}
    1.86 +
    1.87 +NS_IMETHODIMP
    1.88 +nsLayoutDebugger::SetShowEventTargetFrameBorder(bool aEnable)
    1.89 +{
    1.90 +  nsFrame::ShowEventTargetFrameBorder(aEnable);
    1.91 +  return NS_OK;
    1.92 +}
    1.93 +
    1.94 +NS_IMETHODIMP
    1.95 +nsLayoutDebugger::GetShowEventTargetFrameBorder(bool* aResult)
    1.96 +{
    1.97 +  *aResult = nsFrame::GetShowEventTargetFrameBorder();
    1.98 +  return NS_OK;
    1.99 +}
   1.100 +
   1.101 +NS_IMETHODIMP
   1.102 +nsLayoutDebugger::GetContentSize(nsIDocument* aDocument,
   1.103 +                                 int32_t* aSizeInBytesResult)
   1.104 +{
   1.105 +  *aSizeInBytesResult = 0;
   1.106 +  return NS_ERROR_FAILURE;
   1.107 +}
   1.108 +
   1.109 +NS_IMETHODIMP
   1.110 +nsLayoutDebugger::GetFrameSize(nsIPresShell* aPresentation,
   1.111 +                               int32_t* aSizeInBytesResult)
   1.112 +{
   1.113 +  *aSizeInBytesResult = 0;
   1.114 +  return NS_ERROR_FAILURE;
   1.115 +}
   1.116 +
   1.117 +NS_IMETHODIMP
   1.118 +nsLayoutDebugger::GetStyleSize(nsIPresShell* aPresentation,
   1.119 +                               int32_t* aSizeInBytesResult)
   1.120 +{
   1.121 +  *aSizeInBytesResult = 0;
   1.122 +  return NS_ERROR_FAILURE;
   1.123 +}
   1.124 +#endif
   1.125 +
   1.126 +#ifdef MOZ_DUMP_PAINTING
   1.127 +static void
   1.128 +PrintDisplayListTo(nsDisplayListBuilder* aBuilder, const nsDisplayList& aList,
   1.129 +                   FILE* aOutput, uint32_t aIndent, bool aDumpHtml);
   1.130 +
   1.131 +static void
   1.132 +PrintDisplayItemTo(nsDisplayListBuilder* aBuilder, nsDisplayItem* aItem,
   1.133 +                   FILE* aOutput, uint32_t aIndent, bool aDumpSublist, bool aDumpHtml)
   1.134 +{
   1.135 +  nsCString str;
   1.136 +  if (!aDumpHtml) {
   1.137 +    for (uint32_t indent = 0; indent < aIndent; indent++) {
   1.138 +      str += "  ";
   1.139 +    }
   1.140 +  }
   1.141 +  nsIFrame* f = aItem->Frame();
   1.142 +  nsAutoString fName;
   1.143 +#ifdef DEBUG_FRAME_DUMP
   1.144 +  f->GetFrameName(fName);
   1.145 +#endif
   1.146 +  bool snap;
   1.147 +  nsRect rect = aItem->GetBounds(aBuilder, &snap);
   1.148 +  nscolor color;
   1.149 +  nsRect vis = aItem->GetVisibleRect();
   1.150 +  nsRect component = aItem->GetComponentAlphaBounds(aBuilder);
   1.151 +  nsDisplayList* list = aItem->GetChildren();
   1.152 +  const DisplayItemClip& clip = aItem->GetClip();
   1.153 +  nsRegion opaque;
   1.154 +  if (!list || list->DidComputeVisibility()) {
   1.155 +    opaque = aItem->GetOpaqueRegion(aBuilder, &snap);
   1.156 +  }
   1.157 +  if (aDumpHtml && aItem->Painted()) {
   1.158 +    nsCString string(aItem->Name());
   1.159 +    string.Append("-");
   1.160 +    string.AppendInt((uint64_t)aItem);
   1.161 +    str += nsPrintfCString("<a href=\"javascript:ViewImage('%s')\">", string.BeginReading());
   1.162 +  }
   1.163 +  str += nsPrintfCString("%s %p(%s) bounds(%d,%d,%d,%d) visible(%d,%d,%d,%d) componentAlpha(%d,%d,%d,%d) clip(%s) %s",
   1.164 +          aItem->Name(), (void*)f, NS_ConvertUTF16toUTF8(fName).get(),
   1.165 +          rect.x, rect.y, rect.width, rect.height,
   1.166 +          vis.x, vis.y, vis.width, vis.height,
   1.167 +          component.x, component.y, component.width, component.height,
   1.168 +          clip.ToString().get(),
   1.169 +          aItem->IsUniform(aBuilder, &color) ? " uniform" : "");
   1.170 +  nsRegionRectIterator iter(opaque);
   1.171 +  for (const nsRect* r = iter.Next(); r; r = iter.Next()) {
   1.172 +    str += nsPrintfCString(" (opaque %d,%d,%d,%d)", r->x, r->y, r->width, r->height);
   1.173 +  }
   1.174 +  aItem->WriteDebugInfo(str);
   1.175 +  if (aDumpHtml && aItem->Painted()) {
   1.176 +    str += "</a>";
   1.177 +  }
   1.178 +  uint32_t key = aItem->GetPerFrameKey();
   1.179 +  Layer* layer = mozilla::FrameLayerBuilder::GetDebugOldLayerFor(f, key);
   1.180 +  if (layer) {
   1.181 +    if (aDumpHtml) {
   1.182 +      str += nsPrintfCString(" <a href=\"#%p\">layer=%p</a>", layer, layer);
   1.183 +    } else {
   1.184 +      str += nsPrintfCString(" layer=%p", layer);
   1.185 +    }
   1.186 +  }
   1.187 +  if (aItem->GetType() == nsDisplayItem::TYPE_SVG_EFFECTS) {
   1.188 +    (static_cast<nsDisplaySVGEffects*>(aItem))->PrintEffects(str);
   1.189 +  }
   1.190 +  fprintf_stderr(aOutput, "%s\n", str.get());
   1.191 +  if (aDumpSublist && list) {
   1.192 +    PrintDisplayListTo(aBuilder, *list, aOutput, aIndent+1, aDumpHtml);
   1.193 +  }
   1.194 +}
   1.195 +
   1.196 +static void
   1.197 +PrintDisplayListTo(nsDisplayListBuilder* aBuilder, const nsDisplayList& aList,
   1.198 +                   FILE* aOutput, uint32_t aIndent, bool aDumpHtml)
   1.199 +{
   1.200 +  if (aDumpHtml) {
   1.201 +    fprintf_stderr(aOutput, "<ul>");
   1.202 +  }
   1.203 +
   1.204 +  for (nsDisplayItem* i = aList.GetBottom(); i != nullptr; i = i->GetAbove()) {
   1.205 +    if (aDumpHtml) {
   1.206 +      fprintf_stderr(aOutput, "<li>");
   1.207 +    }
   1.208 +    PrintDisplayItemTo(aBuilder, i, aOutput, aIndent, true, aDumpHtml);
   1.209 +    if (aDumpHtml) {
   1.210 +      fprintf_stderr(aOutput, "</li>");
   1.211 +    }
   1.212 +  }
   1.213 +
   1.214 +  if (aDumpHtml) {
   1.215 +    fprintf_stderr(aOutput, "</ul>");
   1.216 +  }
   1.217 +}
   1.218 +
   1.219 +void
   1.220 +nsFrame::PrintDisplayItem(nsDisplayListBuilder* aBuilder,
   1.221 +                          nsDisplayItem* aItem,
   1.222 +                          FILE* aFile,
   1.223 +                          bool aDumpSublist,
   1.224 +                          bool aDumpHtml)
   1.225 +{
   1.226 +  PrintDisplayItemTo(aBuilder, aItem, aFile, 0, aDumpSublist, aDumpHtml);
   1.227 +}
   1.228 +
   1.229 +void
   1.230 +nsFrame::PrintDisplayList(nsDisplayListBuilder* aBuilder,
   1.231 +                          const nsDisplayList& aList,
   1.232 +                          FILE* aFile,
   1.233 +                          bool aDumpHtml)
   1.234 +{
   1.235 +  PrintDisplayListTo(aBuilder, aList, aFile, 0, aDumpHtml);
   1.236 +}
   1.237 +
   1.238 +static void
   1.239 +PrintDisplayListSetItem(nsDisplayListBuilder* aBuilder,
   1.240 +                        const char* aItemName,
   1.241 +                        const nsDisplayList& aList,
   1.242 +                        FILE* aFile,
   1.243 +                        bool aDumpHtml)
   1.244 +{
   1.245 +  if (aDumpHtml) {
   1.246 +    fprintf_stderr(aFile, "<li>");
   1.247 +  }
   1.248 +  fprintf_stderr(aFile, "%s", aItemName);
   1.249 +  PrintDisplayListTo(aBuilder, aList, aFile, 0, aDumpHtml);
   1.250 +  if (aDumpHtml) {
   1.251 +    fprintf_stderr(aFile, "</li>");
   1.252 +  }
   1.253 +}
   1.254 +
   1.255 +void
   1.256 +nsFrame::PrintDisplayListSet(nsDisplayListBuilder* aBuilder,
   1.257 +                             const nsDisplayListSet& aSet,
   1.258 +                             FILE *aFile,
   1.259 +                             bool aDumpHtml)
   1.260 +{
   1.261 +  if (aDumpHtml) {
   1.262 +    fprintf_stderr(aFile, "<ul>");
   1.263 +  }
   1.264 +  PrintDisplayListSetItem(aBuilder, "[BorderBackground]", *(aSet.BorderBackground()), aFile, aDumpHtml);
   1.265 +  PrintDisplayListSetItem(aBuilder, "[BlockBorderBackgrounds]", *(aSet.BlockBorderBackgrounds()), aFile, aDumpHtml);
   1.266 +  PrintDisplayListSetItem(aBuilder, "[Floats]", *(aSet.Floats()), aFile, aDumpHtml);
   1.267 +  PrintDisplayListSetItem(aBuilder, "[PositionedDescendants]", *(aSet.PositionedDescendants()), aFile, aDumpHtml);
   1.268 +  PrintDisplayListSetItem(aBuilder, "[Outlines]", *(aSet.Outlines()), aFile, aDumpHtml);
   1.269 +  PrintDisplayListSetItem(aBuilder, "[Content]", *(aSet.Content()), aFile, aDumpHtml);
   1.270 +  if (aDumpHtml) {
   1.271 +    fprintf_stderr(aFile, "</ul>");
   1.272 +  }
   1.273 +}
   1.274 +
   1.275 +#endif

mercurial