Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / ui / views / widget / desktop_aura / x11_desktop_handler.h
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_VIEWS_WIDGET_DESKTOP_AURA_X11_DESKTOP_HANDLER_H_
6 #define UI_VIEWS_WIDGET_DESKTOP_AURA_X11_DESKTOP_HANDLER_H_
7
8 #include <X11/Xlib.h>
9 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class.
10 #undef RootWindow
11
12 #include <vector>
13
14 #include "ui/aura/env_observer.h"
15 #include "ui/events/platform/platform_event_dispatcher.h"
16 #include "ui/gfx/x/x11_atom_cache.h"
17 #include "ui/gfx/x/x11_types.h"
18 #include "ui/views/views_export.h"
19
20 template <typename T> struct DefaultSingletonTraits;
21
22 namespace views {
23
24 // A singleton that owns global objects related to the desktop and listens for
25 // X11 events on the X11 root window. Destroys itself when aura::Env is
26 // deleted.
27 class VIEWS_EXPORT X11DesktopHandler : public ui::PlatformEventDispatcher,
28                                        public aura::EnvObserver {
29  public:
30   // Returns the singleton handler.
31   static X11DesktopHandler* get();
32
33   // Gets/sets the X11 server time of the most recent mouse click, touch or
34   // key press on a Chrome window.
35   int wm_user_time_ms() const {
36     return wm_user_time_ms_;
37   }
38   void set_wm_user_time_ms(unsigned long time_ms) {
39     wm_user_time_ms_ = time_ms;
40   }
41
42   // Sends a request to the window manager to activate |window|.
43   // This method should only be called if the window is already mapped.
44   void ActivateWindow(::Window window);
45
46   // Attempts to get the window manager to deactivate |window| by moving it to
47   // the bottom of the stack. Regardless of whether |window| was actually
48   // deactivated, sets the window as inactive in our internal state.
49   void DeactivateWindow(::Window window);
50
51   // Checks if the current active window is |window|.
52   bool IsActiveWindow(::Window window) const;
53
54   // Processes activation/focus related events. Some of these events are
55   // dispatched to the X11 window dispatcher, and not to the X11 root-window
56   // dispatcher. The window dispatcher sends these events to here.
57   void ProcessXEvent(XEvent* event);
58
59   // ui::PlatformEventDispatcher
60   virtual bool CanDispatchEvent(const ui::PlatformEvent& event) OVERRIDE;
61   virtual uint32_t DispatchEvent(const ui::PlatformEvent& event) OVERRIDE;
62
63   // Overridden from aura::EnvObserver:
64   virtual void OnWindowInitialized(aura::Window* window) OVERRIDE;
65   virtual void OnWillDestroyEnv() OVERRIDE;
66
67  private:
68   enum ActiveState {
69     ACTIVE,
70     NOT_ACTIVE
71   };
72
73   X11DesktopHandler();
74   virtual ~X11DesktopHandler();
75
76   // Handles changes in activation.
77   void OnActiveWindowChanged(::Window window, ActiveState active_state);
78
79   // Called when |window| has been created or destroyed. |window| may not be
80   // managed by Chrome.
81   void OnWindowCreatedOrDestroyed(int event_type, XID window);
82
83   // The display and the native X window hosting the root window.
84   XDisplay* xdisplay_;
85
86   // The native root window.
87   ::Window x_root_window_;
88
89   // The X11 server time of the most recent mouse click, touch, or key press
90   // on a Chrome window.
91   unsigned long wm_user_time_ms_;
92
93   // The active window according to X11 server.
94   ::Window current_window_;
95
96   // Whether we should treat |current_window_| as active. In particular, we
97   // pretend that a window is deactivated after a call to DeactivateWindow().
98   ActiveState current_window_active_state_;
99
100   ui::X11AtomCache atom_cache_;
101
102   bool wm_supports_active_window_;
103
104   DISALLOW_COPY_AND_ASSIGN(X11DesktopHandler);
105 };
106
107 }  // namespace views
108
109 #endif  // UI_VIEWS_WIDGET_DESKTOP_AURA_X11_DESKTOP_HANDLER_H_