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

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

Issue 1288883002: Make SelectionController not to set invalid selection by mouse down (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-08-13T18:48:09 Created 5 years, 4 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 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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 if (selectionBaseLayoutObject->isSVGText()) { 231 if (selectionBaseLayoutObject->isSVGText()) {
232 if (target->layoutObject()->containingBlock() != selectionBaseLa youtObject->containingBlock()) 232 if (target->layoutObject()->containingBlock() != selectionBaseLa youtObject->containingBlock())
233 return; 233 return;
234 } 234 }
235 } 235 }
236 } 236 }
237 237
238 if (m_selectionState == SelectionState::HaveNotStartedSelection && !dispatch SelectStart(target)) 238 if (m_selectionState == SelectionState::HaveNotStartedSelection && !dispatch SelectStart(target))
239 return; 239 return;
240 240
241 // TODO(yosin) We should check |mousePressNode|, |targetPosition|, and
242 // |newSelection| are valid for |m_frame->document()|.
243 // |dispatchSelectStart()| can change them by "selectstart" event handler.
244
241 if (m_selectionState != SelectionState::ExtendedSelection) { 245 if (m_selectionState != SelectionState::ExtendedSelection) {
242 // Always extend selection here because it's caused by a mouse drag 246 // Always extend selection here because it's caused by a mouse drag
243 m_selectionState = SelectionState::ExtendedSelection; 247 m_selectionState = SelectionState::ExtendedSelection;
244 newSelection = VisibleSelection(targetPosition); 248 newSelection = VisibleSelection(targetPosition);
245 } 249 }
246 250
247 if (RuntimeEnabledFeatures::userSelectAllEnabled()) { 251 if (RuntimeEnabledFeatures::userSelectAllEnabled()) {
248 Node* rootUserSelectAllForMousePressNode = Position::rootUserSelectAllFo rNode(mousePressNode); 252 Node* rootUserSelectAllForMousePressNode = Position::rootUserSelectAllFo rNode(mousePressNode);
249 if (rootUserSelectAllForMousePressNode && rootUserSelectAllForMousePress Node == Position::rootUserSelectAllForNode(target)) { 253 if (rootUserSelectAllForMousePressNode && rootUserSelectAllForMousePress Node == Position::rootUserSelectAllForNode(target)) {
250 newSelection.setBase(PositionType::beforeNode(rootUserSelectAllForMo usePressNode).upstream(CanCrossEditingBoundary)); 254 newSelection.setBase(PositionType::beforeNode(rootUserSelectAllForMo usePressNode).upstream(CanCrossEditingBoundary));
(...skipping 27 matching lines...) Expand all
278 } 282 }
279 283
280 bool SelectionController::updateSelectionForMouseDownDispatchingSelectStart(Node * targetNode, const VisibleSelection& selection, TextGranularity granularity) 284 bool SelectionController::updateSelectionForMouseDownDispatchingSelectStart(Node * targetNode, const VisibleSelection& selection, TextGranularity granularity)
281 { 285 {
282 if (Position::nodeIsUserSelectNone(targetNode)) 286 if (Position::nodeIsUserSelectNone(targetNode))
283 return false; 287 return false;
284 288
285 if (!dispatchSelectStart(targetNode)) 289 if (!dispatchSelectStart(targetNode))
286 return false; 290 return false;
287 291
292 if (!selection.isValidFor(*m_frame->document()))
293 return false;
294
288 if (selection.isRange()) { 295 if (selection.isRange()) {
289 m_selectionState = SelectionState::ExtendedSelection; 296 m_selectionState = SelectionState::ExtendedSelection;
290 } else { 297 } else {
291 granularity = CharacterGranularity; 298 granularity = CharacterGranularity;
292 m_selectionState = SelectionState::PlacedCaret; 299 m_selectionState = SelectionState::PlacedCaret;
293 } 300 }
294 301
295 this->selection().setNonDirectionalSelectionIfNeeded(selection, granularity) ; 302 this->selection().setNonDirectionalSelectionIfNeeded(selection, granularity) ;
296 303
297 return true; 304 return true;
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 else 649 else
643 m_selectionState = SelectionState::HaveNotStartedSelection; 650 m_selectionState = SelectionState::HaveNotStartedSelection;
644 } 651 }
645 652
646 FrameSelection& SelectionController::selection() const 653 FrameSelection& SelectionController::selection() const
647 { 654 {
648 return m_frame->selection(); 655 return m_frame->selection();
649 } 656 }
650 657
651 } // namespace blink 658 } // namespace blink
OLDNEW
« no previous file with comments | « LayoutTests/editing/selection/selectstart-event-crash.html ('k') | Source/core/editing/VisibleSelection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698