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

Side by Side Diff: ui/gfx/canvas_skia.cc

Issue 26291002: Remove Linux-specific canvas_skia.cc hack. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 2 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 | no next file » | 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 #include "ui/gfx/canvas.h" 5 #include "ui/gfx/canvas.h"
6 6
7 #include "base/i18n/rtl.h" 7 #include "base/i18n/rtl.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "ui/gfx/font_list.h" 10 #include "ui/gfx/font_list.h"
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 if (flags & Canvas::NO_SUBPIXEL_RENDERING) 145 if (flags & Canvas::NO_SUBPIXEL_RENDERING)
146 render_text->set_background_is_transparent(true); 146 render_text->set_background_is_transparent(true);
147 147
148 render_text->SetColor(color); 148 render_text->SetColor(color);
149 const int font_style = font_list.GetFontStyle(); 149 const int font_style = font_list.GetFontStyle();
150 render_text->SetStyle(BOLD, (font_style & Font::BOLD) != 0); 150 render_text->SetStyle(BOLD, (font_style & Font::BOLD) != 0);
151 render_text->SetStyle(ITALIC, (font_style & Font::ITALIC) != 0); 151 render_text->SetStyle(ITALIC, (font_style & Font::ITALIC) != 0);
152 render_text->SetStyle(UNDERLINE, (font_style & Font::UNDERLINE) != 0); 152 render_text->SetStyle(UNDERLINE, (font_style & Font::UNDERLINE) != 0);
153 } 153 }
154 154
155 // Returns updated |flags| to match platform-specific expected behavior.
156 int AdjustPlatformSpecificFlags(const base::string16& text, int flags) {
157 #if defined(OS_LINUX)
158 // TODO(asvitkine): ash/tooltips/tooltip_controller.cc adds \n's to the string
159 // without passing MULTI_LINE.
160 if (text.find('\n') != base::string16::npos)
161 flags |= Canvas::MULTI_LINE;
162 #endif
163
164 return flags;
165 }
166
167 } // namespace 155 } // namespace
168 156
169 // static 157 // static
170 void Canvas::SizeStringInt(const base::string16& text, 158 void Canvas::SizeStringInt(const base::string16& text,
171 const FontList& font_list, 159 const FontList& font_list,
172 int* width, int* height, 160 int* width, int* height,
173 int line_height, 161 int line_height,
174 int flags) { 162 int flags) {
175 DCHECK_GE(*width, 0); 163 DCHECK_GE(*width, 0);
176 DCHECK_GE(*height, 0); 164 DCHECK_GE(*height, 0);
177 165
178 flags = AdjustPlatformSpecificFlags(text, flags);
179
180 base::string16 adjusted_text = text; 166 base::string16 adjusted_text = text;
181 #if defined(OS_WIN) 167 #if defined(OS_WIN)
182 AdjustStringDirection(flags, &adjusted_text); 168 AdjustStringDirection(flags, &adjusted_text);
183 #endif 169 #endif
184 170
185 if ((flags & MULTI_LINE) && *width != 0) { 171 if ((flags & MULTI_LINE) && *width != 0) {
186 gfx::WordWrapBehavior wrap_behavior = gfx::TRUNCATE_LONG_WORDS; 172 gfx::WordWrapBehavior wrap_behavior = gfx::TRUNCATE_LONG_WORDS;
187 if (flags & CHARACTER_BREAK) 173 if (flags & CHARACTER_BREAK)
188 wrap_behavior = gfx::WRAP_LONG_WORDS; 174 wrap_behavior = gfx::WRAP_LONG_WORDS;
189 else if (!(flags & NO_ELLIPSIS)) 175 else if (!(flags & NO_ELLIPSIS))
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 void Canvas::DrawStringRectWithShadows(const base::string16& text, 218 void Canvas::DrawStringRectWithShadows(const base::string16& text,
233 const FontList& font_list, 219 const FontList& font_list,
234 SkColor color, 220 SkColor color,
235 const Rect& text_bounds, 221 const Rect& text_bounds,
236 int line_height, 222 int line_height,
237 int flags, 223 int flags,
238 const ShadowValues& shadows) { 224 const ShadowValues& shadows) {
239 if (!IntersectsClipRect(text_bounds)) 225 if (!IntersectsClipRect(text_bounds))
240 return; 226 return;
241 227
242 flags = AdjustPlatformSpecificFlags(text, flags);
243
244 Rect clip_rect(text_bounds); 228 Rect clip_rect(text_bounds);
245 clip_rect.Inset(ShadowValue::GetMargin(shadows)); 229 clip_rect.Inset(ShadowValue::GetMargin(shadows));
246 230
247 canvas_->save(SkCanvas::kClip_SaveFlag); 231 canvas_->save(SkCanvas::kClip_SaveFlag);
248 ClipRect(clip_rect); 232 ClipRect(clip_rect);
249 233
250 Rect rect(text_bounds); 234 Rect rect(text_bounds);
251 base::string16 adjusted_text = text; 235 base::string16 adjusted_text = text;
252 236
253 #if defined(OS_WIN) 237 #if defined(OS_WIN)
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 size_t desired_characters_to_truncate_from_head, 447 size_t desired_characters_to_truncate_from_head,
464 const Font& font, 448 const Font& font,
465 SkColor color, 449 SkColor color,
466 const Rect& display_rect) { 450 const Rect& display_rect) {
467 DrawFadeTruncatingStringRect(text, truncate_mode, 451 DrawFadeTruncatingStringRect(text, truncate_mode,
468 desired_characters_to_truncate_from_head, 452 desired_characters_to_truncate_from_head,
469 FontList(font), color, display_rect); 453 FontList(font), color, display_rect);
470 } 454 }
471 455
472 } // namespace gfx 456 } // namespace gfx
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698