OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "ui/events/event.h" | 7 #include "ui/events/event.h" |
8 #include "ui/events/platform/platform_event_dispatcher.h" | 8 #include "ui/events/platform/platform_event_dispatcher.h" |
9 #include "ui/events/platform/platform_event_source.h" | 9 #include "ui/events/platform/platform_event_source.h" |
10 #include "ui/ozone/public/cursor_factory_ozone.h" | 10 #include "ui/ozone/public/cursor_factory_ozone.h" |
11 #include "ui/ozone/public/event_factory_ozone.h" | 11 #include "ui/ozone/public/event_factory_ozone.h" |
| 12 #include "ui/ozone/public/ozone_platform.h" |
12 #include "ui/ozone/public/surface_factory_ozone.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" |
13 | 16 |
14 namespace mojo { | 17 namespace mojo { |
15 namespace services { | 18 namespace services { |
16 | 19 |
17 bool override_redirect = false; | 20 // TODO(spang): Deduplicate with NativeViewportX11.. but there's a hack |
18 | 21 // in there that prevents this. |
19 class NativeViewportOzone : public NativeViewport, | 22 class NativeViewportOzone : public NativeViewport, |
20 public ui::PlatformEventDispatcher { | 23 public ui::PlatformWindowDelegate { |
21 public: | 24 public: |
22 NativeViewportOzone(NativeViewportDelegate* delegate) | 25 explicit NativeViewportOzone(NativeViewportDelegate* delegate) |
23 : delegate_(delegate), | 26 : delegate_(delegate) { |
24 widget_(gfx::kNullAcceleratedWidget) { | 27 ui::OzonePlatform::InitializeForUI(); |
25 ui::SurfaceFactoryOzone* surface_factory = | |
26 ui::SurfaceFactoryOzone::GetInstance(); | |
27 widget_ = surface_factory->GetAcceleratedWidget(); | |
28 // TODO(sky): need to enable this. | |
29 // ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); | |
30 } | 28 } |
31 | 29 |
32 virtual ~NativeViewportOzone() { | 30 virtual ~NativeViewportOzone() { |
33 // TODO(sky): need to enable this. | 31 // Destroy the platform-window while |this| is still alive. |
34 // ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher( | 32 platform_window_.reset(); |
35 // this); | |
36 } | 33 } |
37 | 34 |
38 private: | 35 private: |
39 // Overridden from NativeViewport: | 36 // Overridden from NativeViewport: |
40 virtual void Init(const gfx::Rect& bounds) OVERRIDE { | 37 virtual void Init(const gfx::Rect& bounds) OVERRIDE { |
41 NOTIMPLEMENTED(); | 38 platform_window_ = |
42 bounds_ = bounds; | 39 ui::OzonePlatform::GetInstance()->CreatePlatformWindow(this, bounds); |
43 delegate_->OnAcceleratedWidgetAvailable(widget_); | |
44 } | 40 } |
45 | 41 |
46 virtual void Show() OVERRIDE { | 42 virtual void Show() OVERRIDE { platform_window_->Show(); } |
47 NOTIMPLEMENTED(); | |
48 } | |
49 | 43 |
50 virtual void Hide() OVERRIDE { | 44 virtual void Hide() OVERRIDE { platform_window_->Hide(); } |
51 NOTIMPLEMENTED(); | |
52 } | |
53 | 45 |
54 virtual void Close() OVERRIDE { | 46 virtual void Close() OVERRIDE { platform_window_->Close(); } |
55 delegate_->OnDestroyed(); | |
56 } | |
57 | 47 |
58 virtual gfx::Size GetSize() OVERRIDE { | 48 virtual gfx::Size GetSize() OVERRIDE { |
59 return bounds_.size(); | 49 return platform_window_->GetBounds().size(); |
60 } | 50 } |
61 | 51 |
62 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE { | 52 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE { |
63 bounds_ = bounds; | 53 platform_window_->SetBounds(bounds); |
64 NOTIMPLEMENTED(); | |
65 } | 54 } |
66 | 55 |
67 virtual void SetCapture() OVERRIDE { | 56 virtual void SetCapture() OVERRIDE { platform_window_->SetCapture(); } |
68 NOTIMPLEMENTED(); | 57 |
| 58 virtual void ReleaseCapture() OVERRIDE { platform_window_->ReleaseCapture(); } |
| 59 |
| 60 // ui::PlatformWindowDelegate: |
| 61 virtual void OnBoundsChanged(const gfx::Rect& new_bounds) OVERRIDE { |
| 62 delegate_->OnBoundsChanged(new_bounds); |
69 } | 63 } |
70 | 64 |
71 virtual void ReleaseCapture() OVERRIDE { | 65 virtual void OnDamageRect(const gfx::Rect& damaged_region) OVERRIDE {} |
72 NOTIMPLEMENTED(); | 66 |
| 67 virtual void DispatchEvent(ui::Event* event) OVERRIDE { |
| 68 delegate_->OnEvent(event); |
73 } | 69 } |
74 | 70 |
75 // ui::PlatformEventDispatcher: | 71 virtual void OnCloseRequest() OVERRIDE { platform_window_->Close(); } |
76 virtual bool CanDispatchEvent(const ui::PlatformEvent& ne) OVERRIDE { | |
77 CHECK(ne); | |
78 ui::Event* event = static_cast<ui::Event*>(ne); | |
79 if (event->IsMouseEvent() || event->IsScrollEvent()) { | |
80 return ui::CursorFactoryOzone::GetInstance()->GetCursorWindow() == | |
81 widget_; | |
82 } | |
83 | 72 |
84 return true; | 73 virtual void OnClosed() OVERRIDE { delegate_->OnDestroyed(); } |
| 74 |
| 75 virtual void OnWindowStateChanged(ui::PlatformWindowState state) OVERRIDE {} |
| 76 |
| 77 virtual void OnLostCapture() OVERRIDE {} |
| 78 |
| 79 virtual void OnAcceleratedWidgetAvailable( |
| 80 gfx::AcceleratedWidget widget) OVERRIDE { |
| 81 delegate_->OnAcceleratedWidgetAvailable(widget); |
85 } | 82 } |
86 | 83 |
87 virtual uint32_t DispatchEvent(const ui::PlatformEvent& ne) OVERRIDE { | 84 scoped_ptr<ui::PlatformWindow> platform_window_; |
88 ui::Event* event = static_cast<ui::Event*>(ne); | |
89 delegate_->OnEvent(event); | |
90 return ui::POST_DISPATCH_STOP_PROPAGATION; | |
91 } | |
92 | |
93 NativeViewportDelegate* delegate_; | 85 NativeViewportDelegate* delegate_; |
94 gfx::AcceleratedWidget widget_; | |
95 gfx::Rect bounds_; | |
96 | 86 |
97 DISALLOW_COPY_AND_ASSIGN(NativeViewportOzone); | 87 DISALLOW_COPY_AND_ASSIGN(NativeViewportOzone); |
98 }; | 88 }; |
99 | 89 |
100 // static | 90 // static |
101 scoped_ptr<NativeViewport> NativeViewport::Create( | 91 scoped_ptr<NativeViewport> NativeViewport::Create( |
102 shell::Context* context, | 92 shell::Context* context, |
103 NativeViewportDelegate* delegate) { | 93 NativeViewportDelegate* delegate) { |
104 return scoped_ptr<NativeViewport>(new NativeViewportOzone(delegate)).Pass(); | 94 return scoped_ptr<NativeViewport>(new NativeViewportOzone(delegate)).Pass(); |
105 } | 95 } |
106 | 96 |
107 } // namespace services | 97 } // namespace services |
108 } // namespace mojo | 98 } // namespace mojo |
OLD | NEW |