| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef UI_VIEWS_SELECTION_CONTROLLER_DELEGATE_H_ | 5 #ifndef UI_VIEWS_SELECTION_CONTROLLER_DELEGATE_H_ |
| 6 #define UI_VIEWS_SELECTION_CONTROLLER_DELEGATE_H_ | 6 #define UI_VIEWS_SELECTION_CONTROLLER_DELEGATE_H_ |
| 7 | 7 |
| 8 #include "third_party/skia/include/core/SkColor.h" |
| 9 #include "ui/views/focus/focus_manager.h" |
| 8 #include "ui/views/views_export.h" | 10 #include "ui/views/views_export.h" |
| 9 | 11 |
| 12 namespace gfx { |
| 13 class RenderText; |
| 14 } |
| 15 |
| 10 namespace ui { | 16 namespace ui { |
| 11 class MouseEvent; | 17 class MouseEvent; |
| 12 } | 18 } |
| 13 | 19 |
| 14 namespace views { | 20 namespace views { |
| 15 | 21 |
| 22 // For cosmetic use only. TODO(patricialor): Probably this can be removed. |
| 23 enum class TextSelectionDrawState { |
| 24 // The control has focus, the selection text color and selection background |
| 25 // color are used. |
| 26 kDrawAsFocused, |
| 27 // The control doesn't have focus, but it was last to be focused before |
| 28 // changing to a different views::Widget or application. The selection text |
| 29 // color and selection background unfocused color are used. |
| 30 kDrawAsLastFocused, |
| 31 // In all other cases, the selection is not drawn at all. |
| 32 kDrawAsUnfocused |
| 33 }; |
| 34 |
| 16 // An interface implemented/managed by a view which uses the | 35 // An interface implemented/managed by a view which uses the |
| 17 // SelectionController. | 36 // SelectionController. |
| 18 class VIEWS_EXPORT SelectionControllerDelegate { | 37 class VIEWS_EXPORT SelectionControllerDelegate |
| 38 : virtual public FocusChangeListener { |
| 19 public: | 39 public: |
| 20 // Returns the associated RenderText instance to be used for selection. | 40 // Returns the associated RenderText instance to be used for selection. |
| 21 virtual gfx::RenderText* GetRenderTextForSelectionController() = 0; | 41 virtual gfx::RenderText* GetRenderTextForSelectionController() = 0; |
| 22 | 42 |
| 23 // Methods related to properties of the associated view. | 43 // Methods related to properties of the associated view. |
| 24 | 44 |
| 25 // Returns true if the associated text view is read only. | 45 // Returns true if the associated text view is read only. |
| 26 virtual bool IsReadOnly() const = 0; | 46 virtual bool IsReadOnly() const = 0; |
| 27 // Returns whether the associated view supports drag-and-drop. | 47 // Returns whether the associated view supports drag-and-drop. |
| 28 virtual bool SupportsDrag() const = 0; | 48 virtual bool SupportsDrag() const = 0; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 54 // Pastes the text from the selection clipboard at the current cursor | 74 // Pastes the text from the selection clipboard at the current cursor |
| 55 // position. Always called within a pointer action for a non-readonly view. | 75 // position. Always called within a pointer action for a non-readonly view. |
| 56 // Returns true if some text was pasted. | 76 // Returns true if some text was pasted. |
| 57 virtual bool PasteSelectionClipboard() = 0; | 77 virtual bool PasteSelectionClipboard() = 0; |
| 58 // Updates the selection clipboard with the currently selected text. Should | 78 // Updates the selection clipboard with the currently selected text. Should |
| 59 // empty the selection clipboard if no text is currently selected. | 79 // empty the selection clipboard if no text is currently selected. |
| 60 // NO-OP if the associated text view is obscured. Since this does not modify | 80 // NO-OP if the associated text view is obscured. Since this does not modify |
| 61 // the render text instance, it may be called outside of a pointer action. | 81 // the render text instance, it may be called outside of a pointer action. |
| 62 virtual void UpdateSelectionClipboard() = 0; | 82 virtual void UpdateSelectionClipboard() = 0; |
| 63 | 83 |
| 84 // These methods are used for drawing the selected text while also considering |
| 85 // its focused state. See TextSelectionDrawState. |
| 86 virtual SkColor GetSelectionTextColor() const = 0; |
| 87 virtual SkColor GetSelectionBackgroundColor() const = 0; |
| 88 virtual SkColor GetSelectionBackgroundUnfocusedColor() const = 0; |
| 89 TextSelectionDrawState UpdateTextSelectionDrawState( |
| 90 const View* this_view, |
| 91 const View* focused_before, |
| 92 const View* focused_now); |
| 93 |
| 94 // Set the FocusManager observed for focus change events. The |
| 95 // SelectionControllerDelegate implementation must call this in order for |
| 96 // selection drawing to reflect changes in focus. |
| 97 virtual void ObserveWidgetFocusChanges(FocusManager* new_focus_manager, |
| 98 bool add_as_listener); |
| 99 |
| 100 // FocusChangeListener overrides: |
| 101 // Subclasses must pass the call below to UpdateTextSelectionDrawState(). |
| 102 void OnWillChangeFocus(View* focused_before, View* focused_now) override = 0; |
| 103 void OnDidChangeFocus(View* focused_before, View* focused_now) override; |
| 104 |
| 64 protected: | 105 protected: |
| 65 virtual ~SelectionControllerDelegate() {} | 106 ~SelectionControllerDelegate() override; |
| 107 |
| 108 FocusManager* focus_manager_ = nullptr; |
| 66 }; | 109 }; |
| 67 | 110 |
| 68 } // namespace views | 111 } // namespace views |
| 69 | 112 |
| 70 #endif // UI_VIEWS_SELECTION_CONTROLLER_DELEGATE_H_ | 113 #endif // UI_VIEWS_SELECTION_CONTROLLER_DELEGATE_H_ |
| OLD | NEW |