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

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

Issue 2457613004: Utilize FrameSelection::setSelection() taking SelectionInDOMTree/SelectionInFlatTree (Closed)
Patch Set: 2016-11-24T13:04:01 Rebase Created 4 years 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) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 // selection to paint again. 450 // selection to paint again.
451 // TODO(yosin): We should paint changed area only rather than whole 451 // TODO(yosin): We should paint changed area only rather than whole
452 // selected range. 452 // selected range.
453 clearLayoutTreeSelection = true; 453 clearLayoutTreeSelection = true;
454 } 454 }
455 455
456 if (clearLayoutTreeSelection) 456 if (clearLayoutTreeSelection)
457 selection().start().document()->layoutViewItem().clearSelection(); 457 selection().start().document()->layoutViewItem().clearSelection();
458 458
459 if (clearDOMTreeSelection) 459 if (clearDOMTreeSelection)
460 setSelection(VisibleSelection(), DoNotSetFocus); 460 setSelection(SelectionInDOMTree(), DoNotSetFocus);
461 m_frameCaret->setCaretRectNeedsUpdate(); 461 m_frameCaret->setCaretRectNeedsUpdate();
462 462
463 // TODO(yosin): We should move to call |TypingCommand::closeTyping()| to 463 // TODO(yosin): We should move to call |TypingCommand::closeTyping()| to
464 // |Editor| class. 464 // |Editor| class.
465 if (!document().isRunningExecCommand()) 465 if (!document().isRunningExecCommand())
466 TypingCommand::closeTyping(m_frame); 466 TypingCommand::closeTyping(m_frame);
467 } 467 }
468 468
469 static Position updatePositionAfterAdoptingTextReplacement( 469 static Position updatePositionAfterAdoptingTextReplacement(
470 const Position& position, 470 const Position& position,
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 686
687 m_granularity = CharacterGranularity; 687 m_granularity = CharacterGranularity;
688 688
689 return true; 689 return true;
690 } 690 }
691 691
692 void FrameSelection::clear() { 692 void FrameSelection::clear() {
693 m_granularity = CharacterGranularity; 693 m_granularity = CharacterGranularity;
694 if (m_granularityStrategy) 694 if (m_granularityStrategy)
695 m_granularityStrategy->Clear(); 695 m_granularityStrategy->Clear();
696 setSelection(VisibleSelection()); 696 setSelection(SelectionInDOMTree());
697 } 697 }
698 698
699 void FrameSelection::documentAttached(Document* document) { 699 void FrameSelection::documentAttached(Document* document) {
700 DCHECK(document); 700 DCHECK(document);
701 DCHECK(!m_document) << "FrameSelection is already attached to " << m_document; 701 DCHECK(!m_document) << "FrameSelection is already attached to " << m_document;
702 m_document = document; 702 m_document = document;
703 m_useSecureKeyboardEntryWhenActive = false; 703 m_useSecureKeyboardEntryWhenActive = false;
704 m_selectionEditor->documentAttached(document); 704 m_selectionEditor->documentAttached(document);
705 } 705 }
706 706
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 840
841 SelectionInDOMTree::Builder builder; 841 SelectionInDOMTree::Builder builder;
842 builder 842 builder
843 .setBaseAndExtentDeprecated(beforeOwnerElement.deepEquivalent(), 843 .setBaseAndExtentDeprecated(beforeOwnerElement.deepEquivalent(),
844 afterOwnerElement.deepEquivalent()) 844 afterOwnerElement.deepEquivalent())
845 .setAffinity(beforeOwnerElement.affinity()); 845 .setAffinity(beforeOwnerElement.affinity());
846 846
847 // Focus on the parent frame, and then select from before this element to 847 // Focus on the parent frame, and then select from before this element to
848 // after. 848 // after.
849 VisibleSelection newSelection = createVisibleSelection(builder.build()); 849 VisibleSelection newSelection = createVisibleSelection(builder.build());
850 // TODO(yosin): We should call |FocusController::setFocusedFrame()| before
851 // |createVisibleSelection()|.
850 page->focusController().setFocusedFrame(parent); 852 page->focusController().setFocusedFrame(parent);
851 // setFocusedFrame can dispatch synchronous focus/blur events. The document 853 // setFocusedFrame can dispatch synchronous focus/blur events. The document
852 // tree might be modified. 854 // tree might be modified.
853 if (newSelection.isNonOrphanedCaretOrRange()) 855 if (newSelection.isNonOrphanedCaretOrRange())
854 toLocalFrame(parent)->selection().setSelection(newSelection); 856 toLocalFrame(parent)->selection().setSelection(newSelection);
855 } 857 }
856 858
857 // Returns a shadow tree node for legacy shadow trees, a child of the 859 // Returns a shadow tree node for legacy shadow trees, a child of the
858 // ShadowRoot node for new shadow trees, or 0 for non-shadow trees. 860 // ShadowRoot node for new shadow trees, or 0 for non-shadow trees.
859 static Node* nonBoundaryShadowTreeRootNode(const Position& position) { 861 static Node* nonBoundaryShadowTreeRootNode(const Position& position) {
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
1289 1291
1290 bool FrameSelection::selectWordAroundPosition(const VisiblePosition& position) { 1292 bool FrameSelection::selectWordAroundPosition(const VisiblePosition& position) {
1291 static const EWordSide wordSideList[2] = {RightWordIfOnBoundary, 1293 static const EWordSide wordSideList[2] = {RightWordIfOnBoundary,
1292 LeftWordIfOnBoundary}; 1294 LeftWordIfOnBoundary};
1293 for (EWordSide wordSide : wordSideList) { 1295 for (EWordSide wordSide : wordSideList) {
1294 VisiblePosition start = startOfWord(position, wordSide); 1296 VisiblePosition start = startOfWord(position, wordSide);
1295 VisiblePosition end = endOfWord(position, wordSide); 1297 VisiblePosition end = endOfWord(position, wordSide);
1296 String text = 1298 String text =
1297 plainText(EphemeralRange(start.deepEquivalent(), end.deepEquivalent())); 1299 plainText(EphemeralRange(start.deepEquivalent(), end.deepEquivalent()));
1298 if (!text.isEmpty() && !isSeparator(text.characterStartingAt(0))) { 1300 if (!text.isEmpty() && !isSeparator(text.characterStartingAt(0))) {
1299 setSelection( 1301 setSelection(SelectionInDOMTree::Builder()
1300 createVisibleSelection(SelectionInDOMTree::Builder() 1302 .collapse(start.toPositionWithAffinity())
1301 .collapse(start.toPositionWithAffinity()) 1303 .extend(end.deepEquivalent())
1302 .extend(end.deepEquivalent()) 1304 .build(),
1303 .build()), 1305 CloseTyping | ClearTypingStyle,
1304 CloseTyping | ClearTypingStyle, CursorAlignOnScroll::IfNeeded, 1306 CursorAlignOnScroll::IfNeeded, WordGranularity);
1305 WordGranularity);
1306 return true; 1307 return true;
1307 } 1308 }
1308 } 1309 }
1309 1310
1310 return false; 1311 return false;
1311 } 1312 }
1312 1313
1313 GranularityStrategy* FrameSelection::granularityStrategy() { 1314 GranularityStrategy* FrameSelection::granularityStrategy() {
1314 // We do lazy initalization for m_granularityStrategy, because if we 1315 // We do lazy initalization for m_granularityStrategy, because if we
1315 // initialize it right in the constructor - the correct settings may not be 1316 // initialize it right in the constructor - the correct settings may not be
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1405 } 1406 }
1406 1407
1407 void showTree(const blink::FrameSelection* sel) { 1408 void showTree(const blink::FrameSelection* sel) {
1408 if (sel) 1409 if (sel)
1409 sel->showTreeForThis(); 1410 sel->showTreeForThis();
1410 else 1411 else
1411 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; 1412 LOG(INFO) << "Cannot showTree for <null> FrameSelection.";
1412 } 1413 }
1413 1414
1414 #endif 1415 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698