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

Unified Diff: ui/gfx/render_text_win.cc

Issue 8536047: Separate selection highlight from pango layout (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: fix an lint error 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
« ui/gfx/render_text_linux.cc ('K') | « 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 109708)
+++ ui/gfx/render_text_win.cc (working copy)
@@ -109,12 +109,6 @@
return string_width_;
}
-void RenderTextWin::Draw(Canvas* canvas) {
- DrawSelection(canvas);
- DrawVisualText(canvas);
- DrawCursor(canvas);
-}
-
SelectionModel RenderTextWin::FindCursorPosition(const Point& point) {
if (text().empty())
return SelectionModel();
@@ -321,6 +315,65 @@
DeleteDC(hdc);
}
+void RenderTextWin::DrawVisualText(Canvas* canvas) {
+ if (text().empty())
+ return;
+
+ SkCanvas* canvas_skia = canvas->GetSkCanvas();
+
+ Point offset(ToViewPoint(Point()));
+ // TODO(msw): Establish a vertical baseline for strings of mixed font heights.
+ size_t height = default_style().font.GetHeight();
+
+ SkScalar x = SkIntToScalar(offset.x());
+ SkScalar y = SkIntToScalar(offset.y());
+ // Center the text vertically in the display area.
+ y += (display_rect().height() - height) / 2;
+ // Offset by the font size to account for Skia expecting y to be the bottom.
+ y += default_style().font.GetFontSize();
+
+ SkPaint paint;
+ paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+ paint.setStyle(SkPaint::kFill_Style);
+ paint.setAntiAlias(true);
+ paint.setSubpixelText(true);
+ paint.setLCDRenderText(true);
+
+ std::vector<SkPoint> pos;
+ for (size_t i = 0; i < runs_.size(); ++i) {
+ // Get the run specified by the visual-to-logical map.
+ internal::TextRun* run = runs_[visual_to_logical_[i]];
+
+ // TODO(msw): Font default/fallback and style integration.
+ SkTypeface::Style style = SkTypeface::kNormal;
+ SkTypeface* typeface =
+ SkTypeface::CreateFromName(run->font.GetFontName().c_str(), style);
+ if (typeface) {
+ paint.setTypeface(typeface);
+ // |paint| adds its own ref. Release the ref from CreateFromName.
+ typeface->unref();
+ }
+ paint.setTextSize(run->font.GetFontSize());
+ paint.setColor(run->foreground);
+
+ SkScalar run_x = x;
+
+ // Based on WebCore::skiaDrawText.
+ pos.resize(run->glyph_count);
+ for (int glyph = 0; glyph < run->glyph_count; glyph++) {
+ pos[glyph].set(x + run->offsets[glyph].du,
+ y + run->offsets[glyph].dv);
+ x += SkIntToScalar(run->advance_widths[glyph]);
+ }
+
+ size_t byte_length = run->glyph_count * sizeof(WORD);
+ canvas_skia->drawPosText(run->glyphs.get(), byte_length, &pos[0], paint);
+
+ if (run->strike || run->underline)
+ DrawTextRunDecorations(canvas_skia, paint, *run, run_x, y);
+ }
+}
+
size_t RenderTextWin::IndexOfAdjacentGrapheme(size_t index, bool next) {
size_t run_index = GetRunContainingPosition(index);
internal::TextRun* run = run_index < runs_.size() ? runs_[run_index] : NULL;
@@ -592,82 +645,6 @@
FirstSelectionModelInsideRun(next);
}
-void RenderTextWin::DrawSelection(Canvas* canvas) {
- std::vector<Rect> sel(
- GetSubstringBounds(GetSelectionStart(), GetCursorPosition()));
- SkColor color = focused() ? kFocusedSelectionColor : kUnfocusedSelectionColor;
- for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i)
- canvas->FillRect(color, *i);
-}
-
-void RenderTextWin::DrawVisualText(Canvas* canvas) {
- if (text().empty())
- return;
-
- SkCanvas* canvas_skia = canvas->GetSkCanvas();
-
- Point offset(ToViewPoint(Point()));
- // TODO(msw): Establish a vertical baseline for strings of mixed font heights.
- size_t height = default_style().font.GetHeight();
-
- SkScalar x = SkIntToScalar(offset.x());
- SkScalar y = SkIntToScalar(offset.y());
- // Center the text vertically in the display area.
- y += (display_rect().height() - height) / 2;
- // Offset by the font size to account for Skia expecting y to be the bottom.
- y += default_style().font.GetFontSize();
-
- SkPaint paint;
- paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
- paint.setStyle(SkPaint::kFill_Style);
- paint.setAntiAlias(true);
- paint.setSubpixelText(true);
- paint.setLCDRenderText(true);
-
- std::vector<SkPoint> pos;
- for (size_t i = 0; i < runs_.size(); ++i) {
- // Get the run specified by the visual-to-logical map.
- internal::TextRun* run = runs_[visual_to_logical_[i]];
-
- // TODO(msw): Font default/fallback and style integration.
- SkTypeface::Style style = SkTypeface::kNormal;
- SkTypeface* typeface =
- SkTypeface::CreateFromName(run->font.GetFontName().c_str(), style);
- if (typeface) {
- paint.setTypeface(typeface);
- // |paint| adds its own ref. Release the ref from CreateFromName.
- typeface->unref();
- }
- paint.setTextSize(run->font.GetFontSize());
- paint.setColor(run->foreground);
-
- SkScalar run_x = x;
-
- // Based on WebCore::skiaDrawText.
- pos.resize(run->glyph_count);
- for (int glyph = 0; glyph < run->glyph_count; glyph++) {
- pos[glyph].set(x + run->offsets[glyph].du,
- y + run->offsets[glyph].dv);
- x += SkIntToScalar(run->advance_widths[glyph]);
- }
-
- size_t byte_length = run->glyph_count * sizeof(WORD);
- canvas_skia->drawPosText(run->glyphs.get(), byte_length, &pos[0], paint);
-
- if (run->strike || run->underline)
- DrawTextRunDecorations(canvas_skia, paint, *run, run_x, y);
- }
-}
-
-void RenderTextWin::DrawCursor(Canvas* canvas) {
- // Paint cursor. Replace cursor is drawn as rectangle for now.
- // TODO(msw): Draw a better cursor with a better indication of association.
- if (cursor_visible() && focused()) {
- Rect r(GetUpdatedCursorBounds());
- canvas->DrawRectInt(kCursorColor, r.x(), r.y(), r.width(), r.height());
- }
-}
-
RenderText* RenderText::CreateRenderText() {
return new RenderTextWin;
}
« ui/gfx/render_text_linux.cc ('K') | « ui/gfx/render_text_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698