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 16 matching lines...) Expand all Loading... | |
| 27 #include "core/editing/VisibleUnits.h" | 27 #include "core/editing/VisibleUnits.h" |
| 28 | 28 |
| 29 #include "core/HTMLNames.h" | 29 #include "core/HTMLNames.h" |
| 30 #include "core/dom/Document.h" | 30 #include "core/dom/Document.h" |
| 31 #include "core/dom/Element.h" | 31 #include "core/dom/Element.h" |
| 32 #include "core/dom/FirstLetterPseudoElement.h" | 32 #include "core/dom/FirstLetterPseudoElement.h" |
| 33 #include "core/dom/NodeTraversal.h" | 33 #include "core/dom/NodeTraversal.h" |
| 34 #include "core/dom/Text.h" | 34 #include "core/dom/Text.h" |
| 35 #include "core/editing/EditingUtilities.h" | 35 #include "core/editing/EditingUtilities.h" |
| 36 #include "core/editing/FrameSelection.h" | 36 #include "core/editing/FrameSelection.h" |
| 37 #include "core/editing/InlineBoxTraversal.h" | |
| 37 #include "core/editing/Position.h" | 38 #include "core/editing/Position.h" |
| 38 #include "core/editing/PositionIterator.h" | 39 #include "core/editing/PositionIterator.h" |
| 39 #include "core/editing/RenderedPosition.h" | 40 #include "core/editing/RenderedPosition.h" |
| 40 #include "core/editing/TextAffinity.h" | 41 #include "core/editing/TextAffinity.h" |
| 41 #include "core/editing/VisiblePosition.h" | 42 #include "core/editing/VisiblePosition.h" |
| 42 #include "core/editing/iterators/BackwardsCharacterIterator.h" | 43 #include "core/editing/iterators/BackwardsCharacterIterator.h" |
| 43 #include "core/editing/iterators/BackwardsTextBuffer.h" | 44 #include "core/editing/iterators/BackwardsTextBuffer.h" |
| 44 #include "core/editing/iterators/CharacterIterator.h" | 45 #include "core/editing/iterators/CharacterIterator.h" |
| 45 #include "core/editing/iterators/ForwardsTextBuffer.h" | 46 #include "core/editing/iterators/ForwardsTextBuffer.h" |
| 46 #include "core/editing/iterators/SimplifiedBackwardsTextIterator.h" | 47 #include "core/editing/iterators/SimplifiedBackwardsTextIterator.h" |
| (...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 874 InlineBox* prev_box = inline_box; | 875 InlineBox* prev_box = inline_box; |
| 875 do { | 876 do { |
| 876 prev_box = prev_box->PrevLeafChild(); | 877 prev_box = prev_box->PrevLeafChild(); |
| 877 } while (prev_box && prev_box->BidiLevel() > level); | 878 } while (prev_box && prev_box->BidiLevel() > level); |
| 878 | 879 |
| 879 // For example, abc FED 123 ^ CBA | 880 // For example, abc FED 123 ^ CBA |
| 880 if (prev_box && prev_box->BidiLevel() == level) | 881 if (prev_box && prev_box->BidiLevel() == level) |
| 881 return InlineBoxPosition(inline_box, caret_offset); | 882 return InlineBoxPosition(inline_box, caret_offset); |
| 882 | 883 |
| 883 // For example, abc 123 ^ CBA | 884 // For example, abc 123 ^ CBA |
| 884 while (InlineBox* next_box = inline_box->NextLeafChild()) { | 885 inline_box = |
|
Xiaocheng
2017/06/15 01:11:48
The existing code is so bad that a loop variable a
yosin_UTC9
2017/06/15 03:42:14
FYI: MSVC has a compile option to detect multiple
| |
| 885 if (next_box->BidiLevel() < level) | 886 InlineBoxTraversal::FindRightBoundaryOfEntireBidiRun(*next_box); |
|
yosin_UTC9
2017/06/14 09:41:34
Because |level = next_box->BidiLevel()| at L874, w
Xiaocheng
2017/06/15 01:11:48
We should pass in |inline_box|, otherwise |next_bo
yosin_UTC9
2017/06/15 03:42:14
Add |level| parameter to |FindXXX()|. Once code cl
| |
| 886 break; | |
| 887 inline_box = next_box; | |
| 888 } | |
| 889 return InlineBoxPosition(inline_box, inline_box->CaretRightmostOffset()); | 887 return InlineBoxPosition(inline_box, inline_box->CaretRightmostOffset()); |
| 890 } | 888 } |
| 891 | 889 |
| 892 if (IsStartOfDifferentDirection(inline_box)) | 890 if (IsStartOfDifferentDirection(inline_box)) |
| 893 return InlineBoxPosition(inline_box, caret_offset); | 891 return InlineBoxPosition(inline_box, caret_offset); |
| 894 | 892 |
| 895 level = inline_box->PrevLeafChild()->BidiLevel(); | 893 level = inline_box->PrevLeafChild()->BidiLevel(); |
| 896 InlineBox* next_box = inline_box; | 894 InlineBox* next_box = inline_box; |
| 897 do { | 895 do { |
| 898 next_box = next_box->NextLeafChild(); | 896 next_box = next_box->NextLeafChild(); |
| 899 } while (next_box && next_box->BidiLevel() > level); | 897 } while (next_box && next_box->BidiLevel() > level); |
| 900 | 898 |
| 901 if (next_box && next_box->BidiLevel() == level) | 899 if (next_box && next_box->BidiLevel() == level) |
| 902 return InlineBoxPosition(inline_box, caret_offset); | 900 return InlineBoxPosition(inline_box, caret_offset); |
| 903 | 901 |
| 904 while (InlineBox* prev_box = inline_box->PrevLeafChild()) { | 902 inline_box = InlineBoxTraversal::FindLeftBoundaryOfEntireBidiRun( |
| 905 if (prev_box->BidiLevel() < level) | 903 *inline_box->PrevLeafChild()); |
|
yosin_UTC9
2017/06/14 09:41:34
To avoid pass both |InlineBox*| and BiDi level to
Xiaocheng
2017/06/15 01:11:48
Ditto.
yosin_UTC9
2017/06/15 03:42:14
Add |level| parameter to |FindXXX()|. Once code cl
| |
| 906 break; | |
| 907 inline_box = prev_box; | |
| 908 } | |
| 909 return InlineBoxPosition(inline_box, inline_box->CaretLeftmostOffset()); | 904 return InlineBoxPosition(inline_box, inline_box->CaretLeftmostOffset()); |
| 910 } | 905 } |
| 911 | 906 |
| 912 if (caret_offset == inline_box->CaretLeftmostOffset()) { | 907 if (caret_offset == inline_box->CaretLeftmostOffset()) { |
| 913 InlineBox* prev_box = inline_box->PrevLeafChildIgnoringLineBreak(); | 908 InlineBox* prev_box = inline_box->PrevLeafChildIgnoringLineBreak(); |
| 914 if (!prev_box || prev_box->BidiLevel() < level) { | 909 if (!prev_box || prev_box->BidiLevel() < level) { |
| 915 // Left edge of a secondary run. Set to the right edge of the entire | 910 // Left edge of a secondary run. Set to the right edge of the entire |
| 916 // run. | 911 // run. |
| 917 while (InlineBox* next_box = | 912 inline_box = |
| 918 inline_box->NextLeafChildIgnoringLineBreak()) { | 913 InlineBoxTraversal::FindRightBoundaryOfEntireBidiRunIgnoringLineBreak( |
| 919 if (next_box->BidiLevel() < level) | 914 *inline_box); |
|
Xiaocheng
2017/06/15 01:11:48
Do we pass in the correct bidi level here?
yosin_UTC9
2017/06/15 03:42:14
Done.
| |
| 920 break; | |
| 921 inline_box = next_box; | |
| 922 } | |
| 923 return InlineBoxPosition(inline_box, inline_box->CaretRightmostOffset()); | 915 return InlineBoxPosition(inline_box, inline_box->CaretRightmostOffset()); |
| 924 } | 916 } |
| 925 | 917 |
| 926 if (prev_box->BidiLevel() > level) { | 918 if (prev_box->BidiLevel() > level) { |
| 927 // Right edge of a "tertiary" run. Set to the left edge of that run. | 919 // Right edge of a "tertiary" run. Set to the left edge of that run. |
| 928 while (InlineBox* tertiary_box = | 920 inline_box = |
| 929 inline_box->PrevLeafChildIgnoringLineBreak()) { | 921 InlineBoxTraversal::FindLeftBoundaryOfBidiRunIgnoringLineBreak( |
|
Xiaocheng
2017/06/15 01:11:48
Do we pass in the correct bidi level here?
yosin_UTC9
2017/06/15 03:42:14
Done.
| |
| 930 if (tertiary_box->BidiLevel() <= level) | 922 *inline_box); |
| 931 break; | |
| 932 inline_box = tertiary_box; | |
| 933 } | |
| 934 return InlineBoxPosition(inline_box, inline_box->CaretLeftmostOffset()); | 923 return InlineBoxPosition(inline_box, inline_box->CaretLeftmostOffset()); |
| 935 } | 924 } |
| 936 return InlineBoxPosition(inline_box, caret_offset); | 925 return InlineBoxPosition(inline_box, caret_offset); |
| 937 } | 926 } |
| 938 | 927 |
| 939 if (unicode_bidi == UnicodeBidi::kPlaintext) { | 928 if (unicode_bidi == UnicodeBidi::kPlaintext) { |
| 940 if (inline_box->BidiLevel() < level) | 929 if (inline_box->BidiLevel() < level) |
| 941 return InlineBoxPosition(inline_box, inline_box->CaretLeftmostOffset()); | 930 return InlineBoxPosition(inline_box, inline_box->CaretLeftmostOffset()); |
| 942 return InlineBoxPosition(inline_box, inline_box->CaretRightmostOffset()); | 931 return InlineBoxPosition(inline_box, inline_box->CaretRightmostOffset()); |
| 943 } | 932 } |
| 944 | 933 |
| 945 InlineBox* next_box = inline_box->NextLeafChildIgnoringLineBreak(); | 934 InlineBox* next_box = inline_box->NextLeafChildIgnoringLineBreak(); |
| 946 if (!next_box || next_box->BidiLevel() < level) { | 935 if (!next_box || next_box->BidiLevel() < level) { |
| 947 // Right edge of a secondary run. Set to the left edge of the entire | 936 // Right edge of a secondary run. Set to the left edge of the entire |
| 948 // run. | 937 // run. |
| 949 while (InlineBox* prev_box = inline_box->PrevLeafChildIgnoringLineBreak()) { | 938 inline_box = |
| 950 if (prev_box->BidiLevel() < level) | 939 InlineBoxTraversal::FindLeftBoundaryOfEntireBidiRunIgnoringLineBreak( |
|
Xiaocheng
2017/06/15 01:11:48
Do we pass in the correct bidi level here?
yosin_UTC9
2017/06/15 03:42:14
Done.
| |
| 951 break; | 940 *inline_box); |
| 952 inline_box = prev_box; | |
| 953 } | |
| 954 return InlineBoxPosition(inline_box, inline_box->CaretLeftmostOffset()); | 941 return InlineBoxPosition(inline_box, inline_box->CaretLeftmostOffset()); |
| 955 } | 942 } |
| 956 | 943 |
| 957 if (next_box->BidiLevel() <= level) | 944 if (next_box->BidiLevel() <= level) |
| 958 return InlineBoxPosition(inline_box, caret_offset); | 945 return InlineBoxPosition(inline_box, caret_offset); |
| 959 | 946 |
| 960 // Left edge of a "tertiary" run. Set to the right edge of that run. | 947 // Left edge of a "tertiary" run. Set to the right edge of that run. |
| 961 while (InlineBox* tertiary_box = | 948 inline_box = InlineBoxTraversal::FindRightBoundaryOfBidiRunIgnoringLineBreak( |
|
Xiaocheng
2017/06/15 01:11:48
Do we pass in the correct bidi level here?
yosin_UTC9
2017/06/15 03:42:14
Done.
| |
| 962 inline_box->NextLeafChildIgnoringLineBreak()) { | 949 *inline_box); |
| 963 if (tertiary_box->BidiLevel() <= level) | |
| 964 break; | |
| 965 inline_box = tertiary_box; | |
| 966 } | |
| 967 return InlineBoxPosition(inline_box, inline_box->CaretRightmostOffset()); | 950 return InlineBoxPosition(inline_box, inline_box->CaretRightmostOffset()); |
| 968 } | 951 } |
| 969 | 952 |
| 970 template <typename Strategy> | 953 template <typename Strategy> |
| 971 static InlineBoxPosition ComputeInlineBoxPositionTemplate( | 954 static InlineBoxPosition ComputeInlineBoxPositionTemplate( |
| 972 const PositionTemplate<Strategy>& position, | 955 const PositionTemplate<Strategy>& position, |
| 973 TextAffinity affinity) { | 956 TextAffinity affinity) { |
| 974 return ComputeInlineBoxPositionTemplate<Strategy>( | 957 return ComputeInlineBoxPositionTemplate<Strategy>( |
| 975 position, affinity, PrimaryDirectionOf(*position.AnchorNode())); | 958 position, affinity, PrimaryDirectionOf(*position.AnchorNode())); |
| 976 } | 959 } |
| (...skipping 1100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2077 | 2060 |
| 2078 IntRect ComputeTextRect(const EphemeralRangeInFlatTree& range) { | 2061 IntRect ComputeTextRect(const EphemeralRangeInFlatTree& range) { |
| 2079 return EnclosingIntRect(ComputeTextRectTemplate(range)); | 2062 return EnclosingIntRect(ComputeTextRectTemplate(range)); |
| 2080 } | 2063 } |
| 2081 | 2064 |
| 2082 FloatRect ComputeTextFloatRect(const EphemeralRange& range) { | 2065 FloatRect ComputeTextFloatRect(const EphemeralRange& range) { |
| 2083 return ComputeTextRectTemplate(range); | 2066 return ComputeTextRectTemplate(range); |
| 2084 } | 2067 } |
| 2085 | 2068 |
| 2086 } // namespace blink | 2069 } // namespace blink |
| OLD | NEW |