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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsPlaceholderFrame.h"
|
2013-02-10 18:28:50 -08:00
|
|
|
|
|
|
|
#include "nsDisplayList.h"
|
|
|
|
#include "nsFrameManager.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsPresContext.h"
|
2011-04-07 18:04:40 -07:00
|
|
|
#include "nsRenderingContext.h"
|
2013-10-01 14:00:38 -07:00
|
|
|
#include "nsIFrameInlines.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2014-01-17 23:08:22 -08:00
|
|
|
#ifdef DEBUG
|
|
|
|
NS_QUERYFRAME_HEAD(nsPlaceholderFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsPlaceholderFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsFrame)
|
|
|
|
#endif
|
|
|
|
|
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
|
2014-07-24 10:03:25 -07:00
|
|
|
nsPlaceholderFrame::AddInlineMinISize(nsRenderingContext* aRenderingContext,
|
|
|
|
nsIFrame::InlineMinISizeData* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// 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
|
2012-08-10 04:16:52 -07:00
|
|
|
if (mOutOfFlowFrame->IsFloating()) {
|
|
|
|
nscoord floatWidth =
|
|
|
|
nsLayoutUtils::IntrinsicForContainer(aRenderingContext,
|
|
|
|
mOutOfFlowFrame,
|
|
|
|
nsLayoutUtils::MIN_WIDTH);
|
|
|
|
aData->floats.AppendElement(
|
2014-07-24 10:03:25 -07:00
|
|
|
InlineIntrinsicISizeData::FloatInfo(mOutOfFlowFrame, floatWidth));
|
2012-08-10 04:16:52 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ void
|
2014-07-24 10:03:25 -07:00
|
|
|
nsPlaceholderFrame::AddInlinePrefISize(nsRenderingContext* aRenderingContext,
|
|
|
|
nsIFrame::InlinePrefISizeData* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// 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
|
2012-08-10 04:16:52 -07:00
|
|
|
if (mOutOfFlowFrame->IsFloating()) {
|
|
|
|
nscoord floatWidth =
|
|
|
|
nsLayoutUtils::IntrinsicForContainer(aRenderingContext,
|
|
|
|
mOutOfFlowFrame,
|
|
|
|
nsLayoutUtils::PREF_WIDTH);
|
|
|
|
aData->floats.AppendElement(
|
2014-07-24 10:03:25 -07:00
|
|
|
InlineIntrinsicISizeData::FloatInfo(mOutOfFlowFrame, floatWidth));
|
2012-08-10 04:16:52 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-05-12 17:47:52 -07:00
|
|
|
void
|
2013-02-10 18:28:50 -08:00
|
|
|
nsPlaceholderFrame::Reflow(nsPresContext* aPresContext,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
2013-05-21 09:15:57 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
// We should be getting reflowed before our out-of-flow.
|
|
|
|
// If this is our first reflow, and our out-of-flow has already received its
|
|
|
|
// first reflow (before us), complain.
|
|
|
|
// XXXdholbert This "look for a previous continuation or IB-split sibling"
|
2014-02-06 17:45:31 -08:00
|
|
|
// code could use nsLayoutUtils::GetPrevContinuationOrIBSplitSibling(), if
|
2013-05-21 09:15:57 -07:00
|
|
|
// we ever add a function like that. (We currently have a "Next" version.)
|
|
|
|
if ((GetStateBits() & NS_FRAME_FIRST_REFLOW) &&
|
|
|
|
!(mOutOfFlowFrame->GetStateBits() & NS_FRAME_FIRST_REFLOW)) {
|
|
|
|
|
|
|
|
// Unfortunately, this can currently happen when the placeholder is in a
|
|
|
|
// later continuation or later IB-split sibling than its out-of-flow (as
|
|
|
|
// is the case in some of our existing unit tests). So for now, in that
|
|
|
|
// case, we'll warn instead of asserting.
|
|
|
|
bool isInContinuationOrIBSplit = false;
|
|
|
|
nsIFrame* ancestor = this;
|
|
|
|
while ((ancestor = ancestor->GetParent())) {
|
|
|
|
if (ancestor->GetPrevContinuation() ||
|
2014-02-06 17:45:31 -08:00
|
|
|
ancestor->Properties().Get(IBSplitPrevSibling())) {
|
2013-05-21 09:15:57 -07:00
|
|
|
isInContinuationOrIBSplit = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isInContinuationOrIBSplit) {
|
|
|
|
NS_WARNING("Out-of-flow frame got reflowed before its placeholder");
|
|
|
|
} else {
|
|
|
|
NS_ERROR("Out-of-flow frame got reflowed before its placeholder");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsPlaceholderFrame");
|
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
2014-07-24 01:30:07 -07:00
|
|
|
aDesiredSize.ClearSize();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-12-23 21:21:15 -08:00
|
|
|
nsPlaceholderFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-12-23 21:20:41 -08:00
|
|
|
nsIFrame* oof = mOutOfFlowFrame;
|
|
|
|
if (oof) {
|
2009-12-23 21:21:15 -08:00
|
|
|
// Unregister out-of-flow frame
|
2013-02-10 18:28:50 -08:00
|
|
|
nsFrameManager* fm = PresContext()->GetPresShell()->FrameManager();
|
|
|
|
fm->UnregisterPlaceholderFrame(this);
|
2012-07-30 07:20:58 -07:00
|
|
|
mOutOfFlowFrame = nullptr;
|
2009-12-23 21:21:15 -08:00
|
|
|
// 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)
|
2013-02-10 18:28:50 -08:00
|
|
|
if ((GetStateBits() & PLACEHOLDER_FOR_POPUP) ||
|
|
|
|
!nsLayoutUtils::IsProperAncestorFrame(aDestructRoot, oof)) {
|
2011-08-24 13:54:30 -07:00
|
|
|
ChildListID listId = nsLayoutUtils::GetChildListNameFor(oof);
|
2013-02-10 18:28:50 -08:00
|
|
|
fm->RemoveFrame(listId, oof);
|
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
|
|
|
|
{
|
2013-02-10 18:28:50 -08:00
|
|
|
return nsGkAtoms::placeholderFrame;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
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,
|
2013-02-10 18:28:50 -08:00
|
|
|
nsPresContext::CSSPixelsToAppUnits(13),
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(3));
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord y = nsPresContext::CSSPixelsToAppUnits(-10);
|
|
|
|
aCtx->FillRect(aPt.x, aPt.y + y,
|
2013-02-10 18:28:50 -08:00
|
|
|
nsPresContext::CSSPixelsToAppUnits(3),
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(10));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
#if defined(DEBUG) || (defined(MOZ_REFLOW_PERF_DSP) && defined(MOZ_REFLOW_PERF))
|
|
|
|
|
2013-02-14 03:12:27 -08:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsPlaceholderFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
DO_GLOBAL_REFLOW_COUNT_DSP("nsPlaceholderFrame");
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2013-02-10 18:28:50 -08:00
|
|
|
if (GetShowFrameBorders()) {
|
2013-02-14 03:12:27 -08:00
|
|
|
aLists.Outlines()->AppendNewToTop(
|
2013-02-10 18:28:50 -08:00
|
|
|
new (aBuilder) nsDisplayGeneric(aBuilder, this, PaintDebugPlaceholder,
|
|
|
|
"DebugPlaceholder",
|
|
|
|
nsDisplayItem::TYPE_DEBUG_PLACEHOLDER));
|
|
|
|
}
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#endif // DEBUG || (MOZ_REFLOW_PERF_DSP && MOZ_REFLOW_PERF)
|
|
|
|
|
2014-01-05 15:31:14 -08:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
nsPlaceholderFrame::GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("Placeholder"), aResult);
|
|
|
|
}
|
|
|
|
|
2013-04-30 11:38:52 -07:00
|
|
|
void
|
2014-01-26 14:07:02 -08:00
|
|
|
nsPlaceholderFrame::List(FILE* out, const char* aPrefix, uint32_t aFlags) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-01-26 14:07:02 -08:00
|
|
|
nsCString str;
|
|
|
|
ListGeneric(str, aPrefix, aFlags);
|
2013-04-30 11:38:52 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mOutOfFlowFrame) {
|
2014-01-26 14:07:02 -08:00
|
|
|
str += " outOfFlowFrame=";
|
|
|
|
nsFrame::ListTag(str, mOutOfFlowFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-01-26 14:07:02 -08:00
|
|
|
fprintf_stderr(out, "%s\n", str.get());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-01-05 15:31:14 -08:00
|
|
|
#endif
|