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

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-17T16:13:56 selectionTypeWithLegacyGranularity() 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
« no previous file with comments | « third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 {
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 16 matching lines...) Expand all
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());
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 DocumentLifecycle::DisallowTransitionScope disallowTransition(
576 document().lifecycle());
577 const SelectionInDOMTree& selection = frame->selection().selectionInDOMTree();
578 const Position& start = selection.computeStartPosition();
543 return selection.isDirectional() 579 return selection.isDirectional()
544 ? (selection.isBaseFirst() ? SelectionHasForwardDirection 580 ? (selection.base() == start ? SelectionHasForwardDirection
545 : SelectionHasBackwardDirection) 581 : SelectionHasBackwardDirection)
546 : SelectionHasNoDirection; 582 : SelectionHasNoDirection;
547 } 583 }
548 584
549 static inline void setContainerAndOffsetForRange(Node* node, 585 static inline void setContainerAndOffsetForRange(Node* node,
550 int offset, 586 int offset,
551 Node*& containerNode, 587 Node*& containerNode,
552 int& offsetInContainer) { 588 int& offsetInContainer) {
553 if (node->isTextNode()) { 589 if (node->isTextNode()) {
554 containerNode = node; 590 containerNode = node;
555 offsetInContainer = offset; 591 offsetInContainer = offset;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 714
679 void TextControlElement::selectionChanged(bool userTriggered) { 715 void TextControlElement::selectionChanged(bool userTriggered) {
680 if (!layoutObject() || !isTextControl()) 716 if (!layoutObject() || !isTextControl())
681 return; 717 return;
682 718
683 // selectionStart() or selectionEnd() will return cached selection when this 719 // selectionStart() or selectionEnd() will return cached selection when this
684 // node doesn't have focus. 720 // node doesn't have focus.
685 cacheSelection(computeSelectionStart(), computeSelectionEnd(), 721 cacheSelection(computeSelectionStart(), computeSelectionEnd(),
686 computeSelectionDirection()); 722 computeSelectionDirection());
687 723
688 if (LocalFrame* frame = document().frame()) { 724 LocalFrame* frame = document().frame();
689 if (frame->selection().isRange() && userTriggered) 725 if (!frame || !userTriggered)
690 dispatchEvent(Event::createBubble(EventTypeNames::select)); 726 return;
691 } 727 const SelectionInDOMTree& selection = frame->selection().selectionInDOMTree();
728 if (selection.selectionTypeWithLegacyGranularity() != RangeSelection)
729 return;
730 dispatchEvent(Event::createBubble(EventTypeNames::select));
692 } 731 }
693 732
694 void TextControlElement::scheduleSelectEvent() { 733 void TextControlElement::scheduleSelectEvent() {
695 Event* event = Event::createBubble(EventTypeNames::select); 734 Event* event = Event::createBubble(EventTypeNames::select);
696 event->setTarget(this); 735 event->setTarget(this);
697 document().enqueueUniqueAnimationFrameEvent(event); 736 document().enqueueUniqueAnimationFrameEvent(event);
698 } 737 }
699 738
700 void TextControlElement::parseAttribute( 739 void TextControlElement::parseAttribute(
701 const AttributeModificationParams& params) { 740 const AttributeModificationParams& params) {
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 936
898 void TextControlElement::copyNonAttributePropertiesFromElement( 937 void TextControlElement::copyNonAttributePropertiesFromElement(
899 const Element& source) { 938 const Element& source) {
900 const TextControlElement& sourceElement = 939 const TextControlElement& sourceElement =
901 static_cast<const TextControlElement&>(source); 940 static_cast<const TextControlElement&>(source);
902 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit; 941 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit;
903 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source); 942 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source);
904 } 943 }
905 944
906 } // namespace blink 945 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698