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

Side by Side Diff: ui/gfx/canvas.h

Issue 141003013: Clean-up: Removes obsolete methods in gfx::Canvas. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Synced. Created 6 years, 10 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
« no previous file with comments | « no previous file | ui/gfx/canvas.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 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_GFX_CANVAS_H_ 5 #ifndef UI_GFX_CANVAS_H_
6 #define UI_GFX_CANVAS_H_ 6 #define UI_GFX_CANVAS_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 27 matching lines...) Expand all
38 // source and destination colors are combined. Unless otherwise specified, 38 // source and destination colors are combined. Unless otherwise specified,
39 // the variant that does not take a SkXfermode::Mode uses a transfer mode 39 // the variant that does not take a SkXfermode::Mode uses a transfer mode
40 // of kSrcOver_Mode. 40 // of kSrcOver_Mode.
41 class GFX_EXPORT Canvas { 41 class GFX_EXPORT Canvas {
42 public: 42 public:
43 enum TruncateFadeMode { 43 enum TruncateFadeMode {
44 TruncateFadeTail, 44 TruncateFadeTail,
45 TruncateFadeHead, 45 TruncateFadeHead,
46 }; 46 };
47 47
48 // Specifies the alignment for text rendered with the DrawStringInt method. 48 // Specifies the alignment for text rendered with the DrawStringRect method.
49 enum { 49 enum {
50 TEXT_ALIGN_LEFT = 1 << 0, 50 TEXT_ALIGN_LEFT = 1 << 0,
51 TEXT_ALIGN_CENTER = 1 << 1, 51 TEXT_ALIGN_CENTER = 1 << 1,
52 TEXT_ALIGN_RIGHT = 1 << 2, 52 TEXT_ALIGN_RIGHT = 1 << 2,
53 53
54 // Specifies the text consists of multiple lines. 54 // Specifies the text consists of multiple lines.
55 MULTI_LINE = 1 << 3, 55 MULTI_LINE = 1 << 3,
56 56
57 // By default DrawStringInt does not process the prefix ('&') character 57 // By default DrawStringRect does not process the prefix ('&') character
58 // specially. That is, the string "&foo" is rendered as "&foo". When 58 // specially. That is, the string "&foo" is rendered as "&foo". When
59 // rendering text from a resource that uses the prefix character for 59 // rendering text from a resource that uses the prefix character for
60 // mnemonics, the prefix should be processed and can be rendered as an 60 // mnemonics, the prefix should be processed and can be rendered as an
61 // underline (SHOW_PREFIX), or not rendered at all (HIDE_PREFIX). 61 // underline (SHOW_PREFIX), or not rendered at all (HIDE_PREFIX).
62 SHOW_PREFIX = 1 << 4, 62 SHOW_PREFIX = 1 << 4,
63 HIDE_PREFIX = 1 << 5, 63 HIDE_PREFIX = 1 << 5,
64 64
65 // Prevent ellipsizing 65 // Prevent ellipsizing
66 NO_ELLIPSIS = 1 << 6, 66 NO_ELLIPSIS = 1 << 6,
67 67
68 // Specifies if words can be split by new lines. 68 // Specifies if words can be split by new lines.
69 // This only works with MULTI_LINE. 69 // This only works with MULTI_LINE.
70 CHARACTER_BREAK = 1 << 7, 70 CHARACTER_BREAK = 1 << 7,
71 71
72 // Instructs DrawStringInt() to render the text using RTL directionality. 72 // Instructs DrawStringRect() to render the text using RTL directionality.
73 // In most cases, passing this flag is not necessary because information 73 // In most cases, passing this flag is not necessary because information
74 // about the text directionality is going to be embedded within the string 74 // about the text directionality is going to be embedded within the string
75 // in the form of special Unicode characters. However, we don't insert 75 // in the form of special Unicode characters. However, we don't insert
76 // directionality characters into strings if the locale is LTR because some 76 // directionality characters into strings if the locale is LTR because some
77 // platforms (for example, an English Windows XP with no RTL fonts 77 // platforms (for example, an English Windows XP with no RTL fonts
78 // installed) don't support these characters. Thus, this flag should be 78 // installed) don't support these characters. Thus, this flag should be
79 // used to render text using RTL directionality when the locale is LTR. 79 // used to render text using RTL directionality when the locale is LTR.
80 FORCE_RTL_DIRECTIONALITY = 1 << 8, 80 FORCE_RTL_DIRECTIONALITY = 1 << 8,
81 81
82 // Similar to FORCE_RTL_DIRECTIONALITY, but left-to-right. 82 // Similar to FORCE_RTL_DIRECTIONALITY, but left-to-right.
83 // See FORCE_RTL_DIRECTIONALITY for details. 83 // See FORCE_RTL_DIRECTIONALITY for details.
84 FORCE_LTR_DIRECTIONALITY = 1 << 9, 84 FORCE_LTR_DIRECTIONALITY = 1 << 9,
85 85
86 // Instructs DrawStringInt() to not use subpixel rendering. This is useful 86 // Instructs DrawStringRect() to not use subpixel rendering. This is useful
87 // when rendering text onto a fully- or partially-transparent background 87 // when rendering text onto a fully- or partially-transparent background
88 // that will later be blended with another image. 88 // that will later be blended with another image.
89 NO_SUBPIXEL_RENDERING = 1 << 10, 89 NO_SUBPIXEL_RENDERING = 1 << 10,
90 }; 90 };
91 91
92 // Creates an empty canvas with image_scale of 1x. 92 // Creates an empty canvas with image_scale of 1x.
93 Canvas(); 93 Canvas();
94 94
95 // Creates canvas with provided DIP |size| and |image_scale|. 95 // Creates canvas with provided DIP |size| and |image_scale|.
96 // If this canvas is not opaque, it's explicitly cleared to transparent before 96 // If this canvas is not opaque, it's explicitly cleared to transparent before
(...skipping 26 matching lines...) Expand all
123 // Attempts to fit the text with the provided width and height. Increases 123 // Attempts to fit the text with the provided width and height. Increases
124 // height and then width as needed to make the text fit. This method 124 // height and then width as needed to make the text fit. This method
125 // supports multiple lines. On Skia only a line_height can be specified and 125 // supports multiple lines. On Skia only a line_height can be specified and
126 // specifying a 0 value for it will cause the default height to be used. 126 // specifying a 0 value for it will cause the default height to be used.
127 static void SizeStringInt(const base::string16& text, 127 static void SizeStringInt(const base::string16& text,
128 const FontList& font_list, 128 const FontList& font_list,
129 int* width, 129 int* width,
130 int* height, 130 int* height,
131 int line_height, 131 int line_height,
132 int flags); 132 int flags);
133 // Obsolete version. Use the above version which takes FontList.
134 static void SizeStringInt(const base::string16& text,
135 const Font& font,
136 int* width,
137 int* height,
138 int line_height,
139 int flags);
140 133
141 // This is same as SizeStringInt except that fractional size is returned. 134 // This is same as SizeStringInt except that fractional size is returned.
142 // See comment in GetStringWidthF for its usage. 135 // See comment in GetStringWidthF for its usage.
143 static void SizeStringFloat(const base::string16& text, 136 static void SizeStringFloat(const base::string16& text,
144 const FontList& font_list, 137 const FontList& font_list,
145 float* width, 138 float* width,
146 float* height, 139 float* height,
147 int line_height, 140 int line_height,
148 int flags); 141 int flags);
149 142
150 // Returns the number of horizontal pixels needed to display the specified 143 // Returns the number of horizontal pixels needed to display the specified
151 // |text| with |font_list|. 144 // |text| with |font_list|.
152 static int GetStringWidth(const base::string16& text, 145 static int GetStringWidth(const base::string16& text,
153 const FontList& font_list); 146 const FontList& font_list);
154 // Obsolete version. Use the above version which takes FontList. 147 // Obsolete version. Use the above version which takes FontList.
155 static int GetStringWidth(const base::string16& text, const Font& font); 148 static int GetStringWidth(const base::string16& text, const Font& font);
156 149
157 // This is same as GetStringWidth except that fractional width is returned. 150 // This is same as GetStringWidth except that fractional width is returned.
158 // Use this method for the scenario that multiple string widths need to be 151 // Use this method for the scenario that multiple string widths need to be
159 // summed up. This is because GetStringWidth returns the ceiled width and 152 // summed up. This is because GetStringWidth returns the ceiled width and
160 // adding multiple ceiled widths could cause more precision loss for certain 153 // adding multiple ceiled widths could cause more precision loss for certain
161 // platform like Mac where the fractioal width is used. 154 // platform like Mac where the fractioal width is used.
162 static float GetStringWidthF(const base::string16& text, 155 static float GetStringWidthF(const base::string16& text,
163 const FontList& font_list); 156 const FontList& font_list);
164 157
165 // Returns the default text alignment to be used when drawing text on a 158 // Returns the default text alignment to be used when drawing text on a
166 // Canvas based on the directionality of the system locale language. 159 // Canvas based on the directionality of the system locale language.
167 // This function is used by Canvas::DrawStringInt when the text alignment 160 // This function is used by Canvas::DrawStringRect when the text alignment
168 // is not specified. 161 // is not specified.
169 // 162 //
170 // This function returns either Canvas::TEXT_ALIGN_LEFT or 163 // This function returns either Canvas::TEXT_ALIGN_LEFT or
171 // Canvas::TEXT_ALIGN_RIGHT. 164 // Canvas::TEXT_ALIGN_RIGHT.
172 static int DefaultCanvasTextAlignment(); 165 static int DefaultCanvasTextAlignment();
173 166
174 // Draws text with a 1-pixel halo around it of the given color. 167 // Draws text with a 1-pixel halo around it of the given color.
175 // On Windows, it allows ClearType to be drawn to an otherwise transparent 168 // On Windows, it allows ClearType to be drawn to an otherwise transparent
176 // bitmap for drag images. Drag images have only 1-bit of transparency, so 169 // bitmap for drag images. Drag images have only 1-bit of transparency, so
177 // we don't do any fancy blurring. 170 // we don't do any fancy blurring.
178 // On Linux, text with halo is created by stroking it with 2px |halo_color| 171 // On Linux, text with halo is created by stroking it with 2px |halo_color|
179 // then filling it with |text_color|. 172 // then filling it with |text_color|.
180 // On Mac, NOTIMPLEMENTED. 173 // On Mac, NOTIMPLEMENTED.
181 // TODO(dhollowa): Skia-native implementation is underway. Cut over to 174 // TODO(dhollowa): Skia-native implementation is underway. Cut over to
182 // that when ready. http::/crbug.com/109946 175 // that when ready. http::/crbug.com/109946
183 void DrawStringRectWithHalo(const base::string16& text, 176 void DrawStringRectWithHalo(const base::string16& text,
184 const FontList& font_list, 177 const FontList& font_list,
185 SkColor text_color, 178 SkColor text_color,
186 SkColor halo_color, 179 SkColor halo_color,
187 const Rect& display_rect, 180 const Rect& display_rect,
188 int flags); 181 int flags);
189 // Obsolete version. Use the above version which takes FontList.
190 void DrawStringWithHalo(const base::string16& text,
191 const Font& font,
192 SkColor text_color,
193 SkColor halo_color,
194 int x,
195 int y,
196 int w,
197 int h,
198 int flags);
199 182
200 // Extracts an ImageSkiaRep from the contents of this canvas. 183 // Extracts an ImageSkiaRep from the contents of this canvas.
201 ImageSkiaRep ExtractImageRep() const; 184 ImageSkiaRep ExtractImageRep() const;
202 185
203 // Draws a dashed rectangle of the specified color. 186 // Draws a dashed rectangle of the specified color.
204 void DrawDashedRect(const Rect& rect, SkColor color); 187 void DrawDashedRect(const Rect& rect, SkColor color);
205 188
206 // Saves a copy of the drawing state onto a stack, operating on this copy 189 // Saves a copy of the drawing state onto a stack, operating on this copy
207 // until a balanced call to Restore() is made. 190 // until a balanced call to Restore() is made.
208 void Save(); 191 void Save();
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 const SkPath& path, 332 const SkPath& path,
350 const SkPaint& paint); 333 const SkPaint& paint);
351 334
352 // Draws text with the specified color, fonts and location. The text is 335 // Draws text with the specified color, fonts and location. The text is
353 // aligned to the left, vertically centered, clipped to the region. If the 336 // aligned to the left, vertically centered, clipped to the region. If the
354 // text is too big, it is truncated and '...' is added to the end. 337 // text is too big, it is truncated and '...' is added to the end.
355 void DrawStringRect(const base::string16& text, 338 void DrawStringRect(const base::string16& text,
356 const FontList& font_list, 339 const FontList& font_list,
357 SkColor color, 340 SkColor color,
358 const Rect& display_rect); 341 const Rect& display_rect);
359 // Obsolete versions. Use the above versions which take FontList.
360 void DrawStringInt(const base::string16& text,
361 const Font& font,
362 SkColor color,
363 int x,
364 int y,
365 int w,
366 int h);
367 void DrawStringInt(const base::string16& text,
368 const Font& font,
369 SkColor color,
370 const Rect& display_rect);
371 342
372 // Draws text with the specified color, fonts and location. The last argument 343 // Draws text with the specified color, fonts and location. The last argument
373 // specifies flags for how the text should be rendered. It can be one of 344 // specifies flags for how the text should be rendered. It can be one of
374 // TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT or TEXT_ALIGN_LEFT. 345 // TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT or TEXT_ALIGN_LEFT.
375 void DrawStringRectWithFlags(const base::string16& text, 346 void DrawStringRectWithFlags(const base::string16& text,
376 const FontList& font_list, 347 const FontList& font_list,
377 SkColor color, 348 SkColor color,
378 const Rect& display_rect, 349 const Rect& display_rect,
379 int flags); 350 int flags);
380 // Obsolete version. Use the above version which takes FontList.
381 void DrawStringInt(const base::string16& text,
382 const Font& font,
383 SkColor color,
384 int x,
385 int y,
386 int w,
387 int h,
388 int flags);
389 351
390 // Similar to above DrawStringInt method but with text shadows support. 352 // Similar to above DrawStringRect method but with text shadows support.
391 // Currently it's only implemented for canvas skia. Specifying a 0 line_height 353 // Currently it's only implemented for canvas skia. Specifying a 0 line_height
392 // will cause the default height to be used. 354 // will cause the default height to be used.
393 void DrawStringRectWithShadows(const base::string16& text, 355 void DrawStringRectWithShadows(const base::string16& text,
394 const FontList& font_list, 356 const FontList& font_list,
395 SkColor color, 357 SkColor color,
396 const Rect& text_bounds, 358 const Rect& text_bounds,
397 int line_height, 359 int line_height,
398 int flags, 360 int flags,
399 const ShadowValues& shadows); 361 const ShadowValues& shadows);
400 // Obsolete version. Use the above version which takes FontList.
401 void DrawStringWithShadows(const base::string16& text,
402 const Font& font,
403 SkColor color,
404 const Rect& text_bounds,
405 int line_height,
406 int flags,
407 const ShadowValues& shadows);
408 362
409 // Draws a dotted gray rectangle used for focus purposes. 363 // Draws a dotted gray rectangle used for focus purposes.
410 void DrawFocusRect(const Rect& rect); 364 void DrawFocusRect(const Rect& rect);
411 365
412 // Draws a |rect| in the specified region with the specified |color| with a 366 // Draws a |rect| in the specified region with the specified |color| with a
413 // with of one logical pixel which might be more device pixels. 367 // with of one logical pixel which might be more device pixels.
414 void DrawSolidFocusRect(const Rect& rect, SkColor color); 368 void DrawSolidFocusRect(const Rect& rect, SkColor color);
415 369
416 // Tiles the image in the specified region. 370 // Tiles the image in the specified region.
417 // Parameters are specified relative to current canvas scale not in pixels. 371 // Parameters are specified relative to current canvas scale not in pixels.
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 447
494 skia::RefPtr<skia::PlatformCanvas> owned_canvas_; 448 skia::RefPtr<skia::PlatformCanvas> owned_canvas_;
495 SkCanvas* canvas_; 449 SkCanvas* canvas_;
496 450
497 DISALLOW_COPY_AND_ASSIGN(Canvas); 451 DISALLOW_COPY_AND_ASSIGN(Canvas);
498 }; 452 };
499 453
500 } // namespace gfx 454 } // namespace gfx
501 455
502 #endif // UI_GFX_CANVAS_H_ 456 #endif // UI_GFX_CANVAS_H_
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/canvas.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698