Upstream version 5.34.92.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 "base/message_loop/message_pump_dispatcher.h"
15 #include "ui/aura/env_observer.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 base::MessagePumpDispatcher,
28                                        public aura::EnvObserver {
29  public:
30   // Returns the singleton handler.
31   static X11DesktopHandler* get();
32
33   // Sends a request to the window manager to activate |window|.
34   // This method should only be called if the window is already mapped.
35   void ActivateWindow(::Window window);
36
37   // Deactivates the |window| and activates the window just below it in z-order.
38   // |window| must be active.
39   void DeactivateWindow(::Window window);
40
41   // Checks if the current active window is |window|.
42   bool IsActiveWindow(::Window window) const;
43
44   // Processes activation/focus related events. Some of these events are
45   // dispatched to the X11 window dispatcher, and not to the X11 root-window
46   // dispatcher. The window dispatcher sends these events to here.
47   void ProcessXEvent(const base::NativeEvent& event);
48
49   // Overridden from MessagePumpDispatcher:
50   virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE;
51
52   // Overridden from aura::EnvObserver:
53   virtual void OnWindowInitialized(aura::Window* window) OVERRIDE;
54   virtual void OnWillDestroyEnv() OVERRIDE;
55
56   // Allows to override wm_supports_active_window_ value for tests. If the WM
57   // supports _NET_ACTIVE_WINDOW, activation is async otherwise it is sync.
58   void SetWMSupportsActiveWindowForTests(bool value) {
59     wm_supports_active_window_ = value;
60   }
61
62  private:
63   explicit X11DesktopHandler();
64   virtual ~X11DesktopHandler();
65
66   // Handles changes in activation.
67   void OnActiveWindowChanged(::Window window);
68
69   // Return the next window to activate based on the current list of windows.
70   // This should only be called if there is an active window. In other words, if
71   // current_window_ is different from None.
72   ::Window GetNextToActivateInStack(const std::vector< ::Window >& windows);
73
74   // The display and the native X window hosting the root window.
75   XDisplay* xdisplay_;
76
77   // The native root window.
78   ::Window x_root_window_;
79
80   // The activated window.
81   ::Window current_window_;
82
83   ui::X11AtomCache atom_cache_;
84
85   bool wm_supports_active_window_;
86
87   DISALLOW_COPY_AND_ASSIGN(X11DesktopHandler);
88 };
89
90 }  // namespace views
91
92 #endif  // UI_VIEWS_WIDGET_DESKTOP_AURA_X11_DESKTOP_HANDLER_H_