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

Side by Side Diff: ui/aura/mus/window_tree_client.cc

Issue 2447303002: Scale client area, hit test mask and bounds by device_scale_factor. (Closed)
Patch Set: bounds 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
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 "ui/aura/mus/window_tree_client.h" 5 #include "ui/aura/mus/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>
(...skipping 20 matching lines...) Expand all
31 #include "ui/aura/mus/window_tree_client_delegate.h" 31 #include "ui/aura/mus/window_tree_client_delegate.h"
32 #include "ui/aura/mus/window_tree_client_observer.h" 32 #include "ui/aura/mus/window_tree_client_observer.h"
33 #include "ui/aura/mus/window_tree_host_mus.h" 33 #include "ui/aura/mus/window_tree_host_mus.h"
34 #include "ui/aura/window.h" 34 #include "ui/aura/window.h"
35 #include "ui/aura/window_delegate.h" 35 #include "ui/aura/window_delegate.h"
36 #include "ui/aura/window_tracker.h" 36 #include "ui/aura/window_tracker.h"
37 #include "ui/base/ui_base_types.h" 37 #include "ui/base/ui_base_types.h"
38 #include "ui/display/display.h" 38 #include "ui/display/display.h"
39 #include "ui/display/screen.h" 39 #include "ui/display/screen.h"
40 #include "ui/events/event.h" 40 #include "ui/events/event.h"
41 #include "ui/gfx/geometry/dip_util.h"
41 #include "ui/gfx/geometry/insets.h" 42 #include "ui/gfx/geometry/insets.h"
42 #include "ui/gfx/geometry/size.h" 43 #include "ui/gfx/geometry/size.h"
43 44
44 #if defined(HiWord) 45 #if defined(HiWord)
45 #undef HiWord 46 #undef HiWord
46 #endif 47 #endif
47 #if defined(LoWord) 48 #if defined(LoWord)
48 #undef LoWord 49 #undef LoWord
49 #endif 50 #endif
50 51
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 } 111 }
111 112
112 WindowTreeHostMus* GetWindowTreeHostMus(WindowMus* window) { 113 WindowTreeHostMus* GetWindowTreeHostMus(WindowMus* window) {
113 return GetWindowTreeHostMus(window->GetWindow()); 114 return GetWindowTreeHostMus(window->GetWindow());
114 } 115 }
115 116
116 bool IsInternalProperty(const void* key) { 117 bool IsInternalProperty(const void* key) {
117 return key == client::kModalKey; 118 return key == client::kModalKey;
118 } 119 }
119 120
121 // Helper function to get the device_scale_factor() of the display::Display
122 // with |display_id|.
123 float DeviceScaleFactorForDisplay(int64_t display_id) {
124 // TODO(riajiang): Change to use display::GetDisplayWithDisplayId() after
125 // https://codereview.chromium.org/2361283002/ is landed.
126 std::vector<display::Display> displays =
127 display::Screen::GetScreen()->GetAllDisplays();
128 auto iter = std::find_if(displays.begin(), displays.end(),
sky 2016/11/09 00:21:13 When this function is used you always have a windo
riajiang 2016/11/09 21:07:08 Changed to use GetDisplayNearestWindow. Kept the T
129 [display_id](const display::Display& display) {
130 return display.id() == display_id;
131 });
132 if (iter != displays.end())
133 return iter->device_scale_factor();
134 return 1.f;
135 }
136
120 } // namespace 137 } // namespace
121 138
122 WindowTreeClient::WindowTreeClient( 139 WindowTreeClient::WindowTreeClient(
123 WindowTreeClientDelegate* delegate, 140 WindowTreeClientDelegate* delegate,
124 WindowManagerDelegate* window_manager_delegate, 141 WindowManagerDelegate* window_manager_delegate,
125 mojo::InterfaceRequest<ui::mojom::WindowTreeClient> request) 142 mojo::InterfaceRequest<ui::mojom::WindowTreeClient> request)
126 : client_id_(0), 143 : client_id_(0),
127 next_window_id_(1), 144 next_window_id_(1),
128 next_change_id_(1), 145 next_change_id_(1),
129 delegate_(delegate), 146 delegate_(delegate),
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 factory->CreateWindowTree(GetProxy(&window_tree), 214 factory->CreateWindowTree(GetProxy(&window_tree),
198 binding_.CreateInterfacePtrAndBind()); 215 binding_.CreateInterfacePtrAndBind());
199 SetWindowTree(std::move(window_tree)); 216 SetWindowTree(std::move(window_tree));
200 } 217 }
201 218
202 void WindowTreeClient::SetClientArea( 219 void WindowTreeClient::SetClientArea(
203 Window* window, 220 Window* window,
204 const gfx::Insets& client_area, 221 const gfx::Insets& client_area,
205 const std::vector<gfx::Rect>& additional_client_areas) { 222 const std::vector<gfx::Rect>& additional_client_areas) {
206 DCHECK(tree_); 223 DCHECK(tree_);
207 tree_->SetClientArea(WindowMus::Get(window)->server_id(), client_area, 224 float device_scale_factor =
208 additional_client_areas); 225 DeviceScaleFactorForDisplay(GetWindowTreeHostMus(window)->display_id());
sky 2016/11/09 00:21:13 GetWindowTreeHostMus might return null.
riajiang 2016/11/09 21:07:08 Not using GetWindowTreeHostMus anymore since chang
226 if (device_scale_factor == 1.f) {
227 tree_->SetClientArea(WindowMus::Get(window)->server_id(), client_area,
228 additional_client_areas);
229 } else {
230 std::vector<gfx::Rect> additional_client_areas_in_pixel;
231 for (const gfx::Rect& area : additional_client_areas) {
232 additional_client_areas_in_pixel.push_back(
233 gfx::ConvertRectToPixel(device_scale_factor, area));
234 }
235 tree_->SetClientArea(
236 WindowMus::Get(window)->server_id(),
237 gfx::ConvertInsetsToPixel(device_scale_factor, client_area),
238 additional_client_areas_in_pixel);
239 }
209 } 240 }
210 241
211 void WindowTreeClient::SetHitTestMask(Window* window, const gfx::Rect& mask) { 242 void WindowTreeClient::SetHitTestMask(Window* window, const gfx::Rect& mask) {
212 DCHECK(tree_); 243 DCHECK(tree_);
213 tree_->SetHitTestMask(WindowMus::Get(window)->server_id(), mask); 244 float device_scale_factor =
245 DeviceScaleFactorForDisplay(GetWindowTreeHostMus(window)->display_id());
246 if (device_scale_factor == 1.f) {
247 tree_->SetHitTestMask(WindowMus::Get(window)->server_id(), mask);
248 } else {
249 tree_->SetHitTestMask(WindowMus::Get(window)->server_id(),
250 gfx::ConvertRectToPixel(device_scale_factor, mask));
251 }
214 } 252 }
215 253
216 void WindowTreeClient::ClearHitTestMask(Window* window) { 254 void WindowTreeClient::ClearHitTestMask(Window* window) {
217 DCHECK(tree_); 255 DCHECK(tree_);
218 tree_->SetHitTestMask(WindowMus::Get(window)->server_id(), base::nullopt); 256 tree_->SetHitTestMask(WindowMus::Get(window)->server_id(), base::nullopt);
219 } 257 }
220 258
221 void WindowTreeClient::SetCanFocus(Window* window, bool can_focus) { 259 void WindowTreeClient::SetCanFocus(Window* window, bool can_focus) {
222 DCHECK(tree_); 260 DCHECK(tree_);
223 DCHECK(window); 261 DCHECK(window);
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 return; 978 return;
941 979
942 SetWindowBoundsFromServer(window, new_bounds); 980 SetWindowBoundsFromServer(window, new_bounds);
943 } 981 }
944 982
945 void WindowTreeClient::OnClientAreaChanged( 983 void WindowTreeClient::OnClientAreaChanged(
946 uint32_t window_id, 984 uint32_t window_id,
947 const gfx::Insets& new_client_area, 985 const gfx::Insets& new_client_area,
948 mojo::Array<gfx::Rect> new_additional_client_areas) { 986 mojo::Array<gfx::Rect> new_additional_client_areas) {
949 // TODO: client area. 987 // TODO: client area.
988 // TODO(riajiang): Convert from pixel to DIP.
950 /* 989 /*
951 Window* window = GetWindowByServerId(window_id); 990 Window* window = GetWindowByServerId(window_id);
952 if (window) { 991 if (window) {
953 WindowPrivate(window).LocalSetClientArea( 992 WindowPrivate(window).LocalSetClientArea(
954 new_client_area, 993 new_client_area,
955 new_additional_client_areas.To<std::vector<gfx::Rect>>()); 994 new_additional_client_areas.To<std::vector<gfx::Rect>>());
956 } 995 }
957 */ 996 */
958 } 997 }
959 998
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
1298 } 1337 }
1299 */ 1338 */
1300 } 1339 }
1301 1340
1302 void WindowTreeClient::WmDisplayModified(const display::Display& display) { 1341 void WindowTreeClient::WmDisplayModified(const display::Display& display) {
1303 DCHECK(window_manager_delegate_); 1342 DCHECK(window_manager_delegate_);
1304 // TODO(sky): this should likely route to WindowTreeHost. 1343 // TODO(sky): this should likely route to WindowTreeHost.
1305 window_manager_delegate_->OnWmDisplayModified(display); 1344 window_manager_delegate_->OnWmDisplayModified(display);
1306 } 1345 }
1307 1346
1347 // TODO(riajiang): Convert between pixel and DIP for window bounds properly.
1308 void WindowTreeClient::WmSetBounds(uint32_t change_id, 1348 void WindowTreeClient::WmSetBounds(uint32_t change_id,
1309 Id window_id, 1349 Id window_id,
1310 const gfx::Rect& transit_bounds) { 1350 const gfx::Rect& transit_bounds) {
1311 WindowMus* window = GetWindowByServerId(window_id); 1351 WindowMus* window = GetWindowByServerId(window_id);
1312 bool result = false; 1352 bool result = false;
1313 if (window) { 1353 if (window) {
1314 DCHECK(window_manager_delegate_); 1354 DCHECK(window_manager_delegate_);
1315 gfx::Rect bounds = transit_bounds; 1355 gfx::Rect bounds = transit_bounds;
1316 // TODO: this needs to trigger scheduling a bounds change on |window|. 1356 // TODO: this needs to trigger scheduling a bounds change on |window|.
1317 result = 1357 result =
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1464 void WindowTreeClient::ActivateNextWindow() { 1504 void WindowTreeClient::ActivateNextWindow() {
1465 if (window_manager_internal_client_) 1505 if (window_manager_internal_client_)
1466 window_manager_internal_client_->ActivateNextWindow(); 1506 window_manager_internal_client_->ActivateNextWindow();
1467 } 1507 }
1468 1508
1469 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea( 1509 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea(
1470 Window* window, 1510 Window* window,
1471 const gfx::Vector2d& offset, 1511 const gfx::Vector2d& offset,
1472 const gfx::Insets& hit_area) { 1512 const gfx::Insets& hit_area) {
1473 if (window_manager_internal_client_) { 1513 if (window_manager_internal_client_) {
1474 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( 1514 float device_scale_factor =
1475 WindowMus::Get(window)->server_id(), offset.x(), offset.y(), hit_area); 1515 DeviceScaleFactorForDisplay(GetWindowTreeHostMus(window)->display_id());
1516 if (device_scale_factor == 1.f) {
1517 window_manager_internal_client_
1518 ->SetUnderlaySurfaceOffsetAndExtendedHitArea(
1519 WindowMus::Get(window)->server_id(), offset.x(), offset.y(),
1520 hit_area);
1521 } else {
1522 window_manager_internal_client_
1523 ->SetUnderlaySurfaceOffsetAndExtendedHitArea(
1524 WindowMus::Get(window)->server_id(), offset.x(), offset.y(),
1525 gfx::ConvertInsetsToDIP(device_scale_factor, hit_area));
1526 }
1476 } 1527 }
1477 } 1528 }
1478 1529
1479 void WindowTreeClient::OnWindowTreeHostBoundsWillChange( 1530 void WindowTreeClient::OnWindowTreeHostBoundsWillChange(
1480 WindowTreeHostMus* window_tree_host, 1531 WindowTreeHostMus* window_tree_host,
1481 const gfx::Rect& bounds) { 1532 const gfx::Rect& bounds) {
1482 ScheduleInFlightBoundsChange(WindowMus::Get(window_tree_host->window()), 1533 ScheduleInFlightBoundsChange(WindowMus::Get(window_tree_host->window()),
1483 window_tree_host->GetBounds(), bounds); 1534 window_tree_host->GetBounds(), bounds);
1484 } 1535 }
1485 1536
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1538 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( 1589 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>(
1539 this, capture_synchronizer_.get(), window)); 1590 this, capture_synchronizer_.get(), window));
1540 } 1591 }
1541 1592
1542 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { 1593 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) {
1543 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( 1594 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>(
1544 this, focus_synchronizer_.get(), window)); 1595 this, focus_synchronizer_.get(), window));
1545 } 1596 }
1546 1597
1547 } // namespace aura 1598 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698