Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(889)

Side by Side Diff: ui/gfx/render_text.cc

Issue 2345183002: Views: Draw Textfield selected text in gray when top-level Widget loses focus.
Patch Set: Fix focus changing to other Views. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 829 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 EnsureLayout(); 840 EnsureLayout();
841 841
842 if (clip_to_display_rect()) { 842 if (clip_to_display_rect()) {
843 Rect clip_rect(display_rect()); 843 Rect clip_rect(display_rect());
844 clip_rect.Inset(ShadowValue::GetMargin(shadows_)); 844 clip_rect.Inset(ShadowValue::GetMargin(shadows_));
845 845
846 canvas->Save(); 846 canvas->Save();
847 canvas->ClipRect(clip_rect); 847 canvas->ClipRect(clip_rect);
848 } 848 }
849 849
850 if (!text().empty() && focused()) 850 if (!selection().is_empty())
851 DrawSelection(canvas); 851 DrawSelection(canvas);
852 852
853 if (cursor_enabled() && cursor_visible() && focused()) 853 if (cursor_enabled() && cursor_visible() && focused())
854 DrawCursor(canvas, selection_model_); 854 DrawCursor(canvas, selection_model_);
855 855
856 if (!text().empty()) { 856 if (!text().empty()) {
857 internal::SkiaTextRenderer renderer(canvas); 857 internal::SkiaTextRenderer renderer(canvas);
858 if (halo_effect()) 858 if (halo_effect())
859 renderer.SetHaloEffect(); 859 renderer.SetHaloEffect();
860 DrawVisualText(&renderer); 860 DrawVisualText(&renderer);
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 } 1050 }
1051 1051
1052 RenderText::RenderText() 1052 RenderText::RenderText()
1053 : horizontal_alignment_(base::i18n::IsRTL() ? ALIGN_RIGHT : ALIGN_LEFT), 1053 : horizontal_alignment_(base::i18n::IsRTL() ? ALIGN_RIGHT : ALIGN_LEFT),
1054 directionality_mode_(DIRECTIONALITY_FROM_TEXT), 1054 directionality_mode_(DIRECTIONALITY_FROM_TEXT),
1055 text_direction_(base::i18n::UNKNOWN_DIRECTION), 1055 text_direction_(base::i18n::UNKNOWN_DIRECTION),
1056 cursor_enabled_(true), 1056 cursor_enabled_(true),
1057 cursor_visible_(false), 1057 cursor_visible_(false),
1058 cursor_color_(kDefaultColor), 1058 cursor_color_(kDefaultColor),
1059 selection_color_(kDefaultColor), 1059 selection_color_(kDefaultColor),
1060 selection_background_focused_color_(kDefaultSelectionBackgroundColor), 1060 selection_background_color_(kDefaultSelectionBackgroundColor),
1061 draw_text_selection_(true),
1061 focused_(false), 1062 focused_(false),
1062 composition_range_(Range::InvalidRange()), 1063 composition_range_(Range::InvalidRange()),
1063 colors_(kDefaultColor), 1064 colors_(kDefaultColor),
1064 baselines_(NORMAL_BASELINE), 1065 baselines_(NORMAL_BASELINE),
1065 weights_(Font::Weight::NORMAL), 1066 weights_(Font::Weight::NORMAL),
1066 styles_(NUM_TEXT_STYLES), 1067 styles_(NUM_TEXT_STYLES),
1067 composition_and_selection_styles_applied_(false), 1068 composition_and_selection_styles_applied_(false),
1068 obscured_(false), 1069 obscured_(false),
1069 obscured_reveal_index_(-1), 1070 obscured_reveal_index_(-1),
1070 truncate_length_(0), 1071 truncate_length_(0),
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
1623 if (cursor_bounds_.right() > display_rect_.right()) 1624 if (cursor_bounds_.right() > display_rect_.right())
1624 delta_x = display_rect_.right() - cursor_bounds_.right(); 1625 delta_x = display_rect_.right() - cursor_bounds_.right();
1625 else if (cursor_bounds_.x() < display_rect_.x()) 1626 else if (cursor_bounds_.x() < display_rect_.x())
1626 delta_x = display_rect_.x() - cursor_bounds_.x(); 1627 delta_x = display_rect_.x() - cursor_bounds_.x();
1627 } 1628 }
1628 1629
1629 SetDisplayOffset(display_offset_.x() + delta_x); 1630 SetDisplayOffset(display_offset_.x() + delta_x);
1630 } 1631 }
1631 1632
1632 void RenderText::DrawSelection(Canvas* canvas) { 1633 void RenderText::DrawSelection(Canvas* canvas) {
1634 if (!draw_text_selection_)
1635 return;
1633 for (const Rect& s : GetSubstringBounds(selection())) 1636 for (const Rect& s : GetSubstringBounds(selection()))
1634 canvas->FillRect(s, selection_background_focused_color_); 1637 canvas->FillRect(s, selection_background_color_);
1635 } 1638 }
1636 1639
1637 size_t RenderText::GetNearestWordStartBoundary(size_t index) const { 1640 size_t RenderText::GetNearestWordStartBoundary(size_t index) const {
1638 const size_t length = text().length(); 1641 const size_t length = text().length();
1639 if (obscured() || length == 0) 1642 if (obscured() || length == 0)
1640 return length; 1643 return length;
1641 1644
1642 base::i18n::BreakIterator iter(text(), base::i18n::BreakIterator::BREAK_WORD); 1645 base::i18n::BreakIterator iter(text(), base::i18n::BreakIterator::BREAK_WORD);
1643 const bool success = iter.Init(); 1646 const bool success = iter.Init();
1644 DCHECK(success); 1647 DCHECK(success);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1684 1687
1685 for (; range_max < length; ++range_max) 1688 for (; range_max < length; ++range_max)
1686 if (iter.IsEndOfWord(range_max) || iter.IsStartOfWord(range_max)) 1689 if (iter.IsEndOfWord(range_max) || iter.IsStartOfWord(range_max))
1687 break; 1690 break;
1688 1691
1689 return range.is_reversed() ? Range(range_max, range_min) 1692 return range.is_reversed() ? Range(range_max, range_min)
1690 : Range(range_min, range_max); 1693 : Range(range_min, range_max);
1691 } 1694 }
1692 1695
1693 } // namespace gfx 1696 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698