Index: third_party/WebKit/Source/core/html/HTMLElement.cpp |
diff --git a/third_party/WebKit/Source/core/html/HTMLElement.cpp b/third_party/WebKit/Source/core/html/HTMLElement.cpp |
index 6315b9278f5133ba3187559df498d20f6070aa9b..2c76cff5df404c7a92c92fd22f562eb830706229 100644 |
--- a/third_party/WebKit/Source/core/html/HTMLElement.cpp |
+++ b/third_party/WebKit/Source/core/html/HTMLElement.cpp |
@@ -711,15 +711,7 @@ bool HTMLElement::hasDirectionAuto() const |
return (isHTMLBDIElement(*this) && direction == nullAtom) || equalIgnoringCase(direction, "auto"); |
} |
-TextDirection HTMLElement::directionalityIfhasDirAutoAttribute(bool& isAuto) const |
-{ |
- isAuto = hasDirectionAuto(); |
- if (!isAuto) |
- return LTR; |
- return directionality(); |
-} |
- |
-TextDirection HTMLElement::directionality(Node** strongDirectionalityTextNode) const |
+TextDirection HTMLElement::computeDirectionality(Node** strongDirectionalityTextNode) const |
{ |
if (isHTMLInputElement(*this)) { |
HTMLInputElement* inputElement = toHTMLInputElement(const_cast<HTMLElement*>(this)); |
@@ -776,32 +768,46 @@ void HTMLElement::dirAttributeChanged(const AtomicString& value) |
updateDistribution(); |
Element* parent = FlatTreeTraversal::parentElement(*this); |
if (parent && parent->isHTMLElement() && toHTMLElement(parent)->selfOrAncestorHasDirAutoAttribute()) |
- toHTMLElement(parent)->adjustDirectionalityIfNeededAfterChildAttributeChanged(this); |
+ toHTMLElement(parent)->updateSelfOrAncestorForDirAuto(); |
- if (equalIgnoringCase(value, "auto")) |
- calculateAndAdjustDirectionality(); |
+ if (equalIgnoringCase(value, "auto")) { |
+ updateForDirAuto(); |
+ } else if (elementData() && elementData()->directionality() != CachedTextDirection::NotAutoOrNotCached) { |
+ DCHECK(elementData()->isUnique()); |
+ const_cast<ElementData*>(elementData())->setDirectionality(CachedTextDirection::NotAutoOrNotCached); |
+ } |
} |
-void HTMLElement::adjustDirectionalityIfNeededAfterChildAttributeChanged(Element* child) |
+void HTMLElement::updateSelfOrAncestorForDirAuto() |
{ |
ASSERT(selfOrAncestorHasDirAutoAttribute()); |
- TextDirection textDirection = directionality(); |
- if (layoutObject() && layoutObject()->style() && layoutObject()->style()->direction() != textDirection) { |
- Element* elementToAdjust = this; |
- for (; elementToAdjust; elementToAdjust = FlatTreeTraversal::parentElement(*elementToAdjust)) { |
- if (elementAffectsDirectionality(elementToAdjust)) { |
- elementToAdjust->setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTracing::create(StyleChangeReason::WritingModeChange)); |
- return; |
- } |
- } |
- } |
+ //XXX add test that this would code would fail |
+ //TextDirection textDirection = computeDirectionality(); |
+ //if (layoutObject() && layoutObject()->style() && layoutObject()->style()->direction() != textDirection) { |
+ Element* elementToAdjust = this; |
+ while (!elementAffectsDirectionality(elementToAdjust)) |
+ elementToAdjust = FlatTreeTraversal::parentElement(*elementToAdjust); |
+ toHTMLElement(elementToAdjust)->updateForDirAuto(); |
+} |
+ |
+void HTMLElement::updateForDirAuto() |
+{ |
+ if (!hasDirectionAuto()) |
+ return; |
+ ensureUniqueElementData().setDirectionality(CachedTextDirection::NotAutoOrNotCached); |
+ pseudoStateChanged(CSSSelector::PseudoDir); |
+ setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTracing::create(StyleChangeReason::WritingModeChange)); |
} |
-void HTMLElement::calculateAndAdjustDirectionality() |
+void HTMLElement::cacheDirectionalityForDirAuto() const |
{ |
- TextDirection textDirection = directionality(); |
- if (layoutObject() && layoutObject()->style() && layoutObject()->style()->direction() != textDirection) |
- setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTracing::create(StyleChangeReason::WritingModeChange)); |
+ DCHECK(hasDirectionAuto()); |
+ DCHECK(elementData() && elementData()->isUnique()); |
+ DCHECK(elementData()->directionality() == CachedTextDirection::NotAutoOrNotCached); |
+ if (computeDirectionality() == LTR) |
+ elementData()->setDirectionality(CachedTextDirection::AutoLTR); |
+ else |
+ elementData()->setDirectionality(CachedTextDirection::AutoRTL); |
} |
void HTMLElement::adjustDirectionalityIfNeededAfterChildrenChanged(const ChildrenChange& change) |
@@ -810,13 +816,7 @@ void HTMLElement::adjustDirectionalityIfNeededAfterChildrenChanged(const Childre |
return; |
updateDistribution(); |
- |
- for (Element* elementToAdjust = this; elementToAdjust; elementToAdjust = FlatTreeTraversal::parentElement(*elementToAdjust)) { |
- if (elementAffectsDirectionality(elementToAdjust)) { |
- toHTMLElement(elementToAdjust)->calculateAndAdjustDirectionality(); |
- return; |
- } |
- } |
+ updateSelfOrAncestorForDirAuto(); |
} |
void HTMLElement::addHTMLLengthToStyle(MutableStylePropertySet* style, CSSPropertyID propertyID, const String& value) |