1 // Copyright 2014 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/native_viewport.h"
7 #include "ui/events/event.h"
8 #include "ui/events/platform/platform_event_dispatcher.h"
9 #include "ui/events/platform/platform_event_source.h"
10 #include "ui/ozone/public/cursor_factory_ozone.h"
11 #include "ui/ozone/public/event_factory_ozone.h"
12 #include "ui/ozone/public/ozone_platform.h"
13 #include "ui/ozone/public/surface_factory_ozone.h"
14 #include "ui/platform_window/platform_window.h"
15 #include "ui/platform_window/platform_window_delegate.h"
20 // TODO(spang): Deduplicate with NativeViewportX11.. but there's a hack
21 // in there that prevents this.
22 class NativeViewportOzone
: public NativeViewport
,
23 public ui::PlatformWindowDelegate
{
25 explicit NativeViewportOzone(NativeViewportDelegate
* delegate
)
26 : delegate_(delegate
) {
27 ui::OzonePlatform::InitializeForUI();
30 virtual ~NativeViewportOzone() {
31 // Destroy the platform-window while |this| is still alive.
32 platform_window_
.reset();
36 // Overridden from NativeViewport:
37 virtual void Init(const gfx::Rect
& bounds
) OVERRIDE
{
39 ui::OzonePlatform::GetInstance()->CreatePlatformWindow(this, bounds
);
42 virtual void Show() OVERRIDE
{ platform_window_
->Show(); }
44 virtual void Hide() OVERRIDE
{ platform_window_
->Hide(); }
46 virtual void Close() OVERRIDE
{ platform_window_
->Close(); }
48 virtual gfx::Size
GetSize() OVERRIDE
{
49 return platform_window_
->GetBounds().size();
52 virtual void SetBounds(const gfx::Rect
& bounds
) OVERRIDE
{
53 platform_window_
->SetBounds(bounds
);
56 virtual void SetCapture() OVERRIDE
{ platform_window_
->SetCapture(); }
58 virtual void ReleaseCapture() OVERRIDE
{ platform_window_
->ReleaseCapture(); }
60 // ui::PlatformWindowDelegate:
61 virtual void OnBoundsChanged(const gfx::Rect
& new_bounds
) OVERRIDE
{
62 delegate_
->OnBoundsChanged(new_bounds
);
65 virtual void OnDamageRect(const gfx::Rect
& damaged_region
) OVERRIDE
{}
67 virtual void DispatchEvent(ui::Event
* event
) OVERRIDE
{
68 delegate_
->OnEvent(event
);
71 virtual void OnCloseRequest() OVERRIDE
{ platform_window_
->Close(); }
73 virtual void OnClosed() OVERRIDE
{ delegate_
->OnDestroyed(); }
75 virtual void OnWindowStateChanged(ui::PlatformWindowState state
) OVERRIDE
{}
77 virtual void OnLostCapture() OVERRIDE
{}
79 virtual void OnAcceleratedWidgetAvailable(
80 gfx::AcceleratedWidget widget
) OVERRIDE
{
81 delegate_
->OnAcceleratedWidgetAvailable(widget
);
84 scoped_ptr
<ui::PlatformWindow
> platform_window_
;
85 NativeViewportDelegate
* delegate_
;
87 DISALLOW_COPY_AND_ASSIGN(NativeViewportOzone
);
91 scoped_ptr
<NativeViewport
> NativeViewport::Create(
92 shell::Context
* context
,
93 NativeViewportDelegate
* delegate
) {
94 return scoped_ptr
<NativeViewport
>(new NativeViewportOzone(delegate
)).Pass();
97 } // namespace services