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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 | 271 |
242 // Apply composition style (underline) to composition range and selection | 272 // Apply composition style (underline) to composition range and selection |
243 // style (foreground) to selection range. | 273 // style (foreground) to selection range. |
244 void ApplyCompositionAndSelectionStyles(StyleRanges* style_ranges) const; | 274 void ApplyCompositionAndSelectionStyles(StyleRanges* style_ranges) const; |
245 | 275 |
246 // Convert points from the text space to the view space and back. | 276 // Convert points from the text space to the view space and back. |
247 // Handles the display area, display offset, and the application LTR/RTL mode. | 277 // Handles the display area, display offset, and the application LTR/RTL mode. |
248 Point ToTextPoint(const Point& point); | 278 Point ToTextPoint(const Point& point); |
249 Point ToViewPoint(const Point& point); | 279 Point ToViewPoint(const Point& point); |
250 | 280 |
| 281 // Returns the origin point for drawing text via Skia. |
| 282 Point GetOriginForSkiaDrawing(); |
| 283 |
251 private: | 284 private: |
252 friend class RenderTextTest; | 285 friend class RenderTextTest; |
253 | 286 |
254 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); | 287 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); |
255 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, CustomDefaultStyle); | 288 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, CustomDefaultStyle); |
256 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyStyleRange); | 289 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyStyleRange); |
257 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StyleRangesAdjust); | 290 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StyleRangesAdjust); |
258 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GraphemePositions); | 291 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GraphemePositions); |
259 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, SelectionModels); | 292 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, SelectionModels); |
260 | 293 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 // The cached bounds and offset are invalidated by changes to the cursor, | 346 // The cached bounds and offset are invalidated by changes to the cursor, |
314 // selection, font, and other operations that adjust the visible text bounds. | 347 // selection, font, and other operations that adjust the visible text bounds. |
315 bool cached_bounds_and_offset_valid_; | 348 bool cached_bounds_and_offset_valid_; |
316 | 349 |
317 DISALLOW_COPY_AND_ASSIGN(RenderText); | 350 DISALLOW_COPY_AND_ASSIGN(RenderText); |
318 }; | 351 }; |
319 | 352 |
320 } // namespace gfx | 353 } // namespace gfx |
321 | 354 |
322 #endif // UI_GFX_RENDER_TEXT_H_ | 355 #endif // UI_GFX_RENDER_TEXT_H_ |
OLD | NEW |