Chromium Code Reviews| Index: ui/gfx/render_text_win.cc |
| =================================================================== |
| --- ui/gfx/render_text_win.cc (revision 111162) |
| +++ ui/gfx/render_text_win.cc (working copy) |
| @@ -168,10 +168,12 @@ |
| } |
| int RenderTextWin::GetStringWidth() { |
| + EnsureLayout(); |
| return string_width_; |
| } |
| void RenderTextWin::Draw(Canvas* canvas) { |
| + EnsureLayout(); |
| DrawSelection(canvas); |
| DrawVisualText(canvas); |
| DrawCursor(canvas); |
| @@ -181,6 +183,7 @@ |
| if (text().empty()) |
| return SelectionModel(); |
| + EnsureLayout(); |
| // Find the run that contains the point and adjust the argument location. |
| Point p(ToTextPoint(point)); |
| size_t run_index = GetRunContainingPoint(p); |
| @@ -210,6 +213,8 @@ |
| Rect RenderTextWin::GetCursorBounds(const SelectionModel& selection, |
| bool insert_mode) { |
| + EnsureLayout(); |
| + |
| // Highlight the logical cursor (selection end) when not in insert mode. |
| size_t pos = insert_mode ? selection.caret_pos() : selection.selection_end(); |
| size_t run_index = GetRunContainingPosition(pos); |
| @@ -262,6 +267,8 @@ |
| SelectionModel RenderTextWin::GetLeftSelectionModel( |
| const SelectionModel& selection, |
| BreakType break_type) { |
| + EnsureLayout(); |
| + |
| if (break_type == LINE_BREAK || text().empty()) |
| return LeftEndSelectionModel(); |
| if (break_type == CHARACTER_BREAK) |
| @@ -273,6 +280,8 @@ |
| SelectionModel RenderTextWin::GetRightSelectionModel( |
| const SelectionModel& selection, |
| BreakType break_type) { |
| + EnsureLayout(); |
| + |
| if (break_type == LINE_BREAK || text().empty()) |
| return RightEndSelectionModel(); |
| if (break_type == CHARACTER_BREAK) |
| @@ -363,6 +372,7 @@ |
| if (position == 0 || position == text().length()) |
| return true; |
| + EnsureLayout(); |
| size_t run_index = GetRunContainingPosition(position); |
| if (run_index >= runs_.size()) |
| return false; |
| @@ -376,13 +386,21 @@ |
| } |
| void RenderTextWin::UpdateLayout() { |
| + needs_layout_ = true; |
|
msw
2011/11/28 21:15:46
Add a simple comment like "Layout is performed laz
Alexei Svitkine (slow)
2011/11/28 21:58:13
Done.
|
| +} |
| + |
| +void RenderTextWin::EnsureLayout() { |
|
msw
2011/11/28 21:15:46
This should be below IndexOfAdjacentGrapheme to ma
Alexei Svitkine (slow)
2011/11/28 21:58:13
Done.
|
| + if (!needs_layout_) |
| + return; |
| // TODO(msw): Skip complex processing if ScriptIsComplex returns false. |
| ItemizeLogicalText(); |
| if (!runs_.empty()) |
| LayoutVisualText(); |
|
msw
2011/11/28 21:15:46
I think we actually need to reset |string_width_|
Alexei Svitkine (slow)
2011/11/28 21:58:13
Good catch! Done.
|
| + needs_layout_ = false; |
| } |
| size_t RenderTextWin::IndexOfAdjacentGrapheme(size_t index, bool next) { |
| + EnsureLayout(); |
| size_t run_index = GetRunContainingPosition(index); |
| internal::TextRun* run = run_index < runs_.size() ? runs_[run_index] : NULL; |
| int start = run ? run->range.start() : 0; |
| @@ -556,6 +574,7 @@ |
| } |
| size_t RenderTextWin::GetRunContainingPosition(size_t position) const { |
| + DCHECK(!needs_layout_); |
| // Find the text run containing the argument position. |
| size_t run = 0; |
| for (; run < runs_.size(); ++run) |
| @@ -566,6 +585,7 @@ |
| } |
| size_t RenderTextWin::GetRunContainingPoint(const Point& point) const { |
| + DCHECK(!needs_layout_); |
| // Find the text run containing the argument point (assumed already offset). |
| size_t run = 0; |
| for (; run < runs_.size(); ++run) |