Chromium Code Reviews| Index: ui/gfx/render_text.cc |
| diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc |
| index c9404fc0b14bc5411008da5f5af69919786d31b4..66eed2eb9986c6e395ade68ac466b587bceb8f28 100644 |
| --- a/ui/gfx/render_text.cc |
| +++ b/ui/gfx/render_text.cc |
| @@ -53,8 +53,9 @@ const base::char16 kPasswordReplacementChar = '*'; |
| // Default color used for the text and cursor. |
| const SkColor kDefaultColor = SK_ColorBLACK; |
| -// Default color used for drawing selection background. |
| +// Default colors used for drawing selection backgrounds. |
| const SkColor kDefaultSelectionBackgroundColor = SK_ColorGRAY; |
| +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
|
| // Fraction of the text size to lower a strike through below the baseline. |
| const SkScalar kStrikeThroughOffset = (-SK_Scalar1 * 6 / 21); |
| @@ -879,7 +880,7 @@ void RenderText::Draw(Canvas* canvas) { |
| canvas->ClipRect(clip_rect); |
| } |
| - if (!text().empty() && focused()) |
| + if (!selection().is_empty()) |
| DrawSelection(canvas); |
| if (cursor_enabled() && cursor_visible() && focused()) |
| @@ -1051,6 +1052,9 @@ RenderText::RenderText() |
| cursor_color_(kDefaultColor), |
| selection_color_(kDefaultColor), |
| selection_background_focused_color_(kDefaultSelectionBackgroundColor), |
| + selection_background_unfocused_color_( |
| + kDefaultUnfocusedSelectionBackgroundColor), |
| + draw_unfocused_selection_(false), |
| focused_(false), |
| composition_range_(Range::InvalidRange()), |
| colors_(kDefaultColor), |
| @@ -1623,8 +1627,12 @@ void RenderText::UpdateCachedBoundsAndOffset() { |
| } |
| void RenderText::DrawSelection(Canvas* canvas) { |
| + if (!focused() && !draw_unfocused_selection_) |
| + return; |
| + SkColor background_color = focused() ? selection_background_focused_color_ |
| + : selection_background_unfocused_color_; |
| for (const Rect& s : GetSubstringBounds(selection())) |
| - canvas->FillRect(s, selection_background_focused_color_); |
| + canvas->FillRect(s, background_color); |
| } |
| } // namespace gfx |