1 // Copyright (c) 2012 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 UI_AURA_CLIENT_CURSOR_CLIENT_H_
6 #define UI_AURA_CLIENT_CURSOR_CLIENT_H_
7 
8 #include "base/strings/string16.h"
9 #include "ui/aura/aura_export.h"
10 #include "ui/base/cursor/cursor.h"
11 #include "ui/gfx/native_widget_types.h"
12 
13 namespace display {
14 class Display;
15 }
16 
17 namespace ui {
18 class KeyEvent;
19 enum class CursorSize;
20 }
21 
22 namespace aura {
23 class Window;
24 namespace client {
25 class CursorClientObserver;
26 
27 // An interface that receives cursor change events.
28 class AURA_EXPORT CursorClient {
29  public:
30   // Notes that |window| has requested the change to |cursor|.
31   virtual void SetCursor(gfx::NativeCursor cursor) = 0;
32 
33   // Returns the current cursor.
34   virtual gfx::NativeCursor GetCursor() const = 0;
35 
36   // Forces the cursor to be updated. This is called when the system may have
37   // changed the cursor without the cursor client's knowledge, which breaks
38   // if the cursor client doesn't think the cursor has changed.
39   virtual void SetCursorForced(gfx::NativeCursor cursor) = 0;
40 
41   // Shows the cursor. This does not take effect When mouse events are disabled.
42   virtual void ShowCursor() = 0;
43 
44   // Hides the cursor. Mouse events keep being sent even when the cursor is
45   // invisible.
46   virtual void HideCursor() = 0;
47 
48   // Sets the type of the mouse cursor icon.
49   virtual void SetCursorSize(ui::CursorSize cursor_size) = 0;
50 
51   // Gets the type of the mouse cursor icon.
52   virtual ui::CursorSize GetCursorSize() const = 0;
53 
54   // Gets whether the cursor is visible.
55   virtual bool IsCursorVisible() const = 0;
56 
57   // Makes mouse events start being sent and shows the cursor if it was hidden
58   // with DisableMouseEvents.
59   virtual void EnableMouseEvents() = 0;
60 
61   // Makes mouse events stop being sent and hides the cursor if it is visible.
62   virtual void DisableMouseEvents() = 0;
63 
64   // Returns true if mouse events are enabled.
65   virtual bool IsMouseEventsEnabled() const = 0;
66 
67   // Sets the display for the cursor.
68   virtual void SetDisplay(const display::Display& display) = 0;
69 
70   // Returns the display where the cursor is located.
71   virtual const display::Display& GetDisplay() const = 0;
72 
73   // Locks the cursor change. The cursor type, cursor visibility, and mouse
74   // events enable state never change as long as lock is held by anyone.
75   virtual void LockCursor() = 0;
76 
77   // Unlocks the cursor change. If all the locks are released, the cursor type,
78   // cursor visibility, and mouse events enable state are restored to the ones
79   // set by the lastest call of SetCursor, ShowCursor/HideCursor, and
80   // EnableMouseEvents/DisableMouseEvents.
81   virtual void UnlockCursor() = 0;
82 
83   // Returns true if the cursor is locked.
84   virtual bool IsCursorLocked() const = 0;
85 
86   // Used to add or remove a CursorClientObserver.
87   virtual void AddObserver(CursorClientObserver* observer) = 0;
88   virtual void RemoveObserver(CursorClientObserver* observer) = 0;
89 
90   // Returns true if the mouse cursor should be hidden on |event|.
91   virtual bool ShouldHideCursorOnKeyEvent(const ui::KeyEvent& event) const = 0;
92 
93  protected:
~CursorClient()94   virtual ~CursorClient() {}
95 };
96 
97 // Sets/Gets the activation client for the specified window.
98 AURA_EXPORT void SetCursorClient(Window* window,
99                                  CursorClient* client);
100 AURA_EXPORT CursorClient* GetCursorClient(Window* window);
101 
102 }  // namespace client
103 }  // namespace aura
104 
105 #endif  // UI_AURA_CLIENT_CURSOR_CLIENT_H_
106