2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-04-16 16:52:49 +04: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/. */
|
|
|
|
|
2014-08-25 06:25:00 +04:00
|
|
|
#ifndef nsColumnSetFrame_h___
|
|
|
|
#define nsColumnSetFrame_h___
|
|
|
|
|
2013-04-16 16:52:49 +04:00
|
|
|
/* rendering object for css3 multi-column layout */
|
|
|
|
|
2013-05-14 20:33:23 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-04-16 16:52:49 +04:00
|
|
|
#include "nsContainerFrame.h"
|
2014-06-03 18:17:14 +04:00
|
|
|
#include "nsIFrameInlines.h" // for methods used by IS_TRUE_OVERFLOW_CONTAINER
|
2013-04-16 16:52:49 +04:00
|
|
|
|
2016-06-10 03:56:23 +03:00
|
|
|
/**
|
|
|
|
* nsColumnSetFrame implements CSS multi-column layout.
|
|
|
|
* @note nsColumnSetFrame keeps true overflow containers in the normal flow
|
|
|
|
* child lists (i.e. the principal and overflow lists).
|
|
|
|
*/
|
|
|
|
class nsColumnSetFrame final : public nsContainerFrame {
|
2013-04-16 16:52:49 +04:00
|
|
|
public:
|
2017-05-26 13:11:11 +03:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS(nsColumnSetFrame)
|
2013-04-16 16:52:49 +04:00
|
|
|
|
2019-02-05 19:45:54 +03:00
|
|
|
explicit nsColumnSetFrame(ComputedStyle* aStyle, nsPresContext* aPresContext);
|
2013-04-16 16:52:49 +04:00
|
|
|
|
2014-05-13 04:47:52 +04:00
|
|
|
virtual void Reflow(nsPresContext* aPresContext, ReflowOutput& aDesiredSize,
|
2016-07-21 13:36:39 +03:00
|
|
|
const ReflowInput& aReflowInput,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsReflowStatus& aStatus) override;
|
2013-04-16 16:52:49 +04:00
|
|
|
|
2014-05-28 23:36:58 +04:00
|
|
|
#ifdef DEBUG
|
2014-05-28 23:36:58 +04:00
|
|
|
virtual void SetInitialChildList(ChildListID aListID,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsFrameList& aChildList) override;
|
2014-05-28 23:36:58 +04:00
|
|
|
virtual void AppendFrames(ChildListID aListID,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsFrameList& aFrameList) override;
|
2014-05-28 23:36:58 +04:00
|
|
|
virtual void InsertFrames(ChildListID aListID, nsIFrame* aPrevFrame,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsFrameList& aFrameList) override;
|
2014-05-28 23:36:58 +04:00
|
|
|
virtual void RemoveFrame(ChildListID aListID, nsIFrame* aOldFrame) override;
|
2014-05-28 23:36:58 +04:00
|
|
|
#endif
|
2013-04-16 16:52:49 +04:00
|
|
|
|
2017-06-09 22:14:53 +03:00
|
|
|
virtual nscoord GetMinISize(gfxContext* aRenderingContext) override;
|
|
|
|
virtual nscoord GetPrefISize(gfxContext* aRenderingContext) override;
|
2013-04-16 16:52:49 +04:00
|
|
|
|
2013-07-25 19:34:31 +04:00
|
|
|
/**
|
|
|
|
* Retrieve the available height for content of this frame. The available
|
|
|
|
* content height is the available height for the frame, minus borders and
|
|
|
|
* padding.
|
|
|
|
*/
|
2016-07-21 13:36:39 +03:00
|
|
|
virtual nscoord GetAvailableContentBSize(const ReflowInput& aReflowInput);
|
2013-07-25 19:34:31 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsContainerFrame* GetContentInsertionFrame() override {
|
2016-01-29 17:42:14 +03:00
|
|
|
nsIFrame* frame = PrincipalChildList().FirstChild();
|
2013-04-16 16:52:49 +04:00
|
|
|
|
|
|
|
// if no children return nullptr
|
|
|
|
if (!frame) return nullptr;
|
|
|
|
|
|
|
|
return frame->GetContentInsertionFrame();
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool IsFrameOfType(uint32_t aFlags) const override {
|
2013-04-16 16:52:49 +04:00
|
|
|
return nsContainerFrame::IsFrameOfType(
|
|
|
|
aFlags & ~(nsIFrame::eCanContainOverflowContainers));
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
2015-03-21 19:28:04 +03:00
|
|
|
const nsDisplayListSet& aLists) override;
|
2013-04-16 16:52:49 +04:00
|
|
|
|
2014-08-25 06:25:00 +04:00
|
|
|
/**
|
|
|
|
* Similar to nsBlockFrame::DrainOverflowLines. Locate any columns not
|
|
|
|
* handled by our prev-in-flow, and any columns sitting on our own
|
|
|
|
* overflow list, and put them in our primary child list for reflowing.
|
|
|
|
*/
|
|
|
|
void DrainOverflowColumns();
|
|
|
|
|
2017-06-16 12:22:33 +03:00
|
|
|
// Return the column-content frame.
|
|
|
|
void AppendDirectlyOwnedAnonBoxes(nsTArray<OwnedAnonBox>& aResult) override;
|
2017-03-15 21:00:43 +03:00
|
|
|
|
2014-01-06 03:31:14 +04:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const override {
|
2013-04-16 16:52:49 +04:00
|
|
|
return MakeFrameName(NS_LITERAL_STRING("ColumnSet"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-01-31 10:18:49 +03:00
|
|
|
nsRect CalculateColumnRuleBounds(const nsPoint& aOffset);
|
2017-03-24 12:35:35 +03:00
|
|
|
void CreateBorderRenderers(nsTArray<nsCSSBorderRenderer>& aBorderRenderers,
|
|
|
|
gfxContext* aCtx, const nsRect& aDirtyRect,
|
|
|
|
const nsPoint& aPt);
|
|
|
|
|
2013-04-16 16:52:49 +04:00
|
|
|
protected:
|
2014-12-04 11:57:16 +03:00
|
|
|
nscoord mLastBalanceBSize;
|
2013-04-16 16:52:49 +04:00
|
|
|
nsReflowStatus mLastFrameStatus;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* These are the parameters that control the layout of columns.
|
|
|
|
*/
|
|
|
|
struct ReflowConfig {
|
|
|
|
// The number of columns that we want to balance across. If we're not
|
|
|
|
// balancing, this will be set to INT32_MAX.
|
2018-10-23 16:08:59 +03:00
|
|
|
int32_t mBalanceColCount = INT32_MAX;
|
2013-04-16 16:52:49 +04:00
|
|
|
|
2014-12-04 11:57:17 +03:00
|
|
|
// The inline-size of each individual column.
|
2018-10-23 16:08:59 +03:00
|
|
|
nscoord mColISize = NS_INTRINSICSIZE;
|
2013-04-16 16:52:49 +04:00
|
|
|
|
2014-12-04 11:57:17 +03:00
|
|
|
// The amount of inline-size that is expected to be left over after all the
|
2013-04-16 16:52:49 +04:00
|
|
|
// columns and column gaps are laid out.
|
2018-10-23 16:08:59 +03:00
|
|
|
nscoord mExpectedISizeLeftOver = 0;
|
2013-04-16 16:52:49 +04:00
|
|
|
|
2014-12-04 11:57:17 +03:00
|
|
|
// The width (inline-size) of each column gap.
|
2018-10-23 16:08:59 +03:00
|
|
|
nscoord mColGap = NS_INTRINSICSIZE;
|
2013-04-16 16:52:49 +04:00
|
|
|
|
2014-12-04 11:57:17 +03:00
|
|
|
// The maximum bSize of any individual column during a reflow iteration.
|
2013-04-16 16:52:49 +04:00
|
|
|
// This parameter is set during each iteration of the binary search for
|
2014-12-04 11:57:17 +03:00
|
|
|
// the best column block-size.
|
2018-10-23 16:08:59 +03:00
|
|
|
nscoord mColMaxBSize = NS_INTRINSICSIZE;
|
2013-04-16 16:52:49 +04:00
|
|
|
|
|
|
|
// A boolean controlling whether or not we are balancing. This should be
|
2018-11-10 00:02:02 +03:00
|
|
|
// equivalent to mBalanceColCount != INT32_MAX.
|
2018-10-23 16:08:59 +03:00
|
|
|
bool mIsBalancing = false;
|
2013-04-16 16:52:49 +04:00
|
|
|
|
2014-12-04 11:57:17 +03:00
|
|
|
// The last known column block-size that was 'feasible'. A column bSize is
|
|
|
|
// feasible if all child content fits within the specified bSize.
|
2018-10-23 16:08:59 +03:00
|
|
|
nscoord mKnownFeasibleBSize = NS_INTRINSICSIZE;
|
2013-04-16 16:52:49 +04:00
|
|
|
|
2014-12-04 11:57:17 +03:00
|
|
|
// The last known block-size that was 'infeasible'. A column bSize is
|
|
|
|
// infeasible if not all child content fits within the specified bSize.
|
2018-10-23 16:08:59 +03:00
|
|
|
nscoord mKnownInfeasibleBSize = 0;
|
2013-07-25 19:34:31 +04:00
|
|
|
|
2014-12-04 11:57:17 +03:00
|
|
|
// block-size of the column set frame
|
2018-10-23 16:08:59 +03:00
|
|
|
nscoord mComputedBSize = NS_INTRINSICSIZE;
|
2013-07-25 19:34:31 +04:00
|
|
|
|
2014-12-04 11:57:17 +03:00
|
|
|
// The block-size "consumed" by previous-in-flows.
|
|
|
|
// The computed block-size should be equal to the block-size of the element
|
|
|
|
// (i.e. the computed block-size itself) plus the consumed block-size.
|
2018-10-23 16:08:59 +03:00
|
|
|
nscoord mConsumedBSize = 0;
|
2013-04-16 16:52:49 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Some data that is better calculated during reflow
|
|
|
|
*/
|
|
|
|
struct ColumnBalanceData {
|
2014-12-04 11:57:17 +03:00
|
|
|
// The maximum "content block-size" of any column
|
2018-10-23 16:09:16 +03:00
|
|
|
nscoord mMaxBSize = 0;
|
|
|
|
|
2014-12-04 11:57:17 +03:00
|
|
|
// The sum of the "content block-size" for all columns
|
2018-10-23 16:09:16 +03:00
|
|
|
nscoord mSumBSize = 0;
|
|
|
|
|
2014-12-04 11:57:17 +03:00
|
|
|
// The "content block-size" of the last column
|
2018-10-23 16:09:16 +03:00
|
|
|
nscoord mLastBSize = 0;
|
|
|
|
|
2014-12-04 11:57:17 +03:00
|
|
|
// The maximum "content block-size" of all columns that overflowed
|
|
|
|
// their available block-size
|
2018-10-23 16:09:16 +03:00
|
|
|
nscoord mMaxOverflowingBSize = 0;
|
|
|
|
|
2013-04-24 19:02:36 +04:00
|
|
|
// This flag determines whether the last reflow of children exceeded the
|
2014-12-04 11:57:17 +03:00
|
|
|
// computed block-size of the column set frame. If so, we set the bSize to
|
|
|
|
// this maximum allowable bSize, and continue reflow without balancing.
|
2018-10-23 16:09:16 +03:00
|
|
|
bool mHasExcessBSize = false;
|
2013-04-24 19:02:36 +04:00
|
|
|
|
2013-04-16 16:52:49 +04:00
|
|
|
void Reset() {
|
2014-12-04 11:57:16 +03:00
|
|
|
mMaxBSize = mSumBSize = mLastBSize = mMaxOverflowingBSize = 0;
|
|
|
|
mHasExcessBSize = false;
|
2013-04-16 16:52:49 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-07-21 13:36:38 +03:00
|
|
|
bool ReflowColumns(ReflowOutput& aDesiredSize,
|
2016-07-21 13:36:39 +03:00
|
|
|
const ReflowInput& aReflowInput,
|
2013-04-24 19:02:36 +04:00
|
|
|
nsReflowStatus& aReflowStatus, ReflowConfig& aConfig,
|
|
|
|
bool aLastColumnUnbounded, ColumnBalanceData& aColData);
|
|
|
|
|
2013-04-16 16:52:49 +04:00
|
|
|
/**
|
|
|
|
* The basic reflow strategy is to call this function repeatedly to
|
|
|
|
* obtain specific parameters that determine the layout of the
|
|
|
|
* columns. This function will compute those parameters from the CSS
|
|
|
|
* style. This function will also be responsible for implementing
|
|
|
|
* the state machine that controls column balancing.
|
|
|
|
*/
|
2016-07-21 13:36:39 +03:00
|
|
|
ReflowConfig ChooseColumnStrategy(const ReflowInput& aReflowInput,
|
2018-10-23 16:08:59 +03:00
|
|
|
bool aForceAuto);
|
2013-04-16 16:52:49 +04:00
|
|
|
|
2013-07-10 00:24:27 +04:00
|
|
|
/**
|
|
|
|
* Perform the binary search for the best balance height for this column set.
|
|
|
|
*
|
2016-07-21 13:36:39 +03:00
|
|
|
* @param aReflowInput The input parameters for the current reflow iteration.
|
2013-07-10 00:24:27 +04:00
|
|
|
* @param aPresContext The presentation context in which the current reflow
|
|
|
|
* iteration is occurring.
|
|
|
|
* @param aConfig The ReflowConfig object associated with this column set
|
|
|
|
* frame, generated by ChooseColumnStrategy().
|
|
|
|
* @param aColData A data structure used to keep track of data needed between
|
|
|
|
* successive iterations of the balancing process.
|
|
|
|
* @param aDesiredSize The final output size of the column set frame (output
|
|
|
|
* of reflow procedure).
|
|
|
|
* @param aUnboundedLastColumn A boolean value indicating that the last column
|
|
|
|
* can be of any height. Used during the first iteration of the
|
|
|
|
* balancing procedure to measure the height of all content in
|
|
|
|
* descendant frames of the column set.
|
|
|
|
* @param aRunWasFeasible An input/output parameter indicating whether or not
|
|
|
|
* the last iteration of the balancing loop was a feasible height to
|
|
|
|
* fit all content from descendant frames.
|
|
|
|
* @param aStatus A final reflow status of the column set frame, passed in as
|
|
|
|
* an output parameter.
|
|
|
|
*/
|
2016-07-21 13:36:39 +03:00
|
|
|
void FindBestBalanceBSize(const ReflowInput& aReflowInput,
|
2014-12-04 11:57:17 +03:00
|
|
|
nsPresContext* aPresContext, ReflowConfig& aConfig,
|
|
|
|
ColumnBalanceData& aColData,
|
2016-07-21 13:36:38 +03:00
|
|
|
ReflowOutput& aDesiredSize,
|
2014-12-04 11:57:17 +03:00
|
|
|
bool& aUnboundedLastColumn, bool& aRunWasFeasible,
|
|
|
|
nsReflowStatus& aStatus);
|
2013-04-16 16:52:49 +04:00
|
|
|
/**
|
|
|
|
* Reflow column children. Returns true iff the content that was reflowed
|
2014-12-04 11:57:16 +03:00
|
|
|
* fit into the mColMaxBSize.
|
2013-04-16 16:52:49 +04:00
|
|
|
*/
|
2016-07-21 13:36:38 +03:00
|
|
|
bool ReflowChildren(ReflowOutput& aDesiredSize,
|
2016-07-21 13:36:39 +03:00
|
|
|
const ReflowInput& aReflowInput, nsReflowStatus& aStatus,
|
2013-04-16 16:52:49 +04:00
|
|
|
const ReflowConfig& aConfig, bool aLastColumnUnbounded,
|
|
|
|
ColumnBalanceData& aColData);
|
2017-05-10 08:55:15 +03:00
|
|
|
|
2018-01-31 10:18:49 +03:00
|
|
|
void ForEachColumnRule(
|
|
|
|
const std::function<void(const nsRect& lineRect)>& aSetLineRect,
|
|
|
|
const nsPoint& aPt);
|
2018-08-13 20:48:42 +03:00
|
|
|
|
|
|
|
static nscoord ClampUsedColumnWidth(const nsStyleCoord& aColumnWidth);
|
2013-04-16 16:52:49 +04:00
|
|
|
};
|
2014-08-25 06:25:00 +04:00
|
|
|
|
|
|
|
#endif // nsColumnSetFrame_h___
|