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

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

Issue 2491763004: Revert of Utilize FrameSelection::setSelection() taking SelectionInDOMTree/SelectionInFlatTree (Closed)
Patch Set: 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(SelectionInDOMTree(), DoNotSetFocus); 460 setSelection(VisibleSelection(), 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(SelectionInDOMTree()); 700 setSelection(VisibleSelection());
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()|.
856 page->focusController().setFocusedFrame(parent); 854 page->focusController().setFocusedFrame(parent);
857 // setFocusedFrame can dispatch synchronous focus/blur events. The document 855 // setFocusedFrame can dispatch synchronous focus/blur events. The document
858 // tree might be modified. 856 // tree might be modified.
859 if (newSelection.isNonOrphanedCaretOrRange()) 857 if (newSelection.isNonOrphanedCaretOrRange())
860 toLocalFrame(parent)->selection().setSelection(newSelection); 858 toLocalFrame(parent)->selection().setSelection(newSelection);
861 } 859 }
862 860
863 // Returns a shadow tree node for legacy shadow trees, a child of the 861 // Returns a shadow tree node for legacy shadow trees, a child of the
864 // ShadowRoot node for new shadow trees, or 0 for non-shadow trees. 862 // ShadowRoot node for new shadow trees, or 0 for non-shadow trees.
865 static Node* nonBoundaryShadowTreeRootNode(const Position& position) { 863 static Node* nonBoundaryShadowTreeRootNode(const Position& position) {
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
1287 1285
1288 bool FrameSelection::selectWordAroundPosition(const VisiblePosition& position) { 1286 bool FrameSelection::selectWordAroundPosition(const VisiblePosition& position) {
1289 static const EWordSide wordSideList[2] = {RightWordIfOnBoundary, 1287 static const EWordSide wordSideList[2] = {RightWordIfOnBoundary,
1290 LeftWordIfOnBoundary}; 1288 LeftWordIfOnBoundary};
1291 for (EWordSide wordSide : wordSideList) { 1289 for (EWordSide wordSide : wordSideList) {
1292 VisiblePosition start = startOfWord(position, wordSide); 1290 VisiblePosition start = startOfWord(position, wordSide);
1293 VisiblePosition end = endOfWord(position, wordSide); 1291 VisiblePosition end = endOfWord(position, wordSide);
1294 String text = 1292 String text =
1295 plainText(EphemeralRange(start.deepEquivalent(), end.deepEquivalent())); 1293 plainText(EphemeralRange(start.deepEquivalent(), end.deepEquivalent()));
1296 if (!text.isEmpty() && !isSeparator(text.characterStartingAt(0))) { 1294 if (!text.isEmpty() && !isSeparator(text.characterStartingAt(0))) {
1297 setSelection(SelectionInDOMTree::Builder() 1295 setSelection(
1298 .collapse(start.toPositionWithAffinity()) 1296 createVisibleSelection(SelectionInDOMTree::Builder()
1299 .extend(end.deepEquivalent()) 1297 .collapse(start.toPositionWithAffinity())
1300 .build(), 1298 .extend(end.deepEquivalent())
1301 CloseTyping | ClearTypingStyle, 1299 .build()),
1302 CursorAlignOnScroll::IfNeeded, WordGranularity); 1300 CloseTyping | ClearTypingStyle, CursorAlignOnScroll::IfNeeded,
1301 WordGranularity);
1303 return true; 1302 return true;
1304 } 1303 }
1305 } 1304 }
1306 1305
1307 return false; 1306 return false;
1308 } 1307 }
1309 1308
1310 GranularityStrategy* FrameSelection::granularityStrategy() { 1309 GranularityStrategy* FrameSelection::granularityStrategy() {
1311 // We do lazy initalization for m_granularityStrategy, because if we 1310 // We do lazy initalization for m_granularityStrategy, because if we
1312 // initialize it right in the constructor - the correct settings may not be 1311 // initialize it right in the constructor - the correct settings may not be
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1402 } 1401 }
1403 1402
1404 void showTree(const blink::FrameSelection* sel) { 1403 void showTree(const blink::FrameSelection* sel) {
1405 if (sel) 1404 if (sel)
1406 sel->showTreeForThis(); 1405 sel->showTreeForThis();
1407 else 1406 else
1408 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; 1407 LOG(INFO) << "Cannot showTree for <null> FrameSelection.";
1409 } 1408 }
1410 1409
1411 #endif 1410 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698