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

Unified Diff: ui/gfx/render_text.cc

Issue 7458014: Implement Uniscribe RenderText for Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add simple BreakIterator support, use scoped_array, fix home/end, invalidate on toggle insert, etc. Created 9 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 side-by-side diff with in-line comments
Download patch
Index: ui/gfx/render_text.cc
diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc
index 498bb3b42a3ad552208fee366dc42ec7de434b44..24753fcbd124c1dfaa4e0d435ec2cbbb3df5d70f 100644
--- a/ui/gfx/render_text.cc
+++ b/ui/gfx/render_text.cc
@@ -175,6 +175,11 @@ void RenderText::SetSelectionModel(const SelectionModel& sel) {
cached_bounds_and_offset_valid_ = false;
}
+void RenderText::ToggleInsertMode() {
+ insert_mode_ = !insert_mode_;
+ cached_bounds_and_offset_valid_ = false;
+}
+
void RenderText::SetDisplayRect(const Rect& r) {
display_rect_ = r;
cached_bounds_and_offset_valid_ = false;
@@ -184,13 +189,8 @@ size_t RenderText::GetCursorPosition() const {
return selection_model_.selection_end();
}
-void RenderText::SetCursorPosition(const size_t position) {
- SelectionModel sel(selection_model());
- sel.set_selection_start(position);
- sel.set_selection_end(position);
- sel.set_caret_pos(GetIndexOfPreviousGrapheme(position));
- sel.set_caret_placement(SelectionModel::TRAILING);
- SetSelectionModel(sel);
+void RenderText::SetCursorPosition(size_t position) {
+ MoveCursorTo(position, false);
}
void RenderText::MoveCursorLeft(BreakType break_type, bool select) {
@@ -237,6 +237,15 @@ void RenderText::MoveCursorRight(BreakType break_type, bool select) {
MoveCursorTo(position);
}
+void RenderText::MoveCursorTo(size_t position, bool select) {
+ size_t caret_pos = GetIndexOfPreviousGrapheme(position);
+ SelectionModel::CaretPlacement placement = (caret_pos == position) ?
+ SelectionModel::LEADING : SelectionModel::TRAILING;
+ size_t selection_start = select ? GetSelectionStart() : position;
+ SelectionModel sel(selection_start, position, caret_pos, placement);
+ SetSelectionModel(sel);
xji 2011/08/18 22:47:54 hmm... the functionality seems different from prev
msw 2011/08/19 10:55:30 This has been reincarnated as a convenience functi
xji 2011/08/19 17:38:13 make sense. but I think for complex script, say f
msw 2011/08/19 18:03:33 Interesting, I wonder how that works with the IMEs
+}
+
bool RenderText::MoveCursorTo(const SelectionModel& selection) {
bool changed = !selection.Equals(selection_model_);
SetSelectionModel(selection);
@@ -251,6 +260,8 @@ bool RenderText::MoveCursorTo(const Point& point, bool select) {
}
bool RenderText::IsPointInSelection(const Point& point) {
+ if (EmptySelection())
+ return false;
// TODO(xji): should this check whether the point is inside the visual
// selection bounds? In case of "abcFED", if "ED" is selected, |point| points
// to the right half of 'c', is the point in selection?
@@ -308,12 +319,8 @@ void RenderText::SelectWord() {
break;
}
- SelectionModel sel(selection_model());
- sel.set_selection_start(selection_start);
- sel.set_selection_end(cursor_position);
- sel.set_caret_pos(GetIndexOfPreviousGrapheme(cursor_position));
- sel.set_caret_placement(SelectionModel::TRAILING);
- SetSelectionModel(sel);
+ MoveCursorTo(selection_start, false);
+ MoveCursorTo(cursor_position, true);
xji 2011/08/18 22:47:54 why this change?
msw 2011/08/19 10:55:30 Convenience of built-in checking for s previous gr
}
const ui::Range& RenderText::GetCompositionRange() const {
@@ -589,7 +596,6 @@ void RenderText::UpdateCachedBoundsAndOffset() {
// function will set |cursor_bounds_| and |display_offset_| to correct values.
cached_bounds_and_offset_valid_ = true;
cursor_bounds_ = GetCursorBounds(selection_model_, insert_mode_);
- cursor_bounds_.set_width(std::max(cursor_bounds_.width(), 1));
// Update |display_offset_| to ensure the current cursor is visible.
int display_width = display_rect_.width();
int string_width = GetStringWidth();

Powered by Google App Engine
This is Rietveld 408576698