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/render_text.h" | 5 #include "ui/gfx/render_text.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <climits> | 8 #include <climits> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 paint->setSubpixelText(params.subpixel_positioning); | 395 paint->setSubpixelText(params.subpixel_positioning); |
396 paint->setAutohinted(params.autohinter); | 396 paint->setAutohinted(params.autohinter); |
397 paint->setHinting(FontRenderParamsHintingToSkPaintHinting(params.hinting)); | 397 paint->setHinting(FontRenderParamsHintingToSkPaintHinting(params.hinting)); |
398 } | 398 } |
399 | 399 |
400 } // namespace internal | 400 } // namespace internal |
401 | 401 |
402 RenderText::~RenderText() { | 402 RenderText::~RenderText() { |
403 } | 403 } |
404 | 404 |
| 405 // static |
405 RenderText* RenderText::CreateInstance() { | 406 RenderText* RenderText::CreateInstance() { |
406 #if defined(OS_MACOSX) | 407 #if defined(OS_MACOSX) |
407 static const bool use_native = | 408 static const bool use_native = |
408 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 409 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
409 switches::kEnableHarfBuzzRenderText); | 410 switches::kEnableHarfBuzzRenderText); |
410 if (use_native) | 411 if (use_native) |
411 return new RenderTextMac; | 412 return new RenderTextMac; |
412 #endif // defined(OS_MACOSX) | 413 #endif // defined(OS_MACOSX) |
413 return new RenderTextHarfBuzz; | 414 return new RenderTextHarfBuzz; |
414 } | 415 } |
415 | 416 |
| 417 // static |
416 RenderText* RenderText::CreateInstanceForEditing() { | 418 RenderText* RenderText::CreateInstanceForEditing() { |
417 return new RenderTextHarfBuzz; | 419 return new RenderTextHarfBuzz; |
418 } | 420 } |
419 | 421 |
420 void RenderText::SetText(const base::string16& text) { | 422 void RenderText::SetText(const base::string16& text) { |
421 DCHECK(!composition_range_.IsValid()); | 423 DCHECK(!composition_range_.IsValid()); |
422 if (text_ == text) | 424 if (text_ == text) |
423 return; | 425 return; |
424 text_ = text; | 426 text_ = text; |
425 | 427 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 | 498 |
497 void RenderText::SetMultiline(bool multiline) { | 499 void RenderText::SetMultiline(bool multiline) { |
498 if (multiline != multiline_) { | 500 if (multiline != multiline_) { |
499 multiline_ = multiline; | 501 multiline_ = multiline; |
500 cached_bounds_and_offset_valid_ = false; | 502 cached_bounds_and_offset_valid_ = false; |
501 lines_.clear(); | 503 lines_.clear(); |
502 OnTextAttributeChanged(); | 504 OnTextAttributeChanged(); |
503 } | 505 } |
504 } | 506 } |
505 | 507 |
| 508 void RenderText::SetReplaceNewlineCharsWithSymbols(bool replace) { |
| 509 if (replace_newline_chars_with_symbols_ == replace) |
| 510 return; |
| 511 replace_newline_chars_with_symbols_ = replace; |
| 512 cached_bounds_and_offset_valid_ = false; |
| 513 OnTextAttributeChanged(); |
| 514 } |
| 515 |
506 void RenderText::SetMinLineHeight(int line_height) { | 516 void RenderText::SetMinLineHeight(int line_height) { |
507 if (min_line_height_ == line_height) | 517 if (min_line_height_ == line_height) |
508 return; | 518 return; |
509 min_line_height_ = line_height; | 519 min_line_height_ = line_height; |
510 cached_bounds_and_offset_valid_ = false; | 520 cached_bounds_and_offset_valid_ = false; |
511 lines_.clear(); | 521 lines_.clear(); |
512 OnDisplayTextAttributeChanged(); | 522 OnDisplayTextAttributeChanged(); |
513 } | 523 } |
514 | 524 |
515 void RenderText::SetElideBehavior(ElideBehavior elide_behavior) { | 525 void RenderText::SetElideBehavior(ElideBehavior elide_behavior) { |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
912 colors_(kDefaultColor), | 922 colors_(kDefaultColor), |
913 styles_(NUM_TEXT_STYLES), | 923 styles_(NUM_TEXT_STYLES), |
914 composition_and_selection_styles_applied_(false), | 924 composition_and_selection_styles_applied_(false), |
915 obscured_(false), | 925 obscured_(false), |
916 obscured_reveal_index_(-1), | 926 obscured_reveal_index_(-1), |
917 truncate_length_(0), | 927 truncate_length_(0), |
918 elide_behavior_(NO_ELIDE), | 928 elide_behavior_(NO_ELIDE), |
919 text_elided_(false), | 929 text_elided_(false), |
920 min_line_height_(0), | 930 min_line_height_(0), |
921 multiline_(false), | 931 multiline_(false), |
| 932 replace_newline_chars_with_symbols_(true), |
922 subpixel_rendering_suppressed_(false), | 933 subpixel_rendering_suppressed_(false), |
923 clip_to_display_rect_(true), | 934 clip_to_display_rect_(true), |
924 baseline_(kInvalidBaseline), | 935 baseline_(kInvalidBaseline), |
925 cached_bounds_and_offset_valid_(false) { | 936 cached_bounds_and_offset_valid_(false) { |
926 } | 937 } |
927 | 938 |
928 SelectionModel RenderText::GetAdjacentSelectionModel( | 939 SelectionModel RenderText::GetAdjacentSelectionModel( |
929 const SelectionModel& current, | 940 const SelectionModel& current, |
930 BreakType break_type, | 941 BreakType break_type, |
931 VisualCursorDirection direction) { | 942 VisualCursorDirection direction) { |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1086 | 1097 |
1087 HorizontalAlignment RenderText::GetCurrentHorizontalAlignment() { | 1098 HorizontalAlignment RenderText::GetCurrentHorizontalAlignment() { |
1088 if (horizontal_alignment_ != ALIGN_TO_HEAD) | 1099 if (horizontal_alignment_ != ALIGN_TO_HEAD) |
1089 return horizontal_alignment_; | 1100 return horizontal_alignment_; |
1090 return GetDisplayTextDirection() == base::i18n::RIGHT_TO_LEFT ? | 1101 return GetDisplayTextDirection() == base::i18n::RIGHT_TO_LEFT ? |
1091 ALIGN_RIGHT : ALIGN_LEFT; | 1102 ALIGN_RIGHT : ALIGN_LEFT; |
1092 } | 1103 } |
1093 | 1104 |
1094 Vector2d RenderText::GetAlignmentOffset(size_t line_number) { | 1105 Vector2d RenderText::GetAlignmentOffset(size_t line_number) { |
1095 // TODO(ckocagil): Enable |lines_| usage on RenderTextMac. | 1106 // TODO(ckocagil): Enable |lines_| usage on RenderTextMac. |
1096 if (multiline_) | 1107 if (MultilineSupported() && multiline_) |
1097 DCHECK_LT(line_number, lines_.size()); | 1108 DCHECK_LT(line_number, lines_.size()); |
1098 Vector2d offset; | 1109 Vector2d offset; |
1099 HorizontalAlignment horizontal_alignment = GetCurrentHorizontalAlignment(); | 1110 HorizontalAlignment horizontal_alignment = GetCurrentHorizontalAlignment(); |
1100 if (horizontal_alignment != ALIGN_LEFT) { | 1111 if (horizontal_alignment != ALIGN_LEFT) { |
1101 const int width = multiline_ ? | 1112 const int width = multiline_ ? |
1102 std::ceil(lines_[line_number].size.width()) + | 1113 std::ceil(lines_[line_number].size.width()) + |
1103 (cursor_enabled_ ? 1 : 0) : | 1114 (cursor_enabled_ ? 1 : 0) : |
1104 GetContentWidth(); | 1115 GetContentWidth(); |
1105 offset.set_x(display_rect().width() - width); | 1116 offset.set_x(display_rect().width() - width); |
1106 // Put any extra margin pixel on the left to match legacy behavior. | 1117 // Put any extra margin pixel on the left to match legacy behavior. |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1261 DCHECK_LE(ellipsis_start, ellipsis_end); | 1272 DCHECK_LE(ellipsis_start, ellipsis_end); |
1262 layout_text_.assign(text.substr(0, ellipsis_start) + kEllipsisUTF16 + | 1273 layout_text_.assign(text.substr(0, ellipsis_start) + kEllipsisUTF16 + |
1263 text.substr(ellipsis_end)); | 1274 text.substr(ellipsis_end)); |
1264 } else { | 1275 } else { |
1265 iter.setIndex32(truncate_length_ - 1); | 1276 iter.setIndex32(truncate_length_ - 1); |
1266 layout_text_.assign(text.substr(0, iter.getIndex()) + kEllipsisUTF16); | 1277 layout_text_.assign(text.substr(0, iter.getIndex()) + kEllipsisUTF16); |
1267 } | 1278 } |
1268 } | 1279 } |
1269 static const base::char16 kNewline[] = { '\n', 0 }; | 1280 static const base::char16 kNewline[] = { '\n', 0 }; |
1270 static const base::char16 kNewlineSymbol[] = { 0x2424, 0 }; | 1281 static const base::char16 kNewlineSymbol[] = { 0x2424, 0 }; |
1271 if (!multiline_) | 1282 if (!multiline_ && replace_newline_chars_with_symbols_) |
1272 base::ReplaceChars(layout_text_, kNewline, kNewlineSymbol, &layout_text_); | 1283 base::ReplaceChars(layout_text_, kNewline, kNewlineSymbol, &layout_text_); |
1273 | 1284 |
1274 OnLayoutTextAttributeChanged(true); | 1285 OnLayoutTextAttributeChanged(true); |
1275 } | 1286 } |
1276 | 1287 |
1277 base::string16 RenderText::Elide(const base::string16& text, | 1288 base::string16 RenderText::Elide(const base::string16& text, |
1278 float text_width, | 1289 float text_width, |
1279 float available_width, | 1290 float available_width, |
1280 ElideBehavior behavior) { | 1291 ElideBehavior behavior) { |
1281 if (available_width <= 0 || text.empty()) | 1292 if (available_width <= 0 || text.empty()) |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1464 | 1475 |
1465 SetDisplayOffset(display_offset_.x() + delta_x); | 1476 SetDisplayOffset(display_offset_.x() + delta_x); |
1466 } | 1477 } |
1467 | 1478 |
1468 void RenderText::DrawSelection(Canvas* canvas) { | 1479 void RenderText::DrawSelection(Canvas* canvas) { |
1469 for (const Rect& s : GetSubstringBounds(selection())) | 1480 for (const Rect& s : GetSubstringBounds(selection())) |
1470 canvas->FillRect(s, selection_background_focused_color_); | 1481 canvas->FillRect(s, selection_background_focused_color_); |
1471 } | 1482 } |
1472 | 1483 |
1473 } // namespace gfx | 1484 } // namespace gfx |
OLD | NEW |