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

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 up diff & add colors to Windows/Mac. Created 4 years, 3 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 namespace { 46 namespace {
47 47
48 // All chars are replaced by this char when the password style is set. 48 // All chars are replaced by this char when the password style is set.
49 // TODO(benrg): GTK uses the first of U+25CF, U+2022, U+2731, U+273A, '*' 49 // TODO(benrg): GTK uses the first of U+25CF, U+2022, U+2731, U+273A, '*'
50 // that's available in the font (find_invisible_char() in gtkentry.c). 50 // that's available in the font (find_invisible_char() in gtkentry.c).
51 const base::char16 kPasswordReplacementChar = '*'; 51 const base::char16 kPasswordReplacementChar = '*';
52 52
53 // Default color used for the text and cursor. 53 // Default color used for the text and cursor.
54 const SkColor kDefaultColor = SK_ColorBLACK; 54 const SkColor kDefaultColor = SK_ColorBLACK;
55 55
56 // Default color used for drawing selection background. 56 // Default colors used for drawing selection backgrounds.
57 const SkColor kDefaultSelectionBackgroundColor = SK_ColorGRAY; 57 const SkColor kDefaultSelectionBackgroundColor = SK_ColorGRAY;
58 const SkColor kDefaultUnfocusedSelectionBackgroundColor = 0xffdcdcdc;
tapted 2016/09/20 06:57:55 Will this be similar to SK_ColorGRAY anyway? (does
Patti Lor 2016/10/12 05:53:00 It's a bit lighter (I just used the Mac default un
58 59
59 // Fraction of the text size to lower a strike through below the baseline. 60 // Fraction of the text size to lower a strike through below the baseline.
60 const SkScalar kStrikeThroughOffset = (-SK_Scalar1 * 6 / 21); 61 const SkScalar kStrikeThroughOffset = (-SK_Scalar1 * 6 / 21);
61 // Fraction of the text size to lower an underline below the baseline. 62 // Fraction of the text size to lower an underline below the baseline.
62 const SkScalar kUnderlineOffset = (SK_Scalar1 / 9); 63 const SkScalar kUnderlineOffset = (SK_Scalar1 / 9);
63 // Fraction of the text size to use for a strike through or under-line. 64 // Fraction of the text size to use for a strike through or under-line.
64 const SkScalar kLineThickness = (SK_Scalar1 / 18); 65 const SkScalar kLineThickness = (SK_Scalar1 / 18);
65 // Fraction of the text size to use for a top margin of a diagonal strike. 66 // Fraction of the text size to use for a top margin of a diagonal strike.
66 const SkScalar kDiagonalStrikeMarginOffset = (SK_Scalar1 / 4); 67 const SkScalar kDiagonalStrikeMarginOffset = (SK_Scalar1 / 4);
67 68
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 EnsureLayout(); 873 EnsureLayout();
873 874
874 if (clip_to_display_rect()) { 875 if (clip_to_display_rect()) {
875 Rect clip_rect(display_rect()); 876 Rect clip_rect(display_rect());
876 clip_rect.Inset(ShadowValue::GetMargin(shadows_)); 877 clip_rect.Inset(ShadowValue::GetMargin(shadows_));
877 878
878 canvas->Save(); 879 canvas->Save();
879 canvas->ClipRect(clip_rect); 880 canvas->ClipRect(clip_rect);
880 } 881 }
881 882
882 if (!text().empty() && focused()) 883 if (!selection().is_empty())
883 DrawSelection(canvas); 884 DrawSelection(canvas);
884 885
885 if (cursor_enabled() && cursor_visible() && focused()) 886 if (cursor_enabled() && cursor_visible() && focused())
886 DrawCursor(canvas, selection_model_); 887 DrawCursor(canvas, selection_model_);
887 888
888 if (!text().empty()) { 889 if (!text().empty()) {
889 internal::SkiaTextRenderer renderer(canvas); 890 internal::SkiaTextRenderer renderer(canvas);
890 if (halo_effect()) 891 if (halo_effect())
891 renderer.SetHaloEffect(); 892 renderer.SetHaloEffect();
892 DrawVisualText(&renderer); 893 DrawVisualText(&renderer);
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 1045
1045 RenderText::RenderText() 1046 RenderText::RenderText()
1046 : horizontal_alignment_(base::i18n::IsRTL() ? ALIGN_RIGHT : ALIGN_LEFT), 1047 : horizontal_alignment_(base::i18n::IsRTL() ? ALIGN_RIGHT : ALIGN_LEFT),
1047 directionality_mode_(DIRECTIONALITY_FROM_TEXT), 1048 directionality_mode_(DIRECTIONALITY_FROM_TEXT),
1048 text_direction_(base::i18n::UNKNOWN_DIRECTION), 1049 text_direction_(base::i18n::UNKNOWN_DIRECTION),
1049 cursor_enabled_(true), 1050 cursor_enabled_(true),
1050 cursor_visible_(false), 1051 cursor_visible_(false),
1051 cursor_color_(kDefaultColor), 1052 cursor_color_(kDefaultColor),
1052 selection_color_(kDefaultColor), 1053 selection_color_(kDefaultColor),
1053 selection_background_focused_color_(kDefaultSelectionBackgroundColor), 1054 selection_background_focused_color_(kDefaultSelectionBackgroundColor),
1055 selection_background_unfocused_color_(
1056 kDefaultUnfocusedSelectionBackgroundColor),
1057 draw_unfocused_selection_(false),
1054 focused_(false), 1058 focused_(false),
1055 composition_range_(Range::InvalidRange()), 1059 composition_range_(Range::InvalidRange()),
1056 colors_(kDefaultColor), 1060 colors_(kDefaultColor),
1057 baselines_(NORMAL_BASELINE), 1061 baselines_(NORMAL_BASELINE),
1058 weights_(Font::Weight::NORMAL), 1062 weights_(Font::Weight::NORMAL),
1059 styles_(NUM_TEXT_STYLES), 1063 styles_(NUM_TEXT_STYLES),
1060 composition_and_selection_styles_applied_(false), 1064 composition_and_selection_styles_applied_(false),
1061 obscured_(false), 1065 obscured_(false),
1062 obscured_reveal_index_(-1), 1066 obscured_reveal_index_(-1),
1063 truncate_length_(0), 1067 truncate_length_(0),
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
1616 if (cursor_bounds_.right() > display_rect_.right()) 1620 if (cursor_bounds_.right() > display_rect_.right())
1617 delta_x = display_rect_.right() - cursor_bounds_.right(); 1621 delta_x = display_rect_.right() - cursor_bounds_.right();
1618 else if (cursor_bounds_.x() < display_rect_.x()) 1622 else if (cursor_bounds_.x() < display_rect_.x())
1619 delta_x = display_rect_.x() - cursor_bounds_.x(); 1623 delta_x = display_rect_.x() - cursor_bounds_.x();
1620 } 1624 }
1621 1625
1622 SetDisplayOffset(display_offset_.x() + delta_x); 1626 SetDisplayOffset(display_offset_.x() + delta_x);
1623 } 1627 }
1624 1628
1625 void RenderText::DrawSelection(Canvas* canvas) { 1629 void RenderText::DrawSelection(Canvas* canvas) {
1630 if (!focused() && !draw_unfocused_selection_)
1631 return;
1632 SkColor background_color = focused() ? selection_background_focused_color_
1633 : selection_background_unfocused_color_;
1626 for (const Rect& s : GetSubstringBounds(selection())) 1634 for (const Rect& s : GetSubstringBounds(selection()))
1627 canvas->FillRect(s, selection_background_focused_color_); 1635 canvas->FillRect(s, background_color);
1628 } 1636 }
1629 1637
1630 } // namespace gfx 1638 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698