Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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 | /* rendering object for CSS display:inline objects */ |
michael@0 | 7 | |
michael@0 | 8 | #ifndef nsInlineFrame_h___ |
michael@0 | 9 | #define nsInlineFrame_h___ |
michael@0 | 10 | |
michael@0 | 11 | #include "mozilla/Attributes.h" |
michael@0 | 12 | #include "nsContainerFrame.h" |
michael@0 | 13 | |
michael@0 | 14 | class nsLineLayout; |
michael@0 | 15 | |
michael@0 | 16 | typedef nsContainerFrame nsInlineFrameBase; |
michael@0 | 17 | |
michael@0 | 18 | /** |
michael@0 | 19 | * Inline frame class. |
michael@0 | 20 | * |
michael@0 | 21 | * This class manages a list of child frames that are inline frames. Working with |
michael@0 | 22 | * nsLineLayout, the class will reflow and place inline frames on a line. |
michael@0 | 23 | */ |
michael@0 | 24 | class nsInlineFrame : public nsInlineFrameBase |
michael@0 | 25 | { |
michael@0 | 26 | public: |
michael@0 | 27 | NS_DECL_QUERYFRAME_TARGET(nsInlineFrame) |
michael@0 | 28 | NS_DECL_QUERYFRAME |
michael@0 | 29 | NS_DECL_FRAMEARENA_HELPERS |
michael@0 | 30 | |
michael@0 | 31 | friend nsIFrame* NS_NewInlineFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); |
michael@0 | 32 | |
michael@0 | 33 | // nsIFrame overrides |
michael@0 | 34 | virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, |
michael@0 | 35 | const nsRect& aDirtyRect, |
michael@0 | 36 | const nsDisplayListSet& aLists) MOZ_OVERRIDE; |
michael@0 | 37 | |
michael@0 | 38 | #ifdef ACCESSIBILITY |
michael@0 | 39 | virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE; |
michael@0 | 40 | #endif |
michael@0 | 41 | |
michael@0 | 42 | #ifdef DEBUG_FRAME_DUMP |
michael@0 | 43 | virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE; |
michael@0 | 44 | #endif |
michael@0 | 45 | virtual nsIAtom* GetType() const MOZ_OVERRIDE; |
michael@0 | 46 | |
michael@0 | 47 | virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE |
michael@0 | 48 | { |
michael@0 | 49 | if (aFlags & eSupportsCSSTransforms) { |
michael@0 | 50 | return false; |
michael@0 | 51 | } |
michael@0 | 52 | return nsContainerFrame::IsFrameOfType(aFlags & |
michael@0 | 53 | ~(nsIFrame::eBidiInlineContainer | nsIFrame::eLineParticipant)); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | virtual void InvalidateFrame(uint32_t aDisplayItemKey = 0) MOZ_OVERRIDE; |
michael@0 | 57 | virtual void InvalidateFrameWithRect(const nsRect& aRect, uint32_t aDisplayItemKey = 0) MOZ_OVERRIDE; |
michael@0 | 58 | |
michael@0 | 59 | virtual bool IsEmpty() MOZ_OVERRIDE; |
michael@0 | 60 | virtual bool IsSelfEmpty() MOZ_OVERRIDE; |
michael@0 | 61 | |
michael@0 | 62 | virtual FrameSearchResult PeekOffsetCharacter(bool aForward, int32_t* aOffset, |
michael@0 | 63 | bool aRespectClusters = true) MOZ_OVERRIDE; |
michael@0 | 64 | |
michael@0 | 65 | // nsIHTMLReflow overrides |
michael@0 | 66 | virtual void AddInlineMinWidth(nsRenderingContext *aRenderingContext, |
michael@0 | 67 | InlineMinWidthData *aData) MOZ_OVERRIDE; |
michael@0 | 68 | virtual void AddInlinePrefWidth(nsRenderingContext *aRenderingContext, |
michael@0 | 69 | InlinePrefWidthData *aData) MOZ_OVERRIDE; |
michael@0 | 70 | virtual nsSize ComputeSize(nsRenderingContext *aRenderingContext, |
michael@0 | 71 | nsSize aCBSize, nscoord aAvailableWidth, |
michael@0 | 72 | nsSize aMargin, nsSize aBorder, nsSize aPadding, |
michael@0 | 73 | uint32_t aFlags) MOZ_OVERRIDE; |
michael@0 | 74 | virtual nsRect ComputeTightBounds(gfxContext* aContext) const MOZ_OVERRIDE; |
michael@0 | 75 | virtual nsresult Reflow(nsPresContext* aPresContext, |
michael@0 | 76 | nsHTMLReflowMetrics& aDesiredSize, |
michael@0 | 77 | const nsHTMLReflowState& aReflowState, |
michael@0 | 78 | nsReflowStatus& aStatus) MOZ_OVERRIDE; |
michael@0 | 79 | |
michael@0 | 80 | virtual bool CanContinueTextRun() const MOZ_OVERRIDE; |
michael@0 | 81 | |
michael@0 | 82 | virtual void PullOverflowsFromPrevInFlow() MOZ_OVERRIDE; |
michael@0 | 83 | virtual nscoord GetBaseline() const MOZ_OVERRIDE; |
michael@0 | 84 | virtual bool DrainSelfOverflowList() MOZ_OVERRIDE; |
michael@0 | 85 | |
michael@0 | 86 | /** |
michael@0 | 87 | * Return true if the frame is first visual frame or first continuation |
michael@0 | 88 | */ |
michael@0 | 89 | bool IsFirst() const { |
michael@0 | 90 | // If the frame's bidi visual state is set, return is-first state |
michael@0 | 91 | // else return true if it's the first continuation. |
michael@0 | 92 | return (GetStateBits() & NS_INLINE_FRAME_BIDI_VISUAL_STATE_IS_SET) |
michael@0 | 93 | ? !!(GetStateBits() & NS_INLINE_FRAME_BIDI_VISUAL_IS_FIRST) |
michael@0 | 94 | : (!GetPrevInFlow()); |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | /** |
michael@0 | 98 | * Return true if the frame is last visual frame or last continuation. |
michael@0 | 99 | */ |
michael@0 | 100 | bool IsLast() const { |
michael@0 | 101 | // If the frame's bidi visual state is set, return is-last state |
michael@0 | 102 | // else return true if it's the last continuation. |
michael@0 | 103 | return (GetStateBits() & NS_INLINE_FRAME_BIDI_VISUAL_STATE_IS_SET) |
michael@0 | 104 | ? !!(GetStateBits() & NS_INLINE_FRAME_BIDI_VISUAL_IS_LAST) |
michael@0 | 105 | : (!GetNextInFlow()); |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | protected: |
michael@0 | 109 | // Additional reflow state used during our reflow methods |
michael@0 | 110 | struct InlineReflowState { |
michael@0 | 111 | nsIFrame* mPrevFrame; |
michael@0 | 112 | nsInlineFrame* mNextInFlow; |
michael@0 | 113 | nsIFrame* mLineContainer; |
michael@0 | 114 | nsLineLayout* mLineLayout; |
michael@0 | 115 | bool mSetParentPointer; // when reflowing child frame first set its |
michael@0 | 116 | // parent frame pointer |
michael@0 | 117 | |
michael@0 | 118 | InlineReflowState() { |
michael@0 | 119 | mPrevFrame = nullptr; |
michael@0 | 120 | mNextInFlow = nullptr; |
michael@0 | 121 | mLineContainer = nullptr; |
michael@0 | 122 | mLineLayout = nullptr; |
michael@0 | 123 | mSetParentPointer = false; |
michael@0 | 124 | } |
michael@0 | 125 | }; |
michael@0 | 126 | |
michael@0 | 127 | nsInlineFrame(nsStyleContext* aContext) : nsContainerFrame(aContext) {} |
michael@0 | 128 | |
michael@0 | 129 | virtual int GetLogicalSkipSides(const nsHTMLReflowState* aReflowState = nullptr) const MOZ_OVERRIDE; |
michael@0 | 130 | |
michael@0 | 131 | nsresult ReflowFrames(nsPresContext* aPresContext, |
michael@0 | 132 | const nsHTMLReflowState& aReflowState, |
michael@0 | 133 | InlineReflowState& rs, |
michael@0 | 134 | nsHTMLReflowMetrics& aMetrics, |
michael@0 | 135 | nsReflowStatus& aStatus); |
michael@0 | 136 | |
michael@0 | 137 | nsresult ReflowInlineFrame(nsPresContext* aPresContext, |
michael@0 | 138 | const nsHTMLReflowState& aReflowState, |
michael@0 | 139 | InlineReflowState& rs, |
michael@0 | 140 | nsIFrame* aFrame, |
michael@0 | 141 | nsReflowStatus& aStatus); |
michael@0 | 142 | |
michael@0 | 143 | /** |
michael@0 | 144 | * Reparent floats whose placeholders are inline descendants of aFrame from |
michael@0 | 145 | * whatever block they're currently parented by to aOurBlock. |
michael@0 | 146 | * @param aReparentSiblings if this is true, we follow aFrame's |
michael@0 | 147 | * GetNextSibling chain reparenting them all |
michael@0 | 148 | */ |
michael@0 | 149 | void ReparentFloatsForInlineChild(nsIFrame* aOurBlock, nsIFrame* aFrame, |
michael@0 | 150 | bool aReparentSiblings); |
michael@0 | 151 | |
michael@0 | 152 | virtual nsIFrame* PullOneFrame(nsPresContext* aPresContext, |
michael@0 | 153 | InlineReflowState& rs, |
michael@0 | 154 | bool* aIsComplete); |
michael@0 | 155 | |
michael@0 | 156 | virtual void PushFrames(nsPresContext* aPresContext, |
michael@0 | 157 | nsIFrame* aFromChild, |
michael@0 | 158 | nsIFrame* aPrevSibling, |
michael@0 | 159 | InlineReflowState& aState); |
michael@0 | 160 | |
michael@0 | 161 | private: |
michael@0 | 162 | // Helper method for DrainSelfOverflowList() to deal with lazy parenting |
michael@0 | 163 | // (which we only do for nsInlineFrame, not nsFirstLineFrame). |
michael@0 | 164 | enum DrainFlags { |
michael@0 | 165 | eDontReparentFrames = 1, // skip reparenting the overflow list frames |
michael@0 | 166 | eInFirstLine = 2, // the request is for an inline descendant of a nsFirstLineFrame |
michael@0 | 167 | }; |
michael@0 | 168 | /** |
michael@0 | 169 | * Move any frames on our overflow list to the end of our principal list. |
michael@0 | 170 | * @param aFlags one or more of the above DrainFlags |
michael@0 | 171 | * @param aLineContainer the nearest line container ancestor |
michael@0 | 172 | * @return true if there were any overflow frames |
michael@0 | 173 | */ |
michael@0 | 174 | bool DrainSelfOverflowListInternal(DrainFlags aFlags, |
michael@0 | 175 | nsIFrame* aLineContainer); |
michael@0 | 176 | protected: |
michael@0 | 177 | nscoord mBaseline; |
michael@0 | 178 | }; |
michael@0 | 179 | |
michael@0 | 180 | //---------------------------------------------------------------------- |
michael@0 | 181 | |
michael@0 | 182 | /** |
michael@0 | 183 | * Variation on inline-frame used to manage lines for line layout in |
michael@0 | 184 | * special situations (:first-line style in particular). |
michael@0 | 185 | */ |
michael@0 | 186 | class nsFirstLineFrame MOZ_FINAL : public nsInlineFrame { |
michael@0 | 187 | public: |
michael@0 | 188 | NS_DECL_FRAMEARENA_HELPERS |
michael@0 | 189 | |
michael@0 | 190 | friend nsIFrame* NS_NewFirstLineFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); |
michael@0 | 191 | |
michael@0 | 192 | #ifdef DEBUG_FRAME_DUMP |
michael@0 | 193 | virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE; |
michael@0 | 194 | #endif |
michael@0 | 195 | virtual nsIAtom* GetType() const MOZ_OVERRIDE; |
michael@0 | 196 | virtual nsresult Reflow(nsPresContext* aPresContext, |
michael@0 | 197 | nsHTMLReflowMetrics& aDesiredSize, |
michael@0 | 198 | const nsHTMLReflowState& aReflowState, |
michael@0 | 199 | nsReflowStatus& aStatus) MOZ_OVERRIDE; |
michael@0 | 200 | |
michael@0 | 201 | virtual void Init(nsIContent* aContent, nsIFrame* aParent, |
michael@0 | 202 | nsIFrame* aPrevInFlow) MOZ_OVERRIDE; |
michael@0 | 203 | virtual void PullOverflowsFromPrevInFlow() MOZ_OVERRIDE; |
michael@0 | 204 | virtual bool DrainSelfOverflowList() MOZ_OVERRIDE; |
michael@0 | 205 | |
michael@0 | 206 | protected: |
michael@0 | 207 | nsFirstLineFrame(nsStyleContext* aContext) : nsInlineFrame(aContext) {} |
michael@0 | 208 | |
michael@0 | 209 | virtual nsIFrame* PullOneFrame(nsPresContext* aPresContext, |
michael@0 | 210 | InlineReflowState& rs, |
michael@0 | 211 | bool* aIsComplete) MOZ_OVERRIDE; |
michael@0 | 212 | }; |
michael@0 | 213 | |
michael@0 | 214 | #endif /* nsInlineFrame_h___ */ |