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

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

Issue 2457613004: Utilize FrameSelection::setSelection() taking SelectionInDOMTree/SelectionInFlatTree (Closed)
Patch Set: 2016-10-28T15:45:56 Created 4 years, 1 month 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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 if (userTriggered == UserTriggered) 690 if (userTriggered == UserTriggered)
691 m_granularity = CharacterGranularity; 691 m_granularity = CharacterGranularity;
692 692
693 return true; 693 return true;
694 } 694 }
695 695
696 void FrameSelection::clear() { 696 void FrameSelection::clear() {
697 m_granularity = CharacterGranularity; 697 m_granularity = CharacterGranularity;
698 if (m_granularityStrategy) 698 if (m_granularityStrategy)
699 m_granularityStrategy->Clear(); 699 m_granularityStrategy->Clear();
700 setSelection(VisibleSelection()); 700 setSelection(SelectionInDOMTree());
701 } 701 }
702 702
703 void FrameSelection::documentAttached(Document* document) { 703 void FrameSelection::documentAttached(Document* document) {
704 DCHECK(document); 704 DCHECK(document);
705 DCHECK(!m_document) << "FrameSelection is already attached to " << m_document; 705 DCHECK(!m_document) << "FrameSelection is already attached to " << m_document;
706 m_document = document; 706 m_document = document;
707 m_selectionEditor->documentAttached(document); 707 m_selectionEditor->documentAttached(document);
708 } 708 }
709 709
710 void FrameSelection::documentDetached(const Document& document) { 710 void FrameSelection::documentDetached(const Document& document) {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 844
845 SelectionInDOMTree::Builder builder; 845 SelectionInDOMTree::Builder builder;
846 builder 846 builder
847 .setBaseAndExtentDeprecated(beforeOwnerElement.deepEquivalent(), 847 .setBaseAndExtentDeprecated(beforeOwnerElement.deepEquivalent(),
848 afterOwnerElement.deepEquivalent()) 848 afterOwnerElement.deepEquivalent())
849 .setAffinity(beforeOwnerElement.affinity()); 849 .setAffinity(beforeOwnerElement.affinity());
850 850
851 // Focus on the parent frame, and then select from before this element to 851 // Focus on the parent frame, and then select from before this element to
852 // after. 852 // after.
853 VisibleSelection newSelection = createVisibleSelection(builder.build()); 853 VisibleSelection newSelection = createVisibleSelection(builder.build());
854 // TODO(yosin): We should call |FocusController::setFocusedFrame()| before
855 // |createVisibleSelection()|.
854 page->focusController().setFocusedFrame(parent); 856 page->focusController().setFocusedFrame(parent);
855 // setFocusedFrame can dispatch synchronous focus/blur events. The document 857 // setFocusedFrame can dispatch synchronous focus/blur events. The document
856 // tree might be modified. 858 // tree might be modified.
857 if (newSelection.isNonOrphanedCaretOrRange()) 859 if (newSelection.isNonOrphanedCaretOrRange())
858 toLocalFrame(parent)->selection().setSelection(newSelection); 860 toLocalFrame(parent)->selection().setSelection(newSelection);
859 } 861 }
860 862
861 // Returns a shadow tree node for legacy shadow trees, a child of the 863 // Returns a shadow tree node for legacy shadow trees, a child of the
862 // ShadowRoot node for new shadow trees, or 0 for non-shadow trees. 864 // ShadowRoot node for new shadow trees, or 0 for non-shadow trees.
863 static Node* nonBoundaryShadowTreeRootNode(const Position& position) { 865 static Node* nonBoundaryShadowTreeRootNode(const Position& position) {
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 1287
1286 bool FrameSelection::selectWordAroundPosition(const VisiblePosition& position) { 1288 bool FrameSelection::selectWordAroundPosition(const VisiblePosition& position) {
1287 static const EWordSide wordSideList[2] = {RightWordIfOnBoundary, 1289 static const EWordSide wordSideList[2] = {RightWordIfOnBoundary,
1288 LeftWordIfOnBoundary}; 1290 LeftWordIfOnBoundary};
1289 for (EWordSide wordSide : wordSideList) { 1291 for (EWordSide wordSide : wordSideList) {
1290 VisiblePosition start = startOfWord(position, wordSide); 1292 VisiblePosition start = startOfWord(position, wordSide);
1291 VisiblePosition end = endOfWord(position, wordSide); 1293 VisiblePosition end = endOfWord(position, wordSide);
1292 String text = 1294 String text =
1293 plainText(EphemeralRange(start.deepEquivalent(), end.deepEquivalent())); 1295 plainText(EphemeralRange(start.deepEquivalent(), end.deepEquivalent()));
1294 if (!text.isEmpty() && !isSeparator(text.characterStartingAt(0))) { 1296 if (!text.isEmpty() && !isSeparator(text.characterStartingAt(0))) {
1295 setSelection( 1297 setSelection(SelectionInDOMTree::Builder()
1296 createVisibleSelection(SelectionInDOMTree::Builder() 1298 .collapse(start.toPositionWithAffinity())
1297 .collapse(start.toPositionWithAffinity()) 1299 .extend(end.deepEquivalent())
1298 .extend(end.deepEquivalent()) 1300 .build(),
1299 .build()), 1301 CloseTyping | ClearTypingStyle,
1300 CloseTyping | ClearTypingStyle, CursorAlignOnScroll::IfNeeded, 1302 CursorAlignOnScroll::IfNeeded, WordGranularity);
1301 WordGranularity);
1302 return true; 1303 return true;
1303 } 1304 }
1304 } 1305 }
1305 1306
1306 return false; 1307 return false;
1307 } 1308 }
1308 1309
1309 GranularityStrategy* FrameSelection::granularityStrategy() { 1310 GranularityStrategy* FrameSelection::granularityStrategy() {
1310 // We do lazy initalization for m_granularityStrategy, because if we 1311 // We do lazy initalization for m_granularityStrategy, because if we
1311 // initialize it right in the constructor - the correct settings may not be 1312 // initialize it right in the constructor - the correct settings may not be
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1401 } 1402 }
1402 1403
1403 void showTree(const blink::FrameSelection* sel) { 1404 void showTree(const blink::FrameSelection* sel) {
1404 if (sel) 1405 if (sel)
1405 sel->showTreeForThis(); 1406 sel->showTreeForThis();
1406 else 1407 else
1407 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; 1408 LOG(INFO) << "Cannot showTree for <null> FrameSelection.";
1408 } 1409 }
1409 1410
1410 #endif 1411 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698