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) | |
|
yosin_UTC9
2017/03/15 09:29:28
nit: No need to have |? true : false|
tanvir
2017/03/15 10:18:15
Done.
tanvir
2017/03/15 10:18:15
Done.
| |
| 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 |
| 645 if (!startNode || !endNode) | 649 if (!startNode || !endNode) |
| 646 return nullptr; | 650 return SelectionInDOMTree(); |
| 647 | 651 |
| 648 return Range::create(document(), startNode, start, endNode, end); | 652 return SelectionInDOMTree::Builder() |
| 653 .setBaseAndExtent(Position(startNode, start), Position(endNode, end)) | |
| 654 .setIsDirectional(selectionDirection() != "none" ? true : false) | |
|
yosin_UTC9
2017/03/15 09:29:28
nit: No need to have |? true : false|
tanvir
2017/03/15 10:18:15
Done.
| |
| 655 .build(); | |
| 649 } | 656 } |
| 650 | 657 |
| 651 const AtomicString& TextControlElement::autocapitalize() const { | 658 const AtomicString& TextControlElement::autocapitalize() const { |
| 652 DEFINE_STATIC_LOCAL(const AtomicString, off, ("off")); | 659 DEFINE_STATIC_LOCAL(const AtomicString, off, ("off")); |
| 653 DEFINE_STATIC_LOCAL(const AtomicString, none, ("none")); | 660 DEFINE_STATIC_LOCAL(const AtomicString, none, ("none")); |
| 654 DEFINE_STATIC_LOCAL(const AtomicString, characters, ("characters")); | 661 DEFINE_STATIC_LOCAL(const AtomicString, characters, ("characters")); |
| 655 DEFINE_STATIC_LOCAL(const AtomicString, words, ("words")); | 662 DEFINE_STATIC_LOCAL(const AtomicString, words, ("words")); |
| 656 DEFINE_STATIC_LOCAL(const AtomicString, sentences, ("sentences")); | 663 DEFINE_STATIC_LOCAL(const AtomicString, sentences, ("sentences")); |
| 657 | 664 |
| 658 const AtomicString& value = fastGetAttribute(autocapitalizeAttr); | 665 const AtomicString& value = fastGetAttribute(autocapitalizeAttr); |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 949 | 956 |
| 950 void TextControlElement::copyNonAttributePropertiesFromElement( | 957 void TextControlElement::copyNonAttributePropertiesFromElement( |
| 951 const Element& source) { | 958 const Element& source) { |
| 952 const TextControlElement& sourceElement = | 959 const TextControlElement& sourceElement = |
| 953 static_cast<const TextControlElement&>(source); | 960 static_cast<const TextControlElement&>(source); |
| 954 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit; | 961 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit; |
| 955 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source); | 962 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source); |
| 956 } | 963 } |
| 957 | 964 |
| 958 } // namespace blink | 965 } // namespace blink |
| OLD | NEW |