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 "ui/aura/window_tree_host_ozone.h"
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"
16 WindowTreeHostOzone::WindowTreeHostOzone(const gfx::Rect& bounds)
19 ui::OzonePlatform::Initialize();
21 // EventFactoryOzone creates converters that obtain input events from the
22 // underlying input system and dispatch them as |ui::Event| instances into
24 ui::EventFactoryOzone::GetInstance()->StartProcessingEvents();
26 gfx::SurfaceFactoryOzone* surface_factory =
27 gfx::SurfaceFactoryOzone::GetInstance();
28 widget_ = surface_factory->GetAcceleratedWidget();
30 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this);
31 CreateCompositor(GetAcceleratedWidget());
34 WindowTreeHostOzone::~WindowTreeHostOzone() {
35 ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this);
40 bool WindowTreeHostOzone::CanDispatchEvent(const ui::PlatformEvent& ne) {
42 ui::Event* event = static_cast<ui::Event*>(ne);
43 if (event->IsMouseEvent() || event->IsScrollEvent())
44 return ui::CursorFactoryOzone::GetInstance()->GetCursorWindow() == widget_;
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;
55 ui::EventSource* WindowTreeHostOzone::GetEventSource() {
59 gfx::AcceleratedWidget WindowTreeHostOzone::GetAcceleratedWidget() {
63 void WindowTreeHostOzone::Show() { NOTIMPLEMENTED(); }
65 void WindowTreeHostOzone::Hide() { NOTIMPLEMENTED(); }
67 gfx::Rect WindowTreeHostOzone::GetBounds() const { return bounds_; }
69 void WindowTreeHostOzone::SetBounds(const gfx::Rect& bounds) {
70 bool origin_changed = bounds_.origin() != bounds.origin();
71 bool size_changed = bounds_.size() != bounds.size();
74 OnHostResized(bounds_.size());
76 OnHostMoved(bounds_.origin());
79 gfx::Point WindowTreeHostOzone::GetLocationOnNativeScreen() const {
80 return bounds_.origin();
83 void WindowTreeHostOzone::SetCapture() { NOTIMPLEMENTED(); }
85 void WindowTreeHostOzone::ReleaseCapture() { NOTIMPLEMENTED(); }
87 void WindowTreeHostOzone::PostNativeEvent(
88 const base::NativeEvent& native_event) {
92 void WindowTreeHostOzone::OnDeviceScaleFactorChanged(
93 float device_scale_factor) {
97 void WindowTreeHostOzone::SetCursorNative(gfx::NativeCursor cursor) {
98 ui::CursorFactoryOzone::GetInstance()->SetCursor(GetAcceleratedWidget(),
102 void WindowTreeHostOzone::MoveCursorToNative(const gfx::Point& location) {
103 ui::EventFactoryOzone::GetInstance()->WarpCursorTo(GetAcceleratedWidget(),
107 void WindowTreeHostOzone::OnCursorVisibilityChangedNative(bool show) {
111 ui::EventProcessor* WindowTreeHostOzone::GetEventProcessor() {
116 WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) {
117 return new WindowTreeHostOzone(bounds);
121 gfx::Size WindowTreeHost::GetNativeScreenSize() {