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

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

Issue 201293002: Add Traversal<*Element>::firstAncestor() API (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add firstAncestorOrSelf() Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/editing/FrameSelection.cpp ('k') | Source/core/html/HTMLEmbedElement.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008 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 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 if (equalIgnoringCase(value, "yes") || equalIgnoringCase(value, "")) 603 if (equalIgnoringCase(value, "yes") || equalIgnoringCase(value, ""))
604 return TranslateAttributeYes; 604 return TranslateAttributeYes;
605 if (equalIgnoringCase(value, "no")) 605 if (equalIgnoringCase(value, "no"))
606 return TranslateAttributeNo; 606 return TranslateAttributeNo;
607 607
608 return TranslateAttributeInherit; 608 return TranslateAttributeInherit;
609 } 609 }
610 610
611 bool HTMLElement::translate() const 611 bool HTMLElement::translate() const
612 { 612 {
613 for (const Node* n = this; n; n = n->parentNode()) { 613 for (const HTMLElement* element = this; element; element = Traversal<HTMLEle ment>::firstAncestor(*element)) {
614 if (n->isHTMLElement()) { 614 TranslateAttributeMode mode = element->translateAttributeMode();
615 TranslateAttributeMode mode = toHTMLElement(n)->translateAttributeMo de(); 615 if (mode != TranslateAttributeInherit) {
616 if (mode != TranslateAttributeInherit) { 616 ASSERT(mode == TranslateAttributeYes || mode == TranslateAttributeNo );
617 ASSERT(mode == TranslateAttributeYes || mode == TranslateAttribu teNo); 617 return mode == TranslateAttributeYes;
618 return mode == TranslateAttributeYes;
619 }
620 } 618 }
621 } 619 }
622 620
623 // Default on the root element is translate=yes. 621 // Default on the root element is translate=yes.
624 return true; 622 return true;
625 } 623 }
626 624
627 void HTMLElement::setTranslate(bool enable) 625 void HTMLElement::setTranslate(bool enable)
628 { 626 {
629 setAttribute(translateAttr, enable ? "yes" : "no"); 627 setAttribute(translateAttr, enable ? "yes" : "no");
630 } 628 }
631 629
632 HTMLFormElement* HTMLElement::findFormAncestor() const 630 HTMLFormElement* HTMLElement::findFormAncestor() const
633 { 631 {
634 for (ContainerNode* ancestor = parentNode(); ancestor; ancestor = ancestor-> parentNode()) { 632 return Traversal<HTMLFormElement>::firstAncestor(*this);
635 if (isHTMLFormElement(*ancestor))
636 return toHTMLFormElement(ancestor);
637 }
638 return 0;
639 } 633 }
640 634
641 static inline bool elementAffectsDirectionality(const Node* node) 635 static inline bool elementAffectsDirectionality(const Node* node)
642 { 636 {
643 return node->isHTMLElement() && (isHTMLBDIElement(*node) || toHTMLElement(no de)->hasAttribute(dirAttr)); 637 return node->isHTMLElement() && (isHTMLBDIElement(*node) || toHTMLElement(no de)->hasAttribute(dirAttr));
644 } 638 }
645 639
646 static void setHasDirAutoFlagRecursively(Node* firstNode, bool flag, Node* lastN ode = 0) 640 static void setHasDirAutoFlagRecursively(Node* firstNode, bool flag, Node* lastN ode = 0)
647 { 641 {
648 firstNode->setSelfOrAncestorHasDirAutoAttribute(flag); 642 firstNode->setSelfOrAncestorHasDirAutoAttribute(flag);
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 #ifndef NDEBUG 961 #ifndef NDEBUG
968 962
969 // For use in the debugger 963 // For use in the debugger
970 void dumpInnerHTML(WebCore::HTMLElement*); 964 void dumpInnerHTML(WebCore::HTMLElement*);
971 965
972 void dumpInnerHTML(WebCore::HTMLElement* element) 966 void dumpInnerHTML(WebCore::HTMLElement* element)
973 { 967 {
974 printf("%s\n", element->innerHTML().ascii().data()); 968 printf("%s\n", element->innerHTML().ascii().data());
975 } 969 }
976 #endif 970 #endif
OLDNEW
« no previous file with comments | « Source/core/editing/FrameSelection.cpp ('k') | Source/core/html/HTMLEmbedElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698