• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 gfx {
14 class Display;
15 }
16 
17 namespace ui {
18 class KeyEvent;
19 }
20 
21 namespace aura {
22 class Window;
23 namespace client {
24 class CursorClientObserver;
25 
26 // An interface that receives cursor change events.
27 class AURA_EXPORT CursorClient {
28  public:
29   // Notes that |window| has requested the change to |cursor|.
30   virtual void SetCursor(gfx::NativeCursor cursor) = 0;
31 
32   // Returns the current cursor.
33   virtual gfx::NativeCursor GetCursor() const = 0;
34 
35   // Shows the cursor. This does not take effect When mouse events are disabled.
36   virtual void ShowCursor() = 0;
37 
38   // Hides the cursor. Mouse events keep being sent even when the cursor is
39   // invisible.
40   virtual void HideCursor() = 0;
41 
42   // Sets the type of the mouse cursor icon.
43   virtual void SetCursorSet(ui::CursorSetType cursor_set) = 0;
44 
45   // Gets the type of the mouse cursor icon.
46   virtual ui::CursorSetType GetCursorSet() const = 0;
47 
48   // Gets whether the cursor is visible.
49   virtual bool IsCursorVisible() const = 0;
50 
51   // Makes mouse events start being sent and shows the cursor if it was hidden
52   // with DisableMouseEvents.
53   virtual void EnableMouseEvents() = 0;
54 
55   // Makes mouse events stop being sent and hides the cursor if it is visible.
56   virtual void DisableMouseEvents() = 0;
57 
58   // Returns true if mouse events are enabled.
59   virtual bool IsMouseEventsEnabled() const = 0;
60 
61   // Sets the display for the cursor.
62   virtual void SetDisplay(const gfx::Display& display) = 0;
63 
64   // Locks the cursor change. The cursor type, cursor visibility, and mouse
65   // events enable state never change as long as lock is held by anyone.
66   virtual void LockCursor() = 0;
67 
68   // Unlocks the cursor change. If all the locks are released, the cursor type,
69   // cursor visibility, and mouse events enable state are restored to the ones
70   // set by the lastest call of SetCursor, ShowCursor/HideCursor, and
71   // EnableMouseEvents/DisableMouseEvents.
72   virtual void UnlockCursor() = 0;
73 
74   // Returns true if the cursor is locked.
75   virtual bool IsCursorLocked() const = 0;
76 
77   // Used to add or remove a CursorClientObserver.
78   virtual void AddObserver(CursorClientObserver* observer) = 0;
79   virtual void RemoveObserver(CursorClientObserver* observer) = 0;
80 
81   // Returns true if the mouse cursor should be hidden on |event|.
82   virtual bool ShouldHideCursorOnKeyEvent(const ui::KeyEvent& event) const = 0;
83 
84  protected:
~CursorClient()85   virtual ~CursorClient() {}
86 };
87 
88 // Sets/Gets the activation client for the specified window.
89 AURA_EXPORT void SetCursorClient(Window* window,
90                                  CursorClient* client);
91 AURA_EXPORT CursorClient* GetCursorClient(Window* window);
92 
93 }  // namespace client
94 }  // namespace aura
95 
96 #endif  // UI_AURA_CLIENT_CURSOR_CLIENT_H_
97