layout/generic/nsPlaceholderFrame.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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 * rendering object for the point that anchors out-of-flow rendering
michael@0 8 * objects such as floats and absolutely positioned elements
michael@0 9 */
michael@0 10
michael@0 11 /*
michael@0 12 * Destruction of a placeholder and its out-of-flow must observe the
michael@0 13 * following constraints:
michael@0 14 *
michael@0 15 * - The mapping from the out-of-flow to the placeholder must be
michael@0 16 * removed from the frame manager before the placeholder is destroyed.
michael@0 17 * - The mapping from the out-of-flow to the placeholder must be
michael@0 18 * removed from the frame manager before the out-of-flow is destroyed.
michael@0 19 * - The placeholder must be removed from the frame tree, or have the
michael@0 20 * mapping from it to its out-of-flow cleared, before the out-of-flow
michael@0 21 * is destroyed (so that the placeholder will not point to a destroyed
michael@0 22 * frame while it's in the frame tree).
michael@0 23 *
michael@0 24 * Furthermore, some code assumes that placeholders point to something
michael@0 25 * useful, so placeholders without an associated out-of-flow should not
michael@0 26 * remain in the tree.
michael@0 27 *
michael@0 28 * The placeholder's Destroy() implementation handles the destruction of
michael@0 29 * the placeholder and its out-of-flow. To avoid crashes, frame removal
michael@0 30 * and destruction code that works with placeholders must not assume
michael@0 31 * that the placeholder points to its out-of-flow.
michael@0 32 */
michael@0 33
michael@0 34 #ifndef nsPlaceholderFrame_h___
michael@0 35 #define nsPlaceholderFrame_h___
michael@0 36
michael@0 37 #include "mozilla/Attributes.h"
michael@0 38 #include "nsFrame.h"
michael@0 39 #include "nsGkAtoms.h"
michael@0 40
michael@0 41 nsIFrame* NS_NewPlaceholderFrame(nsIPresShell* aPresShell,
michael@0 42 nsStyleContext* aContext,
michael@0 43 nsFrameState aTypeBit);
michael@0 44
michael@0 45 #define PLACEHOLDER_TYPE_MASK (PLACEHOLDER_FOR_FLOAT | \
michael@0 46 PLACEHOLDER_FOR_ABSPOS | \
michael@0 47 PLACEHOLDER_FOR_FIXEDPOS | \
michael@0 48 PLACEHOLDER_FOR_POPUP)
michael@0 49
michael@0 50 /**
michael@0 51 * Implementation of a frame that's used as a placeholder for a frame that
michael@0 52 * has been moved out of the flow.
michael@0 53 */
michael@0 54 class nsPlaceholderFrame MOZ_FINAL : public nsFrame {
michael@0 55 public:
michael@0 56 NS_DECL_FRAMEARENA_HELPERS
michael@0 57 #ifdef DEBUG
michael@0 58 NS_DECL_QUERYFRAME_TARGET(nsPlaceholderFrame)
michael@0 59 NS_DECL_QUERYFRAME
michael@0 60 #endif
michael@0 61
michael@0 62 /**
michael@0 63 * Create a new placeholder frame. aTypeBit must be one of the
michael@0 64 * PLACEHOLDER_FOR_* constants above.
michael@0 65 */
michael@0 66 friend nsIFrame* NS_NewPlaceholderFrame(nsIPresShell* aPresShell,
michael@0 67 nsStyleContext* aContext,
michael@0 68 nsFrameState aTypeBit);
michael@0 69 nsPlaceholderFrame(nsStyleContext* aContext, nsFrameState aTypeBit)
michael@0 70 : nsFrame(aContext)
michael@0 71 {
michael@0 72 NS_PRECONDITION(aTypeBit == PLACEHOLDER_FOR_FLOAT ||
michael@0 73 aTypeBit == PLACEHOLDER_FOR_ABSPOS ||
michael@0 74 aTypeBit == PLACEHOLDER_FOR_FIXEDPOS ||
michael@0 75 aTypeBit == PLACEHOLDER_FOR_POPUP,
michael@0 76 "Unexpected type bit");
michael@0 77 AddStateBits(aTypeBit);
michael@0 78 }
michael@0 79
michael@0 80 // Get/Set the associated out of flow frame
michael@0 81 nsIFrame* GetOutOfFlowFrame() const { return mOutOfFlowFrame; }
michael@0 82 void SetOutOfFlowFrame(nsIFrame* aFrame) {
michael@0 83 NS_ASSERTION(!aFrame || !aFrame->GetPrevContinuation(),
michael@0 84 "OOF must be first continuation");
michael@0 85 mOutOfFlowFrame = aFrame;
michael@0 86 }
michael@0 87
michael@0 88 // nsIFrame overrides
michael@0 89 // We need to override GetMinSize and GetPrefSize because XUL uses
michael@0 90 // placeholders not within lines.
michael@0 91 virtual void AddInlineMinWidth(nsRenderingContext* aRenderingContext,
michael@0 92 InlineMinWidthData* aData) MOZ_OVERRIDE;
michael@0 93 virtual void AddInlinePrefWidth(nsRenderingContext* aRenderingContext,
michael@0 94 InlinePrefWidthData* aData) MOZ_OVERRIDE;
michael@0 95 virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
michael@0 96 virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
michael@0 97 virtual nsSize GetMaxSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
michael@0 98
michael@0 99 virtual nsresult Reflow(nsPresContext* aPresContext,
michael@0 100 nsHTMLReflowMetrics& aDesiredSize,
michael@0 101 const nsHTMLReflowState& aReflowState,
michael@0 102 nsReflowStatus& aStatus) MOZ_OVERRIDE;
michael@0 103
michael@0 104 virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
michael@0 105
michael@0 106 #if defined(DEBUG) || (defined(MOZ_REFLOW_PERF_DSP) && defined(MOZ_REFLOW_PERF))
michael@0 107 virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
michael@0 108 const nsRect& aDirtyRect,
michael@0 109 const nsDisplayListSet& aLists) MOZ_OVERRIDE;
michael@0 110 #endif // DEBUG || (MOZ_REFLOW_PERF_DSP && MOZ_REFLOW_PERF)
michael@0 111
michael@0 112 #ifdef DEBUG_FRAME_DUMP
michael@0 113 void List(FILE* out = stderr, const char* aPrefix = "", uint32_t aFlags = 0) const MOZ_OVERRIDE;
michael@0 114 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
michael@0 115 #endif // DEBUG
michael@0 116
michael@0 117 /**
michael@0 118 * Get the "type" of the frame
michael@0 119 *
michael@0 120 * @see nsGkAtoms::placeholderFrame
michael@0 121 */
michael@0 122 virtual nsIAtom* GetType() const MOZ_OVERRIDE;
michael@0 123
michael@0 124 virtual bool IsEmpty() MOZ_OVERRIDE { return true; }
michael@0 125 virtual bool IsSelfEmpty() MOZ_OVERRIDE { return true; }
michael@0 126
michael@0 127 virtual bool CanContinueTextRun() const MOZ_OVERRIDE;
michael@0 128
michael@0 129 #ifdef ACCESSIBILITY
michael@0 130 virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE
michael@0 131 {
michael@0 132 nsIFrame* realFrame = GetRealFrameForPlaceholder(this);
michael@0 133 return realFrame ? realFrame->AccessibleType() :
michael@0 134 nsFrame::AccessibleType();
michael@0 135 }
michael@0 136 #endif
michael@0 137
michael@0 138 virtual nsIFrame* GetParentStyleContextFrame() const MOZ_OVERRIDE;
michael@0 139
michael@0 140 /**
michael@0 141 * @return the out-of-flow for aFrame if aFrame is a placeholder; otherwise
michael@0 142 * aFrame
michael@0 143 */
michael@0 144 static nsIFrame* GetRealFrameFor(nsIFrame* aFrame) {
michael@0 145 NS_PRECONDITION(aFrame, "Must have a frame to work with");
michael@0 146 if (aFrame->GetType() == nsGkAtoms::placeholderFrame) {
michael@0 147 return GetRealFrameForPlaceholder(aFrame);
michael@0 148 }
michael@0 149 return aFrame;
michael@0 150 }
michael@0 151
michael@0 152 /**
michael@0 153 * @return the out-of-flow for aFrame, which is known to be a placeholder
michael@0 154 */
michael@0 155 static nsIFrame* GetRealFrameForPlaceholder(nsIFrame* aFrame) {
michael@0 156 NS_PRECONDITION(aFrame->GetType() == nsGkAtoms::placeholderFrame,
michael@0 157 "Must have placeholder frame as input");
michael@0 158 nsIFrame* outOfFlow =
michael@0 159 static_cast<nsPlaceholderFrame*>(aFrame)->GetOutOfFlowFrame();
michael@0 160 NS_ASSERTION(outOfFlow, "Null out-of-flow for placeholder?");
michael@0 161 return outOfFlow;
michael@0 162 }
michael@0 163
michael@0 164 protected:
michael@0 165 nsIFrame* mOutOfFlowFrame;
michael@0 166 };
michael@0 167
michael@0 168 #endif /* nsPlaceholderFrame_h___ */

mercurial