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

Side by Side Diff: third_party/WebKit/Source/core/editing/InputMethodController.cpp

Issue 2704933006: Expand FrameSeleciton::rootEditableElement() to increase chances of hoisting update layout (Closed)
Patch Set: 2017-02-21T15:42:51 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) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 return false; 272 return false;
273 const SelectionInDOMTree& selection = 273 const SelectionInDOMTree& selection =
274 SelectionInDOMTree::Builder() 274 SelectionInDOMTree::Builder()
275 .setBaseAndExtent(oldSelectionRange) 275 .setBaseAndExtent(oldSelectionRange)
276 .setIsHandleVisible(isHandleVisible) 276 .setIsHandleVisible(isHandleVisible)
277 .build(); 277 .build();
278 frame().selection().setSelection(selection, FrameSelection::CloseTyping); 278 frame().selection().setSelection(selection, FrameSelection::CloseTyping);
279 return true; 279 return true;
280 } 280 }
281 281
282 Element* rootEditableElement = frame().selection().rootEditableElement(); 282 Element* rootEditableElement =
283 frame()
284 .selection()
285 .computeVisibleSelectionInDOMTreeDeprecated()
286 .rootEditableElement();
283 if (!rootEditableElement) 287 if (!rootEditableElement)
284 return false; 288 return false;
285 PlainTextRange compositionRange = 289 PlainTextRange compositionRange =
286 PlainTextRange::create(*rootEditableElement, *m_compositionRange); 290 PlainTextRange::create(*rootEditableElement, *m_compositionRange);
287 if (compositionRange.isNull()) 291 if (compositionRange.isNull())
288 return false; 292 return false;
289 293
290 clear(); 294 clear();
291 295
292 if (!moveCaret(compositionRange.end())) 296 if (!moveCaret(compositionRange.end()))
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 document().markers().addCompositionMarker( 371 document().markers().addCompositionMarker(
368 ephemeralLineRange.startPosition(), ephemeralLineRange.endPosition(), 372 ephemeralLineRange.startPosition(), ephemeralLineRange.endPosition(),
369 underline.color(), underline.thick(), underline.backgroundColor()); 373 underline.color(), underline.thick(), underline.backgroundColor());
370 } 374 }
371 } 375 }
372 376
373 bool InputMethodController::replaceCompositionAndMoveCaret( 377 bool InputMethodController::replaceCompositionAndMoveCaret(
374 const String& text, 378 const String& text,
375 int relativeCaretPosition, 379 int relativeCaretPosition,
376 const Vector<CompositionUnderline>& underlines) { 380 const Vector<CompositionUnderline>& underlines) {
377 Element* rootEditableElement = frame().selection().rootEditableElement(); 381 Element* rootEditableElement =
382 frame()
383 .selection()
384 .computeVisibleSelectionInDOMTreeDeprecated()
385 .rootEditableElement();
378 if (!rootEditableElement) 386 if (!rootEditableElement)
379 return false; 387 return false;
380 DCHECK(hasComposition()); 388 DCHECK(hasComposition());
381 PlainTextRange compositionRange = 389 PlainTextRange compositionRange =
382 PlainTextRange::create(*rootEditableElement, *m_compositionRange); 390 PlainTextRange::create(*rootEditableElement, *m_compositionRange);
383 if (compositionRange.isNull()) 391 if (compositionRange.isNull())
384 return false; 392 return false;
385 int textStart = compositionRange.start(); 393 int textStart = compositionRange.start();
386 394
387 if (!replaceComposition(text)) 395 if (!replaceComposition(text))
(...skipping 24 matching lines...) Expand all
412 const Vector<CompositionUnderline>& underlines) { 420 const Vector<CompositionUnderline>& underlines) {
413 PlainTextRange selectionRange = getSelectionOffsets(); 421 PlainTextRange selectionRange = getSelectionOffsets();
414 if (selectionRange.isNull()) 422 if (selectionRange.isNull())
415 return false; 423 return false;
416 int textStart = selectionRange.start(); 424 int textStart = selectionRange.start();
417 425
418 if (text.length()) { 426 if (text.length()) {
419 if (!insertText(text)) 427 if (!insertText(text))
420 return false; 428 return false;
421 429
422 Element* rootEditableElement = frame().selection().rootEditableElement(); 430 Element* rootEditableElement =
431 frame()
432 .selection()
433 .computeVisibleSelectionInDOMTreeDeprecated()
434 .rootEditableElement();
423 if (rootEditableElement) { 435 if (rootEditableElement) {
424 addCompositionUnderlines(underlines, rootEditableElement, textStart); 436 addCompositionUnderlines(underlines, rootEditableElement, textStart);
425 } 437 }
426 } 438 }
427 439
428 int absoluteCaretPosition = computeAbsoluteCaretPosition( 440 int absoluteCaretPosition = computeAbsoluteCaretPosition(
429 textStart, text.length(), relativeCaretPosition); 441 textStart, text.length(), relativeCaretPosition);
430 return moveCaret(absoluteCaretPosition); 442 return moveCaret(absoluteCaretPosition);
431 } 443 }
432 444
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 static_cast<int>(getSelectionOffsets().start()); 631 static_cast<int>(getSelectionOffsets().start());
620 const int start = selectionOffsetsStart + selectionStart; 632 const int start = selectionOffsetsStart + selectionStart;
621 const int end = selectionOffsetsStart + selectionEnd; 633 const int end = selectionOffsetsStart + selectionEnd;
622 return createRangeForSelection(start, end, textLength); 634 return createRangeForSelection(start, end, textLength);
623 } 635 }
624 636
625 void InputMethodController::setCompositionFromExistingText( 637 void InputMethodController::setCompositionFromExistingText(
626 const Vector<CompositionUnderline>& underlines, 638 const Vector<CompositionUnderline>& underlines,
627 unsigned compositionStart, 639 unsigned compositionStart,
628 unsigned compositionEnd) { 640 unsigned compositionEnd) {
629 Element* editable = frame().selection().rootEditableElement(); 641 Element* editable = frame()
642 .selection()
643 .computeVisibleSelectionInDOMTreeDeprecated()
644 .rootEditableElement();
630 if (!editable) 645 if (!editable)
631 return; 646 return;
632 647
633 DCHECK(!document().needsLayoutTreeUpdate()); 648 DCHECK(!document().needsLayoutTreeUpdate());
634 649
635 const EphemeralRange range = 650 const EphemeralRange range =
636 PlainTextRange(compositionStart, compositionEnd).createRange(*editable); 651 PlainTextRange(compositionStart, compositionEnd).createRange(*editable);
637 if (range.isNull()) 652 if (range.isNull())
638 return; 653 return;
639 654
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 ContainerNode* editable = 697 ContainerNode* editable =
683 frame().selection().rootEditableElementOrTreeScopeRootNode(); 698 frame().selection().rootEditableElementOrTreeScopeRootNode();
684 DCHECK(editable); 699 DCHECK(editable);
685 return PlainTextRange::create(*editable, range); 700 return PlainTextRange::create(*editable, range);
686 } 701 }
687 702
688 EphemeralRange InputMethodController::ephemeralRangeForOffsets( 703 EphemeralRange InputMethodController::ephemeralRangeForOffsets(
689 const PlainTextRange& offsets) const { 704 const PlainTextRange& offsets) const {
690 if (offsets.isNull()) 705 if (offsets.isNull())
691 return EphemeralRange(); 706 return EphemeralRange();
692 Element* rootEditableElement = frame().selection().rootEditableElement(); 707 Element* rootEditableElement =
708 frame()
709 .selection()
710 .computeVisibleSelectionInDOMTreeDeprecated()
711 .rootEditableElement();
693 if (!rootEditableElement) 712 if (!rootEditableElement)
694 return EphemeralRange(); 713 return EphemeralRange();
695 714
696 DCHECK(!document().needsLayoutTreeUpdate()); 715 DCHECK(!document().needsLayoutTreeUpdate());
697 716
698 return offsets.createRange(*rootEditableElement); 717 return offsets.createRange(*rootEditableElement);
699 } 718 }
700 719
701 bool InputMethodController::setSelectionOffsets( 720 bool InputMethodController::setSelectionOffsets(
702 const PlainTextRange& selectionOffsets, 721 const PlainTextRange& selectionOffsets,
(...skipping 16 matching lines...) Expand all
719 } 738 }
720 739
721 PlainTextRange InputMethodController::createRangeForSelection( 740 PlainTextRange InputMethodController::createRangeForSelection(
722 int start, 741 int start,
723 int end, 742 int end,
724 size_t textLength) const { 743 size_t textLength) const {
725 // In case of exceeding the left boundary. 744 // In case of exceeding the left boundary.
726 start = std::max(start, 0); 745 start = std::max(start, 0);
727 end = std::max(end, start); 746 end = std::max(end, start);
728 747
729 Element* rootEditableElement = frame().selection().rootEditableElement(); 748 Element* rootEditableElement =
749 frame()
750 .selection()
751 .computeVisibleSelectionInDOMTreeDeprecated()
752 .rootEditableElement();
730 if (!rootEditableElement) 753 if (!rootEditableElement)
731 return PlainTextRange(); 754 return PlainTextRange();
732 const EphemeralRange& range = 755 const EphemeralRange& range =
733 EphemeralRange::rangeOfContents(*rootEditableElement); 756 EphemeralRange::rangeOfContents(*rootEditableElement);
734 if (range.isNull()) 757 if (range.isNull())
735 return PlainTextRange(); 758 return PlainTextRange();
736 759
737 const TextIteratorBehavior& behavior = 760 const TextIteratorBehavior& behavior =
738 TextIteratorBehavior::Builder() 761 TextIteratorBehavior::Builder()
739 .setEmitsObjectReplacementCharacter(true) 762 .setEmitsObjectReplacementCharacter(true)
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 } 829 }
807 830
808 // TODO(yabinh): We should reduce the number of selectionchange events. 831 // TODO(yabinh): We should reduce the number of selectionchange events.
809 void InputMethodController::deleteSurroundingText(int before, int after) { 832 void InputMethodController::deleteSurroundingText(int before, int after) {
810 if (!editor().canEdit()) 833 if (!editor().canEdit())
811 return; 834 return;
812 const PlainTextRange selectionOffsets(getSelectionOffsets()); 835 const PlainTextRange selectionOffsets(getSelectionOffsets());
813 if (selectionOffsets.isNull()) 836 if (selectionOffsets.isNull())
814 return; 837 return;
815 Element* const rootEditableElement = 838 Element* const rootEditableElement =
816 frame().selection().rootEditableElement(); 839 frame()
840 .selection()
841 .computeVisibleSelectionInDOMTreeDeprecated()
842 .rootEditableElement();
817 if (!rootEditableElement) 843 if (!rootEditableElement)
818 return; 844 return;
819 int selectionStart = static_cast<int>(selectionOffsets.start()); 845 int selectionStart = static_cast<int>(selectionOffsets.start());
820 int selectionEnd = static_cast<int>(selectionOffsets.end()); 846 int selectionEnd = static_cast<int>(selectionOffsets.end());
821 847
822 // Select the text to be deleted before selectionStart. 848 // Select the text to be deleted before selectionStart.
823 if (before > 0 && selectionStart > 0) { 849 if (before > 0 && selectionStart > 0) {
824 // In case of exceeding the left boundary. 850 // In case of exceeding the left boundary.
825 const int start = std::max(selectionStart - before, 0); 851 const int start = std::max(selectionStart - before, 0);
826 852
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 896
871 WebTextInputInfo InputMethodController::textInputInfo() const { 897 WebTextInputInfo InputMethodController::textInputInfo() const {
872 WebTextInputInfo info; 898 WebTextInputInfo info;
873 if (!isAvailable()) 899 if (!isAvailable())
874 return info; 900 return info;
875 901
876 if (!frame().selection().isAvailable()) { 902 if (!frame().selection().isAvailable()) {
877 // plugins/mouse-capture-inside-shadow.html reaches here. 903 // plugins/mouse-capture-inside-shadow.html reaches here.
878 return info; 904 return info;
879 } 905 }
880 Element* element = frame().selection().rootEditableElement(); 906 Element* element = frame()
907 .selection()
908 .computeVisibleSelectionInDOMTreeDeprecated()
909 .rootEditableElement();
881 if (!element) 910 if (!element)
882 return info; 911 return info;
883 912
884 info.inputMode = inputModeOfFocusedElement(); 913 info.inputMode = inputModeOfFocusedElement();
885 info.type = textInputType(); 914 info.type = textInputType();
886 info.flags = textInputFlags(); 915 info.flags = textInputFlags();
887 if (info.type == WebTextInputTypeNone) 916 if (info.type == WebTextInputTypeNone)
888 return info; 917 return info;
889 918
890 if (!frame().editor().canEdit()) 919 if (!frame().editor().canEdit())
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 finishComposingText(DoNotKeepSelection); 1115 finishComposingText(DoNotKeepSelection);
1087 } 1116 }
1088 1117
1089 DEFINE_TRACE(InputMethodController) { 1118 DEFINE_TRACE(InputMethodController) {
1090 visitor->trace(m_frame); 1119 visitor->trace(m_frame);
1091 visitor->trace(m_compositionRange); 1120 visitor->trace(m_compositionRange);
1092 SynchronousMutationObserver::trace(visitor); 1121 SynchronousMutationObserver::trace(visitor);
1093 } 1122 }
1094 1123
1095 } // namespace blink 1124 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/Editor.cpp ('k') | third_party/WebKit/Source/core/editing/commands/EditorCommand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698