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

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

Issue 2900553005: Treat selection as focused if it contains focused element (Closed)
Patch Set: Mon May 22 18:52:27 PDT 2017 Created 3 years, 7 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 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 bool FrameSelection::SelectionHasFocus() const { 427 bool FrameSelection::SelectionHasFocus() const {
428 // TODO(editing-dev): Hoist UpdateStyleAndLayoutIgnorePendingStylesheets 428 // TODO(editing-dev): Hoist UpdateStyleAndLayoutIgnorePendingStylesheets
429 // to caller. See http://crbug.com/590369 for more details. 429 // to caller. See http://crbug.com/590369 for more details.
430 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets(); 430 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets();
431 const Node* current = 431 const Node* current =
432 ComputeVisibleSelectionInDOMTree().Start().ComputeContainerNode(); 432 ComputeVisibleSelectionInDOMTree().Start().ComputeContainerNode();
433 if (!current) 433 if (!current)
434 return false; 434 return false;
435 435
436 // No focused element means document root has focus. 436 // No focused element means document root has focus.
437 const Element* const focused_element = GetDocument().FocusedElement() 437 Element* const focused_element = GetDocument().FocusedElement()
438 ? GetDocument().FocusedElement() 438 ? GetDocument().FocusedElement()
439 : GetDocument().documentElement(); 439 : GetDocument().documentElement();
440 if (!focused_element) 440 if (!focused_element)
441 return false; 441 return false;
442 442
443 if (focused_element->IsTextControl()) 443 if (focused_element->IsTextControl())
444 return focused_element->ContainsIncludingHostElements(*current); 444 return focused_element->ContainsIncludingHostElements(*current);
445 445
446 // Selection has focus if it contains the focused element.
447 const PositionInFlatTree& focused_position =
448 PositionInFlatTree::FirstPositionInNode(focused_element);
449 if (ComputeVisibleSelectionInFlatTree().Start() <= focused_position &&
450 ComputeVisibleSelectionInFlatTree().end() >= focused_position)
451 return true;
452
446 bool has_editable_style = HasEditableStyle(*current); 453 bool has_editable_style = HasEditableStyle(*current);
447 do { 454 do {
448 // If the selection is within an editable sub tree and that sub tree 455 // If the selection is within an editable sub tree and that sub tree
449 // doesn't have focus, the selection doesn't have focus either. 456 // doesn't have focus, the selection doesn't have focus either.
450 if (has_editable_style && !HasEditableStyle(*current)) 457 if (has_editable_style && !HasEditableStyle(*current))
451 return false; 458 return false;
452 459
453 // Selection has focus if its sub tree has focus. 460 // Selection has focus if its sub tree has focus.
454 if (current == focused_element) 461 if (current == focused_element)
455 return true; 462 return true;
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 } 1190 }
1184 1191
1185 void showTree(const blink::FrameSelection* sel) { 1192 void showTree(const blink::FrameSelection* sel) {
1186 if (sel) 1193 if (sel)
1187 sel->ShowTreeForThis(); 1194 sel->ShowTreeForThis();
1188 else 1195 else
1189 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; 1196 LOG(INFO) << "Cannot showTree for <null> FrameSelection.";
1190 } 1197 }
1191 1198
1192 #endif 1199 #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