| 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/base/range/range.h" | 10 #include "ui/base/range/range.h" |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 for (size_t i = 0; i < strings.size(); i++) { | 281 for (size_t i = 0; i < strings.size(); i++) { |
| 282 ui::Range range = StripAcceleratorChars(flags, &strings[i]); | 282 ui::Range range = StripAcceleratorChars(flags, &strings[i]); |
| 283 UpdateRenderText(rect, strings[i], font, flags, color, render_text.get()); | 283 UpdateRenderText(rect, strings[i], font, flags, color, render_text.get()); |
| 284 const int line_height = render_text->GetStringSize().height(); | 284 const int line_height = render_text->GetStringSize().height(); |
| 285 | 285 |
| 286 // TODO(msw|asvitkine): Center Windows multi-line text: crbug.com/107357 | 286 // TODO(msw|asvitkine): Center Windows multi-line text: crbug.com/107357 |
| 287 #if !defined(OS_WIN) | 287 #if !defined(OS_WIN) |
| 288 if (i == 0) { | 288 if (i == 0) { |
| 289 // TODO(msw|asvitkine): Support multi-line text with varied heights. | 289 // TODO(msw|asvitkine): Support multi-line text with varied heights. |
| 290 const int aggregate_height = strings.size() * line_height; | 290 const int aggregate_height = strings.size() * line_height; |
| 291 rect.Offset(0, (text_bounds.height() - aggregate_height) / 2); | 291 rect += gfx::Vector2d(0, (text_bounds.height() - aggregate_height) / 2); |
| 292 } | 292 } |
| 293 #endif | 293 #endif |
| 294 | 294 |
| 295 rect.set_height(line_height); | 295 rect.set_height(line_height); |
| 296 | 296 |
| 297 ApplyUnderlineStyle(range, render_text.get()); | 297 ApplyUnderlineStyle(range, render_text.get()); |
| 298 render_text->SetDisplayRect(rect); | 298 render_text->SetDisplayRect(rect); |
| 299 render_text->Draw(this); | 299 render_text->Draw(this); |
| 300 rect.Offset(0, line_height); | 300 rect += gfx::Vector2d(0, line_height); |
| 301 } | 301 } |
| 302 } else { | 302 } else { |
| 303 ui::Range range = StripAcceleratorChars(flags, &adjusted_text); | 303 ui::Range range = StripAcceleratorChars(flags, &adjusted_text); |
| 304 bool elide_text = ((flags & NO_ELLIPSIS) == 0); | 304 bool elide_text = ((flags & NO_ELLIPSIS) == 0); |
| 305 | 305 |
| 306 #if defined(OS_LINUX) | 306 #if defined(OS_LINUX) |
| 307 // On Linux, eliding really means fading the end of the string. But only | 307 // On Linux, eliding really means fading the end of the string. But only |
| 308 // for LTR text. RTL text is still elided (on the left) with "...". | 308 // for LTR text. RTL text is still elided (on the left) with "...". |
| 309 if (elide_text) { | 309 if (elide_text) { |
| 310 render_text->SetText(adjusted_text); | 310 render_text->SetText(adjusted_text); |
| 311 if (render_text->GetTextDirection() == base::i18n::LEFT_TO_RIGHT) { | 311 if (render_text->GetTextDirection() == base::i18n::LEFT_TO_RIGHT) { |
| 312 render_text->set_fade_tail(true); | 312 render_text->set_fade_tail(true); |
| 313 elide_text = false; | 313 elide_text = false; |
| 314 } | 314 } |
| 315 } | 315 } |
| 316 #endif | 316 #endif |
| 317 | 317 |
| 318 if (elide_text) { | 318 if (elide_text) { |
| 319 ElideTextAndAdjustRange(font, | 319 ElideTextAndAdjustRange(font, |
| 320 text_bounds.width(), | 320 text_bounds.width(), |
| 321 &adjusted_text, | 321 &adjusted_text, |
| 322 &range); | 322 &range); |
| 323 } | 323 } |
| 324 | 324 |
| 325 UpdateRenderText(rect, adjusted_text, font, flags, color, | 325 UpdateRenderText(rect, adjusted_text, font, flags, color, |
| 326 render_text.get()); | 326 render_text.get()); |
| 327 | 327 |
| 328 const int line_height = render_text->GetStringSize().height(); | 328 const int line_height = render_text->GetStringSize().height(); |
| 329 // Center the text vertically. | 329 // Center the text vertically. |
| 330 rect.Offset(0, (text_bounds.height() - line_height) / 2); | 330 rect += gfx::Vector2d(0, (text_bounds.height() - line_height) / 2); |
| 331 rect.set_height(line_height); | 331 rect.set_height(line_height); |
| 332 render_text->SetDisplayRect(rect); | 332 render_text->SetDisplayRect(rect); |
| 333 | 333 |
| 334 ApplyUnderlineStyle(range, render_text.get()); | 334 ApplyUnderlineStyle(range, render_text.get()); |
| 335 render_text->Draw(this); | 335 render_text->Draw(this); |
| 336 } | 336 } |
| 337 | 337 |
| 338 canvas_->restore(); | 338 canvas_->restore(); |
| 339 } | 339 } |
| 340 | 340 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 | 439 |
| 440 // Default to left alignment unless right alignment was chosen above. | 440 // Default to left alignment unless right alignment was chosen above. |
| 441 if (!(flags & TEXT_ALIGN_RIGHT)) | 441 if (!(flags & TEXT_ALIGN_RIGHT)) |
| 442 flags |= TEXT_ALIGN_LEFT; | 442 flags |= TEXT_ALIGN_LEFT; |
| 443 | 443 |
| 444 gfx::Rect rect = display_rect; | 444 gfx::Rect rect = display_rect; |
| 445 UpdateRenderText(rect, clipped_text, font, flags, color, render_text.get()); | 445 UpdateRenderText(rect, clipped_text, font, flags, color, render_text.get()); |
| 446 | 446 |
| 447 const int line_height = render_text->GetStringSize().height(); | 447 const int line_height = render_text->GetStringSize().height(); |
| 448 // Center the text vertically. | 448 // Center the text vertically. |
| 449 rect.Offset(0, (display_rect.height() - line_height) / 2); | 449 rect += gfx::Vector2d(0, (display_rect.height() - line_height) / 2); |
| 450 rect.set_height(line_height); | 450 rect.set_height(line_height); |
| 451 render_text->SetDisplayRect(rect); | 451 render_text->SetDisplayRect(rect); |
| 452 | 452 |
| 453 canvas_->save(SkCanvas::kClip_SaveFlag); | 453 canvas_->save(SkCanvas::kClip_SaveFlag); |
| 454 ClipRect(display_rect); | 454 ClipRect(display_rect); |
| 455 render_text->Draw(this); | 455 render_text->Draw(this); |
| 456 canvas_->restore(); | 456 canvas_->restore(); |
| 457 } | 457 } |
| 458 | 458 |
| 459 } // namespace gfx | 459 } // namespace gfx |
| OLD | NEW |