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
|
|
|
|
|
|
|
/*
|
|
|
|
* rendering object for the point that anchors out-of-flow rendering
|
|
|
|
* objects such as floats and absolutely positioned elements
|
|
|
|
*/
|
|
|
|
|
2009-12-23 21:20:41 -08:00
|
|
|
#include "nsLayoutUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsPlaceholderFrame.h"
|
|
|
|
#include "nsLineLayout.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsPresContext.h"
|
2011-04-07 18:04:40 -07:00
|
|
|
#include "nsRenderingContext.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsFrameManager.h"
|
|
|
|
#include "nsDisplayList.h"
|
|
|
|
|
|
|
|
nsIFrame*
|
2009-11-16 13:00:07 -08:00
|
|
|
NS_NewPlaceholderFrame(nsIPresShell* aPresShell, nsStyleContext* aContext,
|
|
|
|
nsFrameState aTypeBit)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-11-16 13:00:07 -08:00
|
|
|
return new (aPresShell) nsPlaceholderFrame(aContext, aTypeBit);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsPlaceholderFrame)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsPlaceholderFrame::~nsPlaceholderFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
2011-04-07 18:04:40 -07:00
|
|
|
nsPlaceholderFrame::GetMinWidth(nsRenderingContext *aRenderingContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nscoord result = 0;
|
|
|
|
DISPLAY_MIN_WIDTH(this, result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
2011-04-07 18:04:40 -07:00
|
|
|
nsPlaceholderFrame::GetPrefWidth(nsRenderingContext *aRenderingContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nscoord result = 0;
|
|
|
|
DISPLAY_PREF_WIDTH(this, result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-06-21 05:37:35 -07:00
|
|
|
/* virtual */ nsSize
|
|
|
|
nsPlaceholderFrame::GetMinSize(nsBoxLayoutState& aBoxLayoutState)
|
|
|
|
{
|
|
|
|
nsSize size(0, 0);
|
|
|
|
DISPLAY_MIN_SIZE(this, size);
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nsSize
|
|
|
|
nsPlaceholderFrame::GetPrefSize(nsBoxLayoutState& aBoxLayoutState)
|
|
|
|
{
|
|
|
|
nsSize size(0, 0);
|
|
|
|
DISPLAY_PREF_SIZE(this, size);
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nsSize
|
|
|
|
nsPlaceholderFrame::GetMaxSize(nsBoxLayoutState& aBoxLayoutState)
|
|
|
|
{
|
|
|
|
nsSize size(NS_INTRINSICSIZE, NS_INTRINSICSIZE);
|
|
|
|
DISPLAY_MAX_SIZE(this, size);
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* virtual */ void
|
2011-04-07 18:04:40 -07:00
|
|
|
nsPlaceholderFrame::AddInlineMinWidth(nsRenderingContext *aRenderingContext,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame::InlineMinWidthData *aData)
|
|
|
|
{
|
|
|
|
// Override AddInlineMinWith so that *nothing* happens. In
|
|
|
|
// particular, we don't want to zero out |aData->trailingWhitespace|,
|
|
|
|
// since nsLineLayout skips placeholders when trimming trailing
|
|
|
|
// whitespace, and we don't want to set aData->skipWhitespace to
|
|
|
|
// false.
|
|
|
|
|
|
|
|
// ...but push floats onto the list
|
|
|
|
if (mOutOfFlowFrame->GetStyleDisplay()->mFloats != NS_STYLE_FLOAT_NONE)
|
|
|
|
aData->floats.AppendElement(mOutOfFlowFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ void
|
2011-04-07 18:04:40 -07:00
|
|
|
nsPlaceholderFrame::AddInlinePrefWidth(nsRenderingContext *aRenderingContext,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame::InlinePrefWidthData *aData)
|
|
|
|
{
|
|
|
|
// Override AddInlinePrefWith so that *nothing* happens. In
|
|
|
|
// particular, we don't want to zero out |aData->trailingWhitespace|,
|
|
|
|
// since nsLineLayout skips placeholders when trimming trailing
|
|
|
|
// whitespace, and we don't want to set aData->skipWhitespace to
|
|
|
|
// false.
|
|
|
|
|
|
|
|
// ...but push floats onto the list
|
|
|
|
if (mOutOfFlowFrame->GetStyleDisplay()->mFloats != NS_STYLE_FLOAT_NONE)
|
|
|
|
aData->floats.AppendElement(mOutOfFlowFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPlaceholderFrame::Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsPlaceholderFrame");
|
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
|
|
|
aDesiredSize.width = 0;
|
|
|
|
aDesiredSize.height = 0;
|
|
|
|
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-12-23 21:21:15 -08:00
|
|
|
nsPlaceholderFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-03-30 14:11:41 -07:00
|
|
|
nsIPresShell* shell = PresContext()->GetPresShell();
|
2009-12-23 21:20:41 -08:00
|
|
|
nsIFrame* oof = mOutOfFlowFrame;
|
|
|
|
if (oof) {
|
2012-03-26 11:27:37 -07:00
|
|
|
oof->InvalidateFrameSubtree();
|
2009-12-23 21:21:15 -08:00
|
|
|
// Unregister out-of-flow frame
|
2009-12-23 21:20:41 -08:00
|
|
|
shell->FrameManager()->UnregisterPlaceholderFrame(this);
|
2009-12-23 21:21:15 -08:00
|
|
|
mOutOfFlowFrame = nsnull;
|
|
|
|
// If aDestructRoot is not an ancestor of the out-of-flow frame,
|
|
|
|
// then call RemoveFrame on it here.
|
|
|
|
// Also destroy it here if it's a popup frame. (Bug 96291)
|
|
|
|
if (shell->FrameManager() &&
|
2010-08-19 06:38:00 -07:00
|
|
|
((GetStateBits() & PLACEHOLDER_FOR_POPUP) ||
|
2009-12-23 21:21:15 -08:00
|
|
|
!nsLayoutUtils::IsProperAncestorFrame(aDestructRoot, oof))) {
|
2011-08-24 13:54:30 -07:00
|
|
|
ChildListID listId = nsLayoutUtils::GetChildListNameFor(oof);
|
2012-03-26 11:27:37 -07:00
|
|
|
shell->FrameManager()->RemoveFrame(listId, oof, false);
|
2009-12-23 21:21:15 -08:00
|
|
|
}
|
|
|
|
// else oof will be destroyed by its parent
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-12-23 21:21:15 -08:00
|
|
|
nsFrame::DestroyFrom(aDestructRoot);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom*
|
|
|
|
nsPlaceholderFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::placeholderFrame;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
/* virtual */ bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsPlaceholderFrame::CanContinueTextRun() const
|
|
|
|
{
|
|
|
|
if (!mOutOfFlowFrame) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
// first-letter frames can continue text runs, and placeholders for floated
|
|
|
|
// first-letter frames can too
|
|
|
|
return mOutOfFlowFrame->CanContinueTextRun();
|
|
|
|
}
|
|
|
|
|
2011-09-12 09:08:07 -07:00
|
|
|
nsIFrame*
|
2012-02-15 01:28:21 -08:00
|
|
|
nsPlaceholderFrame::GetParentStyleContextFrame() const
|
2007-07-17 19:01:32 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(GetParent(), "How can we not have a parent here?");
|
|
|
|
|
|
|
|
// Lie about our pseudo so we can step out of all anon boxes and
|
|
|
|
// pseudo-elements. The other option would be to reimplement the
|
|
|
|
// {ib} split gunk here.
|
2011-09-12 09:08:07 -07:00
|
|
|
return CorrectStyleParentFrame(GetParent(), nsGkAtoms::placeholderFrame);
|
2007-07-17 19:01:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
static void
|
2011-04-07 18:04:40 -07:00
|
|
|
PaintDebugPlaceholder(nsIFrame* aFrame, nsRenderingContext* aCtx,
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsRect& aDirtyRect, nsPoint aPt)
|
|
|
|
{
|
|
|
|
aCtx->SetColor(NS_RGB(0, 255, 255));
|
|
|
|
nscoord x = nsPresContext::CSSPixelsToAppUnits(-5);
|
|
|
|
aCtx->FillRect(aPt.x + x, aPt.y,
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(13), nsPresContext::CSSPixelsToAppUnits(3));
|
|
|
|
nscoord y = nsPresContext::CSSPixelsToAppUnits(-10);
|
|
|
|
aCtx->FillRect(aPt.x, aPt.y + y,
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(3), nsPresContext::CSSPixelsToAppUnits(10));
|
|
|
|
}
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
#if defined(DEBUG) || (defined(MOZ_REFLOW_PERF_DSP) && defined(MOZ_REFLOW_PERF))
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPlaceholderFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
DO_GLOBAL_REFLOW_COUNT_DSP("nsPlaceholderFrame");
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (!GetShowFrameBorders())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
return aLists.Outlines()->AppendNewToTop(new (aBuilder)
|
2010-08-13 03:01:13 -07:00
|
|
|
nsDisplayGeneric(aBuilder, this, PaintDebugPlaceholder, "DebugPlaceholder",
|
2010-07-15 14:07:49 -07:00
|
|
|
nsDisplayItem::TYPE_DEBUG_PLACEHOLDER));
|
2007-03-22 10:30:00 -07:00
|
|
|
#else // DEBUG
|
|
|
|
return NS_OK;
|
|
|
|
#endif // DEBUG
|
|
|
|
}
|
|
|
|
#endif // DEBUG || (MOZ_REFLOW_PERF_DSP && MOZ_REFLOW_PERF)
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPlaceholderFrame::GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("Placeholder"), aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPlaceholderFrame::List(FILE* out, PRInt32 aIndent) const
|
|
|
|
{
|
|
|
|
IndentBy(out, aIndent);
|
|
|
|
ListTag(out);
|
|
|
|
#ifdef DEBUG_waterson
|
2007-07-08 00:08:04 -07:00
|
|
|
fprintf(out, " [parent=%p]", static_cast<void*>(mParent));
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
if (HasView()) {
|
|
|
|
fprintf(out, " [view=%p]", (void*)GetView());
|
|
|
|
}
|
|
|
|
fprintf(out, " {%d,%d,%d,%d}", mRect.x, mRect.y, mRect.width, mRect.height);
|
|
|
|
if (0 != mState) {
|
2011-12-19 19:46:39 -08:00
|
|
|
fprintf(out, " [state=%016llx]", (unsigned long long)mState);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
nsIFrame* prevInFlow = GetPrevInFlow();
|
|
|
|
nsIFrame* nextInFlow = GetNextInFlow();
|
|
|
|
if (nsnull != prevInFlow) {
|
2007-07-08 00:08:04 -07:00
|
|
|
fprintf(out, " prev-in-flow=%p", static_cast<void*>(prevInFlow));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (nsnull != nextInFlow) {
|
2007-07-08 00:08:04 -07:00
|
|
|
fprintf(out, " next-in-flow=%p", static_cast<void*>(nextInFlow));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-10-15 19:47:03 -07:00
|
|
|
if (nsnull != mContent) {
|
|
|
|
fprintf(out, " [content=%p]", static_cast<void*>(mContent));
|
|
|
|
}
|
2010-06-25 14:51:17 -07:00
|
|
|
if (nsnull != mStyleContext) {
|
|
|
|
fprintf(out, " [sc=%p]", static_cast<void*>(mStyleContext));
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mOutOfFlowFrame) {
|
|
|
|
fprintf(out, " outOfFlowFrame=");
|
|
|
|
nsFrame::ListTag(out, mOutOfFlowFrame);
|
|
|
|
}
|
|
|
|
fputs("\n", out);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|