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 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 393 ++index; | 393 ++index; |
| 394 } | 394 } |
| 395 } | 395 } |
| 396 | 396 |
| 397 return index; | 397 return index; |
| 398 } | 398 } |
| 399 | 399 |
| 400 bool TextControlElement::setSelectionRange( | 400 bool TextControlElement::setSelectionRange( |
| 401 unsigned start, | 401 unsigned start, |
| 402 unsigned end, | 402 unsigned end, |
| 403 TextFieldSelectionDirection direction) { | 403 TextFieldSelectionDirection direction) { |
|
yoichio
2017/02/17 04:18:59
As offline discussion, we put DocumentLifecycle::D
| |
| 404 if (openShadowRoot() || !isTextControl()) | 404 if (openShadowRoot() || !isTextControl()) |
| 405 return false; | 405 return false; |
| 406 const unsigned editorValueLength = innerEditorValue().length(); | 406 const unsigned editorValueLength = innerEditorValue().length(); |
| 407 end = std::min(end, editorValueLength); | 407 end = std::min(end, editorValueLength); |
| 408 start = std::min(start, end); | 408 start = std::min(start, end); |
| 409 LocalFrame* frame = document().frame(); | 409 LocalFrame* frame = document().frame(); |
| 410 if (direction == SelectionHasNoDirection && frame && | 410 if (direction == SelectionHasNoDirection && frame && |
| 411 frame->editor().behavior().shouldConsiderSelectionAsDirectional()) | 411 frame->editor().behavior().shouldConsiderSelectionAsDirectional()) |
| 412 direction = SelectionHasForwardDirection; | 412 direction = SelectionHasForwardDirection; |
| 413 cacheSelection(start, end, direction); | 413 cacheSelection(start, end, direction); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 478 if (!isTextControl()) | 478 if (!isTextControl()) |
| 479 return 0; | 479 return 0; |
| 480 if (document().focusedElement() != this) | 480 if (document().focusedElement() != this) |
| 481 return m_cachedSelectionStart; | 481 return m_cachedSelectionStart; |
| 482 | 482 |
| 483 return computeSelectionStart(); | 483 return computeSelectionStart(); |
| 484 } | 484 } |
| 485 | 485 |
| 486 unsigned TextControlElement::computeSelectionStart() const { | 486 unsigned TextControlElement::computeSelectionStart() const { |
| 487 DCHECK(isTextControl()); | 487 DCHECK(isTextControl()); |
| 488 if (LocalFrame* frame = document().frame()) | 488 LocalFrame* frame = document().frame(); |
| 489 return indexForPosition(innerEditorElement(), frame->selection().start()); | 489 if (!frame) |
| 490 return 0; | 490 return 0; |
| 491 const SelectionInDOMTree& selection = frame->selection().selectionInDOMTree(); | |
| 492 if (selection.granularity() == CharacterGranularity) { | |
|
yoichio
2017/02/17 04:35:16
Why do you split case on granularity?
yosin_UTC9
2017/02/17 05:14:49
I introduce SelectionTemplate::computeSelectionTyp
| |
| 493 return indexForPosition(innerEditorElement(), | |
| 494 selection.computeStartPosition()); | |
| 495 } | |
| 496 const VisibleSelection& visibleSelection = frame->selection().selection(); | |
| 497 return indexForPosition(innerEditorElement(), visibleSelection.start()); | |
| 491 } | 498 } |
| 492 | 499 |
| 493 unsigned TextControlElement::selectionEnd() const { | 500 unsigned TextControlElement::selectionEnd() const { |
| 494 if (!isTextControl()) | 501 if (!isTextControl()) |
| 495 return 0; | 502 return 0; |
| 496 if (document().focusedElement() != this) | 503 if (document().focusedElement() != this) |
| 497 return m_cachedSelectionEnd; | 504 return m_cachedSelectionEnd; |
| 498 return computeSelectionEnd(); | 505 return computeSelectionEnd(); |
| 499 } | 506 } |
| 500 | 507 |
| 501 unsigned TextControlElement::computeSelectionEnd() const { | 508 unsigned TextControlElement::computeSelectionEnd() const { |
| 502 DCHECK(isTextControl()); | 509 DCHECK(isTextControl()); |
| 503 if (LocalFrame* frame = document().frame()) | 510 LocalFrame* frame = document().frame(); |
| 504 return indexForPosition(innerEditorElement(), frame->selection().end()); | 511 if (!frame) |
| 505 return 0; | 512 return 0; |
| 513 const SelectionInDOMTree& selection = frame->selection().selectionInDOMTree(); | |
| 514 if (selection.granularity() == CharacterGranularity) { | |
| 515 return indexForPosition(innerEditorElement(), | |
| 516 selection.computeEndPosition()); | |
| 517 } | |
| 518 const VisibleSelection& visibleSelection = frame->selection().selection(); | |
| 519 return indexForPosition(innerEditorElement(), visibleSelection.end()); | |
| 506 } | 520 } |
| 507 | 521 |
| 508 static const AtomicString& directionString( | 522 static const AtomicString& directionString( |
| 509 TextFieldSelectionDirection direction) { | 523 TextFieldSelectionDirection direction) { |
| 510 DEFINE_STATIC_LOCAL(const AtomicString, none, ("none")); | 524 DEFINE_STATIC_LOCAL(const AtomicString, none, ("none")); |
| 511 DEFINE_STATIC_LOCAL(const AtomicString, forward, ("forward")); | 525 DEFINE_STATIC_LOCAL(const AtomicString, forward, ("forward")); |
| 512 DEFINE_STATIC_LOCAL(const AtomicString, backward, ("backward")); | 526 DEFINE_STATIC_LOCAL(const AtomicString, backward, ("backward")); |
| 513 | 527 |
| 514 switch (direction) { | 528 switch (direction) { |
| 515 case SelectionHasNoDirection: | 529 case SelectionHasNoDirection: |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 532 return directionString(computeSelectionDirection()); | 546 return directionString(computeSelectionDirection()); |
| 533 } | 547 } |
| 534 | 548 |
| 535 TextFieldSelectionDirection TextControlElement::computeSelectionDirection() | 549 TextFieldSelectionDirection TextControlElement::computeSelectionDirection() |
| 536 const { | 550 const { |
| 537 DCHECK(isTextControl()); | 551 DCHECK(isTextControl()); |
| 538 LocalFrame* frame = document().frame(); | 552 LocalFrame* frame = document().frame(); |
| 539 if (!frame) | 553 if (!frame) |
| 540 return SelectionHasNoDirection; | 554 return SelectionHasNoDirection; |
| 541 | 555 |
| 542 const VisibleSelection& selection = frame->selection().selection(); | 556 const SelectionInDOMTree& selection = frame->selection().selectionInDOMTree(); |
| 557 const Position& start = selection.computeStartPosition(); | |
| 543 return selection.isDirectional() | 558 return selection.isDirectional() |
| 544 ? (selection.isBaseFirst() ? SelectionHasForwardDirection | 559 ? (selection.base() == start ? SelectionHasForwardDirection |
| 545 : SelectionHasBackwardDirection) | 560 : SelectionHasBackwardDirection) |
| 546 : SelectionHasNoDirection; | 561 : SelectionHasNoDirection; |
| 547 } | 562 } |
| 548 | 563 |
| 549 static inline void setContainerAndOffsetForRange(Node* node, | 564 static inline void setContainerAndOffsetForRange(Node* node, |
| 550 int offset, | 565 int offset, |
| 551 Node*& containerNode, | 566 Node*& containerNode, |
| 552 int& offsetInContainer) { | 567 int& offsetInContainer) { |
| 553 if (node->isTextNode()) { | 568 if (node->isTextNode()) { |
| 554 containerNode = node; | 569 containerNode = node; |
| 555 offsetInContainer = offset; | 570 offsetInContainer = offset; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 678 | 693 |
| 679 void TextControlElement::selectionChanged(bool userTriggered) { | 694 void TextControlElement::selectionChanged(bool userTriggered) { |
| 680 if (!layoutObject() || !isTextControl()) | 695 if (!layoutObject() || !isTextControl()) |
| 681 return; | 696 return; |
| 682 | 697 |
| 683 // selectionStart() or selectionEnd() will return cached selection when this | 698 // selectionStart() or selectionEnd() will return cached selection when this |
| 684 // node doesn't have focus. | 699 // node doesn't have focus. |
| 685 cacheSelection(computeSelectionStart(), computeSelectionEnd(), | 700 cacheSelection(computeSelectionStart(), computeSelectionEnd(), |
| 686 computeSelectionDirection()); | 701 computeSelectionDirection()); |
| 687 | 702 |
| 688 if (LocalFrame* frame = document().frame()) { | 703 LocalFrame* frame = document().frame(); |
| 689 if (frame->selection().isRange() && userTriggered) | 704 if (!frame || !userTriggered) |
| 690 dispatchEvent(Event::createBubble(EventTypeNames::select)); | 705 return; |
| 691 } | 706 const SelectionInDOMTree& selection = frame->selection().selectionInDOMTree(); |
| 707 if (selection.isNone()) | |
| 708 return; | |
| 709 if (selection.isCaret() && selection.granularity() == CharacterGranularity) | |
| 710 return; | |
| 711 dispatchEvent(Event::createBubble(EventTypeNames::select)); | |
| 692 } | 712 } |
| 693 | 713 |
| 694 void TextControlElement::scheduleSelectEvent() { | 714 void TextControlElement::scheduleSelectEvent() { |
| 695 Event* event = Event::createBubble(EventTypeNames::select); | 715 Event* event = Event::createBubble(EventTypeNames::select); |
| 696 event->setTarget(this); | 716 event->setTarget(this); |
| 697 document().enqueueUniqueAnimationFrameEvent(event); | 717 document().enqueueUniqueAnimationFrameEvent(event); |
| 698 } | 718 } |
| 699 | 719 |
| 700 void TextControlElement::parseAttribute( | 720 void TextControlElement::parseAttribute( |
| 701 const AttributeModificationParams& params) { | 721 const AttributeModificationParams& params) { |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 897 | 917 |
| 898 void TextControlElement::copyNonAttributePropertiesFromElement( | 918 void TextControlElement::copyNonAttributePropertiesFromElement( |
| 899 const Element& source) { | 919 const Element& source) { |
| 900 const TextControlElement& sourceElement = | 920 const TextControlElement& sourceElement = |
| 901 static_cast<const TextControlElement&>(source); | 921 static_cast<const TextControlElement&>(source); |
| 902 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit; | 922 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit; |
| 903 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source); | 923 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source); |
| 904 } | 924 } |
| 905 | 925 |
| 906 } // namespace blink | 926 } // namespace blink |
| OLD | NEW |