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

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

Issue 1958093002: CONTINUED Make FrameSelection to hold non-canonicalized positions Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2017-01-16T20:04:35 Created 3 years, 11 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, 2009, 2010, 2011 Apple Inc. All rights 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights
3 * reserved. 3 * reserved.
4 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) 4 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
5 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies) 5 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies)
6 * Copyright (C) 2015 Google Inc. All rights reserved. 6 * Copyright (C) 2015 Google Inc. All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 } 178 }
179 179
180 const VisiblePositionInFlatTree& visibleHitPos = 180 const VisiblePositionInFlatTree& visibleHitPos =
181 visiblePositionOfHitTestResult(event.hitTestResult()); 181 visiblePositionOfHitTestResult(event.hitTestResult());
182 const VisiblePositionInFlatTree& visiblePos = 182 const VisiblePositionInFlatTree& visiblePos =
183 visibleHitPos.isNull() 183 visibleHitPos.isNull()
184 ? createVisiblePosition( 184 ? createVisiblePosition(
185 PositionInFlatTree::firstPositionInOrBeforeNode(innerNode)) 185 PositionInFlatTree::firstPositionInOrBeforeNode(innerNode))
186 : visibleHitPos; 186 : visibleHitPos;
187 const VisibleSelectionInFlatTree& selection = 187 const VisibleSelectionInFlatTree& selection =
188 this->selection().visibleSelection<EditingInFlatTreeStrategy>(); 188 this->selection().computeVisibleSelectionInFlatTree();
189 189
190 if (extendSelection && !selection.isNone()) { 190 if (extendSelection && !selection.isNone()) {
191 // Note: "fast/events/shift-click-user-select-none.html" makes 191 // Note: "fast/events/shift-click-user-select-none.html" makes
192 // |pos.isNull()| true. 192 // |pos.isNull()| true.
193 const PositionInFlatTree& pos = adjustPositionRespectUserSelectAll( 193 const PositionInFlatTree& pos = adjustPositionRespectUserSelectAll(
194 innerNode, selection.start(), selection.end(), 194 innerNode, selection.start(), selection.end(),
195 visiblePos.deepEquivalent()); 195 visiblePos.deepEquivalent());
196 SelectionInFlatTree::Builder builder; 196 SelectionInFlatTree::Builder builder;
197 builder.setGranularity(this->selection().granularity()); 197 builder.setGranularity(this->selection().granularity());
198 if (m_frame->editor().behavior().shouldConsiderSelectionAsDirectional()) { 198 if (m_frame->editor().behavior().shouldConsiderSelectionAsDirectional()) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 VisiblePositionInFlatTree targetPosition = createVisiblePosition( 260 VisiblePositionInFlatTree targetPosition = createVisiblePosition(
261 fromPositionInDOMTree<EditingInFlatTreeStrategy>(rawTargetPosition)); 261 fromPositionInDOMTree<EditingInFlatTreeStrategy>(rawTargetPosition));
262 // Don't modify the selection if we're not on a node. 262 // Don't modify the selection if we're not on a node.
263 if (targetPosition.isNull()) 263 if (targetPosition.isNull())
264 return; 264 return;
265 265
266 // Restart the selection if this is the first mouse move. This work is usually 266 // Restart the selection if this is the first mouse move. This work is usually
267 // done in handleMousePressEvent, but not if the mouse press was on an 267 // done in handleMousePressEvent, but not if the mouse press was on an
268 // existing selection. 268 // existing selection.
269 VisibleSelectionInFlatTree newSelection = 269 VisibleSelectionInFlatTree newSelection =
270 selection().visibleSelection<EditingInFlatTreeStrategy>(); 270 selection().computeVisibleSelectionInFlatTree();
271 271
272 // Special case to limit selection to the containing block for SVG text. 272 // Special case to limit selection to the containing block for SVG text.
273 // FIXME: Isn't there a better non-SVG-specific way to do this? 273 // FIXME: Isn't there a better non-SVG-specific way to do this?
274 if (Node* selectionBaseNode = newSelection.base().anchorNode()) { 274 if (Node* selectionBaseNode = newSelection.base().anchorNode()) {
275 if (LayoutObject* selectionBaseLayoutObject = 275 if (LayoutObject* selectionBaseLayoutObject =
276 selectionBaseNode->layoutObject()) { 276 selectionBaseNode->layoutObject()) {
277 if (selectionBaseLayoutObject->isSVGText()) { 277 if (selectionBaseLayoutObject->isSVGText()) {
278 if (target->layoutObject()->containingBlock() != 278 if (target->layoutObject()->containingBlock() !=
279 selectionBaseLayoutObject->containingBlock()) 279 selectionBaseLayoutObject->containingBlock())
280 return; 280 return;
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 if (endpointsAdjustmentMode == AdjustEndpointsAtBidiBoundary) 625 if (endpointsAdjustmentMode == AdjustEndpointsAtBidiBoundary)
626 adjustEndpointsAtBidiBoundary(newBase, newExtent); 626 adjustEndpointsAtBidiBoundary(newBase, newExtent);
627 627
628 if (newBase.deepEquivalent() != base.deepEquivalent() || 628 if (newBase.deepEquivalent() != base.deepEquivalent() ||
629 newExtent.deepEquivalent() != extent.deepEquivalent()) { 629 newExtent.deepEquivalent() != extent.deepEquivalent()) {
630 m_originalBaseInFlatTree = base; 630 m_originalBaseInFlatTree = base;
631 setContext(&document()); 631 setContext(&document());
632 newSelection.setBase(newBase); 632 newSelection.setBase(newBase);
633 newSelection.setExtent(newExtent); 633 newSelection.setExtent(newExtent);
634 } else if (originalBase.isNotNull()) { 634 } else if (originalBase.isNotNull()) {
635 if (selection().visibleSelection<EditingInFlatTreeStrategy>().base() == 635 if (selection().computeVisibleSelectionInFlatTree().base() ==
636 newSelection.base()) 636 newSelection.base())
637 newSelection.setBase(originalBase); 637 newSelection.setBase(originalBase);
638 m_originalBaseInFlatTree = VisiblePositionInFlatTree(); 638 m_originalBaseInFlatTree = VisiblePositionInFlatTree();
639 } 639 }
640 640
641 // Adjusting base and extent will make newSelection always directional 641 // Adjusting base and extent will make newSelection always directional
642 newSelection.setIsDirectional(isDirectional); 642 newSelection.setIsDirectional(isDirectional);
643 if (selection().visibleSelection<EditingInFlatTreeStrategy>() == newSelection) 643 if (selection().computeVisibleSelectionInFlatTree() == newSelection)
644 return; 644 return;
645 645
646 const FrameSelection::SetSelectionOptions options = 646 const FrameSelection::SetSelectionOptions options =
647 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle; 647 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle;
648 selection().setSelection(newSelection, options, CursorAlignOnScroll::IfNeeded, 648 selection().setSelection(newSelection, options, CursorAlignOnScroll::IfNeeded,
649 granularity); 649 granularity);
650 } 650 }
651 651
652 void SelectionController::setCaretAtHitTestResult( 652 void SelectionController::setCaretAtHitTestResult(
653 const HitTestResult& hitTestResult) { 653 const HitTestResult& hitTestResult) {
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 WebPointerProperties::Button::Right) { 814 WebPointerProperties::Button::Right) {
815 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets 815 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
816 // needs to be audited. See http://crbug.com/590369 for more details. 816 // needs to be audited. See http://crbug.com/590369 for more details.
817 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); 817 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets();
818 818
819 SelectionInFlatTree::Builder builder; 819 SelectionInFlatTree::Builder builder;
820 Node* node = event.innerNode(); 820 Node* node = event.innerNode();
821 if (node && node->layoutObject() && hasEditableStyle(*node)) { 821 if (node && node->layoutObject() && hasEditableStyle(*node)) {
822 const VisiblePositionInFlatTree pos = 822 const VisiblePositionInFlatTree pos =
823 visiblePositionOfHitTestResult(event.hitTestResult()); 823 visiblePositionOfHitTestResult(event.hitTestResult());
824 if (pos.isNotNull()) 824 if (pos.isNotNull()) {
825 builder.collapse(pos.toPositionWithAffinity()); 825 builder.collapse(pos.toPositionWithAffinity());
826 }
826 } 827 }
827 828
828 if (selection().visibleSelection<EditingInFlatTreeStrategy>() != 829 if (selection().computeVisibleSelectionInFlatTree() !=
829 createVisibleSelection(builder.build())) { 830 createVisibleSelection(builder.build())) {
830 selection().setSelection(builder.build()); 831 selection().setSelection(builder.build());
831 } 832 }
832 833
833 handled = true; 834 handled = true;
834 } 835 }
835 836
836 selection().notifyLayoutObjectOfSelectionChange(UserTriggered); 837 selection().notifyLayoutObjectOfSelectionChange(UserTriggered);
837 838
838 selection().selectFrameElementInParentIfFullySelected(); 839 selection().selectFrameElementInParentIfFullySelected();
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets 974 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
974 // needs to be audited. See http://crbug.com/590369 for more details. 975 // needs to be audited. See http://crbug.com/590369 for more details.
975 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); 976 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets();
976 977
977 const VisiblePositionInFlatTree& visiblePos = 978 const VisiblePositionInFlatTree& visiblePos =
978 visiblePositionOfHitTestResult(mev.hitTestResult()); 979 visiblePositionOfHitTestResult(mev.hitTestResult());
979 if (visiblePos.isNull()) { 980 if (visiblePos.isNull()) {
980 selection().setSelection(SelectionInFlatTree()); 981 selection().setSelection(SelectionInFlatTree());
981 return; 982 return;
982 } 983 }
983 selection().setSelection(SelectionInFlatTree::Builder() 984 SelectionInFlatTree::Builder builder;
984 .collapse(visiblePos.toPositionWithAffinity()) 985 builder.collapse(visiblePos.toPositionWithAffinity());
985 .build()); 986 selection().setSelection(builder.build());
986 } 987 }
987 988
988 void SelectionController::initializeSelectionState() { 989 void SelectionController::initializeSelectionState() {
989 m_selectionState = SelectionState::HaveNotStartedSelection; 990 m_selectionState = SelectionState::HaveNotStartedSelection;
990 } 991 }
991 992
992 void SelectionController::setMouseDownMayStartSelect(bool mayStartSelect) { 993 void SelectionController::setMouseDownMayStartSelect(bool mayStartSelect) {
993 m_mouseDownMayStartSelect = mayStartSelect; 994 m_mouseDownMayStartSelect = mayStartSelect;
994 } 995 }
995 996
(...skipping 22 matching lines...) Expand all
1018 return event.event().altKey() && event.isOverLink(); 1019 return event.event().altKey() && event.isOverLink();
1019 } 1020 }
1020 1021
1021 bool isExtendingSelection(const MouseEventWithHitTestResults& event) { 1022 bool isExtendingSelection(const MouseEventWithHitTestResults& event) {
1022 bool isMouseDownOnLinkOrImage = 1023 bool isMouseDownOnLinkOrImage =
1023 event.isOverLink() || event.hitTestResult().image(); 1024 event.isOverLink() || event.hitTestResult().image();
1024 return event.event().shiftKey() && !isMouseDownOnLinkOrImage; 1025 return event.event().shiftKey() && !isMouseDownOnLinkOrImage;
1025 } 1026 }
1026 1027
1027 } // namespace blink 1028 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698