Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: third_party/WebKit/Source/core/editing/VisibleUnits.cpp

Issue 2220923002: Make computeInlineBoxPosition() to handle unicode-bidi:isolate correctly (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2016-08-08T15:03:39 Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/VisibleUnitsTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv ed. 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv ed.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 1953 matching lines...) Expand 10 before | Expand all | Expand 10 after
1964 PositionTemplate<Strategy> upstreamIgnoringEditingBoundaries(PositionTemplate<St rategy> position) 1964 PositionTemplate<Strategy> upstreamIgnoringEditingBoundaries(PositionTemplate<St rategy> position)
1965 { 1965 {
1966 PositionTemplate<Strategy> lastPosition; 1966 PositionTemplate<Strategy> lastPosition;
1967 while (position != lastPosition) { 1967 while (position != lastPosition) {
1968 lastPosition = position; 1968 lastPosition = position;
1969 position = mostBackwardCaretPosition(position, CanCrossEditingBoundary); 1969 position = mostBackwardCaretPosition(position, CanCrossEditingBoundary);
1970 } 1970 }
1971 return position; 1971 return position;
1972 } 1972 }
1973 1973
1974 // Returns true if |inlineBox| starts different direction of embedded text ru.
1975 // See [1] for details.
1976 // [1] UNICODE BIDIRECTIONAL ALGORITHM, http://unicode.org/reports/tr9/
1977 static bool isStartOfDifferentDirection(const InlineBox* inlineBox)
1978 {
1979 InlineBox* prevBox = inlineBox->prevLeafChild();
1980 if (!prevBox)
1981 return true;
1982 if (prevBox->direction() == inlineBox->direction())
1983 return true;
1984 DCHECK_NE(prevBox->bidiLevel(), inlineBox->bidiLevel());
1985 return prevBox->bidiLevel() > inlineBox->bidiLevel();
1986 }
1987
1974 template <typename Strategy> 1988 template <typename Strategy>
1975 static InlineBoxPosition computeInlineBoxPositionTemplate(const PositionTemplate <Strategy>& position, TextAffinity affinity, TextDirection primaryDirection) 1989 static InlineBoxPosition computeInlineBoxPositionTemplate(const PositionTemplate <Strategy>& position, TextAffinity affinity, TextDirection primaryDirection)
1976 { 1990 {
1977 InlineBox* inlineBox = nullptr; 1991 InlineBox* inlineBox = nullptr;
1978 int caretOffset = position.computeEditingOffset(); 1992 int caretOffset = position.computeEditingOffset();
1979 Node* const anchorNode = position.anchorNode(); 1993 Node* const anchorNode = position.anchorNode();
1980 LayoutObject* layoutObject = anchorNode->isShadowRoot() ? toShadowRoot(ancho rNode)->host().layoutObject() : anchorNode->layoutObject(); 1994 LayoutObject* layoutObject = anchorNode->isShadowRoot() ? toShadowRoot(ancho rNode)->host().layoutObject() : anchorNode->layoutObject();
1981 1995
1982 DCHECK(layoutObject) << position; 1996 DCHECK(layoutObject) << position;
1983 1997
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
2057 2071
2058 // For example, abc 123 ^ CBA 2072 // For example, abc 123 ^ CBA
2059 while (InlineBox* nextBox = inlineBox->nextLeafChild()) { 2073 while (InlineBox* nextBox = inlineBox->nextLeafChild()) {
2060 if (nextBox->bidiLevel() < level) 2074 if (nextBox->bidiLevel() < level)
2061 break; 2075 break;
2062 inlineBox = nextBox; 2076 inlineBox = nextBox;
2063 } 2077 }
2064 return InlineBoxPosition(inlineBox, inlineBox->caretRightmostOffset( )); 2078 return InlineBoxPosition(inlineBox, inlineBox->caretRightmostOffset( ));
2065 } 2079 }
2066 2080
2067 InlineBox* prevBox = inlineBox->prevLeafChild(); 2081 if (isStartOfDifferentDirection(inlineBox))
2068 if (!prevBox || prevBox->bidiLevel() >= level)
2069 return InlineBoxPosition(inlineBox, caretOffset); 2082 return InlineBoxPosition(inlineBox, caretOffset);
2070 2083
2071 level = prevBox->bidiLevel(); 2084 level = inlineBox->prevLeafChild()->bidiLevel();
2072 InlineBox* nextBox = inlineBox; 2085 InlineBox* nextBox = inlineBox;
2073 do { 2086 do {
2074 nextBox = nextBox->nextLeafChild(); 2087 nextBox = nextBox->nextLeafChild();
2075 } while (nextBox && nextBox->bidiLevel() > level); 2088 } while (nextBox && nextBox->bidiLevel() > level);
2076 2089
2077 if (nextBox && nextBox->bidiLevel() == level) 2090 if (nextBox && nextBox->bidiLevel() == level)
2078 return InlineBoxPosition(inlineBox, caretOffset); 2091 return InlineBoxPosition(inlineBox, caretOffset);
2079 2092
2080 while (InlineBox* prevBox = inlineBox->prevLeafChild()) { 2093 while (InlineBox* prevBox = inlineBox->prevLeafChild()) {
2081 if (prevBox->bidiLevel() < level) 2094 if (prevBox->bidiLevel() < level)
(...skipping 1225 matching lines...) Expand 10 before | Expand all | Expand 10 after
3307 { 3320 {
3308 return previousPositionOfAlgorithm<EditingStrategy>(visiblePosition, rule); 3321 return previousPositionOfAlgorithm<EditingStrategy>(visiblePosition, rule);
3309 } 3322 }
3310 3323
3311 VisiblePositionInFlatTree previousPositionOf(const VisiblePositionInFlatTree& vi siblePosition, EditingBoundaryCrossingRule rule) 3324 VisiblePositionInFlatTree previousPositionOf(const VisiblePositionInFlatTree& vi siblePosition, EditingBoundaryCrossingRule rule)
3312 { 3325 {
3313 return previousPositionOfAlgorithm<EditingInFlatTreeStrategy>(visiblePositio n, rule); 3326 return previousPositionOfAlgorithm<EditingInFlatTreeStrategy>(visiblePositio n, rule);
3314 } 3327 }
3315 3328
3316 } // namespace blink 3329 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/VisibleUnitsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698