michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: #ifndef nsTableOuterFrame_h__ michael@0: #define nsTableOuterFrame_h__ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "nscore.h" michael@0: #include "nsContainerFrame.h" michael@0: #include "nsCellMap.h" michael@0: #include "nsBlockFrame.h" michael@0: #include "nsTableFrame.h" michael@0: michael@0: class nsTableCaptionFrame : public nsBlockFrame michael@0: { michael@0: public: michael@0: NS_DECL_FRAMEARENA_HELPERS michael@0: michael@0: // nsISupports michael@0: virtual nsIAtom* GetType() const MOZ_OVERRIDE; michael@0: friend nsIFrame* NS_NewTableCaptionFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); michael@0: michael@0: virtual nsSize ComputeAutoSize(nsRenderingContext *aRenderingContext, michael@0: nsSize aCBSize, nscoord aAvailableWidth, michael@0: nsSize aMargin, nsSize aBorder, michael@0: nsSize aPadding, bool aShrinkWrap) MOZ_OVERRIDE; michael@0: michael@0: virtual nsIFrame* GetParentStyleContextFrame() const MOZ_OVERRIDE; michael@0: michael@0: #ifdef ACCESSIBILITY michael@0: virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE; michael@0: #endif michael@0: michael@0: #ifdef DEBUG_FRAME_DUMP michael@0: virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE; michael@0: #endif michael@0: michael@0: protected: michael@0: nsTableCaptionFrame(nsStyleContext* aContext); michael@0: virtual ~nsTableCaptionFrame(); michael@0: }; michael@0: michael@0: michael@0: /* TODO michael@0: 1. decide if we'll allow subclassing. If so, decide which methods really need to be virtual. michael@0: */ michael@0: michael@0: /** michael@0: * main frame for an nsTable content object, michael@0: * the nsTableOuterFrame contains 0 or one caption frame, and a nsTableFrame michael@0: * pseudo-frame (referred to as the "inner frame'). michael@0: */ michael@0: class nsTableOuterFrame : public nsContainerFrame michael@0: { michael@0: public: michael@0: NS_DECL_QUERYFRAME michael@0: NS_DECL_FRAMEARENA_HELPERS michael@0: michael@0: NS_DECL_QUERYFRAME_TARGET(nsTableOuterFrame) michael@0: michael@0: /** instantiate a new instance of nsTableRowFrame. michael@0: * @param aPresShell the pres shell for this frame michael@0: * michael@0: * @return the frame that was created michael@0: */ michael@0: friend nsIFrame* NS_NewTableOuterFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); michael@0: michael@0: // nsIFrame overrides - see there for a description michael@0: michael@0: virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult SetInitialChildList(ChildListID aListID, michael@0: nsFrameList& aChildList) MOZ_OVERRIDE; michael@0: michael@0: virtual const nsFrameList& GetChildList(ChildListID aListID) const MOZ_OVERRIDE; michael@0: virtual void GetChildLists(nsTArray* aLists) const MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult AppendFrames(ChildListID aListID, michael@0: nsFrameList& aFrameList) MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult InsertFrames(ChildListID aListID, michael@0: nsIFrame* aPrevFrame, michael@0: nsFrameList& aFrameList) MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult RemoveFrame(ChildListID aListID, michael@0: nsIFrame* aOldFrame) MOZ_OVERRIDE; michael@0: michael@0: virtual nsIFrame* GetContentInsertionFrame() MOZ_OVERRIDE { michael@0: return GetFirstPrincipalChild()->GetContentInsertionFrame(); michael@0: } michael@0: michael@0: #ifdef ACCESSIBILITY michael@0: virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE; michael@0: #endif michael@0: michael@0: virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, michael@0: const nsRect& aDirtyRect, michael@0: const nsDisplayListSet& aLists) MOZ_OVERRIDE; michael@0: michael@0: void BuildDisplayListForInnerTable(nsDisplayListBuilder* aBuilder, michael@0: const nsRect& aDirtyRect, michael@0: const nsDisplayListSet& aLists); michael@0: michael@0: virtual nscoord GetBaseline() const MOZ_OVERRIDE; michael@0: michael@0: virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE; michael@0: virtual nscoord GetPrefWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE; michael@0: virtual nsSize ComputeAutoSize(nsRenderingContext *aRenderingContext, michael@0: nsSize aCBSize, nscoord aAvailableWidth, michael@0: nsSize aMargin, nsSize aBorder, michael@0: nsSize aPadding, bool aShrinkWrap) MOZ_OVERRIDE; michael@0: michael@0: /** process a reflow command for the table. michael@0: * This involves reflowing the caption and the inner table. michael@0: * @see nsIFrame::Reflow */ michael@0: virtual nsresult Reflow(nsPresContext* aPresContext, michael@0: nsHTMLReflowMetrics& aDesiredSize, michael@0: const nsHTMLReflowState& aReflowState, michael@0: nsReflowStatus& aStatus) MOZ_OVERRIDE; michael@0: michael@0: /** michael@0: * Get the "type" of the frame michael@0: * michael@0: * @see nsGkAtoms::tableOuterFrame michael@0: */ michael@0: virtual nsIAtom* GetType() const MOZ_OVERRIDE; michael@0: michael@0: #ifdef DEBUG_FRAME_DUMP michael@0: virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE; michael@0: #endif michael@0: michael@0: virtual nsIFrame* GetParentStyleContextFrame() const MOZ_OVERRIDE; michael@0: michael@0: /** michael@0: * Return the content for the cell at the given row and column. michael@0: */ michael@0: nsIContent* GetCellAt(uint32_t aRowIdx, uint32_t aColIdx) const; michael@0: michael@0: /** michael@0: * Return the number of rows in the table. michael@0: */ michael@0: int32_t GetRowCount() const michael@0: { michael@0: return InnerTableFrame()->GetRowCount(); michael@0: } michael@0: michael@0: /** michael@0: * Return the number of columns in the table. michael@0: */ michael@0: int32_t GetColCount() const michael@0: { michael@0: return InnerTableFrame()->GetColCount(); michael@0: } michael@0: michael@0: /** michael@0: * Return the index of the cell at the given row and column. michael@0: */ michael@0: int32_t GetIndexByRowAndColumn(int32_t aRowIdx, int32_t aColIdx) const michael@0: { michael@0: nsTableCellMap* cellMap = InnerTableFrame()->GetCellMap(); michael@0: if (!cellMap) michael@0: return -1; michael@0: michael@0: return cellMap->GetIndexByRowAndColumn(aRowIdx, aColIdx); michael@0: } michael@0: michael@0: /** michael@0: * Get the row and column indices for the cell at the given index. michael@0: */ michael@0: void GetRowAndColumnByIndex(int32_t aCellIdx, int32_t* aRowIdx, michael@0: int32_t* aColIdx) const michael@0: { michael@0: *aRowIdx = *aColIdx = 0; michael@0: nsTableCellMap* cellMap = InnerTableFrame()->GetCellMap(); michael@0: if (cellMap) { michael@0: cellMap->GetRowAndColumnByIndex(aCellIdx, aRowIdx, aColIdx); michael@0: } michael@0: } michael@0: michael@0: /** michael@0: * return the frame for the cell at the given row and column. michael@0: */ michael@0: nsTableCellFrame* GetCellFrameAt(uint32_t aRowIdx, uint32_t aColIdx) const michael@0: { michael@0: nsTableCellMap* map = InnerTableFrame()->GetCellMap(); michael@0: if (!map) { michael@0: return nullptr; michael@0: } michael@0: michael@0: return map->GetCellInfoAt(aRowIdx, aColIdx); michael@0: } michael@0: michael@0: /** michael@0: * Return the col span of the cell at the given row and column indices. michael@0: */ michael@0: uint32_t GetEffectiveColSpanAt(uint32_t aRowIdx, uint32_t aColIdx) const michael@0: { michael@0: nsTableCellMap* map = InnerTableFrame()->GetCellMap(); michael@0: return map->GetEffectiveColSpan(aRowIdx, aColIdx); michael@0: } michael@0: michael@0: /** michael@0: * Return the effective row span of the cell at the given row and column. michael@0: */ michael@0: uint32_t GetEffectiveRowSpanAt(uint32_t aRowIdx, uint32_t aColIdx) const michael@0: { michael@0: nsTableCellMap* map = InnerTableFrame()->GetCellMap(); michael@0: return map->GetEffectiveRowSpan(aRowIdx, aColIdx); michael@0: } michael@0: michael@0: protected: michael@0: michael@0: michael@0: nsTableOuterFrame(nsStyleContext* aContext); michael@0: virtual ~nsTableOuterFrame(); michael@0: michael@0: void InitChildReflowState(nsPresContext& aPresContext, michael@0: nsHTMLReflowState& aReflowState); michael@0: michael@0: uint8_t GetCaptionSide(); // NS_STYLE_CAPTION_SIDE_* or NO_SIDE michael@0: michael@0: bool HasSideCaption() { michael@0: uint8_t captionSide = GetCaptionSide(); michael@0: return captionSide == NS_STYLE_CAPTION_SIDE_LEFT || michael@0: captionSide == NS_STYLE_CAPTION_SIDE_RIGHT; michael@0: } michael@0: michael@0: uint8_t GetCaptionVerticalAlign(); michael@0: michael@0: void SetDesiredSize(uint8_t aCaptionSide, michael@0: const nsMargin& aInnerMargin, michael@0: const nsMargin& aCaptionMargin, michael@0: nscoord& aWidth, michael@0: nscoord& aHeight); michael@0: michael@0: nsresult GetCaptionOrigin(uint32_t aCaptionSide, michael@0: const nsSize& aContainBlockSize, michael@0: const nsSize& aInnerSize, michael@0: const nsMargin& aInnerMargin, michael@0: const nsSize& aCaptionSize, michael@0: nsMargin& aCaptionMargin, michael@0: nsPoint& aOrigin); michael@0: michael@0: nsresult GetInnerOrigin(uint32_t aCaptionSide, michael@0: const nsSize& aContainBlockSize, michael@0: const nsSize& aCaptionSize, michael@0: const nsMargin& aCaptionMargin, michael@0: const nsSize& aInnerSize, michael@0: nsMargin& aInnerMargin, michael@0: nsPoint& aOrigin); michael@0: michael@0: // reflow the child (caption or innertable frame) michael@0: void OuterBeginReflowChild(nsPresContext* aPresContext, michael@0: nsIFrame* aChildFrame, michael@0: const nsHTMLReflowState& aOuterRS, michael@0: void* aChildRSSpace, michael@0: nscoord aAvailWidth); michael@0: michael@0: nsresult OuterDoReflowChild(nsPresContext* aPresContext, michael@0: nsIFrame* aChildFrame, michael@0: const nsHTMLReflowState& aChildRS, michael@0: nsHTMLReflowMetrics& aMetrics, michael@0: nsReflowStatus& aStatus); michael@0: michael@0: // Set the reflow metrics michael@0: void UpdateReflowMetrics(uint8_t aCaptionSide, michael@0: nsHTMLReflowMetrics& aMet, michael@0: const nsMargin& aInnerMargin, michael@0: const nsMargin& aCaptionMargin); michael@0: michael@0: // Get the margin. aMarginNoAuto is aMargin, but with auto michael@0: // margins set to 0 michael@0: void GetChildMargin(nsPresContext* aPresContext, michael@0: const nsHTMLReflowState& aOuterRS, michael@0: nsIFrame* aChildFrame, michael@0: nscoord aAvailableWidth, michael@0: nsMargin& aMargin); michael@0: michael@0: virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE michael@0: { michael@0: return nsContainerFrame::IsFrameOfType(aFlags & michael@0: (~eCanContainOverflowContainers)); michael@0: } michael@0: michael@0: nsTableFrame* InnerTableFrame() const { michael@0: return static_cast(mFrames.FirstChild()); michael@0: } michael@0: michael@0: private: michael@0: nsFrameList mCaptionFrames; michael@0: }; michael@0: michael@0: #endif