1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
From d7680c81c95c4609bf4ffbad05656a09d589a382 Mon Sep 17 00:00:00 2001
From: Maksim Sisov <msisov@igalia.com>
Date: Fri, 6 Dec 2019 19:49:45 +0000
Subject: [PATCH 3/9] ozone/Wayland: move bounds translation util to utilities.
Just moving the translation helper method to utilities.
Bug: 1028919
Change-Id: I6e60bcdf804e4aaff9cb39d437e4302af2ed3fd2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1953710
Commit-Queue: Maksim Sisov <msisov@igalia.com>
Reviewed-by: Michael Spang <spang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#722582}
---
.../platform/wayland/common/wayland_util.cc | 14 ++++++++++
.../platform/wayland/common/wayland_util.h | 8 ++++++
.../platform/wayland/host/wayland_window.cc | 27 +++----------------
3 files changed, 26 insertions(+), 23 deletions(-)
diff --git a/ui/ozone/platform/wayland/common/wayland_util.cc b/ui/ozone/platform/wayland/common/wayland_util.cc
index 0201f689e90d..e0430b860adf 100644
--- a/ui/ozone/platform/wayland/common/wayland_util.cc
+++ b/ui/ozone/platform/wayland/common/wayland_util.cc
@@ -141,4 +141,18 @@ void ReadDataFromFD(base::ScopedFD fd, std::vector<uint8_t>* contents) {
contents->insert(contents->end(), buffer, buffer + length);
}
+gfx::Rect TranslateBoundsToParentCoordinates(const gfx::Rect& child_bounds,
+ const gfx::Rect& parent_bounds) {
+ return gfx::Rect(
+ (child_bounds.origin() - parent_bounds.origin().OffsetFromOrigin()),
+ child_bounds.size());
+}
+
+gfx::Rect TranslateBoundsToTopLevelCoordinates(const gfx::Rect& child_bounds,
+ const gfx::Rect& parent_bounds) {
+ return gfx::Rect(
+ (child_bounds.origin() + parent_bounds.origin().OffsetFromOrigin()),
+ child_bounds.size());
+}
+
} // namespace wl
diff --git a/ui/ozone/platform/wayland/common/wayland_util.h b/ui/ozone/platform/wayland/common/wayland_util.h
index 368f3d9a9427..48332e059da0 100644
--- a/ui/ozone/platform/wayland/common/wayland_util.h
+++ b/ui/ozone/platform/wayland/common/wayland_util.h
@@ -13,6 +13,7 @@
#include "base/containers/flat_map.h"
#include "base/files/scoped_file.h"
#include "base/macros.h"
+#include "ui/gfx/geometry/rect.h"
#include "ui/ozone/platform/wayland/common/wayland_object.h"
class SkBitmap;
@@ -50,6 +51,13 @@ bool DrawBitmap(const SkBitmap& bitmap, ui::WaylandShmBuffer* out_buffer);
// Helper function to read data from a file.
void ReadDataFromFD(base::ScopedFD fd, std::vector<uint8_t>* contents);
+// Translates bounds relative to top level window to specified parent.
+gfx::Rect TranslateBoundsToParentCoordinates(const gfx::Rect& child_bounds,
+ const gfx::Rect& parent_bounds);
+// Translates bounds relative to parent window to top level window.
+gfx::Rect TranslateBoundsToTopLevelCoordinates(const gfx::Rect& child_bounds,
+ const gfx::Rect& parent_bounds);
+
} // namespace wl
#endif // UI_OZONE_PLATFORM_WAYLAND_COMMON_WAYLAND_UTIL_H_
diff --git a/ui/ozone/platform/wayland/host/wayland_window.cc b/ui/ozone/platform/wayland/host/wayland_window.cc
index da9a4cb368b8..709fb681f7d9 100644
--- a/ui/ozone/platform/wayland/host/wayland_window.cc
+++ b/ui/ozone/platform/wayland/host/wayland_window.cc
@@ -16,6 +16,7 @@
#include "ui/events/event_utils.h"
#include "ui/events/ozone/events_ozone.h"
#include "ui/gfx/geometry/point_f.h"
+#include "ui/ozone/platform/wayland/common/wayland_util.h"
#include "ui/ozone/platform/wayland/host/shell_object_factory.h"
#include "ui/ozone/platform/wayland/host/shell_popup_wrapper.h"
#include "ui/ozone/platform/wayland/host/shell_surface_wrapper.h"
@@ -28,26 +29,6 @@
namespace ui {
-namespace {
-
-// Translates bounds relative to top level window to specified parent.
-gfx::Rect TranslateBoundsToParentCoordinates(const gfx::Rect& child_bounds,
- const gfx::Rect& parent_bounds) {
- return gfx::Rect(gfx::Point(child_bounds.x() - parent_bounds.x(),
- child_bounds.y() - parent_bounds.y()),
- child_bounds.size());
-}
-
-// Translates bounds relative to parent window to top level window.
-gfx::Rect TranslateBoundsToTopLevelCoordinates(const gfx::Rect& child_bounds,
- const gfx::Rect& parent_bounds) {
- return gfx::Rect(gfx::Point(child_bounds.x() + parent_bounds.x(),
- child_bounds.y() + parent_bounds.y()),
- child_bounds.size());
-}
-
-} // namespace
-
WaylandWindow::WaylandWindow(PlatformWindowDelegate* delegate,
WaylandConnection* connection)
: delegate_(delegate),
@@ -177,7 +158,7 @@ void WaylandWindow::CreateAndShowTooltipSubSurface() {
const auto parent_bounds_dip =
gfx::ScaleToRoundedRect(parent_window->GetBounds(), 1.0 / ui_scale_);
auto new_bounds_dip =
- TranslateBoundsToParentCoordinates(bounds_px_, parent_bounds_dip);
+ wl::TranslateBoundsToParentCoordinates(bounds_px_, parent_bounds_dip);
auto bounds_px =
gfx::ScaleToRoundedRect(new_bounds_dip, ui_scale_ / buffer_scale_);
@@ -671,7 +652,7 @@ void WaylandWindow::HandlePopupConfigure(const gfx::Rect& bounds_dip) {
// window, which automatically becomes the same as relative to an origin of
// a display.
new_bounds_dip = gfx::ScaleToRoundedRect(
- TranslateBoundsToTopLevelCoordinates(
+ wl::TranslateBoundsToTopLevelCoordinates(
gfx::ScaleToRoundedRect(new_bounds_dip, buffer_scale_),
parent_window_->GetBounds()),
1.0 / buffer_scale_);
@@ -962,7 +943,7 @@ gfx::Rect WaylandWindow::AdjustPopupWindowPosition() const {
const gfx::Rect parent_bounds_dip =
gfx::ScaleToRoundedRect(parent_window_->GetBounds(), 1.0 / ui_scale_);
gfx::Rect new_bounds_dip =
- TranslateBoundsToParentCoordinates(bounds_px_, parent_bounds_dip);
+ wl::TranslateBoundsToParentCoordinates(bounds_px_, parent_bounds_dip);
// Chromium may decide to position nested menu windows on the left side
// instead of the right side of parent menu windows when the size of the
--
2.24.1
|