diff options
author | Matt A. Tobin <email@mattatobin.com> | 2020-04-17 05:50:47 -0400 |
---|---|---|
committer | Matt A. Tobin <email@mattatobin.com> | 2020-04-17 05:50:47 -0400 |
commit | 4d1d777e706322cb9aca8ed2d5a6e50b805d3bd1 (patch) | |
tree | 1cea0ad854fb25e536caf93f240258eebfb3aea8 /dom/base | |
parent | 32e8155127126c187ce32f7368742057bcaf69da (diff) | |
download | UXP-4d1d777e706322cb9aca8ed2d5a6e50b805d3bd1.tar UXP-4d1d777e706322cb9aca8ed2d5a6e50b805d3bd1.tar.gz UXP-4d1d777e706322cb9aca8ed2d5a6e50b805d3bd1.tar.lz UXP-4d1d777e706322cb9aca8ed2d5a6e50b805d3bd1.tar.xz UXP-4d1d777e706322cb9aca8ed2d5a6e50b805d3bd1.zip |
Bug 1373798 - Move HTML dir attribute state into event state flags
* Stop calling SetHasDirAuto/ClearHasDirAuto in input element code
* Introduce event state flags that track the state of an element's dir attribute
* Rewrite our existing checks for the state of the dir attr on top of the new event state flags
* Add pseudo-classes for matching on the dir attribute states
* Use the new dir attribute pseudoclasses in html.css
Tag #1375
Diffstat (limited to 'dom/base')
-rw-r--r-- | dom/base/DirectionalityUtils.cpp | 4 | ||||
-rw-r--r-- | dom/base/Element.h | 36 | ||||
-rw-r--r-- | dom/base/nsIContentInlines.h | 6 | ||||
-rw-r--r-- | dom/base/nsINode.h | 28 |
4 files changed, 41 insertions, 33 deletions
diff --git a/dom/base/DirectionalityUtils.cpp b/dom/base/DirectionalityUtils.cpp index d9a6c4524..632abb2c8 100644 --- a/dom/base/DirectionalityUtils.cpp +++ b/dom/base/DirectionalityUtils.cpp @@ -728,7 +728,7 @@ WalkDescendantsResetAutoDirection(Element* aElement) { nsIContent* child = aElement->GetFirstChild(); while (child) { - if (child->HasDirAuto()) { + if (child->IsElement() && child->AsElement()->HasDirAuto()) { child = child->GetNextNonChildNode(aElement); continue; } @@ -791,7 +791,7 @@ WalkDescendantsClearAncestorDirAuto(Element* aElement) { nsIContent* child = aElement->GetFirstChild(); while (child) { - if (child->HasDirAuto()) { + if (child->IsElement() && child->AsElement()->HasDirAuto()) { child = child->GetNextNonChildNode(aElement); continue; } diff --git a/dom/base/Element.h b/dom/base/Element.h index df0dbcc45..76f0767e6 100644 --- a/dom/base/Element.h +++ b/dom/base/Element.h @@ -256,6 +256,23 @@ public: void ClearStyleStateLocks(); /** + * Accessors for the state of our dir attribute. + */ + bool HasDirAuto() const + { + return State().HasState(NS_EVENT_STATE_DIR_ATTR_LIKE_AUTO); + } + + /** + * Elements with dir="rtl" or dir="ltr". + */ + bool HasFixedDir() const + { + return State().HasAtLeastOneOfStates(NS_EVENT_STATE_DIR_ATTR_LTR | + NS_EVENT_STATE_DIR_ATTR_RTL); + } + + /** * Get the inline style declaration, if any, for this element. */ virtual DeclarationBlock* GetInlineStyleDeclaration(); @@ -380,15 +397,6 @@ public: bool GetBindingURL(nsIDocument *aDocument, css::URLValue **aResult); - // The bdi element defaults to dir=auto if it has no dir attribute set. - // Other elements will only have dir=auto if they have an explicit dir=auto, - // which will mean that HasValidDir() returns true but HasFixedDir() returns - // false - inline bool HasDirAuto() const { - return (!HasFixedDir() && - (HasValidDir() || IsHTMLElement(nsGkAtoms::bdi))); - } - Directionality GetComputedDirectionality() const; inline Element* GetFlattenedTreeParentElementForStyle() const; @@ -501,6 +509,16 @@ protected: RemoveStatesSilently(aStates); NotifyStateChange(aStates); } + virtual void ToggleStates(EventStates aStates, bool aNotify) + { + NS_PRECONDITION(!aStates.HasAtLeastOneOfStates(INTRINSIC_STATES), + "Should only be removing externally-managed states here"); + mState ^= aStates; + if (aNotify) { + NotifyStateChange(aStates); + } + } + public: virtual void UpdateEditableState(bool aNotify) override; diff --git a/dom/base/nsIContentInlines.h b/dom/base/nsIContentInlines.h index 6a82f7f65..6a9bd7afa 100644 --- a/dom/base/nsIContentInlines.h +++ b/dom/base/nsIContentInlines.h @@ -87,4 +87,10 @@ nsINode::GetFlattenedTreeParentNodeForStyle() const return ::GetFlattenedTreeParentNode<nsIContent::eForStyle>(this); } +inline bool +nsINode::NodeOrAncestorHasDirAuto() const +{ + return AncestorHasDirAuto() || (IsElement() && AsElement()->HasDirAuto()); +} + #endif // nsIContentInlines_h diff --git a/dom/base/nsINode.h b/dom/base/nsINode.h index 0f882445f..7c3eb9134 100644 --- a/dom/base/nsINode.h +++ b/dom/base/nsINode.h @@ -1608,10 +1608,11 @@ private: NodeIsContent, // Set if the node has animations or transitions ElementHasAnimations, - // Set if node has a dir attribute with a valid value (ltr, rtl, or auto) + // Set if node has a dir attribute with a valid value (ltr, rtl, or auto). + // Note that we cannot compute this from the dir attribute event state + // flags, because we can't use those to distinguish + // <bdi dir="some-invalid-value"> and <bdi dir="auto">. NodeHasValidDirAttribute, - // Set if node has a dir attribute with a fixed value (ltr or rtl, NOT auto) - NodeHasFixedDir, // Set if the node has dir=auto and has a property pointing to the text // node that determines its direction NodeHasDirAutoSet, @@ -1619,8 +1620,6 @@ private: // and has a TextNodeDirectionalityMap property listing the elements whose // direction it determines. NodeHasTextNodeDirectionalityMap, - // Set if the node has dir=auto. - NodeHasDirAuto, // Set if a node in the node's parent chain has dir=auto. NodeAncestorHasDirAuto, // Set if the element is in the scope of a scoped style sheet; this flag is @@ -1715,17 +1714,6 @@ public: void SetHasValidDir() { SetBoolFlag(NodeHasValidDirAttribute); } void ClearHasValidDir() { ClearBoolFlag(NodeHasValidDirAttribute); } bool HasValidDir() const { return GetBoolFlag(NodeHasValidDirAttribute); } - void SetHasFixedDir() { - MOZ_ASSERT(NodeType() != nsIDOMNode::TEXT_NODE, - "SetHasFixedDir on text node"); - SetBoolFlag(NodeHasFixedDir); - } - void ClearHasFixedDir() { - MOZ_ASSERT(NodeType() != nsIDOMNode::TEXT_NODE, - "ClearHasFixedDir on text node"); - ClearBoolFlag(NodeHasFixedDir); - } - bool HasFixedDir() const { return GetBoolFlag(NodeHasFixedDir); } void SetHasDirAutoSet() { MOZ_ASSERT(NodeType() != nsIDOMNode::TEXT_NODE, "SetHasDirAutoSet on text node"); @@ -1754,16 +1742,12 @@ public: return GetBoolFlag(NodeHasTextNodeDirectionalityMap); } - void SetHasDirAuto() { SetBoolFlag(NodeHasDirAuto); } - void ClearHasDirAuto() { ClearBoolFlag(NodeHasDirAuto); } - bool HasDirAuto() const { return GetBoolFlag(NodeHasDirAuto); } - void SetAncestorHasDirAuto() { SetBoolFlag(NodeAncestorHasDirAuto); } void ClearAncestorHasDirAuto() { ClearBoolFlag(NodeAncestorHasDirAuto); } bool AncestorHasDirAuto() const { return GetBoolFlag(NodeAncestorHasDirAuto); } - bool NodeOrAncestorHasDirAuto() const - { return HasDirAuto() || AncestorHasDirAuto(); } + // Implemented in nsIContentInlines.h. + inline bool NodeOrAncestorHasDirAuto() const; void SetIsElementInStyleScope(bool aValue) { MOZ_ASSERT(IsElement(), "SetIsInStyleScope on a non-Element node"); |