forked from mirrors/gecko-dev
Bug 1856156 - Make Directionality an enum class. r=smaug
A bit neater this way. Differential Revision: https://phabricator.services.mozilla.com/D198590
This commit is contained in:
parent
72ccddb050
commit
9231eae657
8 changed files with 71 additions and 61 deletions
|
|
@ -258,11 +258,11 @@ nsresult CharacterData::SetTextInternal(
|
|||
MutationObservers::NotifyCharacterDataWillChange(this, info);
|
||||
}
|
||||
|
||||
Directionality oldDir = eDir_NotSet;
|
||||
bool dirAffectsAncestor =
|
||||
(NodeType() == TEXT_NODE &&
|
||||
TextNodeWillChangeDirection(static_cast<nsTextNode*>(this), &oldDir,
|
||||
aOffset));
|
||||
auto oldDir = Directionality::Unset;
|
||||
const bool dirAffectsAncestor =
|
||||
NodeType() == TEXT_NODE &&
|
||||
TextNodeWillChangeDirection(static_cast<nsTextNode*>(this), &oldDir,
|
||||
aOffset);
|
||||
|
||||
if (aOffset == 0 && endOffset == textLength) {
|
||||
// Replacing whole text or old text was empty.
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
When a new text node with non-neutral content is appended to a textarea
|
||||
element with NodeHasDirAuto, if the directionality of the textarea element
|
||||
is still unresolved, it is resolved based on the value of the text node.
|
||||
Elements with unresolved directionality behave as LTR.
|
||||
Elements with unresolved directionality behave as Ltr.
|
||||
|
||||
When a new text node with non-neutral content is appended to an element that
|
||||
is not a textarea but has either of the NodeAncestorHasDirAuto or
|
||||
|
|
@ -308,13 +308,13 @@ static Directionality GetDirectionFromChar(uint32_t ch) {
|
|||
switch (intl::UnicodeProperties::GetBidiClass(ch)) {
|
||||
case intl::BidiClass::RightToLeft:
|
||||
case intl::BidiClass::RightToLeftArabic:
|
||||
return eDir_RTL;
|
||||
return Directionality::Rtl;
|
||||
|
||||
case intl::BidiClass::LeftToRight:
|
||||
return eDir_LTR;
|
||||
return Directionality::Ltr;
|
||||
|
||||
default:
|
||||
return eDir_NotSet;
|
||||
return Directionality::Unset;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -343,7 +343,7 @@ Directionality GetDirectionFromText(const char16_t* aText,
|
|||
// Just ignore lone surrogates
|
||||
if (!IS_SURROGATE(ch)) {
|
||||
Directionality dir = GetDirectionFromChar(ch);
|
||||
if (dir != eDir_NotSet) {
|
||||
if (dir != Directionality::Unset) {
|
||||
if (aFirstStrong) {
|
||||
*aFirstStrong = current;
|
||||
}
|
||||
|
|
@ -355,7 +355,7 @@ Directionality GetDirectionFromText(const char16_t* aText,
|
|||
if (aFirstStrong) {
|
||||
*aFirstStrong = UINT32_MAX;
|
||||
}
|
||||
return eDir_NotSet;
|
||||
return Directionality::Unset;
|
||||
}
|
||||
|
||||
static Directionality GetDirectionFromText(const char* aText,
|
||||
|
|
@ -369,7 +369,7 @@ static Directionality GetDirectionFromText(const char* aText,
|
|||
unsigned char ch = (unsigned char)*start++;
|
||||
|
||||
Directionality dir = GetDirectionFromChar(ch);
|
||||
if (dir != eDir_NotSet) {
|
||||
if (dir != Directionality::Unset) {
|
||||
if (aFirstStrong) {
|
||||
*aFirstStrong = current;
|
||||
}
|
||||
|
|
@ -380,7 +380,7 @@ static Directionality GetDirectionFromText(const char* aText,
|
|||
if (aFirstStrong) {
|
||||
*aFirstStrong = UINT32_MAX;
|
||||
}
|
||||
return eDir_NotSet;
|
||||
return Directionality::Unset;
|
||||
}
|
||||
|
||||
static Directionality GetDirectionFromText(const mozilla::dom::Text* aTextNode,
|
||||
|
|
@ -412,7 +412,7 @@ static nsTextNode* WalkDescendantsAndGetDirectionFromText(
|
|||
auto text = static_cast<nsTextNode*>(assignedNode);
|
||||
if (assignedNode != aSkip) {
|
||||
Directionality textNodeDir = GetDirectionFromText(text);
|
||||
if (textNodeDir != eDir_NotSet) {
|
||||
if (textNodeDir != Directionality::Unset) {
|
||||
*aDirectionality = textNodeDir;
|
||||
return text;
|
||||
}
|
||||
|
|
@ -432,7 +432,7 @@ static nsTextNode* WalkDescendantsAndGetDirectionFromText(
|
|||
if (child->NodeType() == nsINode::TEXT_NODE && child != aSkip) {
|
||||
auto text = static_cast<nsTextNode*>(child);
|
||||
Directionality textNodeDir = GetDirectionFromText(text);
|
||||
if (textNodeDir != eDir_NotSet) {
|
||||
if (textNodeDir != Directionality::Unset) {
|
||||
*aDirectionality = textNodeDir;
|
||||
return text;
|
||||
}
|
||||
|
|
@ -461,7 +461,7 @@ static nsTextNode* WalkDescendantsSetDirectionFromText(
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
Directionality textNodeDir = eDir_NotSet;
|
||||
Directionality textNodeDir = Directionality::Unset;
|
||||
|
||||
// Check the text in Shadow DOM.
|
||||
if (ShadowRoot* shadowRoot = aElement->GetShadowRoot()) {
|
||||
|
|
@ -482,8 +482,8 @@ static nsTextNode* WalkDescendantsSetDirectionFromText(
|
|||
}
|
||||
|
||||
// We walked all the descendants without finding a text node with strong
|
||||
// directional characters. Set the directionality to LTR
|
||||
aElement->SetDirectionality(eDir_LTR, aNotify);
|
||||
// directional characters. Set the directionality to Ltr
|
||||
aElement->SetDirectionality(Directionality::Ltr, aNotify);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
@ -685,12 +685,12 @@ Directionality GetParentDirectionality(const Element* aElement) {
|
|||
// the directionality is the same as the parent element (but don't
|
||||
// propagate the parent directionality if it isn't set yet).
|
||||
Directionality parentDir = parent->AsElement()->GetDirectionality();
|
||||
if (parentDir != eDir_NotSet) {
|
||||
if (parentDir != Directionality::Unset) {
|
||||
return parentDir;
|
||||
}
|
||||
}
|
||||
}
|
||||
return eDir_LTR;
|
||||
return Directionality::Ltr;
|
||||
}
|
||||
|
||||
Directionality RecomputeDirectionality(Element* aElement, bool aNotify) {
|
||||
|
|
@ -710,8 +710,8 @@ Directionality RecomputeDirectionality(Element* aElement, bool aNotify) {
|
|||
// The directionality of the element is 'ltr'.
|
||||
if (auto* input = HTMLInputElement::FromNode(*aElement)) {
|
||||
if (input->ControlType() == FormControlType::InputTel) {
|
||||
aElement->SetDirectionality(eDir_LTR, aNotify);
|
||||
return eDir_LTR;
|
||||
aElement->SetDirectionality(Directionality::Ltr, aNotify);
|
||||
return Directionality::Ltr;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1122,8 +1122,9 @@ bool TextNodeWillChangeDirection(nsTextNode* aTextNode, Directionality* aOldDir,
|
|||
void TextNodeChangedDirection(nsTextNode* aTextNode, Directionality aOldDir,
|
||||
bool aNotify) {
|
||||
Directionality newDir = GetDirectionFromText(aTextNode);
|
||||
if (newDir == eDir_NotSet) {
|
||||
if (aOldDir != eDir_NotSet && aTextNode->HasTextNodeDirectionalityMap()) {
|
||||
if (newDir == Directionality::Unset) {
|
||||
if (aOldDir != Directionality::Unset &&
|
||||
aTextNode->HasTextNodeDirectionalityMap()) {
|
||||
// This node used to have a strong directional character but no
|
||||
// longer does. ResetTextNodeDirection() will re-resolve the
|
||||
// directionality of any elements whose directionality was
|
||||
|
|
@ -1158,7 +1159,7 @@ void SetDirectionFromNewTextNode(nsTextNode* aTextNode) {
|
|||
}
|
||||
|
||||
Directionality dir = GetDirectionFromText(aTextNode);
|
||||
if (dir != eDir_NotSet) {
|
||||
if (dir != Directionality::Unset) {
|
||||
SetAncestorDirectionIfAuto(aTextNode, dir);
|
||||
}
|
||||
}
|
||||
|
|
@ -1170,7 +1171,8 @@ void ResetDirectionSetByTextNode(nsTextNode* aTextNode) {
|
|||
}
|
||||
|
||||
Directionality dir = GetDirectionFromText(aTextNode);
|
||||
if (dir != eDir_NotSet && aTextNode->HasTextNodeDirectionalityMap()) {
|
||||
if (dir != Directionality::Unset &&
|
||||
aTextNode->HasTextNodeDirectionalityMap()) {
|
||||
nsTextNodeDirectionalityMap::ResetTextNodeDirection(aTextNode, aTextNode);
|
||||
}
|
||||
}
|
||||
|
|
@ -1179,8 +1181,8 @@ void SetDirectionalityFromValue(Element* aElement, const nsAString& value,
|
|||
bool aNotify) {
|
||||
Directionality dir =
|
||||
GetDirectionFromText(value.BeginReading(), value.Length());
|
||||
if (dir == eDir_NotSet) {
|
||||
dir = eDir_LTR;
|
||||
if (dir == Directionality::Unset) {
|
||||
dir = Directionality::Ltr;
|
||||
}
|
||||
|
||||
if (aElement->GetDirectionality() != dir) {
|
||||
|
|
|
|||
|
|
@ -22,16 +22,16 @@ class HTMLSlotElement;
|
|||
|
||||
namespace mozilla {
|
||||
|
||||
enum Directionality : uint8_t { eDir_NotSet, eDir_RTL, eDir_LTR, eDir_Auto };
|
||||
enum class Directionality : uint8_t { Unset, Rtl, Ltr, Auto };
|
||||
|
||||
/**
|
||||
* Various methods for returning the directionality of a string using the
|
||||
* first-strong algorithm defined in http://unicode.org/reports/tr9/#P2
|
||||
*
|
||||
* @param[out] aFirstStrong the offset to the first character in the string with
|
||||
* strong directionality, or UINT32_MAX if there is none (return
|
||||
value is eDir_NotSet).
|
||||
* @return the directionality of the string
|
||||
* strong directionality, or UINT32_MAX if there is none (in which
|
||||
* case the return value is Directionality::Unset).
|
||||
* @return the directionality of the string, or Unset if not available.
|
||||
*/
|
||||
Directionality GetDirectionFromText(const char16_t* aText,
|
||||
const uint32_t aLength,
|
||||
|
|
|
|||
|
|
@ -4156,8 +4156,8 @@ void Element::SetOrRemoveNullableStringAttr(nsAtom* aName,
|
|||
Directionality Element::GetComputedDirectionality() const {
|
||||
if (nsIFrame* frame = GetPrimaryFrame()) {
|
||||
return frame->StyleVisibility()->mDirection == StyleDirection::Ltr
|
||||
? eDir_LTR
|
||||
: eDir_RTL;
|
||||
? Directionality::Ltr
|
||||
: Directionality::Rtl;
|
||||
}
|
||||
|
||||
return GetDirectionality();
|
||||
|
|
|
|||
|
|
@ -483,25 +483,27 @@ class Element : public FragmentOrElement {
|
|||
inline Directionality GetDirectionality() const {
|
||||
ElementState state = State();
|
||||
if (state.HasState(ElementState::RTL)) {
|
||||
return eDir_RTL;
|
||||
return Directionality::Rtl;
|
||||
}
|
||||
if (state.HasState(ElementState::LTR)) {
|
||||
return eDir_LTR;
|
||||
return Directionality::Ltr;
|
||||
}
|
||||
return eDir_NotSet;
|
||||
return Directionality::Unset;
|
||||
}
|
||||
|
||||
inline void SetDirectionality(Directionality aDir, bool aNotify) {
|
||||
AutoStateChangeNotifier notifier(*this, aNotify);
|
||||
RemoveStatesSilently(ElementState::DIR_STATES);
|
||||
switch (aDir) {
|
||||
case eDir_RTL:
|
||||
case Directionality::Rtl:
|
||||
AddStatesSilently(ElementState::RTL);
|
||||
break;
|
||||
case eDir_LTR:
|
||||
case Directionality::Ltr:
|
||||
AddStatesSilently(ElementState::LTR);
|
||||
break;
|
||||
default:
|
||||
case Directionality::Unset:
|
||||
case Directionality::Auto:
|
||||
MOZ_ASSERT_UNREACHABLE("Setting unresolved directionality?");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4375,16 +4375,16 @@ nsDOMWindowUtils::GetDirectionFromText(const nsAString& aString,
|
|||
Directionality dir =
|
||||
::GetDirectionFromText(aString.BeginReading(), aString.Length(), nullptr);
|
||||
switch (dir) {
|
||||
case eDir_NotSet:
|
||||
case Directionality::Unset:
|
||||
*aRetval = nsIDOMWindowUtils::DIRECTION_NOT_SET;
|
||||
break;
|
||||
case eDir_RTL:
|
||||
case Directionality::Rtl:
|
||||
*aRetval = nsIDOMWindowUtils::DIRECTION_RTL;
|
||||
break;
|
||||
case eDir_LTR:
|
||||
case Directionality::Ltr:
|
||||
*aRetval = nsIDOMWindowUtils::DIRECTION_LTR;
|
||||
break;
|
||||
case eDir_Auto:
|
||||
case Directionality::Auto:
|
||||
MOZ_ASSERT_UNREACHABLE(
|
||||
"GetDirectionFromText should never return this value");
|
||||
return NS_ERROR_FAILURE;
|
||||
|
|
|
|||
|
|
@ -3849,14 +3849,16 @@ nsresult HTMLInputElement::PostHandleEvent(EventChainPostVisitor& aVisitor) {
|
|||
Decimal newValue;
|
||||
switch (keyEvent->mKeyCode) {
|
||||
case NS_VK_LEFT:
|
||||
newValue =
|
||||
value +
|
||||
(GetComputedDirectionality() == eDir_RTL ? step : -step);
|
||||
newValue = value +
|
||||
(GetComputedDirectionality() == Directionality::Rtl
|
||||
? step
|
||||
: -step);
|
||||
break;
|
||||
case NS_VK_RIGHT:
|
||||
newValue =
|
||||
value +
|
||||
(GetComputedDirectionality() == eDir_RTL ? -step : step);
|
||||
newValue = value +
|
||||
(GetComputedDirectionality() == Directionality::Rtl
|
||||
? -step
|
||||
: step);
|
||||
break;
|
||||
case NS_VK_UP:
|
||||
// Even for horizontal range, "up" means "increase"
|
||||
|
|
@ -4176,7 +4178,7 @@ nsresult HTMLInputElement::MaybeHandleRadioButtonNavigation(
|
|||
return RadioButtonMove::Forward;
|
||||
case NS_VK_LEFT:
|
||||
case NS_VK_RIGHT: {
|
||||
const bool isRtl = GetComputedDirectionality() == eDir_RTL;
|
||||
const bool isRtl = GetComputedDirectionality() == Directionality::Rtl;
|
||||
return isRtl == (aKeyCode == NS_VK_LEFT) ? RadioButtonMove::Forward
|
||||
: RadioButtonMove::Back;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -174,7 +174,11 @@ nsresult nsGenericHTMLElement::CopyInnerTo(Element* aDst) {
|
|||
}
|
||||
|
||||
static const nsAttrValue::EnumTable kDirTable[] = {
|
||||
{"ltr", eDir_LTR}, {"rtl", eDir_RTL}, {"auto", eDir_Auto}, {nullptr, 0}};
|
||||
{"ltr", Directionality::Ltr},
|
||||
{"rtl", Directionality::Rtl},
|
||||
{"auto", Directionality::Auto},
|
||||
{nullptr, 0},
|
||||
};
|
||||
|
||||
namespace {
|
||||
// See <https://html.spec.whatwg.org/#the-popover-attribute>.
|
||||
|
|
@ -768,7 +772,7 @@ void nsGenericHTMLElement::AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
|
|||
NewRunnableMethod("nsGenericHTMLElement::AfterSetPopoverAttr", this,
|
||||
&nsGenericHTMLElement::AfterSetPopoverAttr));
|
||||
} else if (aName == nsGkAtoms::dir) {
|
||||
Directionality dir = eDir_LTR;
|
||||
auto dir = Directionality::Ltr;
|
||||
// A boolean tracking whether we need to recompute our directionality.
|
||||
// This needs to happen after we update our internal "dir" attribute
|
||||
// state but before we call SetDirectionalityOnDescendants.
|
||||
|
|
@ -777,16 +781,16 @@ void nsGenericHTMLElement::AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
|
|||
if (aValue && aValue->Type() == nsAttrValue::eEnum) {
|
||||
SetHasValidDir();
|
||||
dirStates |= ElementState::HAS_DIR_ATTR;
|
||||
Directionality dirValue = (Directionality)aValue->GetEnumValue();
|
||||
if (dirValue == eDir_Auto) {
|
||||
auto dirValue = Directionality(aValue->GetEnumValue());
|
||||
if (dirValue == Directionality::Auto) {
|
||||
dirStates |= ElementState::HAS_DIR_ATTR_LIKE_AUTO;
|
||||
} else {
|
||||
dir = dirValue;
|
||||
SetDirectionality(dir, aNotify);
|
||||
if (dirValue == eDir_LTR) {
|
||||
if (dirValue == Directionality::Ltr) {
|
||||
dirStates |= ElementState::HAS_DIR_ATTR_LTR;
|
||||
} else {
|
||||
MOZ_ASSERT(dirValue == eDir_RTL);
|
||||
MOZ_ASSERT(dirValue == Directionality::Rtl);
|
||||
dirStates |= ElementState::HAS_DIR_ATTR_RTL;
|
||||
}
|
||||
}
|
||||
|
|
@ -2769,11 +2773,11 @@ nsresult nsGenericHTMLFormControlElement::SubmitDirnameDir(
|
|||
nsAutoString dirname;
|
||||
GetAttr(nsGkAtoms::dirname, dirname);
|
||||
if (!dirname.IsEmpty()) {
|
||||
const Directionality eDir = GetDirectionality();
|
||||
MOZ_ASSERT(eDir == eDir_RTL || eDir == eDir_LTR,
|
||||
const Directionality dir = GetDirectionality();
|
||||
MOZ_ASSERT(dir == Directionality::Ltr || dir == Directionality::Rtl,
|
||||
"The directionality of an element is either ltr or rtl");
|
||||
const nsString dir = eDir == eDir_LTR ? u"ltr"_ns : u"rtl"_ns;
|
||||
return aFormData->AddNameValuePair(dirname, dir);
|
||||
return aFormData->AddNameValuePair(
|
||||
dirname, dir == Directionality::Ltr ? u"ltr"_ns : u"rtl"_ns);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
|
|
|
|||
Loading…
Reference in a new issue