2014-02-27 11:45:29 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code is subject to the terms of the Mozilla Public License
|
|
|
|
* version 2.0 (the "License"). You can obtain a copy of the License at
|
|
|
|
* http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2014-05-13 01:16:05 +04:00
|
|
|
/* rendering object for CSS "display: grid | inline-grid" */
|
2014-02-27 11:45:29 +04:00
|
|
|
|
|
|
|
#include "nsGridContainerFrame.h"
|
2014-05-13 01:16:05 +04:00
|
|
|
|
2015-03-26 21:57:39 +03:00
|
|
|
#include <algorithm> // for std::stable_sort
|
|
|
|
#include <limits>
|
2015-03-18 12:02:32 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2015-03-26 21:57:39 +03:00
|
|
|
#include "nsAbsoluteContainingBlock.h"
|
|
|
|
#include "nsAlgorithm.h" // for clamped()
|
2015-03-26 21:57:39 +03:00
|
|
|
#include "nsAutoPtr.h"
|
2014-05-20 03:57:00 +04:00
|
|
|
#include "nsCSSAnonBoxes.h"
|
2015-03-18 12:02:32 +03:00
|
|
|
#include "nsDataHashtable.h"
|
2015-03-26 21:57:39 +03:00
|
|
|
#include "nsDisplayList.h"
|
2015-03-18 12:02:32 +03:00
|
|
|
#include "nsHashKeys.h"
|
2015-03-26 21:57:39 +03:00
|
|
|
#include "nsIFrameInlines.h"
|
2014-02-27 11:45:29 +04:00
|
|
|
#include "nsPresContext.h"
|
2015-01-15 00:59:59 +03:00
|
|
|
#include "nsReadableUtils.h"
|
2015-03-18 12:02:32 +03:00
|
|
|
#include "nsRuleNode.h"
|
2014-02-27 11:45:29 +04:00
|
|
|
#include "nsStyleContext.h"
|
|
|
|
|
2014-07-24 12:30:07 +04:00
|
|
|
using namespace mozilla;
|
2015-03-18 12:02:32 +03:00
|
|
|
typedef nsGridContainerFrame::TrackSize TrackSize;
|
2015-04-30 21:42:50 +03:00
|
|
|
const uint32_t nsGridContainerFrame::kTranslatedMaxLine =
|
|
|
|
uint32_t(nsStyleGridLine::kMaxLine - nsStyleGridLine::kMinLine - 1);
|
2015-05-06 00:53:22 +03:00
|
|
|
const uint32_t nsGridContainerFrame::kAutoLine = kTranslatedMaxLine + 3457U;
|
2014-07-24 12:30:07 +04:00
|
|
|
|
2015-03-26 21:57:39 +03:00
|
|
|
class nsGridContainerFrame::GridItemCSSOrderIterator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum OrderState { eUnknownOrder, eKnownOrdered, eKnownUnordered };
|
2015-05-06 00:53:22 +03:00
|
|
|
enum ChildFilter { eSkipPlaceholders, eIncludeAll };
|
2015-03-26 21:57:39 +03:00
|
|
|
GridItemCSSOrderIterator(nsIFrame* aGridContainer,
|
|
|
|
nsIFrame::ChildListID aListID,
|
2015-05-06 00:53:22 +03:00
|
|
|
ChildFilter aFilter = eSkipPlaceholders,
|
2015-03-26 21:57:39 +03:00
|
|
|
OrderState aState = eUnknownOrder)
|
|
|
|
: mChildren(aGridContainer->GetChildList(aListID))
|
|
|
|
, mArrayIndex(0)
|
2015-05-06 00:53:22 +03:00
|
|
|
, mSkipPlaceholders(aFilter == eSkipPlaceholders)
|
2015-03-26 21:57:39 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
, mGridContainer(aGridContainer)
|
|
|
|
, mListID(aListID)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
size_t count = 0;
|
|
|
|
bool isOrdered = aState != eKnownUnordered;
|
|
|
|
if (aState == eUnknownOrder) {
|
|
|
|
auto maxOrder = std::numeric_limits<int32_t>::min();
|
|
|
|
for (nsFrameList::Enumerator e(mChildren); !e.AtEnd(); e.Next()) {
|
|
|
|
++count;
|
|
|
|
int32_t order = e.get()->StylePosition()->mOrder;
|
|
|
|
if (order < maxOrder) {
|
|
|
|
isOrdered = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
maxOrder = order;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isOrdered) {
|
|
|
|
mEnumerator.emplace(mChildren);
|
|
|
|
} else {
|
|
|
|
count *= 2; // XXX somewhat arbitrary estimate for now...
|
|
|
|
mArray.emplace(count);
|
|
|
|
for (nsFrameList::Enumerator e(mChildren); !e.AtEnd(); e.Next()) {
|
|
|
|
mArray->AppendElement(e.get());
|
|
|
|
}
|
|
|
|
// XXX replace this with nsTArray::StableSort when bug 1147091 is fixed.
|
|
|
|
std::stable_sort(mArray->begin(), mArray->end(), IsCSSOrderLessThan);
|
|
|
|
}
|
2015-05-06 00:53:22 +03:00
|
|
|
|
|
|
|
if (mSkipPlaceholders) {
|
|
|
|
SkipPlaceholders();
|
|
|
|
}
|
2015-03-26 21:57:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* operator*() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!AtEnd());
|
|
|
|
if (mEnumerator) {
|
|
|
|
return mEnumerator->get();
|
|
|
|
}
|
|
|
|
return (*mArray)[mArrayIndex];
|
|
|
|
}
|
|
|
|
|
2015-05-06 00:53:22 +03:00
|
|
|
/**
|
|
|
|
* Skip over placeholder children.
|
|
|
|
*/
|
|
|
|
void SkipPlaceholders()
|
|
|
|
{
|
|
|
|
if (mEnumerator) {
|
|
|
|
for (; !mEnumerator->AtEnd(); mEnumerator->Next()) {
|
|
|
|
nsIFrame* child = mEnumerator->get();
|
|
|
|
if (child->GetType() != nsGkAtoms::placeholderFrame) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (; mArrayIndex < mArray->Length(); ++mArrayIndex) {
|
|
|
|
nsIFrame* child = (*mArray)[mArrayIndex];
|
|
|
|
if (child->GetType() != nsGkAtoms::placeholderFrame) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 21:57:39 +03:00
|
|
|
bool AtEnd() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mEnumerator || mArrayIndex <= mArray->Length());
|
|
|
|
return mEnumerator ? mEnumerator->AtEnd() : mArrayIndex >= mArray->Length();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Next()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsFrameList list = mGridContainer->GetChildList(mListID);
|
|
|
|
MOZ_ASSERT(list.FirstChild() == mChildren.FirstChild() &&
|
|
|
|
list.LastChild() == mChildren.LastChild(),
|
|
|
|
"the list of child frames must not change while iterating!");
|
|
|
|
#endif
|
|
|
|
if (mEnumerator) {
|
|
|
|
mEnumerator->Next();
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(mArrayIndex < mArray->Length(), "iterating past end");
|
|
|
|
++mArrayIndex;
|
|
|
|
}
|
2015-05-06 00:53:22 +03:00
|
|
|
if (mSkipPlaceholders) {
|
|
|
|
SkipPlaceholders();
|
|
|
|
}
|
2015-03-26 21:57:39 +03:00
|
|
|
}
|
|
|
|
|
2015-05-06 00:53:22 +03:00
|
|
|
void Reset(ChildFilter aFilter = eSkipPlaceholders)
|
2015-03-26 21:57:39 +03:00
|
|
|
{
|
|
|
|
if (mEnumerator) {
|
|
|
|
mEnumerator.reset();
|
|
|
|
mEnumerator.emplace(mChildren);
|
|
|
|
} else {
|
|
|
|
mArrayIndex = 0;
|
|
|
|
}
|
2015-05-06 00:53:22 +03:00
|
|
|
mSkipPlaceholders = aFilter == eSkipPlaceholders;
|
|
|
|
if (mSkipPlaceholders) {
|
|
|
|
SkipPlaceholders();
|
|
|
|
}
|
2015-03-26 21:57:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ItemsAreAlreadyInOrder() const { return mEnumerator.isSome(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
static bool IsCSSOrderLessThan(nsIFrame* const& a, nsIFrame* const& b)
|
|
|
|
{ return a->StylePosition()->mOrder < b->StylePosition()->mOrder; }
|
|
|
|
|
|
|
|
nsFrameList mChildren;
|
|
|
|
// Used if child list is already in ascending 'order'.
|
|
|
|
Maybe<nsFrameList::Enumerator> mEnumerator;
|
|
|
|
// Used if child list is *not* in ascending 'order'.
|
|
|
|
Maybe<nsTArray<nsIFrame*>> mArray;
|
|
|
|
size_t mArrayIndex;
|
2015-05-06 00:53:22 +03:00
|
|
|
// Skip placeholder children in the iteration?
|
|
|
|
bool mSkipPlaceholders;
|
2015-03-26 21:57:39 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsIFrame* mGridContainer;
|
|
|
|
nsIFrame::ChildListID mListID;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2015-03-18 12:02:32 +03:00
|
|
|
/**
|
|
|
|
* Search for the aNth occurrence of aName in aNameList (forward), starting at
|
|
|
|
* the zero-based aFromIndex, and return the 1-based index (line number).
|
|
|
|
* Also take into account there is an unconditional match at aImplicitLine
|
|
|
|
* unless it's zero.
|
2015-04-30 21:42:50 +03:00
|
|
|
* Return zero if aNth occurrences can't be found. In that case, aNth has
|
|
|
|
* been decremented with the number of occurrences that were found (if any).
|
2015-03-18 12:02:32 +03:00
|
|
|
*/
|
|
|
|
static uint32_t
|
2015-04-30 21:42:50 +03:00
|
|
|
FindLine(const nsString& aName, int32_t* aNth,
|
2015-03-18 12:02:32 +03:00
|
|
|
uint32_t aFromIndex, uint32_t aImplicitLine,
|
|
|
|
const nsTArray<nsTArray<nsString>>& aNameList)
|
|
|
|
{
|
2015-04-30 21:42:50 +03:00
|
|
|
MOZ_ASSERT(aNth && *aNth > 0);
|
|
|
|
int32_t nth = *aNth;
|
2015-03-18 12:02:32 +03:00
|
|
|
const uint32_t len = aNameList.Length();
|
|
|
|
uint32_t line;
|
|
|
|
uint32_t i = aFromIndex;
|
|
|
|
for (; i < len; i = line) {
|
|
|
|
line = i + 1;
|
|
|
|
if (line == aImplicitLine || aNameList[i].Contains(aName)) {
|
2015-04-30 21:42:50 +03:00
|
|
|
if (--nth == 0) {
|
|
|
|
return line;
|
2015-03-18 12:02:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (aImplicitLine > i) {
|
|
|
|
// aImplicitLine is after the lines we searched above so it's last.
|
|
|
|
// (grid-template-areas has more tracks than grid-template-[rows|columns])
|
2015-04-30 21:42:50 +03:00
|
|
|
if (--nth == 0) {
|
|
|
|
return aImplicitLine;
|
|
|
|
}
|
2015-03-18 12:02:32 +03:00
|
|
|
}
|
2015-04-30 21:42:50 +03:00
|
|
|
MOZ_ASSERT(nth > 0, "should have returned a valid line above already");
|
|
|
|
*aNth = nth;
|
|
|
|
return 0;
|
2015-03-18 12:02:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see FindLine, this function does the same but searches in reverse.
|
|
|
|
*/
|
|
|
|
static uint32_t
|
2015-04-30 21:42:50 +03:00
|
|
|
RFindLine(const nsString& aName, int32_t* aNth,
|
2015-03-18 12:02:32 +03:00
|
|
|
uint32_t aFromIndex, uint32_t aImplicitLine,
|
|
|
|
const nsTArray<nsTArray<nsString>>& aNameList)
|
|
|
|
{
|
2015-04-30 21:42:50 +03:00
|
|
|
MOZ_ASSERT(aNth && *aNth > 0);
|
|
|
|
int32_t nth = *aNth;
|
2015-03-18 12:02:32 +03:00
|
|
|
const uint32_t len = aNameList.Length();
|
|
|
|
// The implicit line may be beyond the length of aNameList so we match this
|
2015-04-30 21:42:50 +03:00
|
|
|
// line first if it's within the len..aFromIndex range.
|
2015-03-18 12:02:32 +03:00
|
|
|
if (aImplicitLine > len && aImplicitLine < aFromIndex) {
|
2015-04-30 21:42:50 +03:00
|
|
|
if (--nth == 0) {
|
|
|
|
return aImplicitLine;
|
2015-03-18 12:02:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
uint32_t i = aFromIndex == 0 ? len : std::min(aFromIndex, len);
|
|
|
|
for (; i; --i) {
|
|
|
|
if (i == aImplicitLine || aNameList[i - 1].Contains(aName)) {
|
2015-04-30 21:42:50 +03:00
|
|
|
if (--nth == 0) {
|
|
|
|
return i;
|
2015-03-18 12:02:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-30 21:42:50 +03:00
|
|
|
MOZ_ASSERT(nth > 0, "should have returned a valid line above already");
|
|
|
|
*aNth = nth;
|
|
|
|
return 0;
|
2015-03-18 12:02:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t
|
2015-04-30 21:42:50 +03:00
|
|
|
FindNamedLine(const nsString& aName, int32_t* aNth,
|
2015-03-18 12:02:32 +03:00
|
|
|
uint32_t aFromIndex, uint32_t aImplicitLine,
|
|
|
|
const nsTArray<nsTArray<nsString>>& aNameList)
|
|
|
|
{
|
2015-04-30 21:42:50 +03:00
|
|
|
MOZ_ASSERT(aNth && *aNth != 0);
|
|
|
|
if (*aNth > 0) {
|
2015-03-18 12:02:32 +03:00
|
|
|
return ::FindLine(aName, aNth, aFromIndex, aImplicitLine, aNameList);
|
|
|
|
}
|
2015-04-30 21:42:50 +03:00
|
|
|
int32_t nth = -*aNth;
|
|
|
|
int32_t line = ::RFindLine(aName, &nth, aFromIndex, aImplicitLine, aNameList);
|
|
|
|
*aNth = -nth;
|
|
|
|
return line;
|
2015-03-18 12:02:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A convenience method to lookup a name in 'grid-template-areas'.
|
|
|
|
* @param aStyle the StylePosition() for the grid container
|
|
|
|
* @return null if not found
|
|
|
|
*/
|
|
|
|
static const css::GridNamedArea*
|
|
|
|
FindNamedArea(const nsSubstring& aName, const nsStylePosition* aStyle)
|
|
|
|
{
|
|
|
|
if (!aStyle->mGridTemplateAreas) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
const nsTArray<css::GridNamedArea>& areas =
|
|
|
|
aStyle->mGridTemplateAreas->mNamedAreas;
|
|
|
|
size_t len = areas.Length();
|
|
|
|
for (size_t i = 0; i < len; ++i) {
|
|
|
|
const css::GridNamedArea& area = areas[i];
|
|
|
|
if (area.mName == aName) {
|
|
|
|
return &area;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-01-15 00:59:59 +03:00
|
|
|
// Return true if aString ends in aSuffix and has at least one character before
|
|
|
|
// the suffix. Assign aIndex to where the suffix starts.
|
|
|
|
static bool
|
|
|
|
IsNameWithSuffix(const nsString& aString, const nsString& aSuffix,
|
|
|
|
uint32_t* aIndex)
|
|
|
|
{
|
|
|
|
if (StringEndsWith(aString, aSuffix)) {
|
|
|
|
*aIndex = aString.Length() - aSuffix.Length();
|
|
|
|
return *aIndex != 0;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
IsNameWithEndSuffix(const nsString& aString, uint32_t* aIndex)
|
|
|
|
{
|
|
|
|
return IsNameWithSuffix(aString, NS_LITERAL_STRING("-end"), aIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
IsNameWithStartSuffix(const nsString& aString, uint32_t* aIndex)
|
|
|
|
{
|
|
|
|
return IsNameWithSuffix(aString, NS_LITERAL_STRING("-start"), aIndex);
|
|
|
|
}
|
|
|
|
|
2015-03-26 21:57:39 +03:00
|
|
|
static nscoord
|
|
|
|
GridLinePosition(uint32_t aLine, const nsTArray<TrackSize>& aTrackSizes)
|
|
|
|
{
|
2015-04-30 21:42:50 +03:00
|
|
|
const uint32_t endIndex = aLine;
|
2015-03-26 21:57:39 +03:00
|
|
|
MOZ_ASSERT(endIndex <= aTrackSizes.Length(), "aTrackSizes is too small");
|
|
|
|
nscoord pos = 0;
|
|
|
|
for (uint32_t i = 0; i < endIndex; ++i) {
|
|
|
|
pos += aTrackSizes[i].mBase;
|
|
|
|
}
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
2015-03-26 21:57:39 +03:00
|
|
|
/**
|
|
|
|
* (XXX share this utility function with nsFlexContainerFrame at some point)
|
|
|
|
*
|
|
|
|
* Helper for BuildDisplayList, to implement this special-case for grid
|
|
|
|
* items from the spec:
|
|
|
|
* The painting order of grid items is exactly the same as inline blocks,
|
|
|
|
* except that [...] 'z-index' values other than 'auto' create a stacking
|
|
|
|
* context even if 'position' is 'static'.
|
|
|
|
* http://dev.w3.org/csswg/css-grid/#z-order
|
|
|
|
*/
|
|
|
|
static uint32_t
|
|
|
|
GetDisplayFlagsForGridItem(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
const nsStylePosition* pos = aFrame->StylePosition();
|
|
|
|
if (pos->mZIndex.GetUnit() == eStyleUnit_Integer) {
|
|
|
|
return nsIFrame::DISPLAY_CHILD_FORCE_STACKING_CONTEXT;
|
|
|
|
}
|
|
|
|
return nsIFrame::DISPLAY_CHILD_FORCE_PSEUDO_STACKING_CONTEXT;
|
|
|
|
}
|
|
|
|
|
2014-02-27 11:45:29 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Frame class boilerplate
|
|
|
|
// =======================
|
|
|
|
|
|
|
|
NS_QUERYFRAME_HEAD(nsGridContainerFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsGridContainerFrame)
|
2014-05-13 01:16:05 +04:00
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
|
2014-02-27 11:45:29 +04:00
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsGridContainerFrame)
|
|
|
|
|
2014-05-25 02:20:40 +04:00
|
|
|
nsContainerFrame*
|
2014-02-27 11:45:29 +04:00
|
|
|
NS_NewGridContainerFrame(nsIPresShell* aPresShell,
|
|
|
|
nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsGridContainerFrame(aContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// nsGridContainerFrame Method Implementations
|
|
|
|
// ===========================================
|
|
|
|
|
2015-03-26 21:57:39 +03:00
|
|
|
/*static*/ const nsRect&
|
|
|
|
nsGridContainerFrame::GridItemCB(nsIFrame* aChild)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT((aChild->GetStateBits() & NS_FRAME_OUT_OF_FLOW) &&
|
|
|
|
aChild->IsAbsolutelyPositioned());
|
|
|
|
nsRect* cb = static_cast<nsRect*>(aChild->Properties().Get(
|
|
|
|
GridItemContainingBlockRect()));
|
|
|
|
MOZ_ASSERT(cb, "this method must only be called on grid items, and the grid "
|
|
|
|
"container should've reflowed this item by now and set up cb");
|
|
|
|
return *cb;
|
|
|
|
}
|
|
|
|
|
2015-01-15 00:59:59 +03:00
|
|
|
void
|
|
|
|
nsGridContainerFrame::AddImplicitNamedAreas(
|
|
|
|
const nsTArray<nsTArray<nsString>>& aLineNameLists)
|
|
|
|
{
|
|
|
|
// http://dev.w3.org/csswg/css-grid/#implicit-named-areas
|
|
|
|
// XXX this just checks x-start .. x-end in one dimension and there's
|
|
|
|
// no other error checking. A few wrong cases (maybe):
|
|
|
|
// (x-start x-end)
|
|
|
|
// (x-start) 0 (x-start) 0 (x-end)
|
|
|
|
// (x-end) 0 (x-start) 0 (x-end)
|
|
|
|
// (x-start) 0 (x-end) 0 (x-start) 0 (x-end)
|
2015-04-30 21:42:50 +03:00
|
|
|
const uint32_t len =
|
|
|
|
std::min(aLineNameLists.Length(), size_t(nsStyleGridLine::kMaxLine));
|
2015-01-15 00:59:59 +03:00
|
|
|
nsTHashtable<nsStringHashKey> currentStarts;
|
|
|
|
ImplicitNamedAreas* areas = GetImplicitNamedAreas();
|
|
|
|
for (uint32_t i = 0; i < len; ++i) {
|
|
|
|
const nsTArray<nsString>& names(aLineNameLists[i]);
|
|
|
|
const uint32_t jLen = names.Length();
|
|
|
|
for (uint32_t j = 0; j < jLen; ++j) {
|
|
|
|
const nsString& name = names[j];
|
|
|
|
uint32_t index;
|
|
|
|
if (::IsNameWithStartSuffix(name, &index)) {
|
|
|
|
currentStarts.PutEntry(nsDependentSubstring(name, 0, index));
|
|
|
|
} else if (::IsNameWithEndSuffix(name, &index)) {
|
|
|
|
nsDependentSubstring area(name, 0, index);
|
|
|
|
if (currentStarts.Contains(area)) {
|
|
|
|
if (!areas) {
|
|
|
|
areas = new ImplicitNamedAreas;
|
|
|
|
Properties().Set(ImplicitNamedAreasProperty(), areas);
|
|
|
|
}
|
|
|
|
areas->PutEntry(area);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGridContainerFrame::InitImplicitNamedAreas(const nsStylePosition* aStyle)
|
|
|
|
{
|
|
|
|
ImplicitNamedAreas* areas = GetImplicitNamedAreas();
|
|
|
|
if (areas) {
|
|
|
|
// Clear it, but reuse the hashtable itself for now. We'll remove it
|
|
|
|
// below if it isn't needed anymore.
|
|
|
|
areas->Clear();
|
|
|
|
}
|
|
|
|
AddImplicitNamedAreas(aStyle->mGridTemplateColumns.mLineNameLists);
|
|
|
|
AddImplicitNamedAreas(aStyle->mGridTemplateRows.mLineNameLists);
|
|
|
|
if (areas && areas->Count() == 0) {
|
|
|
|
Properties().Delete(ImplicitNamedAreasProperty());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-30 21:42:50 +03:00
|
|
|
int32_t
|
2015-03-18 12:02:32 +03:00
|
|
|
nsGridContainerFrame::ResolveLine(
|
|
|
|
const nsStyleGridLine& aLine,
|
|
|
|
int32_t aNth,
|
|
|
|
uint32_t aFromIndex,
|
|
|
|
const nsTArray<nsTArray<nsString>>& aLineNameList,
|
|
|
|
uint32_t GridNamedArea::* aAreaStart,
|
|
|
|
uint32_t GridNamedArea::* aAreaEnd,
|
|
|
|
uint32_t aExplicitGridEnd,
|
|
|
|
LineRangeSide aSide,
|
|
|
|
const nsStylePosition* aStyle)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!aLine.IsAuto());
|
2015-04-30 21:42:50 +03:00
|
|
|
int32_t line = 0;
|
2015-03-18 12:02:32 +03:00
|
|
|
if (aLine.mLineName.IsEmpty()) {
|
|
|
|
MOZ_ASSERT(aNth != 0, "css-grid 9.2: <integer> must not be zero.");
|
2015-04-30 21:42:50 +03:00
|
|
|
line = int32_t(aFromIndex) + aNth;
|
2015-03-18 12:02:32 +03:00
|
|
|
} else {
|
|
|
|
if (aNth == 0) {
|
|
|
|
// <integer> was omitted; treat it as 1.
|
|
|
|
aNth = 1;
|
|
|
|
}
|
|
|
|
bool isNameOnly = !aLine.mHasSpan && aLine.mInteger == 0;
|
|
|
|
if (isNameOnly) {
|
|
|
|
const GridNamedArea* area = ::FindNamedArea(aLine.mLineName, aStyle);
|
|
|
|
if (area || HasImplicitNamedArea(aLine.mLineName)) {
|
|
|
|
// The given name is a named area - look for explicit lines named
|
|
|
|
// <name>-start/-end depending on which side we're resolving.
|
|
|
|
// http://dev.w3.org/csswg/css-grid/#grid-placement-slot
|
|
|
|
uint32_t implicitLine = 0;
|
|
|
|
nsAutoString lineName(aLine.mLineName);
|
|
|
|
if (aSide == eLineRangeSideStart) {
|
|
|
|
lineName.AppendLiteral("-start");
|
|
|
|
implicitLine = area ? area->*aAreaStart : 0;
|
|
|
|
} else {
|
|
|
|
lineName.AppendLiteral("-end");
|
|
|
|
implicitLine = area ? area->*aAreaEnd : 0;
|
|
|
|
}
|
|
|
|
// XXX must Implicit Named Areas have all four lines?
|
|
|
|
// http://dev.w3.org/csswg/css-grid/#implicit-named-areas
|
2015-04-30 21:42:50 +03:00
|
|
|
line = ::FindNamedLine(lineName, &aNth, aFromIndex, implicitLine,
|
2015-03-18 12:02:32 +03:00
|
|
|
aLineNameList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (line == 0) {
|
|
|
|
// If mLineName ends in -start/-end, try the prefix as a named area.
|
|
|
|
uint32_t implicitLine = 0;
|
|
|
|
uint32_t index;
|
|
|
|
auto GridNamedArea::* areaEdge = aAreaStart;
|
|
|
|
bool found = ::IsNameWithStartSuffix(aLine.mLineName, &index);
|
|
|
|
if (!found) {
|
|
|
|
found = ::IsNameWithEndSuffix(aLine.mLineName, &index);
|
|
|
|
areaEdge = aAreaEnd;
|
|
|
|
}
|
|
|
|
if (found) {
|
|
|
|
const GridNamedArea* area =
|
|
|
|
::FindNamedArea(nsDependentSubstring(aLine.mLineName, 0, index),
|
|
|
|
aStyle);
|
|
|
|
if (area) {
|
|
|
|
implicitLine = area->*areaEdge;
|
|
|
|
}
|
|
|
|
}
|
2015-04-30 21:42:50 +03:00
|
|
|
line = ::FindNamedLine(aLine.mLineName, &aNth, aFromIndex, implicitLine,
|
2015-03-18 12:02:32 +03:00
|
|
|
aLineNameList);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (line == 0) {
|
2015-04-30 21:42:50 +03:00
|
|
|
MOZ_ASSERT(aNth != 0, "we found all N named lines but 'line' is zero!");
|
|
|
|
int32_t edgeLine;
|
2015-03-18 12:02:32 +03:00
|
|
|
if (aLine.mHasSpan) {
|
|
|
|
// http://dev.w3.org/csswg/css-grid/#grid-placement-span-int
|
2015-04-30 21:42:50 +03:00
|
|
|
// 'span <custom-ident> N'
|
|
|
|
edgeLine = aSide == eLineRangeSideStart ? 1 : aExplicitGridEnd;
|
2015-03-18 12:02:32 +03:00
|
|
|
} else {
|
|
|
|
// http://dev.w3.org/csswg/css-grid/#grid-placement-int
|
2015-04-30 21:42:50 +03:00
|
|
|
// '<custom-ident> N'
|
|
|
|
edgeLine = aNth < 0 ? 1 : aExplicitGridEnd;
|
2015-03-18 12:02:32 +03:00
|
|
|
}
|
2015-04-30 21:42:50 +03:00
|
|
|
// "If not enough lines with that name exist, all lines in the implicit
|
|
|
|
// grid are assumed to have that name..."
|
|
|
|
line = edgeLine + aNth;
|
2015-03-18 12:02:32 +03:00
|
|
|
}
|
|
|
|
}
|
2015-04-30 21:42:50 +03:00
|
|
|
return clamped(line, nsStyleGridLine::kMinLine, nsStyleGridLine::kMaxLine);
|
2015-03-18 12:02:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsGridContainerFrame::LinePair
|
|
|
|
nsGridContainerFrame::ResolveLineRangeHelper(
|
|
|
|
const nsStyleGridLine& aStart,
|
|
|
|
const nsStyleGridLine& aEnd,
|
|
|
|
const nsTArray<nsTArray<nsString>>& aLineNameList,
|
|
|
|
uint32_t GridNamedArea::* aAreaStart,
|
|
|
|
uint32_t GridNamedArea::* aAreaEnd,
|
|
|
|
uint32_t aExplicitGridEnd,
|
|
|
|
const nsStylePosition* aStyle)
|
|
|
|
{
|
2015-04-30 21:42:50 +03:00
|
|
|
MOZ_ASSERT(int32_t(nsGridContainerFrame::kAutoLine) > nsStyleGridLine::kMaxLine);
|
2015-04-30 21:42:50 +03:00
|
|
|
|
2015-03-18 12:02:32 +03:00
|
|
|
if (aStart.mHasSpan) {
|
|
|
|
if (aEnd.mHasSpan || aEnd.IsAuto()) {
|
|
|
|
// http://dev.w3.org/csswg/css-grid/#grid-placement-errors
|
|
|
|
if (aStart.mLineName.IsEmpty()) {
|
|
|
|
// span <integer> / span *
|
|
|
|
// span <integer> / auto
|
2015-04-30 21:42:50 +03:00
|
|
|
return LinePair(kAutoLine, aStart.mInteger);
|
2015-03-18 12:02:32 +03:00
|
|
|
}
|
|
|
|
// span <custom-ident> / span *
|
|
|
|
// span <custom-ident> / auto
|
2015-04-30 21:42:50 +03:00
|
|
|
return LinePair(kAutoLine, 1); // XXX subgrid explicit size instead of 1?
|
2015-03-18 12:02:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
auto end = ResolveLine(aEnd, aEnd.mInteger, 0, aLineNameList, aAreaStart,
|
|
|
|
aAreaEnd, aExplicitGridEnd, eLineRangeSideEnd,
|
|
|
|
aStyle);
|
|
|
|
int32_t span = aStart.mInteger == 0 ? 1 : aStart.mInteger;
|
2015-04-30 21:42:50 +03:00
|
|
|
if (end <= 1) {
|
|
|
|
// The end is at or before the first explicit line, thus all lines before
|
|
|
|
// it match <custom-ident> since they're implicit.
|
|
|
|
int32_t start = std::max(end - span, nsStyleGridLine::kMinLine);
|
|
|
|
return LinePair(start, end);
|
|
|
|
}
|
2015-03-18 12:02:32 +03:00
|
|
|
auto start = ResolveLine(aStart, -span, end, aLineNameList, aAreaStart,
|
|
|
|
aAreaEnd, aExplicitGridEnd, eLineRangeSideStart,
|
|
|
|
aStyle);
|
|
|
|
return LinePair(start, end);
|
|
|
|
}
|
|
|
|
|
2015-04-30 21:42:50 +03:00
|
|
|
int32_t start = kAutoLine;
|
2015-04-30 21:42:50 +03:00
|
|
|
if (aStart.IsAuto()) {
|
|
|
|
if (aEnd.IsAuto()) {
|
|
|
|
// auto / auto
|
|
|
|
return LinePair(start, 1); // XXX subgrid explicit size instead of 1?
|
|
|
|
}
|
|
|
|
if (aEnd.mHasSpan) {
|
|
|
|
if (aEnd.mLineName.IsEmpty()) {
|
|
|
|
// auto / span <integer>
|
|
|
|
MOZ_ASSERT(aEnd.mInteger != 0);
|
|
|
|
return LinePair(start, aEnd.mInteger);
|
|
|
|
}
|
|
|
|
// http://dev.w3.org/csswg/css-grid/#grid-placement-errors
|
|
|
|
// auto / span <custom-ident>
|
|
|
|
return LinePair(start, 1); // XXX subgrid explicit size instead of 1?
|
|
|
|
}
|
|
|
|
} else {
|
2015-03-18 12:02:32 +03:00
|
|
|
start = ResolveLine(aStart, aStart.mInteger, 0, aLineNameList, aAreaStart,
|
|
|
|
aAreaEnd, aExplicitGridEnd, eLineRangeSideStart,
|
|
|
|
aStyle);
|
2015-04-30 21:42:50 +03:00
|
|
|
if (aEnd.IsAuto()) {
|
|
|
|
// A "definite line / auto" should resolve the auto to 'span 1'.
|
|
|
|
// The error handling in ResolveLineRange will make that happen and also
|
|
|
|
// clamp the end line correctly if we return "start / start".
|
|
|
|
return LinePair(start, start);
|
2015-03-18 12:02:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-30 21:42:50 +03:00
|
|
|
uint32_t from = 0;
|
|
|
|
int32_t nth = aEnd.mInteger == 0 ? 1 : aEnd.mInteger;
|
|
|
|
if (aEnd.mHasSpan) {
|
|
|
|
if (MOZ_UNLIKELY(start < 0)) {
|
|
|
|
if (aEnd.mLineName.IsEmpty()) {
|
|
|
|
return LinePair(start, start + nth);
|
|
|
|
}
|
|
|
|
// Fall through and start searching from the start of the grid (from=0).
|
|
|
|
} else {
|
|
|
|
if (start >= int32_t(aExplicitGridEnd)) {
|
|
|
|
// The start is at or after the last explicit line, thus all lines
|
|
|
|
// after it match <custom-ident> since they're implicit.
|
|
|
|
return LinePair(start, std::min(start + nth, nsStyleGridLine::kMaxLine));
|
|
|
|
}
|
|
|
|
from = start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto end = ResolveLine(aEnd, nth, from, aLineNameList, aAreaStart,
|
2015-03-18 12:02:32 +03:00
|
|
|
aAreaEnd, aExplicitGridEnd, eLineRangeSideEnd, aStyle);
|
2015-04-30 21:42:50 +03:00
|
|
|
if (start == int32_t(kAutoLine)) {
|
2015-04-30 21:42:50 +03:00
|
|
|
// auto / definite line
|
2015-04-30 21:42:50 +03:00
|
|
|
start = std::max(nsStyleGridLine::kMinLine, end - 1);
|
2015-03-18 12:02:32 +03:00
|
|
|
}
|
|
|
|
return LinePair(start, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGridContainerFrame::LineRange
|
|
|
|
nsGridContainerFrame::ResolveLineRange(
|
|
|
|
const nsStyleGridLine& aStart,
|
|
|
|
const nsStyleGridLine& aEnd,
|
|
|
|
const nsTArray<nsTArray<nsString>>& aLineNameList,
|
|
|
|
uint32_t GridNamedArea::* aAreaStart,
|
|
|
|
uint32_t GridNamedArea::* aAreaEnd,
|
|
|
|
uint32_t aExplicitGridEnd,
|
|
|
|
const nsStylePosition* aStyle)
|
|
|
|
{
|
|
|
|
LinePair r = ResolveLineRangeHelper(aStart, aEnd, aLineNameList, aAreaStart,
|
|
|
|
aAreaEnd, aExplicitGridEnd, aStyle);
|
2015-04-30 21:42:50 +03:00
|
|
|
MOZ_ASSERT(r.second != int32_t(kAutoLine));
|
2015-03-18 12:02:32 +03:00
|
|
|
|
2015-04-30 21:42:50 +03:00
|
|
|
if (r.first == int32_t(kAutoLine)) {
|
2015-04-30 21:42:50 +03:00
|
|
|
// r.second is a span, clamp it to kMaxLine - 1 so that the returned
|
|
|
|
// range has a HypotheticalEnd <= kMaxLine.
|
|
|
|
// http://dev.w3.org/csswg/css-grid/#overlarge-grids
|
|
|
|
r.second = std::min(r.second, nsStyleGridLine::kMaxLine - 1);
|
|
|
|
} else if (r.second <= r.first) {
|
|
|
|
// http://dev.w3.org/csswg/css-grid/#grid-placement-errors
|
|
|
|
if (MOZ_UNLIKELY(r.first == nsStyleGridLine::kMaxLine)) {
|
|
|
|
r.first = nsStyleGridLine::kMaxLine - 1;
|
|
|
|
}
|
2015-04-30 21:42:50 +03:00
|
|
|
r.second = r.first + 1; // XXX subgrid explicit size instead of 1?
|
2015-03-18 12:02:32 +03:00
|
|
|
}
|
|
|
|
return LineRange(r.first, r.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGridContainerFrame::GridArea
|
|
|
|
nsGridContainerFrame::PlaceDefinite(nsIFrame* aChild,
|
|
|
|
const nsStylePosition* aStyle)
|
|
|
|
{
|
|
|
|
const nsStylePosition* itemStyle = aChild->StylePosition();
|
|
|
|
return GridArea(
|
|
|
|
ResolveLineRange(itemStyle->mGridColumnStart, itemStyle->mGridColumnEnd,
|
|
|
|
aStyle->mGridTemplateColumns.mLineNameLists,
|
|
|
|
&GridNamedArea::mColumnStart, &GridNamedArea::mColumnEnd,
|
|
|
|
mExplicitGridColEnd, aStyle),
|
|
|
|
ResolveLineRange(itemStyle->mGridRowStart, itemStyle->mGridRowEnd,
|
|
|
|
aStyle->mGridTemplateRows.mLineNameLists,
|
|
|
|
&GridNamedArea::mRowStart, &GridNamedArea::mRowEnd,
|
|
|
|
mExplicitGridRowEnd, aStyle));
|
|
|
|
}
|
|
|
|
|
2015-03-26 21:57:39 +03:00
|
|
|
nsGridContainerFrame::LineRange
|
|
|
|
nsGridContainerFrame::ResolveAbsPosLineRange(
|
|
|
|
const nsStyleGridLine& aStart,
|
|
|
|
const nsStyleGridLine& aEnd,
|
|
|
|
const nsTArray<nsTArray<nsString>>& aLineNameList,
|
|
|
|
uint32_t GridNamedArea::* aAreaStart,
|
|
|
|
uint32_t GridNamedArea::* aAreaEnd,
|
|
|
|
uint32_t aExplicitGridEnd,
|
2015-04-30 21:42:50 +03:00
|
|
|
int32_t aGridStart,
|
|
|
|
int32_t aGridEnd,
|
2015-03-26 21:57:39 +03:00
|
|
|
const nsStylePosition* aStyle)
|
|
|
|
{
|
|
|
|
if (aStart.IsAuto()) {
|
|
|
|
if (aEnd.IsAuto()) {
|
2015-04-30 21:42:50 +03:00
|
|
|
return LineRange(kAutoLine, kAutoLine);
|
2015-03-26 21:57:39 +03:00
|
|
|
}
|
2015-04-30 21:42:50 +03:00
|
|
|
int32_t end = ResolveLine(aEnd, aEnd.mInteger, 0, aLineNameList, aAreaStart,
|
|
|
|
aAreaEnd, aExplicitGridEnd, eLineRangeSideEnd,
|
|
|
|
aStyle);
|
2015-03-26 21:57:39 +03:00
|
|
|
if (aEnd.mHasSpan) {
|
|
|
|
++end;
|
|
|
|
}
|
2015-08-25 16:40:10 +03:00
|
|
|
// A line outside the existing grid is treated as 'auto' for abs.pos (10.1).
|
|
|
|
end = AutoIfOutside(end, aGridStart, aGridEnd);
|
|
|
|
return LineRange(kAutoLine, end);
|
2015-03-26 21:57:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aEnd.IsAuto()) {
|
2015-04-30 21:42:50 +03:00
|
|
|
int32_t start =
|
2015-03-26 21:57:39 +03:00
|
|
|
ResolveLine(aStart, aStart.mInteger, 0, aLineNameList, aAreaStart,
|
|
|
|
aAreaEnd, aExplicitGridEnd, eLineRangeSideStart, aStyle);
|
|
|
|
if (aStart.mHasSpan) {
|
2015-04-30 21:42:50 +03:00
|
|
|
start = std::max(aGridEnd - start, aGridStart);
|
2015-03-26 21:57:39 +03:00
|
|
|
}
|
2015-08-25 16:40:10 +03:00
|
|
|
start = AutoIfOutside(start, aGridStart, aGridEnd);
|
|
|
|
return LineRange(start, kAutoLine);
|
2015-03-26 21:57:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
LineRange r = ResolveLineRange(aStart, aEnd, aLineNameList, aAreaStart,
|
|
|
|
aAreaEnd, aExplicitGridEnd, aStyle);
|
2015-08-25 16:40:10 +03:00
|
|
|
if (r.IsAuto()) {
|
|
|
|
MOZ_ASSERT(aStart.mHasSpan && aEnd.mHasSpan, "span / span is the only case "
|
|
|
|
"leading to IsAuto here -- we dealt with the other cases above");
|
|
|
|
// The second span was ignored per 9.2.1. For abs.pos., 10.1 says that this
|
|
|
|
// case should result in "auto / auto" unlike normal flow grid items.
|
|
|
|
return LineRange(kAutoLine, kAutoLine);
|
|
|
|
}
|
|
|
|
|
2015-08-25 16:40:10 +03:00
|
|
|
return LineRange(AutoIfOutside(r.mUntranslatedStart, aGridStart, aGridEnd),
|
|
|
|
AutoIfOutside(r.mUntranslatedEnd, aGridStart, aGridEnd));
|
2015-03-26 21:57:39 +03:00
|
|
|
}
|
|
|
|
|
2015-03-18 12:02:32 +03:00
|
|
|
uint32_t
|
|
|
|
nsGridContainerFrame::FindAutoCol(uint32_t aStartCol, uint32_t aLockedRow,
|
|
|
|
const GridArea* aArea) const
|
|
|
|
{
|
|
|
|
const uint32_t extent = aArea->mCols.Extent();
|
2015-04-30 21:42:50 +03:00
|
|
|
const uint32_t iStart = aLockedRow;
|
2015-03-18 12:02:32 +03:00
|
|
|
const uint32_t iEnd = iStart + aArea->mRows.Extent();
|
2015-04-30 21:42:50 +03:00
|
|
|
uint32_t candidate = aStartCol;
|
2015-03-18 12:02:32 +03:00
|
|
|
for (uint32_t i = iStart; i < iEnd; ) {
|
|
|
|
if (i >= mCellMap.mCells.Length()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
const nsTArray<CellMap::Cell>& cellsInRow = mCellMap.mCells[i];
|
|
|
|
const uint32_t len = cellsInRow.Length();
|
|
|
|
const uint32_t lastCandidate = candidate;
|
|
|
|
// Find the first gap in the current row that's at least 'extent' wide.
|
|
|
|
// ('gap' tracks how wide the current column gap is.)
|
|
|
|
for (uint32_t j = candidate, gap = 0; j < len && gap < extent; ++j) {
|
|
|
|
++gap; // tentative, but we may reset it below if a column is occupied
|
|
|
|
if (cellsInRow[j].mIsOccupied) {
|
|
|
|
// Optimization: skip as many occupied cells as we can.
|
|
|
|
do {
|
|
|
|
++j;
|
|
|
|
} while (j < len && cellsInRow[j].mIsOccupied);
|
|
|
|
candidate = j;
|
|
|
|
gap = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (lastCandidate < candidate && i != iStart) {
|
|
|
|
// Couldn't fit 'extent' tracks at 'lastCandidate' here so we must
|
|
|
|
// restart from the beginning with the new 'candidate'.
|
|
|
|
i = iStart;
|
|
|
|
} else {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
2015-04-30 21:42:50 +03:00
|
|
|
return candidate;
|
2015-03-18 12:02:32 +03:00
|
|
|
}
|
|
|
|
|
2015-03-26 21:57:39 +03:00
|
|
|
nsGridContainerFrame::GridArea
|
|
|
|
nsGridContainerFrame::PlaceAbsPos(nsIFrame* aChild,
|
|
|
|
const nsStylePosition* aStyle)
|
|
|
|
{
|
|
|
|
const nsStylePosition* itemStyle = aChild->StylePosition();
|
2015-04-30 21:42:50 +03:00
|
|
|
int32_t gridColStart = 1 - mExplicitGridOffsetCol;
|
|
|
|
int32_t gridRowStart = 1 - mExplicitGridOffsetRow;
|
2015-03-26 21:57:39 +03:00
|
|
|
return GridArea(
|
|
|
|
ResolveAbsPosLineRange(itemStyle->mGridColumnStart,
|
|
|
|
itemStyle->mGridColumnEnd,
|
|
|
|
aStyle->mGridTemplateColumns.mLineNameLists,
|
|
|
|
&GridNamedArea::mColumnStart,
|
|
|
|
&GridNamedArea::mColumnEnd,
|
2015-04-30 21:42:50 +03:00
|
|
|
mExplicitGridColEnd, gridColStart, mGridColEnd,
|
|
|
|
aStyle),
|
2015-03-26 21:57:39 +03:00
|
|
|
ResolveAbsPosLineRange(itemStyle->mGridRowStart,
|
|
|
|
itemStyle->mGridRowEnd,
|
|
|
|
aStyle->mGridTemplateRows.mLineNameLists,
|
|
|
|
&GridNamedArea::mRowStart,
|
|
|
|
&GridNamedArea::mRowEnd,
|
2015-04-30 21:42:50 +03:00
|
|
|
mExplicitGridRowEnd, gridRowStart, mGridRowEnd,
|
|
|
|
aStyle));
|
2015-03-26 21:57:39 +03:00
|
|
|
}
|
|
|
|
|
2015-03-18 12:02:32 +03:00
|
|
|
void
|
|
|
|
nsGridContainerFrame::PlaceAutoCol(uint32_t aStartCol, GridArea* aArea) const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aArea->mRows.IsDefinite() && aArea->mCols.IsAuto());
|
|
|
|
uint32_t col = FindAutoCol(aStartCol, aArea->mRows.mStart, aArea);
|
|
|
|
aArea->mCols.ResolveAutoPosition(col);
|
|
|
|
MOZ_ASSERT(aArea->IsDefinite());
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
nsGridContainerFrame::FindAutoRow(uint32_t aLockedCol, uint32_t aStartRow,
|
|
|
|
const GridArea* aArea) const
|
|
|
|
{
|
|
|
|
const uint32_t extent = aArea->mRows.Extent();
|
2015-04-30 21:42:50 +03:00
|
|
|
const uint32_t jStart = aLockedCol;
|
2015-03-18 12:02:32 +03:00
|
|
|
const uint32_t jEnd = jStart + aArea->mCols.Extent();
|
|
|
|
const uint32_t iEnd = mCellMap.mCells.Length();
|
2015-04-30 21:42:50 +03:00
|
|
|
uint32_t candidate = aStartRow;
|
2015-03-18 12:02:32 +03:00
|
|
|
// Find the first gap in the rows that's at least 'extent' tall.
|
|
|
|
// ('gap' tracks how tall the current row gap is.)
|
|
|
|
for (uint32_t i = candidate, gap = 0; i < iEnd && gap < extent; ++i) {
|
|
|
|
++gap; // tentative, but we may reset it below if a column is occupied
|
|
|
|
const nsTArray<CellMap::Cell>& cellsInRow = mCellMap.mCells[i];
|
|
|
|
const uint32_t clampedJEnd = std::min<uint32_t>(jEnd, cellsInRow.Length());
|
|
|
|
// Check if the current row is unoccupied from jStart to jEnd.
|
|
|
|
for (uint32_t j = jStart; j < clampedJEnd; ++j) {
|
|
|
|
if (cellsInRow[j].mIsOccupied) {
|
|
|
|
// Couldn't fit 'extent' rows at 'candidate' here; we hit something
|
|
|
|
// at row 'i'. So, try the row after 'i' as our next candidate.
|
|
|
|
candidate = i + 1;
|
|
|
|
gap = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-30 21:42:50 +03:00
|
|
|
return candidate;
|
2015-03-18 12:02:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGridContainerFrame::PlaceAutoRow(uint32_t aStartRow, GridArea* aArea) const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aArea->mCols.IsDefinite() && aArea->mRows.IsAuto());
|
|
|
|
uint32_t row = FindAutoRow(aArea->mCols.mStart, aStartRow, aArea);
|
|
|
|
aArea->mRows.ResolveAutoPosition(row);
|
|
|
|
MOZ_ASSERT(aArea->IsDefinite());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGridContainerFrame::PlaceAutoAutoInRowOrder(uint32_t aStartCol,
|
|
|
|
uint32_t aStartRow,
|
|
|
|
GridArea* aArea) const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aArea->mCols.IsAuto() && aArea->mRows.IsAuto());
|
|
|
|
const uint32_t colExtent = aArea->mCols.Extent();
|
|
|
|
const uint32_t gridRowEnd = mGridRowEnd;
|
|
|
|
const uint32_t gridColEnd = mGridColEnd;
|
|
|
|
uint32_t col = aStartCol;
|
|
|
|
uint32_t row = aStartRow;
|
|
|
|
for (; row < gridRowEnd; ++row) {
|
|
|
|
col = FindAutoCol(col, row, aArea);
|
|
|
|
if (col + colExtent <= gridColEnd) {
|
|
|
|
break;
|
|
|
|
}
|
2015-04-30 21:42:50 +03:00
|
|
|
col = 0;
|
2015-03-18 12:02:32 +03:00
|
|
|
}
|
2015-04-30 21:42:50 +03:00
|
|
|
MOZ_ASSERT(row < gridRowEnd || col == 0,
|
|
|
|
"expected column 0 for placing in a new row");
|
2015-03-18 12:02:32 +03:00
|
|
|
aArea->mCols.ResolveAutoPosition(col);
|
|
|
|
aArea->mRows.ResolveAutoPosition(row);
|
|
|
|
MOZ_ASSERT(aArea->IsDefinite());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGridContainerFrame::PlaceAutoAutoInColOrder(uint32_t aStartCol,
|
|
|
|
uint32_t aStartRow,
|
|
|
|
GridArea* aArea) const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aArea->mCols.IsAuto() && aArea->mRows.IsAuto());
|
|
|
|
const uint32_t rowExtent = aArea->mRows.Extent();
|
|
|
|
const uint32_t gridRowEnd = mGridRowEnd;
|
|
|
|
const uint32_t gridColEnd = mGridColEnd;
|
|
|
|
uint32_t col = aStartCol;
|
|
|
|
uint32_t row = aStartRow;
|
|
|
|
for (; col < gridColEnd; ++col) {
|
|
|
|
row = FindAutoRow(col, row, aArea);
|
|
|
|
if (row + rowExtent <= gridRowEnd) {
|
|
|
|
break;
|
|
|
|
}
|
2015-04-30 21:42:50 +03:00
|
|
|
row = 0;
|
2015-03-18 12:02:32 +03:00
|
|
|
}
|
2015-04-30 21:42:50 +03:00
|
|
|
MOZ_ASSERT(col < gridColEnd || row == 0,
|
|
|
|
"expected row 0 for placing in a new column");
|
2015-03-18 12:02:32 +03:00
|
|
|
aArea->mCols.ResolveAutoPosition(col);
|
|
|
|
aArea->mRows.ResolveAutoPosition(row);
|
|
|
|
MOZ_ASSERT(aArea->IsDefinite());
|
|
|
|
}
|
|
|
|
|
2015-03-18 12:02:32 +03:00
|
|
|
void
|
|
|
|
nsGridContainerFrame::InitializeGridBounds(const nsStylePosition* aStyle)
|
|
|
|
{
|
|
|
|
// http://dev.w3.org/csswg/css-grid/#grid-definition
|
2015-04-30 21:42:50 +03:00
|
|
|
// Note that this is for a grid with a 1,1 origin. We'll change that
|
|
|
|
// to a 0,0 based grid after placing definite lines.
|
2015-03-18 12:02:32 +03:00
|
|
|
uint32_t colEnd = aStyle->mGridTemplateColumns.mLineNameLists.Length();
|
|
|
|
uint32_t rowEnd = aStyle->mGridTemplateRows.mLineNameLists.Length();
|
|
|
|
auto areas = aStyle->mGridTemplateAreas.get();
|
|
|
|
mExplicitGridColEnd = std::max(colEnd, areas ? areas->mNColumns + 1 : 1);
|
|
|
|
mExplicitGridRowEnd = std::max(rowEnd, areas ? areas->NRows() + 1 : 1);
|
2015-04-30 21:42:50 +03:00
|
|
|
mExplicitGridColEnd =
|
|
|
|
std::min(mExplicitGridColEnd, uint32_t(nsStyleGridLine::kMaxLine));
|
|
|
|
mExplicitGridRowEnd =
|
|
|
|
std::min(mExplicitGridRowEnd, uint32_t(nsStyleGridLine::kMaxLine));
|
2015-03-18 12:02:32 +03:00
|
|
|
mGridColEnd = mExplicitGridColEnd;
|
|
|
|
mGridRowEnd = mExplicitGridRowEnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-03-26 21:57:39 +03:00
|
|
|
nsGridContainerFrame::PlaceGridItems(GridItemCSSOrderIterator& aIter,
|
|
|
|
const nsStylePosition* aStyle)
|
2015-03-18 12:02:32 +03:00
|
|
|
{
|
2015-03-18 12:02:32 +03:00
|
|
|
mCellMap.ClearOccupied();
|
2015-03-18 12:02:32 +03:00
|
|
|
InitializeGridBounds(aStyle);
|
|
|
|
|
2015-03-18 12:02:32 +03:00
|
|
|
// http://dev.w3.org/csswg/css-grid/#line-placement
|
|
|
|
// Resolve definite positions per spec chap 9.2.
|
2015-04-30 21:42:50 +03:00
|
|
|
int32_t minCol = 1;
|
|
|
|
int32_t minRow = 1;
|
|
|
|
for (; !aIter.AtEnd(); aIter.Next()) {
|
|
|
|
nsIFrame* child = *aIter;
|
|
|
|
const GridArea& area = PlaceDefinite(child, aStyle);
|
|
|
|
if (area.mCols.IsDefinite()) {
|
|
|
|
minCol = std::min(minCol, area.mCols.mUntranslatedStart);
|
|
|
|
}
|
|
|
|
if (area.mRows.IsDefinite()) {
|
|
|
|
minRow = std::min(minRow, area.mRows.mUntranslatedStart);
|
|
|
|
}
|
|
|
|
GridArea* prop = GetGridAreaForChild(child);
|
|
|
|
if (prop) {
|
|
|
|
*prop = area;
|
|
|
|
} else {
|
|
|
|
prop = new GridArea(area);
|
|
|
|
child->Properties().Set(GridAreaProperty(), prop);
|
2015-03-18 12:02:32 +03:00
|
|
|
}
|
2015-04-30 21:42:50 +03:00
|
|
|
}
|
2015-04-30 21:42:50 +03:00
|
|
|
|
2015-04-30 21:42:50 +03:00
|
|
|
// Translate the whole grid so that the top-/left-most area is at 0,0.
|
|
|
|
mExplicitGridOffsetCol = 1 - minCol; // minCol/Row is always <= 1, see above
|
|
|
|
mExplicitGridOffsetRow = 1 - minRow;
|
|
|
|
const int32_t offsetToColZero = int32_t(mExplicitGridOffsetCol) - 1;
|
|
|
|
const int32_t offsetToRowZero = int32_t(mExplicitGridOffsetRow) - 1;
|
|
|
|
mGridColEnd += offsetToColZero;
|
|
|
|
mGridRowEnd += offsetToRowZero;
|
|
|
|
aIter.Reset();
|
|
|
|
for (; !aIter.AtEnd(); aIter.Next()) {
|
|
|
|
nsIFrame* child = *aIter;
|
|
|
|
GridArea* area = GetGridAreaForChild(child);
|
|
|
|
if (area->mCols.IsDefinite()) {
|
|
|
|
area->mCols.mStart = area->mCols.mUntranslatedStart + offsetToColZero;
|
|
|
|
area->mCols.mEnd = area->mCols.mUntranslatedEnd + offsetToColZero;
|
|
|
|
}
|
|
|
|
if (area->mRows.IsDefinite()) {
|
|
|
|
area->mRows.mStart = area->mRows.mUntranslatedStart + offsetToRowZero;
|
|
|
|
area->mRows.mEnd = area->mRows.mUntranslatedEnd + offsetToRowZero;
|
|
|
|
}
|
|
|
|
if (area->IsDefinite()) {
|
|
|
|
mCellMap.Fill(*area);
|
|
|
|
InflateGridFor(*area);
|
2015-03-18 12:02:32 +03:00
|
|
|
}
|
2015-03-18 12:02:32 +03:00
|
|
|
}
|
2015-03-18 12:02:32 +03:00
|
|
|
|
|
|
|
// http://dev.w3.org/csswg/css-grid/#auto-placement-algo
|
|
|
|
// Step 1, place 'auto' items that have one definite position -
|
|
|
|
// definite row (column) for grid-auto-flow:row (column).
|
|
|
|
auto flowStyle = aStyle->mGridAutoFlow;
|
|
|
|
const bool isRowOrder = (flowStyle & NS_STYLE_GRID_AUTO_FLOW_ROW);
|
|
|
|
const bool isSparse = !(flowStyle & NS_STYLE_GRID_AUTO_FLOW_DENSE);
|
|
|
|
// We need 1 cursor per row (or column) if placement is sparse.
|
|
|
|
{
|
|
|
|
Maybe<nsDataHashtable<nsUint32HashKey, uint32_t>> cursors;
|
|
|
|
if (isSparse) {
|
|
|
|
cursors.emplace();
|
|
|
|
}
|
|
|
|
auto placeAutoMinorFunc = isRowOrder ? &nsGridContainerFrame::PlaceAutoCol
|
|
|
|
: &nsGridContainerFrame::PlaceAutoRow;
|
2015-03-26 21:57:39 +03:00
|
|
|
aIter.Reset();
|
|
|
|
for (; !aIter.AtEnd(); aIter.Next()) {
|
|
|
|
nsIFrame* child = *aIter;
|
2015-03-18 12:02:32 +03:00
|
|
|
GridArea* area = GetGridAreaForChild(child);
|
|
|
|
LineRange& major = isRowOrder ? area->mRows : area->mCols;
|
|
|
|
LineRange& minor = isRowOrder ? area->mCols : area->mRows;
|
|
|
|
if (major.IsDefinite() && minor.IsAuto()) {
|
|
|
|
// Items with 'auto' in the minor dimension only.
|
2015-04-30 21:42:50 +03:00
|
|
|
uint32_t cursor = 0;
|
2015-03-18 12:02:32 +03:00
|
|
|
if (isSparse) {
|
|
|
|
cursors->Get(major.mStart, &cursor);
|
|
|
|
}
|
|
|
|
(this->*placeAutoMinorFunc)(cursor, area);
|
|
|
|
mCellMap.Fill(*area);
|
|
|
|
if (isSparse) {
|
|
|
|
cursors->Put(major.mStart, minor.mEnd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
InflateGridFor(*area); // Step 2, inflating for auto items too
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX NOTE possible spec issue.
|
|
|
|
// XXX It's unclear if the remaining major-dimension auto and
|
|
|
|
// XXX auto in both dimensions should use the same cursor or not,
|
|
|
|
// XXX https://www.w3.org/Bugs/Public/show_bug.cgi?id=16044
|
|
|
|
// XXX seems to indicate it shouldn't.
|
|
|
|
// XXX http://dev.w3.org/csswg/css-grid/#auto-placement-cursor
|
|
|
|
// XXX now says it should (but didn't in earlier versions)
|
|
|
|
|
|
|
|
// Step 3, place the remaining grid items
|
2015-04-30 21:42:50 +03:00
|
|
|
uint32_t cursorMajor = 0; // for 'dense' these two cursors will stay at 0,0
|
|
|
|
uint32_t cursorMinor = 0;
|
2015-03-18 12:02:32 +03:00
|
|
|
auto placeAutoMajorFunc = isRowOrder ? &nsGridContainerFrame::PlaceAutoRow
|
|
|
|
: &nsGridContainerFrame::PlaceAutoCol;
|
2015-03-26 21:57:39 +03:00
|
|
|
aIter.Reset();
|
|
|
|
for (; !aIter.AtEnd(); aIter.Next()) {
|
|
|
|
nsIFrame* child = *aIter;
|
2015-03-18 12:02:32 +03:00
|
|
|
GridArea* area = GetGridAreaForChild(child);
|
|
|
|
LineRange& major = isRowOrder ? area->mRows : area->mCols;
|
|
|
|
LineRange& minor = isRowOrder ? area->mCols : area->mRows;
|
|
|
|
if (major.IsAuto()) {
|
|
|
|
if (minor.IsDefinite()) {
|
|
|
|
// Items with 'auto' in the major dimension only.
|
|
|
|
if (isSparse) {
|
2015-04-30 21:42:50 +03:00
|
|
|
if (minor.mStart < cursorMinor) {
|
2015-03-18 12:02:32 +03:00
|
|
|
++cursorMajor;
|
|
|
|
}
|
|
|
|
cursorMinor = minor.mStart;
|
|
|
|
}
|
|
|
|
(this->*placeAutoMajorFunc)(cursorMajor, area);
|
|
|
|
if (isSparse) {
|
|
|
|
cursorMajor = major.mStart;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Items with 'auto' in both dimensions.
|
|
|
|
if (isRowOrder) {
|
|
|
|
PlaceAutoAutoInRowOrder(cursorMinor, cursorMajor, area);
|
|
|
|
} else {
|
|
|
|
PlaceAutoAutoInColOrder(cursorMajor, cursorMinor, area);
|
|
|
|
}
|
|
|
|
if (isSparse) {
|
|
|
|
cursorMajor = major.mStart;
|
|
|
|
cursorMinor = minor.mEnd;
|
|
|
|
#ifdef DEBUG
|
|
|
|
uint32_t gridMajorEnd = isRowOrder ? mGridRowEnd : mGridColEnd;
|
|
|
|
uint32_t gridMinorEnd = isRowOrder ? mGridColEnd : mGridRowEnd;
|
|
|
|
MOZ_ASSERT(cursorMajor <= gridMajorEnd,
|
|
|
|
"we shouldn't need to place items further than 1 track "
|
|
|
|
"past the current end of the grid, in major dimension");
|
|
|
|
MOZ_ASSERT(cursorMinor <= gridMinorEnd,
|
|
|
|
"we shouldn't add implicit minor tracks for auto/auto");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mCellMap.Fill(*area);
|
|
|
|
InflateGridFor(*area);
|
|
|
|
}
|
|
|
|
}
|
2015-03-26 21:57:39 +03:00
|
|
|
|
|
|
|
if (IsAbsoluteContainer()) {
|
|
|
|
// 9.4 Absolutely-positioned Grid Items
|
|
|
|
// http://dev.w3.org/csswg/css-grid/#abspos-items
|
|
|
|
// We only resolve definite lines here; we'll align auto positions to the
|
|
|
|
// grid container later during reflow.
|
|
|
|
nsFrameList children(GetChildList(GetAbsoluteListID()));
|
2015-04-30 21:42:50 +03:00
|
|
|
const int32_t offsetToColZero = int32_t(mExplicitGridOffsetCol) - 1;
|
|
|
|
const int32_t offsetToRowZero = int32_t(mExplicitGridOffsetRow) - 1;
|
2015-04-30 21:42:50 +03:00
|
|
|
// Untranslate the grid again temporarily while resolving abs.pos. lines.
|
|
|
|
AutoRestore<uint32_t> save1(mGridColEnd);
|
|
|
|
AutoRestore<uint32_t> save2(mGridRowEnd);
|
2015-04-30 21:42:50 +03:00
|
|
|
mGridColEnd -= offsetToColZero;
|
|
|
|
mGridRowEnd -= offsetToRowZero;
|
2015-03-26 21:57:39 +03:00
|
|
|
for (nsFrameList::Enumerator e(children); !e.AtEnd(); e.Next()) {
|
|
|
|
nsIFrame* child = e.get();
|
|
|
|
GridArea area(PlaceAbsPos(child, aStyle));
|
2015-04-30 21:42:50 +03:00
|
|
|
if (area.mCols.mUntranslatedStart != int32_t(kAutoLine)) {
|
|
|
|
area.mCols.mStart = area.mCols.mUntranslatedStart + offsetToColZero;
|
2015-04-30 21:42:50 +03:00
|
|
|
}
|
2015-04-30 21:42:50 +03:00
|
|
|
if (area.mCols.mUntranslatedEnd != int32_t(kAutoLine)) {
|
|
|
|
area.mCols.mEnd = area.mCols.mUntranslatedEnd + offsetToColZero;
|
2015-04-30 21:42:50 +03:00
|
|
|
}
|
2015-04-30 21:42:50 +03:00
|
|
|
if (area.mRows.mUntranslatedStart != int32_t(kAutoLine)) {
|
|
|
|
area.mRows.mStart = area.mRows.mUntranslatedStart + offsetToRowZero;
|
2015-04-30 21:42:50 +03:00
|
|
|
}
|
2015-04-30 21:42:50 +03:00
|
|
|
if (area.mRows.mUntranslatedEnd != int32_t(kAutoLine)) {
|
|
|
|
area.mRows.mEnd = area.mRows.mUntranslatedEnd + offsetToRowZero;
|
2015-04-30 21:42:50 +03:00
|
|
|
}
|
2015-03-26 21:57:39 +03:00
|
|
|
GridArea* prop = GetGridAreaForChild(child);
|
|
|
|
if (prop) {
|
|
|
|
*prop = area;
|
|
|
|
} else {
|
|
|
|
child->Properties().Set(GridAreaProperty(), new GridArea(area));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-03-18 12:02:32 +03:00
|
|
|
}
|
|
|
|
|
2015-03-18 12:02:32 +03:00
|
|
|
static void
|
|
|
|
InitializeTrackSize(nscoord aPercentageBasis,
|
|
|
|
const nsStyleCoord& aMinCoord,
|
|
|
|
const nsStyleCoord& aMaxCoord,
|
|
|
|
TrackSize* aTrackSize)
|
|
|
|
{
|
|
|
|
// http://dev.w3.org/csswg/css-grid/#algo-init
|
|
|
|
nscoord& base = aTrackSize->mBase;
|
2015-04-04 15:50:00 +03:00
|
|
|
switch (aMinCoord.GetUnit()) {
|
2015-04-30 21:42:50 +03:00
|
|
|
case eStyleUnit_Auto:
|
2015-03-18 12:02:32 +03:00
|
|
|
case eStyleUnit_Enumerated:
|
|
|
|
case eStyleUnit_FlexFraction:
|
|
|
|
base = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
base = nsRuleNode::ComputeCoordPercentCalc(aMinCoord, aPercentageBasis);
|
|
|
|
}
|
|
|
|
nscoord& limit = aTrackSize->mLimit;
|
|
|
|
switch (aMaxCoord.GetUnit()) {
|
2015-04-30 21:42:50 +03:00
|
|
|
case eStyleUnit_Auto:
|
2015-03-18 12:02:32 +03:00
|
|
|
case eStyleUnit_Enumerated:
|
|
|
|
limit = NS_UNCONSTRAINEDSIZE;
|
|
|
|
break;
|
|
|
|
case eStyleUnit_FlexFraction:
|
|
|
|
limit = base;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
limit = nsRuleNode::ComputeCoordPercentCalc(aMaxCoord, aPercentageBasis);
|
|
|
|
if (limit < base) {
|
|
|
|
limit = base;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
InitializeTrackSizes(nscoord aPercentageBasis,
|
|
|
|
const nsTArray<nsStyleCoord>& aMinSizingFunctions,
|
|
|
|
const nsTArray<nsStyleCoord>& aMaxSizingFunctions,
|
|
|
|
const nsStyleCoord& aAutoMinFunction,
|
|
|
|
const nsStyleCoord& aAutoMaxFunction,
|
2015-04-30 21:42:50 +03:00
|
|
|
uint32_t aExplicitGridOffset,
|
2015-03-18 12:02:32 +03:00
|
|
|
nsTArray<TrackSize>& aResults)
|
|
|
|
{
|
2015-04-30 21:42:50 +03:00
|
|
|
MOZ_ASSERT(aResults.Length() >= aExplicitGridOffset + aMinSizingFunctions.Length());
|
2015-03-18 12:02:32 +03:00
|
|
|
MOZ_ASSERT(aMinSizingFunctions.Length() == aMaxSizingFunctions.Length());
|
|
|
|
size_t i = 0;
|
2015-04-30 21:42:50 +03:00
|
|
|
for (; i < aExplicitGridOffset; ++i) {
|
2015-03-18 12:02:32 +03:00
|
|
|
InitializeTrackSize(aPercentageBasis,
|
2015-04-30 21:42:50 +03:00
|
|
|
aAutoMinFunction, aAutoMaxFunction,
|
2015-03-18 12:02:32 +03:00
|
|
|
&aResults[i]);
|
|
|
|
}
|
2015-04-30 21:42:50 +03:00
|
|
|
size_t j = 0;
|
|
|
|
for (const size_t len = aMinSizingFunctions.Length(); j < len; ++j) {
|
|
|
|
InitializeTrackSize(aPercentageBasis,
|
|
|
|
aMinSizingFunctions[j], aMaxSizingFunctions[j],
|
|
|
|
&aResults[i + j]);
|
|
|
|
}
|
|
|
|
i += j;
|
2015-03-18 12:02:32 +03:00
|
|
|
for (; i < aResults.Length(); ++i) {
|
|
|
|
InitializeTrackSize(aPercentageBasis,
|
|
|
|
aAutoMinFunction, aAutoMaxFunction,
|
|
|
|
&aResults[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGridContainerFrame::CalculateTrackSizes(const LogicalSize& aPercentageBasis,
|
|
|
|
const nsStylePosition* aStyle,
|
|
|
|
nsTArray<TrackSize>& aColSizes,
|
|
|
|
nsTArray<TrackSize>& aRowSizes)
|
|
|
|
{
|
2015-04-30 21:42:50 +03:00
|
|
|
aColSizes.SetLength(mGridColEnd);
|
|
|
|
aRowSizes.SetLength(mGridRowEnd);
|
2015-03-18 12:02:32 +03:00
|
|
|
WritingMode wm = GetWritingMode();
|
|
|
|
InitializeTrackSizes(aPercentageBasis.ISize(wm),
|
|
|
|
aStyle->mGridTemplateColumns.mMinTrackSizingFunctions,
|
|
|
|
aStyle->mGridTemplateColumns.mMaxTrackSizingFunctions,
|
|
|
|
aStyle->mGridAutoColumnsMin,
|
|
|
|
aStyle->mGridAutoColumnsMax,
|
2015-04-30 21:42:50 +03:00
|
|
|
mExplicitGridOffsetCol,
|
2015-03-18 12:02:32 +03:00
|
|
|
aColSizes);
|
|
|
|
InitializeTrackSizes(aPercentageBasis.BSize(wm),
|
|
|
|
aStyle->mGridTemplateRows.mMinTrackSizingFunctions,
|
|
|
|
aStyle->mGridTemplateRows.mMaxTrackSizingFunctions,
|
|
|
|
aStyle->mGridAutoRowsMin,
|
|
|
|
aStyle->mGridAutoRowsMax,
|
2015-04-30 21:42:50 +03:00
|
|
|
mExplicitGridOffsetRow,
|
2015-03-18 12:02:32 +03:00
|
|
|
aRowSizes);
|
|
|
|
}
|
|
|
|
|
2015-03-18 12:02:32 +03:00
|
|
|
void
|
|
|
|
nsGridContainerFrame::LineRange::ToPositionAndLength(
|
|
|
|
const nsTArray<TrackSize>& aTrackSizes, nscoord* aPos, nscoord* aLength) const
|
|
|
|
{
|
2015-04-30 21:42:50 +03:00
|
|
|
MOZ_ASSERT(mStart != kAutoLine && mEnd != kAutoLine,
|
|
|
|
"expected a definite LineRange");
|
2015-03-18 12:02:32 +03:00
|
|
|
nscoord pos = 0;
|
2015-04-30 21:42:50 +03:00
|
|
|
const uint32_t start = mStart;
|
2015-03-18 12:02:32 +03:00
|
|
|
uint32_t i = 0;
|
|
|
|
for (; i < start; ++i) {
|
|
|
|
pos += aTrackSizes[i].mBase;
|
|
|
|
}
|
|
|
|
*aPos = pos;
|
|
|
|
|
|
|
|
nscoord length = 0;
|
2015-04-30 21:42:50 +03:00
|
|
|
const uint32_t end = mEnd;
|
2015-03-18 12:02:32 +03:00
|
|
|
MOZ_ASSERT(end <= aTrackSizes.Length(), "aTrackSizes isn't large enough");
|
|
|
|
for (; i < end; ++i) {
|
|
|
|
length += aTrackSizes[i].mBase;
|
|
|
|
}
|
|
|
|
*aLength = length;
|
|
|
|
}
|
|
|
|
|
2015-03-26 21:57:39 +03:00
|
|
|
void
|
|
|
|
nsGridContainerFrame::LineRange::ToPositionAndLengthForAbsPos(
|
|
|
|
const nsTArray<TrackSize>& aTrackSizes, nscoord aGridOrigin,
|
|
|
|
nscoord* aPos, nscoord* aLength) const
|
|
|
|
{
|
2015-04-30 21:42:50 +03:00
|
|
|
// kAutoLine for abspos children contributes the corresponding edge
|
|
|
|
// of the grid container's padding-box.
|
|
|
|
if (mEnd == kAutoLine) {
|
|
|
|
if (mStart == kAutoLine) {
|
2015-03-26 21:57:39 +03:00
|
|
|
// done
|
|
|
|
} else {
|
|
|
|
const nscoord endPos = *aPos + *aLength;
|
|
|
|
nscoord startPos = ::GridLinePosition(mStart, aTrackSizes);
|
|
|
|
*aPos = aGridOrigin + startPos;
|
|
|
|
*aLength = std::max(endPos - *aPos, 0);
|
|
|
|
}
|
|
|
|
} else {
|
2015-04-30 21:42:50 +03:00
|
|
|
if (mStart == kAutoLine) {
|
2015-03-26 21:57:39 +03:00
|
|
|
nscoord endPos = ::GridLinePosition(mEnd, aTrackSizes);
|
|
|
|
*aLength = std::max(aGridOrigin + endPos, 0);
|
|
|
|
} else {
|
|
|
|
nscoord pos;
|
|
|
|
ToPositionAndLength(aTrackSizes, &pos, aLength);
|
|
|
|
*aPos = aGridOrigin + pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-18 12:02:32 +03:00
|
|
|
LogicalRect
|
|
|
|
nsGridContainerFrame::ContainingBlockFor(
|
|
|
|
const WritingMode& aWM,
|
|
|
|
const GridArea& aArea,
|
|
|
|
const nsTArray<TrackSize>& aColSizes,
|
|
|
|
const nsTArray<TrackSize>& aRowSizes) const
|
|
|
|
{
|
|
|
|
nscoord i, b, iSize, bSize;
|
2015-04-30 21:42:50 +03:00
|
|
|
MOZ_ASSERT(aArea.mCols.Extent() > 0, "grid items cover at least one track");
|
|
|
|
MOZ_ASSERT(aArea.mRows.Extent() > 0, "grid items cover at least one track");
|
2015-03-18 12:02:32 +03:00
|
|
|
aArea.mCols.ToPositionAndLength(aColSizes, &i, &iSize);
|
|
|
|
aArea.mRows.ToPositionAndLength(aRowSizes, &b, &bSize);
|
|
|
|
return LogicalRect(aWM, i, b, iSize, bSize);
|
|
|
|
}
|
|
|
|
|
2015-03-26 21:57:39 +03:00
|
|
|
LogicalRect
|
|
|
|
nsGridContainerFrame::ContainingBlockForAbsPos(
|
|
|
|
const WritingMode& aWM,
|
|
|
|
const GridArea& aArea,
|
|
|
|
const nsTArray<TrackSize>& aColSizes,
|
|
|
|
const nsTArray<TrackSize>& aRowSizes,
|
|
|
|
const LogicalPoint& aGridOrigin,
|
|
|
|
const LogicalRect& aGridCB) const
|
|
|
|
{
|
|
|
|
nscoord i = aGridCB.IStart(aWM);
|
|
|
|
nscoord b = aGridCB.BStart(aWM);
|
|
|
|
nscoord iSize = aGridCB.ISize(aWM);
|
|
|
|
nscoord bSize = aGridCB.BSize(aWM);
|
|
|
|
aArea.mCols.ToPositionAndLengthForAbsPos(aColSizes, aGridOrigin.I(aWM),
|
|
|
|
&i, &iSize);
|
|
|
|
aArea.mRows.ToPositionAndLengthForAbsPos(aRowSizes, aGridOrigin.B(aWM),
|
|
|
|
&b, &bSize);
|
|
|
|
return LogicalRect(aWM, i, b, iSize, bSize);
|
|
|
|
}
|
|
|
|
|
2015-03-18 12:02:32 +03:00
|
|
|
void
|
2015-03-26 21:57:39 +03:00
|
|
|
nsGridContainerFrame::ReflowChildren(GridItemCSSOrderIterator& aIter,
|
|
|
|
const LogicalRect& aContentArea,
|
2015-03-18 12:02:32 +03:00
|
|
|
const nsTArray<TrackSize>& aColSizes,
|
|
|
|
const nsTArray<TrackSize>& aRowSizes,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
WritingMode wm = aReflowState.GetWritingMode();
|
|
|
|
const LogicalPoint gridOrigin(aContentArea.Origin(wm));
|
2015-07-16 12:07:57 +03:00
|
|
|
const nsSize containerSize =
|
|
|
|
(aContentArea.Size(wm) +
|
|
|
|
aReflowState.ComputedLogicalBorderPadding().Size(wm)).GetPhysicalSize(wm);
|
2015-03-18 12:02:32 +03:00
|
|
|
nsPresContext* pc = PresContext();
|
2015-03-26 21:57:39 +03:00
|
|
|
for (; !aIter.AtEnd(); aIter.Next()) {
|
|
|
|
nsIFrame* child = *aIter;
|
2015-05-06 00:53:22 +03:00
|
|
|
const bool isGridItem = child->GetType() != nsGkAtoms::placeholderFrame;
|
|
|
|
LogicalRect cb(wm);
|
|
|
|
if (MOZ_LIKELY(isGridItem)) {
|
|
|
|
GridArea* area = GetGridAreaForChild(child);
|
|
|
|
MOZ_ASSERT(area && area->IsDefinite());
|
|
|
|
cb = ContainingBlockFor(wm, *area, aColSizes, aRowSizes);
|
|
|
|
cb += gridOrigin;
|
|
|
|
} else {
|
|
|
|
cb = aContentArea;
|
|
|
|
}
|
2015-06-06 09:15:36 +03:00
|
|
|
WritingMode childWM = child->GetWritingMode();
|
|
|
|
LogicalSize childCBSize = cb.Size(wm).ConvertTo(childWM, wm);
|
|
|
|
nsHTMLReflowState childRS(pc, aReflowState, child, childCBSize);
|
2015-03-18 12:02:32 +03:00
|
|
|
const LogicalMargin margin = childRS.ComputedLogicalMargin();
|
2015-05-06 00:53:22 +03:00
|
|
|
if (childRS.ComputedBSize() == NS_AUTOHEIGHT && MOZ_LIKELY(isGridItem)) {
|
2015-03-18 12:02:32 +03:00
|
|
|
// XXX the start of an align-self:stretch impl. Needs min-/max-bsize
|
|
|
|
// clamping though, and check the prop value is actually 'stretch'!
|
|
|
|
LogicalMargin bp = childRS.ComputedLogicalBorderPadding();
|
|
|
|
bp.ApplySkipSides(child->GetLogicalSkipSides());
|
2015-06-06 09:15:36 +03:00
|
|
|
nscoord bSize = childCBSize.BSize(childWM) - bp.BStartEnd(childWM) -
|
|
|
|
margin.BStartEnd(childWM);
|
2015-03-18 12:02:32 +03:00
|
|
|
childRS.SetComputedBSize(std::max(bSize, 0));
|
|
|
|
}
|
2015-06-06 09:15:36 +03:00
|
|
|
// We need the width of the child before we can correctly convert
|
2015-07-16 12:07:57 +03:00
|
|
|
// the writing-mode of its origin, so we reflow at (0, 0) using a dummy
|
|
|
|
// containerSize, and then pass the correct position to FinishReflowChild.
|
2015-03-18 12:02:32 +03:00
|
|
|
nsHTMLReflowMetrics childSize(childRS);
|
|
|
|
nsReflowStatus childStatus;
|
2015-07-16 12:07:57 +03:00
|
|
|
const nsSize dummyContainerSize;
|
2015-06-06 09:15:36 +03:00
|
|
|
ReflowChild(child, pc, childSize, childRS, childWM, LogicalPoint(childWM),
|
2015-07-16 12:07:57 +03:00
|
|
|
dummyContainerSize, 0, childStatus);
|
2015-06-06 09:15:36 +03:00
|
|
|
LogicalPoint childPos =
|
2015-07-16 12:07:57 +03:00
|
|
|
cb.Origin(wm).ConvertTo(childWM, wm,
|
|
|
|
containerSize - childSize.PhysicalSize() -
|
|
|
|
margin.Size(childWM).GetPhysicalSize(childWM));
|
2015-06-06 09:15:36 +03:00
|
|
|
childPos.I(childWM) += margin.IStart(childWM);
|
|
|
|
childPos.B(childWM) += margin.BStart(childWM);
|
2015-07-16 12:07:57 +03:00
|
|
|
childRS.ApplyRelativePositioning(&childPos, containerSize);
|
2015-06-06 09:15:36 +03:00
|
|
|
FinishReflowChild(child, pc, childSize, &childRS, childWM, childPos,
|
2015-07-16 12:07:57 +03:00
|
|
|
containerSize, 0);
|
2015-03-18 12:02:32 +03:00
|
|
|
ConsiderChildOverflow(aDesiredSize.mOverflowAreas, child);
|
|
|
|
// XXX deal with 'childStatus' not being COMPLETE
|
|
|
|
}
|
2015-03-26 21:57:39 +03:00
|
|
|
|
|
|
|
if (IsAbsoluteContainer()) {
|
|
|
|
nsFrameList children(GetChildList(GetAbsoluteListID()));
|
|
|
|
if (!children.IsEmpty()) {
|
|
|
|
LogicalMargin pad(aReflowState.ComputedLogicalPadding());
|
|
|
|
pad.ApplySkipSides(GetLogicalSkipSides(&aReflowState));
|
|
|
|
// 'gridOrigin' is the origin of the grid (the start of the first track),
|
|
|
|
// with respect to the grid container's padding-box (CB).
|
|
|
|
const LogicalPoint gridOrigin(wm, pad.IStart(wm), pad.BStart(wm));
|
|
|
|
const LogicalRect gridCB(wm, 0, 0,
|
|
|
|
aContentArea.ISize(wm) + pad.IStartEnd(wm),
|
|
|
|
aContentArea.BSize(wm) + pad.BStartEnd(wm));
|
|
|
|
for (nsFrameList::Enumerator e(children); !e.AtEnd(); e.Next()) {
|
|
|
|
nsIFrame* child = e.get();
|
|
|
|
GridArea* area = GetGridAreaForChild(child);
|
|
|
|
MOZ_ASSERT(area);
|
|
|
|
LogicalRect itemCB(ContainingBlockForAbsPos(wm, *area,
|
|
|
|
aColSizes, aRowSizes,
|
|
|
|
gridOrigin, gridCB));
|
|
|
|
// nsAbsoluteContainingBlock::Reflow uses physical coordinates.
|
|
|
|
nsRect* cb = static_cast<nsRect*>(child->Properties().Get(
|
|
|
|
GridItemContainingBlockRect()));
|
|
|
|
if (!cb) {
|
|
|
|
cb = new nsRect;
|
|
|
|
child->Properties().Set(GridItemContainingBlockRect(), cb);
|
|
|
|
}
|
2015-07-16 12:07:57 +03:00
|
|
|
*cb = itemCB.GetPhysicalRect(wm, containerSize);
|
2015-03-26 21:57:39 +03:00
|
|
|
}
|
|
|
|
// This rect isn't used at all for layout so we use it to optimize
|
|
|
|
// away the virtual GetType() call in the callee in most cases.
|
|
|
|
// @see nsAbsoluteContainingBlock::Reflow
|
|
|
|
nsRect dummyRect(0, 0, VERY_LIKELY_A_GRID_CONTAINER, 0);
|
|
|
|
GetAbsoluteContainingBlock()->Reflow(this, pc, aReflowState, aStatus,
|
|
|
|
dummyRect, true,
|
|
|
|
true, true, // XXX could be optimized
|
|
|
|
&aDesiredSize.mOverflowAreas);
|
|
|
|
}
|
|
|
|
}
|
2015-03-18 12:02:32 +03:00
|
|
|
}
|
|
|
|
|
2014-05-13 04:47:54 +04:00
|
|
|
void
|
|
|
|
nsGridContainerFrame::Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
2015-03-30 01:38:40 +03:00
|
|
|
MarkInReflow();
|
2014-05-13 04:47:54 +04:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsGridContainerFrame");
|
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
|
|
|
|
|
|
|
if (IsFrameTreeTooDeep(aReflowState, aDesiredSize, aStatus)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-20 03:57:00 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
SanityCheckAnonymousGridItems();
|
|
|
|
#endif // DEBUG
|
|
|
|
|
2014-07-24 12:30:07 +04:00
|
|
|
LogicalMargin bp = aReflowState.ComputedLogicalBorderPadding();
|
|
|
|
bp.ApplySkipSides(GetLogicalSkipSides());
|
2015-01-15 00:59:59 +03:00
|
|
|
const nsStylePosition* stylePos = aReflowState.mStylePosition;
|
|
|
|
InitImplicitNamedAreas(stylePos);
|
2015-03-26 21:57:39 +03:00
|
|
|
GridItemCSSOrderIterator normalFlowIter(this, kPrincipalList);
|
|
|
|
mIsNormalFlowInCSSOrder = normalFlowIter.ItemsAreAlreadyInOrder();
|
|
|
|
PlaceGridItems(normalFlowIter, stylePos);
|
2015-01-15 00:59:59 +03:00
|
|
|
|
2015-03-18 12:02:32 +03:00
|
|
|
nsAutoTArray<TrackSize, 32> colSizes;
|
|
|
|
nsAutoTArray<TrackSize, 32> rowSizes;
|
2015-03-18 12:02:32 +03:00
|
|
|
WritingMode wm = aReflowState.GetWritingMode();
|
|
|
|
const nscoord computedBSize = aReflowState.ComputedBSize();
|
|
|
|
const nscoord computedISize = aReflowState.ComputedISize();
|
|
|
|
LogicalSize percentageBasis(wm, computedISize,
|
|
|
|
computedBSize == NS_AUTOHEIGHT ? 0 : computedBSize);
|
2015-03-18 12:02:32 +03:00
|
|
|
CalculateTrackSizes(percentageBasis, stylePos, colSizes, rowSizes);
|
|
|
|
|
2015-03-18 12:02:32 +03:00
|
|
|
nscoord bSize = 0;
|
|
|
|
if (computedBSize == NS_AUTOHEIGHT) {
|
2015-04-30 21:42:50 +03:00
|
|
|
for (uint32_t i = 0; i < mGridRowEnd; ++i) {
|
2015-03-18 12:02:32 +03:00
|
|
|
bSize += rowSizes[i].mBase;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bSize = computedBSize;
|
|
|
|
}
|
|
|
|
bSize = std::max(bSize - GetConsumedBSize(), 0);
|
|
|
|
LogicalSize desiredSize(wm, computedISize + bp.IStartEnd(wm),
|
|
|
|
bSize + bp.BStartEnd(wm));
|
|
|
|
aDesiredSize.SetSize(wm, desiredSize);
|
|
|
|
aDesiredSize.SetOverflowAreasToDesiredBounds();
|
|
|
|
|
|
|
|
LogicalRect contentArea(wm, bp.IStart(wm), bp.BStart(wm),
|
|
|
|
computedISize, bSize);
|
2015-05-06 00:53:22 +03:00
|
|
|
normalFlowIter.Reset(GridItemCSSOrderIterator::eIncludeAll);
|
2015-03-26 21:57:39 +03:00
|
|
|
ReflowChildren(normalFlowIter, contentArea, colSizes, rowSizes, aDesiredSize,
|
2015-03-18 12:02:32 +03:00
|
|
|
aReflowState, aStatus);
|
|
|
|
|
|
|
|
FinishAndStoreOverflow(&aDesiredSize);
|
2014-05-13 04:47:54 +04:00
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
|
|
|
}
|
|
|
|
|
2014-02-27 11:45:29 +04:00
|
|
|
nsIAtom*
|
|
|
|
nsGridContainerFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::gridContainerFrame;
|
|
|
|
}
|
|
|
|
|
2015-03-26 21:57:39 +03:00
|
|
|
void
|
|
|
|
nsGridContainerFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
DisplayBorderBackgroundOutline(aBuilder, aLists);
|
|
|
|
|
|
|
|
// Our children are all grid-level boxes, which behave the same as
|
|
|
|
// inline-blocks in painting, so their borders/backgrounds all go on
|
|
|
|
// the BlockBorderBackgrounds list.
|
2015-03-26 21:57:39 +03:00
|
|
|
// Also, we capture positioned descendants so we can sort them by
|
|
|
|
// CSS 'order'.
|
|
|
|
nsDisplayList positionedDescendants;
|
|
|
|
nsDisplayListSet childLists(aLists.BlockBorderBackgrounds(),
|
|
|
|
aLists.BlockBorderBackgrounds(),
|
|
|
|
aLists.Floats(),
|
|
|
|
aLists.Content(),
|
|
|
|
&positionedDescendants,
|
|
|
|
aLists.Outlines());
|
2015-03-26 21:57:39 +03:00
|
|
|
typedef GridItemCSSOrderIterator::OrderState OrderState;
|
|
|
|
OrderState order = mIsNormalFlowInCSSOrder ? OrderState::eKnownOrdered
|
|
|
|
: OrderState::eKnownUnordered;
|
2015-05-06 00:53:22 +03:00
|
|
|
GridItemCSSOrderIterator iter(this, kPrincipalList,
|
|
|
|
GridItemCSSOrderIterator::eIncludeAll, order);
|
2015-03-26 21:57:39 +03:00
|
|
|
for (; !iter.AtEnd(); iter.Next()) {
|
|
|
|
nsIFrame* child = *iter;
|
2015-03-26 21:57:39 +03:00
|
|
|
BuildDisplayListForChild(aBuilder, child, aDirtyRect, childLists,
|
|
|
|
::GetDisplayFlagsForGridItem(child));
|
|
|
|
}
|
2015-03-26 21:57:39 +03:00
|
|
|
positionedDescendants.SortByCSSOrder(aBuilder);
|
|
|
|
aLists.PositionedDescendants()->AppendToTop(&positionedDescendants);
|
2015-03-26 21:57:39 +03:00
|
|
|
}
|
|
|
|
|
2014-02-27 11:45:29 +04:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
|
|
|
nsresult
|
|
|
|
nsGridContainerFrame::GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("GridContainer"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
2014-05-20 03:57:00 +04:00
|
|
|
|
2015-03-18 12:02:32 +03:00
|
|
|
void
|
|
|
|
nsGridContainerFrame::CellMap::Fill(const GridArea& aGridArea)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aGridArea.IsDefinite());
|
|
|
|
MOZ_ASSERT(aGridArea.mRows.mStart < aGridArea.mRows.mEnd);
|
|
|
|
MOZ_ASSERT(aGridArea.mCols.mStart < aGridArea.mCols.mEnd);
|
2015-04-30 21:42:50 +03:00
|
|
|
const auto numRows = aGridArea.mRows.mEnd;
|
|
|
|
const auto numCols = aGridArea.mCols.mEnd;
|
2015-03-18 12:02:32 +03:00
|
|
|
mCells.EnsureLengthAtLeast(numRows);
|
2015-04-30 21:42:50 +03:00
|
|
|
for (auto i = aGridArea.mRows.mStart; i < numRows; ++i) {
|
2015-03-18 12:02:32 +03:00
|
|
|
nsTArray<Cell>& cellsInRow = mCells[i];
|
|
|
|
cellsInRow.EnsureLengthAtLeast(numCols);
|
2015-04-30 21:42:50 +03:00
|
|
|
for (auto j = aGridArea.mCols.mStart; j < numCols; ++j) {
|
2015-03-18 12:02:32 +03:00
|
|
|
cellsInRow[j].mIsOccupied = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGridContainerFrame::CellMap::ClearOccupied()
|
|
|
|
{
|
|
|
|
const size_t numRows = mCells.Length();
|
|
|
|
for (size_t i = 0; i < numRows; ++i) {
|
|
|
|
nsTArray<Cell>& cellsInRow = mCells[i];
|
|
|
|
const size_t numCols = cellsInRow.Length();
|
|
|
|
for (size_t j = 0; j < numCols; ++j) {
|
|
|
|
cellsInRow[j].mIsOccupied = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-20 03:57:00 +04:00
|
|
|
#ifdef DEBUG
|
2015-03-18 12:02:32 +03:00
|
|
|
void
|
|
|
|
nsGridContainerFrame::CellMap::Dump() const
|
|
|
|
{
|
|
|
|
const size_t numRows = mCells.Length();
|
|
|
|
for (size_t i = 0; i < numRows; ++i) {
|
|
|
|
const nsTArray<Cell>& cellsInRow = mCells[i];
|
|
|
|
const size_t numCols = cellsInRow.Length();
|
|
|
|
printf("%lu:\t", (unsigned long)i + 1);
|
|
|
|
for (size_t j = 0; j < numCols; ++j) {
|
|
|
|
printf(cellsInRow[j].mIsOccupied ? "X " : ". ");
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-20 03:57:00 +04:00
|
|
|
static bool
|
|
|
|
FrameWantsToBeInAnonymousGridItem(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
// Note: This needs to match the logic in
|
|
|
|
// nsCSSFrameConstructor::FrameConstructionItem::NeedsAnonFlexOrGridItem()
|
2015-05-06 00:53:22 +03:00
|
|
|
return aFrame->IsFrameOfType(nsIFrame::eLineParticipant);
|
2014-05-20 03:57:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Debugging method, to let us assert that our anonymous grid items are
|
|
|
|
// set up correctly -- in particular, we assert:
|
|
|
|
// (1) we don't have any inline non-replaced children
|
|
|
|
// (2) we don't have any consecutive anonymous grid items
|
|
|
|
// (3) we don't have any empty anonymous grid items
|
|
|
|
// (4) all children are on the expected child lists
|
|
|
|
void
|
|
|
|
nsGridContainerFrame::SanityCheckAnonymousGridItems() const
|
|
|
|
{
|
|
|
|
// XXX handle kOverflowContainersList / kExcessOverflowContainersList
|
|
|
|
// when we implement fragmentation?
|
|
|
|
ChildListIDs noCheckLists = kAbsoluteList | kFixedList;
|
|
|
|
ChildListIDs checkLists = kPrincipalList | kOverflowList;
|
|
|
|
for (nsIFrame::ChildListIterator childLists(this);
|
|
|
|
!childLists.IsDone(); childLists.Next()) {
|
|
|
|
if (!checkLists.Contains(childLists.CurrentID())) {
|
|
|
|
MOZ_ASSERT(noCheckLists.Contains(childLists.CurrentID()),
|
|
|
|
"unexpected non-empty child list");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool prevChildWasAnonGridItem = false;
|
|
|
|
nsFrameList children = childLists.CurrentList();
|
|
|
|
for (nsFrameList::Enumerator e(children); !e.AtEnd(); e.Next()) {
|
|
|
|
nsIFrame* child = e.get();
|
|
|
|
MOZ_ASSERT(!FrameWantsToBeInAnonymousGridItem(child),
|
|
|
|
"frame wants to be inside an anonymous grid item, "
|
|
|
|
"but it isn't");
|
|
|
|
if (child->StyleContext()->GetPseudo() ==
|
|
|
|
nsCSSAnonBoxes::anonymousGridItem) {
|
|
|
|
/*
|
|
|
|
XXX haven't decided yet whether to reorder children or not.
|
|
|
|
XXX If we do, we want this assertion instead of the one below.
|
|
|
|
MOZ_ASSERT(!prevChildWasAnonGridItem ||
|
|
|
|
HasAnyStateBits(NS_STATE_GRID_CHILDREN_REORDERED),
|
|
|
|
"two anon grid items in a row (shouldn't happen, unless our "
|
|
|
|
"children have been reordered with the 'order' property)");
|
|
|
|
*/
|
|
|
|
MOZ_ASSERT(!prevChildWasAnonGridItem, "two anon grid items in a row");
|
|
|
|
nsIFrame* firstWrappedChild = child->GetFirstPrincipalChild();
|
|
|
|
MOZ_ASSERT(firstWrappedChild,
|
|
|
|
"anonymous grid item is empty (shouldn't happen)");
|
|
|
|
prevChildWasAnonGridItem = true;
|
|
|
|
} else {
|
|
|
|
prevChildWasAnonGridItem = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // DEBUG
|