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

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

Issue 1189243002: Introduce expandSelectionUsingGranularity() in SelectionController (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-06-19T13:30:25 Rebase Created 5 years, 6 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 newSelection.setExtent(PositionType::afterNode(rootUserSelectAll).downstream (CanCrossEditingBoundary)); 92 newSelection.setExtent(PositionType::afterNode(rootUserSelectAll).downstream (CanCrossEditingBoundary));
93 93
94 return newSelection; 94 return newSelection;
95 } 95 }
96 96
97 static VisibleSelection expandSelectionToRespectUserSelectAll(Node* targetNode, const VisibleSelection& selection) 97 static VisibleSelection expandSelectionToRespectUserSelectAll(Node* targetNode, const VisibleSelection& selection)
98 { 98 {
99 return expandSelectionToRespectUserSelectAllAlgorithm<VisibleSelection::InDO MTree>(targetNode, selection); 99 return expandSelectionToRespectUserSelectAllAlgorithm<VisibleSelection::InDO MTree>(targetNode, selection);
100 } 100 }
101 101
102 static bool expandSelectionUsingGranularity(VisibleSelection& selection, TextGra nularity granularity)
103 {
104 return selection.expandUsingGranularity(granularity);
105 }
106
102 bool SelectionController::updateSelectionForMouseDownDispatchingSelectStart(Node * targetNode, const VisibleSelection& selection, TextGranularity granularity) 107 bool SelectionController::updateSelectionForMouseDownDispatchingSelectStart(Node * targetNode, const VisibleSelection& selection, TextGranularity granularity)
103 { 108 {
104 if (Position::nodeIsUserSelectNone(targetNode)) 109 if (Position::nodeIsUserSelectNone(targetNode))
105 return false; 110 return false;
106 111
107 if (!dispatchSelectStart(targetNode)) 112 if (!dispatchSelectStart(targetNode))
108 return false; 113 return false;
109 114
110 if (selection.isRange()) { 115 if (selection.isRange()) {
111 m_selectionInitiationState = ExtendedSelection; 116 m_selectionInitiationState = ExtendedSelection;
112 } else { 117 } else {
113 granularity = CharacterGranularity; 118 granularity = CharacterGranularity;
114 m_selectionInitiationState = PlacedCaret; 119 m_selectionInitiationState = PlacedCaret;
115 } 120 }
116 121
117 m_frame->selection().setNonDirectionalSelectionIfNeeded(selection, granulari ty); 122 m_frame->selection().setNonDirectionalSelectionIfNeeded(selection, granulari ty);
118 123
119 return true; 124 return true;
120 } 125 }
121 126
122 void SelectionController::selectClosestWordFromHitTestResult(const HitTestResult & result, AppendTrailingWhitespace appendTrailingWhitespace) 127 void SelectionController::selectClosestWordFromHitTestResult(const HitTestResult & result, AppendTrailingWhitespace appendTrailingWhitespace)
123 { 128 {
124 Node* innerNode = result.innerNode(); 129 Node* innerNode = result.innerNode();
125 VisibleSelection newSelection; 130 VisibleSelection newSelection;
126 131
127 if (innerNode && innerNode->layoutObject()) { 132 if (innerNode && innerNode->layoutObject()) {
128 VisiblePosition pos(innerNode->layoutObject()->positionForPoint(result.l ocalPoint())); 133 VisiblePosition pos(innerNode->layoutObject()->positionForPoint(result.l ocalPoint()));
129 if (pos.isNotNull()) { 134 if (pos.isNotNull()) {
130 newSelection = VisibleSelection(pos); 135 newSelection = VisibleSelection(pos);
131 newSelection.expandUsingGranularity(WordGranularity); 136 expandSelectionUsingGranularity(newSelection, WordGranularity);
132 } 137 }
133 138
134 if (appendTrailingWhitespace == ShouldAppendTrailingWhitespace && newSel ection.isRange()) 139 if (appendTrailingWhitespace == ShouldAppendTrailingWhitespace && newSel ection.isRange())
135 newSelection.appendTrailingWhitespace(); 140 newSelection.appendTrailingWhitespace();
136 141
137 updateSelectionForMouseDownDispatchingSelectStart(innerNode, expandSelec tionToRespectUserSelectAll(innerNode, newSelection), WordGranularity); 142 updateSelectionForMouseDownDispatchingSelectStart(innerNode, expandSelec tionToRespectUserSelectAll(innerNode, newSelection), WordGranularity);
138 } 143 }
139 } 144 }
140 145
141 void SelectionController::selectClosestMisspellingFromHitTestResult(const HitTes tResult& result, AppendTrailingWhitespace appendTrailingWhitespace) 146 void SelectionController::selectClosestMisspellingFromHitTestResult(const HitTes tResult& result, AppendTrailingWhitespace appendTrailingWhitespace)
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 return false; 230 return false;
226 231
227 Node* innerNode = event.innerNode(); 232 Node* innerNode = event.innerNode();
228 if (!(innerNode && innerNode->layoutObject() && m_mouseDownMayStartSelect)) 233 if (!(innerNode && innerNode->layoutObject() && m_mouseDownMayStartSelect))
229 return false; 234 return false;
230 235
231 VisibleSelection newSelection; 236 VisibleSelection newSelection;
232 VisiblePosition pos(innerNode->layoutObject()->positionForPoint(event.localP oint())); 237 VisiblePosition pos(innerNode->layoutObject()->positionForPoint(event.localP oint()));
233 if (pos.isNotNull()) { 238 if (pos.isNotNull()) {
234 newSelection = VisibleSelection(pos); 239 newSelection = VisibleSelection(pos);
235 newSelection.expandUsingGranularity(ParagraphGranularity); 240 expandSelectionUsingGranularity(newSelection, ParagraphGranularity);
236 } 241 }
237 242
238 return updateSelectionForMouseDownDispatchingSelectStart(innerNode, expandSe lectionToRespectUserSelectAll(innerNode, newSelection), ParagraphGranularity); 243 return updateSelectionForMouseDownDispatchingSelectStart(innerNode, expandSe lectionToRespectUserSelectAll(innerNode, newSelection), ParagraphGranularity);
239 } 244 }
240 245
241 static int textDistance(const Position& start, const Position& end) 246 static int textDistance(const Position& start, const Position& end)
242 { 247 {
243 RefPtrWillBeRawPtr<Range> range = Range::create(*start.document(), start, en d); 248 RefPtrWillBeRawPtr<Range> range = Range::create(*start.document(), start, en d);
244 return TextIterator::rangeLength(range->startPosition(), range->endPosition( ), true); 249 return TextIterator::rangeLength(range->startPosition(), range->endPosition( ), true);
245 } 250 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 newSelection = VisibleSelection(end, pos); 300 newSelection = VisibleSelection(end, pos);
296 else 301 else
297 newSelection = VisibleSelection(start, pos); 302 newSelection = VisibleSelection(start, pos);
298 } 303 }
299 } else { 304 } else {
300 newSelection.setExtent(pos); 305 newSelection.setExtent(pos);
301 } 306 }
302 307
303 if (m_frame->selection().granularity() != CharacterGranularity) { 308 if (m_frame->selection().granularity() != CharacterGranularity) {
304 granularity = m_frame->selection().granularity(); 309 granularity = m_frame->selection().granularity();
305 newSelection.expandUsingGranularity(m_frame->selection().granularity ()); 310 expandSelectionUsingGranularity(newSelection, m_frame->selection().g ranularity());
306 } 311 }
307 } else { 312 } else {
308 newSelection = expandSelectionToRespectUserSelectAll(innerNode, VisibleS election(visiblePos)); 313 newSelection = expandSelectionToRespectUserSelectAll(innerNode, VisibleS election(visiblePos));
309 } 314 }
310 315
311 // Updating the selection is considered side-effect of the event and so it d oesn't impact the handled state. 316 // Updating the selection is considered side-effect of the event and so it d oesn't impact the handled state.
312 updateSelectionForMouseDownDispatchingSelectStart(innerNode, newSelection, g ranularity); 317 updateSelectionForMouseDownDispatchingSelectStart(innerNode, newSelection, g ranularity);
313 return false; 318 return false;
314 } 319 }
315 320
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 else if (rootUserSelectAllForTarget && mousePressNode->layoutObject( )) 418 else if (rootUserSelectAllForTarget && mousePressNode->layoutObject( ))
414 newSelection.setExtent(positionAfterNode(rootUserSelectAllForTar get).downstream(CanCrossEditingBoundary)); 419 newSelection.setExtent(positionAfterNode(rootUserSelectAllForTar get).downstream(CanCrossEditingBoundary));
415 else 420 else
416 newSelection.setExtent(targetPosition); 421 newSelection.setExtent(targetPosition);
417 } 422 }
418 } else { 423 } else {
419 newSelection.setExtent(targetPosition); 424 newSelection.setExtent(targetPosition);
420 } 425 }
421 426
422 if (m_frame->selection().granularity() != CharacterGranularity) 427 if (m_frame->selection().granularity() != CharacterGranularity)
423 newSelection.expandUsingGranularity(m_frame->selection().granularity()); 428 expandSelectionUsingGranularity(newSelection, m_frame->selection().granu larity());
424 429
425 m_frame->selection().setNonDirectionalSelectionIfNeeded(newSelection, m_fram e->selection().granularity(), 430 m_frame->selection().setNonDirectionalSelectionIfNeeded(newSelection, m_fram e->selection().granularity(),
426 FrameSelection::AdjustEndpointsAtBidiBoundary); 431 FrameSelection::AdjustEndpointsAtBidiBoundary);
427 } 432 }
428 433
429 bool SelectionController::handleMouseReleaseEvent(const MouseEventWithHitTestRes ults& event, const LayoutPoint& dragStartPos) 434 bool SelectionController::handleMouseReleaseEvent(const MouseEventWithHitTestRes ults& event, const LayoutPoint& dragStartPos)
430 { 435 {
431 bool handled = false; 436 bool handled = false;
432 m_mouseDownMayStartSelect = false; 437 m_mouseDownMayStartSelect = false;
433 // Clear the selection if the mouse didn't move after the last mouse 438 // Clear the selection if the mouse didn't move after the last mouse
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 { 570 {
566 return m_mouseDownMayStartSelect; 571 return m_mouseDownMayStartSelect;
567 } 572 }
568 573
569 bool SelectionController::mouseDownWasSingleClickInSelection() const 574 bool SelectionController::mouseDownWasSingleClickInSelection() const
570 { 575 {
571 return m_mouseDownWasSingleClickInSelection; 576 return m_mouseDownWasSingleClickInSelection;
572 } 577 }
573 578
574 } // namespace blink 579 } // 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