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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
710 | 712 |
711 base::i18n::TextDirection RenderText::GetDisplayTextDirection() { | 713 base::i18n::TextDirection RenderText::GetDisplayTextDirection() { |
712 return GetTextDirection(GetDisplayText()); | 714 return GetTextDirection(GetDisplayText()); |
713 } | 715 } |
714 | 716 |
715 VisualCursorDirection RenderText::GetVisualDirectionOfLogicalEnd() { | 717 VisualCursorDirection RenderText::GetVisualDirectionOfLogicalEnd() { |
716 return GetDisplayTextDirection() == base::i18n::LEFT_TO_RIGHT ? | 718 return GetDisplayTextDirection() == base::i18n::LEFT_TO_RIGHT ? |
717 CURSOR_RIGHT : CURSOR_LEFT; | 719 CURSOR_RIGHT : CURSOR_LEFT; |
718 } | 720 } |
719 | 721 |
722 const base::string16& RenderText::GetAccessibleText() { | |
723 return layout_text_; | |
msw
2015/02/25 23:54:26
I think this should work as-is, since |layout_text
Jun Mukai
2015/02/26 01:40:24
This method was removed.
| |
724 } | |
725 | |
720 SizeF RenderText::GetStringSizeF() { | 726 SizeF RenderText::GetStringSizeF() { |
721 return GetStringSize(); | 727 return GetStringSize(); |
722 } | 728 } |
723 | 729 |
724 float RenderText::GetContentWidthF() { | 730 float RenderText::GetContentWidthF() { |
725 const float string_size = GetStringSizeF().width(); | 731 const float string_size = GetStringSizeF().width(); |
726 // The cursor is drawn one pixel beyond the int-enclosed text bounds. | 732 // The cursor is drawn one pixel beyond the int-enclosed text bounds. |
727 return cursor_enabled_ ? std::ceil(string_size) + 1 : string_size; | 733 return cursor_enabled_ ? std::ceil(string_size) + 1 : string_size; |
728 } | 734 } |
729 | 735 |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1086 | 1092 |
1087 HorizontalAlignment RenderText::GetCurrentHorizontalAlignment() { | 1093 HorizontalAlignment RenderText::GetCurrentHorizontalAlignment() { |
1088 if (horizontal_alignment_ != ALIGN_TO_HEAD) | 1094 if (horizontal_alignment_ != ALIGN_TO_HEAD) |
1089 return horizontal_alignment_; | 1095 return horizontal_alignment_; |
1090 return GetDisplayTextDirection() == base::i18n::RIGHT_TO_LEFT ? | 1096 return GetDisplayTextDirection() == base::i18n::RIGHT_TO_LEFT ? |
1091 ALIGN_RIGHT : ALIGN_LEFT; | 1097 ALIGN_RIGHT : ALIGN_LEFT; |
1092 } | 1098 } |
1093 | 1099 |
1094 Vector2d RenderText::GetAlignmentOffset(size_t line_number) { | 1100 Vector2d RenderText::GetAlignmentOffset(size_t line_number) { |
1095 // TODO(ckocagil): Enable |lines_| usage on RenderTextMac. | 1101 // TODO(ckocagil): Enable |lines_| usage on RenderTextMac. |
1096 if (multiline_) | 1102 if (MultilineSupported() && multiline_) |
1097 DCHECK_LT(line_number, lines_.size()); | 1103 DCHECK_LT(line_number, lines_.size()); |
1098 Vector2d offset; | 1104 Vector2d offset; |
1099 HorizontalAlignment horizontal_alignment = GetCurrentHorizontalAlignment(); | 1105 HorizontalAlignment horizontal_alignment = GetCurrentHorizontalAlignment(); |
1100 if (horizontal_alignment != ALIGN_LEFT) { | 1106 if (horizontal_alignment != ALIGN_LEFT) { |
1101 const int width = multiline_ ? | 1107 const int width = multiline_ ? |
1102 std::ceil(lines_[line_number].size.width()) + | 1108 std::ceil(lines_[line_number].size.width()) + |
1103 (cursor_enabled_ ? 1 : 0) : | 1109 (cursor_enabled_ ? 1 : 0) : |
1104 GetContentWidth(); | 1110 GetContentWidth(); |
1105 offset.set_x(display_rect().width() - width); | 1111 offset.set_x(display_rect().width() - width); |
1106 // Put any extra margin pixel on the left to match legacy behavior. | 1112 // Put any extra margin pixel on the left to match legacy behavior. |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1453 | 1459 |
1454 SetDisplayOffset(display_offset_.x() + delta_x); | 1460 SetDisplayOffset(display_offset_.x() + delta_x); |
1455 } | 1461 } |
1456 | 1462 |
1457 void RenderText::DrawSelection(Canvas* canvas) { | 1463 void RenderText::DrawSelection(Canvas* canvas) { |
1458 for (const Rect& s : GetSubstringBounds(selection())) | 1464 for (const Rect& s : GetSubstringBounds(selection())) |
1459 canvas->FillRect(s, selection_background_focused_color_); | 1465 canvas->FillRect(s, selection_background_focused_color_); |
1460 } | 1466 } |
1461 | 1467 |
1462 } // namespace gfx | 1468 } // namespace gfx |
OLD | NEW |