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

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: convert 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 ScaleFactorForDisplay(Window* window) {
124 // TODO(riajiang): Change to use display::GetDisplayWithDisplayId() after
125 // https://codereview.chromium.org/2361283002/ is landed.
126 return display::Screen::GetScreen()
127 ->GetDisplayNearestWindow(window)
128 .device_scale_factor();
129 }
130
120 } // namespace 131 } // namespace
121 132
122 WindowTreeClient::WindowTreeClient( 133 WindowTreeClient::WindowTreeClient(
123 WindowTreeClientDelegate* delegate, 134 WindowTreeClientDelegate* delegate,
124 WindowManagerDelegate* window_manager_delegate, 135 WindowManagerDelegate* window_manager_delegate,
125 mojo::InterfaceRequest<ui::mojom::WindowTreeClient> request) 136 mojo::InterfaceRequest<ui::mojom::WindowTreeClient> request)
126 : client_id_(0), 137 : client_id_(0),
127 next_window_id_(1), 138 next_window_id_(1),
128 next_change_id_(1), 139 next_change_id_(1),
129 delegate_(delegate), 140 delegate_(delegate),
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 factory->CreateWindowTree(GetProxy(&window_tree), 208 factory->CreateWindowTree(GetProxy(&window_tree),
198 binding_.CreateInterfacePtrAndBind()); 209 binding_.CreateInterfacePtrAndBind());
199 SetWindowTree(std::move(window_tree)); 210 SetWindowTree(std::move(window_tree));
200 } 211 }
201 212
202 void WindowTreeClient::SetClientArea( 213 void WindowTreeClient::SetClientArea(
203 Window* window, 214 Window* window,
204 const gfx::Insets& client_area, 215 const gfx::Insets& client_area,
205 const std::vector<gfx::Rect>& additional_client_areas) { 216 const std::vector<gfx::Rect>& additional_client_areas) {
206 DCHECK(tree_); 217 DCHECK(tree_);
207 tree_->SetClientArea(WindowMus::Get(window)->server_id(), client_area, 218 float device_scale_factor = ScaleFactorForDisplay(window);
208 additional_client_areas); 219 if (device_scale_factor == 1.f) {
sky 2016/11/10 23:55:15 Again, this isn't performance sensitive code, so I
riajiang 2016/11/11 19:41:21 Okay makes sense, done.
220 tree_->SetClientArea(WindowMus::Get(window)->server_id(), client_area,
221 additional_client_areas);
222 } else {
223 std::vector<gfx::Rect> additional_client_areas_in_pixel;
224 for (const gfx::Rect& area : additional_client_areas) {
225 additional_client_areas_in_pixel.push_back(
226 gfx::ConvertRectToPixel(device_scale_factor, area));
227 }
228 tree_->SetClientArea(
229 WindowMus::Get(window)->server_id(),
230 gfx::ConvertInsetsToPixel(device_scale_factor, client_area),
231 additional_client_areas_in_pixel);
232 }
209 } 233 }
210 234
211 void WindowTreeClient::SetHitTestMask(Window* window, const gfx::Rect& mask) { 235 void WindowTreeClient::SetHitTestMask(Window* window, const gfx::Rect& mask) {
212 DCHECK(tree_); 236 DCHECK(tree_);
213 tree_->SetHitTestMask(WindowMus::Get(window)->server_id(), mask); 237 float device_scale_factor = ScaleFactorForDisplay(window);
238 if (device_scale_factor == 1.f) {
239 tree_->SetHitTestMask(WindowMus::Get(window)->server_id(), mask);
240 } else {
241 tree_->SetHitTestMask(WindowMus::Get(window)->server_id(),
242 gfx::ConvertRectToPixel(device_scale_factor, mask));
243 }
214 } 244 }
215 245
216 void WindowTreeClient::ClearHitTestMask(Window* window) { 246 void WindowTreeClient::ClearHitTestMask(Window* window) {
217 DCHECK(tree_); 247 DCHECK(tree_);
218 tree_->SetHitTestMask(WindowMus::Get(window)->server_id(), base::nullopt); 248 tree_->SetHitTestMask(WindowMus::Get(window)->server_id(), base::nullopt);
219 } 249 }
220 250
221 void WindowTreeClient::SetCanFocus(Window* window, bool can_focus) { 251 void WindowTreeClient::SetCanFocus(Window* window, bool can_focus) {
222 DCHECK(tree_); 252 DCHECK(tree_);
223 DCHECK(window); 253 DCHECK(window);
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 return; 964 return;
935 965
936 SetWindowBoundsFromServer(window, new_bounds); 966 SetWindowBoundsFromServer(window, new_bounds);
937 } 967 }
938 968
939 void WindowTreeClient::OnClientAreaChanged( 969 void WindowTreeClient::OnClientAreaChanged(
940 uint32_t window_id, 970 uint32_t window_id,
941 const gfx::Insets& new_client_area, 971 const gfx::Insets& new_client_area,
942 mojo::Array<gfx::Rect> new_additional_client_areas) { 972 mojo::Array<gfx::Rect> new_additional_client_areas) {
943 // TODO: client area. 973 // TODO: client area.
974 // TODO(riajiang): Convert from pixel to DIP. (http://crbug.com/600815)
944 /* 975 /*
945 Window* window = GetWindowByServerId(window_id); 976 Window* window = GetWindowByServerId(window_id);
946 if (window) { 977 if (window) {
947 WindowPrivate(window).LocalSetClientArea( 978 WindowPrivate(window).LocalSetClientArea(
948 new_client_area, 979 new_client_area,
949 new_additional_client_areas.To<std::vector<gfx::Rect>>()); 980 new_additional_client_areas.To<std::vector<gfx::Rect>>());
950 } 981 }
951 */ 982 */
952 } 983 }
953 984
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
1290 } 1321 }
1291 */ 1322 */
1292 } 1323 }
1293 1324
1294 void WindowTreeClient::WmDisplayModified(const display::Display& display) { 1325 void WindowTreeClient::WmDisplayModified(const display::Display& display) {
1295 DCHECK(window_manager_delegate_); 1326 DCHECK(window_manager_delegate_);
1296 // TODO(sky): this should likely route to WindowTreeHost. 1327 // TODO(sky): this should likely route to WindowTreeHost.
1297 window_manager_delegate_->OnWmDisplayModified(display); 1328 window_manager_delegate_->OnWmDisplayModified(display);
1298 } 1329 }
1299 1330
1331 // TODO(riajiang): Convert between pixel and DIP for window bounds properly.
1332 // (http://crbug.com/646942)
1300 void WindowTreeClient::WmSetBounds(uint32_t change_id, 1333 void WindowTreeClient::WmSetBounds(uint32_t change_id,
1301 Id window_id, 1334 Id window_id,
1302 const gfx::Rect& transit_bounds) { 1335 const gfx::Rect& transit_bounds) {
1303 WindowMus* window = GetWindowByServerId(window_id); 1336 WindowMus* window = GetWindowByServerId(window_id);
1304 bool result = false; 1337 bool result = false;
1305 if (window) { 1338 if (window) {
1306 DCHECK(window_manager_delegate_); 1339 DCHECK(window_manager_delegate_);
1307 gfx::Rect bounds = transit_bounds; 1340 gfx::Rect bounds = transit_bounds;
1308 // TODO: this needs to trigger scheduling a bounds change on |window|. 1341 // TODO: this needs to trigger scheduling a bounds change on |window|.
1309 result = 1342 result =
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 void WindowTreeClient::ActivateNextWindow() { 1489 void WindowTreeClient::ActivateNextWindow() {
1457 if (window_manager_internal_client_) 1490 if (window_manager_internal_client_)
1458 window_manager_internal_client_->ActivateNextWindow(); 1491 window_manager_internal_client_->ActivateNextWindow();
1459 } 1492 }
1460 1493
1461 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea( 1494 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea(
1462 Window* window, 1495 Window* window,
1463 const gfx::Vector2d& offset, 1496 const gfx::Vector2d& offset,
1464 const gfx::Insets& hit_area) { 1497 const gfx::Insets& hit_area) {
1465 if (window_manager_internal_client_) { 1498 if (window_manager_internal_client_) {
1466 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( 1499 float device_scale_factor = ScaleFactorForDisplay(window);
1467 WindowMus::Get(window)->server_id(), offset.x(), offset.y(), hit_area); 1500 if (device_scale_factor == 1.f) {
1501 window_manager_internal_client_
1502 ->SetUnderlaySurfaceOffsetAndExtendedHitArea(
1503 WindowMus::Get(window)->server_id(), offset.x(), offset.y(),
1504 hit_area);
1505 } else {
1506 window_manager_internal_client_
1507 ->SetUnderlaySurfaceOffsetAndExtendedHitArea(
1508 WindowMus::Get(window)->server_id(), offset.x(), offset.y(),
sky 2016/11/10 23:55:15 Don't offset.x/y need to be convered?
riajiang 2016/11/11 19:41:21 When I was converting offset, browser tabs were no
1509 gfx::ConvertInsetsToDIP(device_scale_factor, hit_area));
1510 }
1468 } 1511 }
1469 } 1512 }
1470 1513
1471 void WindowTreeClient::OnWindowTreeHostBoundsWillChange( 1514 void WindowTreeClient::OnWindowTreeHostBoundsWillChange(
1472 WindowTreeHostMus* window_tree_host, 1515 WindowTreeHostMus* window_tree_host,
1473 const gfx::Rect& bounds) { 1516 const gfx::Rect& bounds) {
1474 ScheduleInFlightBoundsChange(WindowMus::Get(window_tree_host->window()), 1517 ScheduleInFlightBoundsChange(WindowMus::Get(window_tree_host->window()),
1475 window_tree_host->GetBounds(), bounds); 1518 window_tree_host->GetBounds(), bounds);
1476 } 1519 }
1477 1520
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1530 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( 1573 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>(
1531 this, capture_synchronizer_.get(), window)); 1574 this, capture_synchronizer_.get(), window));
1532 } 1575 }
1533 1576
1534 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { 1577 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) {
1535 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( 1578 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>(
1536 this, focus_synchronizer_.get(), window)); 1579 this, focus_synchronizer_.get(), window));
1537 } 1580 }
1538 1581
1539 } // namespace aura 1582 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698