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

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

Issue 2579883002: Scale bounds in aura-mus client-lib and NativeWidgetMus in hdpi mode. (Closed)
Patch Set: change a comment about pixels Created 3 years, 12 months 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 if (type_iter == properties.end()) 127 if (type_iter == properties.end())
128 return; 128 return;
129 129
130 // TODO: need to validate type! http://crbug.com/654924. 130 // TODO: need to validate type! http://crbug.com/654924.
131 ui::mojom::WindowType window_type = static_cast<ui::mojom::WindowType>( 131 ui::mojom::WindowType window_type = static_cast<ui::mojom::WindowType>(
132 mojo::ConvertTo<int32_t>(type_iter->second)); 132 mojo::ConvertTo<int32_t>(type_iter->second));
133 SetWindowType(window, window_type); 133 SetWindowType(window, window_type);
134 } 134 }
135 135
136 // Helper function to get the device_scale_factor() of the display::Display 136 // Helper function to get the device_scale_factor() of the display::Display
137 // with |display_id|. 137 // nearest to |window|.
138 float ScaleFactorForDisplay(Window* window) { 138 float ScaleFactorForDisplay(Window* window) {
139 // TODO(riajiang): Change to use display::GetDisplayWithDisplayId() after
140 // https://codereview.chromium.org/2361283002/ is landed.
141 return display::Screen::GetScreen() 139 return display::Screen::GetScreen()
142 ->GetDisplayNearestWindow(window) 140 ->GetDisplayNearestWindow(window)
143 .device_scale_factor(); 141 .device_scale_factor();
144 } 142 }
145 143
146 } // namespace 144 } // namespace
147 145
148 WindowTreeClient::WindowTreeClient( 146 WindowTreeClient::WindowTreeClient(
149 service_manager::Connector* connector, 147 service_manager::Connector* connector,
150 WindowTreeClientDelegate* delegate, 148 WindowTreeClientDelegate* delegate,
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 const ui::mojom::WindowData& window_data) { 417 const ui::mojom::WindowData& window_data) {
420 // This function is only called for windows coming from other clients. 418 // This function is only called for windows coming from other clients.
421 std::unique_ptr<WindowPortMus> window_port_mus( 419 std::unique_ptr<WindowPortMus> window_port_mus(
422 CreateWindowPortMus(window_data, WindowMusType::OTHER)); 420 CreateWindowPortMus(window_data, WindowMusType::OTHER));
423 WindowPortMus* window_port_mus_ptr = window_port_mus.get(); 421 WindowPortMus* window_port_mus_ptr = window_port_mus.get();
424 Window* window = new Window(nullptr, std::move(window_port_mus)); 422 Window* window = new Window(nullptr, std::move(window_port_mus));
425 WindowMus* window_mus = window_port_mus_ptr; 423 WindowMus* window_mus = window_port_mus_ptr;
426 SetWindowTypeFromProperties(window, window_data.properties); 424 SetWindowTypeFromProperties(window, window_data.properties);
427 window->Init(ui::LAYER_NOT_DRAWN); 425 window->Init(ui::LAYER_NOT_DRAWN);
428 SetLocalPropertiesFromServerProperties(window_mus, window_data); 426 SetLocalPropertiesFromServerProperties(window_mus, window_data);
429 window_mus->SetBoundsFromServer(window_data.bounds); 427 window_mus->SetBoundsFromServer(
428 gfx::ConvertRectToDIP(ScaleFactorForDisplay(window), window_data.bounds));
430 if (parent) 429 if (parent)
431 parent->AddChildFromServer(window_port_mus_ptr); 430 parent->AddChildFromServer(window_port_mus_ptr);
432 if (window_data.visible) 431 if (window_data.visible)
433 window_mus->SetVisibleFromServer(true); 432 window_mus->SetVisibleFromServer(true);
434 return window_port_mus_ptr; 433 return window_port_mus_ptr;
435 } 434 }
436 435
437 void WindowTreeClient::SetWindowTree(ui::mojom::WindowTreePtr window_tree_ptr) { 436 void WindowTreeClient::SetWindowTree(ui::mojom::WindowTreePtr window_tree_ptr) {
438 tree_ptr_ = std::move(window_tree_ptr); 437 tree_ptr_ = std::move(window_tree_ptr);
439 WindowTreeConnectionEstablished(tree_ptr_.get()); 438 WindowTreeConnectionEstablished(tree_ptr_.get());
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 } 529 }
531 530
532 void WindowTreeClient::OnReceivedCursorLocationMemory( 531 void WindowTreeClient::OnReceivedCursorLocationMemory(
533 mojo::ScopedSharedBufferHandle handle) { 532 mojo::ScopedSharedBufferHandle handle) {
534 cursor_location_mapping_ = handle->Map(sizeof(base::subtle::Atomic32)); 533 cursor_location_mapping_ = handle->Map(sizeof(base::subtle::Atomic32));
535 DCHECK(cursor_location_mapping_); 534 DCHECK(cursor_location_mapping_);
536 } 535 }
537 536
538 void WindowTreeClient::SetWindowBoundsFromServer( 537 void WindowTreeClient::SetWindowBoundsFromServer(
539 WindowMus* window, 538 WindowMus* window,
540 const gfx::Rect& revert_bounds) { 539 const gfx::Rect& revert_bounds) {
sadrul 2016/12/21 16:22:44 Let's call this revert_bounds_in_pixels
riajiang 2016/12/21 17:48:33 Done.
541 if (IsRoot(window)) { 540 if (IsRoot(window)) {
542 GetWindowTreeHostMus(window)->SetBoundsFromServer(revert_bounds); 541 GetWindowTreeHostMus(window)->SetBoundsFromServer(revert_bounds);
sadrul 2016/12/21 16:22:44 Add a comment here that WindowTreeHost expects bou
riajiang 2016/12/21 17:48:32 Done.
543 return; 542 return;
544 } 543 }
545 544
546 window->SetBoundsFromServer(revert_bounds); 545 window->SetBoundsFromServer(gfx::ConvertRectToDIP(
546 ScaleFactorForDisplay(window->GetWindow()), revert_bounds));
547 } 547 }
548 548
549 void WindowTreeClient::SetWindowVisibleFromServer(WindowMus* window, 549 void WindowTreeClient::SetWindowVisibleFromServer(WindowMus* window,
550 bool visible) { 550 bool visible) {
551 if (!IsRoot(window)) { 551 if (!IsRoot(window)) {
552 window->SetVisibleFromServer(visible); 552 window->SetVisibleFromServer(visible);
553 return; 553 return;
554 } 554 }
555 555
556 std::unique_ptr<WindowMusChangeData> data = 556 std::unique_ptr<WindowMusChangeData> data =
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 641
642 void WindowTreeClient::OnWindowMusBoundsChanged(WindowMus* window, 642 void WindowTreeClient::OnWindowMusBoundsChanged(WindowMus* window,
643 const gfx::Rect& old_bounds, 643 const gfx::Rect& old_bounds,
644 const gfx::Rect& new_bounds) { 644 const gfx::Rect& new_bounds) {
645 // Changes to bounds of root windows are routed through 645 // Changes to bounds of root windows are routed through
646 // OnWindowTreeHostBoundsWillChange(). Any bounds that happen here are a side 646 // OnWindowTreeHostBoundsWillChange(). Any bounds that happen here are a side
647 // effect of those and can be ignored. 647 // effect of those and can be ignored.
648 if (IsRoot(window)) 648 if (IsRoot(window))
649 return; 649 return;
650 650
651 ScheduleInFlightBoundsChange(window, old_bounds, new_bounds); 651 ScheduleInFlightBoundsChange(
sadrul 2016/12/21 16:22:44 float device_scale_factor = ScaleFactorForDisplay(
riajiang 2016/12/21 17:48:33 Done.
652 window, gfx::ConvertRectToPixel(
653 ScaleFactorForDisplay(window->GetWindow()), old_bounds),
654 gfx::ConvertRectToPixel(ScaleFactorForDisplay(window->GetWindow()),
655 new_bounds));
652 } 656 }
653 657
654 void WindowTreeClient::OnWindowMusAddChild(WindowMus* parent, 658 void WindowTreeClient::OnWindowMusAddChild(WindowMus* parent,
655 WindowMus* child) { 659 WindowMus* child) {
656 // TODO: add checks to ensure this can work. 660 // TODO: add checks to ensure this can work.
657 const uint32_t change_id = ScheduleInFlightChange( 661 const uint32_t change_id = ScheduleInFlightChange(
658 base::MakeUnique<CrashInFlightChange>(parent, ChangeType::ADD_CHILD)); 662 base::MakeUnique<CrashInFlightChange>(parent, ChangeType::ADD_CHILD));
659 tree_->AddWindow(change_id, parent->server_id(), child->server_id()); 663 tree_->AddWindow(change_id, parent->server_id(), child->server_id());
660 } 664 }
661 665
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 SetWindowVisibleFromServer(window, true); 922 SetWindowVisibleFromServer(window, true);
919 } 923 }
920 924
921 const gfx::Rect bounds(data->bounds); 925 const gfx::Rect bounds(data->bounds);
922 { 926 {
923 InFlightBoundsChange bounds_change(this, window, bounds); 927 InFlightBoundsChange bounds_change(this, window, bounds);
924 InFlightChange* current_change = 928 InFlightChange* current_change =
925 GetOldestInFlightChangeMatching(bounds_change); 929 GetOldestInFlightChangeMatching(bounds_change);
926 if (current_change) 930 if (current_change)
927 current_change->SetRevertValueFrom(bounds_change); 931 current_change->SetRevertValueFrom(bounds_change);
928 else if (window->GetWindow()->bounds() != bounds) 932 else if (gfx::ConvertRectToPixel(ScaleFactorForDisplay(window->GetWindow()),
933 window->GetWindow()->bounds()) != bounds)
929 SetWindowBoundsFromServer(window, bounds); 934 SetWindowBoundsFromServer(window, bounds);
930 } 935 }
931 936
932 // There is currently no API to bulk set properties, so we iterate over each 937 // There is currently no API to bulk set properties, so we iterate over each
933 // property individually. 938 // property individually.
934 for (const auto& pair : data->properties) { 939 for (const auto& pair : data->properties) {
935 std::unique_ptr<std::vector<uint8_t>> revert_value( 940 std::unique_ptr<std::vector<uint8_t>> revert_value(
936 base::MakeUnique<std::vector<uint8_t>>(pair.second)); 941 base::MakeUnique<std::vector<uint8_t>>(pair.second));
937 InFlightPropertyChange property_change(window, pair.first, 942 InFlightPropertyChange property_change(window, pair.first,
938 std::move(revert_value)); 943 std::move(revert_value));
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
1340 } 1345 }
1341 } 1346 }
1342 } 1347 }
1343 1348
1344 void WindowTreeClient::WmDisplayModified(const display::Display& display) { 1349 void WindowTreeClient::WmDisplayModified(const display::Display& display) {
1345 DCHECK(window_manager_delegate_); 1350 DCHECK(window_manager_delegate_);
1346 // TODO(sky): this should likely route to WindowTreeHost. 1351 // TODO(sky): this should likely route to WindowTreeHost.
1347 window_manager_delegate_->OnWmDisplayModified(display); 1352 window_manager_delegate_->OnWmDisplayModified(display);
1348 } 1353 }
1349 1354
1350 // TODO(riajiang): Convert between pixel and DIP for window bounds properly.
1351 // (http://crbug.com/646942)
1352 void WindowTreeClient::WmSetBounds(uint32_t change_id, 1355 void WindowTreeClient::WmSetBounds(uint32_t change_id,
1353 Id window_id, 1356 Id window_id,
1354 const gfx::Rect& transit_bounds) { 1357 const gfx::Rect& transit_bounds_in_pixels) {
1355 WindowMus* window = GetWindowByServerId(window_id); 1358 WindowMus* window = GetWindowByServerId(window_id);
1356 bool result = false; 1359 bool result = false;
1357 if (window) { 1360 if (window) {
1361 float device_scale_factor = ScaleFactorForDisplay(window->GetWindow());
1358 DCHECK(window_manager_delegate_); 1362 DCHECK(window_manager_delegate_);
1359 gfx::Rect bounds = transit_bounds; 1363 gfx::Rect transit_bounds_in_dip =
1364 gfx::ConvertRectToDIP(device_scale_factor, transit_bounds_in_pixels);
1365 gfx::Rect bounds_in_dip = transit_bounds_in_dip;
1360 // TODO: this needs to trigger scheduling a bounds change on |window|. 1366 // TODO: this needs to trigger scheduling a bounds change on |window|.
1361 result = 1367 result = window_manager_delegate_->OnWmSetBounds(window->GetWindow(),
1362 window_manager_delegate_->OnWmSetBounds(window->GetWindow(), &bounds); 1368 &bounds_in_dip);
1363 if (result) { 1369 if (result) {
1364 // If the resulting bounds differ return false. Returning false ensures 1370 // If the resulting bounds differ return false. Returning false ensures
1365 // the client applies the bounds we set below. 1371 // the client applies the bounds we set below.
1366 result = bounds == transit_bounds; 1372 result = bounds_in_dip == transit_bounds_in_dip;
1367 window->SetBoundsFromServer(bounds); 1373 window->SetBoundsFromServer(bounds_in_dip);
1368 } 1374 }
1369 } 1375 }
1370 if (window_manager_internal_client_) 1376 if (window_manager_internal_client_)
1371 window_manager_internal_client_->WmResponse(change_id, result); 1377 window_manager_internal_client_->WmResponse(change_id, result);
1372 } 1378 }
1373 1379
1374 void WindowTreeClient::WmSetProperty( 1380 void WindowTreeClient::WmSetProperty(
1375 uint32_t change_id, 1381 uint32_t change_id,
1376 Id window_id, 1382 Id window_id,
1377 const std::string& name, 1383 const std::string& name,
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1521 void WindowTreeClient::ActivateNextWindow() { 1527 void WindowTreeClient::ActivateNextWindow() {
1522 if (window_manager_internal_client_) 1528 if (window_manager_internal_client_)
1523 window_manager_internal_client_->ActivateNextWindow(); 1529 window_manager_internal_client_->ActivateNextWindow();
1524 } 1530 }
1525 1531
1526 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea( 1532 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea(
1527 Window* window, 1533 Window* window,
1528 const gfx::Vector2d& offset, 1534 const gfx::Vector2d& offset,
1529 const gfx::Insets& hit_area) { 1535 const gfx::Insets& hit_area) {
1530 if (window_manager_internal_client_) { 1536 if (window_manager_internal_client_) {
1531 // TODO(riajiang): Figure out if |offset| needs to be converted. 1537 float device_scale_factor = ScaleFactorForDisplay(window);
1532 // (http://crbugs.com/646932)
1533 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( 1538 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea(
1534 WindowMus::Get(window)->server_id(), offset.x(), offset.y(), 1539 WindowMus::Get(window)->server_id(), offset.x() * device_scale_factor,
1535 gfx::ConvertInsetsToDIP(ScaleFactorForDisplay(window), hit_area)); 1540 offset.y() * device_scale_factor,
sadrul 2016/12/21 16:22:44 Use gfx::ScaleVector2d(offset, device_scale_factor
riajiang 2016/12/21 17:48:32 Done.
1541 gfx::ConvertInsetsToPixel(device_scale_factor, hit_area));
1536 } 1542 }
1537 } 1543 }
1538 1544
1539 void WindowTreeClient::RequestClose(Window* window) { 1545 void WindowTreeClient::RequestClose(Window* window) {
1540 DCHECK(window); 1546 DCHECK(window);
1541 if (window_manager_internal_client_) 1547 if (window_manager_internal_client_)
1542 window_manager_internal_client_->WmRequestClose( 1548 window_manager_internal_client_->WmRequestClose(
1543 WindowMus::Get(window)->server_id()); 1549 WindowMus::Get(window)->server_id());
1544 } 1550 }
1545 1551
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1690 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( 1696 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>(
1691 this, capture_synchronizer_.get(), window)); 1697 this, capture_synchronizer_.get(), window));
1692 } 1698 }
1693 1699
1694 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { 1700 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) {
1695 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( 1701 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>(
1696 this, focus_synchronizer_.get(), window)); 1702 this, focus_synchronizer_.get(), window));
1697 } 1703 }
1698 1704
1699 } // namespace aura 1705 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698