Ken Buchanan | 520f29c | 2017-07-13 23:29:51 | [diff] [blame] | 1 | // Copyright (c) 2017 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 | #ifndef CONTENT_BROWSER_RENDERER_HOST_CURSOR_MANAGER_H_ |
| 6 | #define CONTENT_BROWSER_RENDERER_HOST_CURSOR_MANAGER_H_ |
| 7 | |
| 8 | #include <map> |
| 9 | |
| 10 | #include "content/common/content_export.h" |
| 11 | #include "content/common/cursors/webcursor.h" |
| 12 | |
| 13 | namespace content { |
| 14 | |
| 15 | class RenderWidgetHostViewBase; |
| 16 | |
| 17 | // CursorManager coordinates mouse cursors for multiple RenderWidgetHostViews |
| 18 | // on a single page. It is owned by the top-level RenderWidgetHostView and |
| 19 | // calls back to its DisplayCursor method when the cursor needs to change, |
| 20 | // either because the mouse moved over a different view or because a cursor |
| 21 | // update was received for the current view. |
| 22 | class CONTENT_EXPORT CursorManager { |
| 23 | public: |
W. James MacLean | 3fef335b | 2018-04-20 06:31:32 | [diff] [blame] | 24 | class TooltipObserver { |
| 25 | public: |
| 26 | virtual ~TooltipObserver() {} |
| 27 | |
| 28 | virtual void OnSetTooltipTextForView( |
| 29 | const RenderWidgetHostViewBase* view, |
| 30 | const base::string16& tooltip_text) = 0; |
| 31 | }; |
| 32 | |
Ken Buchanan | 520f29c | 2017-07-13 23:29:51 | [diff] [blame] | 33 | CursorManager(RenderWidgetHostViewBase* root); |
| 34 | ~CursorManager(); |
| 35 | |
| 36 | // Called for any RenderWidgetHostView that received an UpdateCursor message |
| 37 | // from its renderer process. |
| 38 | void UpdateCursor(RenderWidgetHostViewBase*, const WebCursor&); |
| 39 | |
| 40 | // Called when the mouse moves over a different RenderWidgetHostView. |
| 41 | void UpdateViewUnderCursor(RenderWidgetHostViewBase*); |
| 42 | |
W. James MacLean | 3fef335b | 2018-04-20 06:31:32 | [diff] [blame] | 43 | // Accepts TooltipText updates from views, but only updates what's displayed |
| 44 | // if the requesting view is currently under the mouse cursor. |
| 45 | void SetTooltipTextForView(const RenderWidgetHostViewBase* view, |
| 46 | const base::string16& tooltip_text); |
| 47 | |
Ken Buchanan | 520f29c | 2017-07-13 23:29:51 | [diff] [blame] | 48 | // Notification of a RenderWidgetHostView being destroyed, so that its |
| 49 | // cursor map entry can be removed if it has one. If it is the current |
| 50 | // view_under_cursor_, then the root_view_'s cursor will be displayed. |
| 51 | void ViewBeingDestroyed(RenderWidgetHostViewBase*); |
| 52 | |
| 53 | // Accessor for browser tests, enabling verification of the cursor_map_. |
| 54 | // Returns false if the provided View is not in the map, and outputs |
| 55 | // the cursor otherwise. |
| 56 | bool GetCursorForTesting(RenderWidgetHostViewBase*, WebCursor&); |
| 57 | |
W. James MacLean | 3fef335b | 2018-04-20 06:31:32 | [diff] [blame] | 58 | void SetTooltipObserverForTesting(TooltipObserver* observer); |
| 59 | |
Ken Buchanan | 520f29c | 2017-07-13 23:29:51 | [diff] [blame] | 60 | private: |
| 61 | // Stores the last received cursor from each RenderWidgetHostView. |
| 62 | std::map<RenderWidgetHostViewBase*, WebCursor> cursor_map_; |
| 63 | |
| 64 | // The view currently underneath the cursor, which corresponds to the cursor |
| 65 | // currently displayed. |
| 66 | RenderWidgetHostViewBase* view_under_cursor_; |
| 67 | |
| 68 | // The root view is the target for DisplayCursor calls whenever the active |
| 69 | // cursor needs to change. |
| 70 | RenderWidgetHostViewBase* root_view_; |
W. James MacLean | 3fef335b | 2018-04-20 06:31:32 | [diff] [blame] | 71 | |
| 72 | TooltipObserver* tooltip_observer_for_testing_; |
Ken Buchanan | 520f29c | 2017-07-13 23:29:51 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | } // namespace content |
| 76 | |
W. James MacLean | 3fef335b | 2018-04-20 06:31:32 | [diff] [blame] | 77 | #endif // CONTENT_BROWSER_RENDERER_HOST_CURSOR_MANAGER_H_ |