Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: third_party/WebKit/Source/core/html/TextControlElement.cpp

Issue 2698793003: Get rid of redundant layout tree update related to selection (Closed)
Patch Set: 2017-02-16T17:15:58 Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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) {
493 return indexForPosition(innerEditorElement(),
494 selection.computeStartPosition());
495 }
496 const VisibleSelection& visibleSelection =
497 frame->selection().computeVisibleSelectionInDOMTree();
498 return indexForPosition(innerEditorElement(), visibleSelection.start());
491 } 499 }
492 500
493 unsigned TextControlElement::selectionEnd() const { 501 unsigned TextControlElement::selectionEnd() const {
494 if (!isTextControl()) 502 if (!isTextControl())
495 return 0; 503 return 0;
496 if (document().focusedElement() != this) 504 if (document().focusedElement() != this)
497 return m_cachedSelectionEnd; 505 return m_cachedSelectionEnd;
498 return computeSelectionEnd(); 506 return computeSelectionEnd();
499 } 507 }
500 508
501 unsigned TextControlElement::computeSelectionEnd() const { 509 unsigned TextControlElement::computeSelectionEnd() const {
502 DCHECK(isTextControl()); 510 DCHECK(isTextControl());
503 if (LocalFrame* frame = document().frame()) 511 LocalFrame* frame = document().frame();
504 return indexForPosition(innerEditorElement(), frame->selection().end()); 512 if (!frame)
505 return 0; 513 return 0;
514 const SelectionInDOMTree& selection = frame->selection().selectionInDOMTree();
515 if (selection.granularity() == CharacterGranularity) {
516 return indexForPosition(innerEditorElement(),
517 selection.computeEndPosition());
518 }
519 const VisibleSelection& visibleSelection =
520 frame->selection().computeVisibleSelectionInDOMTree();
521 return indexForPosition(innerEditorElement(), visibleSelection.end());
506 } 522 }
507 523
508 static const AtomicString& directionString( 524 static const AtomicString& directionString(
509 TextFieldSelectionDirection direction) { 525 TextFieldSelectionDirection direction) {
510 DEFINE_STATIC_LOCAL(const AtomicString, none, ("none")); 526 DEFINE_STATIC_LOCAL(const AtomicString, none, ("none"));
511 DEFINE_STATIC_LOCAL(const AtomicString, forward, ("forward")); 527 DEFINE_STATIC_LOCAL(const AtomicString, forward, ("forward"));
512 DEFINE_STATIC_LOCAL(const AtomicString, backward, ("backward")); 528 DEFINE_STATIC_LOCAL(const AtomicString, backward, ("backward"));
513 529
514 switch (direction) { 530 switch (direction) {
515 case SelectionHasNoDirection: 531 case SelectionHasNoDirection:
(...skipping 16 matching lines...) Expand all
532 return directionString(computeSelectionDirection()); 548 return directionString(computeSelectionDirection());
533 } 549 }
534 550
535 TextFieldSelectionDirection TextControlElement::computeSelectionDirection() 551 TextFieldSelectionDirection TextControlElement::computeSelectionDirection()
536 const { 552 const {
537 DCHECK(isTextControl()); 553 DCHECK(isTextControl());
538 LocalFrame* frame = document().frame(); 554 LocalFrame* frame = document().frame();
539 if (!frame) 555 if (!frame)
540 return SelectionHasNoDirection; 556 return SelectionHasNoDirection;
541 557
542 const VisibleSelection& selection = frame->selection().selection(); 558 const SelectionInDOMTree& selection = frame->selection().selectionInDOMTree();
559 const Position& start = selection.computeStartPosition();
543 return selection.isDirectional() 560 return selection.isDirectional()
544 ? (selection.isBaseFirst() ? SelectionHasForwardDirection 561 ? (selection.base() == start ? SelectionHasForwardDirection
545 : SelectionHasBackwardDirection) 562 : SelectionHasBackwardDirection)
546 : SelectionHasNoDirection; 563 : SelectionHasNoDirection;
547 } 564 }
548 565
549 static inline void setContainerAndOffsetForRange(Node* node, 566 static inline void setContainerAndOffsetForRange(Node* node,
550 int offset, 567 int offset,
551 Node*& containerNode, 568 Node*& containerNode,
552 int& offsetInContainer) { 569 int& offsetInContainer) {
553 if (node->isTextNode()) { 570 if (node->isTextNode()) {
554 containerNode = node; 571 containerNode = node;
555 offsetInContainer = offset; 572 offsetInContainer = offset;
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 void TextControlElement::selectionChanged(bool userTriggered) { 696 void TextControlElement::selectionChanged(bool userTriggered) {
680 if (!layoutObject() || !isTextControl()) 697 if (!layoutObject() || !isTextControl())
681 return; 698 return;
682 699
683 // selectionStart() or selectionEnd() will return cached selection when this 700 // selectionStart() or selectionEnd() will return cached selection when this
684 // node doesn't have focus. 701 // node doesn't have focus.
685 cacheSelection(computeSelectionStart(), computeSelectionEnd(), 702 cacheSelection(computeSelectionStart(), computeSelectionEnd(),
686 computeSelectionDirection()); 703 computeSelectionDirection());
687 704
688 if (LocalFrame* frame = document().frame()) { 705 if (LocalFrame* frame = document().frame()) {
689 if (frame->selection().isRange() && userTriggered) 706 if (frame->selection().selectionInDOMTree().isRange() && userTriggered)
690 dispatchEvent(Event::createBubble(EventTypeNames::select)); 707 dispatchEvent(Event::createBubble(EventTypeNames::select));
691 } 708 }
692 } 709 }
693 710
694 void TextControlElement::scheduleSelectEvent() { 711 void TextControlElement::scheduleSelectEvent() {
695 Event* event = Event::createBubble(EventTypeNames::select); 712 Event* event = Event::createBubble(EventTypeNames::select);
696 event->setTarget(this); 713 event->setTarget(this);
697 document().enqueueUniqueAnimationFrameEvent(event); 714 document().enqueueUniqueAnimationFrameEvent(event);
698 } 715 }
699 716
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 914
898 void TextControlElement::copyNonAttributePropertiesFromElement( 915 void TextControlElement::copyNonAttributePropertiesFromElement(
899 const Element& source) { 916 const Element& source) {
900 const TextControlElement& sourceElement = 917 const TextControlElement& sourceElement =
901 static_cast<const TextControlElement&>(source); 918 static_cast<const TextControlElement&>(source);
902 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit; 919 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit;
903 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source); 920 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source);
904 } 921 }
905 922
906 } // namespace blink 923 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698