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

Unified Diff: ui/gfx/render_text_win.cc

Issue 8633019: Itemize and layout text lazily in RenderTextWin. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 1 month 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_win.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)
« no previous file with comments | « ui/gfx/render_text_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698