| 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 <limits.h> | 7 #include <limits.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <climits> | 10 #include <climits> |
| (...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 845 EnsureLayout(); | 845 EnsureLayout(); |
| 846 | 846 |
| 847 if (clip_to_display_rect()) { | 847 if (clip_to_display_rect()) { |
| 848 Rect clip_rect(display_rect()); | 848 Rect clip_rect(display_rect()); |
| 849 clip_rect.Inset(ShadowValue::GetMargin(shadows_)); | 849 clip_rect.Inset(ShadowValue::GetMargin(shadows_)); |
| 850 | 850 |
| 851 canvas->Save(); | 851 canvas->Save(); |
| 852 canvas->ClipRect(clip_rect); | 852 canvas->ClipRect(clip_rect); |
| 853 } | 853 } |
| 854 | 854 |
| 855 if (!text().empty() && focused()) | 855 if (!selection().is_empty()) |
| 856 DrawSelection(canvas); | 856 DrawSelection(canvas); |
| 857 | 857 |
| 858 if (cursor_enabled() && cursor_visible() && focused()) | 858 if (cursor_enabled() && cursor_visible() && focused()) |
| 859 DrawCursor(canvas, selection_model_); | 859 DrawCursor(canvas, selection_model_); |
| 860 | 860 |
| 861 if (!text().empty()) { | 861 if (!text().empty()) { |
| 862 internal::SkiaTextRenderer renderer(canvas); | 862 internal::SkiaTextRenderer renderer(canvas); |
| 863 if (halo_effect()) | 863 if (halo_effect()) |
| 864 renderer.SetHaloEffect(); | 864 renderer.SetHaloEffect(); |
| 865 DrawVisualText(&renderer); | 865 DrawVisualText(&renderer); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1055 } | 1055 } |
| 1056 | 1056 |
| 1057 RenderText::RenderText() | 1057 RenderText::RenderText() |
| 1058 : horizontal_alignment_(base::i18n::IsRTL() ? ALIGN_RIGHT : ALIGN_LEFT), | 1058 : horizontal_alignment_(base::i18n::IsRTL() ? ALIGN_RIGHT : ALIGN_LEFT), |
| 1059 directionality_mode_(DIRECTIONALITY_FROM_TEXT), | 1059 directionality_mode_(DIRECTIONALITY_FROM_TEXT), |
| 1060 text_direction_(base::i18n::UNKNOWN_DIRECTION), | 1060 text_direction_(base::i18n::UNKNOWN_DIRECTION), |
| 1061 cursor_enabled_(true), | 1061 cursor_enabled_(true), |
| 1062 cursor_visible_(false), | 1062 cursor_visible_(false), |
| 1063 cursor_color_(kDefaultColor), | 1063 cursor_color_(kDefaultColor), |
| 1064 selection_color_(kDefaultColor), | 1064 selection_color_(kDefaultColor), |
| 1065 selection_background_focused_color_(kDefaultSelectionBackgroundColor), | 1065 selection_background_color_(kDefaultSelectionBackgroundColor), |
| 1066 draw_text_selection_(false), |
| 1066 focused_(false), | 1067 focused_(false), |
| 1067 composition_range_(Range::InvalidRange()), | 1068 composition_range_(Range::InvalidRange()), |
| 1068 colors_(kDefaultColor), | 1069 colors_(kDefaultColor), |
| 1069 baselines_(NORMAL_BASELINE), | 1070 baselines_(NORMAL_BASELINE), |
| 1070 weights_(Font::Weight::NORMAL), | 1071 weights_(Font::Weight::NORMAL), |
| 1071 styles_(NUM_TEXT_STYLES), | 1072 styles_(NUM_TEXT_STYLES), |
| 1072 composition_and_selection_styles_applied_(false), | 1073 composition_and_selection_styles_applied_(false), |
| 1073 obscured_(false), | 1074 obscured_(false), |
| 1074 obscured_reveal_index_(-1), | 1075 obscured_reveal_index_(-1), |
| 1075 truncate_length_(0), | 1076 truncate_length_(0), |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1629 if (cursor_bounds_.right() > display_rect_.right()) | 1630 if (cursor_bounds_.right() > display_rect_.right()) |
| 1630 delta_x = display_rect_.right() - cursor_bounds_.right(); | 1631 delta_x = display_rect_.right() - cursor_bounds_.right(); |
| 1631 else if (cursor_bounds_.x() < display_rect_.x()) | 1632 else if (cursor_bounds_.x() < display_rect_.x()) |
| 1632 delta_x = display_rect_.x() - cursor_bounds_.x(); | 1633 delta_x = display_rect_.x() - cursor_bounds_.x(); |
| 1633 } | 1634 } |
| 1634 | 1635 |
| 1635 SetDisplayOffset(display_offset_.x() + delta_x); | 1636 SetDisplayOffset(display_offset_.x() + delta_x); |
| 1636 } | 1637 } |
| 1637 | 1638 |
| 1638 void RenderText::DrawSelection(Canvas* canvas) { | 1639 void RenderText::DrawSelection(Canvas* canvas) { |
| 1640 if (!draw_text_selection_) |
| 1641 return; |
| 1639 for (const Rect& s : GetSubstringBounds(selection())) | 1642 for (const Rect& s : GetSubstringBounds(selection())) |
| 1640 canvas->FillRect(s, selection_background_focused_color_); | 1643 canvas->FillRect(s, selection_background_color_); |
| 1641 } | 1644 } |
| 1642 | 1645 |
| 1643 size_t RenderText::GetNearestWordStartBoundary(size_t index) const { | 1646 size_t RenderText::GetNearestWordStartBoundary(size_t index) const { |
| 1644 const size_t length = text().length(); | 1647 const size_t length = text().length(); |
| 1645 if (obscured() || length == 0) | 1648 if (obscured() || length == 0) |
| 1646 return length; | 1649 return length; |
| 1647 | 1650 |
| 1648 base::i18n::BreakIterator iter(text(), base::i18n::BreakIterator::BREAK_WORD); | 1651 base::i18n::BreakIterator iter(text(), base::i18n::BreakIterator::BREAK_WORD); |
| 1649 const bool success = iter.Init(); | 1652 const bool success = iter.Init(); |
| 1650 DCHECK(success); | 1653 DCHECK(success); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1690 | 1693 |
| 1691 for (; range_max < length; ++range_max) | 1694 for (; range_max < length; ++range_max) |
| 1692 if (iter.IsEndOfWord(range_max) || iter.IsStartOfWord(range_max)) | 1695 if (iter.IsEndOfWord(range_max) || iter.IsStartOfWord(range_max)) |
| 1693 break; | 1696 break; |
| 1694 | 1697 |
| 1695 return range.is_reversed() ? Range(range_max, range_min) | 1698 return range.is_reversed() ? Range(range_max, range_min) |
| 1696 : Range(range_min, range_max); | 1699 : Range(range_min, range_max); |
| 1697 } | 1700 } |
| 1698 | 1701 |
| 1699 } // namespace gfx | 1702 } // namespace gfx |
| OLD | NEW |