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

Side by Side Diff: views/controls/textfield/text_style.cc

Issue 7265011: RenderText API Outline. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add TODO comments, revise cursor movement API, etc. Created 9 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "views/controls/textfield/text_style.h"
6
7 #include "ui/gfx/canvas.h"
8 #include "ui/gfx/canvas_skia.h"
9 #include "ui/gfx/font.h"
10
11 namespace {
12 // Text color for read only.
13 const SkColor kReadonlyTextColor = SK_ColorDKGRAY;
14
15 // Strike line width.
16 const int kStrikeWidth = 2;
17 }
18
19 namespace views {
20
21 TextStyle::TextStyle()
22 : foreground_(SK_ColorBLACK),
23 strike_(false),
24 underline_(false) {
25 }
26
27 TextStyle::~TextStyle() {
28 }
29
30 void TextStyle::DrawString(gfx::Canvas* canvas,
31 string16& text,
32 gfx::Font& base_font,
33 bool readonly,
34 int x, int y, int width, int height) const {
35 SkColor text_color = readonly ? kReadonlyTextColor : foreground_;
36
37 gfx::Font font = underline_ ?
38 base_font.DeriveFont(0, base_font.GetStyle() | gfx::Font::UNDERLINED) :
39 base_font;
40 canvas->DrawStringInt(text, font, text_color, x, y, width, height);
41 if (strike_) {
42 SkPaint paint;
43 paint.setAntiAlias(true);
44 paint.setStyle(SkPaint::kFill_Style);
45 paint.setColor(text_color);
46 paint.setStrokeWidth(kStrikeWidth);
47 canvas->AsCanvasSkia()->drawLine(
48 SkIntToScalar(x), SkIntToScalar(y + height),
49 SkIntToScalar(x + width), SkIntToScalar(y),
50 paint);
51 }
52 }
53
54 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698