| 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(GetBounds().size()); | 64 UpdateRootWindowSizeInPixel(GetBounds().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 GetBounds().size()); | 71 GetBounds().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(GetBounds().size()); | 99 UpdateRootWindowSizeInPixel(GetBounds().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::SetOutputSurfacePaddingInPixel( |
| 111 if (output_surface_padding_ == padding) | 111 const gfx::Insets& padding_in_pixel) { |
| 112 if (output_surface_padding_in_pixel_ == padding_in_pixel) |
| 112 return; | 113 return; |
| 113 | 114 |
| 114 output_surface_padding_ = padding; | 115 output_surface_padding_in_pixel_ = padding_in_pixel; |
| 115 OnHostResized(GetBounds().size()); | 116 OnHostResizedInPixel(GetBounds().size()); |
| 116 } | 117 } |
| 117 | 118 |
| 118 void WindowTreeHost::UpdateRootWindowSize(const gfx::Size& host_size) { | 119 void WindowTreeHost::UpdateRootWindowSizeInPixel( |
| 119 gfx::Rect bounds(output_surface_padding_.left(), | 120 const gfx::Size& host_size_in_pixel) { |
| 120 output_surface_padding_.top(), host_size.width(), | 121 gfx::Rect bounds(output_surface_padding_in_pixel_.left(), |
| 121 host_size.height()); | 122 output_surface_padding_in_pixel_.top(), |
| 123 host_size_in_pixel.width(), host_size_in_pixel.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::ConvertPointFromDIPToNativeScreen( |
| 130 ConvertPointToHost(point); | 132 gfx::Point* point) const { |
| 131 gfx::Point location = GetLocationOnNativeScreen(); | 133 ConvertPointFromDIPToHost(point); |
| 134 gfx::Point location = GetLocationOnNativeScreenInPixel(); |
| 132 point->Offset(location.x(), location.y()); | 135 point->Offset(location.x(), location.y()); |
| 133 } | 136 } |
| 134 | 137 |
| 135 void WindowTreeHost::ConvertPointFromNativeScreen(gfx::Point* point) const { | 138 void WindowTreeHost::ConvertPointFromNativeScreenToDIP( |
| 136 gfx::Point location = GetLocationOnNativeScreen(); | 139 gfx::Point* point) const { |
| 140 gfx::Point location = GetLocationOnNativeScreenInPixel(); |
| 137 point->Offset(-location.x(), -location.y()); | 141 point->Offset(-location.x(), -location.y()); |
| 138 ConvertPointFromHost(point); | 142 ConvertPointFromHostToDIP(point); |
| 139 } | 143 } |
| 140 | 144 |
| 141 void WindowTreeHost::ConvertPointToHost(gfx::Point* point) const { | 145 void WindowTreeHost::ConvertPointFromDIPToHost(gfx::Point* point) const { |
| 142 auto point_3f = gfx::Point3F(gfx::PointF(*point)); | 146 auto point_3f = gfx::Point3F(gfx::PointF(*point)); |
| 143 GetRootTransform().TransformPoint(&point_3f); | 147 GetRootTransform().TransformPoint(&point_3f); |
| 144 *point = gfx::ToFlooredPoint(point_3f.AsPointF()); | 148 *point = gfx::ToFlooredPoint(point_3f.AsPointF()); |
| 145 } | 149 } |
| 146 | 150 |
| 147 void WindowTreeHost::ConvertPointFromHost(gfx::Point* point) const { | 151 void WindowTreeHost::ConvertPointFromHostToDIP(gfx::Point* point) const { |
| 148 auto point_3f = gfx::Point3F(gfx::PointF(*point)); | 152 auto point_3f = gfx::Point3F(gfx::PointF(*point)); |
| 149 GetInverseRootTransform().TransformPoint(&point_3f); | 153 GetInverseRootTransform().TransformPoint(&point_3f); |
| 150 *point = gfx::ToFlooredPoint(point_3f.AsPointF()); | 154 *point = gfx::ToFlooredPoint(point_3f.AsPointF()); |
| 151 } | 155 } |
| 152 | 156 |
| 153 void WindowTreeHost::SetCursor(gfx::NativeCursor cursor) { | 157 void WindowTreeHost::SetCursor(gfx::NativeCursor cursor) { |
| 154 last_cursor_ = cursor; | 158 last_cursor_ = cursor; |
| 155 // A lot of code seems to depend on NULL cursors actually showing an arrow, | 159 // A lot of code seems to depend on NULL cursors actually showing an arrow, |
| 156 // so just pass everything along to the host. | 160 // so just pass everything along to the host. |
| 157 SetCursorNative(cursor); | 161 SetCursorNative(cursor); |
| 158 } | 162 } |
| 159 | 163 |
| 160 void WindowTreeHost::OnCursorVisibilityChanged(bool show) { | 164 void WindowTreeHost::OnCursorVisibilityChanged(bool show) { |
| 161 // Clear any existing mouse hover effects when the cursor becomes invisible. | 165 // 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 | 166 // 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 | 167 // visible because that can only happen in response to a mouse event, which |
| 164 // will trigger its own mouse enter. | 168 // will trigger its own mouse enter. |
| 165 if (!show) { | 169 if (!show) { |
| 166 ui::EventDispatchDetails details = dispatcher()->DispatchMouseExitAtPoint( | 170 ui::EventDispatchDetails details = dispatcher()->DispatchMouseExitAtPoint( |
| 167 nullptr, dispatcher()->GetLastMouseLocationInRoot()); | 171 nullptr, dispatcher()->GetLastMouseLocationInRoot()); |
| 168 if (details.dispatcher_destroyed) | 172 if (details.dispatcher_destroyed) |
| 169 return; | 173 return; |
| 170 } | 174 } |
| 171 | 175 |
| 172 OnCursorVisibilityChangedNative(show); | 176 OnCursorVisibilityChangedNative(show); |
| 173 } | 177 } |
| 174 | 178 |
| 175 void WindowTreeHost::MoveCursorTo(const gfx::Point& location_in_dip) { | 179 void WindowTreeHost::MoveCursorToLocationInDIP( |
| 180 const gfx::Point& location_in_dip) { |
| 176 gfx::Point host_location(location_in_dip); | 181 gfx::Point host_location(location_in_dip); |
| 177 ConvertPointToHost(&host_location); | 182 ConvertPointFromDIPToHost(&host_location); |
| 178 MoveCursorToInternal(location_in_dip, host_location); | 183 MoveCursorToInternal(location_in_dip, host_location); |
| 179 } | 184 } |
| 180 | 185 |
| 181 void WindowTreeHost::MoveCursorToHostLocation(const gfx::Point& host_location) { | 186 void WindowTreeHost::MoveCursorToHostLocationInPixel( |
| 182 gfx::Point root_location(host_location); | 187 const gfx::Point& host_location_in_pixel) { |
| 183 ConvertPointFromHost(&root_location); | 188 gfx::Point root_location(host_location_in_pixel); |
| 184 MoveCursorToInternal(root_location, host_location); | 189 ConvertPointFromHostToDIP(&root_location); |
| 190 MoveCursorToInternal(root_location, host_location_in_pixel); |
| 185 } | 191 } |
| 186 | 192 |
| 187 ui::InputMethod* WindowTreeHost::GetInputMethod() { | 193 ui::InputMethod* WindowTreeHost::GetInputMethod() { |
| 188 if (!input_method_) { | 194 if (!input_method_) { |
| 189 input_method_ = | 195 input_method_ = |
| 190 ui::CreateInputMethod(this, GetAcceleratedWidget()).release(); | 196 ui::CreateInputMethod(this, GetAcceleratedWidget()).release(); |
| 191 owned_input_method_ = true; | 197 owned_input_method_ = true; |
| 192 } | 198 } |
| 193 return input_method_; | 199 return input_method_; |
| 194 } | 200 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 dispatcher_.reset(new WindowEventDispatcher(this)); | 267 dispatcher_.reset(new WindowEventDispatcher(this)); |
| 262 } | 268 } |
| 263 } | 269 } |
| 264 | 270 |
| 265 void WindowTreeHost::OnAcceleratedWidgetAvailable() { | 271 void WindowTreeHost::OnAcceleratedWidgetAvailable() { |
| 266 compositor_->SetAcceleratedWidget(GetAcceleratedWidget()); | 272 compositor_->SetAcceleratedWidget(GetAcceleratedWidget()); |
| 267 prop_.reset(new ui::ViewProp(GetAcceleratedWidget(), | 273 prop_.reset(new ui::ViewProp(GetAcceleratedWidget(), |
| 268 kWindowTreeHostForAcceleratedWidget, this)); | 274 kWindowTreeHostForAcceleratedWidget, this)); |
| 269 } | 275 } |
| 270 | 276 |
| 271 void WindowTreeHost::OnHostMoved(const gfx::Point& new_location) { | 277 void WindowTreeHost::OnHostMovedInPixel( |
| 272 TRACE_EVENT1("ui", "WindowTreeHost::OnHostMoved", | 278 const gfx::Point& new_location_in_pixel) { |
| 273 "origin", new_location.ToString()); | 279 TRACE_EVENT1("ui", "WindowTreeHost::OnHostMovedInPixel", "origin", |
| 280 new_location_in_pixel.ToString()); |
| 274 | 281 |
| 275 for (WindowTreeHostObserver& observer : observers_) | 282 for (WindowTreeHostObserver& observer : observers_) |
| 276 observer.OnHostMoved(this, new_location); | 283 observer.OnHostMovedInPixel(this, new_location_in_pixel); |
| 277 } | 284 } |
| 278 | 285 |
| 279 void WindowTreeHost::OnHostResized(const gfx::Size& new_size) { | 286 void WindowTreeHost::OnHostResizedInPixel(const gfx::Size& new_size_in_pixel) { |
| 280 gfx::Size adjusted_size(new_size); | 287 gfx::Size adjusted_size(new_size_in_pixel); |
| 281 adjusted_size.Enlarge(output_surface_padding_.width(), | 288 adjusted_size.Enlarge(output_surface_padding_in_pixel_.width(), |
| 282 output_surface_padding_.height()); | 289 output_surface_padding_in_pixel_.height()); |
| 283 // The compositor should have the same size as the native root window host. | 290 // 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. | 291 // Get the latest scale from display because it might have been changed. |
| 285 compositor_->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(window()), | 292 compositor_->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(window()), |
| 286 adjusted_size); | 293 adjusted_size); |
| 287 | 294 |
| 288 gfx::Size layer_size = GetBounds().size(); | 295 gfx::Size layer_size = GetBounds().size(); |
| 289 // The layer, and the observers should be notified of the | 296 // The layer, and the observers should be notified of the |
| 290 // transformed size of the root window. | 297 // transformed size of the root window. |
| 291 UpdateRootWindowSize(layer_size); | 298 UpdateRootWindowSizeInPixel(layer_size); |
| 292 for (WindowTreeHostObserver& observer : observers_) | 299 for (WindowTreeHostObserver& observer : observers_) |
| 293 observer.OnHostResized(this); | 300 observer.OnHostResized(this); |
| 294 } | 301 } |
| 295 | 302 |
| 296 void WindowTreeHost::OnHostWorkspaceChanged() { | 303 void WindowTreeHost::OnHostWorkspaceChanged() { |
| 297 for (WindowTreeHostObserver& observer : observers_) | 304 for (WindowTreeHostObserver& observer : observers_) |
| 298 observer.OnHostWorkspaceChanged(this); | 305 observer.OnHostWorkspaceChanged(this); |
| 299 } | 306 } |
| 300 | 307 |
| 301 void WindowTreeHost::OnHostCloseRequested() { | 308 void WindowTreeHost::OnHostCloseRequested() { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 322 ui::EventProcessor* WindowTreeHost::GetEventProcessor() { | 329 ui::EventProcessor* WindowTreeHost::GetEventProcessor() { |
| 323 return event_processor(); | 330 return event_processor(); |
| 324 } | 331 } |
| 325 | 332 |
| 326 //////////////////////////////////////////////////////////////////////////////// | 333 //////////////////////////////////////////////////////////////////////////////// |
| 327 // WindowTreeHost, private: | 334 // WindowTreeHost, private: |
| 328 | 335 |
| 329 void WindowTreeHost::MoveCursorToInternal(const gfx::Point& root_location, | 336 void WindowTreeHost::MoveCursorToInternal(const gfx::Point& root_location, |
| 330 const gfx::Point& host_location) { | 337 const gfx::Point& host_location) { |
| 331 last_cursor_request_position_in_host_ = host_location; | 338 last_cursor_request_position_in_host_ = host_location; |
| 332 MoveCursorToNative(host_location); | 339 MoveCursorToNativeInPixel(host_location); |
| 333 client::CursorClient* cursor_client = client::GetCursorClient(window()); | 340 client::CursorClient* cursor_client = client::GetCursorClient(window()); |
| 334 if (cursor_client) { | 341 if (cursor_client) { |
| 335 const display::Display& display = | 342 const display::Display& display = |
| 336 display::Screen::GetScreen()->GetDisplayNearestWindow(window()); | 343 display::Screen::GetScreen()->GetDisplayNearestWindow(window()); |
| 337 cursor_client->SetDisplay(display); | 344 cursor_client->SetDisplay(display); |
| 338 } | 345 } |
| 339 dispatcher()->OnCursorMovedToRootLocation(root_location); | 346 dispatcher()->OnCursorMovedToRootLocation(root_location); |
| 340 } | 347 } |
| 341 | 348 |
| 342 } // namespace aura | 349 } // namespace aura |
| OLD | NEW |