| 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 821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 affinity, primary_direction); | 832 affinity, primary_direction); |
| 833 } | 833 } |
| 834 | 834 |
| 835 // TODO(yosin): We should make |ComputeInlineBoxPositionForTextNode()| to take | 835 // TODO(yosin): We should make |ComputeInlineBoxPositionForTextNode()| to take |
| 836 // |const LayoutText&|. | 836 // |const LayoutText&|. |
| 837 static InlineBoxPosition ComputeInlineBoxPositionForTextNode( | 837 static InlineBoxPosition ComputeInlineBoxPositionForTextNode( |
| 838 LayoutObject* layout_object, | 838 LayoutObject* layout_object, |
| 839 int caret_offset, | 839 int caret_offset, |
| 840 TextAffinity affinity, | 840 TextAffinity affinity, |
| 841 TextDirection primary_direction) { | 841 TextDirection primary_direction) { |
| 842 // TODO(yosin): We should move this code fragment to another function to | |
| 843 // remove the scope. | |
| 844 InlineBox* inline_box = nullptr; | 842 InlineBox* inline_box = nullptr; |
| 845 { | 843 LayoutText* text_layout_object = ToLayoutText(layout_object); |
| 846 LayoutText* text_layout_object = ToLayoutText(layout_object); | |
| 847 | 844 |
| 848 InlineTextBox* candidate = nullptr; | 845 InlineTextBox* candidate = nullptr; |
| 849 | 846 |
| 850 for (InlineTextBox* box : InlineTextBoxesOf(*text_layout_object)) { | 847 for (InlineTextBox* box : InlineTextBoxesOf(*text_layout_object)) { |
| 851 int caret_min_offset = box->CaretMinOffset(); | 848 int caret_min_offset = box->CaretMinOffset(); |
| 852 int caret_max_offset = box->CaretMaxOffset(); | 849 int caret_max_offset = box->CaretMaxOffset(); |
| 853 | 850 |
| 854 if (caret_offset < caret_min_offset || caret_offset > caret_max_offset || | 851 if (caret_offset < caret_min_offset || caret_offset > caret_max_offset || |
| 855 (caret_offset == caret_max_offset && box->IsLineBreak())) | 852 (caret_offset == caret_max_offset && box->IsLineBreak())) |
| 856 continue; | 853 continue; |
| 857 | 854 |
| 858 if (caret_offset > caret_min_offset && caret_offset < caret_max_offset) | 855 if (caret_offset > caret_min_offset && caret_offset < caret_max_offset) |
| 859 return InlineBoxPosition(box, caret_offset); | 856 return InlineBoxPosition(box, caret_offset); |
| 860 | 857 |
| 861 if (IsCaretAtEdgeOfInlineTextBox(caret_offset, *box, affinity)) { | 858 if (IsCaretAtEdgeOfInlineTextBox(caret_offset, *box, affinity)) { |
| 862 inline_box = box; | 859 inline_box = box; |
| 863 break; | 860 break; |
| 864 } | 861 } |
| 865 | 862 |
| 866 candidate = box; | 863 candidate = box; |
| 867 } | |
| 868 if (candidate && candidate == text_layout_object->LastTextBox() && | |
| 869 affinity == TextAffinity::kDownstream) { | |
| 870 inline_box = SearchAheadForBetterMatch(text_layout_object); | |
| 871 if (inline_box) | |
| 872 caret_offset = inline_box->CaretMinOffset(); | |
| 873 } | |
| 874 if (!inline_box) | |
| 875 inline_box = candidate; | |
| 876 } | 864 } |
| 865 if (candidate && candidate == text_layout_object->LastTextBox() && |
| 866 affinity == TextAffinity::kDownstream) { |
| 867 inline_box = SearchAheadForBetterMatch(text_layout_object); |
| 868 if (inline_box) |
| 869 caret_offset = inline_box->CaretMinOffset(); |
| 870 } |
| 871 if (!inline_box) |
| 872 inline_box = candidate; |
| 877 | 873 |
| 878 if (!inline_box) | 874 if (!inline_box) |
| 879 return InlineBoxPosition(); | 875 return InlineBoxPosition(); |
| 880 return AdjustInlineBoxPositionForTextDirection( | 876 return AdjustInlineBoxPositionForTextDirection( |
| 881 inline_box, caret_offset, layout_object->Style()->GetUnicodeBidi(), | 877 inline_box, caret_offset, layout_object->Style()->GetUnicodeBidi(), |
| 882 primary_direction); | 878 primary_direction); |
| 883 } | 879 } |
| 884 | 880 |
| 885 static InlineBoxPosition AdjustInlineBoxPositionForTextDirection( | 881 static InlineBoxPosition AdjustInlineBoxPositionForTextDirection( |
| 886 InlineBox* inline_box, | 882 InlineBox* inline_box, |
| (...skipping 1215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2102 | 2098 |
| 2103 IntRect ComputeTextRect(const EphemeralRangeInFlatTree& range) { | 2099 IntRect ComputeTextRect(const EphemeralRangeInFlatTree& range) { |
| 2104 return EnclosingIntRect(ComputeTextRectTemplate(range)); | 2100 return EnclosingIntRect(ComputeTextRectTemplate(range)); |
| 2105 } | 2101 } |
| 2106 | 2102 |
| 2107 FloatRect ComputeTextFloatRect(const EphemeralRange& range) { | 2103 FloatRect ComputeTextFloatRect(const EphemeralRange& range) { |
| 2108 return ComputeTextRectTemplate(range); | 2104 return ComputeTextRectTemplate(range); |
| 2109 } | 2105 } |
| 2110 | 2106 |
| 2111 } // namespace blink | 2107 } // namespace blink |
| OLD | NEW |