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

Unified Diff: ui/gfx/render_text_win.cc

Issue 10693061: Fix RenderTextWin base dir and adjacent char code; remove test exceptions; etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments; add unit test. Created 8 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/render_text_unittest.cc ('k') | ui/views/controls/textfield/native_textfield_views_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « ui/gfx/render_text_unittest.cc ('k') | ui/views/controls/textfield/native_textfield_views_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698