OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 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 #include "wm/host/foreign_window_host_linux.h" |
| 6 |
| 7 #include <X11/extensions/Xdamage.h> |
| 8 |
| 9 #include "wm/host/foreign_window_host_delegate.h" |
| 10 |
| 11 namespace wm { |
| 12 |
| 13 ForeignWindowHostLinux::ForeignWindowHostLinux( |
| 14 gfx::PluginWindowHandle window_handle) : |
| 15 xdisplay_(base::MessagePumpAuraX11::GetDefaultXDisplay()), |
| 16 window_handle_(window_handle), |
| 17 delegate_(NULL) { |
| 18 DCHECK(window_handle_); |
| 19 // Damage resource is automatically freed when the window is destroyed or |
| 20 // we close our connection to the X server. |
| 21 // TODO(reveman): Ignore possible X error. |
| 22 XDamageCreate(xdisplay_, window_handle_, XDamageReportRawRectangles); |
| 23 base::MessagePumpAuraX11::Current()->AddDispatcherForWindow( |
| 24 this, window_handle_); |
| 25 } |
| 26 |
| 27 ForeignWindowHostLinux::~ForeignWindowHostLinux() { |
| 28 if (window_handle_) { |
| 29 base::MessagePumpAuraX11::Current()->RemoveDispatcherForWindow( |
| 30 window_handle_); |
| 31 } |
| 32 } |
| 33 |
| 34 void ForeignWindowHostLinux::SetDelegate(ForeignWindowHostDelegate* delegate) { |
| 35 DCHECK(!delegate_); |
| 36 delegate_ = delegate; |
| 37 } |
| 38 |
| 39 gfx::PluginWindowHandle ForeignWindowHostLinux::GetWindowHandle() const { |
| 40 return window_handle_; |
| 41 } |
| 42 |
| 43 void ForeignWindowHostLinux::Close() { |
| 44 DCHECK(window_handle_); |
| 45 // TODO(reveman): Close managed window by sending a client message. |
| 46 } |
| 47 |
| 48 void ForeignWindowHostLinux::OnWindowDestroyed() { |
| 49 DCHECK(window_handle_); |
| 50 base::MessagePumpAuraX11::Current()->RemoveDispatcherForWindow( |
| 51 window_handle_); |
| 52 window_handle_ = 0; |
| 53 } |
| 54 |
| 55 bool ForeignWindowHostLinux::Dispatch(const base::NativeEvent& event) { |
| 56 DCHECK(window_handle_); |
| 57 // TODO(reveman): Only schedule repaint of the area that was damaged. |
| 58 delegate_->OnWindowContentsChanged(); |
| 59 return true; |
| 60 } |
| 61 |
| 62 // static |
| 63 ForeignWindowHost* ForeignWindowHost::Create( |
| 64 gfx::PluginWindowHandle window_handle) { |
| 65 return new ForeignWindowHostLinux(window_handle); |
| 66 } |
| 67 |
| 68 } // namespace wm |
OLD | NEW |