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 ~CefWindowX11() override; 40 41 void Close(); 42 43 void Show(); 44 void Hide(); 45 46 void Focus(); 47 48 void SetBounds(const gfx::Rect& bounds); 49 50 gfx::Rect GetBoundsInScreen(); 51 52 views::DesktopWindowTreeHostLinux* GetHost(); 53 54 // ui::PlatformEventDispatcher methods: 55 bool CanDispatchEvent(const ui::PlatformEvent& event) override; 56 uint32_t DispatchEvent(const ui::PlatformEvent& event) override; 57 58 // x11::EventObserver methods: 59 void OnEvent(const x11::Event& event) override; 60 xwindow()61 x11::Window xwindow() const { return xwindow_; } bounds()62 gfx::Rect bounds() const { return bounds_; } 63 64 bool TopLevelAlwaysOnTop() const; 65 66 private: 67 void ContinueFocus(); 68 69 void ProcessXEvent(const x11::Event& xev); 70 71 CefRefPtr<CefBrowserHostBase> browser_; 72 73 // The display and the native X window hosting the root window. 74 x11::Connection* const connection_; 75 x11::Window parent_xwindow_; 76 x11::Window xwindow_; 77 78 // Events selected on |xwindow_|. 79 std::unique_ptr<x11::XScopedEventSelector> xwindow_events_; 80 81 // Is the window mapped to the screen? 82 bool window_mapped_ = false; 83 84 // The bounds of |xwindow_|. 85 gfx::Rect bounds_; 86 87 bool focus_pending_ = false; 88 89 // Must always be the last member. 90 base::WeakPtrFactory<CefWindowX11> weak_ptr_factory_; 91 92 DISALLOW_COPY_AND_ASSIGN(CefWindowX11); 93 }; 94 95 #endif // CEF_LIBCEF_BROWSER_NATIVE_WINDOW_X11_H_ 96