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

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

Issue 2920583003: Stop crashing when VisibleSelections in DOM and Flat trees are inconsistent (Closed)
Patch Set: Mon Jun 5 11:40:52 PDT 2017 Created 3 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 | third_party/WebKit/Source/core/editing/FrameSelectionTest.cpp » ('j') | 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) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 granularity_ = kCharacterGranularity; 422 granularity_ = kCharacterGranularity;
423 if (granularity_strategy_) 423 if (granularity_strategy_)
424 granularity_strategy_->Clear(); 424 granularity_strategy_->Clear();
425 SetSelection(SelectionInDOMTree()); 425 SetSelection(SelectionInDOMTree());
426 } 426 }
427 427
428 bool FrameSelection::SelectionHasFocus() const { 428 bool FrameSelection::SelectionHasFocus() const {
429 // TODO(editing-dev): Hoist UpdateStyleAndLayoutIgnorePendingStylesheets 429 // TODO(editing-dev): Hoist UpdateStyleAndLayoutIgnorePendingStylesheets
430 // to caller. See http://crbug.com/590369 for more details. 430 // to caller. See http://crbug.com/590369 for more details.
431 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets(); 431 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets();
432 if (ComputeVisibleSelectionInFlatTree().IsNone())
433 return false;
432 const Node* current = 434 const Node* current =
433 ComputeVisibleSelectionInDOMTree().Start().ComputeContainerNode(); 435 ComputeVisibleSelectionInFlatTree().Start().ComputeContainerNode();
434 if (!current) 436 if (!current)
435 return false; 437 return false;
436 438
437 // No focused element means document root has focus. 439 // No focused element means document root has focus.
438 Element* const focused_element = GetDocument().FocusedElement() 440 Element* const focused_element = GetDocument().FocusedElement()
439 ? GetDocument().FocusedElement() 441 ? GetDocument().FocusedElement()
440 : GetDocument().documentElement(); 442 : GetDocument().documentElement();
441 if (!focused_element) 443 if (!focused_element)
442 return false; 444 return false;
443 445
444 if (focused_element->IsTextControl()) 446 if (focused_element->IsTextControl())
445 return focused_element->ContainsIncludingHostElements(*current); 447 return focused_element->ContainsIncludingHostElements(*current);
446 448
447 if (ComputeVisibleSelectionInFlatTree().IsNone()) {
448 // TODO(editing-dev): We should avoid any case where VSInFlatTree is none
449 // but VSInDOMTree is not none.
450 DLOG(FATAL) << ComputeVisibleSelectionInDOMTree();
451 }
452
453 // Selection has focus if it contains the focused element. 449 // Selection has focus if it contains the focused element.
454 const PositionInFlatTree& focused_position = 450 const PositionInFlatTree& focused_position =
455 PositionInFlatTree::FirstPositionInNode(focused_element); 451 PositionInFlatTree::FirstPositionInNode(focused_element);
456 if (ComputeVisibleSelectionInFlatTree().Start() <= focused_position && 452 if (ComputeVisibleSelectionInFlatTree().Start() <= focused_position &&
457 ComputeVisibleSelectionInFlatTree().End() >= focused_position) 453 ComputeVisibleSelectionInFlatTree().End() >= focused_position)
458 return true; 454 return true;
459 455
460 bool has_editable_style = HasEditableStyle(*current); 456 bool has_editable_style = HasEditableStyle(*current);
461 do { 457 do {
462 // If the selection is within an editable sub tree and that sub tree 458 // If the selection is within an editable sub tree and that sub tree
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 } 1182 }
1187 1183
1188 void showTree(const blink::FrameSelection* sel) { 1184 void showTree(const blink::FrameSelection* sel) {
1189 if (sel) 1185 if (sel)
1190 sel->ShowTreeForThis(); 1186 sel->ShowTreeForThis();
1191 else 1187 else
1192 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; 1188 LOG(INFO) << "Cannot showTree for <null> FrameSelection.";
1193 } 1189 }
1194 1190
1195 #endif 1191 #endif
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/FrameSelectionTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698