OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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_platform.h" | |
6 | |
7 | |
sadrul
2015/10/15 19:47:40
Remove extra blank line.
no sievers
2015/10/16 18:26:15
Done.
| |
8 #include <algorithm> | |
9 | |
10 #if defined(OS_WIN) | |
11 #include <windows.h> | |
12 #endif | |
13 | |
14 #include "base/trace_event/trace_event.h" | |
15 #include "ui/aura/window_event_dispatcher.h" | |
16 #include "ui/compositor/compositor.h" | |
17 #include "ui/events/event.h" | |
18 | |
19 #if defined(OS_ANDROID) | |
20 #include "ui/platform_window/android/platform_window_android.h" | |
21 #endif | |
22 | |
23 #if defined(USE_OZONE) | |
24 #include "ui/ozone/public/ozone_platform.h" | |
25 #endif | |
26 | |
27 #if defined(OS_WIN) | |
28 #include "base/message_loop/message_loop.h" | |
29 #include "ui/base/cursor/cursor_loader_win.h" | |
30 #include "ui/platform_window/win/win_window.h" | |
31 #endif | |
32 | |
33 using std::max; | |
34 using std::min; | |
35 | |
36 namespace aura { | |
37 | |
38 // static | |
39 WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) { | |
40 return new WindowTreeHostPlatform(bounds); | |
41 } | |
42 | |
43 WindowTreeHostPlatform::WindowTreeHostPlatform(const gfx::Rect& bounds) | |
44 : widget_(gfx::kNullAcceleratedWidget), | |
45 current_cursor_(ui::kCursorNull), | |
46 has_capture_(false) { | |
47 #if defined(USE_OZONE) | |
48 window_ = | |
49 ui::OzonePlatform::GetInstance()->CreatePlatformWindow(this, bounds); | |
50 #elif defined(OS_WIN) | |
51 window_.reset(new ui::WinWindow(this, bounds)); | |
52 #elif defined(OS_ANDROID) | |
53 window_.reset(new ui::PlatformWindowAndroid(this)); | |
54 #else | |
55 NOTIMPLEMENTED(); | |
56 #endif | |
57 } | |
58 | |
59 WindowTreeHostPlatform::~WindowTreeHostPlatform() { | |
60 DestroyCompositor(); | |
61 DestroyDispatcher(); | |
62 } | |
63 | |
64 ui::EventSource* WindowTreeHostPlatform::GetEventSource() { | |
65 return this; | |
66 } | |
67 | |
68 gfx::AcceleratedWidget WindowTreeHostPlatform::GetAcceleratedWidget() { | |
69 return widget_; | |
70 } | |
71 | |
72 void WindowTreeHostPlatform::ShowImpl() { | |
73 window_->Show(); | |
74 } | |
75 | |
76 void WindowTreeHostPlatform::HideImpl() { | |
77 window_->Hide(); | |
78 } | |
79 | |
80 gfx::Rect WindowTreeHostPlatform::GetBounds() const { | |
81 return window_->GetBounds(); | |
82 } | |
83 | |
84 void WindowTreeHostPlatform::SetBounds(const gfx::Rect& bounds) { | |
85 window_->SetBounds(bounds); | |
86 } | |
87 | |
88 gfx::Point WindowTreeHostPlatform::GetLocationOnNativeScreen() const { | |
89 return window_->GetBounds().origin(); | |
90 } | |
91 | |
92 void WindowTreeHostPlatform::SetCapture() { | |
93 if (!has_capture_) { | |
94 has_capture_ = true; | |
95 window_->SetCapture(); | |
96 } | |
97 } | |
98 | |
99 void WindowTreeHostPlatform::ReleaseCapture() { | |
100 if (has_capture_) | |
101 window_->ReleaseCapture(); | |
102 } | |
103 | |
104 void WindowTreeHostPlatform::SetCursorNative(gfx::NativeCursor cursor) { | |
105 if (cursor == current_cursor_) | |
106 return; | |
107 current_cursor_ = cursor; | |
108 | |
109 #if defined(OS_WIN) | |
110 // Custom web cursors are handled directly. | |
111 if (cursor == ui::kCursorCustom) | |
112 return; | |
113 | |
114 ui::CursorLoaderWin cursor_loader; | |
115 cursor_loader.SetPlatformCursor(&cursor); | |
116 ::SetCursor(cursor.platform()); | |
sadrul
2015/10/15 19:47:40
Can this bit move into WinWindow() instead, and we
no sievers
2015/10/16 18:26:15
Done.
| |
117 #else | |
118 window_->SetCursor(cursor.platform()); | |
119 #endif | |
120 } | |
121 | |
122 void WindowTreeHostPlatform::MoveCursorToNative(const gfx::Point& location) { | |
123 #if defined(OS_WIN) | |
124 // Deliberately not implemented. | |
125 #else | |
126 window_->MoveCursorTo(location); | |
127 #endif | |
sadrul
2015/10/15 19:47:39
WinWindow::MoveCursorTo() doesn't do anything. So
no sievers
2015/10/16 18:26:15
Done.
| |
128 } | |
129 | |
130 void WindowTreeHostPlatform::OnCursorVisibilityChangedNative(bool show) { | |
131 NOTIMPLEMENTED(); | |
132 } | |
133 | |
134 void WindowTreeHostPlatform::OnBoundsChanged(const gfx::Rect& new_bounds) { | |
135 gfx::Rect old_bounds = bounds_; | |
136 bounds_ = new_bounds; | |
137 if (bounds_.origin() != old_bounds.origin()) | |
no sievers
2015/10/16 00:06:14
These two optimizations for redundant calls are ca
| |
138 OnHostMoved(bounds_.origin()); | |
139 if (bounds_.size() != old_bounds.size()) | |
140 OnHostResized(bounds_.size()); | |
141 } | |
142 | |
143 void WindowTreeHostPlatform::OnDamageRect(const gfx::Rect& damage_rect) { | |
144 compositor()->ScheduleRedrawRect(damage_rect); | |
145 } | |
146 | |
147 void WindowTreeHostPlatform::DispatchEvent(ui::Event* event) { | |
148 TRACE_EVENT0("input", "WindowTreeHostPlatform::DispatchEvent"); | |
149 ui::EventDispatchDetails details = SendEventToProcessor(event); | |
150 if (details.dispatcher_destroyed) | |
151 event->SetHandled(); | |
152 } | |
153 | |
154 void WindowTreeHostPlatform::OnCloseRequest() { | |
155 #if defined(OS_WIN) | |
156 // TODO: this obviously shouldn't be here. | |
157 base::MessageLoopForUI::current()->QuitWhenIdle(); | |
158 #else | |
159 OnHostCloseRequested(); | |
160 #endif | |
161 } | |
162 | |
163 void WindowTreeHostPlatform::OnClosed() {} | |
164 | |
165 void WindowTreeHostPlatform::OnWindowStateChanged( | |
166 ui::PlatformWindowState new_state) {} | |
167 | |
168 void WindowTreeHostPlatform::OnLostCapture() { | |
169 if (has_capture_) { | |
170 has_capture_ = false; | |
171 OnHostLostWindowCapture(); | |
172 } | |
173 } | |
174 | |
175 void WindowTreeHostPlatform::OnAcceleratedWidgetAvailable( | |
176 gfx::AcceleratedWidget widget, | |
177 float device_pixel_ratio) { | |
178 widget_ = widget; | |
179 CreateCompositor(); | |
180 WindowTreeHost::OnAcceleratedWidgetAvailable(); | |
181 } | |
182 | |
183 void WindowTreeHostPlatform::OnActivationChanged(bool active) { | |
184 if (active) | |
185 OnHostActivated(); | |
186 } | |
187 | |
188 } // namespace aura | |
OLD | NEW |