OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "ui/aura/window_tree_host.h" | 5 #include "ui/aura/window_tree_host.h" |
6 | 6 |
7 #include "base/threading/thread_task_runner_handle.h" | 7 #include "base/threading/thread_task_runner_handle.h" |
8 #include "base/trace_event/trace_event.h" | 8 #include "base/trace_event/trace_event.h" |
9 #include "ui/aura/client/capture_client.h" | 9 #include "ui/aura/client/capture_client.h" |
10 #include "ui/aura/client/cursor_client.h" | 10 #include "ui/aura/client/cursor_client.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 | 54 |
55 // static | 55 // static |
56 WindowTreeHost* WindowTreeHost::GetForAcceleratedWidget( | 56 WindowTreeHost* WindowTreeHost::GetForAcceleratedWidget( |
57 gfx::AcceleratedWidget widget) { | 57 gfx::AcceleratedWidget widget) { |
58 return reinterpret_cast<WindowTreeHost*>( | 58 return reinterpret_cast<WindowTreeHost*>( |
59 ui::ViewProp::GetValue(widget, kWindowTreeHostForAcceleratedWidget)); | 59 ui::ViewProp::GetValue(widget, kWindowTreeHostForAcceleratedWidget)); |
60 } | 60 } |
61 | 61 |
62 void WindowTreeHost::InitHost() { | 62 void WindowTreeHost::InitHost() { |
63 InitCompositor(); | 63 InitCompositor(); |
64 UpdateRootWindowSize(GetBoundsInPixels().size()); | 64 UpdateRootWindowSizeInPixels(GetBoundsInPixels().size()); |
65 Env::GetInstance()->NotifyHostInitialized(this); | 65 Env::GetInstance()->NotifyHostInitialized(this); |
66 window()->Show(); | 66 window()->Show(); |
67 } | 67 } |
68 | 68 |
69 void WindowTreeHost::InitCompositor() { | 69 void WindowTreeHost::InitCompositor() { |
70 compositor_->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(window()), | 70 compositor_->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(window()), |
71 GetBoundsInPixels().size()); | 71 GetBoundsInPixels().size()); |
72 compositor_->SetRootLayer(window()->layer()); | 72 compositor_->SetRootLayer(window()->layer()); |
73 compositor_->SetDisplayColorSpace( | 73 compositor_->SetDisplayColorSpace( |
74 GetICCProfileForCurrentDisplay().GetColorSpace()); | 74 GetICCProfileForCurrentDisplay().GetColorSpace()); |
(...skipping 14 matching lines...) Expand all Loading... |
89 gfx::Transform WindowTreeHost::GetRootTransform() const { | 89 gfx::Transform WindowTreeHost::GetRootTransform() const { |
90 float scale = ui::GetDeviceScaleFactor(window()->layer()); | 90 float scale = ui::GetDeviceScaleFactor(window()->layer()); |
91 gfx::Transform transform; | 91 gfx::Transform transform; |
92 transform.Scale(scale, scale); | 92 transform.Scale(scale, scale); |
93 transform *= window()->layer()->transform(); | 93 transform *= window()->layer()->transform(); |
94 return transform; | 94 return transform; |
95 } | 95 } |
96 | 96 |
97 void WindowTreeHost::SetRootTransform(const gfx::Transform& transform) { | 97 void WindowTreeHost::SetRootTransform(const gfx::Transform& transform) { |
98 window()->SetTransform(transform); | 98 window()->SetTransform(transform); |
99 UpdateRootWindowSize(GetBoundsInPixels().size()); | 99 UpdateRootWindowSizeInPixels(GetBoundsInPixels().size()); |
100 } | 100 } |
101 | 101 |
102 gfx::Transform WindowTreeHost::GetInverseRootTransform() const { | 102 gfx::Transform WindowTreeHost::GetInverseRootTransform() const { |
103 gfx::Transform invert; | 103 gfx::Transform invert; |
104 gfx::Transform transform = GetRootTransform(); | 104 gfx::Transform transform = GetRootTransform(); |
105 if (!transform.GetInverse(&invert)) | 105 if (!transform.GetInverse(&invert)) |
106 return transform; | 106 return transform; |
107 return invert; | 107 return invert; |
108 } | 108 } |
109 | 109 |
110 void WindowTreeHost::SetOutputSurfacePadding(const gfx::Insets& padding) { | 110 void WindowTreeHost::SetOutputSurfacePaddingInPixels( |
111 if (output_surface_padding_ == padding) | 111 const gfx::Insets& padding_in_pixels) { |
| 112 if (output_surface_padding_in_pixels_ == padding_in_pixels) |
112 return; | 113 return; |
113 | 114 |
114 output_surface_padding_ = padding; | 115 output_surface_padding_in_pixels_ = padding_in_pixels; |
115 OnHostResized(GetBoundsInPixels().size()); | 116 OnHostResizedInPixels(GetBoundsInPixels().size()); |
116 } | 117 } |
117 | 118 |
118 void WindowTreeHost::UpdateRootWindowSize(const gfx::Size& host_size) { | 119 void WindowTreeHost::UpdateRootWindowSizeInPixels( |
119 gfx::Rect bounds(output_surface_padding_.left(), | 120 const gfx::Size& host_size_in_pixels) { |
120 output_surface_padding_.top(), host_size.width(), | 121 gfx::Rect bounds(output_surface_padding_in_pixels_.left(), |
121 host_size.height()); | 122 output_surface_padding_in_pixels_.top(), |
| 123 host_size_in_pixels.width(), host_size_in_pixels.height()); |
122 float scale_factor = ui::GetDeviceScaleFactor(window()->layer()); | 124 float scale_factor = ui::GetDeviceScaleFactor(window()->layer()); |
123 gfx::RectF new_bounds = | 125 gfx::RectF new_bounds = |
124 gfx::ScaleRect(gfx::RectF(bounds), 1.0f / scale_factor); | 126 gfx::ScaleRect(gfx::RectF(bounds), 1.0f / scale_factor); |
125 window()->layer()->transform().TransformRect(&new_bounds); | 127 window()->layer()->transform().TransformRect(&new_bounds); |
126 window()->SetBounds(gfx::ToEnclosingRect(new_bounds)); | 128 window()->SetBounds(gfx::ToEnclosingRect(new_bounds)); |
127 } | 129 } |
128 | 130 |
129 void WindowTreeHost::ConvertPointToNativeScreen(gfx::Point* point) const { | 131 void WindowTreeHost::ConvertDIPToScreenInPixels(gfx::Point* point) const { |
130 ConvertPointToHost(point); | 132 ConvertDIPToPixels(point); |
131 gfx::Point location = GetLocationOnNativeScreen(); | 133 gfx::Point location = GetLocationOnScreenInPixels(); |
132 point->Offset(location.x(), location.y()); | 134 point->Offset(location.x(), location.y()); |
133 } | 135 } |
134 | 136 |
135 void WindowTreeHost::ConvertPointFromNativeScreen(gfx::Point* point) const { | 137 void WindowTreeHost::ConvertScreenInPixelsToDIP(gfx::Point* point) const { |
136 gfx::Point location = GetLocationOnNativeScreen(); | 138 gfx::Point location = GetLocationOnScreenInPixels(); |
137 point->Offset(-location.x(), -location.y()); | 139 point->Offset(-location.x(), -location.y()); |
138 ConvertPointFromHost(point); | 140 ConvertPixelsToDIP(point); |
139 } | 141 } |
140 | 142 |
141 void WindowTreeHost::ConvertPointToHost(gfx::Point* point) const { | 143 void WindowTreeHost::ConvertDIPToPixels(gfx::Point* point) const { |
142 auto point_3f = gfx::Point3F(gfx::PointF(*point)); | 144 auto point_3f = gfx::Point3F(gfx::PointF(*point)); |
143 GetRootTransform().TransformPoint(&point_3f); | 145 GetRootTransform().TransformPoint(&point_3f); |
144 *point = gfx::ToFlooredPoint(point_3f.AsPointF()); | 146 *point = gfx::ToFlooredPoint(point_3f.AsPointF()); |
145 } | 147 } |
146 | 148 |
147 void WindowTreeHost::ConvertPointFromHost(gfx::Point* point) const { | 149 void WindowTreeHost::ConvertPixelsToDIP(gfx::Point* point) const { |
148 auto point_3f = gfx::Point3F(gfx::PointF(*point)); | 150 auto point_3f = gfx::Point3F(gfx::PointF(*point)); |
149 GetInverseRootTransform().TransformPoint(&point_3f); | 151 GetInverseRootTransform().TransformPoint(&point_3f); |
150 *point = gfx::ToFlooredPoint(point_3f.AsPointF()); | 152 *point = gfx::ToFlooredPoint(point_3f.AsPointF()); |
151 } | 153 } |
152 | 154 |
153 void WindowTreeHost::SetCursor(gfx::NativeCursor cursor) { | 155 void WindowTreeHost::SetCursor(gfx::NativeCursor cursor) { |
154 last_cursor_ = cursor; | 156 last_cursor_ = cursor; |
155 // A lot of code seems to depend on NULL cursors actually showing an arrow, | 157 // A lot of code seems to depend on NULL cursors actually showing an arrow, |
156 // so just pass everything along to the host. | 158 // so just pass everything along to the host. |
157 SetCursorNative(cursor); | 159 SetCursorNative(cursor); |
158 } | 160 } |
159 | 161 |
160 void WindowTreeHost::OnCursorVisibilityChanged(bool show) { | 162 void WindowTreeHost::OnCursorVisibilityChanged(bool show) { |
161 // Clear any existing mouse hover effects when the cursor becomes invisible. | 163 // Clear any existing mouse hover effects when the cursor becomes invisible. |
162 // Note we do not need to dispatch a mouse enter when the cursor becomes | 164 // Note we do not need to dispatch a mouse enter when the cursor becomes |
163 // visible because that can only happen in response to a mouse event, which | 165 // visible because that can only happen in response to a mouse event, which |
164 // will trigger its own mouse enter. | 166 // will trigger its own mouse enter. |
165 if (!show) { | 167 if (!show) { |
166 ui::EventDispatchDetails details = dispatcher()->DispatchMouseExitAtPoint( | 168 ui::EventDispatchDetails details = dispatcher()->DispatchMouseExitAtPoint( |
167 nullptr, dispatcher()->GetLastMouseLocationInRoot()); | 169 nullptr, dispatcher()->GetLastMouseLocationInRoot()); |
168 if (details.dispatcher_destroyed) | 170 if (details.dispatcher_destroyed) |
169 return; | 171 return; |
170 } | 172 } |
171 | 173 |
172 OnCursorVisibilityChangedNative(show); | 174 OnCursorVisibilityChangedNative(show); |
173 } | 175 } |
174 | 176 |
175 void WindowTreeHost::MoveCursorTo(const gfx::Point& location_in_dip) { | 177 void WindowTreeHost::MoveCursorToLocationInDIP( |
| 178 const gfx::Point& location_in_dip) { |
176 gfx::Point host_location(location_in_dip); | 179 gfx::Point host_location(location_in_dip); |
177 ConvertPointToHost(&host_location); | 180 ConvertDIPToPixels(&host_location); |
178 MoveCursorToInternal(location_in_dip, host_location); | 181 MoveCursorToInternal(location_in_dip, host_location); |
179 } | 182 } |
180 | 183 |
181 void WindowTreeHost::MoveCursorToHostLocation(const gfx::Point& host_location) { | 184 void WindowTreeHost::MoveCursorToLocationInPixels( |
182 gfx::Point root_location(host_location); | 185 const gfx::Point& location_in_pixels) { |
183 ConvertPointFromHost(&root_location); | 186 gfx::Point root_location(location_in_pixels); |
184 MoveCursorToInternal(root_location, host_location); | 187 ConvertPixelsToDIP(&root_location); |
| 188 MoveCursorToInternal(root_location, location_in_pixels); |
185 } | 189 } |
186 | 190 |
187 ui::InputMethod* WindowTreeHost::GetInputMethod() { | 191 ui::InputMethod* WindowTreeHost::GetInputMethod() { |
188 if (!input_method_) { | 192 if (!input_method_) { |
189 input_method_ = | 193 input_method_ = |
190 ui::CreateInputMethod(this, GetAcceleratedWidget()).release(); | 194 ui::CreateInputMethod(this, GetAcceleratedWidget()).release(); |
191 owned_input_method_ = true; | 195 owned_input_method_ = true; |
192 } | 196 } |
193 return input_method_; | 197 return input_method_; |
194 } | 198 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 dispatcher_.reset(new WindowEventDispatcher(this)); | 265 dispatcher_.reset(new WindowEventDispatcher(this)); |
262 } | 266 } |
263 } | 267 } |
264 | 268 |
265 void WindowTreeHost::OnAcceleratedWidgetAvailable() { | 269 void WindowTreeHost::OnAcceleratedWidgetAvailable() { |
266 compositor_->SetAcceleratedWidget(GetAcceleratedWidget()); | 270 compositor_->SetAcceleratedWidget(GetAcceleratedWidget()); |
267 prop_.reset(new ui::ViewProp(GetAcceleratedWidget(), | 271 prop_.reset(new ui::ViewProp(GetAcceleratedWidget(), |
268 kWindowTreeHostForAcceleratedWidget, this)); | 272 kWindowTreeHostForAcceleratedWidget, this)); |
269 } | 273 } |
270 | 274 |
271 void WindowTreeHost::OnHostMoved(const gfx::Point& new_location) { | 275 void WindowTreeHost::OnHostMovedInPixels( |
272 TRACE_EVENT1("ui", "WindowTreeHost::OnHostMoved", | 276 const gfx::Point& new_location_in_pixels) { |
273 "origin", new_location.ToString()); | 277 TRACE_EVENT1("ui", "WindowTreeHost::OnHostMovedInPixels", "origin", |
| 278 new_location_in_pixels.ToString()); |
274 | 279 |
275 for (WindowTreeHostObserver& observer : observers_) | 280 for (WindowTreeHostObserver& observer : observers_) |
276 observer.OnHostMoved(this, new_location); | 281 observer.OnHostMovedInPixels(this, new_location_in_pixels); |
277 } | 282 } |
278 | 283 |
279 void WindowTreeHost::OnHostResized(const gfx::Size& new_size) { | 284 void WindowTreeHost::OnHostResizedInPixels( |
280 gfx::Size adjusted_size(new_size); | 285 const gfx::Size& new_size_in_pixels) { |
281 adjusted_size.Enlarge(output_surface_padding_.width(), | 286 gfx::Size adjusted_size(new_size_in_pixels); |
282 output_surface_padding_.height()); | 287 adjusted_size.Enlarge(output_surface_padding_in_pixels_.width(), |
| 288 output_surface_padding_in_pixels_.height()); |
283 // The compositor should have the same size as the native root window host. | 289 // The compositor should have the same size as the native root window host. |
284 // Get the latest scale from display because it might have been changed. | 290 // Get the latest scale from display because it might have been changed. |
285 compositor_->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(window()), | 291 compositor_->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(window()), |
286 adjusted_size); | 292 adjusted_size); |
287 | 293 |
288 gfx::Size layer_size = GetBoundsInPixels().size(); | 294 gfx::Size layer_size = GetBoundsInPixels().size(); |
289 // The layer, and the observers should be notified of the | 295 // The layer, and the observers should be notified of the |
290 // transformed size of the root window. | 296 // transformed size of the root window. |
291 UpdateRootWindowSize(layer_size); | 297 UpdateRootWindowSizeInPixels(layer_size); |
292 for (WindowTreeHostObserver& observer : observers_) | 298 for (WindowTreeHostObserver& observer : observers_) |
293 observer.OnHostResized(this); | 299 observer.OnHostResized(this); |
294 } | 300 } |
295 | 301 |
296 void WindowTreeHost::OnHostWorkspaceChanged() { | 302 void WindowTreeHost::OnHostWorkspaceChanged() { |
297 for (WindowTreeHostObserver& observer : observers_) | 303 for (WindowTreeHostObserver& observer : observers_) |
298 observer.OnHostWorkspaceChanged(this); | 304 observer.OnHostWorkspaceChanged(this); |
299 } | 305 } |
300 | 306 |
301 void WindowTreeHost::OnHostCloseRequested() { | 307 void WindowTreeHost::OnHostCloseRequested() { |
(...skipping 20 matching lines...) Expand all Loading... |
322 ui::EventProcessor* WindowTreeHost::GetEventProcessor() { | 328 ui::EventProcessor* WindowTreeHost::GetEventProcessor() { |
323 return event_processor(); | 329 return event_processor(); |
324 } | 330 } |
325 | 331 |
326 //////////////////////////////////////////////////////////////////////////////// | 332 //////////////////////////////////////////////////////////////////////////////// |
327 // WindowTreeHost, private: | 333 // WindowTreeHost, private: |
328 | 334 |
329 void WindowTreeHost::MoveCursorToInternal(const gfx::Point& root_location, | 335 void WindowTreeHost::MoveCursorToInternal(const gfx::Point& root_location, |
330 const gfx::Point& host_location) { | 336 const gfx::Point& host_location) { |
331 last_cursor_request_position_in_host_ = host_location; | 337 last_cursor_request_position_in_host_ = host_location; |
332 MoveCursorToNative(host_location); | 338 MoveCursorToScreenLocationInPixels(host_location); |
333 client::CursorClient* cursor_client = client::GetCursorClient(window()); | 339 client::CursorClient* cursor_client = client::GetCursorClient(window()); |
334 if (cursor_client) { | 340 if (cursor_client) { |
335 const display::Display& display = | 341 const display::Display& display = |
336 display::Screen::GetScreen()->GetDisplayNearestWindow(window()); | 342 display::Screen::GetScreen()->GetDisplayNearestWindow(window()); |
337 cursor_client->SetDisplay(display); | 343 cursor_client->SetDisplay(display); |
338 } | 344 } |
339 dispatcher()->OnCursorMovedToRootLocation(root_location); | 345 dispatcher()->OnCursorMovedToRootLocation(root_location); |
340 } | 346 } |
341 | 347 |
342 } // namespace aura | 348 } // namespace aura |
OLD | NEW |