Bug 1648938 - Convert writing-modes #defines to an enum class. r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D84016
This commit is contained in:
Philipp Zech 2020-07-23 21:31:23 +00:00
Родитель 977d27e7b7
Коммит 3d4be168ae
8 изменённых файлов: 33 добавлений и 31 удалений

Просмотреть файл

@ -76,8 +76,8 @@ static bool IsIsolateControl(char16_t aChar) {
// Returns 0 if no override control character is implied by this style.
static char16_t GetBidiOverride(ComputedStyle* aComputedStyle) {
const nsStyleVisibility* vis = aComputedStyle->StyleVisibility();
if ((vis->mWritingMode == NS_STYLE_WRITING_MODE_VERTICAL_RL ||
vis->mWritingMode == NS_STYLE_WRITING_MODE_VERTICAL_LR) &&
if ((vis->mWritingMode == StyleWritingModeProperty::VerticalRl ||
vis->mWritingMode == StyleWritingModeProperty::VerticalLr) &&
vis->mTextOrientation == StyleTextOrientation::Upright) {
return kLRO;
}

Просмотреть файл

@ -7574,13 +7574,13 @@ nsIFrame* nsLayoutUtils::GetReferenceFrame(nsIFrame* aFrame) {
/* static */ gfx::ShapedTextFlags nsLayoutUtils::GetTextRunOrientFlagsForStyle(
ComputedStyle* aComputedStyle) {
uint8_t writingMode = aComputedStyle->StyleVisibility()->mWritingMode;
auto writingMode = aComputedStyle->StyleVisibility()->mWritingMode;
switch (writingMode) {
case NS_STYLE_WRITING_MODE_HORIZONTAL_TB:
case StyleWritingModeProperty::HorizontalTb:
return gfx::ShapedTextFlags::TEXT_ORIENT_HORIZONTAL;
case NS_STYLE_WRITING_MODE_VERTICAL_LR:
case NS_STYLE_WRITING_MODE_VERTICAL_RL:
case StyleWritingModeProperty::VerticalLr:
case StyleWritingModeProperty::VerticalRl:
switch (aComputedStyle->StyleVisibility()->mTextOrientation) {
case StyleTextOrientation::Mixed:
return gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_MIXED;
@ -7593,10 +7593,10 @@ nsIFrame* nsLayoutUtils::GetReferenceFrame(nsIFrame* aFrame) {
return gfx::ShapedTextFlags();
}
case NS_STYLE_WRITING_MODE_SIDEWAYS_LR:
case StyleWritingModeProperty::SidewaysLr:
return gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_SIDEWAYS_LEFT;
case NS_STYLE_WRITING_MODE_SIDEWAYS_RL:
case StyleWritingModeProperty::SidewaysRl:
return gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_SIDEWAYS_RIGHT;
default:

Просмотреть файл

@ -316,9 +316,9 @@ class WritingMode {
// orientation and bit 0 of a LogicalAxis value indicating the inline axis,
// so that it can correctly form mozilla::PhysicalAxis values using bit
// manipulation.
static_assert(NS_STYLE_WRITING_MODE_HORIZONTAL_TB == 0 &&
NS_STYLE_WRITING_MODE_VERTICAL_RL == 1 &&
NS_STYLE_WRITING_MODE_VERTICAL_LR == 3 &&
static_assert(uint8_t(StyleWritingModeProperty::HorizontalTb) == 0 &&
uint8_t(StyleWritingModeProperty::VerticalRl) == 1 &&
uint8_t(StyleWritingModeProperty::VerticalLr) == 3 &&
eLogicalAxisBlock == 0 && eLogicalAxisInline == 1 &&
eAxisVertical == 0 && eAxisHorizontal == 1,
"unexpected writing-mode, logical axis or physical axis "
@ -327,8 +327,8 @@ class WritingMode {
}
mozilla::PhysicalAxis PhysicalAxis(LogicalAxis aAxis) const {
// This will set wm to either NS_STYLE_WRITING_MODE_HORIZONTAL_TB or
// NS_STYLE_WRITING_MODE_VERTICAL_RL, and not the other two (real
// This will set wm to either StyleWritingModel::HorizontalTB or
// StyleWritingModeProperty::VerticalRL, and not the other two (real
// and hypothetical) values. But this is fine; we only need to
// distinguish between vertical and horizontal in
// PhysicalAxisForLogicalAxis.
@ -338,7 +338,7 @@ class WritingMode {
static mozilla::Side PhysicalSideForBlockAxis(uint8_t aWritingModeValue,
LogicalEdge aEdge) {
// indexes are NS_STYLE_WRITING_MODE_* values, which are the same as these
// indexes are StyleWritingModeProperty values, which are the same as these
// two-bit values:
// bit 0 = the StyleWritingMode::VERTICAL value
// bit 1 = the StyleWritingMode::VERTICAL_LR value
@ -349,9 +349,9 @@ class WritingMode {
{eSideLeft, eSideRight}, // vertical-lr
};
// Ignore the SIDEWAYS_MASK bit of the writing-mode value, as this has no
// Ignore the SidewaysMask bit of the writing-mode value, as this has no
// effect on the side mappings.
aWritingModeValue &= ~NS_STYLE_WRITING_MODE_SIDEWAYS_MASK;
aWritingModeValue &= ~kWritingModeSidewaysMask;
// What's left of the writing-mode should be in the range 0-3:
NS_ASSERTION(aWritingModeValue < 4, "invalid aWritingModeValue value");

Просмотреть файл

@ -164,6 +164,7 @@ rusty-enums = [
"mozilla::StyleBlend",
"mozilla::StyleMaskComposite",
"mozilla::StyleControlCharacterVisibility",
"mozilla::StyleWritingModeProperty",
]
whitelist-vars = [
"NS_ATTRVALUE_.*",

Просмотреть файл

@ -338,21 +338,21 @@ enum class StyleDirection : uint8_t { Ltr, Rtl };
// See nsStyleVisibility
// NOTE: WritingModes.h depends on the particular values used here.
#define NS_STYLE_WRITING_MODE_HORIZONTAL_TB 0
#define NS_STYLE_WRITING_MODE_VERTICAL_RL 1
// #define NS_STYLE_WRITING_MODE_HORIZONTAL_BT 2 // hypothetical
#define NS_STYLE_WRITING_MODE_VERTICAL_LR 3
// Single-bit flag, used in combination with VERTICAL_LR and _RL to specify
// the corresponding SIDEWAYS_* modes.
// Single-bit flag, used in combination with VerticalLR and RL to specify
// the corresponding Sideways* modes.
// (To avoid ambiguity, this bit must be high enough such that no other
// values here accidentally use it in their binary representation.)
#define NS_STYLE_WRITING_MODE_SIDEWAYS_MASK 4
static constexpr uint8_t kWritingModeSidewaysMask = 4;
#define NS_STYLE_WRITING_MODE_SIDEWAYS_RL \
(NS_STYLE_WRITING_MODE_VERTICAL_RL | NS_STYLE_WRITING_MODE_SIDEWAYS_MASK)
#define NS_STYLE_WRITING_MODE_SIDEWAYS_LR \
(NS_STYLE_WRITING_MODE_VERTICAL_LR | NS_STYLE_WRITING_MODE_SIDEWAYS_MASK)
enum class StyleWritingModeProperty : uint8_t {
HorizontalTb = 0,
VerticalRl = 1,
// HorizontalBT = 2, // hypothetical
VerticalLr = 3,
SidewaysRl = VerticalRl | kWritingModeSidewaysMask,
SidewaysLr = VerticalLr | kWritingModeSidewaysMask,
};
// See nsStylePosition
enum class StyleFlexDirection : uint8_t {

Просмотреть файл

@ -1286,8 +1286,8 @@ nsChangeHint nsStylePosition::CalcDifference(
// It doesn't matter whether we're looking at the old or new visibility
// struct, since a change between vertical and horizontal writing-mode will
// cause a reframe.
bool isVertical =
aOldStyleVisibility.mWritingMode != NS_STYLE_WRITING_MODE_HORIZONTAL_TB;
bool isVertical = aOldStyleVisibility.mWritingMode !=
StyleWritingModeProperty::HorizontalTb;
if (isVertical ? widthChanged : heightChanged) {
hint |= nsChangeHint_ReflowHintsForBSizeChange;
}
@ -2736,7 +2736,7 @@ nsStyleVisibility::nsStyleVisibility(const Document& aDocument)
: StyleDirection::Ltr),
mVisible(StyleVisibility::Visible),
mImageRendering(StyleImageRendering::Auto),
mWritingMode(NS_STYLE_WRITING_MODE_HORIZONTAL_TB),
mWritingMode(StyleWritingModeProperty::HorizontalTb),
mTextOrientation(StyleTextOrientation::Mixed),
mColorAdjust(StyleColorAdjust::Economy) {
MOZ_COUNT_CTOR(nsStyleVisibility);

Просмотреть файл

@ -1067,7 +1067,7 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleVisibility {
mozilla::StyleDirection mDirection;
mozilla::StyleVisibility mVisible;
mozilla::StyleImageRendering mImageRendering;
uint8_t mWritingMode; // NS_STYLE_WRITING_MODE_*
mozilla::StyleWritingModeProperty mWritingMode;
mozilla::StyleTextOrientation mTextOrientation;
mozilla::StyleColorAdjust mColorAdjust;

Просмотреть файл

@ -31,6 +31,7 @@ ${helpers.single_keyword(
servo_2020_pref="layout.writing-mode.enabled",
animation_value_type="none",
spec="https://drafts.csswg.org/css-writing-modes/#propdef-writing-mode",
gecko_enum_prefix="StyleWritingModeProperty",
servo_restyle_damage="rebuild_and_reflow",
)}