Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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(focused_element, 0); | |
|
yosin_UTC9
2017/05/23 01:15:50
It is better to use PositionInFlatTree::FirstPosit
| |
| 448 if (ComputeVisibleSelectionInFlatTree().Start() <= focused_position && | |
| 449 ComputeVisibleSelectionInFlatTree().end() >= focused_position) | |
| 450 return true; | |
| 451 | |
| 446 bool has_editable_style = HasEditableStyle(*current); | 452 bool has_editable_style = HasEditableStyle(*current); |
| 447 do { | 453 do { |
| 448 // If the selection is within an editable sub tree and that sub tree | 454 // 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. | 455 // doesn't have focus, the selection doesn't have focus either. |
| 450 if (has_editable_style && !HasEditableStyle(*current)) | 456 if (has_editable_style && !HasEditableStyle(*current)) |
| 451 return false; | 457 return false; |
| 452 | 458 |
| 453 // Selection has focus if its sub tree has focus. | 459 // Selection has focus if its sub tree has focus. |
| 454 if (current == focused_element) | 460 if (current == focused_element) |
| 455 return true; | 461 return true; |
| (...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1183 } | 1189 } |
| 1184 | 1190 |
| 1185 void showTree(const blink::FrameSelection* sel) { | 1191 void showTree(const blink::FrameSelection* sel) { |
| 1186 if (sel) | 1192 if (sel) |
| 1187 sel->ShowTreeForThis(); | 1193 sel->ShowTreeForThis(); |
| 1188 else | 1194 else |
| 1189 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; | 1195 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; |
| 1190 } | 1196 } |
| 1191 | 1197 |
| 1192 #endif | 1198 #endif |
| OLD | NEW |