summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authormsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-30 06:21:14 +0000
committermsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-30 06:21:14 +0000
commit0d7176036fdc81f4b945308335a1f4078a8231d0 (patch)
tree6eaadd07455547012912a8f33add0c9b10791ebe /views
parent139212d9794f971f21374292a26bc6060d68b701 (diff)
downloadchromium_src-0d7176036fdc81f4b945308335a1f4078a8231d0.zip
chromium_src-0d7176036fdc81f4b945308335a1f4078a8231d0.tar.gz
chromium_src-0d7176036fdc81f4b945308335a1f4078a8231d0.tar.bz2
Implement Uniscribe RenderText for Windows.
Follow the I18N recommendations for BiDi text editing. Visual cursor movement and logical selection over BiDi text. Cleanup some common RenderText code and interfaces. Fixup TextfieldExample for views_examples. Known issues: Word breaking is not well implemented. Font sizes and vertical alignments are slightly off. Text styles break runs (colors can affect glyph shaping). Composition/selection ranges aren't stylized. BUG=90426 TEST=--use-pure-views text editing Review URL: http://codereview.chromium.org/7458014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98785 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/controls/textfield/native_textfield_views.cc11
-rw-r--r--views/controls/textfield/textfield_views_model.cc13
-rw-r--r--views/controls/textfield/textfield_views_model.h3
-rw-r--r--views/examples/textfield_example.cc33
4 files changed, 29 insertions, 31 deletions
diff --git a/views/controls/textfield/native_textfield_views.cc b/views/controls/textfield/native_textfield_views.cc
index 5b43215..e8fd03d 100644
--- a/views/controls/textfield/native_textfield_views.cc
+++ b/views/controls/textfield/native_textfield_views.cc
@@ -874,11 +874,12 @@ bool NativeTextfieldViews::HandleKeyEvent(const KeyEvent& key_event) {
cursor_changed = true;
break;
case ui::VKEY_END:
- model_->MoveCursorRight(gfx::LINE_BREAK, selection);
- cursor_changed = true;
- break;
case ui::VKEY_HOME:
- model_->MoveCursorLeft(gfx::LINE_BREAK, selection);
+ if ((key_code == ui::VKEY_HOME) ==
+ (GetRenderText()->GetTextDirection() == base::i18n::RIGHT_TO_LEFT))
+ model_->MoveCursorRight(gfx::LINE_BREAK, selection);
+ else
+ model_->MoveCursorLeft(gfx::LINE_BREAK, selection);
cursor_changed = true;
break;
case ui::VKEY_BACK:
@@ -921,7 +922,7 @@ bool NativeTextfieldViews::HandleKeyEvent(const KeyEvent& key_event) {
cursor_changed = text_changed = model_->Delete();
break;
case ui::VKEY_INSERT:
- GetRenderText()->toggle_insert_mode();
+ GetRenderText()->ToggleInsertMode();
cursor_changed = true;
break;
default:
diff --git a/views/controls/textfield/textfield_views_model.cc b/views/controls/textfield/textfield_views_model.cc
index 3f927dd..85e2179 100644
--- a/views/controls/textfield/textfield_views_model.cc
+++ b/views/controls/textfield/textfield_views_model.cc
@@ -398,11 +398,6 @@ bool TextfieldViewsModel::MoveCursorTo(const gfx::Point& point, bool select) {
return render_text_->MoveCursorTo(point, select);
}
-std::vector<gfx::Rect> TextfieldViewsModel::GetSelectionBounds() const {
- return render_text_->GetSubstringBounds(render_text_->GetSelectionStart(),
- render_text_->GetCursorPosition());
-}
-
string16 TextfieldViewsModel::GetSelectedText() const {
return GetText().substr(render_text_->MinOfSelection(),
(render_text_->MaxOfSelection() - render_text_->MinOfSelection()));
@@ -421,7 +416,7 @@ void TextfieldViewsModel::SelectRange(const ui::Range& range) {
void TextfieldViewsModel::SelectSelectionModel(const gfx::SelectionModel& sel) {
if (HasCompositionText())
ConfirmCompositionText();
- render_text_->SetSelectionModel(sel);
+ render_text_->MoveCursorTo(sel);
}
void TextfieldViewsModel::SelectAll() {
@@ -509,7 +504,7 @@ bool TextfieldViewsModel::Cut() {
render_text_->GetSelectionStart(),
render_text_->GetSelectionStart(),
gfx::SelectionModel::LEADING);
- render_text_->SetSelectionModel(sel);
+ render_text_->MoveCursorTo(sel);
DeleteSelection();
return true;
}
@@ -589,7 +584,7 @@ void TextfieldViewsModel::SetCompositionText(
size_t end =
std::min(range.start() + composition.selection.end(), range.end());
gfx::SelectionModel sel(start, end);
- render_text_->SetSelectionModel(sel);
+ render_text_->MoveCursorTo(sel);
} else {
render_text_->SetCursorPosition(range.end());
}
@@ -662,7 +657,7 @@ void TextfieldViewsModel::ReplaceTextInternal(const string16& text,
size_t cursor = GetCursorPosition();
gfx::SelectionModel sel(render_text_->selection_model());
sel.set_selection_start(cursor + text.length());
- render_text_->SetSelectionModel(sel);
+ render_text_->MoveCursorTo(sel);
}
// Edit history is recorded in InsertText.
InsertTextInternal(text, mergeable);
diff --git a/views/controls/textfield/textfield_views_model.h b/views/controls/textfield/textfield_views_model.h
index 616255f..abd1e13 100644
--- a/views/controls/textfield/textfield_views_model.h
+++ b/views/controls/textfield/textfield_views_model.h
@@ -143,9 +143,6 @@ class VIEWS_EXPORT TextfieldViewsModel {
// Helper function to call MoveCursorTo on the TextfieldViewsModel.
bool MoveCursorTo(const gfx::Point& point, bool select);
- // Returns the bounds of selected text.
- std::vector<gfx::Rect> GetSelectionBounds() const;
-
// Selection related method
// Returns the selected text.
diff --git a/views/examples/textfield_example.cc b/views/examples/textfield_example.cc
index bb1ab24..af0f2b9 100644
--- a/views/examples/textfield_example.cc
+++ b/views/examples/textfield_example.cc
@@ -90,22 +90,27 @@ void TextfieldExample::ButtonPressed(views::Button* sender,
} else if (sender == set_) {
name_->SetText(WideToUTF16(L"[set]"));
} else if (sender == set_style_) {
- gfx::StyleRange color;
- color.foreground = SK_ColorYELLOW;
- color.range = ui::Range(0, 11);
- name_->ApplyStyleRange(color);
+ if (!name_->text().empty()) {
+ gfx::StyleRange color;
+ color.foreground = SK_ColorYELLOW;
+ color.range = ui::Range(0, name_->text().length());
+ name_->ApplyStyleRange(color);
- gfx::StyleRange underline;
- underline.underline = true;
- underline.foreground = SK_ColorBLUE;
- underline.range = ui::Range(1, 7);
- name_->ApplyStyleRange(underline);
+ if (name_->text().length() >= 5) {
+ size_t fifth = name_->text().length() / 5;
+ gfx::StyleRange underline;
+ underline.underline = true;
+ underline.foreground = SK_ColorBLUE;
+ underline.range = ui::Range(1 * fifth, 4 * fifth);
+ name_->ApplyStyleRange(underline);
- gfx::StyleRange strike;
- strike.strike = true;
- strike.foreground = SK_ColorRED;
- strike.range = ui::Range(6, 9);
- name_->ApplyStyleRange(strike);
+ gfx::StyleRange strike;
+ strike.strike = true;
+ strike.foreground = SK_ColorRED;
+ strike.range = ui::Range(2 * fifth, 3 * fifth);
+ name_->ApplyStyleRange(strike);
+ }
+ }
}
}