| 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 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 return prev_box->BidiLevel() > inline_box->BidiLevel(); | 748 return prev_box->BidiLevel() > inline_box->BidiLevel(); |
| 749 } | 749 } |
| 750 | 750 |
| 751 // TODO(yosin): We have a forward declaration here to reduce patch size. We'll | 751 // TODO(yosin): We have a forward declaration here to reduce patch size. We'll |
| 752 // replice this with an implementation once review finished. | 752 // replice this with an implementation once review finished. |
| 753 static InlineBoxPosition AdjustInlineBoxPositionForTextDirection(InlineBox*, | 753 static InlineBoxPosition AdjustInlineBoxPositionForTextDirection(InlineBox*, |
| 754 int, | 754 int, |
| 755 UnicodeBidi, | 755 UnicodeBidi, |
| 756 TextDirection); | 756 TextDirection); |
| 757 | 757 |
| 758 // Returns true if |caret_offset| is at edge of |box| based on |affinity|. |
| 759 // |caret_offset| must be either |box.CaretMinOffset()| or |
| 760 // |box.CaretMaxOffset()|. |
| 761 static bool IsCaretAtEdgeOfInlineTextBox(int caret_offset, |
| 762 const InlineTextBox& box, |
| 763 TextAffinity affinity) { |
| 764 if (caret_offset == box.CaretMinOffset()) |
| 765 return affinity == TextAffinity::kDownstream; |
| 766 DCHECK_EQ(caret_offset, box.CaretMaxOffset()); |
| 767 if (affinity == TextAffinity::kUpstream) |
| 768 return true; |
| 769 return box.NextLeafChild() && box.NextLeafChild()->IsLineBreak(); |
| 770 } |
| 771 |
| 758 template <typename Strategy> | 772 template <typename Strategy> |
| 759 static InlineBoxPosition ComputeInlineBoxPositionTemplate( | 773 static InlineBoxPosition ComputeInlineBoxPositionTemplate( |
| 760 const PositionTemplate<Strategy>& position, | 774 const PositionTemplate<Strategy>& position, |
| 761 TextAffinity affinity, | 775 TextAffinity affinity, |
| 762 TextDirection primary_direction) { | 776 TextDirection primary_direction) { |
| 763 InlineBox* inline_box = nullptr; | 777 InlineBox* inline_box = nullptr; |
| 764 int caret_offset = position.ComputeEditingOffset(); | 778 int caret_offset = position.ComputeEditingOffset(); |
| 765 Node* const anchor_node = position.AnchorNode(); | 779 Node* const anchor_node = position.AnchorNode(); |
| 766 LayoutObject* layout_object = | 780 LayoutObject* layout_object = |
| 767 anchor_node->IsShadowRoot() | 781 anchor_node->IsShadowRoot() |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 int caret_min_offset = box->CaretMinOffset(); | 824 int caret_min_offset = box->CaretMinOffset(); |
| 811 int caret_max_offset = box->CaretMaxOffset(); | 825 int caret_max_offset = box->CaretMaxOffset(); |
| 812 | 826 |
| 813 if (caret_offset < caret_min_offset || caret_offset > caret_max_offset || | 827 if (caret_offset < caret_min_offset || caret_offset > caret_max_offset || |
| 814 (caret_offset == caret_max_offset && box->IsLineBreak())) | 828 (caret_offset == caret_max_offset && box->IsLineBreak())) |
| 815 continue; | 829 continue; |
| 816 | 830 |
| 817 if (caret_offset > caret_min_offset && caret_offset < caret_max_offset) | 831 if (caret_offset > caret_min_offset && caret_offset < caret_max_offset) |
| 818 return InlineBoxPosition(box, caret_offset); | 832 return InlineBoxPosition(box, caret_offset); |
| 819 | 833 |
| 820 if (((caret_offset == caret_max_offset) ^ | 834 if (IsCaretAtEdgeOfInlineTextBox(caret_offset, *box, affinity)) { |
| 821 (affinity == TextAffinity::kDownstream)) || | |
| 822 ((caret_offset == caret_min_offset) ^ | |
| 823 (affinity == TextAffinity::kUpstream)) || | |
| 824 (caret_offset == caret_max_offset && box->NextLeafChild() && | |
| 825 box->NextLeafChild()->IsLineBreak())) { | |
| 826 inline_box = box; | 835 inline_box = box; |
| 827 break; | 836 break; |
| 828 } | 837 } |
| 829 | 838 |
| 830 candidate = box; | 839 candidate = box; |
| 831 } | 840 } |
| 832 if (candidate && candidate == text_layout_object->LastTextBox() && | 841 if (candidate && candidate == text_layout_object->LastTextBox() && |
| 833 affinity == TextAffinity::kDownstream) { | 842 affinity == TextAffinity::kDownstream) { |
| 834 inline_box = SearchAheadForBetterMatch(text_layout_object); | 843 inline_box = SearchAheadForBetterMatch(text_layout_object); |
| 835 if (inline_box) | 844 if (inline_box) |
| (...skipping 1226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2062 | 2071 |
| 2063 IntRect ComputeTextRect(const EphemeralRangeInFlatTree& range) { | 2072 IntRect ComputeTextRect(const EphemeralRangeInFlatTree& range) { |
| 2064 return EnclosingIntRect(ComputeTextRectTemplate(range)); | 2073 return EnclosingIntRect(ComputeTextRectTemplate(range)); |
| 2065 } | 2074 } |
| 2066 | 2075 |
| 2067 FloatRect ComputeTextFloatRect(const EphemeralRange& range) { | 2076 FloatRect ComputeTextFloatRect(const EphemeralRange& range) { |
| 2068 return ComputeTextRectTemplate(range); | 2077 return ComputeTextRectTemplate(range); |
| 2069 } | 2078 } |
| 2070 | 2079 |
| 2071 } // namespace blink | 2080 } // namespace blink |
| OLD | NEW |