OLD | NEW |
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 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. | 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. |
6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) | 6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) |
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 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 left = middle + 1; | 541 left = middle + 1; |
542 } | 542 } |
543 | 543 |
544 ASSERT(left < m_associatedElementsBeforeIndex || left >= m_associatedElement
sAfterIndex); | 544 ASSERT(left < m_associatedElementsBeforeIndex || left >= m_associatedElement
sAfterIndex); |
545 position = element->compareDocumentPosition(toHTMLElement(m_associatedElemen
ts[left])); | 545 position = element->compareDocumentPosition(toHTMLElement(m_associatedElemen
ts[left])); |
546 if (position & DOCUMENT_POSITION_FOLLOWING) | 546 if (position & DOCUMENT_POSITION_FOLLOWING) |
547 return left; | 547 return left; |
548 return left + 1; | 548 return left + 1; |
549 } | 549 } |
550 | 550 |
551 unsigned HTMLFormElement::formElementIndex(FormAssociatedElement* associatedElem
ent) | 551 unsigned HTMLFormElement::formElementIndex(FormAssociatedElement& associatedElem
ent) |
552 { | 552 { |
553 HTMLElement* associatedHTMLElement = toHTMLElement(associatedElement); | 553 HTMLElement& associatedHTMLElement = toHTMLElement(associatedElement); |
554 // Treats separately the case where this element has the form attribute | 554 // Treats separately the case where this element has the form attribute |
555 // for performance consideration. | 555 // for performance consideration. |
556 if (associatedHTMLElement->fastHasAttribute(formAttr)) { | 556 if (associatedHTMLElement.fastHasAttribute(formAttr)) { |
557 unsigned short position = compareDocumentPosition(associatedHTMLElement)
; | 557 unsigned short position = compareDocumentPosition(&associatedHTMLElement
); |
558 if (position & DOCUMENT_POSITION_PRECEDING) { | 558 if (position & DOCUMENT_POSITION_PRECEDING) { |
559 ++m_associatedElementsBeforeIndex; | 559 ++m_associatedElementsBeforeIndex; |
560 ++m_associatedElementsAfterIndex; | 560 ++m_associatedElementsAfterIndex; |
561 return HTMLFormElement::formElementIndexWithFormAttribute(associated
HTMLElement, 0, m_associatedElementsBeforeIndex - 1); | 561 return HTMLFormElement::formElementIndexWithFormAttribute(&associate
dHTMLElement, 0, m_associatedElementsBeforeIndex - 1); |
562 } | 562 } |
563 if (position & DOCUMENT_POSITION_FOLLOWING && !(position & DOCUMENT_POSI
TION_CONTAINED_BY)) | 563 if (position & DOCUMENT_POSITION_FOLLOWING && !(position & DOCUMENT_POSI
TION_CONTAINED_BY)) |
564 return HTMLFormElement::formElementIndexWithFormAttribute(associated
HTMLElement, m_associatedElementsAfterIndex, m_associatedElements.size()); | 564 return HTMLFormElement::formElementIndexWithFormAttribute(&associate
dHTMLElement, m_associatedElementsAfterIndex, m_associatedElements.size()); |
565 } | 565 } |
566 | 566 |
567 // Check for the special case where this element is the very last thing in | 567 // Check for the special case where this element is the very last thing in |
568 // the form's tree of children; we don't want to walk the entire tree in tha
t | 568 // the form's tree of children; we don't want to walk the entire tree in tha
t |
569 // common case that occurs during parsing; instead we'll just return a value | 569 // common case that occurs during parsing; instead we'll just return a value |
570 // that says "add this form element to the end of the array". | 570 // that says "add this form element to the end of the array". |
571 if (ElementTraversal::next(associatedHTMLElement, this)) { | 571 if (ElementTraversal::next(associatedHTMLElement, this)) { |
572 unsigned i = m_associatedElementsBeforeIndex; | 572 unsigned i = m_associatedElementsBeforeIndex; |
573 for (Element* element = this; element; element = ElementTraversal::next(
element, this)) { | 573 for (Element* element = this; element; element = ElementTraversal::next(
*element, this)) { |
574 if (element == associatedHTMLElement) { | 574 if (element == associatedHTMLElement) { |
575 ++m_associatedElementsAfterIndex; | 575 ++m_associatedElementsAfterIndex; |
576 return i; | 576 return i; |
577 } | 577 } |
578 if (!element->isFormControlElement() && !element->hasTagName(objectT
ag)) | 578 if (!element->isFormControlElement() && !element->hasTagName(objectT
ag)) |
579 continue; | 579 continue; |
580 if (!element->isHTMLElement() || toHTMLElement(element)->form() != t
his) | 580 if (!element->isHTMLElement() || toHTMLElement(element)->form() != t
his) |
581 continue; | 581 continue; |
582 ++i; | 582 ++i; |
583 } | 583 } |
584 } | 584 } |
585 return m_associatedElementsAfterIndex++; | 585 return m_associatedElementsAfterIndex++; |
586 } | 586 } |
587 | 587 |
588 void HTMLFormElement::registerFormElement(FormAssociatedElement* e) | 588 void HTMLFormElement::registerFormElement(FormAssociatedElement& e) |
589 { | 589 { |
590 m_associatedElements.insert(formElementIndex(e), e); | 590 m_associatedElements.insert(formElementIndex(e), &e); |
591 } | 591 } |
592 | 592 |
593 void HTMLFormElement::removeFormElement(FormAssociatedElement* e) | 593 void HTMLFormElement::removeFormElement(FormAssociatedElement* e) |
594 { | 594 { |
595 unsigned index; | 595 unsigned index; |
596 for (index = 0; index < m_associatedElements.size(); ++index) { | 596 for (index = 0; index < m_associatedElements.size(); ++index) { |
597 if (m_associatedElements[index] == e) | 597 if (m_associatedElements[index] == e) |
598 break; | 598 break; |
599 } | 599 } |
600 ASSERT_WITH_SECURITY_IMPLICATION(index < m_associatedElements.size()); | 600 ASSERT_WITH_SECURITY_IMPLICATION(index < m_associatedElements.size()); |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
821 } | 821 } |
822 | 822 |
823 void HTMLFormElement::setDemoted(bool demoted) | 823 void HTMLFormElement::setDemoted(bool demoted) |
824 { | 824 { |
825 if (demoted) | 825 if (demoted) |
826 UseCounter::count(document(), UseCounter::DemotedFormElement); | 826 UseCounter::count(document(), UseCounter::DemotedFormElement); |
827 m_wasDemoted = demoted; | 827 m_wasDemoted = demoted; |
828 } | 828 } |
829 | 829 |
830 } // namespace | 830 } // namespace |
OLD | NEW |