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

Side by Side Diff: ui/views/view_text_utils.h

Issue 9562038: ui/gfx: Make gfx::Canvas inherit from gfx::CanvasSkia. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more fixes Created 8 years, 9 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_VIEWS_VIEW_TEXT_UTILS_H_ 5 #ifndef UI_VIEWS_VIEW_TEXT_UTILS_H_
6 #define UI_VIEWS_VIEW_TEXT_UTILS_H_ 6 #define UI_VIEWS_VIEW_TEXT_UTILS_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/string16.h" 9 #include "base/string16.h"
10 #include "ui/views/views_export.h" 10 #include "ui/views/views_export.h"
11 11
12 namespace gfx { 12 namespace gfx {
13 class Canvas; 13 class CanvasSkia;
14 class Font; 14 class Font;
15 class Rect; 15 class Rect;
16 class Size; 16 class Size;
17 } 17 }
18 18
19 namespace views { 19 namespace views {
20 class Label; 20 class Label;
21 class Link; 21 class Link;
22 } 22 }
23 23
24 // This file defines utility functions for working with text in views. 24 // This file defines utility functions for working with text in views.
25 25
26 namespace view_text_utils { 26 namespace view_text_utils {
27 27
28 // Draws a string onto the canvas (wrapping if needed) while also keeping 28 // Draws a string onto the canvas (wrapping if needed) while also keeping
29 // track of where it ends so we can position a URL after the text. The 29 // track of where it ends so we can position a URL after the text. The
30 // parameter |bounds| represents the boundary we have to work with, |position| 30 // parameter |bounds| represents the boundary we have to work with, |position|
31 // specifies where to draw the string (relative to the top left corner of the 31 // specifies where to draw the string (relative to the top left corner of the
32 // |bounds| rectangle and |font| specifies the font to use when drawing. When 32 // |bounds| rectangle and |font| specifies the font to use when drawing. When
33 // the function returns, the parameter |rect| contains where to draw the URL 33 // the function returns, the parameter |rect| contains where to draw the URL
34 // (to the right of where we just drew the text) and |position| is updated to 34 // (to the right of where we just drew the text) and |position| is updated to
35 // reflect where to draw the next string after the URL. |label| is a dummy 35 // reflect where to draw the next string after the URL. |label| is a dummy
36 // label with the correct width and origin for the text to be written; it's 36 // label with the correct width and origin for the text to be written; it's
37 // used so that the x position can be correctly mirrored in RTL languages. 37 // used so that the x position can be correctly mirrored in RTL languages.
38 // |text_direction_is_rtl| is true if an RTL language is being used. 38 // |text_direction_is_rtl| is true if an RTL language is being used.
39 // NOTE: The reason why we need this function is because while Skia knows how 39 // NOTE: The reason why we need this function is because while Skia knows how
40 // to wrap text appropriately, it doesn't tell us where it drew the last 40 // to wrap text appropriately, it doesn't tell us where it drew the last
41 // character, which we need to position the URLs within the text. 41 // character, which we need to position the URLs within the text.
42 VIEWS_EXPORT void DrawTextAndPositionUrl(gfx::Canvas* canvas, 42 VIEWS_EXPORT void DrawTextAndPositionUrl(gfx::CanvasSkia* canvas,
43 views::Label* label, 43 views::Label* label,
44 const string16& text, 44 const string16& text,
45 views::Link* link, 45 views::Link* link,
46 gfx::Rect* rect, 46 gfx::Rect* rect,
47 gfx::Size* position, 47 gfx::Size* position,
48 bool text_direction_is_rtl, 48 bool text_direction_is_rtl,
49 const gfx::Rect& bounds, 49 const gfx::Rect& bounds,
50 const gfx::Font& font); 50 const gfx::Font& font);
51 51
52 // A helper function for DrawTextAndPositionUrl, which simply draws the text 52 // A helper function for DrawTextAndPositionUrl, which simply draws the text
53 // from a certain starting point |position| and wraps within bounds. 53 // from a certain starting point |position| and wraps within bounds.
54 // |word_for_word| specifies whether to draw the text word for word or whether 54 // |word_for_word| specifies whether to draw the text word for word or whether
55 // to treat the text as one blurb (similar to the way URL's are treated inside 55 // to treat the text as one blurb (similar to the way URL's are treated inside
56 // RTL text. For details on the other parameters, see DrawTextAndPositionUrl. 56 // RTL text. For details on the other parameters, see DrawTextAndPositionUrl.
57 void DrawTextStartingFrom(gfx::Canvas* canvas, 57 void DrawTextStartingFrom(gfx::CanvasSkia* canvas,
58 views::Label* label, 58 views::Label* label,
59 const string16& text, 59 const string16& text,
60 gfx::Size* position, 60 gfx::Size* position,
61 const gfx::Rect& bounds, 61 const gfx::Rect& bounds,
62 const gfx::Font& font, 62 const gfx::Font& font,
63 bool text_direction_is_rtl, 63 bool text_direction_is_rtl,
64 bool word_for_word); 64 bool word_for_word);
65 65
66 // A simply utility function that calculates whether a word of width 66 // A simply utility function that calculates whether a word of width
67 // |word_width| fits at position |position| within the |bounds| rectangle. If 67 // |word_width| fits at position |position| within the |bounds| rectangle. If
68 // not, |position| is updated to wrap to the beginning of the next line. 68 // not, |position| is updated to wrap to the beginning of the next line.
69 void WrapIfWordDoesntFit(int word_width, 69 void WrapIfWordDoesntFit(int word_width,
70 int font_height, 70 int font_height,
71 gfx::Size* position, 71 gfx::Size* position,
72 const gfx::Rect& bounds); 72 const gfx::Rect& bounds);
73 73
74 } // namespace view_text_utils 74 } // namespace view_text_utils
75 75
76 #endif // UI_VIEWS_VIEW_TEXT_UTILS_H_ 76 #endif // UI_VIEWS_VIEW_TEXT_UTILS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698