| 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 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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 |
| OLD | NEW |