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 467 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 { | |
492 // To avoid regression on speedometer benchmark[1] test, we should not | |
493 // update layout tree in this code block. | |
494 // [1] http://browserbench.org/Speedometer/ | |
495 DocumentLifecycle::DisallowTransitionScope disallowTransition( | |
496 document().lifecycle()); | |
497 const SelectionInDOMTree& selection = | |
498 frame->selection().selectionInDOMTree(); | |
499 if (selection.granularity() == CharacterGranularity) { | |
500 return indexForPosition(innerEditorElement(), | |
501 selection.computeStartPosition()); | |
502 } | |
503 } | |
504 const VisibleSelection& visibleSelection = frame->selection().selection(); | |
505 return indexForPosition(innerEditorElement(), visibleSelection.start()); | |
491 } | 506 } |
492 | 507 |
493 unsigned TextControlElement::selectionEnd() const { | 508 unsigned TextControlElement::selectionEnd() const { |
494 if (!isTextControl()) | 509 if (!isTextControl()) |
495 return 0; | 510 return 0; |
496 if (document().focusedElement() != this) | 511 if (document().focusedElement() != this) |
497 return m_cachedSelectionEnd; | 512 return m_cachedSelectionEnd; |
498 return computeSelectionEnd(); | 513 return computeSelectionEnd(); |
499 } | 514 } |
500 | 515 |
501 unsigned TextControlElement::computeSelectionEnd() const { | 516 unsigned TextControlElement::computeSelectionEnd() const { |
502 DCHECK(isTextControl()); | 517 DCHECK(isTextControl()); |
503 if (LocalFrame* frame = document().frame()) | 518 LocalFrame* frame = document().frame(); |
504 return indexForPosition(innerEditorElement(), frame->selection().end()); | 519 if (!frame) |
505 return 0; | 520 return 0; |
521 { | |
522 // To avoid regression on speedometer benchmark[1] test, we should not | |
523 // update layout tree in this code block. | |
524 // [1] http://browserbench.org/Speedometer/ | |
525 DocumentLifecycle::DisallowTransitionScope disallowTransition( | |
526 document().lifecycle()); | |
527 const SelectionInDOMTree& selection = | |
528 frame->selection().selectionInDOMTree(); | |
529 if (selection.granularity() == CharacterGranularity) { | |
530 return indexForPosition(innerEditorElement(), | |
531 selection.computeEndPosition()); | |
532 } | |
533 } | |
534 const VisibleSelection& visibleSelection = frame->selection().selection(); | |
535 return indexForPosition(innerEditorElement(), visibleSelection.end()); | |
506 } | 536 } |
507 | 537 |
508 static const AtomicString& directionString( | 538 static const AtomicString& directionString( |
509 TextFieldSelectionDirection direction) { | 539 TextFieldSelectionDirection direction) { |
510 DEFINE_STATIC_LOCAL(const AtomicString, none, ("none")); | 540 DEFINE_STATIC_LOCAL(const AtomicString, none, ("none")); |
511 DEFINE_STATIC_LOCAL(const AtomicString, forward, ("forward")); | 541 DEFINE_STATIC_LOCAL(const AtomicString, forward, ("forward")); |
512 DEFINE_STATIC_LOCAL(const AtomicString, backward, ("backward")); | 542 DEFINE_STATIC_LOCAL(const AtomicString, backward, ("backward")); |
513 | 543 |
514 switch (direction) { | 544 switch (direction) { |
515 case SelectionHasNoDirection: | 545 case SelectionHasNoDirection: |
(...skipping 11 matching lines...) Expand all Loading... | |
527 const AtomicString& TextControlElement::selectionDirection() const { | 557 const AtomicString& TextControlElement::selectionDirection() const { |
528 // Ensured by HTMLInputElement::selectionDirectionForBinding(). | 558 // Ensured by HTMLInputElement::selectionDirectionForBinding(). |
529 DCHECK(isTextControl()); | 559 DCHECK(isTextControl()); |
530 if (document().focusedElement() != this) | 560 if (document().focusedElement() != this) |
531 return directionString(m_cachedSelectionDirection); | 561 return directionString(m_cachedSelectionDirection); |
532 return directionString(computeSelectionDirection()); | 562 return directionString(computeSelectionDirection()); |
533 } | 563 } |
534 | 564 |
535 TextFieldSelectionDirection TextControlElement::computeSelectionDirection() | 565 TextFieldSelectionDirection TextControlElement::computeSelectionDirection() |
536 const { | 566 const { |
537 DCHECK(isTextControl()); | 567 DCHECK(isTextControl()); |
yoichio
2017/02/17 05:26:37
Can we have DocumentLifecycle::DisallowTransitionS
| |
538 LocalFrame* frame = document().frame(); | 568 LocalFrame* frame = document().frame(); |
539 if (!frame) | 569 if (!frame) |
540 return SelectionHasNoDirection; | 570 return SelectionHasNoDirection; |
541 | 571 |
542 const VisibleSelection& selection = frame->selection().selection(); | 572 // To avoid regression on speedometer benchmark[1] test, we should not |
573 // update layout tree in this code block. | |
574 // [1] http://browserbench.org/Speedometer/ | |
575 const SelectionInDOMTree& selection = frame->selection().selectionInDOMTree(); | |
576 const Position& start = selection.computeStartPosition(); | |
543 return selection.isDirectional() | 577 return selection.isDirectional() |
544 ? (selection.isBaseFirst() ? SelectionHasForwardDirection | 578 ? (selection.base() == start ? SelectionHasForwardDirection |
545 : SelectionHasBackwardDirection) | 579 : SelectionHasBackwardDirection) |
546 : SelectionHasNoDirection; | 580 : SelectionHasNoDirection; |
547 } | 581 } |
548 | 582 |
549 static inline void setContainerAndOffsetForRange(Node* node, | 583 static inline void setContainerAndOffsetForRange(Node* node, |
550 int offset, | 584 int offset, |
551 Node*& containerNode, | 585 Node*& containerNode, |
552 int& offsetInContainer) { | 586 int& offsetInContainer) { |
553 if (node->isTextNode()) { | 587 if (node->isTextNode()) { |
554 containerNode = node; | 588 containerNode = node; |
555 offsetInContainer = offset; | 589 offsetInContainer = offset; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
678 | 712 |
679 void TextControlElement::selectionChanged(bool userTriggered) { | 713 void TextControlElement::selectionChanged(bool userTriggered) { |
680 if (!layoutObject() || !isTextControl()) | 714 if (!layoutObject() || !isTextControl()) |
681 return; | 715 return; |
682 | 716 |
683 // selectionStart() or selectionEnd() will return cached selection when this | 717 // selectionStart() or selectionEnd() will return cached selection when this |
684 // node doesn't have focus. | 718 // node doesn't have focus. |
685 cacheSelection(computeSelectionStart(), computeSelectionEnd(), | 719 cacheSelection(computeSelectionStart(), computeSelectionEnd(), |
686 computeSelectionDirection()); | 720 computeSelectionDirection()); |
687 | 721 |
688 if (LocalFrame* frame = document().frame()) { | 722 LocalFrame* frame = document().frame(); |
689 if (frame->selection().isRange() && userTriggered) | 723 if (!frame || !userTriggered) |
690 dispatchEvent(Event::createBubble(EventTypeNames::select)); | 724 return; |
691 } | 725 const SelectionInDOMTree& selection = frame->selection().selectionInDOMTree(); |
726 if (selection.computeSelectionTypeConsideringGranularity() != RangeSelection) | |
727 return; | |
728 dispatchEvent(Event::createBubble(EventTypeNames::select)); | |
692 } | 729 } |
693 | 730 |
694 void TextControlElement::scheduleSelectEvent() { | 731 void TextControlElement::scheduleSelectEvent() { |
695 Event* event = Event::createBubble(EventTypeNames::select); | 732 Event* event = Event::createBubble(EventTypeNames::select); |
696 event->setTarget(this); | 733 event->setTarget(this); |
697 document().enqueueUniqueAnimationFrameEvent(event); | 734 document().enqueueUniqueAnimationFrameEvent(event); |
698 } | 735 } |
699 | 736 |
700 void TextControlElement::parseAttribute( | 737 void TextControlElement::parseAttribute( |
701 const AttributeModificationParams& params) { | 738 const AttributeModificationParams& params) { |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
897 | 934 |
898 void TextControlElement::copyNonAttributePropertiesFromElement( | 935 void TextControlElement::copyNonAttributePropertiesFromElement( |
899 const Element& source) { | 936 const Element& source) { |
900 const TextControlElement& sourceElement = | 937 const TextControlElement& sourceElement = |
901 static_cast<const TextControlElement&>(source); | 938 static_cast<const TextControlElement&>(source); |
902 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit; | 939 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit; |
903 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source); | 940 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source); |
904 } | 941 } |
905 | 942 |
906 } // namespace blink | 943 } // namespace blink |
OLD | NEW |