OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_GFX_RENDER_TEXT_H_ | 5 #ifndef UI_GFX_RENDER_TEXT_H_ |
6 #define UI_GFX_RENDER_TEXT_H_ | 6 #define UI_GFX_RENDER_TEXT_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
14 #include "base/string16.h" | 14 #include "base/string16.h" |
15 #include "third_party/skia/include/core/SkColor.h" | 15 #include "third_party/skia/include/core/SkColor.h" |
| 16 #include "third_party/skia/include/core/SkPaint.h" |
16 #include "ui/base/range/range.h" | 17 #include "ui/base/range/range.h" |
17 #include "ui/gfx/font.h" | 18 #include "ui/gfx/font.h" |
18 #include "ui/gfx/point.h" | 19 #include "ui/gfx/point.h" |
19 #include "ui/gfx/rect.h" | 20 #include "ui/gfx/rect.h" |
20 #include "ui/gfx/selection_model.h" | 21 #include "ui/gfx/selection_model.h" |
21 | 22 |
| 23 class SkCanvas; |
| 24 struct SkPoint; |
| 25 |
22 namespace gfx { | 26 namespace gfx { |
23 | 27 |
| 28 class Canvas; |
| 29 class RenderTextTest; |
| 30 |
| 31 namespace internal { |
| 32 |
| 33 // Internal helper class used by derived classes to draw text through Skia. |
| 34 class SkiaTextRenderer { |
| 35 public: |
| 36 explicit SkiaTextRenderer(Canvas* canvas); |
| 37 ~SkiaTextRenderer(); |
| 38 |
| 39 void SetFont(const gfx::Font& font); |
| 40 void SetForegroundColor(SkColor foreground); |
| 41 void DrawSelection(const std::vector<Rect>& selection, SkColor color); |
| 42 void DrawPosText(const SkPoint* pos, |
| 43 const uint16* glyphs, |
| 44 size_t glyph_count); |
| 45 void DrawDecorations(int x, int y, int width, bool underline, bool strike); |
| 46 void DrawCursor(const gfx::Rect& bounds); |
| 47 |
| 48 private: |
| 49 SkCanvas* canvas_skia_; |
| 50 SkPaint paint_; |
| 51 |
| 52 DISALLOW_COPY_AND_ASSIGN(SkiaTextRenderer); |
| 53 }; |
| 54 |
| 55 } // namespace internal |
| 56 |
24 // Color settings for text, backgrounds and cursor. | 57 // Color settings for text, backgrounds and cursor. |
25 // These are tentative, and should be derived from theme, system | 58 // These are tentative, and should be derived from theme, system |
26 // settings and current settings. | 59 // settings and current settings. |
27 // TODO(oshima): Change this to match the standard chrome | 60 // TODO(oshima): Change this to match the standard chrome |
28 // before dogfooding textfield views. | 61 // before dogfooding textfield views. |
29 const SkColor kSelectedTextColor = SK_ColorWHITE; | 62 const SkColor kSelectedTextColor = SK_ColorWHITE; |
30 const SkColor kFocusedSelectionColor = SkColorSetRGB(30, 144, 255); | 63 const SkColor kFocusedSelectionColor = SkColorSetRGB(30, 144, 255); |
31 const SkColor kUnfocusedSelectionColor = SK_ColorLTGRAY; | 64 const SkColor kUnfocusedSelectionColor = SK_ColorLTGRAY; |
32 const SkColor kCursorColor = SK_ColorBLACK; | 65 const SkColor kCursorColor = SK_ColorBLACK; |
33 | 66 |
34 class Canvas; | |
35 class RenderTextTest; | |
36 | |
37 // A visual style applicable to a range of text. | 67 // A visual style applicable to a range of text. |
38 struct UI_EXPORT StyleRange { | 68 struct UI_EXPORT StyleRange { |
39 StyleRange(); | 69 StyleRange(); |
40 | 70 |
41 Font font; | 71 Font font; |
42 SkColor foreground; | 72 SkColor foreground; |
43 bool strike; | 73 bool strike; |
44 bool underline; | 74 bool underline; |
45 ui::Range range; | 75 ui::Range range; |
46 }; | 76 }; |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 | 268 |
239 // Apply composition style (underline) to composition range and selection | 269 // Apply composition style (underline) to composition range and selection |
240 // style (foreground) to selection range. | 270 // style (foreground) to selection range. |
241 void ApplyCompositionAndSelectionStyles(StyleRanges* style_ranges) const; | 271 void ApplyCompositionAndSelectionStyles(StyleRanges* style_ranges) const; |
242 | 272 |
243 // Convert points from the text space to the view space and back. | 273 // Convert points from the text space to the view space and back. |
244 // Handles the display area, display offset, and the application LTR/RTL mode. | 274 // Handles the display area, display offset, and the application LTR/RTL mode. |
245 Point ToTextPoint(const Point& point); | 275 Point ToTextPoint(const Point& point); |
246 Point ToViewPoint(const Point& point); | 276 Point ToViewPoint(const Point& point); |
247 | 277 |
| 278 // Returns the origin point for drawing text via Skia. |
| 279 Point GetOriginForSkiaDrawing(); |
| 280 |
248 private: | 281 private: |
249 friend class RenderTextTest; | 282 friend class RenderTextTest; |
250 | 283 |
251 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); | 284 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); |
252 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, CustomDefaultStyle); | 285 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, CustomDefaultStyle); |
253 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyStyleRange); | 286 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyStyleRange); |
254 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StyleRangesAdjust); | 287 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StyleRangesAdjust); |
255 | 288 |
256 // Return an index belonging to the |next| or previous logical grapheme. | 289 // Return an index belonging to the |next| or previous logical grapheme. |
257 // The return value is bounded by 0 and the text length, inclusive. | 290 // The return value is bounded by 0 and the text length, inclusive. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 // The cached bounds and offset are invalidated by changes to the cursor, | 338 // The cached bounds and offset are invalidated by changes to the cursor, |
306 // selection, font, and other operations that adjust the visible text bounds. | 339 // selection, font, and other operations that adjust the visible text bounds. |
307 bool cached_bounds_and_offset_valid_; | 340 bool cached_bounds_and_offset_valid_; |
308 | 341 |
309 DISALLOW_COPY_AND_ASSIGN(RenderText); | 342 DISALLOW_COPY_AND_ASSIGN(RenderText); |
310 }; | 343 }; |
311 | 344 |
312 } // namespace gfx | 345 } // namespace gfx |
313 | 346 |
314 #endif // UI_GFX_RENDER_TEXT_H_ | 347 #endif // UI_GFX_RENDER_TEXT_H_ |
OLD | NEW |