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

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

Issue 1191253002: Templatize handleMousePressEventSingleClick in SelectionController (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-06-19T17:58:51 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 | « Source/core/editing/SelectionController.h ('k') | 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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 return updateSelectionForMouseDownDispatchingSelectStart(innerNode, expandSe lectionToRespectUserSelectAll(innerNode, newSelection), ParagraphGranularity); 243 return updateSelectionForMouseDownDispatchingSelectStart(innerNode, expandSe lectionToRespectUserSelectAll(innerNode, newSelection), ParagraphGranularity);
244 } 244 }
245 245
246 static int textDistance(const Position& start, const Position& end) 246 static int textDistance(const Position& start, const Position& end)
247 { 247 {
248 return TextIterator::rangeLength(start, end, true); 248 return TextIterator::rangeLength(start, end, true);
249 } 249 }
250 250
251 bool SelectionController::handleMousePressEventSingleClick(const MouseEventWithH itTestResults& event) 251 bool SelectionController::handleMousePressEventSingleClick(const MouseEventWithH itTestResults& event)
252 { 252 {
253 return handleMousePressEventSingleClickAlgorithm<VisibleSelection::InDOMTree >(event);
254 }
255
256 template <typename Strategy>
257 bool SelectionController::handleMousePressEventSingleClickAlgorithm(const MouseE ventWithHitTestResults& event)
258 {
253 TRACE_EVENT0("blink", "SelectionController::handleMousePressEventSingleClick "); 259 TRACE_EVENT0("blink", "SelectionController::handleMousePressEventSingleClick ");
260 using PositionType = typename Strategy::PositionType;
254 261
255 m_frame->document()->updateLayoutIgnorePendingStylesheets(); 262 m_frame->document()->updateLayoutIgnorePendingStylesheets();
256 Node* innerNode = event.innerNode(); 263 Node* innerNode = event.innerNode();
257 if (!(innerNode && innerNode->layoutObject() && m_mouseDownMayStartSelect)) 264 if (!(innerNode && innerNode->layoutObject() && m_mouseDownMayStartSelect))
258 return false; 265 return false;
259 266
260 // Extend the selection if the Shift key is down, unless the click is in a l ink. 267 // Extend the selection if the Shift key is down, unless the click is in a l ink.
261 bool extendSelection = event.event().shiftKey() && !event.isOverLink(); 268 bool extendSelection = event.event().shiftKey() && !event.isOverLink();
262 269
263 // Don't restart the selection when the mouse is pressed on an 270 // Don't restart the selection when the mouse is pressed on an
264 // existing selection so we can allow for text dragging. 271 // existing selection so we can allow for text dragging.
265 if (FrameView* view = m_frame->view()) { 272 if (FrameView* view = m_frame->view()) {
266 LayoutPoint vPoint = view->rootFrameToContents(event.event().position()) ; 273 LayoutPoint vPoint = view->rootFrameToContents(event.event().position()) ;
267 if (!extendSelection && m_frame->selection().contains(vPoint)) { 274 if (!extendSelection && m_frame->selection().contains(vPoint)) {
268 m_mouseDownWasSingleClickInSelection = true; 275 m_mouseDownWasSingleClickInSelection = true;
269 return false; 276 return false;
270 } 277 }
271 } 278 }
272 279
273 VisiblePosition visiblePos(innerNode->layoutObject()->positionForPoint(event .localPoint())); 280 VisiblePosition visiblePos(innerNode->layoutObject()->positionForPoint(event .localPoint()));
274 if (visiblePos.isNull()) 281 if (visiblePos.isNull())
275 visiblePos = VisiblePosition(firstPositionInOrBeforeNode(innerNode), DOW NSTREAM); 282 visiblePos = VisiblePosition(firstPositionInOrBeforeNode(innerNode), DOW NSTREAM);
276 Position pos = visiblePos.deepEquivalent(); 283 PositionType pos = Strategy::toPositionType(visiblePos.deepEquivalent());
277 284
278 VisibleSelection newSelection = m_frame->selection().selection(); 285 VisibleSelection newSelection = m_frame->selection().selection();
279 TextGranularity granularity = CharacterGranularity; 286 TextGranularity granularity = CharacterGranularity;
280 287
281 if (extendSelection && newSelection.isCaretOrRange()) { 288 if (extendSelection && newSelection.isCaretOrRange()) {
282 VisibleSelection selectionInUserSelectAll(expandSelectionToRespectUserSe lectAll(innerNode, VisibleSelection(VisiblePosition(pos)))); 289 VisibleSelection selectionInUserSelectAll(expandSelectionToRespectUserSe lectAll(innerNode, VisibleSelection(VisiblePosition(pos))));
283 if (selectionInUserSelectAll.isRange()) { 290 if (selectionInUserSelectAll.isRange()) {
284 if (comparePositions(selectionInUserSelectAll.start(), newSelection. start()) < 0) 291 if (Strategy::selectionStart(selectionInUserSelectAll).compareTo(Str ategy::selectionStart(newSelection)) < 0)
285 pos = selectionInUserSelectAll.start(); 292 pos = Strategy::selectionStart(selectionInUserSelectAll);
286 else if (comparePositions(newSelection.end(), selectionInUserSelectA ll.end()) < 0) 293 else if (Strategy::selectionEnd(newSelection).compareTo(Strategy::se lectionEnd(selectionInUserSelectAll)) < 0)
287 pos = selectionInUserSelectAll.end(); 294 pos = Strategy::selectionEnd(selectionInUserSelectAll);
288 } 295 }
289 296
290 if (!m_frame->editor().behavior().shouldConsiderSelectionAsDirectional() ) { 297 if (!m_frame->editor().behavior().shouldConsiderSelectionAsDirectional() ) {
291 if (pos.isNotNull()) { 298 if (pos.isNotNull()) {
292 // See <rdar://problem/3668157> REGRESSION (Mail): shift-click d eselects when selection 299 // See <rdar://problem/3668157> REGRESSION (Mail): shift-click d eselects when selection
293 // was created right-to-left 300 // was created right-to-left
294 Position start = newSelection.start(); 301 PositionType start = Strategy::selectionStart(newSelection);
295 Position end = newSelection.end(); 302 PositionType end = Strategy::selectionEnd(newSelection);
296 int distanceToStart = textDistance(start, pos); 303 int distanceToStart = textDistance(start, pos);
297 int distanceToEnd = textDistance(pos, end); 304 int distanceToEnd = textDistance(pos, end);
298 if (distanceToStart <= distanceToEnd) 305 if (distanceToStart <= distanceToEnd)
299 newSelection = VisibleSelection(end, pos); 306 newSelection = VisibleSelection(end, pos);
300 else 307 else
301 newSelection = VisibleSelection(start, pos); 308 newSelection = VisibleSelection(start, pos);
302 } 309 }
303 } else { 310 } else {
304 newSelection.setExtent(pos); 311 newSelection.setExtent(pos);
305 } 312 }
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 { 588 {
582 return m_mouseDownMayStartSelect; 589 return m_mouseDownMayStartSelect;
583 } 590 }
584 591
585 bool SelectionController::mouseDownWasSingleClickInSelection() const 592 bool SelectionController::mouseDownWasSingleClickInSelection() const
586 { 593 {
587 return m_mouseDownWasSingleClickInSelection; 594 return m_mouseDownWasSingleClickInSelection;
588 } 595 }
589 596
590 } // namespace blink 597 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/editing/SelectionController.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698