Chromium Code Reviews| Index: ui/gfx/render_text_win.cc |
| diff --git a/ui/gfx/render_text_win.cc b/ui/gfx/render_text_win.cc |
| index c2a2c2c047b3422daf88eeacc1b6d62bb136c64a..7d63e4fc1401c0c83dbc7a6bf1f6ba6829feddb2 100644 |
| --- a/ui/gfx/render_text_win.cc |
| +++ b/ui/gfx/render_text_win.cc |
| @@ -7,6 +7,7 @@ |
| #include <algorithm> |
| #include "base/i18n/break_iterator.h" |
| +#include "base/i18n/rtl.h" |
| #include "base/logging.h" |
| #include "base/string_split.h" |
| #include "base/string_util.h" |
| @@ -302,11 +303,9 @@ RenderTextWin::~RenderTextWin() { |
| } |
| base::i18n::TextDirection RenderTextWin::GetTextDirection() { |
| - // TODO(benrg): Code moved from RenderText::GetTextDirection. Needs to be |
| - // replaced by a correct Windows implementation. |
| - if (base::i18n::IsRTL()) |
| - return base::i18n::RIGHT_TO_LEFT; |
| - return base::i18n::LEFT_TO_RIGHT; |
| + EnsureLayout(); |
| + return (script_state_.uBidiLevel == 0) ? |
| + base::i18n::LEFT_TO_RIGHT : base::i18n::RIGHT_TO_LEFT; |
| } |
| Size RenderTextWin::GetStringSize() { |
| @@ -365,12 +364,13 @@ SelectionModel RenderTextWin::AdjacentCharSelectionModel( |
| DCHECK(!needs_layout_); |
| internal::TextRun* run; |
| size_t run_index = GetRunContainingCaret(selection); |
| - if (run_index == runs_.size()) { |
| + if (run_index >= runs_.size()) { |
| // The cursor is not in any run: we're at the visual and logical edge. |
| SelectionModel edge = EdgeSelectionModel(direction); |
| if (edge.caret_pos() == selection.caret_pos()) |
| return edge; |
| - run = direction == CURSOR_RIGHT ? runs_.front() : runs_.back(); |
| + int visual_index = (direction == CURSOR_RIGHT) ? 0 : runs_.size() - 1; |
| + run = runs_[visual_to_logical_[visual_index]]; |
| } else { |
| // If the cursor is moving within the current run, just move it by one |
| // grapheme in the appropriate direction. |
| @@ -596,12 +596,19 @@ void RenderTextWin::ItemizeLogicalText() { |
| runs_.reset(); |
| string_size_ = Size(0, GetFont().GetHeight()); |
| common_baseline_ = 0; |
| + script_state_.uBidiLevel = 0; |
|
Alexei Svitkine (slow)
2012/07/03 18:37:57
Can you add a case to your test that would fail if
msw
2012/07/03 22:34:04
I adjusted the logic and added a test.
|
| if (text().empty()) |
| return; |
| const wchar_t* raw_text = text().c_str(); |
| const int text_length = text().length(); |
| + // Initialize the base direction of the text. |
| + if (base::i18n::GetFirstStrongCharacterDirection(text()) == |
| + base::i18n::RIGHT_TO_LEFT) { |
|
Alexei Svitkine (slow)
2012/07/03 18:37:57
Nit: Indent 4 more spaces since it's breaking on a
msw
2012/07/03 22:34:04
Moot.
|
| + script_state_.uBidiLevel = 1; |
| + } |
| + |
| HRESULT hr = E_OUTOFMEMORY; |
| int script_items_count = 0; |
| std::vector<SCRIPT_ITEM> script_items; |