Chromium Code Reviews| 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 2628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2639 // This assertion fires in layout tests in the case-transform.html test | 2639 // This assertion fires in layout tests in the case-transform.html test |
| 2640 // because of a mix-up between offsets in the text in the DOM tree with | 2640 // because of a mix-up between offsets in the text in the DOM tree with |
| 2641 // text in the layout tree which can have a different length due to case | 2641 // text in the layout tree which can have a different length due to case |
| 2642 // transformation. | 2642 // transformation. |
| 2643 // Until we resolve that, disable this so we can run the layout tests! | 2643 // Until we resolve that, disable this so we can run the layout tests! |
| 2644 // DCHECK_GE(currentOffset, layoutObject->caretMaxOffset()); | 2644 // DCHECK_GE(currentOffset, layoutObject->caretMaxOffset()); |
| 2645 return PositionTemplate<Strategy>( | 2645 return PositionTemplate<Strategy>( |
| 2646 current_node, layout_object->CaretMaxOffset() + text_start_offset); | 2646 current_node, layout_object->CaretMaxOffset() + text_start_offset); |
| 2647 } | 2647 } |
| 2648 | 2648 |
| 2649 // Map offset in DOM node to offset in InlineBox. | 2649 if (CanBackwardCaretPosition(text_layout_object, |
| 2650 DCHECK_GE(current_pos.OffsetInLeafNode(), | 2650 current_pos.OffsetInLeafNode())) { |
| 2651 static_cast<int>(text_start_offset)); | 2651 return current_pos.ComputePosition(); |
| 2652 const unsigned text_offset = | |
| 2653 current_pos.OffsetInLeafNode() - text_start_offset; | |
| 2654 InlineTextBox* last_text_box = text_layout_object->LastTextBox(); | |
| 2655 for (InlineTextBox* box = text_layout_object->FirstTextBox(); box; | |
| 2656 box = box->NextTextBox()) { | |
| 2657 if (text_offset == box->Start()) { | |
| 2658 if (text_layout_object->IsTextFragment() && | |
| 2659 ToLayoutTextFragment(layout_object) | |
| 2660 ->IsRemainingTextLayoutObject()) { | |
| 2661 // |currentPos| is at start of remaining text of | |
| 2662 // |Text| node with :first-letter. | |
| 2663 DCHECK_GE(current_pos.OffsetInLeafNode(), 1); | |
| 2664 LayoutObject* first_letter_layout_object = | |
| 2665 ToLayoutTextFragment(layout_object) | |
| 2666 ->GetFirstLetterPseudoElement() | |
| 2667 ->GetLayoutObject(); | |
| 2668 if (first_letter_layout_object && | |
| 2669 first_letter_layout_object->Style()->Visibility() == | |
| 2670 EVisibility::kVisible) | |
| 2671 return current_pos.ComputePosition(); | |
| 2672 } | |
| 2673 continue; | |
| 2674 } | |
| 2675 if (text_offset <= box->Start() + box->Len()) { | |
| 2676 if (text_offset > box->Start()) | |
| 2677 return current_pos.ComputePosition(); | |
| 2678 continue; | |
| 2679 } | |
| 2680 | |
| 2681 if (box == last_text_box || | |
| 2682 text_offset != box->Start() + box->Len() + 1) | |
| 2683 continue; | |
| 2684 | |
| 2685 // The text continues on the next line only if the last text box is not | |
| 2686 // on this line and none of the boxes on this line have a larger start | |
| 2687 // offset. | |
| 2688 | |
| 2689 bool continues_on_next_line = true; | |
| 2690 InlineBox* other_box = box; | |
| 2691 while (continues_on_next_line) { | |
| 2692 other_box = other_box->NextLeafChild(); | |
| 2693 if (!other_box) | |
| 2694 break; | |
| 2695 if (other_box == last_text_box || | |
| 2696 (LineLayoutAPIShim::LayoutObjectFrom( | |
| 2697 other_box->GetLineLayoutItem()) == text_layout_object && | |
| 2698 ToInlineTextBox(other_box)->Start() > text_offset)) | |
| 2699 continues_on_next_line = false; | |
| 2700 } | |
| 2701 | |
| 2702 other_box = box; | |
| 2703 while (continues_on_next_line) { | |
| 2704 other_box = other_box->PrevLeafChild(); | |
| 2705 if (!other_box) | |
| 2706 break; | |
| 2707 if (other_box == last_text_box || | |
| 2708 (LineLayoutAPIShim::LayoutObjectFrom( | |
| 2709 other_box->GetLineLayoutItem()) == text_layout_object && | |
| 2710 ToInlineTextBox(other_box)->Start() > text_offset)) | |
| 2711 continues_on_next_line = false; | |
| 2712 } | |
| 2713 | |
| 2714 if (continues_on_next_line) | |
| 2715 return current_pos.ComputePosition(); | |
| 2716 } | 2652 } |
| 2717 } | 2653 } |
| 2718 } | 2654 } |
| 2719 return last_visible.DeprecatedComputePosition(); | 2655 return last_visible.DeprecatedComputePosition(); |
| 2720 } | 2656 } |
| 2721 | 2657 |
| 2658 // TODO(editing-dev): This function is just moved out from | |
| 2659 // |MostBackwardCaretPosition()|. We should study this function more and | |
| 2660 // name it appropriately. See https://trac.webkit.org/changeset/32438/ | |
| 2661 // which introduce this. | |
| 2662 static bool CanBackwardCaretPosition(const LayoutText* text_layout_object, | |
|
Xiaocheng
2017/06/05 19:36:37
nit: |CanBeBackwardCaretPosition| seems a better n
yosin_UTC9
2017/06/06 04:48:52
Done. Thanks for providing good name.
| |
| 2663 int offset_in_node) { | |
| 2664 const unsigned text_start_offset = text_layout_object->TextStartOffset(); | |
| 2665 DCHECK_GE(offset_in_node, static_cast<int>(text_start_offset)); | |
| 2666 const unsigned text_offset = offset_in_node - text_start_offset; | |
| 2667 InlineTextBox* const last_text_box = text_layout_object->LastTextBox(); | |
| 2668 for (InlineTextBox* box = text_layout_object->FirstTextBox(); box; | |
| 2669 box = box->NextTextBox()) { | |
| 2670 if (text_offset == box->Start()) { | |
| 2671 if (text_layout_object->IsTextFragment() && | |
| 2672 ToLayoutTextFragment(text_layout_object) | |
| 2673 ->IsRemainingTextLayoutObject()) { | |
| 2674 // |offset_in_node| is at start of remaining text of | |
| 2675 // |Text| node with :first-letter. | |
| 2676 DCHECK_GE(offset_in_node, 1); | |
| 2677 LayoutObject* first_letter_layout_object = | |
| 2678 ToLayoutTextFragment(text_layout_object) | |
| 2679 ->GetFirstLetterPseudoElement() | |
| 2680 ->GetLayoutObject(); | |
| 2681 if (first_letter_layout_object && | |
| 2682 first_letter_layout_object->Style()->Visibility() == | |
| 2683 EVisibility::kVisible) | |
| 2684 return true; | |
| 2685 } | |
| 2686 continue; | |
| 2687 } | |
| 2688 if (text_offset <= box->Start() + box->Len()) { | |
| 2689 if (text_offset > box->Start()) | |
| 2690 return true; | |
| 2691 continue; | |
| 2692 } | |
| 2693 | |
| 2694 if (box == last_text_box || text_offset != box->Start() + box->Len() + 1) | |
| 2695 continue; | |
| 2696 | |
| 2697 // TODO(yosin): We should move below code fragment into | |
| 2698 // |DoesContinueOnNextLine()|. Note: |MostForwardCaretPosition()| has | |
| 2699 // same code fragment except for comparison on |text_offset|. | |
| 2700 // Backward: other_box->Start() > text_offset | |
| 2701 // Forward: other_box->Start() >= text_offset | |
| 2702 // The text continues on the next line only if the last text box is not | |
| 2703 // on this line and none of the boxes on this line have a larger start | |
| 2704 // offset. | |
| 2705 bool continues_on_next_line = true; | |
| 2706 InlineBox* other_box = box; | |
| 2707 while (continues_on_next_line) { | |
| 2708 other_box = other_box->NextLeafChild(); | |
| 2709 if (!other_box) | |
| 2710 break; | |
| 2711 if (other_box == last_text_box || | |
| 2712 (LineLayoutAPIShim::LayoutObjectFrom( | |
| 2713 other_box->GetLineLayoutItem()) == text_layout_object && | |
| 2714 ToInlineTextBox(other_box)->Start() > text_offset)) | |
| 2715 continues_on_next_line = false; | |
| 2716 } | |
| 2717 | |
| 2718 other_box = box; | |
| 2719 while (continues_on_next_line) { | |
| 2720 other_box = other_box->PrevLeafChild(); | |
| 2721 if (!other_box) | |
| 2722 break; | |
| 2723 if (other_box == last_text_box || | |
| 2724 (LineLayoutAPIShim::LayoutObjectFrom( | |
| 2725 other_box->GetLineLayoutItem()) == text_layout_object && | |
| 2726 ToInlineTextBox(other_box)->Start() > text_offset)) | |
| 2727 continues_on_next_line = false; | |
| 2728 } | |
| 2729 | |
| 2730 if (continues_on_next_line) | |
| 2731 return true; | |
| 2732 } | |
| 2733 return false; | |
| 2734 } | |
| 2735 | |
| 2722 Position MostBackwardCaretPosition(const Position& position, | 2736 Position MostBackwardCaretPosition(const Position& position, |
| 2723 EditingBoundaryCrossingRule rule) { | 2737 EditingBoundaryCrossingRule rule) { |
| 2724 return MostBackwardCaretPosition<EditingStrategy>(position, rule); | 2738 return MostBackwardCaretPosition<EditingStrategy>(position, rule); |
| 2725 } | 2739 } |
| 2726 | 2740 |
| 2727 PositionInFlatTree MostBackwardCaretPosition(const PositionInFlatTree& position, | 2741 PositionInFlatTree MostBackwardCaretPosition(const PositionInFlatTree& position, |
| 2728 EditingBoundaryCrossingRule rule) { | 2742 EditingBoundaryCrossingRule rule) { |
| 2729 return MostBackwardCaretPosition<EditingInFlatTreeStrategy>(position, rule); | 2743 return MostBackwardCaretPosition<EditingInFlatTreeStrategy>(position, rule); |
| 2730 } | 2744 } |
| 2731 | 2745 |
| (...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3756 | 3770 |
| 3757 IntRect ComputeTextRect(const EphemeralRangeInFlatTree& range) { | 3771 IntRect ComputeTextRect(const EphemeralRangeInFlatTree& range) { |
| 3758 return EnclosingIntRect(ComputeTextRectTemplate(range)); | 3772 return EnclosingIntRect(ComputeTextRectTemplate(range)); |
| 3759 } | 3773 } |
| 3760 | 3774 |
| 3761 FloatRect ComputeTextFloatRect(const EphemeralRange& range) { | 3775 FloatRect ComputeTextFloatRect(const EphemeralRange& range) { |
| 3762 return ComputeTextRectTemplate(range); | 3776 return ComputeTextRectTemplate(range); |
| 3763 } | 3777 } |
| 3764 | 3778 |
| 3765 } // namespace blink | 3779 } // namespace blink |
| OLD | NEW |