Chromium Code Reviews| 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 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 601 int& offsetInContainer) { | 601 int& offsetInContainer) { |
| 602 if (node->isTextNode()) { | 602 if (node->isTextNode()) { |
| 603 containerNode = node; | 603 containerNode = node; |
| 604 offsetInContainer = offset; | 604 offsetInContainer = offset; |
| 605 } else { | 605 } else { |
| 606 containerNode = node->parentNode(); | 606 containerNode = node->parentNode(); |
| 607 offsetInContainer = node->nodeIndex() + offset; | 607 offsetInContainer = node->nodeIndex() + offset; |
| 608 } | 608 } |
| 609 } | 609 } |
| 610 | 610 |
| 611 Range* TextControlElement::selection() const { | 611 const SelectionInDOMTree TextControlElement::selection() const { |
| 612 if (!layoutObject() || !isTextControl()) | 612 if (!layoutObject() || !isTextControl()) |
| 613 return nullptr; | 613 return SelectionInDOMTree(); |
| 614 | 614 |
| 615 int start = m_cachedSelectionStart; | 615 int start = m_cachedSelectionStart; |
| 616 int end = m_cachedSelectionEnd; | 616 int end = m_cachedSelectionEnd; |
| 617 | 617 |
| 618 DCHECK_LE(start, end); | 618 DCHECK_LE(start, end); |
| 619 HTMLElement* innerText = innerEditorElement(); | 619 HTMLElement* innerText = innerEditorElement(); |
| 620 if (!innerText) | 620 if (!innerText) |
| 621 return nullptr; | 621 return SelectionInDOMTree(); |
| 622 | 622 |
| 623 if (!innerText->hasChildren()) | 623 if (!innerText->hasChildren()) { |
| 624 return Range::create(document(), innerText, 0, innerText, 0); | 624 return SelectionInDOMTree::Builder() |
| 625 .collapse(Position(innerText, 0)) | |
| 626 .setIsDirectional(selectionDirection() != "none" ? true : false) | |
| 627 .build(); | |
| 628 } | |
| 625 | 629 |
| 626 int offset = 0; | 630 int offset = 0; |
| 627 Node* startNode = 0; | 631 Node* startNode = 0; |
| 628 Node* endNode = 0; | 632 Node* endNode = 0; |
| 629 for (Node& node : NodeTraversal::descendantsOf(*innerText)) { | 633 for (Node& node : NodeTraversal::descendantsOf(*innerText)) { |
| 630 DCHECK(!node.hasChildren()); | 634 DCHECK(!node.hasChildren()); |
| 631 DCHECK(node.isTextNode() || isHTMLBRElement(node)); | 635 DCHECK(node.isTextNode() || isHTMLBRElement(node)); |
| 632 int length = node.isTextNode() ? Position::lastOffsetInNode(&node) : 1; | 636 int length = node.isTextNode() ? Position::lastOffsetInNode(&node) : 1; |
| 633 | 637 |
| 634 if (offset <= start && start <= offset + length) | 638 if (offset <= start && start <= offset + length) |
| 635 setContainerAndOffsetForRange(&node, start - offset, startNode, start); | 639 setContainerAndOffsetForRange(&node, start - offset, startNode, start); |
| 636 | 640 |
| 637 if (offset <= end && end <= offset + length) { | 641 if (offset <= end && end <= offset + length) { |
| 638 setContainerAndOffsetForRange(&node, end - offset, endNode, end); | 642 setContainerAndOffsetForRange(&node, end - offset, endNode, end); |
| 639 break; | 643 break; |
| 640 } | 644 } |
| 641 | 645 |
| 642 offset += length; | 646 offset += length; |
| 643 } | 647 } |
| 644 | 648 |
|
Shanmuga Pandi
2017/03/14 14:31:48
We need to keep.
if (!startNode || !endNode)
re
tanvir
2017/03/14 15:00:30
Done.
| |
| 645 if (!startNode || !endNode) | 649 return SelectionInDOMTree::Builder() |
| 646 return nullptr; | 650 .setBaseAndExtent(Position(startNode, start), Position(endNode, end)) |
| 647 | 651 .setIsDirectional(selectionDirection() != "none" ? true : false) |
| 648 return Range::create(document(), startNode, start, endNode, end); | 652 .build(); |
| 649 } | 653 } |
| 650 | 654 |
| 651 const AtomicString& TextControlElement::autocapitalize() const { | 655 const AtomicString& TextControlElement::autocapitalize() const { |
| 652 DEFINE_STATIC_LOCAL(const AtomicString, off, ("off")); | 656 DEFINE_STATIC_LOCAL(const AtomicString, off, ("off")); |
| 653 DEFINE_STATIC_LOCAL(const AtomicString, none, ("none")); | 657 DEFINE_STATIC_LOCAL(const AtomicString, none, ("none")); |
| 654 DEFINE_STATIC_LOCAL(const AtomicString, characters, ("characters")); | 658 DEFINE_STATIC_LOCAL(const AtomicString, characters, ("characters")); |
| 655 DEFINE_STATIC_LOCAL(const AtomicString, words, ("words")); | 659 DEFINE_STATIC_LOCAL(const AtomicString, words, ("words")); |
| 656 DEFINE_STATIC_LOCAL(const AtomicString, sentences, ("sentences")); | 660 DEFINE_STATIC_LOCAL(const AtomicString, sentences, ("sentences")); |
| 657 | 661 |
| 658 const AtomicString& value = fastGetAttribute(autocapitalizeAttr); | 662 const AtomicString& value = fastGetAttribute(autocapitalizeAttr); |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 949 | 953 |
| 950 void TextControlElement::copyNonAttributePropertiesFromElement( | 954 void TextControlElement::copyNonAttributePropertiesFromElement( |
| 951 const Element& source) { | 955 const Element& source) { |
| 952 const TextControlElement& sourceElement = | 956 const TextControlElement& sourceElement = |
| 953 static_cast<const TextControlElement&>(source); | 957 static_cast<const TextControlElement&>(source); |
| 954 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit; | 958 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit; |
| 955 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source); | 959 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source); |
| 956 } | 960 } |
| 957 | 961 |
| 958 } // namespace blink | 962 } // namespace blink |
| OLD | NEW |