| 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 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 const InlineTextBox& box, | 763 const InlineTextBox& box, |
| 764 TextAffinity affinity) { | 764 TextAffinity affinity) { |
| 765 if (caret_offset == box.CaretMinOffset()) | 765 if (caret_offset == box.CaretMinOffset()) |
| 766 return affinity == TextAffinity::kDownstream; | 766 return affinity == TextAffinity::kDownstream; |
| 767 DCHECK_EQ(caret_offset, box.CaretMaxOffset()); | 767 DCHECK_EQ(caret_offset, box.CaretMaxOffset()); |
| 768 if (affinity == TextAffinity::kUpstream) | 768 if (affinity == TextAffinity::kUpstream) |
| 769 return true; | 769 return true; |
| 770 return box.NextLeafChild() && box.NextLeafChild()->IsLineBreak(); | 770 return box.NextLeafChild() && box.NextLeafChild()->IsLineBreak(); |
| 771 } | 771 } |
| 772 | 772 |
| 773 // TODO(yosin): We have a forward declaration here to reduce patch size. We'll | 773 static InlineBoxPosition ComputeInlineBoxPositionForTextNode( |
| 774 // replace this with an implementation once review finished. | 774 LayoutObject* layout_object, |
| 775 static InlineBoxPosition ComputeInlineBoxPositionForTextNode(LayoutObject*, | 775 int caret_offset, |
| 776 int caret_offset, | 776 TextAffinity affinity, |
| 777 TextAffinity, | 777 TextDirection primary_direction) { |
| 778 TextDirection); | 778 InlineBox* inline_box = nullptr; |
| 779 LayoutText* text_layout_object = ToLayoutText(layout_object); |
| 780 |
| 781 InlineTextBox* candidate = nullptr; |
| 782 |
| 783 for (InlineTextBox* box : InlineTextBoxesOf(*text_layout_object)) { |
| 784 int caret_min_offset = box->CaretMinOffset(); |
| 785 int caret_max_offset = box->CaretMaxOffset(); |
| 786 |
| 787 if (caret_offset < caret_min_offset || caret_offset > caret_max_offset || |
| 788 (caret_offset == caret_max_offset && box->IsLineBreak())) |
| 789 continue; |
| 790 |
| 791 if (caret_offset > caret_min_offset && caret_offset < caret_max_offset) |
| 792 return InlineBoxPosition(box, caret_offset); |
| 793 |
| 794 if (IsCaretAtEdgeOfInlineTextBox(caret_offset, *box, affinity)) { |
| 795 inline_box = box; |
| 796 break; |
| 797 } |
| 798 |
| 799 candidate = box; |
| 800 } |
| 801 if (candidate && candidate == text_layout_object->LastTextBox() && |
| 802 affinity == TextAffinity::kDownstream) { |
| 803 inline_box = SearchAheadForBetterMatch(text_layout_object); |
| 804 if (inline_box) |
| 805 caret_offset = inline_box->CaretMinOffset(); |
| 806 } |
| 807 if (!inline_box) |
| 808 inline_box = candidate; |
| 809 |
| 810 if (!inline_box) |
| 811 return InlineBoxPosition(); |
| 812 return AdjustInlineBoxPositionForTextDirection( |
| 813 inline_box, caret_offset, layout_object->Style()->GetUnicodeBidi(), |
| 814 primary_direction); |
| 815 } |
| 779 | 816 |
| 780 template <typename Strategy> | 817 template <typename Strategy> |
| 781 static InlineBoxPosition ComputeInlineBoxPositionTemplate( | 818 static InlineBoxPosition ComputeInlineBoxPositionTemplate( |
| 782 const PositionTemplate<Strategy>& position, | 819 const PositionTemplate<Strategy>& position, |
| 783 TextAffinity affinity, | 820 TextAffinity affinity, |
| 784 TextDirection primary_direction) { | 821 TextDirection primary_direction) { |
| 785 int caret_offset = position.ComputeEditingOffset(); | 822 int caret_offset = position.ComputeEditingOffset(); |
| 786 Node* const anchor_node = position.AnchorNode(); | 823 Node* const anchor_node = position.AnchorNode(); |
| 787 LayoutObject* layout_object = | 824 LayoutObject* layout_object = |
| 788 anchor_node->IsShadowRoot() | 825 anchor_node->IsShadowRoot() |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 return InlineBoxPosition(inline_box, caret_offset); | 863 return InlineBoxPosition(inline_box, caret_offset); |
| 827 return AdjustInlineBoxPositionForTextDirection( | 864 return AdjustInlineBoxPositionForTextDirection( |
| 828 inline_box, caret_offset, layout_object->Style()->GetUnicodeBidi(), | 865 inline_box, caret_offset, layout_object->Style()->GetUnicodeBidi(), |
| 829 primary_direction); | 866 primary_direction); |
| 830 } | 867 } |
| 831 | 868 |
| 832 return ComputeInlineBoxPositionForTextNode(layout_object, caret_offset, | 869 return ComputeInlineBoxPositionForTextNode(layout_object, caret_offset, |
| 833 affinity, primary_direction); | 870 affinity, primary_direction); |
| 834 } | 871 } |
| 835 | 872 |
| 836 // TODO(yosin): We should make |ComputeInlineBoxPositionForTextNode()| to take | |
| 837 // |const LayoutText&|. | |
| 838 static InlineBoxPosition ComputeInlineBoxPositionForTextNode( | |
| 839 LayoutObject* layout_object, | |
| 840 int caret_offset, | |
| 841 TextAffinity affinity, | |
| 842 TextDirection primary_direction) { | |
| 843 InlineBox* inline_box = nullptr; | |
| 844 LayoutText* text_layout_object = ToLayoutText(layout_object); | |
| 845 | |
| 846 InlineTextBox* candidate = nullptr; | |
| 847 | |
| 848 for (InlineTextBox* box : InlineTextBoxesOf(*text_layout_object)) { | |
| 849 int caret_min_offset = box->CaretMinOffset(); | |
| 850 int caret_max_offset = box->CaretMaxOffset(); | |
| 851 | |
| 852 if (caret_offset < caret_min_offset || caret_offset > caret_max_offset || | |
| 853 (caret_offset == caret_max_offset && box->IsLineBreak())) | |
| 854 continue; | |
| 855 | |
| 856 if (caret_offset > caret_min_offset && caret_offset < caret_max_offset) | |
| 857 return InlineBoxPosition(box, caret_offset); | |
| 858 | |
| 859 if (IsCaretAtEdgeOfInlineTextBox(caret_offset, *box, affinity)) { | |
| 860 inline_box = box; | |
| 861 break; | |
| 862 } | |
| 863 | |
| 864 candidate = box; | |
| 865 } | |
| 866 if (candidate && candidate == text_layout_object->LastTextBox() && | |
| 867 affinity == TextAffinity::kDownstream) { | |
| 868 inline_box = SearchAheadForBetterMatch(text_layout_object); | |
| 869 if (inline_box) | |
| 870 caret_offset = inline_box->CaretMinOffset(); | |
| 871 } | |
| 872 if (!inline_box) | |
| 873 inline_box = candidate; | |
| 874 | |
| 875 if (!inline_box) | |
| 876 return InlineBoxPosition(); | |
| 877 return AdjustInlineBoxPositionForTextDirection( | |
| 878 inline_box, caret_offset, layout_object->Style()->GetUnicodeBidi(), | |
| 879 primary_direction); | |
| 880 } | |
| 881 | |
| 882 static InlineBoxPosition AdjustInlineBoxPositionForTextDirection( | 873 static InlineBoxPosition AdjustInlineBoxPositionForTextDirection( |
| 883 InlineBox* inline_box, | 874 InlineBox* inline_box, |
| 884 int caret_offset, | 875 int caret_offset, |
| 885 UnicodeBidi unicode_bidi, | 876 UnicodeBidi unicode_bidi, |
| 886 TextDirection primary_direction) { | 877 TextDirection primary_direction) { |
| 887 unsigned char level = inline_box->BidiLevel(); | 878 unsigned char level = inline_box->BidiLevel(); |
| 888 | 879 |
| 889 if (inline_box->Direction() == primary_direction) { | 880 if (inline_box->Direction() == primary_direction) { |
| 890 if (caret_offset == inline_box->CaretRightmostOffset()) { | 881 if (caret_offset == inline_box->CaretRightmostOffset()) { |
| 891 InlineBox* next_box = inline_box->NextLeafChild(); | 882 InlineBox* next_box = inline_box->NextLeafChild(); |
| (...skipping 1189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2081 | 2072 |
| 2082 IntRect ComputeTextRect(const EphemeralRangeInFlatTree& range) { | 2073 IntRect ComputeTextRect(const EphemeralRangeInFlatTree& range) { |
| 2083 return EnclosingIntRect(ComputeTextRectTemplate(range)); | 2074 return EnclosingIntRect(ComputeTextRectTemplate(range)); |
| 2084 } | 2075 } |
| 2085 | 2076 |
| 2086 FloatRect ComputeTextFloatRect(const EphemeralRange& range) { | 2077 FloatRect ComputeTextFloatRect(const EphemeralRange& range) { |
| 2087 return ComputeTextRectTemplate(range); | 2078 return ComputeTextRectTemplate(range); |
| 2088 } | 2079 } |
| 2089 | 2080 |
| 2090 } // namespace blink | 2081 } // namespace blink |
| OLD | NEW |