| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights |
| 3 * reserved. | 3 * reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 } | 314 } |
| 315 | 315 |
| 316 VisiblePositionInFlatTree LogicalStartOfLine( | 316 VisiblePositionInFlatTree LogicalStartOfLine( |
| 317 const VisiblePositionInFlatTree& current_position) { | 317 const VisiblePositionInFlatTree& current_position) { |
| 318 DCHECK(current_position.IsValid()) << current_position; | 318 DCHECK(current_position.IsValid()) << current_position; |
| 319 return CreateVisiblePosition( | 319 return CreateVisiblePosition( |
| 320 LogicalStartOfLineAlgorithm<EditingInFlatTreeStrategy>( | 320 LogicalStartOfLineAlgorithm<EditingInFlatTreeStrategy>( |
| 321 current_position.ToPositionWithAffinity())); | 321 current_position.ToPositionWithAffinity())); |
| 322 } | 322 } |
| 323 | 323 |
| 324 InlineBox* FindLeftNonPseudoNodeInlineBox(const RootInlineBox& root_box) { |
| 325 for (InlineBox* runner = root_box.LastLeafChild(); runner; |
| 326 runner = runner->PrevLeafChild()) { |
| 327 if (runner->GetLineLayoutItem().NonPseudoNode()) |
| 328 return runner; |
| 329 } |
| 330 return nullptr; |
| 331 } |
| 332 |
| 324 template <typename Strategy> | 333 template <typename Strategy> |
| 325 static VisiblePositionTemplate<Strategy> EndPositionForLine( | 334 static VisiblePositionTemplate<Strategy> EndPositionForLine( |
| 326 const VisiblePositionTemplate<Strategy>& c, | 335 const VisiblePositionTemplate<Strategy>& c, |
| 327 LineEndpointComputationMode mode) { | 336 LineEndpointComputationMode mode) { |
| 328 DCHECK(c.IsValid()) << c; | 337 DCHECK(c.IsValid()) << c; |
| 329 if (c.IsNull()) | 338 if (c.IsNull()) |
| 330 return VisiblePositionTemplate<Strategy>(); | 339 return VisiblePositionTemplate<Strategy>(); |
| 331 | 340 |
| 332 RootInlineBox* root_box = RenderedPosition(c).RootBox(); | 341 RootInlineBox* root_box = RenderedPosition(c).RootBox(); |
| 333 if (!root_box) { | 342 if (!root_box) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 344 Node* end_node; | 353 Node* end_node; |
| 345 InlineBox* end_box; | 354 InlineBox* end_box; |
| 346 if (mode == kUseLogicalOrdering) { | 355 if (mode == kUseLogicalOrdering) { |
| 347 end_node = root_box->GetLogicalEndBoxWithNode(end_box); | 356 end_node = root_box->GetLogicalEndBoxWithNode(end_box); |
| 348 if (!end_node) | 357 if (!end_node) |
| 349 return VisiblePositionTemplate<Strategy>(); | 358 return VisiblePositionTemplate<Strategy>(); |
| 350 } else { | 359 } else { |
| 351 // Generated content (e.g. list markers and CSS :before and :after | 360 // Generated content (e.g. list markers and CSS :before and :after |
| 352 // pseudo elements) have no corresponding DOM element, and so cannot be | 361 // pseudo elements) have no corresponding DOM element, and so cannot be |
| 353 // represented by a VisiblePosition. Use whatever precedes instead. | 362 // represented by a VisiblePosition. Use whatever precedes instead. |
| 354 end_box = root_box->LastLeafChild(); | 363 // TODO(editing-dev): We should consider text-direction of line to |
| 355 while (true) { | 364 // find non-pseudo node. |
| 356 if (!end_box) | 365 end_box = FindLeftNonPseudoNodeInlineBox(*root_box); |
| 357 return VisiblePositionTemplate<Strategy>(); | 366 if (!end_box) |
| 358 | 367 return VisiblePositionTemplate<Strategy>(); |
| 359 end_node = end_box->GetLineLayoutItem().NonPseudoNode(); | 368 end_node = end_box->GetLineLayoutItem().NonPseudoNode(); |
| 360 if (end_node) | |
| 361 break; | |
| 362 | |
| 363 end_box = end_box->PrevLeafChild(); | |
| 364 } | |
| 365 } | 369 } |
| 366 | 370 |
| 367 PositionTemplate<Strategy> pos; | 371 PositionTemplate<Strategy> pos; |
| 368 if (isHTMLBRElement(*end_node)) { | 372 if (isHTMLBRElement(*end_node)) { |
| 369 pos = PositionTemplate<Strategy>::BeforeNode(end_node); | 373 pos = PositionTemplate<Strategy>::BeforeNode(end_node); |
| 370 } else if (end_box->IsInlineTextBox() && end_node->IsTextNode()) { | 374 } else if (end_box->IsInlineTextBox() && end_node->IsTextNode()) { |
| 371 InlineTextBox* end_text_box = ToInlineTextBox(end_box); | 375 InlineTextBox* end_text_box = ToInlineTextBox(end_box); |
| 372 int end_offset = end_text_box->Start(); | 376 int end_offset = end_text_box->Start(); |
| 373 if (!end_text_box->IsLineBreak()) | 377 if (!end_text_box->IsLineBreak()) |
| 374 end_offset += end_text_box->Len(); | 378 end_offset += end_text_box->Len(); |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 // to the end of the line we're on. | 684 // to the end of the line we're on. |
| 681 Element* root_element = HasEditableStyle(*node, editable_type) | 685 Element* root_element = HasEditableStyle(*node, editable_type) |
| 682 ? RootEditableElement(*node, editable_type) | 686 ? RootEditableElement(*node, editable_type) |
| 683 : node->GetDocument().documentElement(); | 687 : node->GetDocument().documentElement(); |
| 684 if (!root_element) | 688 if (!root_element) |
| 685 return VisiblePosition(); | 689 return VisiblePosition(); |
| 686 return VisiblePosition::LastPositionInNode(root_element); | 690 return VisiblePosition::LastPositionInNode(root_element); |
| 687 } | 691 } |
| 688 | 692 |
| 689 } // namespace blink | 693 } // namespace blink |
| OLD | NEW |