Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 | 103 |
| 104 if (flags & Canvas::TEXT_ALIGN_TO_HEAD) | 104 if (flags & Canvas::TEXT_ALIGN_TO_HEAD) |
| 105 render_text->SetHorizontalAlignment(ALIGN_TO_HEAD); | 105 render_text->SetHorizontalAlignment(ALIGN_TO_HEAD); |
| 106 else if (flags & Canvas::TEXT_ALIGN_RIGHT) | 106 else if (flags & Canvas::TEXT_ALIGN_RIGHT) |
| 107 render_text->SetHorizontalAlignment(ALIGN_RIGHT); | 107 render_text->SetHorizontalAlignment(ALIGN_RIGHT); |
| 108 else if (flags & Canvas::TEXT_ALIGN_CENTER) | 108 else if (flags & Canvas::TEXT_ALIGN_CENTER) |
| 109 render_text->SetHorizontalAlignment(ALIGN_CENTER); | 109 render_text->SetHorizontalAlignment(ALIGN_CENTER); |
| 110 else | 110 else |
| 111 render_text->SetHorizontalAlignment(ALIGN_LEFT); | 111 render_text->SetHorizontalAlignment(ALIGN_LEFT); |
| 112 | 112 |
| 113 render_text->SetMultiline((flags & Canvas::MULTI_LINE) != 0); | |
|
msw
2015/04/01 15:07:17
This will break RenderTextMac, which doesn't suppo
| |
| 114 | |
| 115 if (flags & Canvas::TEXT_ALIGN_TOP) | |
| 116 render_text->SetVerticalAlignment(VALIGN_TOP); | |
| 117 else if (flags & Canvas::TEXT_ALIGN_BOTTOM) | |
| 118 render_text->SetVerticalAlignment(VALIGN_BOTTOM); | |
| 119 else | |
| 120 render_text->SetVerticalAlignment(VALIGN_MIDDLE); | |
| 121 | |
| 113 render_text->set_subpixel_rendering_suppressed( | 122 render_text->set_subpixel_rendering_suppressed( |
| 114 (flags & Canvas::NO_SUBPIXEL_RENDERING) != 0); | 123 (flags & Canvas::NO_SUBPIXEL_RENDERING) != 0); |
| 115 | 124 |
| 116 render_text->SetColor(color); | 125 render_text->SetColor(color); |
| 117 const int font_style = font_list.GetFontStyle(); | 126 const int font_style = font_list.GetFontStyle(); |
| 118 render_text->SetStyle(BOLD, (font_style & Font::BOLD) != 0); | 127 render_text->SetStyle(BOLD, (font_style & Font::BOLD) != 0); |
| 119 render_text->SetStyle(ITALIC, (font_style & Font::ITALIC) != 0); | 128 render_text->SetStyle(ITALIC, (font_style & Font::ITALIC) != 0); |
| 120 render_text->SetStyle(UNDERLINE, (font_style & Font::UNDERLINE) != 0); | 129 render_text->SetStyle(UNDERLINE, (font_style & Font::UNDERLINE) != 0); |
| 121 } | 130 } |
| 122 | 131 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 clip_rect.Inset(ShadowValue::GetMargin(shadows)); | 195 clip_rect.Inset(ShadowValue::GetMargin(shadows)); |
| 187 | 196 |
| 188 canvas_->save(); | 197 canvas_->save(); |
| 189 ClipRect(clip_rect); | 198 ClipRect(clip_rect); |
| 190 | 199 |
| 191 Rect rect(text_bounds); | 200 Rect rect(text_bounds); |
| 192 | 201 |
| 193 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | 202 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
| 194 render_text->set_shadows(shadows); | 203 render_text->set_shadows(shadows); |
| 195 | 204 |
| 196 if (flags & MULTI_LINE) { | 205 base::string16 adjusted_text = text; |
| 197 WordWrapBehavior wrap_behavior = IGNORE_LONG_WORDS; | 206 Range range = StripAcceleratorChars(flags, &adjusted_text); |
|
msw
2015/04/01 15:07:17
The new code should configure RenderText's word wr
| |
| 198 if (flags & CHARACTER_BREAK) | 207 bool elide_text = ((flags & NO_ELLIPSIS) == 0); |
| 199 wrap_behavior = WRAP_LONG_WORDS; | |
| 200 else if (!(flags & NO_ELLIPSIS)) | |
| 201 wrap_behavior = ELIDE_LONG_WORDS; | |
|
msw
2015/04/01 15:07:17
RenderTextHarfBuzz doesn't yet support ELIDE_LONG_
| |
| 202 | 208 |
| 203 std::vector<base::string16> strings; | 209 #if defined(OS_LINUX) |
| 204 ElideRectangleText(text, font_list, | 210 // On Linux, eliding really means fading the end of the string. But only |
| 205 static_cast<float>(text_bounds.width()), | 211 // for LTR text. RTL text is still elided (on the left) with "...". |
| 206 text_bounds.height(), wrap_behavior, &strings); | 212 if (elide_text) { |
| 207 | 213 render_text->SetText(adjusted_text); |
| 208 for (size_t i = 0; i < strings.size(); i++) { | 214 if (render_text->GetDisplayTextDirection() == base::i18n::LEFT_TO_RIGHT) { |
| 209 Range range = StripAcceleratorChars(flags, &strings[i]); | 215 render_text->SetElideBehavior(FADE_TAIL); |
| 210 UpdateRenderText(rect, strings[i], font_list, flags, color, | 216 elide_text = false; |
| 211 render_text.get()); | 217 } |
| 212 int line_padding = 0; | 218 } |
| 213 if (line_height > 0) | |
| 214 line_padding = line_height - render_text->GetStringSize().height(); | |
| 215 else | |
| 216 line_height = render_text->GetStringSize().height(); | |
| 217 | |
| 218 // TODO(msw|asvitkine): Center Windows multi-line text: crbug.com/107357 | |
| 219 #if !defined(OS_WIN) | |
| 220 if (i == 0) { | |
| 221 // TODO(msw|asvitkine): Support multi-line text with varied heights. | |
| 222 const int text_height = strings.size() * line_height - line_padding; | |
| 223 rect += Vector2d(0, (text_bounds.height() - text_height) / 2); | |
| 224 } | |
| 225 #endif | 219 #endif |
| 226 | 220 |
| 227 rect.set_height(line_height - line_padding); | 221 if (elide_text) { |
| 222 ElideTextAndAdjustRange(font_list, static_cast<float>(text_bounds.width()), | |
| 223 &adjusted_text, &range); | |
| 224 } | |
| 228 | 225 |
| 229 if (range.IsValid()) | 226 UpdateRenderText(rect, adjusted_text, font_list, flags, color, |
| 230 render_text->ApplyStyle(UNDERLINE, true, range); | 227 render_text.get()); |
| 231 render_text->SetDisplayRect(rect); | 228 if (range.IsValid()) |
| 232 render_text->Draw(this); | 229 render_text->ApplyStyle(UNDERLINE, true, range); |
| 233 rect += Vector2d(0, line_height); | 230 render_text->Draw(this); |
| 234 } | |
| 235 } else { | |
| 236 base::string16 adjusted_text = text; | |
| 237 Range range = StripAcceleratorChars(flags, &adjusted_text); | |
| 238 bool elide_text = ((flags & NO_ELLIPSIS) == 0); | |
| 239 | |
| 240 #if defined(OS_LINUX) | |
| 241 // On Linux, eliding really means fading the end of the string. But only | |
| 242 // for LTR text. RTL text is still elided (on the left) with "...". | |
| 243 if (elide_text) { | |
| 244 render_text->SetText(adjusted_text); | |
| 245 if (render_text->GetDisplayTextDirection() == base::i18n::LEFT_TO_RIGHT) { | |
| 246 render_text->SetElideBehavior(FADE_TAIL); | |
| 247 elide_text = false; | |
| 248 } | |
| 249 } | |
| 250 #endif | |
| 251 | |
| 252 if (elide_text) { | |
| 253 ElideTextAndAdjustRange(font_list, | |
| 254 static_cast<float>(text_bounds.width()), | |
| 255 &adjusted_text, &range); | |
| 256 } | |
| 257 | |
| 258 UpdateRenderText(rect, adjusted_text, font_list, flags, color, | |
| 259 render_text.get()); | |
| 260 if (range.IsValid()) | |
| 261 render_text->ApplyStyle(UNDERLINE, true, range); | |
| 262 render_text->Draw(this); | |
| 263 } | |
| 264 | 231 |
| 265 canvas_->restore(); | 232 canvas_->restore(); |
| 266 } | 233 } |
| 267 | 234 |
| 268 void Canvas::DrawStringRectWithHalo(const base::string16& text, | 235 void Canvas::DrawStringRectWithHalo(const base::string16& text, |
| 269 const FontList& font_list, | 236 const FontList& font_list, |
| 270 SkColor text_color, | 237 SkColor text_color, |
| 271 SkColor halo_color_in, | 238 SkColor halo_color_in, |
| 272 const Rect& display_rect, | 239 const Rect& display_rect, |
| 273 int flags) { | 240 int flags) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 UpdateRenderText(rect, text, font_list, flags, color, render_text.get()); | 301 UpdateRenderText(rect, text, font_list, flags, color, render_text.get()); |
| 335 render_text->SetElideBehavior(FADE_TAIL); | 302 render_text->SetElideBehavior(FADE_TAIL); |
| 336 | 303 |
| 337 canvas_->save(); | 304 canvas_->save(); |
| 338 ClipRect(display_rect); | 305 ClipRect(display_rect); |
| 339 render_text->Draw(this); | 306 render_text->Draw(this); |
| 340 canvas_->restore(); | 307 canvas_->restore(); |
| 341 } | 308 } |
| 342 | 309 |
| 343 } // namespace gfx | 310 } // namespace gfx |
| OLD | NEW |