platform_viewport_x11.cc revision 6e8cce623b6e4fe0c9e4af605d675dd9d0338c38
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 3// found in the LICENSE file. 4 5#include "mojo/services/native_viewport/platform_viewport.h" 6 7#include "base/command_line.h" 8#include "base/message_loop/message_loop.h" 9#include "ui/events/event.h" 10#include "ui/events/event_utils.h" 11#include "ui/events/platform/platform_event_dispatcher.h" 12#include "ui/events/platform/platform_event_source.h" 13#include "ui/gfx/rect.h" 14#include "ui/platform_window/platform_window.h" 15#include "ui/platform_window/platform_window_delegate.h" 16#include "ui/platform_window/x11/x11_window.h" 17 18namespace mojo { 19 20class PlatformViewportX11 : public PlatformViewport, 21 public ui::PlatformWindowDelegate { 22 public: 23 explicit PlatformViewportX11(Delegate* delegate) : delegate_(delegate) { 24 } 25 26 virtual ~PlatformViewportX11() { 27 // Destroy the platform-window while |this| is still alive. 28 platform_window_.reset(); 29 } 30 31 private: 32 // Overridden from PlatformViewport: 33 virtual void Init(const gfx::Rect& bounds) OVERRIDE { 34 CHECK(!event_source_); 35 CHECK(!platform_window_); 36 37 event_source_ = ui::PlatformEventSource::CreateDefault(); 38 39 platform_window_.reset(new ui::X11Window(this)); 40 platform_window_->SetBounds(bounds); 41 } 42 43 virtual void Show() OVERRIDE { 44 platform_window_->Show(); 45 } 46 47 virtual void Hide() OVERRIDE { 48 platform_window_->Hide(); 49 } 50 51 virtual void Close() OVERRIDE { 52 platform_window_->Close(); 53 } 54 55 virtual gfx::Size GetSize() OVERRIDE { 56 return bounds_.size(); 57 } 58 59 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE { 60 platform_window_->SetBounds(bounds); 61 } 62 63 virtual void SetCapture() OVERRIDE { 64 platform_window_->SetCapture(); 65 } 66 67 virtual void ReleaseCapture() OVERRIDE { 68 platform_window_->ReleaseCapture(); 69 } 70 71 // ui::PlatformWindowDelegate: 72 virtual void OnBoundsChanged(const gfx::Rect& new_bounds) OVERRIDE { 73 bounds_ = new_bounds; 74 delegate_->OnBoundsChanged(new_bounds); 75 } 76 77 virtual void OnDamageRect(const gfx::Rect& damaged_region) OVERRIDE { 78 } 79 80 virtual void DispatchEvent(ui::Event* event) OVERRIDE { 81 delegate_->OnEvent(event); 82 } 83 84 virtual void OnCloseRequest() OVERRIDE { 85 platform_window_->Close(); 86 } 87 88 virtual void OnClosed() OVERRIDE { 89 delegate_->OnDestroyed(); 90 } 91 92 virtual void OnWindowStateChanged(ui::PlatformWindowState state) OVERRIDE { 93 } 94 95 virtual void OnLostCapture() OVERRIDE { 96 } 97 98 virtual void OnAcceleratedWidgetAvailable( 99 gfx::AcceleratedWidget widget) OVERRIDE { 100 delegate_->OnAcceleratedWidgetAvailable(widget); 101 } 102 103 virtual void OnActivationChanged(bool active) OVERRIDE {} 104 105 scoped_ptr<ui::PlatformEventSource> event_source_; 106 scoped_ptr<ui::PlatformWindow> platform_window_; 107 Delegate* delegate_; 108 gfx::Rect bounds_; 109 110 DISALLOW_COPY_AND_ASSIGN(PlatformViewportX11); 111}; 112 113// static 114scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate) { 115 return scoped_ptr<PlatformViewport>(new PlatformViewportX11(delegate)).Pass(); 116} 117 118} // namespace mojo 119