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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/aura/mus/window_tree_client.cc » ('j') | ui/aura/mus/window_tree_client.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/ui/public/cpp/window_tree_client.cc
diff --git a/services/ui/public/cpp/window_tree_client.cc b/services/ui/public/cpp/window_tree_client.cc
index 31e47c6f1bd93956907a5d44e235bf168ab67d91..6a334a53d349e2595c21b0030f3a3921a902f52c 100644
--- a/services/ui/public/cpp/window_tree_client.cc
+++ b/services/ui/public/cpp/window_tree_client.cc
@@ -25,7 +25,9 @@
#include "services/ui/public/cpp/window_tree_client_delegate.h"
#include "services/ui/public/cpp/window_tree_client_observer.h"
#include "services/ui/public/interfaces/window_manager_window_tree_factory.mojom.h"
+#include "ui/display/screen.h"
#include "ui/events/event.h"
+#include "ui/gfx/geometry/dip_util.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/size.h"
@@ -35,6 +37,22 @@ Id MakeTransportId(ClientSpecificId client_id, ClientSpecificId local_id) {
return (client_id << 16) | local_id;
}
+// Helper function to get the device_scale_factor() of the display::Display
+// with |display_id|.
+float DeviceScaleFactorForDisplay(int64_t display_id) {
+ // TODO(riajiang): Change to use display::GetDisplayWithDisplayId() after
+ // https://codereview.chromium.org/2361283002/ is landed.
+ std::vector<display::Display> displays =
+ display::Screen::GetScreen()->GetAllDisplays();
+ auto iter = std::find_if(displays.begin(), displays.end(),
+ [display_id](const display::Display& display) {
+ return display.id() == display_id;
+ });
+ if (iter != displays.end())
+ return iter->device_scale_factor();
+ return 1.f;
+}
+
// Helper called to construct a local window object from transport data.
Window* AddWindowToClient(WindowTreeClient* client,
Window* parent,
@@ -50,7 +68,14 @@ Window* AddWindowToClient(WindowTreeClient* client,
window_data->properties
.To<std::map<std::string, std::vector<uint8_t>>>());
client->AddWindow(window);
- private_window.LocalSetBounds(gfx::Rect(), window_data->bounds);
+ float device_scale_factor = DeviceScaleFactorForDisplay(window->display_id());
+ if (device_scale_factor == 1.f) {
+ private_window.LocalSetBounds(gfx::Rect(), window_data->bounds);
+ } else {
+ private_window.LocalSetBounds(
+ gfx::Rect(),
+ gfx::ConvertRectToDIP(device_scale_factor, window_data->bounds));
sky 2016/11/09 00:21:13 How come you adjust bounds in the mus side, but no
riajiang 2016/11/09 21:07:08 The window bounds adjustment in the mus side of WT
+ }
if (parent)
WindowPrivate(parent).LocalAddChild(window);
return window;
@@ -218,7 +243,14 @@ void WindowTreeClient::SetBounds(Window* window,
DCHECK(tree_);
const uint32_t change_id = ScheduleInFlightChange(
base::MakeUnique<InFlightBoundsChange>(window, old_bounds));
- tree_->SetWindowBounds(change_id, server_id(window), bounds);
+ float device_scale_factor = DeviceScaleFactorForDisplay(window->display_id());
+ if (device_scale_factor == 1.f) {
+ tree_->SetWindowBounds(change_id, server_id(window), bounds);
+ } else {
+ tree_->SetWindowBounds(
+ change_id, server_id(window),
+ gfx::ConvertRectToPixel(device_scale_factor, bounds));
+ }
}
void WindowTreeClient::SetCapture(Window* window) {
@@ -250,12 +282,32 @@ void WindowTreeClient::SetClientArea(
const gfx::Insets& client_area,
const std::vector<gfx::Rect>& additional_client_areas) {
DCHECK(tree_);
- tree_->SetClientArea(window_id, client_area, additional_client_areas);
+ float device_scale_factor =
+ DeviceScaleFactorForDisplay(GetWindowByServerId(window_id)->display_id());
+ if (device_scale_factor == 1.f) {
+ tree_->SetClientArea(window_id, client_area, additional_client_areas);
+ } else {
+ std::vector<gfx::Rect> additional_client_areas_in_pixel;
+ for (const gfx::Rect& area : additional_client_areas) {
+ additional_client_areas_in_pixel.push_back(
+ gfx::ConvertRectToPixel(device_scale_factor, area));
+ }
+ tree_->SetClientArea(
+ window_id, gfx::ConvertInsetsToPixel(device_scale_factor, client_area),
+ additional_client_areas_in_pixel);
+ }
}
void WindowTreeClient::SetHitTestMask(Id window_id, const gfx::Rect& mask) {
DCHECK(tree_);
- tree_->SetHitTestMask(window_id, mask);
+ float device_scale_factor =
+ DeviceScaleFactorForDisplay(GetWindowByServerId(window_id)->display_id());
+ if (device_scale_factor == 1.f) {
+ tree_->SetHitTestMask(window_id, mask);
+ } else {
+ tree_->SetHitTestMask(window_id,
+ gfx::ConvertRectToPixel(device_scale_factor, mask));
+ }
}
void WindowTreeClient::ClearHitTestMask(Id window_id) {
@@ -879,11 +931,22 @@ void WindowTreeClient::OnWindowBoundsChanged(Id window_id,
if (!window)
return;
- InFlightBoundsChange new_change(window, new_bounds);
- if (ApplyServerChangeToExistingInFlightChange(new_change))
- return;
-
- WindowPrivate(window).LocalSetBounds(old_bounds, new_bounds);
+ float device_scale_factor = DeviceScaleFactorForDisplay(window->display_id());
+ if (device_scale_factor == 1.f) {
+ InFlightBoundsChange new_change(window, new_bounds);
+ if (ApplyServerChangeToExistingInFlightChange(new_change))
+ return;
+ WindowPrivate(window).LocalSetBounds(old_bounds, new_bounds);
+ } else {
+ gfx::Rect old_bounds_in_dip =
+ gfx::ConvertRectToDIP(device_scale_factor, old_bounds);
+ gfx::Rect new_bounds_in_dip =
+ gfx::ConvertRectToDIP(device_scale_factor, new_bounds);
+ InFlightBoundsChange new_change(window, new_bounds_in_dip);
+ if (ApplyServerChangeToExistingInFlightChange(new_change))
+ return;
+ WindowPrivate(window).LocalSetBounds(old_bounds_in_dip, new_bounds_in_dip);
+ }
}
void WindowTreeClient::OnClientAreaChanged(
@@ -892,9 +955,22 @@ void WindowTreeClient::OnClientAreaChanged(
mojo::Array<gfx::Rect> new_additional_client_areas) {
Window* window = GetWindowByServerId(window_id);
if (window) {
- WindowPrivate(window).LocalSetClientArea(
- new_client_area,
- new_additional_client_areas.To<std::vector<gfx::Rect>>());
+ float device_scale_factor =
+ DeviceScaleFactorForDisplay(window->display_id());
+ if (device_scale_factor == 1.f) {
+ WindowPrivate(window).LocalSetClientArea(
+ new_client_area,
+ new_additional_client_areas.To<std::vector<gfx::Rect>>());
+ } else {
+ std::vector<gfx::Rect> new_additional_client_areas_in_dip;
+ for (const gfx::Rect& area : new_additional_client_areas) {
+ new_additional_client_areas_in_dip.push_back(
+ gfx::ConvertRectToDIP(device_scale_factor, area));
+ }
+ WindowPrivate(window).LocalSetClientArea(
+ gfx::ConvertInsetsToDIP(device_scale_factor, new_client_area),
+ new_additional_client_areas_in_dip);
+ }
}
}
@@ -1277,12 +1353,21 @@ void WindowTreeClient::WmSetBounds(uint32_t change_id,
bool result = false;
if (window) {
DCHECK(window_manager_delegate_);
- gfx::Rect bounds = transit_bounds;
+ float device_scale_factor =
+ DeviceScaleFactorForDisplay(window->display_id());
+ gfx::Rect transit_bounds_in_dip;
+ if (device_scale_factor == 1.f) {
+ transit_bounds_in_dip = transit_bounds;
+ } else {
+ transit_bounds_in_dip =
+ gfx::ConvertRectToDIP(device_scale_factor, transit_bounds);
+ }
+ gfx::Rect bounds = transit_bounds_in_dip;
result = window_manager_delegate_->OnWmSetBounds(window, &bounds);
if (result) {
// If the resulting bounds differ return false. Returning false ensures
// the client applies the bounds we set below.
- result = bounds == transit_bounds;
+ result = bounds == transit_bounds_in_dip;
window->SetBounds(bounds);
}
}
@@ -1430,8 +1515,18 @@ void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea(
const gfx::Vector2d& offset,
const gfx::Insets& hit_area) {
if (window_manager_internal_client_) {
- window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea(
- server_id(window), offset.x(), offset.y(), hit_area);
+ float device_scale_factor =
+ DeviceScaleFactorForDisplay(window->display_id());
+ if (device_scale_factor == 1.f) {
+ window_manager_internal_client_
+ ->SetUnderlaySurfaceOffsetAndExtendedHitArea(
+ server_id(window), offset.x(), offset.y(), hit_area);
+ } else {
+ window_manager_internal_client_
+ ->SetUnderlaySurfaceOffsetAndExtendedHitArea(
+ server_id(window), offset.x(), offset.y(),
+ gfx::ConvertInsetsToDIP(device_scale_factor, hit_area));
+ }
}
}
« no previous file with comments | « no previous file | ui/aura/mus/window_tree_client.cc » ('j') | ui/aura/mus/window_tree_client.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698