1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/generic/nsInlineFrame.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,214 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* rendering object for CSS display:inline objects */ 1.10 + 1.11 +#ifndef nsInlineFrame_h___ 1.12 +#define nsInlineFrame_h___ 1.13 + 1.14 +#include "mozilla/Attributes.h" 1.15 +#include "nsContainerFrame.h" 1.16 + 1.17 +class nsLineLayout; 1.18 + 1.19 +typedef nsContainerFrame nsInlineFrameBase; 1.20 + 1.21 +/** 1.22 + * Inline frame class. 1.23 + * 1.24 + * This class manages a list of child frames that are inline frames. Working with 1.25 + * nsLineLayout, the class will reflow and place inline frames on a line. 1.26 + */ 1.27 +class nsInlineFrame : public nsInlineFrameBase 1.28 +{ 1.29 +public: 1.30 + NS_DECL_QUERYFRAME_TARGET(nsInlineFrame) 1.31 + NS_DECL_QUERYFRAME 1.32 + NS_DECL_FRAMEARENA_HELPERS 1.33 + 1.34 + friend nsIFrame* NS_NewInlineFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); 1.35 + 1.36 + // nsIFrame overrides 1.37 + virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, 1.38 + const nsRect& aDirtyRect, 1.39 + const nsDisplayListSet& aLists) MOZ_OVERRIDE; 1.40 + 1.41 +#ifdef ACCESSIBILITY 1.42 + virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE; 1.43 +#endif 1.44 + 1.45 +#ifdef DEBUG_FRAME_DUMP 1.46 + virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE; 1.47 +#endif 1.48 + virtual nsIAtom* GetType() const MOZ_OVERRIDE; 1.49 + 1.50 + virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE 1.51 + { 1.52 + if (aFlags & eSupportsCSSTransforms) { 1.53 + return false; 1.54 + } 1.55 + return nsContainerFrame::IsFrameOfType(aFlags & 1.56 + ~(nsIFrame::eBidiInlineContainer | nsIFrame::eLineParticipant)); 1.57 + } 1.58 + 1.59 + virtual void InvalidateFrame(uint32_t aDisplayItemKey = 0) MOZ_OVERRIDE; 1.60 + virtual void InvalidateFrameWithRect(const nsRect& aRect, uint32_t aDisplayItemKey = 0) MOZ_OVERRIDE; 1.61 + 1.62 + virtual bool IsEmpty() MOZ_OVERRIDE; 1.63 + virtual bool IsSelfEmpty() MOZ_OVERRIDE; 1.64 + 1.65 + virtual FrameSearchResult PeekOffsetCharacter(bool aForward, int32_t* aOffset, 1.66 + bool aRespectClusters = true) MOZ_OVERRIDE; 1.67 + 1.68 + // nsIHTMLReflow overrides 1.69 + virtual void AddInlineMinWidth(nsRenderingContext *aRenderingContext, 1.70 + InlineMinWidthData *aData) MOZ_OVERRIDE; 1.71 + virtual void AddInlinePrefWidth(nsRenderingContext *aRenderingContext, 1.72 + InlinePrefWidthData *aData) MOZ_OVERRIDE; 1.73 + virtual nsSize ComputeSize(nsRenderingContext *aRenderingContext, 1.74 + nsSize aCBSize, nscoord aAvailableWidth, 1.75 + nsSize aMargin, nsSize aBorder, nsSize aPadding, 1.76 + uint32_t aFlags) MOZ_OVERRIDE; 1.77 + virtual nsRect ComputeTightBounds(gfxContext* aContext) const MOZ_OVERRIDE; 1.78 + virtual nsresult Reflow(nsPresContext* aPresContext, 1.79 + nsHTMLReflowMetrics& aDesiredSize, 1.80 + const nsHTMLReflowState& aReflowState, 1.81 + nsReflowStatus& aStatus) MOZ_OVERRIDE; 1.82 + 1.83 + virtual bool CanContinueTextRun() const MOZ_OVERRIDE; 1.84 + 1.85 + virtual void PullOverflowsFromPrevInFlow() MOZ_OVERRIDE; 1.86 + virtual nscoord GetBaseline() const MOZ_OVERRIDE; 1.87 + virtual bool DrainSelfOverflowList() MOZ_OVERRIDE; 1.88 + 1.89 + /** 1.90 + * Return true if the frame is first visual frame or first continuation 1.91 + */ 1.92 + bool IsFirst() const { 1.93 + // If the frame's bidi visual state is set, return is-first state 1.94 + // else return true if it's the first continuation. 1.95 + return (GetStateBits() & NS_INLINE_FRAME_BIDI_VISUAL_STATE_IS_SET) 1.96 + ? !!(GetStateBits() & NS_INLINE_FRAME_BIDI_VISUAL_IS_FIRST) 1.97 + : (!GetPrevInFlow()); 1.98 + } 1.99 + 1.100 + /** 1.101 + * Return true if the frame is last visual frame or last continuation. 1.102 + */ 1.103 + bool IsLast() const { 1.104 + // If the frame's bidi visual state is set, return is-last state 1.105 + // else return true if it's the last continuation. 1.106 + return (GetStateBits() & NS_INLINE_FRAME_BIDI_VISUAL_STATE_IS_SET) 1.107 + ? !!(GetStateBits() & NS_INLINE_FRAME_BIDI_VISUAL_IS_LAST) 1.108 + : (!GetNextInFlow()); 1.109 + } 1.110 + 1.111 +protected: 1.112 + // Additional reflow state used during our reflow methods 1.113 + struct InlineReflowState { 1.114 + nsIFrame* mPrevFrame; 1.115 + nsInlineFrame* mNextInFlow; 1.116 + nsIFrame* mLineContainer; 1.117 + nsLineLayout* mLineLayout; 1.118 + bool mSetParentPointer; // when reflowing child frame first set its 1.119 + // parent frame pointer 1.120 + 1.121 + InlineReflowState() { 1.122 + mPrevFrame = nullptr; 1.123 + mNextInFlow = nullptr; 1.124 + mLineContainer = nullptr; 1.125 + mLineLayout = nullptr; 1.126 + mSetParentPointer = false; 1.127 + } 1.128 + }; 1.129 + 1.130 + nsInlineFrame(nsStyleContext* aContext) : nsContainerFrame(aContext) {} 1.131 + 1.132 + virtual int GetLogicalSkipSides(const nsHTMLReflowState* aReflowState = nullptr) const MOZ_OVERRIDE; 1.133 + 1.134 + nsresult ReflowFrames(nsPresContext* aPresContext, 1.135 + const nsHTMLReflowState& aReflowState, 1.136 + InlineReflowState& rs, 1.137 + nsHTMLReflowMetrics& aMetrics, 1.138 + nsReflowStatus& aStatus); 1.139 + 1.140 + nsresult ReflowInlineFrame(nsPresContext* aPresContext, 1.141 + const nsHTMLReflowState& aReflowState, 1.142 + InlineReflowState& rs, 1.143 + nsIFrame* aFrame, 1.144 + nsReflowStatus& aStatus); 1.145 + 1.146 + /** 1.147 + * Reparent floats whose placeholders are inline descendants of aFrame from 1.148 + * whatever block they're currently parented by to aOurBlock. 1.149 + * @param aReparentSiblings if this is true, we follow aFrame's 1.150 + * GetNextSibling chain reparenting them all 1.151 + */ 1.152 + void ReparentFloatsForInlineChild(nsIFrame* aOurBlock, nsIFrame* aFrame, 1.153 + bool aReparentSiblings); 1.154 + 1.155 + virtual nsIFrame* PullOneFrame(nsPresContext* aPresContext, 1.156 + InlineReflowState& rs, 1.157 + bool* aIsComplete); 1.158 + 1.159 + virtual void PushFrames(nsPresContext* aPresContext, 1.160 + nsIFrame* aFromChild, 1.161 + nsIFrame* aPrevSibling, 1.162 + InlineReflowState& aState); 1.163 + 1.164 +private: 1.165 + // Helper method for DrainSelfOverflowList() to deal with lazy parenting 1.166 + // (which we only do for nsInlineFrame, not nsFirstLineFrame). 1.167 + enum DrainFlags { 1.168 + eDontReparentFrames = 1, // skip reparenting the overflow list frames 1.169 + eInFirstLine = 2, // the request is for an inline descendant of a nsFirstLineFrame 1.170 + }; 1.171 + /** 1.172 + * Move any frames on our overflow list to the end of our principal list. 1.173 + * @param aFlags one or more of the above DrainFlags 1.174 + * @param aLineContainer the nearest line container ancestor 1.175 + * @return true if there were any overflow frames 1.176 + */ 1.177 + bool DrainSelfOverflowListInternal(DrainFlags aFlags, 1.178 + nsIFrame* aLineContainer); 1.179 +protected: 1.180 + nscoord mBaseline; 1.181 +}; 1.182 + 1.183 +//---------------------------------------------------------------------- 1.184 + 1.185 +/** 1.186 + * Variation on inline-frame used to manage lines for line layout in 1.187 + * special situations (:first-line style in particular). 1.188 + */ 1.189 +class nsFirstLineFrame MOZ_FINAL : public nsInlineFrame { 1.190 +public: 1.191 + NS_DECL_FRAMEARENA_HELPERS 1.192 + 1.193 + friend nsIFrame* NS_NewFirstLineFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); 1.194 + 1.195 +#ifdef DEBUG_FRAME_DUMP 1.196 + virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE; 1.197 +#endif 1.198 + virtual nsIAtom* GetType() const MOZ_OVERRIDE; 1.199 + virtual nsresult Reflow(nsPresContext* aPresContext, 1.200 + nsHTMLReflowMetrics& aDesiredSize, 1.201 + const nsHTMLReflowState& aReflowState, 1.202 + nsReflowStatus& aStatus) MOZ_OVERRIDE; 1.203 + 1.204 + virtual void Init(nsIContent* aContent, nsIFrame* aParent, 1.205 + nsIFrame* aPrevInFlow) MOZ_OVERRIDE; 1.206 + virtual void PullOverflowsFromPrevInFlow() MOZ_OVERRIDE; 1.207 + virtual bool DrainSelfOverflowList() MOZ_OVERRIDE; 1.208 + 1.209 +protected: 1.210 + nsFirstLineFrame(nsStyleContext* aContext) : nsInlineFrame(aContext) {} 1.211 + 1.212 + virtual nsIFrame* PullOneFrame(nsPresContext* aPresContext, 1.213 + InlineReflowState& rs, 1.214 + bool* aIsComplete) MOZ_OVERRIDE; 1.215 +}; 1.216 + 1.217 +#endif /* nsInlineFrame_h___ */