blob: a835fdd5abf7bc5dc0b21c4be5ceaa4d451e89c3 [file] [log] [blame]
Ken Buchanan520f29c2017-07-13 23:29:511// 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
13namespace content {
14
15class 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.
22class CONTENT_EXPORT CursorManager {
23 public:
W. James MacLean3fef335b2018-04-20 06:31:3224 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 Buchanan520f29c2017-07-13 23:29:5133 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 MacLean3fef335b2018-04-20 06:31:3243 // 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 Buchanan520f29c2017-07-13 23:29:5148 // 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 MacLean3fef335b2018-04-20 06:31:3258 void SetTooltipObserverForTesting(TooltipObserver* observer);
59
Ken Buchanan520f29c2017-07-13 23:29:5160 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 MacLean3fef335b2018-04-20 06:31:3271
72 TooltipObserver* tooltip_observer_for_testing_;
Ken Buchanan520f29c2017-07-13 23:29:5173};
74
75} // namespace content
76
W. James MacLean3fef335b2018-04-20 06:31:3277#endif // CONTENT_BROWSER_RENDERER_HOST_CURSOR_MANAGER_H_