Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / ui / aura / window_tree_host_ozone.cc
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 "ui/aura/window_tree_host_ozone.h"
6
7 #include "ui/aura/window_event_dispatcher.h"
8 #include "ui/base/cursor/ozone/cursor_factory_ozone.h"
9 #include "ui/events/ozone/event_factory_ozone.h"
10 #include "ui/events/platform/platform_event_source.h"
11 #include "ui/gfx/ozone/surface_factory_ozone.h"
12 #include "ui/ozone/ozone_platform.h"
13
14 namespace aura {
15
16 WindowTreeHostOzone::WindowTreeHostOzone(const gfx::Rect& bounds)
17     : widget_(0),
18       bounds_(bounds) {
19   ui::OzonePlatform::Initialize();
20
21   // EventFactoryOzone creates converters that obtain input events from the
22   // underlying input system and dispatch them as |ui::Event| instances into
23   // Aura.
24   ui::EventFactoryOzone::GetInstance()->StartProcessingEvents();
25
26   gfx::SurfaceFactoryOzone* surface_factory =
27       gfx::SurfaceFactoryOzone::GetInstance();
28   widget_ = surface_factory->GetAcceleratedWidget();
29
30   ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this);
31   CreateCompositor(GetAcceleratedWidget());
32 }
33
34 WindowTreeHostOzone::~WindowTreeHostOzone() {
35   ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this);
36   DestroyCompositor();
37   DestroyDispatcher();
38 }
39
40 bool WindowTreeHostOzone::CanDispatchEvent(const ui::PlatformEvent& ne) {
41   CHECK(ne);
42   ui::Event* event = static_cast<ui::Event*>(ne);
43   if (event->IsMouseEvent() || event->IsScrollEvent())
44     return ui::CursorFactoryOzone::GetInstance()->GetCursorWindow() == widget_;
45
46   return true;
47 }
48
49 uint32_t WindowTreeHostOzone::DispatchEvent(const ui::PlatformEvent& ne) {
50   ui::Event* event = static_cast<ui::Event*>(ne);
51   ui::EventDispatchDetails details ALLOW_UNUSED = SendEventToProcessor(event);
52   return ui::POST_DISPATCH_STOP_PROPAGATION;
53 }
54
55 ui::EventSource* WindowTreeHostOzone::GetEventSource() {
56   return this;
57 }
58
59 gfx::AcceleratedWidget WindowTreeHostOzone::GetAcceleratedWidget() {
60   return widget_;
61 }
62
63 void WindowTreeHostOzone::Show() { NOTIMPLEMENTED(); }
64
65 void WindowTreeHostOzone::Hide() { NOTIMPLEMENTED(); }
66
67 gfx::Rect WindowTreeHostOzone::GetBounds() const { return bounds_; }
68
69 void WindowTreeHostOzone::SetBounds(const gfx::Rect& bounds) {
70   bool origin_changed = bounds_.origin() != bounds.origin();
71   bool size_changed = bounds_.size() != bounds.size();
72   bounds_ = bounds;
73   if (size_changed)
74     OnHostResized(bounds_.size());
75   if (origin_changed)
76     OnHostMoved(bounds_.origin());
77 }
78
79 gfx::Point WindowTreeHostOzone::GetLocationOnNativeScreen() const {
80   return bounds_.origin();
81 }
82
83 void WindowTreeHostOzone::SetCapture() { NOTIMPLEMENTED(); }
84
85 void WindowTreeHostOzone::ReleaseCapture() { NOTIMPLEMENTED(); }
86
87 void WindowTreeHostOzone::PostNativeEvent(
88     const base::NativeEvent& native_event) {
89   NOTIMPLEMENTED();
90 }
91
92 void WindowTreeHostOzone::OnDeviceScaleFactorChanged(
93     float device_scale_factor) {
94   NOTIMPLEMENTED();
95 }
96
97 void WindowTreeHostOzone::SetCursorNative(gfx::NativeCursor cursor) {
98   ui::CursorFactoryOzone::GetInstance()->SetCursor(GetAcceleratedWidget(),
99                                                    cursor.platform());
100 }
101
102 void WindowTreeHostOzone::MoveCursorToNative(const gfx::Point& location) {
103   ui::EventFactoryOzone::GetInstance()->WarpCursorTo(GetAcceleratedWidget(),
104                                                      location);
105 }
106
107 void WindowTreeHostOzone::OnCursorVisibilityChangedNative(bool show) {
108   NOTIMPLEMENTED();
109 }
110
111 ui::EventProcessor* WindowTreeHostOzone::GetEventProcessor() {
112   return dispatcher();
113 }
114
115 // static
116 WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) {
117   return new WindowTreeHostOzone(bounds);
118 }
119
120 // static
121 gfx::Size WindowTreeHost::GetNativeScreenSize() {
122   NOTIMPLEMENTED();
123   return gfx::Size();
124 }
125
126 }  // namespace aura