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: |
| 24 | CursorManager(RenderWidgetHostViewBase* root); |
| 25 | ~CursorManager(); |
| 26 | |
| 27 | // Called for any RenderWidgetHostView that received an UpdateCursor message |
| 28 | // from its renderer process. |
| 29 | void UpdateCursor(RenderWidgetHostViewBase*, const WebCursor&); |
| 30 | |
| 31 | // Called when the mouse moves over a different RenderWidgetHostView. |
| 32 | void UpdateViewUnderCursor(RenderWidgetHostViewBase*); |
| 33 | |
| 34 | // Notification of a RenderWidgetHostView being destroyed, so that its |
| 35 | // cursor map entry can be removed if it has one. If it is the current |
| 36 | // view_under_cursor_, then the root_view_'s cursor will be displayed. |
| 37 | void ViewBeingDestroyed(RenderWidgetHostViewBase*); |
| 38 | |
| 39 | // Accessor for browser tests, enabling verification of the cursor_map_. |
| 40 | // Returns false if the provided View is not in the map, and outputs |
| 41 | // the cursor otherwise. |
| 42 | bool GetCursorForTesting(RenderWidgetHostViewBase*, WebCursor&); |
| 43 | |
| 44 | private: |
| 45 | // Stores the last received cursor from each RenderWidgetHostView. |
| 46 | std::map<RenderWidgetHostViewBase*, WebCursor> cursor_map_; |
| 47 | |
| 48 | // The view currently underneath the cursor, which corresponds to the cursor |
| 49 | // currently displayed. |
| 50 | RenderWidgetHostViewBase* view_under_cursor_; |
| 51 | |
| 52 | // The root view is the target for DisplayCursor calls whenever the active |
| 53 | // cursor needs to change. |
| 54 | RenderWidgetHostViewBase* root_view_; |
| 55 | }; |
| 56 | |
| 57 | } // namespace content |
| 58 | |
| 59 | #endif // CONTENT_BROWSER_RENDERER_HOST_CURSOR_MANAGER_H_ |