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

Issue 9390022: Simplify handling of BiDi cursor movement (Closed)

Created:
8 years, 10 months ago by benrg
Modified:
8 years, 9 months ago
CC:
chromium-reviews, sadrul, yusukes+watch_chromium.org, ben+watch_chromium.org, dhollowa+watch_chromium.org, penghuang+watch_chromium.org, tfarina, James Su, msw, Alexei Svitkine (slow)
Visibility:
Public.

Description

Simplify handling of BiDi cursor movement The current caret position and the end of the current selection in a text field are logically the same thing, but the current code represents them separately as SelectionModel::caret_pos_ and SelectionModel::selection_end_, which sometimes have different values, for two reasons: 1. selection_end_ indexes a point between two graphemes (range 0 to N, where N is the text length), but caret_pos_ indexes a grapheme (range 0 to N-1). SelectionModel::caret_placement_ specifies whether the caret is to be displayed at the leading or trailing edge of that grapheme. When the placement is LEADING, selection_end_ and caret_pos_ have the same value, but when it's TRAILING, caret_pos_ points to the start of the grapheme while selection_end_ points to the end. 2. The first and last logical graphemes of the text are not always at the visual boundary (for example, when the text is visually abcFED, the last logical character, F, is in the middle). In order to make the cursor appear at the visual boundary in such cases, the current code attaches it to the leading edge of the D, whereas selection_end_ points after the F. The first case can be fixed by making caret_pos_ point between graphemes like selection_end_. This is enough to determine the caret position except when it is between bidi runs that aren't visually contiguous: in that case, an extra field ("affinity", replacing placement) indicates whether it appears attached to the previous or the next run. The second case can be fixed by pretending that the text is surrounded on both sides by text in the default bidi direction, and allowing the caret to be attached to those runs. This makes EdgeSelectionModel() much simpler: it always returns either (0, previous) or (text_length, next). After these changes, caret_pos_ and selection_end_ always have the same value, so I merged them. For examples of how the old and new SelectionModels compare, look at the changes to ui/gfx/render_text_unittest.cc. The visual behavior of the text field is mostly unaffected by this change. I'm not sure that the current behavior is actually what we want (it's different from WebKit, Windows, and GTK behavior, all of which are different from each other), but that's a separate issue. Visible changes: * RenderText::IsPointInSelection should now behave as expected when clicking on the trailing half of a glyph (it was a TODO). * Clicking on the right half of a glyph used to place the caret to the left of the glyph on Windows. It should now place it on the right. * There was a bug in the Windows cursoring code: with the text "CBAdef" in a LTR locale, pressing End, then Left repeatedly, causes the caret to cycle through the leftmost five visual positions instead of stopping at the left. This should now be fixed. Drive-by changes: * Replaced the selection with a ui::Range and use ui::Range methods like GetMin() and is_reversed() instead of SelectionModel-specific code. * Merged RenderText{Linux,Win}::{EdgeSelectionModel,GetCursorBounds} into RenderText. I didn't merge other methods (such as AdjacentCharSelectionModel) that should eventually be merged but aren't as easy to merge. * Some simplification of the unit tests. BUG=90426 TEST=existing unit tests Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=126287

Patch Set 1 : . #

Total comments: 4

Patch Set 2 : comments #

Total comments: 85

Patch Set 3 : comments #

Total comments: 26

Patch Set 4 : address comments, fix overstrike and operator<< bugs #

Patch Set 5 : make set_selection_start private, fix accidental inclusion of local hacks #

Total comments: 39

Patch Set 6 : rebase (not for review) #

Patch Set 7 : address comments #

Total comments: 6

Patch Set 8 : rewrite comments #

Patch Set 9 : address comment #

Patch Set 10 : rebase (no changes) #

Total comments: 6

Patch Set 11 : windows fixes #

Patch Set 12 : rebase, more windows fixes #

Patch Set 13 : fix merge breakage #

Unified diffs Side-by-side diffs Delta from patch set Stats (+749 lines, -1001 lines) Patch
M ui/base/range/range.h View 1 chunk +2 lines, -1 line 0 comments Download
M ui/gfx/canvas_skia_skia.cc View 1 2 3 4 5 2 chunks +2 lines, -2 lines 0 comments Download
M ui/gfx/render_text.h View 1 2 3 4 5 6 10 chunks +29 lines, -52 lines 0 comments Download
M ui/gfx/render_text.cc View 1 2 3 4 5 6 7 8 14 chunks +109 lines, -111 lines 0 comments Download
M ui/gfx/render_text_linux.h View 1 2 3 4 5 6 7 8 9 4 chunks +11 lines, -11 lines 0 comments Download
M ui/gfx/render_text_linux.cc View 1 2 3 4 5 6 7 8 9 10 11 12 5 chunks +82 lines, -154 lines 0 comments Download
M ui/gfx/render_text_unittest.cc View 1 2 3 4 5 6 7 8 9 10 11 28 chunks +211 lines, -240 lines 0 comments Download
M ui/gfx/render_text_win.h View 1 2 3 4 5 3 chunks +6 lines, -7 lines 0 comments Download
M ui/gfx/render_text_win.cc View 1 2 3 4 5 6 7 8 9 10 11 11 chunks +92 lines, -157 lines 0 comments Download
M ui/gfx/selection_model.h View 1 2 3 4 5 6 7 2 chunks +67 lines, -49 lines 0 comments Download
M ui/gfx/selection_model.cc View 1 2 3 4 5 6 1 chunk +20 lines, -34 lines 0 comments Download
M ui/views/controls/textfield/native_textfield_views.cc View 1 2 3 4 5 6 7 8 9 10 11 5 chunks +14 lines, -32 lines 0 comments Download
M ui/views/controls/textfield/native_textfield_views_unittest.cc View 1 2 3 4 5 2 chunks +10 lines, -10 lines 0 comments Download
M ui/views/controls/textfield/textfield_views_model.h View 1 2 2 chunks +1 line, -4 lines 0 comments Download
M ui/views/controls/textfield/textfield_views_model.cc View 1 2 3 4 5 10 chunks +26 lines, -36 lines 0 comments Download
M ui/views/controls/textfield/textfield_views_model_unittest.cc View 1 2 3 4 5 20 chunks +66 lines, -100 lines 0 comments Download
M ui/views/touchui/touch_selection_controller_impl_unittest.cc View 1 2 1 chunk +1 line, -1 line 0 comments Download

Messages

Total messages: 39 (0 generated)
benrg
xji, are you willing to take a look at this?
8 years, 10 months ago (2012-02-14 19:25:32 UTC) #1
Alexei Svitkine (slow)
http://codereview.chromium.org/9390022/diff/10005/ui/gfx/render_text_linux.cc File ui/gfx/render_text_linux.cc (right): http://codereview.chromium.org/9390022/diff/10005/ui/gfx/render_text_linux.cc#newcode414 ui/gfx/render_text_linux.cc:414: // NB: exploits unsigned wraparound (0 - 1) This ...
8 years, 10 months ago (2012-02-14 20:16:31 UTC) #2
xji
On 2012/02/14 19:25:32, benrg wrote: > xji, are you willing to take a look at ...
8 years, 10 months ago (2012-02-14 21:12:29 UTC) #3
xji
8 years, 10 months ago (2012-02-14 21:12:50 UTC) #4
benrg
>IsPointInSelection() did not work correctly before? Before, in the case of abcFED, with ED selected, ...
8 years, 10 months ago (2012-02-14 23:39:02 UTC) #5
Alexei Svitkine (slow)
> > http://codereview.chromium.**org/9390022/diff/10005/ui/gfx/** > render_text_linux.cc#**newcode414<http://codereview.chromium.org/9390022/diff/10005/ui/gfx/render_text_linux.cc#newcode414> > ui/gfx/render_text_linux.cc:**414: // NB: exploits unsigned wraparound (0 > - ...
8 years, 10 months ago (2012-02-15 01:48:33 UTC) #6
msw
This is pretty awesome, I always wanted SelectionModel to contain a single range, and I ...
8 years, 10 months ago (2012-02-16 00:09:20 UTC) #7
msw
Also, set BUG=90426.
8 years, 10 months ago (2012-02-16 00:10:53 UTC) #8
xji
http://codereview.chromium.org/9390022/diff/12022/ui/gfx/render_text.cc File ui/gfx/render_text.cc (right): http://codereview.chromium.org/9390022/diff/12022/ui/gfx/render_text.cc#newcode415 ui/gfx/render_text.cc:415: if (model.caret_pos() > text_length) are "{" and "}" needed ...
8 years, 10 months ago (2012-02-16 02:38:29 UTC) #9
xji
http://codereview.chromium.org/9390022/diff/12022/ui/gfx/render_text_linux.cc File ui/gfx/render_text_linux.cc (right): http://codereview.chromium.org/9390022/diff/12022/ui/gfx/render_text_linux.cc#newcode418 ui/gfx/render_text_linux.cc:418: if (RangeContainsCaret(ui::Range(item->offset, item->offset + item->length), On 2012/02/16 02:38:29, xji ...
8 years, 10 months ago (2012-02-16 02:40:50 UTC) #10
benrg
msw (and everybody), sorry about the complexity of the CL. Alexei: > Is there a ...
8 years, 10 months ago (2012-02-16 09:20:55 UTC) #11
xji
http://codereview.chromium.org/9390022/diff/12022/ui/gfx/render_text.cc File ui/gfx/render_text.cc (right): http://codereview.chromium.org/9390022/diff/12022/ui/gfx/render_text.cc#newcode444 ui/gfx/render_text.cc:444: (sel.is_reversed() || (sel.is_empty() && sel.start() != 0)) ? On ...
8 years, 10 months ago (2012-02-16 19:52:55 UTC) #12
msw
http://codereview.chromium.org/9390022/diff/12022/ui/gfx/render_text_linux.cc File ui/gfx/render_text_linux.cc (right): http://codereview.chromium.org/9390022/diff/12022/ui/gfx/render_text_linux.cc#newcode83 ui/gfx/render_text_linux.cc:83: int width, height; On 2012/02/16 09:20:55, benrg wrote: > ...
8 years, 10 months ago (2012-02-21 21:13:38 UTC) #13
msw
+oshima for review
8 years, 10 months ago (2012-02-21 21:14:10 UTC) #14
Alexei Svitkine (slow)
http://codereview.chromium.org/9390022/diff/28022/ui/gfx/render_text.h File ui/gfx/render_text.h (right): http://codereview.chromium.org/9390022/diff/28022/ui/gfx/render_text.h#newcode208 ui/gfx/render_text.h:208: virtual void GetGlyphBounds(size_t index, ui::Range* xspan, int* height) = ...
8 years, 10 months ago (2012-02-21 21:40:27 UTC) #15
benrg
In addition to the comments I fixed a regression in the overstrike behavior. Even with ...
8 years, 10 months ago (2012-02-21 23:21:45 UTC) #16
xji
On 2012/02/21 23:21:45, benrg wrote: > In addition to the comments I fixed a regression ...
8 years, 10 months ago (2012-02-22 01:30:33 UTC) #17
xji
LGTM with following comments addressed. http://codereview.chromium.org/9390022/diff/34024/ui/gfx/render_text.cc File ui/gfx/render_text.cc (right): http://codereview.chromium.org/9390022/diff/34024/ui/gfx/render_text.cc#newcode568 ui/gfx/render_text.cc:568: // In overstrike mode, ...
8 years, 10 months ago (2012-02-24 20:16:52 UTC) #18
msw
http://codereview.chromium.org/9390022/diff/28022/ui/gfx/render_text_unittest.cc File ui/gfx/render_text_unittest.cc (right): http://codereview.chromium.org/9390022/diff/28022/ui/gfx/render_text_unittest.cc#newcode335 ui/gfx/render_text_unittest.cc:335: expected.push_back(SelectionModel(6, CURSOR_FORWARD)); On 2012/02/21 23:21:45, benrg wrote: > On ...
8 years, 9 months ago (2012-02-28 22:51:32 UTC) #19
benrg
msw, PTAL. https://chromiumcodereview.appspot.com/9390022/diff/34024/ui/gfx/render_text.cc File ui/gfx/render_text.cc (right): https://chromiumcodereview.appspot.com/9390022/diff/34024/ui/gfx/render_text.cc#newcode458 ui/gfx/render_text.cc:458: SetSelectionModel(SelectionModel(selection_model_.caret_pos(), On 2012/02/28 22:51:32, msw wrote: > ...
8 years, 9 months ago (2012-03-07 01:04:43 UTC) #20
msw
https://chromiumcodereview.appspot.com/9390022/diff/34024/ui/gfx/selection_model.h File ui/gfx/selection_model.h (right): https://chromiumcodereview.appspot.com/9390022/diff/34024/ui/gfx/selection_model.h#newcode56 ui/gfx/selection_model.h:56: void set_selection_start(size_t pos) { selection_.set_start(pos); } That's correct; users ...
8 years, 9 months ago (2012-03-08 18:07:18 UTC) #21
msw
https://chromiumcodereview.appspot.com/9390022/diff/34024/ui/gfx/selection_model.h File ui/gfx/selection_model.h (right): https://chromiumcodereview.appspot.com/9390022/diff/34024/ui/gfx/selection_model.h#newcode56 ui/gfx/selection_model.h:56: void set_selection_start(size_t pos) { selection_.set_start(pos); } Gah, correction: when ...
8 years, 9 months ago (2012-03-08 18:09:36 UTC) #22
xji
https://chromiumcodereview.appspot.com/9390022/diff/34024/ui/gfx/selection_model.h File ui/gfx/selection_model.h (right): https://chromiumcodereview.appspot.com/9390022/diff/34024/ui/gfx/selection_model.h#newcode56 ui/gfx/selection_model.h:56: void set_selection_start(size_t pos) { selection_.set_start(pos); } On 2012/03/07 01:04:44, ...
8 years, 9 months ago (2012-03-08 20:30:01 UTC) #23
benrg
Saintlou understandably wants me to work on higher-priority bugs, so I think I should either ...
8 years, 9 months ago (2012-03-08 21:22:03 UTC) #24
msw
I think you addressed all my major concerns (except below). LGTM, but be prepared to ...
8 years, 9 months ago (2012-03-08 21:33:57 UTC) #25
benrg
Ben, do you have time to look at this? http://codereview.chromium.org/9390022/diff/62021/ui/gfx/render_text.cc File ui/gfx/render_text.cc (right): http://codereview.chromium.org/9390022/diff/62021/ui/gfx/render_text.cc#newcode427 ui/gfx/render_text.cc:427: ...
8 years, 9 months ago (2012-03-08 22:06:31 UTC) #26
Alexei Svitkine (slow)
http://codereview.chromium.org/9390022/diff/70022/ui/gfx/render_text_win.cc File ui/gfx/render_text_win.cc (right): http://codereview.chromium.org/9390022/diff/70022/ui/gfx/render_text_win.cc#newcode144 ui/gfx/render_text_win.cc:144: DCHECK_GE(index, run->range.start()) Add ; http://codereview.chromium.org/9390022/diff/70022/ui/gfx/render_text_win.cc#newcode145 ui/gfx/render_text_win.cc:145: DCHECK_LT(index, run->range.end()) Add ...
8 years, 9 months ago (2012-03-08 22:32:15 UTC) #27
msw
http://codereview.chromium.org/9390022/diff/70022/ui/gfx/render_text_win.cc File ui/gfx/render_text_win.cc (right): http://codereview.chromium.org/9390022/diff/70022/ui/gfx/render_text_win.cc#newcode144 ui/gfx/render_text_win.cc:144: DCHECK_GE(index, run->range.start()) These have been broken since Patch Set ...
8 years, 9 months ago (2012-03-08 22:37:48 UTC) #28
Ben Goodger (Google)
I don't really have any idea how any of this text rendering works, so I'll ...
8 years, 9 months ago (2012-03-08 23:07:03 UTC) #29
benrg
http://codereview.chromium.org/9390022/diff/70022/ui/gfx/render_text_win.cc File ui/gfx/render_text_win.cc (right): http://codereview.chromium.org/9390022/diff/70022/ui/gfx/render_text_win.cc#newcode144 ui/gfx/render_text_win.cc:144: DCHECK_GE(index, run->range.start()) On 2012/03/08 22:37:48, msw wrote: > These ...
8 years, 9 months ago (2012-03-08 23:20:59 UTC) #30
Alexei Svitkine (slow)
LGTM
8 years, 9 months ago (2012-03-08 23:23:35 UTC) #31
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/benrg@chromium.org/9390022/82002
8 years, 9 months ago (2012-03-12 16:54:00 UTC) #32
commit-bot: I haz the power
Try job failure for 9390022-82002 (retry) on linux_chromeos for step "compile" (clobber build). It's a ...
8 years, 9 months ago (2012-03-12 17:12:15 UTC) #33
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/benrg@chromium.org/9390022/86003
8 years, 9 months ago (2012-03-12 17:54:40 UTC) #34
commit-bot: I haz the power
Try job failure for 9390022-86003 (retry) on linux_rel for step "compile" (clobber build). It's a ...
8 years, 9 months ago (2012-03-12 18:23:21 UTC) #35
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/benrg@chromium.org/9390022/86003
8 years, 9 months ago (2012-03-12 18:51:53 UTC) #36
commit-bot: I haz the power
Try job failure for 9390022-86003 (retry) on win_rel for step "check_deps". It's a second try, ...
8 years, 9 months ago (2012-03-12 21:18:05 UTC) #37
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/benrg@chromium.org/9390022/86003
8 years, 9 months ago (2012-03-12 22:55:01 UTC) #38
commit-bot: I haz the power
8 years, 9 months ago (2012-03-13 01:09:33 UTC) #39
Change committed as 126287

Powered by Google App Engine
This is Rietveld 408576698