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.
5 #include "mojo/services/native_viewport/platform_viewport.h"
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"
20 class PlatformViewportX11
: public PlatformViewport
,
21 public ui::PlatformWindowDelegate
{
23 explicit PlatformViewportX11(Delegate
* delegate
) : delegate_(delegate
) {
26 virtual ~PlatformViewportX11() {
27 // Destroy the platform-window while |this| is still alive.
28 platform_window_
.reset();
32 // Overridden from PlatformViewport:
33 virtual void Init(const gfx::Rect
& bounds
) OVERRIDE
{
34 CHECK(!event_source_
);
35 CHECK(!platform_window_
);
37 event_source_
= ui::PlatformEventSource::CreateDefault();
39 platform_window_
.reset(new ui::X11Window(this));
40 platform_window_
->SetBounds(bounds
);
43 virtual void Show() OVERRIDE
{
44 platform_window_
->Show();
47 virtual void Hide() OVERRIDE
{
48 platform_window_
->Hide();
51 virtual void Close() OVERRIDE
{
52 platform_window_
->Close();
55 virtual gfx::Size
GetSize() OVERRIDE
{
56 return bounds_
.size();
59 virtual void SetBounds(const gfx::Rect
& bounds
) OVERRIDE
{
60 platform_window_
->SetBounds(bounds
);
63 virtual void SetCapture() OVERRIDE
{
64 platform_window_
->SetCapture();
67 virtual void ReleaseCapture() OVERRIDE
{
68 platform_window_
->ReleaseCapture();
71 // ui::PlatformWindowDelegate:
72 virtual void OnBoundsChanged(const gfx::Rect
& new_bounds
) OVERRIDE
{
74 delegate_
->OnBoundsChanged(new_bounds
);
77 virtual void OnDamageRect(const gfx::Rect
& damaged_region
) OVERRIDE
{
80 virtual void DispatchEvent(ui::Event
* event
) OVERRIDE
{
81 delegate_
->OnEvent(event
);
84 virtual void OnCloseRequest() OVERRIDE
{
85 platform_window_
->Close();
88 virtual void OnClosed() OVERRIDE
{
89 delegate_
->OnDestroyed();
92 virtual void OnWindowStateChanged(ui::PlatformWindowState state
) OVERRIDE
{
95 virtual void OnLostCapture() OVERRIDE
{
98 virtual void OnAcceleratedWidgetAvailable(
99 gfx::AcceleratedWidget widget
) OVERRIDE
{
100 delegate_
->OnAcceleratedWidgetAvailable(widget
);
103 virtual void OnActivationChanged(bool active
) OVERRIDE
{}
105 scoped_ptr
<ui::PlatformEventSource
> event_source_
;
106 scoped_ptr
<ui::PlatformWindow
> platform_window_
;
110 DISALLOW_COPY_AND_ASSIGN(PlatformViewportX11
);
114 scoped_ptr
<PlatformViewport
> PlatformViewport::Create(Delegate
* delegate
) {
115 return scoped_ptr
<PlatformViewport
>(new PlatformViewportX11(delegate
)).Pass();