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

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

Issue 2353893002: Prune CreateVisiblePositionDeprecated from SelectionController (Closed)
Patch Set: Update layout in handleMouseReleaseEvent and passMousePressEventToSubframe Created 4 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv ed. 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv ed.
3 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) 3 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
4 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies) 4 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies)
5 * Copyright (C) 2015 Google Inc. All rights reserved. 5 * Copyright (C) 2015 Google Inc. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 return true; 107 return true;
108 108
109 if (!node->canStartSelection()) 109 if (!node->canStartSelection())
110 return false; 110 return false;
111 111
112 return true; 112 return true;
113 } 113 }
114 114
115 VisiblePositionInFlatTree visiblePositionOfHitTestResult(const HitTestResult& hi tTestResult) 115 VisiblePositionInFlatTree visiblePositionOfHitTestResult(const HitTestResult& hi tTestResult)
116 { 116 {
117 return createVisiblePositionDeprecated( 117 return createVisiblePosition(
118 fromPositionInDOMTree<EditingInFlatTreeStrategy>(hitTestResult.innerNode ()->layoutObject()->positionForPoint(hitTestResult.localPoint()))); 118 fromPositionInDOMTree<EditingInFlatTreeStrategy>(hitTestResult.innerNode ()->layoutObject()->positionForPoint(hitTestResult.localPoint())));
119 } 119 }
120 120
121 } // namespace 121 } // namespace
122 122
123 bool SelectionController::handleMousePressEventSingleClick(const MouseEventWithH itTestResults& event) 123 bool SelectionController::handleMousePressEventSingleClick(const MouseEventWithH itTestResults& event)
124 { 124 {
125 TRACE_EVENT0("blink", "SelectionController::handleMousePressEventSingleClick "); 125 TRACE_EVENT0("blink", "SelectionController::handleMousePressEventSingleClick ");
126 126
127 DCHECK(!m_frame->document()->needsLayoutTreeUpdate()); 127 DCHECK(!m_frame->document()->needsLayoutTreeUpdate());
128 Node* innerNode = event.innerNode(); 128 Node* innerNode = event.innerNode();
129 if (!(innerNode && innerNode->layoutObject() && m_mouseDownMayStartSelect)) 129 if (!(innerNode && innerNode->layoutObject() && m_mouseDownMayStartSelect))
130 return false; 130 return false;
131 131
132 // Extend the selection if the Shift key is down, unless the click is in a l ink or image. 132 // Extend the selection if the Shift key is down, unless the click is in a l ink or image.
133 bool extendSelection = isExtendingSelection(event); 133 bool extendSelection = isExtendingSelection(event);
134 134
135 // Don't restart the selection when the mouse is pressed on an 135 // Don't restart the selection when the mouse is pressed on an
136 // existing selection so we can allow for text dragging. 136 // existing selection so we can allow for text dragging.
137 if (FrameView* view = m_frame->view()) { 137 if (FrameView* view = m_frame->view()) {
138 LayoutPoint vPoint = view->rootFrameToContents(event.event().position()) ; 138 LayoutPoint vPoint = view->rootFrameToContents(event.event().position()) ;
139 if (!extendSelection && selection().contains(vPoint)) { 139 if (!extendSelection && selection().contains(vPoint)) {
140 m_mouseDownWasSingleClickInSelection = true; 140 m_mouseDownWasSingleClickInSelection = true;
141 return false; 141 return false;
142 } 142 }
143 } 143 }
144 144
145 VisiblePositionInFlatTree visiblePos = visiblePositionOfHitTestResult(event. hitTestResult()); 145 VisiblePositionInFlatTree visiblePos = visiblePositionOfHitTestResult(event. hitTestResult());
146 if (visiblePos.isNull()) 146 if (visiblePos.isNull())
147 visiblePos = createVisiblePositionDeprecated(PositionInFlatTree::firstPo sitionInOrBeforeNode(innerNode)); 147 visiblePos = createVisiblePosition(PositionInFlatTree::firstPositionInOr BeforeNode(innerNode));
148 PositionInFlatTree pos = visiblePos.deepEquivalent(); 148 PositionInFlatTree pos = visiblePos.deepEquivalent();
149 149
150 VisibleSelectionInFlatTree newSelection = selection().visibleSelection<Editi ngInFlatTreeStrategy>(); 150 VisibleSelectionInFlatTree newSelection = selection().visibleSelection<Editi ngInFlatTreeStrategy>();
151 TextGranularity granularity = CharacterGranularity; 151 TextGranularity granularity = CharacterGranularity;
152 152
153 if (extendSelection && !newSelection.isNone()) { 153 if (extendSelection && !newSelection.isNone()) {
154 const VisibleSelectionInFlatTree selectionInUserSelectAll(expandSelectio nToRespectUserSelectAll(innerNode, VisibleSelectionInFlatTree(createVisiblePosit ionDeprecated(pos)))); 154 const VisibleSelectionInFlatTree selectionInUserSelectAll(expandSelectio nToRespectUserSelectAll(innerNode, VisibleSelectionInFlatTree(createVisiblePosit ion(pos))));
155 if (selectionInUserSelectAll.isRange()) { 155 if (selectionInUserSelectAll.isRange()) {
156 if (selectionInUserSelectAll.start().compareTo(newSelection.start()) < 0) 156 if (selectionInUserSelectAll.start().compareTo(newSelection.start()) < 0)
157 pos = selectionInUserSelectAll.start(); 157 pos = selectionInUserSelectAll.start();
158 else if (newSelection.end().compareTo(selectionInUserSelectAll.end() ) < 0) 158 else if (newSelection.end().compareTo(selectionInUserSelectAll.end() ) < 0)
159 pos = selectionInUserSelectAll.end(); 159 pos = selectionInUserSelectAll.end();
160 } 160 }
161 161
162 if (!m_frame->editor().behavior().shouldConsiderSelectionAsDirectional() ) { 162 if (!m_frame->editor().behavior().shouldConsiderSelectionAsDirectional() ) {
163 if (pos.isNotNull()) { 163 if (pos.isNotNull()) {
164 // See <rdar://problem/3668157> REGRESSION (Mail): shift-click 164 // See <rdar://problem/3668157> REGRESSION (Mail): shift-click
(...skipping 26 matching lines...) Expand all
191 191
192 void SelectionController::updateSelectionForMouseDrag(const HitTestResult& hitTe stResult, Node* mousePressNode, const LayoutPoint& dragStartPos, const IntPoint& lastKnownMousePosition) 192 void SelectionController::updateSelectionForMouseDrag(const HitTestResult& hitTe stResult, Node* mousePressNode, const LayoutPoint& dragStartPos, const IntPoint& lastKnownMousePosition)
193 { 193 {
194 if (!m_mouseDownMayStartSelect) 194 if (!m_mouseDownMayStartSelect)
195 return; 195 return;
196 196
197 Node* target = hitTestResult.innerNode(); 197 Node* target = hitTestResult.innerNode();
198 if (!target) 198 if (!target)
199 return; 199 return;
200 200
201 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
202 // needs to be audited. See http://crbug.com/590369 for more details.
203 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets();
204
201 const PositionWithAffinity& rawTargetPosition = positionRespectingEditingBou ndary(selection().selection().start(), hitTestResult.localPoint(), target); 205 const PositionWithAffinity& rawTargetPosition = positionRespectingEditingBou ndary(selection().selection().start(), hitTestResult.localPoint(), target);
202 VisiblePositionInFlatTree targetPosition = createVisiblePositionDeprecated(f romPositionInDOMTree<EditingInFlatTreeStrategy>(rawTargetPosition)); 206 VisiblePositionInFlatTree targetPosition = createVisiblePosition(fromPositio nInDOMTree<EditingInFlatTreeStrategy>(rawTargetPosition));
203 // Don't modify the selection if we're not on a node. 207 // Don't modify the selection if we're not on a node.
204 if (targetPosition.isNull()) 208 if (targetPosition.isNull())
205 return; 209 return;
206 210
207 // Restart the selection if this is the first mouse move. This work is usual ly 211 // Restart the selection if this is the first mouse move. This work is usual ly
208 // done in handleMousePressEvent, but not if the mouse press was on an exist ing selection. 212 // done in handleMousePressEvent, but not if the mouse press was on an exist ing selection.
209 VisibleSelectionInFlatTree newSelection = selection().visibleSelection<Editi ngInFlatTreeStrategy>(); 213 VisibleSelectionInFlatTree newSelection = selection().visibleSelection<Editi ngInFlatTreeStrategy>();
210 214
211 // Special case to limit selection to the containing block for SVG text. 215 // Special case to limit selection to the containing block for SVG text.
212 // FIXME: Isn't there a better non-SVG-specific way to do this? 216 // FIXME: Isn't there a better non-SVG-specific way to do this?
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 bool handled = false; 514 bool handled = false;
511 m_mouseDownMayStartSelect = false; 515 m_mouseDownMayStartSelect = false;
512 // Clear the selection if the mouse didn't move after the last mouse 516 // Clear the selection if the mouse didn't move after the last mouse
513 // press and it's not a context menu click. We do this so when clicking 517 // press and it's not a context menu click. We do this so when clicking
514 // on the selection, the selection goes away. However, if we are 518 // on the selection, the selection goes away. However, if we are
515 // editing, place the caret. 519 // editing, place the caret.
516 if (m_mouseDownWasSingleClickInSelection && m_selectionState != SelectionSta te::ExtendedSelection 520 if (m_mouseDownWasSingleClickInSelection && m_selectionState != SelectionSta te::ExtendedSelection
517 && dragStartPos == event.event().position() 521 && dragStartPos == event.event().position()
518 && selection().isRange() 522 && selection().isRange()
519 && event.event().pointerProperties().button != WebPointerProperties::But ton::Right) { 523 && event.event().pointerProperties().button != WebPointerProperties::But ton::Right) {
524 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesh eets
525 // needs to be audited. See http://crbug.com/590369 for more details.
526 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets();
527
520 VisibleSelectionInFlatTree newSelection; 528 VisibleSelectionInFlatTree newSelection;
521 Node* node = event.innerNode(); 529 Node* node = event.innerNode();
522 bool caretBrowsing = m_frame->settings() && m_frame->settings()->caretBr owsingEnabled(); 530 bool caretBrowsing = m_frame->settings() && m_frame->settings()->caretBr owsingEnabled();
523 if (node && node->layoutObject() && (caretBrowsing || hasEditableStyle(* node))) { 531 if (node && node->layoutObject() && (caretBrowsing || hasEditableStyle(* node))) {
524 const VisiblePositionInFlatTree pos = visiblePositionOfHitTestResult (event.hitTestResult()); 532 const VisiblePositionInFlatTree pos = visiblePositionOfHitTestResult (event.hitTestResult());
525 newSelection = VisibleSelectionInFlatTree(pos); 533 newSelection = VisibleSelectionInFlatTree(pos);
526 } 534 }
527 535
528 setSelectionIfNeeded(selection(), newSelection); 536 setSelectionIfNeeded(selection(), newSelection);
529 537
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 void SelectionController::passMousePressEventToSubframe(const MouseEventWithHitT estResults& mev) 630 void SelectionController::passMousePressEventToSubframe(const MouseEventWithHitT estResults& mev)
623 { 631 {
624 // If we're clicking into a frame that is selected, the frame will appear 632 // If we're clicking into a frame that is selected, the frame will appear
625 // greyed out even though we're clicking on the selection. This looks 633 // greyed out even though we're clicking on the selection. This looks
626 // really strange (having the whole frame be greyed out), so we deselect the 634 // really strange (having the whole frame be greyed out), so we deselect the
627 // selection. 635 // selection.
628 IntPoint p = m_frame->view()->rootFrameToContents(mev.event().position()); 636 IntPoint p = m_frame->view()->rootFrameToContents(mev.event().position());
629 if (!selection().contains(p)) 637 if (!selection().contains(p))
630 return; 638 return;
631 639
640 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
641 // needs to be audited. See http://crbug.com/590369 for more details.
642 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets();
643
632 const VisiblePositionInFlatTree& visiblePos = visiblePositionOfHitTestResult (mev.hitTestResult()); 644 const VisiblePositionInFlatTree& visiblePos = visiblePositionOfHitTestResult (mev.hitTestResult());
633 VisibleSelectionInFlatTree newSelection(visiblePos); 645 VisibleSelectionInFlatTree newSelection(visiblePos);
634 selection().setSelection(newSelection); 646 selection().setSelection(newSelection);
635 } 647 }
636 648
637 void SelectionController::initializeSelectionState() 649 void SelectionController::initializeSelectionState()
638 { 650 {
639 m_selectionState = SelectionState::HaveNotStartedSelection; 651 m_selectionState = SelectionState::HaveNotStartedSelection;
640 } 652 }
641 653
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 return event.event().altKey() && event.isOverLink(); 686 return event.event().altKey() && event.isOverLink();
675 } 687 }
676 688
677 bool isExtendingSelection(const MouseEventWithHitTestResults& event) 689 bool isExtendingSelection(const MouseEventWithHitTestResults& event)
678 { 690 {
679 bool isMouseDownOnLinkOrImage = event.isOverLink() || event.hitTestResult(). image(); 691 bool isMouseDownOnLinkOrImage = event.isOverLink() || event.hitTestResult(). image();
680 return event.event().shiftKey() && !isMouseDownOnLinkOrImage; 692 return event.event().shiftKey() && !isMouseDownOnLinkOrImage;
681 } 693 }
682 694
683 } // namespace blink 695 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698