Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(864)

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLElement.cpp

Issue 1898403002: [WIP] Implement :dir() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase... other changes too probably Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2004-2008, 2013, 2014 Apple Inc. All rights reserved. 4 * Copyright (C) 2004-2008, 2013, 2014 Apple Inc. All rights reserved.
5 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 5 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
6 * Copyright (C) 2011 Motorola Mobility. All rights reserved. 6 * Copyright (C) 2011 Motorola Mobility. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 } 704 }
705 705
706 bool HTMLElement::hasDirectionAuto() const 706 bool HTMLElement::hasDirectionAuto() const
707 { 707 {
708 // <bdi> defaults to dir="auto" 708 // <bdi> defaults to dir="auto"
709 // https://html.spec.whatwg.org/multipage/semantics.html#the-bdi-element 709 // https://html.spec.whatwg.org/multipage/semantics.html#the-bdi-element
710 const AtomicString& direction = fastGetAttribute(dirAttr); 710 const AtomicString& direction = fastGetAttribute(dirAttr);
711 return (isHTMLBDIElement(*this) && direction == nullAtom) || equalIgnoringCa se(direction, "auto"); 711 return (isHTMLBDIElement(*this) && direction == nullAtom) || equalIgnoringCa se(direction, "auto");
712 } 712 }
713 713
714 TextDirection HTMLElement::directionalityIfhasDirAutoAttribute(bool& isAuto) con st 714 TextDirection HTMLElement::computeDirectionality(Node** strongDirectionalityText Node) const
715 {
716 isAuto = hasDirectionAuto();
717 if (!isAuto)
718 return LTR;
719 return directionality();
720 }
721
722 TextDirection HTMLElement::directionality(Node** strongDirectionalityTextNode) c onst
723 { 715 {
724 if (isHTMLInputElement(*this)) { 716 if (isHTMLInputElement(*this)) {
725 HTMLInputElement* inputElement = toHTMLInputElement(const_cast<HTMLEleme nt*>(this)); 717 HTMLInputElement* inputElement = toHTMLInputElement(const_cast<HTMLEleme nt*>(this));
726 bool hasStrongDirectionality; 718 bool hasStrongDirectionality;
727 TextDirection textDirection = determineDirectionality(inputElement->valu e(), &hasStrongDirectionality); 719 TextDirection textDirection = determineDirectionality(inputElement->valu e(), &hasStrongDirectionality);
728 if (strongDirectionalityTextNode) 720 if (strongDirectionalityTextNode)
729 *strongDirectionalityTextNode = hasStrongDirectionality ? inputEleme nt : 0; 721 *strongDirectionalityTextNode = hasStrongDirectionality ? inputEleme nt : 0;
730 return textDirection; 722 return textDirection;
731 } 723 }
732 724
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 return layoutObject() && layoutObject()->style() && layoutObject()->style()- >selfOrAncestorHasDirAutoAttribute(); 761 return layoutObject() && layoutObject()->style() && layoutObject()->style()- >selfOrAncestorHasDirAutoAttribute();
770 } 762 }
771 763
772 void HTMLElement::dirAttributeChanged(const AtomicString& value) 764 void HTMLElement::dirAttributeChanged(const AtomicString& value)
773 { 765 {
774 // If an ancestor has dir=auto, and this node has the first character, 766 // If an ancestor has dir=auto, and this node has the first character,
775 // changes to dir attribute may affect the ancestor. 767 // changes to dir attribute may affect the ancestor.
776 updateDistribution(); 768 updateDistribution();
777 Element* parent = FlatTreeTraversal::parentElement(*this); 769 Element* parent = FlatTreeTraversal::parentElement(*this);
778 if (parent && parent->isHTMLElement() && toHTMLElement(parent)->selfOrAncest orHasDirAutoAttribute()) 770 if (parent && parent->isHTMLElement() && toHTMLElement(parent)->selfOrAncest orHasDirAutoAttribute())
779 toHTMLElement(parent)->adjustDirectionalityIfNeededAfterChildAttributeCh anged(this); 771 toHTMLElement(parent)->updateSelfOrAncestorForDirAuto();
780 772
781 if (equalIgnoringCase(value, "auto")) 773 if (equalIgnoringCase(value, "auto")) {
782 calculateAndAdjustDirectionality(); 774 updateForDirAuto();
783 } 775 } else if (elementData() && elementData()->directionality() != CachedTextDir ection::NotAutoOrNotCached) {
784 776 DCHECK(elementData()->isUnique());
785 void HTMLElement::adjustDirectionalityIfNeededAfterChildAttributeChanged(Element * child) 777 const_cast<ElementData*>(elementData())->setDirectionality(CachedTextDir ection::NotAutoOrNotCached);
786 {
787 ASSERT(selfOrAncestorHasDirAutoAttribute());
788 TextDirection textDirection = directionality();
789 if (layoutObject() && layoutObject()->style() && layoutObject()->style()->di rection() != textDirection) {
790 Element* elementToAdjust = this;
791 for (; elementToAdjust; elementToAdjust = FlatTreeTraversal::parentEleme nt(*elementToAdjust)) {
792 if (elementAffectsDirectionality(elementToAdjust)) {
793 elementToAdjust->setNeedsStyleRecalc(LocalStyleChange, StyleChan geReasonForTracing::create(StyleChangeReason::WritingModeChange));
794 return;
795 }
796 }
797 } 778 }
798 } 779 }
799 780
800 void HTMLElement::calculateAndAdjustDirectionality() 781 void HTMLElement::updateSelfOrAncestorForDirAuto()
801 { 782 {
802 TextDirection textDirection = directionality(); 783 ASSERT(selfOrAncestorHasDirAutoAttribute());
803 if (layoutObject() && layoutObject()->style() && layoutObject()->style()->di rection() != textDirection) 784 //XXX add test that this would code would fail
804 setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTracing::creat e(StyleChangeReason::WritingModeChange)); 785 //TextDirection textDirection = computeDirectionality();
786 //if (layoutObject() && layoutObject()->style() && layoutObject()->style()-> direction() != textDirection) {
787 Element* elementToAdjust = this;
788 while (!elementAffectsDirectionality(elementToAdjust))
789 elementToAdjust = FlatTreeTraversal::parentElement(*elementToAdjust);
790 toHTMLElement(elementToAdjust)->updateForDirAuto();
791 }
792
793 void HTMLElement::updateForDirAuto()
794 {
795 if (!hasDirectionAuto())
796 return;
797 ensureUniqueElementData().setDirectionality(CachedTextDirection::NotAutoOrNo tCached);
798 pseudoStateChanged(CSSSelector::PseudoDir);
799 setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTracing::create(St yleChangeReason::WritingModeChange));
800 }
801
802 void HTMLElement::cacheDirectionalityForDirAuto() const
803 {
804 DCHECK(hasDirectionAuto());
805 DCHECK(elementData() && elementData()->isUnique());
806 DCHECK(elementData()->directionality() == CachedTextDirection::NotAutoOrNotC ached);
807 if (computeDirectionality() == LTR)
808 elementData()->setDirectionality(CachedTextDirection::AutoLTR);
809 else
810 elementData()->setDirectionality(CachedTextDirection::AutoRTL);
805 } 811 }
806 812
807 void HTMLElement::adjustDirectionalityIfNeededAfterChildrenChanged(const Childre nChange& change) 813 void HTMLElement::adjustDirectionalityIfNeededAfterChildrenChanged(const Childre nChange& change)
808 { 814 {
809 if (!selfOrAncestorHasDirAutoAttribute()) 815 if (!selfOrAncestorHasDirAutoAttribute())
810 return; 816 return;
811 817
812 updateDistribution(); 818 updateDistribution();
813 819 updateSelfOrAncestorForDirAuto();
814 for (Element* elementToAdjust = this; elementToAdjust; elementToAdjust = Fla tTreeTraversal::parentElement(*elementToAdjust)) {
815 if (elementAffectsDirectionality(elementToAdjust)) {
816 toHTMLElement(elementToAdjust)->calculateAndAdjustDirectionality();
817 return;
818 }
819 }
820 } 820 }
821 821
822 void HTMLElement::addHTMLLengthToStyle(MutableStylePropertySet* style, CSSProper tyID propertyID, const String& value) 822 void HTMLElement::addHTMLLengthToStyle(MutableStylePropertySet* style, CSSProper tyID propertyID, const String& value)
823 { 823 {
824 // FIXME: This function should not spin up the CSS parser, but should instea d just figure out the correct 824 // FIXME: This function should not spin up the CSS parser, but should instea d just figure out the correct
825 // length unit and make the appropriate parsed value. 825 // length unit and make the appropriate parsed value.
826 826
827 // strip attribute garbage.. 827 // strip attribute garbage..
828 StringImpl* v = value.impl(); 828 StringImpl* v = value.impl();
829 if (v) { 829 if (v) {
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 #ifndef NDEBUG 1037 #ifndef NDEBUG
1038 1038
1039 // For use in the debugger 1039 // For use in the debugger
1040 void dumpInnerHTML(blink::HTMLElement*); 1040 void dumpInnerHTML(blink::HTMLElement*);
1041 1041
1042 void dumpInnerHTML(blink::HTMLElement* element) 1042 void dumpInnerHTML(blink::HTMLElement* element)
1043 { 1043 {
1044 printf("%s\n", element->innerHTML().ascii().data()); 1044 printf("%s\n", element->innerHTML().ascii().data());
1045 } 1045 }
1046 #endif 1046 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698