| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mojo/services/native_viewport/native_viewport.h" | 5 #include "mojo/services/native_viewport/native_viewport.h" |
| 6 | 6 |
| 7 #include <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
| 8 | 8 |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/message_loop/message_pump_x11.h" | 10 #include "base/message_loop/message_pump_x11.h" |
| 11 #include "ui/gfx/rect.h" | 11 #include "ui/gfx/rect.h" |
| 12 #include "ui/gfx/x/x11_types.h" | 12 #include "ui/gfx/x/x11_types.h" |
| 13 | 13 |
| 14 namespace mojo { | 14 namespace mojo { |
| 15 namespace services { | 15 namespace services { |
| 16 | 16 |
| 17 class NativeViewportX11 : public NativeViewport, | 17 class NativeViewportX11 : public NativeViewport, |
| 18 public base::MessagePumpDispatcher { | 18 public base::MessagePumpDispatcher { |
| 19 public: | 19 public: |
| 20 NativeViewportX11(NativeViewportDelegate* delegate) | 20 NativeViewportX11(NativeViewportDelegate* delegate) |
| 21 : delegate_(delegate), | 21 : delegate_(delegate), |
| 22 bounds_(10, 10, 500, 500) { | 22 bounds_(10, 10, 500, 500) { |
| 23 } |
| 24 |
| 25 virtual ~NativeViewportX11() { |
| 26 base::MessagePumpX11::Current()->RemoveDispatcherForRootWindow(this); |
| 27 base::MessagePumpX11::Current()->RemoveDispatcherForWindow(window_); |
| 28 |
| 29 XDestroyWindow(gfx::GetXDisplay(), window_); |
| 30 } |
| 31 |
| 32 private: |
| 33 // Overridden from NativeViewport: |
| 34 |
| 35 virtual gfx::Size GetSize() OVERRIDE { |
| 36 return bounds_.size(); |
| 37 } |
| 38 |
| 39 virtual void Open() OVERRIDE { |
| 23 XDisplay* display = gfx::GetXDisplay(); | 40 XDisplay* display = gfx::GetXDisplay(); |
| 24 XSetWindowAttributes swa; | 41 XSetWindowAttributes swa; |
| 25 memset(&swa, 0, sizeof(swa)); | 42 memset(&swa, 0, sizeof(swa)); |
| 26 swa.override_redirect = False; | 43 swa.override_redirect = False; |
| 27 window_ = XCreateWindow( | 44 window_ = XCreateWindow( |
| 28 display, | 45 display, |
| 29 DefaultRootWindow(display), | 46 DefaultRootWindow(display), |
| 30 bounds_.x(), bounds_.y(), bounds_.width(), bounds_.height(), | 47 bounds_.x(), bounds_.y(), bounds_.width(), bounds_.height(), |
| 31 0, // border width | 48 0, // border width |
| 32 CopyFromParent, // depth | 49 CopyFromParent, // depth |
| 33 InputOutput, | 50 InputOutput, |
| 34 CopyFromParent, // visual | 51 CopyFromParent, // visual |
| 35 CWBackPixmap | CWOverrideRedirect, &swa); | 52 CWBackPixmap | CWOverrideRedirect, &swa); |
| 36 | 53 |
| 37 base::MessagePumpX11::Current()->AddDispatcherForWindow(this, window_); | 54 base::MessagePumpX11::Current()->AddDispatcherForWindow(this, window_); |
| 38 base::MessagePumpX11::Current()->AddDispatcherForRootWindow(this); | 55 base::MessagePumpX11::Current()->AddDispatcherForRootWindow(this); |
| 39 | 56 |
| 40 XMapWindow(display, window_); | 57 XMapWindow(display, window_); |
| 41 XFlush(display); | 58 XFlush(display); |
| 42 | 59 |
| 43 delegate_->OnAcceleratedWidgetAvailable(window_); | 60 delegate_->OnAcceleratedWidgetAvailable(window_); |
| 44 } | 61 } |
| 45 | 62 |
| 46 virtual ~NativeViewportX11() { | |
| 47 base::MessagePumpX11::Current()->RemoveDispatcherForRootWindow(this); | |
| 48 base::MessagePumpX11::Current()->RemoveDispatcherForWindow(window_); | |
| 49 | |
| 50 XDestroyWindow(gfx::GetXDisplay(), window_); | |
| 51 } | |
| 52 | |
| 53 private: | |
| 54 // Overridden from NativeViewport: | |
| 55 virtual gfx::Size GetSize() OVERRIDE { | |
| 56 return bounds_.size(); | |
| 57 } | |
| 58 virtual void Close() OVERRIDE { | 63 virtual void Close() OVERRIDE { |
| 59 // TODO(beng): perform this in response to XWindow destruction. | 64 // TODO(beng): perform this in response to XWindow destruction. |
| 60 delegate_->OnDestroyed(); | 65 delegate_->OnDestroyed(); |
| 61 } | 66 } |
| 62 | 67 |
| 63 // Overridden from base::MessagePumpDispatcher: | 68 // Overridden from base::MessagePumpDispatcher: |
| 64 virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE { | 69 virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE { |
| 65 return true; | 70 return true; |
| 66 } | 71 } |
| 67 | 72 |
| 68 NativeViewportDelegate* delegate_; | 73 NativeViewportDelegate* delegate_; |
| 69 gfx::Rect bounds_; | 74 gfx::Rect bounds_; |
| 70 XID window_; | 75 XID window_; |
| 71 | 76 |
| 72 DISALLOW_COPY_AND_ASSIGN(NativeViewportX11); | 77 DISALLOW_COPY_AND_ASSIGN(NativeViewportX11); |
| 73 }; | 78 }; |
| 74 | 79 |
| 75 // static | 80 // static |
| 76 scoped_ptr<NativeViewport> NativeViewport::Create( | 81 scoped_ptr<NativeViewport> NativeViewport::Create( |
| 77 shell::Context* context, | 82 shell::Context* context, |
| 78 NativeViewportDelegate* delegate) { | 83 NativeViewportDelegate* delegate) { |
| 79 return scoped_ptr<NativeViewport>(new NativeViewportX11(delegate)).Pass(); | 84 return scoped_ptr<NativeViewport>(new NativeViewportX11(delegate)).Pass(); |
| 80 } | 85 } |
| 81 | 86 |
| 82 } // namespace services | 87 } // namespace services |
| 83 } // namespace mojo | 88 } // namespace mojo |
| OLD | NEW |