| 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 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 static bool IsStartOfDifferentDirection(const InlineBox* inline_box) { | 742 static bool IsStartOfDifferentDirection(const InlineBox* inline_box) { |
| 743 InlineBox* prev_box = inline_box->PrevLeafChild(); | 743 InlineBox* prev_box = inline_box->PrevLeafChild(); |
| 744 if (!prev_box) | 744 if (!prev_box) |
| 745 return true; | 745 return true; |
| 746 if (prev_box->Direction() == inline_box->Direction()) | 746 if (prev_box->Direction() == inline_box->Direction()) |
| 747 return true; | 747 return true; |
| 748 DCHECK_NE(prev_box->BidiLevel(), inline_box->BidiLevel()); | 748 DCHECK_NE(prev_box->BidiLevel(), inline_box->BidiLevel()); |
| 749 return prev_box->BidiLevel() > inline_box->BidiLevel(); | 749 return prev_box->BidiLevel() > inline_box->BidiLevel(); |
| 750 } | 750 } |
| 751 | 751 |
| 752 static InlineBoxPosition AdjustInlineBoxPositionForPrimaryDirection( |
| 753 InlineBox* inline_box, |
| 754 int caret_offset) { |
| 755 if (caret_offset == inline_box->CaretRightmostOffset()) { |
| 756 InlineBox* const next_box = inline_box->NextLeafChild(); |
| 757 if (!next_box || next_box->BidiLevel() >= inline_box->BidiLevel()) |
| 758 return InlineBoxPosition(inline_box, caret_offset); |
| 759 |
| 760 const unsigned level = next_box->BidiLevel(); |
| 761 InlineBox* const prev_box = |
| 762 InlineBoxTraversal::FindLeftBidiRun(*inline_box, level); |
| 763 |
| 764 // For example, abc FED 123 ^ CBA |
| 765 if (prev_box && prev_box->BidiLevel() == level) |
| 766 return InlineBoxPosition(inline_box, caret_offset); |
| 767 |
| 768 // For example, abc 123 ^ CBA |
| 769 inline_box = InlineBoxTraversal::FindRightBoundaryOfEntireBidiRun( |
| 770 *inline_box, level); |
| 771 return InlineBoxPosition(inline_box, inline_box->CaretRightmostOffset()); |
| 772 } |
| 773 |
| 774 if (IsStartOfDifferentDirection(inline_box)) |
| 775 return InlineBoxPosition(inline_box, caret_offset); |
| 776 |
| 777 const unsigned level = inline_box->PrevLeafChild()->BidiLevel(); |
| 778 InlineBox* const next_box = |
| 779 InlineBoxTraversal::FindRightBidiRun(*inline_box, level); |
| 780 |
| 781 if (next_box && next_box->BidiLevel() == level) |
| 782 return InlineBoxPosition(inline_box, caret_offset); |
| 783 |
| 784 inline_box = |
| 785 InlineBoxTraversal::FindLeftBoundaryOfEntireBidiRun(*inline_box, level); |
| 786 return InlineBoxPosition(inline_box, inline_box->CaretLeftmostOffset()); |
| 787 } |
| 788 |
| 752 static InlineBoxPosition AdjustInlineBoxPositionForTextDirection( | 789 static InlineBoxPosition AdjustInlineBoxPositionForTextDirection( |
| 753 InlineBox* inline_box, | 790 InlineBox* inline_box, |
| 754 int caret_offset, | 791 int caret_offset, |
| 755 UnicodeBidi unicode_bidi, | 792 UnicodeBidi unicode_bidi, |
| 756 TextDirection primary_direction) { | 793 TextDirection primary_direction) { |
| 757 unsigned char level = inline_box->BidiLevel(); | 794 if (inline_box->Direction() == primary_direction) |
| 795 return AdjustInlineBoxPositionForPrimaryDirection(inline_box, caret_offset); |
| 758 | 796 |
| 759 if (inline_box->Direction() == primary_direction) { | 797 const unsigned char level = inline_box->BidiLevel(); |
| 760 if (caret_offset == inline_box->CaretRightmostOffset()) { | |
| 761 InlineBox* next_box = inline_box->NextLeafChild(); | |
| 762 if (!next_box || next_box->BidiLevel() >= level) | |
| 763 return InlineBoxPosition(inline_box, caret_offset); | |
| 764 | |
| 765 level = next_box->BidiLevel(); | |
| 766 InlineBox* const prev_box = | |
| 767 InlineBoxTraversal::FindLeftBidiRun(*inline_box, level); | |
| 768 | |
| 769 // For example, abc FED 123 ^ CBA | |
| 770 if (prev_box && prev_box->BidiLevel() == level) | |
| 771 return InlineBoxPosition(inline_box, caret_offset); | |
| 772 | |
| 773 // For example, abc 123 ^ CBA | |
| 774 inline_box = InlineBoxTraversal::FindRightBoundaryOfEntireBidiRun( | |
| 775 *inline_box, level); | |
| 776 return InlineBoxPosition(inline_box, inline_box->CaretRightmostOffset()); | |
| 777 } | |
| 778 | |
| 779 if (IsStartOfDifferentDirection(inline_box)) | |
| 780 return InlineBoxPosition(inline_box, caret_offset); | |
| 781 | |
| 782 level = inline_box->PrevLeafChild()->BidiLevel(); | |
| 783 InlineBox* const next_box = | |
| 784 InlineBoxTraversal::FindRightBidiRun(*inline_box, level); | |
| 785 | |
| 786 if (next_box && next_box->BidiLevel() == level) | |
| 787 return InlineBoxPosition(inline_box, caret_offset); | |
| 788 | |
| 789 inline_box = | |
| 790 InlineBoxTraversal::FindLeftBoundaryOfEntireBidiRun(*inline_box, level); | |
| 791 return InlineBoxPosition(inline_box, inline_box->CaretLeftmostOffset()); | |
| 792 } | |
| 793 | |
| 794 if (caret_offset == inline_box->CaretLeftmostOffset()) { | 798 if (caret_offset == inline_box->CaretLeftmostOffset()) { |
| 795 InlineBox* prev_box = inline_box->PrevLeafChildIgnoringLineBreak(); | 799 InlineBox* prev_box = inline_box->PrevLeafChildIgnoringLineBreak(); |
| 796 if (!prev_box || prev_box->BidiLevel() < level) { | 800 if (!prev_box || prev_box->BidiLevel() < level) { |
| 797 // Left edge of a secondary run. Set to the right edge of the entire | 801 // Left edge of a secondary run. Set to the right edge of the entire |
| 798 // run. | 802 // run. |
| 799 inline_box = | 803 inline_box = |
| 800 InlineBoxTraversal::FindRightBoundaryOfEntireBidiRunIgnoringLineBreak( | 804 InlineBoxTraversal::FindRightBoundaryOfEntireBidiRunIgnoringLineBreak( |
| 801 *inline_box, level); | 805 *inline_box, level); |
| 802 return InlineBoxPosition(inline_box, inline_box->CaretRightmostOffset()); | 806 return InlineBoxPosition(inline_box, inline_box->CaretRightmostOffset()); |
| 803 } | 807 } |
| (...skipping 1266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2070 | 2074 |
| 2071 IntRect ComputeTextRect(const EphemeralRangeInFlatTree& range) { | 2075 IntRect ComputeTextRect(const EphemeralRangeInFlatTree& range) { |
| 2072 return EnclosingIntRect(ComputeTextRectTemplate(range)); | 2076 return EnclosingIntRect(ComputeTextRectTemplate(range)); |
| 2073 } | 2077 } |
| 2074 | 2078 |
| 2075 FloatRect ComputeTextFloatRect(const EphemeralRange& range) { | 2079 FloatRect ComputeTextFloatRect(const EphemeralRange& range) { |
| 2076 return ComputeTextRectTemplate(range); | 2080 return ComputeTextRectTemplate(range); |
| 2077 } | 2081 } |
| 2078 | 2082 |
| 2079 } // namespace blink | 2083 } // namespace blink |
| OLD | NEW |