2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* implementation of interface that allows layout-debug extension access
|
|
|
|
* to some internals of layout
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsILayoutDebugger.h"
|
2009-08-20 14:52:48 -07:00
|
|
|
#include "nsFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsDisplayList.h"
|
2011-01-03 19:56:57 -08:00
|
|
|
#include "FrameLayerBuilder.h"
|
2014-01-26 14:07:08 -08:00
|
|
|
#include "nsPrintfCString.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2013-03-04 01:56:02 -08:00
|
|
|
using namespace mozilla;
|
2011-01-03 19:56:57 -08:00
|
|
|
using namespace mozilla::layers;
|
|
|
|
|
2012-06-25 12:59:42 -07:00
|
|
|
#ifdef DEBUG
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsLayoutDebugger : public nsILayoutDebugger {
|
|
|
|
public:
|
|
|
|
nsLayoutDebugger();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2014-02-24 06:41:56 -08:00
|
|
|
NS_IMETHOD SetShowFrameBorders(bool aEnable) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-24 06:41:56 -08:00
|
|
|
NS_IMETHOD GetShowFrameBorders(bool* aResult) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-24 06:41:56 -08:00
|
|
|
NS_IMETHOD SetShowEventTargetFrameBorder(bool aEnable) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-24 06:41:56 -08:00
|
|
|
NS_IMETHOD GetShowEventTargetFrameBorder(bool* aResult) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHOD GetContentSize(nsIDocument* aDocument,
|
2014-02-24 06:41:56 -08:00
|
|
|
int32_t* aSizeInBytesResult) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHOD GetFrameSize(nsIPresShell* aPresentation,
|
2014-02-24 06:41:56 -08:00
|
|
|
int32_t* aSizeInBytesResult) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHOD GetStyleSize(nsIPresShell* aPresentation,
|
2014-02-24 06:41:56 -08:00
|
|
|
int32_t* aSizeInBytesResult) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-06-23 15:40:01 -07:00
|
|
|
protected:
|
|
|
|
virtual ~nsLayoutDebugger();
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewLayoutDebugger(nsILayoutDebugger** aResult)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aResult, "null OUT ptr");
|
|
|
|
if (!aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
nsLayoutDebugger* it = new nsLayoutDebugger();
|
|
|
|
return it->QueryInterface(NS_GET_IID(nsILayoutDebugger), (void**)aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsLayoutDebugger::nsLayoutDebugger()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsLayoutDebugger::~nsLayoutDebugger()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(nsLayoutDebugger, nsILayoutDebugger)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsLayoutDebugger::SetShowFrameBorders(bool aEnable)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-08-20 14:52:48 -07:00
|
|
|
nsFrame::ShowFrameBorders(aEnable);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsLayoutDebugger::GetShowFrameBorders(bool* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-08-20 14:52:48 -07:00
|
|
|
*aResult = nsFrame::GetShowFrameBorders();
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsLayoutDebugger::SetShowEventTargetFrameBorder(bool aEnable)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-08-20 14:52:48 -07:00
|
|
|
nsFrame::ShowEventTargetFrameBorder(aEnable);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsLayoutDebugger::GetShowEventTargetFrameBorder(bool* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-08-20 14:52:48 -07:00
|
|
|
*aResult = nsFrame::GetShowEventTargetFrameBorder();
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLayoutDebugger::GetContentSize(nsIDocument* aDocument,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t* aSizeInBytesResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*aSizeInBytesResult = 0;
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLayoutDebugger::GetFrameSize(nsIPresShell* aPresentation,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t* aSizeInBytesResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*aSizeInBytesResult = 0;
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLayoutDebugger::GetStyleSize(nsIPresShell* aPresentation,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t* aSizeInBytesResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*aSizeInBytesResult = 0;
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2011-11-16 19:44:16 -08:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-11-16 19:44:16 -08:00
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
2014-06-19 15:36:25 -07:00
|
|
|
std::ostream& operator<<(std::ostream& os, const nsPrintfCString& rhs) {
|
|
|
|
os << rhs.get();
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:09:14 -08:00
|
|
|
static void
|
|
|
|
PrintDisplayListTo(nsDisplayListBuilder* aBuilder, const nsDisplayList& aList,
|
2014-06-19 15:36:25 -07:00
|
|
|
std::stringstream& aStream, uint32_t aIndent, bool aDumpHtml);
|
2014-01-26 14:09:14 -08:00
|
|
|
|
|
|
|
static void
|
|
|
|
PrintDisplayItemTo(nsDisplayListBuilder* aBuilder, nsDisplayItem* aItem,
|
2014-06-19 15:36:25 -07:00
|
|
|
std::stringstream& aStream, uint32_t aIndent, bool aDumpSublist, bool aDumpHtml)
|
2014-01-26 14:09:14 -08:00
|
|
|
{
|
2014-06-19 15:36:25 -07:00
|
|
|
std::stringstream ss;
|
|
|
|
|
2014-01-26 14:09:14 -08:00
|
|
|
if (!aDumpHtml) {
|
|
|
|
for (uint32_t indent = 0; indent < aIndent; indent++) {
|
2014-06-19 15:36:25 -07:00
|
|
|
aStream << " ";
|
2014-01-26 14:09:14 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
nsIFrame* f = aItem->Frame();
|
|
|
|
nsAutoString fName;
|
2014-03-02 14:22:29 -08:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-01-26 14:09:14 -08:00
|
|
|
f->GetFrameName(fName);
|
|
|
|
#endif
|
|
|
|
bool snap;
|
|
|
|
nsRect rect = aItem->GetBounds(aBuilder, &snap);
|
2014-12-18 10:32:51 -08:00
|
|
|
nsRect layerRect = rect -
|
|
|
|
nsLayoutUtils::GetAnimatedGeometryRootFor(aItem, aBuilder, nullptr)->
|
|
|
|
GetOffsetToCrossDoc(aItem->ReferenceFrame());
|
2014-01-26 14:09:14 -08:00
|
|
|
nscolor color;
|
|
|
|
nsRect vis = aItem->GetVisibleRect();
|
|
|
|
nsRect component = aItem->GetComponentAlphaBounds(aBuilder);
|
|
|
|
nsDisplayList* list = aItem->GetChildren();
|
|
|
|
const DisplayItemClip& clip = aItem->GetClip();
|
2014-06-08 21:48:01 -07:00
|
|
|
nsRegion opaque = aItem->GetOpaqueRegion(aBuilder, &snap);
|
2014-01-26 14:09:14 -08:00
|
|
|
if (aDumpHtml && aItem->Painted()) {
|
|
|
|
nsCString string(aItem->Name());
|
2014-05-21 20:48:52 -07:00
|
|
|
string.Append('-');
|
2014-01-26 14:09:14 -08:00
|
|
|
string.AppendInt((uint64_t)aItem);
|
2014-06-19 15:36:25 -07:00
|
|
|
aStream << nsPrintfCString("<a href=\"javascript:ViewImage('%s')\">", string.BeginReading());
|
2014-01-26 14:09:14 -08:00
|
|
|
}
|
2014-12-18 10:32:51 -08:00
|
|
|
aStream << nsPrintfCString("%s p=0x%p f=0x%p(%s) %sbounds(%d,%d,%d,%d) layerBounds(%d,%d,%d,%d) visible(%d,%d,%d,%d) componentAlpha(%d,%d,%d,%d) clip(%s) %s",
|
2014-07-09 12:11:51 -07:00
|
|
|
aItem->Name(), aItem, (void*)f, NS_ConvertUTF16toUTF8(fName).get(),
|
2014-07-23 18:50:26 -07:00
|
|
|
(aItem->ZIndex() ? nsPrintfCString("z=%d ", aItem->ZIndex()).get() : ""),
|
2014-01-26 14:09:14 -08:00
|
|
|
rect.x, rect.y, rect.width, rect.height,
|
2014-12-18 10:32:51 -08:00
|
|
|
layerRect.x, layerRect.y, layerRect.width, layerRect.height,
|
2014-01-26 14:09:14 -08:00
|
|
|
vis.x, vis.y, vis.width, vis.height,
|
|
|
|
component.x, component.y, component.width, component.height,
|
|
|
|
clip.ToString().get(),
|
|
|
|
aItem->IsUniform(aBuilder, &color) ? " uniform" : "");
|
2014-06-13 08:32:15 -07:00
|
|
|
|
2014-01-26 14:09:14 -08:00
|
|
|
nsRegionRectIterator iter(opaque);
|
|
|
|
for (const nsRect* r = iter.Next(); r; r = iter.Next()) {
|
2014-06-19 15:36:25 -07:00
|
|
|
aStream << nsPrintfCString(" (opaque %d,%d,%d,%d)", r->x, r->y, r->width, r->height);
|
2014-01-26 14:09:14 -08:00
|
|
|
}
|
2014-06-13 08:32:15 -07:00
|
|
|
|
2014-08-04 20:25:00 -07:00
|
|
|
if (aItem->ShouldFixToViewport(nullptr)) {
|
2014-07-25 01:37:50 -07:00
|
|
|
aStream << " fixed";
|
|
|
|
}
|
|
|
|
|
2014-06-13 08:32:15 -07:00
|
|
|
if (aItem->Frame()->StyleDisplay()->mWillChange.Length() > 0) {
|
2014-06-19 15:36:25 -07:00
|
|
|
aStream << " (will-change=";
|
2014-06-13 08:32:15 -07:00
|
|
|
for (size_t i = 0; i < aItem->Frame()->StyleDisplay()->mWillChange.Length(); i++) {
|
|
|
|
if (i > 0) {
|
2014-06-19 15:36:25 -07:00
|
|
|
aStream << ",";
|
2014-06-13 08:32:15 -07:00
|
|
|
}
|
2014-06-19 15:36:25 -07:00
|
|
|
aStream << NS_LossyConvertUTF16toASCII(aItem->Frame()->StyleDisplay()->mWillChange[i]).get();
|
2014-06-13 08:32:15 -07:00
|
|
|
}
|
2014-06-19 15:36:25 -07:00
|
|
|
aStream << ")";
|
2014-06-13 08:32:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Display item specific debug info
|
2014-11-25 05:45:19 -08:00
|
|
|
aItem->WriteDebugInfo(aStream);
|
2014-06-13 08:32:15 -07:00
|
|
|
|
2014-01-26 14:09:14 -08:00
|
|
|
if (aDumpHtml && aItem->Painted()) {
|
2014-06-19 15:36:25 -07:00
|
|
|
aStream << "</a>";
|
2014-01-26 14:09:14 -08:00
|
|
|
}
|
|
|
|
uint32_t key = aItem->GetPerFrameKey();
|
|
|
|
Layer* layer = mozilla::FrameLayerBuilder::GetDebugOldLayerFor(f, key);
|
|
|
|
if (layer) {
|
|
|
|
if (aDumpHtml) {
|
2014-06-19 15:36:25 -07:00
|
|
|
aStream << nsPrintfCString(" <a href=\"#%p\">layer=%p</a>", layer, layer);
|
2014-01-26 14:09:14 -08:00
|
|
|
} else {
|
2014-07-09 12:11:51 -07:00
|
|
|
aStream << nsPrintfCString(" layer=0x%p", layer);
|
2014-01-26 14:09:14 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (aItem->GetType() == nsDisplayItem::TYPE_SVG_EFFECTS) {
|
2014-06-19 15:36:25 -07:00
|
|
|
nsCString str;
|
2014-01-26 14:09:14 -08:00
|
|
|
(static_cast<nsDisplaySVGEffects*>(aItem))->PrintEffects(str);
|
2014-06-19 15:36:25 -07:00
|
|
|
aStream << str.get();
|
2014-01-26 14:09:14 -08:00
|
|
|
}
|
2014-06-19 15:36:25 -07:00
|
|
|
aStream << "\n";
|
|
|
|
|
2014-01-26 14:09:14 -08:00
|
|
|
if (aDumpSublist && list) {
|
2014-06-19 15:36:25 -07:00
|
|
|
PrintDisplayListTo(aBuilder, *list, aStream, aIndent+1, aDumpHtml);
|
2014-01-26 14:09:14 -08:00
|
|
|
}
|
|
|
|
}
|
2012-08-07 10:57:26 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static void
|
|
|
|
PrintDisplayListTo(nsDisplayListBuilder* aBuilder, const nsDisplayList& aList,
|
2014-06-19 15:36:25 -07:00
|
|
|
std::stringstream& aStream, uint32_t aIndent, bool aDumpHtml)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-07 10:57:26 -07:00
|
|
|
if (aDumpHtml) {
|
2014-06-19 15:36:25 -07:00
|
|
|
aStream << "<ul>";
|
2012-08-07 10:57:26 -07:00
|
|
|
}
|
2012-03-01 00:26:09 -08:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
for (nsDisplayItem* i = aList.GetBottom(); i != nullptr; i = i->GetAbove()) {
|
2012-08-07 10:57:26 -07:00
|
|
|
if (aDumpHtml) {
|
2014-06-19 15:36:25 -07:00
|
|
|
aStream << "<li>";
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-06-19 15:36:25 -07:00
|
|
|
PrintDisplayItemTo(aBuilder, i, aStream, aIndent, true, aDumpHtml);
|
2012-08-07 10:57:26 -07:00
|
|
|
if (aDumpHtml) {
|
2014-06-19 15:36:25 -07:00
|
|
|
aStream << "</li>";
|
2012-08-07 10:57:26 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aDumpHtml) {
|
2014-06-19 15:36:25 -07:00
|
|
|
aStream << "</ul>";
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:09:14 -08:00
|
|
|
void
|
|
|
|
nsFrame::PrintDisplayItem(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayItem* aItem,
|
2014-06-19 15:36:25 -07:00
|
|
|
std::stringstream& aStream,
|
2014-01-26 14:09:14 -08:00
|
|
|
bool aDumpSublist,
|
|
|
|
bool aDumpHtml)
|
|
|
|
{
|
2014-06-19 15:36:25 -07:00
|
|
|
PrintDisplayItemTo(aBuilder, aItem, aStream, 0, aDumpSublist, aDumpHtml);
|
2014-01-26 14:09:14 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
2009-08-20 14:52:48 -07:00
|
|
|
nsFrame::PrintDisplayList(nsDisplayListBuilder* aBuilder,
|
2012-03-01 00:26:09 -08:00
|
|
|
const nsDisplayList& aList,
|
2014-06-19 15:36:25 -07:00
|
|
|
std::stringstream& aStream,
|
2012-08-07 10:57:26 -07:00
|
|
|
bool aDumpHtml)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-06-19 15:36:25 -07:00
|
|
|
PrintDisplayListTo(aBuilder, aList, aStream, 0, aDumpHtml);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-12-12 10:27:07 -08:00
|
|
|
static void
|
|
|
|
PrintDisplayListSetItem(nsDisplayListBuilder* aBuilder,
|
|
|
|
const char* aItemName,
|
|
|
|
const nsDisplayList& aList,
|
2014-06-19 15:36:25 -07:00
|
|
|
std::stringstream& aStream,
|
2013-12-12 10:27:07 -08:00
|
|
|
bool aDumpHtml)
|
|
|
|
{
|
|
|
|
if (aDumpHtml) {
|
2014-06-19 15:36:25 -07:00
|
|
|
aStream << "<li>";
|
2013-12-12 10:27:07 -08:00
|
|
|
}
|
2014-07-23 18:50:26 -07:00
|
|
|
aStream << aItemName << "\n";
|
2014-06-19 15:36:25 -07:00
|
|
|
PrintDisplayListTo(aBuilder, aList, aStream, 0, aDumpHtml);
|
2013-12-12 10:27:07 -08:00
|
|
|
if (aDumpHtml) {
|
2014-06-19 15:36:25 -07:00
|
|
|
aStream << "</li>";
|
2013-12-12 10:27:07 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFrame::PrintDisplayListSet(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayListSet& aSet,
|
2014-06-19 15:36:25 -07:00
|
|
|
std::stringstream& aStream,
|
2013-12-12 10:27:07 -08:00
|
|
|
bool aDumpHtml)
|
|
|
|
{
|
|
|
|
if (aDumpHtml) {
|
2014-06-19 15:36:25 -07:00
|
|
|
aStream << "<ul>";
|
2013-12-12 10:27:07 -08:00
|
|
|
}
|
2014-06-19 15:36:25 -07:00
|
|
|
PrintDisplayListSetItem(aBuilder, "[BorderBackground]", *(aSet.BorderBackground()), aStream, aDumpHtml);
|
|
|
|
PrintDisplayListSetItem(aBuilder, "[BlockBorderBackgrounds]", *(aSet.BlockBorderBackgrounds()), aStream, aDumpHtml);
|
|
|
|
PrintDisplayListSetItem(aBuilder, "[Floats]", *(aSet.Floats()), aStream, aDumpHtml);
|
|
|
|
PrintDisplayListSetItem(aBuilder, "[PositionedDescendants]", *(aSet.PositionedDescendants()), aStream, aDumpHtml);
|
|
|
|
PrintDisplayListSetItem(aBuilder, "[Outlines]", *(aSet.Outlines()), aStream, aDumpHtml);
|
|
|
|
PrintDisplayListSetItem(aBuilder, "[Content]", *(aSet.Content()), aStream, aDumpHtml);
|
2013-12-12 10:27:07 -08:00
|
|
|
if (aDumpHtml) {
|
2014-06-19 15:36:25 -07:00
|
|
|
aStream << "</ul>";
|
2013-12-12 10:27:07 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|