| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/views/selection_controller_delegate.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "ui/gfx/render_text.h" |
| 9 |
| 10 namespace views { |
| 11 |
| 12 TextSelectionDrawState |
| 13 SelectionControllerDelegate::UpdateTextSelectionDrawState( |
| 14 const View* this_view, |
| 15 const View* focused_before, |
| 16 const View* focused_now) { |
| 17 // Selection should not be drawn if: |
| 18 // - Nothing is focused now and |this_view| was not the last focused View. |
| 19 // - The currently focused View is a different View (not |this_view|). |
| 20 if ((focused_now == nullptr && focused_before != this_view) || |
| 21 (focused_now != this_view && focused_now != nullptr)) { |
| 22 GetRenderTextForSelectionController()->set_draw_text_selection(false); |
| 23 return TextSelectionDrawState::kDrawAsUnfocused; |
| 24 } |
| 25 |
| 26 SkColor selection_bg_color; |
| 27 TextSelectionDrawState text_selection_draw_state; |
| 28 if (focused_now) { |
| 29 selection_bg_color = GetSelectionBackgroundColor(); |
| 30 text_selection_draw_state = TextSelectionDrawState::kDrawAsFocused; |
| 31 } else { |
| 32 selection_bg_color = GetSelectionBackgroundUnfocusedColor(); |
| 33 text_selection_draw_state = TextSelectionDrawState::kDrawAsLastFocused; |
| 34 } |
| 35 GetRenderTextForSelectionController()->set_selection_color( |
| 36 GetSelectionTextColor()); |
| 37 GetRenderTextForSelectionController()->set_selection_background_color( |
| 38 selection_bg_color); |
| 39 GetRenderTextForSelectionController()->set_draw_text_selection(true); |
| 40 return text_selection_draw_state; |
| 41 } |
| 42 |
| 43 void SelectionControllerDelegate::ObserveWidgetFocusChanges( |
| 44 FocusManager* new_focus_manager, |
| 45 bool add_as_listener) { |
| 46 if (focus_manager_) { |
| 47 focus_manager_->RemoveFocusChangeListener(this); |
| 48 focus_manager_ = nullptr; |
| 49 } |
| 50 |
| 51 if (add_as_listener) { |
| 52 focus_manager_ = new_focus_manager; |
| 53 if (!focus_manager_) { |
| 54 return; |
| 55 } |
| 56 focus_manager_->AddFocusChangeListener(this); |
| 57 } |
| 58 } |
| 59 |
| 60 void SelectionControllerDelegate::OnDidChangeFocus(View* focused_before, |
| 61 View* focused_now) {} |
| 62 |
| 63 SelectionControllerDelegate::~SelectionControllerDelegate() { |
| 64 DCHECK(!focus_manager_); |
| 65 } |
| 66 |
| 67 } // namespace views |
| OLD | NEW |