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

Side by Side Diff: services/ui/public/cpp/window_tree_client.cc

Issue 2447303002: Scale client area, hit test mask and bounds by device_scale_factor. (Closed)
Patch Set: conditionals Created 4 years, 1 month 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
« no previous file with comments | « no previous file | ui/aura/mus/window_tree_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "services/ui/public/cpp/window_tree_client.h" 5 #include "services/ui/public/cpp/window_tree_client.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "services/service_manager/public/cpp/connector.h" 15 #include "services/service_manager/public/cpp/connector.h"
16 #include "services/ui/common/util.h" 16 #include "services/ui/common/util.h"
17 #include "services/ui/public/cpp/in_flight_change.h" 17 #include "services/ui/public/cpp/in_flight_change.h"
18 #include "services/ui/public/cpp/input_event_handler.h" 18 #include "services/ui/public/cpp/input_event_handler.h"
19 #include "services/ui/public/cpp/surface_id_handler.h" 19 #include "services/ui/public/cpp/surface_id_handler.h"
20 #include "services/ui/public/cpp/window_drop_target.h" 20 #include "services/ui/public/cpp/window_drop_target.h"
21 #include "services/ui/public/cpp/window_manager_delegate.h" 21 #include "services/ui/public/cpp/window_manager_delegate.h"
22 #include "services/ui/public/cpp/window_observer.h" 22 #include "services/ui/public/cpp/window_observer.h"
23 #include "services/ui/public/cpp/window_private.h" 23 #include "services/ui/public/cpp/window_private.h"
24 #include "services/ui/public/cpp/window_tracker.h" 24 #include "services/ui/public/cpp/window_tracker.h"
25 #include "services/ui/public/cpp/window_tree_client_delegate.h" 25 #include "services/ui/public/cpp/window_tree_client_delegate.h"
26 #include "services/ui/public/cpp/window_tree_client_observer.h" 26 #include "services/ui/public/cpp/window_tree_client_observer.h"
27 #include "services/ui/public/interfaces/window_manager_window_tree_factory.mojom .h" 27 #include "services/ui/public/interfaces/window_manager_window_tree_factory.mojom .h"
28 #include "ui/display/screen.h"
28 #include "ui/events/event.h" 29 #include "ui/events/event.h"
30 #include "ui/gfx/geometry/dip_util.h"
29 #include "ui/gfx/geometry/insets.h" 31 #include "ui/gfx/geometry/insets.h"
30 #include "ui/gfx/geometry/size.h" 32 #include "ui/gfx/geometry/size.h"
31 33
32 namespace ui { 34 namespace ui {
33 35
34 Id MakeTransportId(ClientSpecificId client_id, ClientSpecificId local_id) { 36 Id MakeTransportId(ClientSpecificId client_id, ClientSpecificId local_id) {
35 return (client_id << 16) | local_id; 37 return (client_id << 16) | local_id;
36 } 38 }
37 39
40 // Helper function to get the device_scale_factor() of the display::Display
41 // with |display_id|.
42 float ScaleFactorForDisplay(int64_t display_id) {
43 // TODO(riajiang): Change to use display::GetDisplayWithDisplayId() after
44 // https://codereview.chromium.org/2361283002/ is landed.
45 std::vector<display::Display> displays =
46 display::Screen::GetScreen()->GetAllDisplays();
47 auto iter = std::find_if(displays.begin(), displays.end(),
48 [display_id](const display::Display& display) {
49 return display.id() == display_id;
50 });
51 if (iter != displays.end())
52 return iter->device_scale_factor();
53 return 1.f;
54 }
55
38 // Helper called to construct a local window object from transport data. 56 // Helper called to construct a local window object from transport data.
39 Window* AddWindowToClient(WindowTreeClient* client, 57 Window* AddWindowToClient(WindowTreeClient* client,
40 Window* parent, 58 Window* parent,
41 const mojom::WindowDataPtr& window_data) { 59 const mojom::WindowDataPtr& window_data) {
42 // We don't use the ctor that takes a WindowTreeClient here, since it will 60 // We don't use the ctor that takes a WindowTreeClient here, since it will
43 // call back to the service and attempt to create a new window. 61 // call back to the service and attempt to create a new window.
44 Window* window = WindowPrivate::LocalCreate(); 62 Window* window = WindowPrivate::LocalCreate();
45 WindowPrivate private_window(window); 63 WindowPrivate private_window(window);
46 private_window.set_client(client); 64 private_window.set_client(client);
47 private_window.set_server_id(window_data->window_id); 65 private_window.set_server_id(window_data->window_id);
48 private_window.set_visible(window_data->visible); 66 private_window.set_visible(window_data->visible);
49 private_window.set_properties( 67 private_window.set_properties(
50 window_data->properties 68 window_data->properties
51 .To<std::map<std::string, std::vector<uint8_t>>>()); 69 .To<std::map<std::string, std::vector<uint8_t>>>());
52 client->AddWindow(window); 70 client->AddWindow(window);
53 private_window.LocalSetBounds(gfx::Rect(), window_data->bounds); 71 private_window.LocalSetBounds(
72 gfx::Rect(),
73 gfx::ConvertRectToDIP(ScaleFactorForDisplay(window->display_id()),
74 window_data->bounds));
54 if (parent) 75 if (parent)
55 WindowPrivate(parent).LocalAddChild(window); 76 WindowPrivate(parent).LocalAddChild(window);
56 return window; 77 return window;
57 } 78 }
58 79
59 struct WindowTreeClient::CurrentDragState { 80 struct WindowTreeClient::CurrentDragState {
60 // The current change id of the current drag an drop ipc. 81 // The current change id of the current drag an drop ipc.
61 uint32_t change_id; 82 uint32_t change_id;
62 83
63 // The effect to return when we send our finish signal. 84 // The effect to return when we send our finish signal.
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 return HiWord(server_id(window)) == client_id_ && 232 return HiWord(server_id(window)) == client_id_ &&
212 roots_.count(const_cast<Window*>(window)) == 0; 233 roots_.count(const_cast<Window*>(window)) == 0;
213 } 234 }
214 235
215 void WindowTreeClient::SetBounds(Window* window, 236 void WindowTreeClient::SetBounds(Window* window,
216 const gfx::Rect& old_bounds, 237 const gfx::Rect& old_bounds,
217 const gfx::Rect& bounds) { 238 const gfx::Rect& bounds) {
218 DCHECK(tree_); 239 DCHECK(tree_);
219 const uint32_t change_id = ScheduleInFlightChange( 240 const uint32_t change_id = ScheduleInFlightChange(
220 base::MakeUnique<InFlightBoundsChange>(window, old_bounds)); 241 base::MakeUnique<InFlightBoundsChange>(window, old_bounds));
221 tree_->SetWindowBounds(change_id, server_id(window), bounds); 242 tree_->SetWindowBounds(
243 change_id, server_id(window),
244 gfx::ConvertRectToPixel(ScaleFactorForDisplay(window->display_id()),
245 bounds));
222 } 246 }
223 247
224 void WindowTreeClient::SetCapture(Window* window) { 248 void WindowTreeClient::SetCapture(Window* window) {
225 // In order for us to get here we had to have exposed a window, which implies 249 // In order for us to get here we had to have exposed a window, which implies
226 // we got a client. 250 // we got a client.
227 DCHECK(tree_); 251 DCHECK(tree_);
228 if (capture_window_ == window) 252 if (capture_window_ == window)
229 return; 253 return;
230 const uint32_t change_id = ScheduleInFlightChange( 254 const uint32_t change_id = ScheduleInFlightChange(
231 base::MakeUnique<InFlightCaptureChange>(this, capture_window_)); 255 base::MakeUnique<InFlightCaptureChange>(this, capture_window_));
(...skipping 11 matching lines...) Expand all
243 base::MakeUnique<InFlightCaptureChange>(this, window)); 267 base::MakeUnique<InFlightCaptureChange>(this, window));
244 tree_->ReleaseCapture(change_id, server_id(window)); 268 tree_->ReleaseCapture(change_id, server_id(window));
245 LocalSetCapture(nullptr); 269 LocalSetCapture(nullptr);
246 } 270 }
247 271
248 void WindowTreeClient::SetClientArea( 272 void WindowTreeClient::SetClientArea(
249 Id window_id, 273 Id window_id,
250 const gfx::Insets& client_area, 274 const gfx::Insets& client_area,
251 const std::vector<gfx::Rect>& additional_client_areas) { 275 const std::vector<gfx::Rect>& additional_client_areas) {
252 DCHECK(tree_); 276 DCHECK(tree_);
253 tree_->SetClientArea(window_id, client_area, additional_client_areas); 277 float device_scale_factor =
278 ScaleFactorForDisplay(GetWindowByServerId(window_id)->display_id());
279 std::vector<gfx::Rect> additional_client_areas_in_pixel;
280 for (const gfx::Rect& area : additional_client_areas) {
281 additional_client_areas_in_pixel.push_back(
282 gfx::ConvertRectToPixel(device_scale_factor, area));
283 }
284 tree_->SetClientArea(
285 window_id, gfx::ConvertInsetsToPixel(device_scale_factor, client_area),
286 additional_client_areas_in_pixel);
254 } 287 }
255 288
256 void WindowTreeClient::SetHitTestMask(Id window_id, const gfx::Rect& mask) { 289 void WindowTreeClient::SetHitTestMask(Id window_id, const gfx::Rect& mask) {
257 DCHECK(tree_); 290 DCHECK(tree_);
258 tree_->SetHitTestMask(window_id, mask); 291 tree_->SetHitTestMask(
292 window_id,
293 gfx::ConvertRectToPixel(
294 ScaleFactorForDisplay(GetWindowByServerId(window_id)->display_id()),
295 mask));
259 } 296 }
260 297
261 void WindowTreeClient::ClearHitTestMask(Id window_id) { 298 void WindowTreeClient::ClearHitTestMask(Id window_id) {
262 DCHECK(tree_); 299 DCHECK(tree_);
263 tree_->SetHitTestMask(window_id, base::nullopt); 300 tree_->SetHitTestMask(window_id, base::nullopt);
264 } 301 }
265 302
266 void WindowTreeClient::SetFocus(Window* window) { 303 void WindowTreeClient::SetFocus(Window* window) {
267 // In order for us to get here we had to have exposed a window, which implies 304 // In order for us to get here we had to have exposed a window, which implies
268 // we got a client. 305 // we got a client.
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 DCHECK_EQ(0u, data->parent_id); 902 DCHECK_EQ(0u, data->parent_id);
866 } 903 }
867 904
868 void WindowTreeClient::OnWindowBoundsChanged(Id window_id, 905 void WindowTreeClient::OnWindowBoundsChanged(Id window_id,
869 const gfx::Rect& old_bounds, 906 const gfx::Rect& old_bounds,
870 const gfx::Rect& new_bounds) { 907 const gfx::Rect& new_bounds) {
871 Window* window = GetWindowByServerId(window_id); 908 Window* window = GetWindowByServerId(window_id);
872 if (!window) 909 if (!window)
873 return; 910 return;
874 911
875 InFlightBoundsChange new_change(window, new_bounds); 912 float device_scale_factor = ScaleFactorForDisplay(window->display_id());
913 gfx::Rect old_bounds_in_dip =
914 gfx::ConvertRectToDIP(device_scale_factor, old_bounds);
915 gfx::Rect new_bounds_in_dip =
916 gfx::ConvertRectToDIP(device_scale_factor, new_bounds);
917
918 InFlightBoundsChange new_change(window, new_bounds_in_dip);
876 if (ApplyServerChangeToExistingInFlightChange(new_change)) 919 if (ApplyServerChangeToExistingInFlightChange(new_change))
877 return; 920 return;
878 921 WindowPrivate(window).LocalSetBounds(old_bounds_in_dip, new_bounds_in_dip);
sky 2016/11/11 21:16:53 Good thing we're getting rid of this. I worry roun
879 WindowPrivate(window).LocalSetBounds(old_bounds, new_bounds);
880 } 922 }
881 923
882 void WindowTreeClient::OnClientAreaChanged( 924 void WindowTreeClient::OnClientAreaChanged(
883 uint32_t window_id, 925 uint32_t window_id,
884 const gfx::Insets& new_client_area, 926 const gfx::Insets& new_client_area,
885 mojo::Array<gfx::Rect> new_additional_client_areas) { 927 mojo::Array<gfx::Rect> new_additional_client_areas) {
886 Window* window = GetWindowByServerId(window_id); 928 Window* window = GetWindowByServerId(window_id);
887 if (window) { 929 if (window) {
930 float device_scale_factor = ScaleFactorForDisplay(window->display_id());
931 std::vector<gfx::Rect> new_additional_client_areas_in_dip;
932 for (const gfx::Rect& area : new_additional_client_areas) {
933 new_additional_client_areas_in_dip.push_back(
934 gfx::ConvertRectToDIP(device_scale_factor, area));
935 }
888 WindowPrivate(window).LocalSetClientArea( 936 WindowPrivate(window).LocalSetClientArea(
889 new_client_area, 937 gfx::ConvertInsetsToDIP(device_scale_factor, new_client_area),
890 new_additional_client_areas.To<std::vector<gfx::Rect>>()); 938 new_additional_client_areas_in_dip);
891 } 939 }
892 } 940 }
893 941
894 void WindowTreeClient::OnTransientWindowAdded( 942 void WindowTreeClient::OnTransientWindowAdded(
895 uint32_t window_id, 943 uint32_t window_id,
896 uint32_t transient_window_id) { 944 uint32_t transient_window_id) {
897 Window* window = GetWindowByServerId(window_id); 945 Window* window = GetWindowByServerId(window_id);
898 Window* transient_window = GetWindowByServerId(transient_window_id); 946 Window* transient_window = GetWindowByServerId(transient_window_id);
899 // window or transient_window or both may be null if a local delete occurs 947 // window or transient_window or both may be null if a local delete occurs
900 // with an in flight add from the server. 948 // with an in flight add from the server.
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 window_manager_delegate_->OnWmDisplayModified(display); 1309 window_manager_delegate_->OnWmDisplayModified(display);
1262 } 1310 }
1263 1311
1264 void WindowTreeClient::WmSetBounds(uint32_t change_id, 1312 void WindowTreeClient::WmSetBounds(uint32_t change_id,
1265 Id window_id, 1313 Id window_id,
1266 const gfx::Rect& transit_bounds) { 1314 const gfx::Rect& transit_bounds) {
1267 Window* window = GetWindowByServerId(window_id); 1315 Window* window = GetWindowByServerId(window_id);
1268 bool result = false; 1316 bool result = false;
1269 if (window) { 1317 if (window) {
1270 DCHECK(window_manager_delegate_); 1318 DCHECK(window_manager_delegate_);
1271 gfx::Rect bounds = transit_bounds; 1319 gfx::Rect transit_bounds_in_dip = gfx::ConvertRectToDIP(
1320 ScaleFactorForDisplay(window->display_id()), transit_bounds);
1321 gfx::Rect bounds = transit_bounds_in_dip;
1272 result = window_manager_delegate_->OnWmSetBounds(window, &bounds); 1322 result = window_manager_delegate_->OnWmSetBounds(window, &bounds);
1273 if (result) { 1323 if (result) {
1274 // If the resulting bounds differ return false. Returning false ensures 1324 // If the resulting bounds differ return false. Returning false ensures
1275 // the client applies the bounds we set below. 1325 // the client applies the bounds we set below.
1276 result = bounds == transit_bounds; 1326 result = bounds == transit_bounds_in_dip;
1277 window->SetBounds(bounds); 1327 window->SetBounds(bounds);
1278 } 1328 }
1279 } 1329 }
1280 if (window_manager_internal_client_) 1330 if (window_manager_internal_client_)
1281 window_manager_internal_client_->WmResponse(change_id, result); 1331 window_manager_internal_client_->WmResponse(change_id, result);
1282 } 1332 }
1283 1333
1284 void WindowTreeClient::WmSetProperty(uint32_t change_id, 1334 void WindowTreeClient::WmSetProperty(uint32_t change_id,
1285 Id window_id, 1335 Id window_id,
1286 const mojo::String& name, 1336 const mojo::String& name,
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1414 void WindowTreeClient::ActivateNextWindow() { 1464 void WindowTreeClient::ActivateNextWindow() {
1415 if (window_manager_internal_client_) 1465 if (window_manager_internal_client_)
1416 window_manager_internal_client_->ActivateNextWindow(); 1466 window_manager_internal_client_->ActivateNextWindow();
1417 } 1467 }
1418 1468
1419 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea( 1469 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea(
1420 Window* window, 1470 Window* window,
1421 const gfx::Vector2d& offset, 1471 const gfx::Vector2d& offset,
1422 const gfx::Insets& hit_area) { 1472 const gfx::Insets& hit_area) {
1423 if (window_manager_internal_client_) { 1473 if (window_manager_internal_client_) {
1474 // TODO(riajiang): Figure out if |offset| needs to be converted.
sky 2016/11/11 21:16:53 I will be quite surprised if it doesn't need to be
1475 // (http://crbugs.com/646932)
1424 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( 1476 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea(
1425 server_id(window), offset.x(), offset.y(), hit_area); 1477 server_id(window), offset.x(), offset.y(),
1478 gfx::ConvertInsetsToDIP(ScaleFactorForDisplay(window->display_id()),
1479 hit_area));
1426 } 1480 }
1427 } 1481 }
1428 1482
1429 } // namespace ui 1483 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | ui/aura/mus/window_tree_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698