| 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 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 it.advance(index - 1); | 402 it.advance(index - 1); |
| 403 return createVisiblePosition(it.endPosition(), TextAffinity::Upstream); | 403 return createVisiblePosition(it.endPosition(), TextAffinity::Upstream); |
| 404 } | 404 } |
| 405 | 405 |
| 406 int HTMLTextFormControlElement::indexForVisiblePosition(const VisiblePosition& p
os) const | 406 int HTMLTextFormControlElement::indexForVisiblePosition(const VisiblePosition& p
os) const |
| 407 { | 407 { |
| 408 Position indexPosition = pos.deepEquivalent().parentAnchoredEquivalent(); | 408 Position indexPosition = pos.deepEquivalent().parentAnchoredEquivalent(); |
| 409 if (enclosingTextFormControl(indexPosition) != this) | 409 if (enclosingTextFormControl(indexPosition) != this) |
| 410 return 0; | 410 return 0; |
| 411 ASSERT(indexPosition.document()); | 411 ASSERT(indexPosition.document()); |
| 412 RefPtrWillBeRawPtr<Range> range = Range::create(*indexPosition.document()); | 412 RawPtr<Range> range = Range::create(*indexPosition.document()); |
| 413 range->setStart(innerEditorElement(), 0, ASSERT_NO_EXCEPTION); | 413 range->setStart(innerEditorElement(), 0, ASSERT_NO_EXCEPTION); |
| 414 range->setEnd(indexPosition.computeContainerNode(), indexPosition.offsetInCo
ntainerNode(), ASSERT_NO_EXCEPTION); | 414 range->setEnd(indexPosition.computeContainerNode(), indexPosition.offsetInCo
ntainerNode(), ASSERT_NO_EXCEPTION); |
| 415 return TextIterator::rangeLength(range->startPosition(), range->endPosition(
)); | 415 return TextIterator::rangeLength(range->startPosition(), range->endPosition(
)); |
| 416 } | 416 } |
| 417 | 417 |
| 418 int HTMLTextFormControlElement::selectionStart() const | 418 int HTMLTextFormControlElement::selectionStart() const |
| 419 { | 419 { |
| 420 if (!isTextFormControl()) | 420 if (!isTextFormControl()) |
| 421 return 0; | 421 return 0; |
| 422 if (document().focusedElement() != this) | 422 if (document().focusedElement() != this) |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 { | 498 { |
| 499 if (node->isTextNode()) { | 499 if (node->isTextNode()) { |
| 500 containerNode = node; | 500 containerNode = node; |
| 501 offsetInContainer = offset; | 501 offsetInContainer = offset; |
| 502 } else { | 502 } else { |
| 503 containerNode = node->parentNode(); | 503 containerNode = node->parentNode(); |
| 504 offsetInContainer = node->nodeIndex() + offset; | 504 offsetInContainer = node->nodeIndex() + offset; |
| 505 } | 505 } |
| 506 } | 506 } |
| 507 | 507 |
| 508 PassRefPtrWillBeRawPtr<Range> HTMLTextFormControlElement::selection() const | 508 RawPtr<Range> HTMLTextFormControlElement::selection() const |
| 509 { | 509 { |
| 510 if (!layoutObject() || !isTextFormControl()) | 510 if (!layoutObject() || !isTextFormControl()) |
| 511 return nullptr; | 511 return nullptr; |
| 512 | 512 |
| 513 int start = m_cachedSelectionStart; | 513 int start = m_cachedSelectionStart; |
| 514 int end = m_cachedSelectionEnd; | 514 int end = m_cachedSelectionEnd; |
| 515 | 515 |
| 516 ASSERT(start <= end); | 516 ASSERT(start <= end); |
| 517 HTMLElement* innerText = innerEditorElement(); | 517 HTMLElement* innerText = innerEditorElement(); |
| 518 if (!innerText) | 518 if (!innerText) |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 cacheSelection(computeSelectionStart(), computeSelectionEnd(), computeSelect
ionDirection()); | 587 cacheSelection(computeSelectionStart(), computeSelectionEnd(), computeSelect
ionDirection()); |
| 588 | 588 |
| 589 if (LocalFrame* frame = document().frame()) { | 589 if (LocalFrame* frame = document().frame()) { |
| 590 if (frame->selection().isRange() && userTriggered) | 590 if (frame->selection().isRange() && userTriggered) |
| 591 dispatchEvent(Event::createBubble(EventTypeNames::select)); | 591 dispatchEvent(Event::createBubble(EventTypeNames::select)); |
| 592 } | 592 } |
| 593 } | 593 } |
| 594 | 594 |
| 595 void HTMLTextFormControlElement::scheduleSelectEvent() | 595 void HTMLTextFormControlElement::scheduleSelectEvent() |
| 596 { | 596 { |
| 597 RefPtrWillBeRawPtr<Event> event = Event::createBubble(EventTypeNames::select
); | 597 RawPtr<Event> event = Event::createBubble(EventTypeNames::select); |
| 598 event->setTarget(this); | 598 event->setTarget(this); |
| 599 document().enqueueUniqueAnimationFrameEvent(event.release()); | 599 document().enqueueUniqueAnimationFrameEvent(event.release()); |
| 600 } | 600 } |
| 601 | 601 |
| 602 void HTMLTextFormControlElement::parseAttribute(const QualifiedName& name, const
AtomicString& oldValue, const AtomicString& value) | 602 void HTMLTextFormControlElement::parseAttribute(const QualifiedName& name, const
AtomicString& oldValue, const AtomicString& value) |
| 603 { | 603 { |
| 604 if (name == autocapitalizeAttr) | 604 if (name == autocapitalizeAttr) |
| 605 UseCounter::count(document(), UseCounter::AutocapitalizeAttribute); | 605 UseCounter::count(document(), UseCounter::AutocapitalizeAttribute); |
| 606 | 606 |
| 607 if (name == placeholderAttr) { | 607 if (name == placeholderAttr) { |
| 608 updatePlaceholderText(); | 608 updatePlaceholderText(); |
| 609 updatePlaceholderVisibility(); | 609 updatePlaceholderVisibility(); |
| 610 UseCounter::count(document(), UseCounter::PlaceholderAttribute); | 610 UseCounter::count(document(), UseCounter::PlaceholderAttribute); |
| 611 } else { | 611 } else { |
| 612 HTMLFormControlElementWithState::parseAttribute(name, oldValue, value); | 612 HTMLFormControlElementWithState::parseAttribute(name, oldValue, value); |
| 613 } | 613 } |
| 614 } | 614 } |
| 615 | 615 |
| 616 bool HTMLTextFormControlElement::lastChangeWasUserEdit() const | 616 bool HTMLTextFormControlElement::lastChangeWasUserEdit() const |
| 617 { | 617 { |
| 618 if (!isTextFormControl()) | 618 if (!isTextFormControl()) |
| 619 return false; | 619 return false; |
| 620 return m_lastChangeWasUserEdit; | 620 return m_lastChangeWasUserEdit; |
| 621 } | 621 } |
| 622 | 622 |
| 623 PassRefPtrWillBeRawPtr<Node> HTMLTextFormControlElement::createPlaceholderBreakE
lement() const | 623 RawPtr<Node> HTMLTextFormControlElement::createPlaceholderBreakElement() const |
| 624 { | 624 { |
| 625 return HTMLBRElement::create(document()); | 625 return HTMLBRElement::create(document()); |
| 626 } | 626 } |
| 627 | 627 |
| 628 void HTMLTextFormControlElement::addPlaceholderBreakElementIfNecessary() | 628 void HTMLTextFormControlElement::addPlaceholderBreakElementIfNecessary() |
| 629 { | 629 { |
| 630 HTMLElement* innerEditor = innerEditorElement(); | 630 HTMLElement* innerEditor = innerEditorElement(); |
| 631 if (innerEditor->layoutObject() && !innerEditor->layoutObject()->style()->pr
eserveNewline()) | 631 if (innerEditor->layoutObject() && !innerEditor->layoutObject()->style()->pr
eserveNewline()) |
| 632 return; | 632 return; |
| 633 Node* lastChild = innerEditor->lastChild(); | 633 Node* lastChild = innerEditor->lastChild(); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 { | 792 { |
| 793 return toHTMLElement(userAgentShadowRoot()->getElementById(ShadowElementName
s::innerEditor())); | 793 return toHTMLElement(userAgentShadowRoot()->getElementById(ShadowElementName
s::innerEditor())); |
| 794 } | 794 } |
| 795 | 795 |
| 796 static Position innerNodePosition(const Position& innerPosition) | 796 static Position innerNodePosition(const Position& innerPosition) |
| 797 { | 797 { |
| 798 ASSERT(!innerPosition.isBeforeAnchor()); | 798 ASSERT(!innerPosition.isBeforeAnchor()); |
| 799 ASSERT(!innerPosition.isAfterAnchor()); | 799 ASSERT(!innerPosition.isAfterAnchor()); |
| 800 HTMLElement* element = toHTMLElement(innerPosition.anchorNode()); | 800 HTMLElement* element = toHTMLElement(innerPosition.anchorNode()); |
| 801 ASSERT(element); | 801 ASSERT(element); |
| 802 RefPtrWillBeRawPtr<NodeList> childNodes = element->childNodes(); | 802 RawPtr<NodeList> childNodes = element->childNodes(); |
| 803 if (!childNodes->length()) | 803 if (!childNodes->length()) |
| 804 return Position(element, 0); | 804 return Position(element, 0); |
| 805 | 805 |
| 806 unsigned offset = 0; | 806 unsigned offset = 0; |
| 807 | 807 |
| 808 if (innerPosition.isOffsetInAnchor()) | 808 if (innerPosition.isOffsetInAnchor()) |
| 809 offset = std::max(0, std::min(innerPosition.offsetInContainerNode(), sta
tic_cast<int>(childNodes->length()))); | 809 offset = std::max(0, std::min(innerPosition.offsetInContainerNode(), sta
tic_cast<int>(childNodes->length()))); |
| 810 else if (innerPosition.isAfterChildren()) | 810 else if (innerPosition.isAfterChildren()) |
| 811 offset = childNodes->length(); | 811 offset = childNodes->length(); |
| 812 | 812 |
| 813 if (offset == childNodes->length()) | 813 if (offset == childNodes->length()) |
| 814 return Position(element->lastChild(), PositionAnchorType::AfterAnchor); | 814 return Position(element->lastChild(), PositionAnchorType::AfterAnchor); |
| 815 | 815 |
| 816 Node* node = childNodes->item(offset); | 816 Node* node = childNodes->item(offset); |
| 817 if (node->isTextNode()) | 817 if (node->isTextNode()) |
| 818 return Position(toText(node), 0); | 818 return Position(toText(node), 0); |
| 819 | 819 |
| 820 return Position(node, PositionAnchorType::BeforeAnchor); | 820 return Position(node, PositionAnchorType::BeforeAnchor); |
| 821 } | 821 } |
| 822 | 822 |
| 823 enum FindOption { | 823 enum FindOption { |
| 824 FindStart, | 824 FindStart, |
| 825 FindEnd | 825 FindEnd |
| 826 }; | 826 }; |
| 827 | 827 |
| 828 static Position findWordBoundary(const HTMLElement* innerEditor, const Position&
startPosition, const Position& endPosition, FindOption findOption) | 828 static Position findWordBoundary(const HTMLElement* innerEditor, const Position&
startPosition, const Position& endPosition, FindOption findOption) |
| 829 { | 829 { |
| 830 StringBuilder concatTexts; | 830 StringBuilder concatTexts; |
| 831 Vector<unsigned> lengthList; | 831 Vector<unsigned> lengthList; |
| 832 WillBeHeapVector<RawPtrWillBeMember<Text>> textList; | 832 HeapVector<Member<Text>> textList; |
| 833 | 833 |
| 834 if (startPosition.anchorNode()->isTextNode()) | 834 if (startPosition.anchorNode()->isTextNode()) |
| 835 ASSERT(startPosition.isOffsetInAnchor()); | 835 ASSERT(startPosition.isOffsetInAnchor()); |
| 836 if (endPosition.anchorNode()->isTextNode()) | 836 if (endPosition.anchorNode()->isTextNode()) |
| 837 ASSERT(endPosition.isOffsetInAnchor()); | 837 ASSERT(endPosition.isOffsetInAnchor()); |
| 838 | 838 |
| 839 // Traverse text nodes. | 839 // Traverse text nodes. |
| 840 for (Node* node = startPosition.anchorNode(); node; node = NodeTraversal::ne
xt(*node, innerEditor)) { | 840 for (Node* node = startPosition.anchorNode(); node; node = NodeTraversal::ne
xt(*node, innerEditor)) { |
| 841 bool isStartNode = node == startPosition.anchorNode(); | 841 bool isStartNode = node == startPosition.anchorNode(); |
| 842 bool isEndNode = node == endPosition.anchorNode(); | 842 bool isEndNode = node == endPosition.anchorNode(); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1028 } | 1028 } |
| 1029 | 1029 |
| 1030 void HTMLTextFormControlElement::copyNonAttributePropertiesFromElement(const Ele
ment& source) | 1030 void HTMLTextFormControlElement::copyNonAttributePropertiesFromElement(const Ele
ment& source) |
| 1031 { | 1031 { |
| 1032 const HTMLTextFormControlElement& sourceElement = static_cast<const HTMLText
FormControlElement&>(source); | 1032 const HTMLTextFormControlElement& sourceElement = static_cast<const HTMLText
FormControlElement&>(source); |
| 1033 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit; | 1033 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit; |
| 1034 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source); | 1034 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source); |
| 1035 } | 1035 } |
| 1036 | 1036 |
| 1037 } // namespace blink | 1037 } // namespace blink |
| OLD | NEW |