Bug 1159305 - patch 1 - Provide logical accessors for nsStylePosition and nsStyleSides fields. r=dbaron

This commit is contained in:
Jonathan Kew 2015-05-11 11:35:47 +01:00
parent 273904de3f
commit a4b720a1bf
3 changed files with 216 additions and 16 deletions

View File

@ -36,22 +36,6 @@ enum PhysicalAxis {
eAxisHorizontal = 0x1
};
// Logical axis, edge and side constants for use in various places.
enum LogicalAxis {
eLogicalAxisBlock = 0x0,
eLogicalAxisInline = 0x1
};
enum LogicalEdge {
eLogicalEdgeStart = 0x0,
eLogicalEdgeEnd = 0x1
};
enum LogicalSide {
eLogicalSideBStart = (eLogicalAxisBlock << 1) | eLogicalEdgeStart, // 0x0
eLogicalSideBEnd = (eLogicalAxisBlock << 1) | eLogicalEdgeEnd, // 0x1
eLogicalSideIStart = (eLogicalAxisInline << 1) | eLogicalEdgeStart, // 0x2
eLogicalSideIEnd = (eLogicalAxisInline << 1) | eLogicalEdgeEnd // 0x3
};
inline bool IsInline(LogicalSide aSide) { return aSide & 0x2; }
inline bool IsBlock(LogicalSide aSide) { return !IsInline(aSide); }
inline bool IsEnd(LogicalSide aSide) { return aSide & 0x1; }
@ -1809,4 +1793,153 @@ private:
} // namespace mozilla
// Definitions of inline methods for nsStyleSides, declared in nsStyleCoord.h
// but not defined there because they need WritingMode.
inline nsStyleUnit nsStyleSides::GetUnit(mozilla::WritingMode aWM,
mozilla::LogicalSide aSide) const
{
return GetUnit(aWM.PhysicalSide(aSide));
}
inline nsStyleUnit nsStyleSides::GetIStartUnit(mozilla::WritingMode aWM) const
{
return GetUnit(aWM, mozilla::eLogicalSideIStart);
}
inline nsStyleUnit nsStyleSides::GetBStartUnit(mozilla::WritingMode aWM) const
{
return GetUnit(aWM, mozilla::eLogicalSideBStart);
}
inline nsStyleUnit nsStyleSides::GetIEndUnit(mozilla::WritingMode aWM) const
{
return GetUnit(aWM, mozilla::eLogicalSideIEnd);
}
inline nsStyleUnit nsStyleSides::GetBEndUnit(mozilla::WritingMode aWM) const
{
return GetUnit(aWM, mozilla::eLogicalSideBEnd);
}
inline nsStyleCoord nsStyleSides::Get(mozilla::WritingMode aWM,
mozilla::LogicalSide aSide) const
{
return Get(aWM.PhysicalSide(aSide));
}
inline nsStyleCoord nsStyleSides::GetIStart(mozilla::WritingMode aWM) const
{
return Get(aWM, mozilla::eLogicalSideIStart);
}
inline nsStyleCoord nsStyleSides::GetBStart(mozilla::WritingMode aWM) const
{
return Get(aWM, mozilla::eLogicalSideBStart);
}
inline nsStyleCoord nsStyleSides::GetIEnd(mozilla::WritingMode aWM) const
{
return Get(aWM, mozilla::eLogicalSideIEnd);
}
inline nsStyleCoord nsStyleSides::GetBEnd(mozilla::WritingMode aWM) const
{
return Get(aWM, mozilla::eLogicalSideBEnd);
}
// Definitions of inline methods for nsStylePosition, declared in
// nsStyleStruct.h but not defined there because they need WritingMode.
inline nsStyleCoord& nsStylePosition::ISize(mozilla::WritingMode aWM)
{
return aWM.IsVertical() ? mHeight : mWidth;
}
inline nsStyleCoord& nsStylePosition::MinISize(mozilla::WritingMode aWM)
{
return aWM.IsVertical() ? mMinHeight : mMinWidth;
}
inline nsStyleCoord& nsStylePosition::MaxISize(mozilla::WritingMode aWM)
{
return aWM.IsVertical() ? mMaxHeight : mMaxWidth;
}
inline nsStyleCoord& nsStylePosition::BSize(mozilla::WritingMode aWM)
{
return aWM.IsVertical() ? mWidth : mHeight;
}
inline nsStyleCoord& nsStylePosition::MinBSize(mozilla::WritingMode aWM)
{
return aWM.IsVertical() ? mMinWidth : mMinHeight;
}
inline nsStyleCoord& nsStylePosition::MaxBSize(mozilla::WritingMode aWM)
{
return aWM.IsVertical() ? mMaxWidth : mMaxHeight;
}
inline const nsStyleCoord&
nsStylePosition::ISize(mozilla::WritingMode aWM) const
{
return aWM.IsVertical() ? mHeight : mWidth;
}
inline const nsStyleCoord&
nsStylePosition::MinISize(mozilla::WritingMode aWM) const
{
return aWM.IsVertical() ? mMinHeight : mMinWidth;
}
inline const nsStyleCoord&
nsStylePosition::MaxISize(mozilla::WritingMode aWM) const
{
return aWM.IsVertical() ? mMaxHeight : mMaxWidth;
}
inline const nsStyleCoord&
nsStylePosition::BSize(mozilla::WritingMode aWM) const
{
return aWM.IsVertical() ? mWidth : mHeight;
}
inline const nsStyleCoord&
nsStylePosition::MinBSize(mozilla::WritingMode aWM) const
{
return aWM.IsVertical() ? mMinWidth : mMinHeight;
}
inline const nsStyleCoord&
nsStylePosition::MaxBSize(mozilla::WritingMode aWM) const
{
return aWM.IsVertical() ? mMaxWidth : mMaxHeight;
}
inline bool
nsStylePosition::ISizeDependsOnContainer(mozilla::WritingMode aWM) const
{
return aWM.IsVertical() ? HeightDependsOnContainer()
: WidthDependsOnContainer();
}
inline bool
nsStylePosition::MinISizeDependsOnContainer(mozilla::WritingMode aWM) const
{
return aWM.IsVertical() ? MinHeightDependsOnContainer()
: MinWidthDependsOnContainer();
}
inline bool
nsStylePosition::MaxISizeDependsOnContainer(mozilla::WritingMode aWM) const
{
return aWM.IsVertical() ? MaxHeightDependsOnContainer()
: MaxWidthDependsOnContainer();
}
inline bool
nsStylePosition::BSizeDependsOnContainer(mozilla::WritingMode aWM) const
{
return aWM.IsVertical() ? WidthDependsOnContainer()
: HeightDependsOnContainer();
}
inline bool
nsStylePosition::MinBSizeDependsOnContainer(mozilla::WritingMode aWM) const
{
return aWM.IsVertical() ? MinWidthDependsOnContainer()
: MinHeightDependsOnContainer();
}
inline bool
nsStylePosition::MaxBSizeDependsOnContainer(mozilla::WritingMode aWM) const
{
return aWM.IsVertical() ? MaxWidthDependsOnContainer()
: MaxHeightDependsOnContainer();
}
#endif // WritingModes_h_

View File

@ -11,6 +11,26 @@
#include "nsCoord.h"
#include "nsStyleConsts.h"
namespace mozilla {
class WritingMode;
// Logical axis, edge and side constants for use in various places.
enum LogicalAxis {
eLogicalAxisBlock = 0x0,
eLogicalAxisInline = 0x1
};
enum LogicalEdge {
eLogicalEdgeStart = 0x0,
eLogicalEdgeEnd = 0x1
};
enum LogicalSide {
eLogicalSideBStart = (eLogicalAxisBlock << 1) | eLogicalEdgeStart, // 0x0
eLogicalSideBEnd = (eLogicalAxisBlock << 1) | eLogicalEdgeEnd, // 0x1
eLogicalSideIStart = (eLogicalAxisInline << 1) | eLogicalEdgeStart, // 0x2
eLogicalSideIEnd = (eLogicalAxisInline << 1) | eLogicalEdgeEnd // 0x3
};
};
enum nsStyleUnit : uint8_t {
eStyleUnit_Null = 0, // (no value) value is not specified
eStyleUnit_Normal = 1, // (no value)
@ -221,6 +241,24 @@ public:
inline nsStyleCoord GetRight() const;
inline nsStyleCoord GetBottom() const;
// Methods to access the units and values in terms of logical sides
// for a given writing mode.
// NOTE: The definitions are in WritingModes.h (after we have the full
// declaration of WritingMode available).
inline nsStyleUnit GetUnit(mozilla::WritingMode aWritingMode,
mozilla::LogicalSide aSide) const;
inline nsStyleUnit GetIStartUnit(mozilla::WritingMode aWritingMode) const;
inline nsStyleUnit GetBStartUnit(mozilla::WritingMode aWritingMode) const;
inline nsStyleUnit GetIEndUnit(mozilla::WritingMode aWritingMode) const;
inline nsStyleUnit GetBEndUnit(mozilla::WritingMode aWritingMode) const;
inline nsStyleCoord Get(mozilla::WritingMode aWritingMode,
mozilla::LogicalSide aSide) const;
inline nsStyleCoord GetIStart(mozilla::WritingMode aWritingMode) const;
inline nsStyleCoord GetBStart(mozilla::WritingMode aWritingMode) const;
inline nsStyleCoord GetIEnd(mozilla::WritingMode aWritingMode) const;
inline nsStyleCoord GetBEnd(mozilla::WritingMode aWritingMode) const;
// Sets each side to null and releases any refcounted objects. Only use this
// if the object is initialized (i.e. don't use it in nsStyleSides
// constructors).

View File

@ -1394,6 +1394,11 @@ struct nsStylePosition {
nsStyleGridLine mGridRowStart;
nsStyleGridLine mGridRowEnd;
// FIXME: Logical-coordinate equivalents to these WidthDepends... and
// HeightDepends... methods have been introduced (see below); we probably
// want to work towards removing the physical methods, and using the logical
// ones in all cases.
bool WidthDependsOnContainer() const
{
return mWidth.GetUnit() == eStyleUnit_Auto ||
@ -1419,6 +1424,7 @@ struct nsStylePosition {
// for it, since it is the most common case.
// FIXME: We should probably change the assumption to be the other way
// around.
// Consider this as part of moving to the logical-coordinate APIs.
bool HeightDependsOnContainer() const
{
return mHeight.GetUnit() == eStyleUnit_Auto || // CSS 2.1, 10.6.4, item (5)
@ -1437,6 +1443,29 @@ struct nsStylePosition {
return mOffset.Get(aSide).HasPercent();
}
// Logical-coordinate accessors for width and height properties,
// given a WritingMode value. The definitions of these methods are
// found in WritingModes.h (after the WritingMode class is fully
// declared).
inline nsStyleCoord& ISize(mozilla::WritingMode aWM);
inline nsStyleCoord& MinISize(mozilla::WritingMode aWM);
inline nsStyleCoord& MaxISize(mozilla::WritingMode aWM);
inline nsStyleCoord& BSize(mozilla::WritingMode aWM);
inline nsStyleCoord& MinBSize(mozilla::WritingMode aWM);
inline nsStyleCoord& MaxBSize(mozilla::WritingMode aWM);
inline const nsStyleCoord& ISize(mozilla::WritingMode aWM) const;
inline const nsStyleCoord& MinISize(mozilla::WritingMode aWM) const;
inline const nsStyleCoord& MaxISize(mozilla::WritingMode aWM) const;
inline const nsStyleCoord& BSize(mozilla::WritingMode aWM) const;
inline const nsStyleCoord& MinBSize(mozilla::WritingMode aWM) const;
inline const nsStyleCoord& MaxBSize(mozilla::WritingMode aWM) const;
inline bool ISizeDependsOnContainer(mozilla::WritingMode aWM) const;
inline bool MinISizeDependsOnContainer(mozilla::WritingMode aWM) const;
inline bool MaxISizeDependsOnContainer(mozilla::WritingMode aWM) const;
inline bool BSizeDependsOnContainer(mozilla::WritingMode aWM) const;
inline bool MinBSizeDependsOnContainer(mozilla::WritingMode aWM) const;
inline bool MaxBSizeDependsOnContainer(mozilla::WritingMode aWM) const;
private:
static bool WidthCoordDependsOnContainer(const nsStyleCoord &aCoord);
static bool HeightCoordDependsOnContainer(const nsStyleCoord &aCoord)