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 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1086 | 1088 |
1087 HorizontalAlignment RenderText::GetCurrentHorizontalAlignment() { | 1089 HorizontalAlignment RenderText::GetCurrentHorizontalAlignment() { |
1088 if (horizontal_alignment_ != ALIGN_TO_HEAD) | 1090 if (horizontal_alignment_ != ALIGN_TO_HEAD) |
1089 return horizontal_alignment_; | 1091 return horizontal_alignment_; |
1090 return GetDisplayTextDirection() == base::i18n::RIGHT_TO_LEFT ? | 1092 return GetDisplayTextDirection() == base::i18n::RIGHT_TO_LEFT ? |
1091 ALIGN_RIGHT : ALIGN_LEFT; | 1093 ALIGN_RIGHT : ALIGN_LEFT; |
1092 } | 1094 } |
1093 | 1095 |
1094 Vector2d RenderText::GetAlignmentOffset(size_t line_number) { | 1096 Vector2d RenderText::GetAlignmentOffset(size_t line_number) { |
1095 // TODO(ckocagil): Enable |lines_| usage on RenderTextMac. | 1097 // TODO(ckocagil): Enable |lines_| usage on RenderTextMac. |
1096 if (multiline_) | 1098 if (MultilineSupported() && multiline_) |
1097 DCHECK_LT(line_number, lines_.size()); | 1099 DCHECK_LT(line_number, lines_.size()); |
1098 Vector2d offset; | 1100 Vector2d offset; |
1099 HorizontalAlignment horizontal_alignment = GetCurrentHorizontalAlignment(); | 1101 HorizontalAlignment horizontal_alignment = GetCurrentHorizontalAlignment(); |
1100 if (horizontal_alignment != ALIGN_LEFT) { | 1102 if (horizontal_alignment != ALIGN_LEFT) { |
1101 const int width = multiline_ ? | 1103 const int width = multiline_ ? |
1102 std::ceil(lines_[line_number].size.width()) + | 1104 std::ceil(lines_[line_number].size.width()) + |
1103 (cursor_enabled_ ? 1 : 0) : | 1105 (cursor_enabled_ ? 1 : 0) : |
1104 GetContentWidth(); | 1106 GetContentWidth(); |
1105 offset.set_x(display_rect().width() - width); | 1107 offset.set_x(display_rect().width() - width); |
1106 // Put any extra margin pixel on the left to match legacy behavior. | 1108 // 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 | 1455 |
1454 SetDisplayOffset(display_offset_.x() + delta_x); | 1456 SetDisplayOffset(display_offset_.x() + delta_x); |
1455 } | 1457 } |
1456 | 1458 |
1457 void RenderText::DrawSelection(Canvas* canvas) { | 1459 void RenderText::DrawSelection(Canvas* canvas) { |
1458 for (const Rect& s : GetSubstringBounds(selection())) | 1460 for (const Rect& s : GetSubstringBounds(selection())) |
1459 canvas->FillRect(s, selection_background_focused_color_); | 1461 canvas->FillRect(s, selection_background_focused_color_); |
1460 } | 1462 } |
1461 | 1463 |
1462 } // namespace gfx | 1464 } // namespace gfx |
OLD | NEW |