Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(326)

Side by Side Diff: ui/aura/window_tree_host.cc

Issue 2525113002: Rename WindowTreeHost functions to indicate pixels/dips. (Closed)
Patch Set: DIP + rebase Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 UpdateRootWindowSizeInPixels(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
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 UpdateRootWindowSizeInPixels(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::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(GetBounds().size()); 116 OnHostResizedInPixels(GetBounds().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::ConvertPointFromDIPToNativeScreen(
130 ConvertPointToHost(point); 132 gfx::Point* point) const {
131 gfx::Point location = GetLocationOnNativeScreen(); 133 ConvertPointFromDIPToHost(point);
134 gfx::Point location = GetLocationOnNativeScreenInPixels();
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 = GetLocationOnNativeScreenInPixels();
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::MoveCursorToHostLocationInPixels(
182 gfx::Point root_location(host_location); 187 const gfx::Point& host_location_in_pixels) {
183 ConvertPointFromHost(&root_location); 188 gfx::Point root_location(host_location_in_pixels);
184 MoveCursorToInternal(root_location, host_location); 189 ConvertPointFromHostToDIP(&root_location);
190 MoveCursorToInternal(root_location, host_location_in_pixels);
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
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::OnHostMovedInPixels(
272 TRACE_EVENT1("ui", "WindowTreeHost::OnHostMoved", 278 const gfx::Point& new_location_in_pixels) {
273 "origin", new_location.ToString()); 279 TRACE_EVENT1("ui", "WindowTreeHost::OnHostMovedInPixels", "origin",
280 new_location_in_pixels.ToString());
274 281
275 for (WindowTreeHostObserver& observer : observers_) 282 for (WindowTreeHostObserver& observer : observers_)
276 observer.OnHostMoved(this, new_location); 283 observer.OnHostMovedInPixels(this, new_location_in_pixels);
277 } 284 }
278 285
279 void WindowTreeHost::OnHostResized(const gfx::Size& new_size) { 286 void WindowTreeHost::OnHostResizedInPixels(
280 gfx::Size adjusted_size(new_size); 287 const gfx::Size& new_size_in_pixels) {
281 adjusted_size.Enlarge(output_surface_padding_.width(), 288 gfx::Size adjusted_size(new_size_in_pixels);
282 output_surface_padding_.height()); 289 adjusted_size.Enlarge(output_surface_padding_in_pixels_.width(),
290 output_surface_padding_in_pixels_.height());
283 // The compositor should have the same size as the native root window host. 291 // 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. 292 // Get the latest scale from display because it might have been changed.
285 compositor_->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(window()), 293 compositor_->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(window()),
286 adjusted_size); 294 adjusted_size);
287 295
288 gfx::Size layer_size = GetBounds().size(); 296 gfx::Size layer_size = GetBounds().size();
289 // The layer, and the observers should be notified of the 297 // The layer, and the observers should be notified of the
290 // transformed size of the root window. 298 // transformed size of the root window.
291 UpdateRootWindowSize(layer_size); 299 UpdateRootWindowSizeInPixels(layer_size);
292 for (WindowTreeHostObserver& observer : observers_) 300 for (WindowTreeHostObserver& observer : observers_)
293 observer.OnHostResized(this); 301 observer.OnHostResized(this);
294 } 302 }
295 303
296 void WindowTreeHost::OnHostWorkspaceChanged() { 304 void WindowTreeHost::OnHostWorkspaceChanged() {
297 for (WindowTreeHostObserver& observer : observers_) 305 for (WindowTreeHostObserver& observer : observers_)
298 observer.OnHostWorkspaceChanged(this); 306 observer.OnHostWorkspaceChanged(this);
299 } 307 }
300 308
301 void WindowTreeHost::OnHostCloseRequested() { 309 void WindowTreeHost::OnHostCloseRequested() {
(...skipping 20 matching lines...) Expand all
322 ui::EventProcessor* WindowTreeHost::GetEventProcessor() { 330 ui::EventProcessor* WindowTreeHost::GetEventProcessor() {
323 return event_processor(); 331 return event_processor();
324 } 332 }
325 333
326 //////////////////////////////////////////////////////////////////////////////// 334 ////////////////////////////////////////////////////////////////////////////////
327 // WindowTreeHost, private: 335 // WindowTreeHost, private:
328 336
329 void WindowTreeHost::MoveCursorToInternal(const gfx::Point& root_location, 337 void WindowTreeHost::MoveCursorToInternal(const gfx::Point& root_location,
330 const gfx::Point& host_location) { 338 const gfx::Point& host_location) {
331 last_cursor_request_position_in_host_ = host_location; 339 last_cursor_request_position_in_host_ = host_location;
332 MoveCursorToNative(host_location); 340 MoveCursorToNativeInPixels(host_location);
333 client::CursorClient* cursor_client = client::GetCursorClient(window()); 341 client::CursorClient* cursor_client = client::GetCursorClient(window());
334 if (cursor_client) { 342 if (cursor_client) {
335 const display::Display& display = 343 const display::Display& display =
336 display::Screen::GetScreen()->GetDisplayNearestWindow(window()); 344 display::Screen::GetScreen()->GetDisplayNearestWindow(window());
337 cursor_client->SetDisplay(display); 345 cursor_client->SetDisplay(display);
338 } 346 }
339 dispatcher()->OnCursorMovedToRootLocation(root_location); 347 dispatcher()->OnCursorMovedToRootLocation(root_location);
340 } 348 }
341 349
342 } // namespace aura 350 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698