| 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 Apple Inc. All rights reserved. | 5 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. |
| 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 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 it.advance(index - 1); | 401 it.advance(index - 1); |
| 402 return createVisiblePosition(it.endPosition(), TextAffinity::Upstream); | 402 return createVisiblePosition(it.endPosition(), TextAffinity::Upstream); |
| 403 } | 403 } |
| 404 | 404 |
| 405 int HTMLTextFormControlElement::indexForVisiblePosition(const VisiblePosition& p
os) const | 405 int HTMLTextFormControlElement::indexForVisiblePosition(const VisiblePosition& p
os) const |
| 406 { | 406 { |
| 407 Position indexPosition = pos.deepEquivalent().parentAnchoredEquivalent(); | 407 Position indexPosition = pos.deepEquivalent().parentAnchoredEquivalent(); |
| 408 if (enclosingTextFormControl(indexPosition) != this) | 408 if (enclosingTextFormControl(indexPosition) != this) |
| 409 return 0; | 409 return 0; |
| 410 ASSERT(indexPosition.document()); | 410 ASSERT(indexPosition.document()); |
| 411 RefPtrWillBeRawPtr<Range> range = Range::create(*indexPosition.document()); | 411 RawPtr<Range> range = Range::create(*indexPosition.document()); |
| 412 range->setStart(innerEditorElement(), 0, ASSERT_NO_EXCEPTION); | 412 range->setStart(innerEditorElement(), 0, ASSERT_NO_EXCEPTION); |
| 413 range->setEnd(indexPosition.computeContainerNode(), indexPosition.offsetInCo
ntainerNode(), ASSERT_NO_EXCEPTION); | 413 range->setEnd(indexPosition.computeContainerNode(), indexPosition.offsetInCo
ntainerNode(), ASSERT_NO_EXCEPTION); |
| 414 return TextIterator::rangeLength(range->startPosition(), range->endPosition(
)); | 414 return TextIterator::rangeLength(range->startPosition(), range->endPosition(
)); |
| 415 } | 415 } |
| 416 | 416 |
| 417 int HTMLTextFormControlElement::selectionStart() const | 417 int HTMLTextFormControlElement::selectionStart() const |
| 418 { | 418 { |
| 419 if (!isTextFormControl()) | 419 if (!isTextFormControl()) |
| 420 return 0; | 420 return 0; |
| 421 if (document().focusedElement() != this) | 421 if (document().focusedElement() != this) |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 { | 497 { |
| 498 if (node->isTextNode()) { | 498 if (node->isTextNode()) { |
| 499 containerNode = node; | 499 containerNode = node; |
| 500 offsetInContainer = offset; | 500 offsetInContainer = offset; |
| 501 } else { | 501 } else { |
| 502 containerNode = node->parentNode(); | 502 containerNode = node->parentNode(); |
| 503 offsetInContainer = node->nodeIndex() + offset; | 503 offsetInContainer = node->nodeIndex() + offset; |
| 504 } | 504 } |
| 505 } | 505 } |
| 506 | 506 |
| 507 PassRefPtrWillBeRawPtr<Range> HTMLTextFormControlElement::selection() const | 507 RawPtr<Range> HTMLTextFormControlElement::selection() const |
| 508 { | 508 { |
| 509 if (!layoutObject() || !isTextFormControl()) | 509 if (!layoutObject() || !isTextFormControl()) |
| 510 return nullptr; | 510 return nullptr; |
| 511 | 511 |
| 512 int start = m_cachedSelectionStart; | 512 int start = m_cachedSelectionStart; |
| 513 int end = m_cachedSelectionEnd; | 513 int end = m_cachedSelectionEnd; |
| 514 | 514 |
| 515 ASSERT(start <= end); | 515 ASSERT(start <= end); |
| 516 HTMLElement* innerText = innerEditorElement(); | 516 HTMLElement* innerText = innerEditorElement(); |
| 517 if (!innerText) | 517 if (!innerText) |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 cacheSelection(computeSelectionStart(), computeSelectionEnd(), computeSelect
ionDirection()); | 586 cacheSelection(computeSelectionStart(), computeSelectionEnd(), computeSelect
ionDirection()); |
| 587 | 587 |
| 588 if (LocalFrame* frame = document().frame()) { | 588 if (LocalFrame* frame = document().frame()) { |
| 589 if (frame->selection().isRange() && userTriggered) | 589 if (frame->selection().isRange() && userTriggered) |
| 590 dispatchEvent(Event::createBubble(EventTypeNames::select)); | 590 dispatchEvent(Event::createBubble(EventTypeNames::select)); |
| 591 } | 591 } |
| 592 } | 592 } |
| 593 | 593 |
| 594 void HTMLTextFormControlElement::scheduleSelectEvent() | 594 void HTMLTextFormControlElement::scheduleSelectEvent() |
| 595 { | 595 { |
| 596 RefPtrWillBeRawPtr<Event> event = Event::createBubble(EventTypeNames::select
); | 596 RawPtr<Event> event = Event::createBubble(EventTypeNames::select); |
| 597 event->setTarget(this); | 597 event->setTarget(this); |
| 598 document().enqueueUniqueAnimationFrameEvent(event.release()); | 598 document().enqueueUniqueAnimationFrameEvent(event.release()); |
| 599 } | 599 } |
| 600 | 600 |
| 601 void HTMLTextFormControlElement::parseAttribute(const QualifiedName& name, const
AtomicString& oldValue, const AtomicString& value) | 601 void HTMLTextFormControlElement::parseAttribute(const QualifiedName& name, const
AtomicString& oldValue, const AtomicString& value) |
| 602 { | 602 { |
| 603 if (name == autocapitalizeAttr) | 603 if (name == autocapitalizeAttr) |
| 604 UseCounter::count(document(), UseCounter::AutocapitalizeAttribute); | 604 UseCounter::count(document(), UseCounter::AutocapitalizeAttribute); |
| 605 | 605 |
| 606 if (name == placeholderAttr) { | 606 if (name == placeholderAttr) { |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 { | 773 { |
| 774 return toHTMLElement(userAgentShadowRoot()->getElementById(ShadowElementName
s::innerEditor())); | 774 return toHTMLElement(userAgentShadowRoot()->getElementById(ShadowElementName
s::innerEditor())); |
| 775 } | 775 } |
| 776 | 776 |
| 777 static Position innerNodePosition(const Position& innerPosition) | 777 static Position innerNodePosition(const Position& innerPosition) |
| 778 { | 778 { |
| 779 ASSERT(!innerPosition.isBeforeAnchor()); | 779 ASSERT(!innerPosition.isBeforeAnchor()); |
| 780 ASSERT(!innerPosition.isAfterAnchor()); | 780 ASSERT(!innerPosition.isAfterAnchor()); |
| 781 HTMLElement* element = toHTMLElement(innerPosition.anchorNode()); | 781 HTMLElement* element = toHTMLElement(innerPosition.anchorNode()); |
| 782 ASSERT(element); | 782 ASSERT(element); |
| 783 RefPtrWillBeRawPtr<NodeList> childNodes = element->childNodes(); | 783 RawPtr<NodeList> childNodes = element->childNodes(); |
| 784 if (!childNodes->length()) | 784 if (!childNodes->length()) |
| 785 return Position(element, 0); | 785 return Position(element, 0); |
| 786 | 786 |
| 787 unsigned offset = 0; | 787 unsigned offset = 0; |
| 788 | 788 |
| 789 if (innerPosition.isOffsetInAnchor()) | 789 if (innerPosition.isOffsetInAnchor()) |
| 790 offset = std::max(0, std::min(innerPosition.offsetInContainerNode(), sta
tic_cast<int>(childNodes->length()))); | 790 offset = std::max(0, std::min(innerPosition.offsetInContainerNode(), sta
tic_cast<int>(childNodes->length()))); |
| 791 else if (innerPosition.isAfterChildren()) | 791 else if (innerPosition.isAfterChildren()) |
| 792 offset = childNodes->length(); | 792 offset = childNodes->length(); |
| 793 | 793 |
| 794 if (offset == childNodes->length()) | 794 if (offset == childNodes->length()) |
| 795 return Position(element->lastChild(), PositionAnchorType::AfterAnchor); | 795 return Position(element->lastChild(), PositionAnchorType::AfterAnchor); |
| 796 | 796 |
| 797 Node* node = childNodes->item(offset); | 797 Node* node = childNodes->item(offset); |
| 798 if (node->isTextNode()) | 798 if (node->isTextNode()) |
| 799 return Position(toText(node), 0); | 799 return Position(toText(node), 0); |
| 800 | 800 |
| 801 return Position(node, PositionAnchorType::BeforeAnchor); | 801 return Position(node, PositionAnchorType::BeforeAnchor); |
| 802 } | 802 } |
| 803 | 803 |
| 804 enum FindOption { | 804 enum FindOption { |
| 805 FindStart, | 805 FindStart, |
| 806 FindEnd | 806 FindEnd |
| 807 }; | 807 }; |
| 808 | 808 |
| 809 static Position findWordBoundary(const HTMLElement* innerEditor, const Position&
startPosition, const Position& endPosition, FindOption findOption) | 809 static Position findWordBoundary(const HTMLElement* innerEditor, const Position&
startPosition, const Position& endPosition, FindOption findOption) |
| 810 { | 810 { |
| 811 StringBuilder concatTexts; | 811 StringBuilder concatTexts; |
| 812 Vector<unsigned> lengthList; | 812 Vector<unsigned> lengthList; |
| 813 WillBeHeapVector<RawPtrWillBeMember<Text>> textList; | 813 HeapVector<Member<Text>> textList; |
| 814 | 814 |
| 815 if (startPosition.anchorNode()->isTextNode()) | 815 if (startPosition.anchorNode()->isTextNode()) |
| 816 ASSERT(startPosition.isOffsetInAnchor()); | 816 ASSERT(startPosition.isOffsetInAnchor()); |
| 817 if (endPosition.anchorNode()->isTextNode()) | 817 if (endPosition.anchorNode()->isTextNode()) |
| 818 ASSERT(endPosition.isOffsetInAnchor()); | 818 ASSERT(endPosition.isOffsetInAnchor()); |
| 819 | 819 |
| 820 // Traverse text nodes. | 820 // Traverse text nodes. |
| 821 for (Node* node = startPosition.anchorNode(); node; node = NodeTraversal::ne
xt(*node, innerEditor)) { | 821 for (Node* node = startPosition.anchorNode(); node; node = NodeTraversal::ne
xt(*node, innerEditor)) { |
| 822 bool isStartNode = node == startPosition.anchorNode(); | 822 bool isStartNode = node == startPosition.anchorNode(); |
| 823 bool isEndNode = node == endPosition.anchorNode(); | 823 bool isEndNode = node == endPosition.anchorNode(); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1009 } | 1009 } |
| 1010 | 1010 |
| 1011 void HTMLTextFormControlElement::copyNonAttributePropertiesFromElement(const Ele
ment& source) | 1011 void HTMLTextFormControlElement::copyNonAttributePropertiesFromElement(const Ele
ment& source) |
| 1012 { | 1012 { |
| 1013 const HTMLTextFormControlElement& sourceElement = static_cast<const HTMLText
FormControlElement&>(source); | 1013 const HTMLTextFormControlElement& sourceElement = static_cast<const HTMLText
FormControlElement&>(source); |
| 1014 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit; | 1014 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit; |
| 1015 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source); | 1015 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source); |
| 1016 } | 1016 } |
| 1017 | 1017 |
| 1018 } // namespace blink | 1018 } // namespace blink |
| OLD | NEW |