• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 The Chromium Embedded Framework Authors.
2 // Portions copyright 2014 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 
6 #ifndef CEF_LIBCEF_BROWSER_NATIVE_WINDOW_X11_H_
7 #define CEF_LIBCEF_BROWSER_NATIVE_WINDOW_X11_H_
8 #pragma once
9 
10 #include <memory>
11 
12 #include "include/internal/cef_ptr.h"
13 
14 #include "base/memory/weak_ptr.h"
15 #include "ui/events/platform/platform_event_dispatcher.h"
16 #include "ui/gfx/geometry/rect.h"
17 #include "ui/gfx/x/connection.h"
18 #include "ui/gfx/x/x11_atom_cache.h"
19 
20 namespace x11 {
21 class XScopedEventSelector;
22 }
23 
24 namespace views {
25 class DesktopWindowTreeHostLinux;
26 }
27 
28 class CefBrowserHostBase;
29 
30 // Object wrapper for an X11 Window.
31 // Based on WindowTreeHostX11 and DesktopWindowTreeHostX11.
32 class CefWindowX11 : public ui::PlatformEventDispatcher,
33                      public x11::EventObserver {
34  public:
35   CefWindowX11(CefRefPtr<CefBrowserHostBase> browser,
36                x11::Window parent_xwindow,
37                const gfx::Rect& bounds,
38                const std::string& title);
39 
40   CefWindowX11(const CefWindowX11&) = delete;
41   CefWindowX11& operator=(const CefWindowX11&) = delete;
42 
43   ~CefWindowX11() override;
44 
45   void Close();
46 
47   void Show();
48   void Hide();
49 
50   void Focus();
51 
52   void SetBounds(const gfx::Rect& bounds);
53 
54   gfx::Rect GetBoundsInScreen();
55 
56   views::DesktopWindowTreeHostLinux* GetHost();
57 
58   // ui::PlatformEventDispatcher methods:
59   bool CanDispatchEvent(const ui::PlatformEvent& event) override;
60   uint32_t DispatchEvent(const ui::PlatformEvent& event) override;
61 
62   // x11::EventObserver methods:
63   void OnEvent(const x11::Event& event) override;
64 
xwindow()65   x11::Window xwindow() const { return xwindow_; }
bounds()66   gfx::Rect bounds() const { return bounds_; }
67 
68   bool TopLevelAlwaysOnTop() const;
69 
70  private:
71   void ContinueFocus();
72 
73   void ProcessXEvent(const x11::Event& xev);
74 
75   CefRefPtr<CefBrowserHostBase> browser_;
76 
77   // The display and the native X window hosting the root window.
78   x11::Connection* const connection_;
79   x11::Window parent_xwindow_;
80   x11::Window xwindow_;
81 
82   // Events selected on |xwindow_|.
83   std::unique_ptr<x11::XScopedEventSelector> xwindow_events_;
84 
85   // Is the window mapped to the screen?
86   bool window_mapped_ = false;
87 
88   // The bounds of |xwindow_|.
89   gfx::Rect bounds_;
90 
91   bool focus_pending_ = false;
92 
93   // Must always be the last member.
94   base::WeakPtrFactory<CefWindowX11> weak_ptr_factory_;
95 };
96 
97 #endif  // CEF_LIBCEF_BROWSER_NATIVE_WINDOW_X11_H_
98