Commit 24085438 authored by Maksim Sisov's avatar Maksim Sisov Committed by Commit Bot

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: default avatarMichael Spang <spang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#722582}
parent 118865f3
...@@ -141,4 +141,18 @@ void ReadDataFromFD(base::ScopedFD fd, std::vector<uint8_t>* contents) { ...@@ -141,4 +141,18 @@ void ReadDataFromFD(base::ScopedFD fd, std::vector<uint8_t>* contents) {
contents->insert(contents->end(), buffer, buffer + length); 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 } // namespace wl
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/containers/flat_map.h" #include "base/containers/flat_map.h"
#include "base/files/scoped_file.h" #include "base/files/scoped_file.h"
#include "base/macros.h" #include "base/macros.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/ozone/platform/wayland/common/wayland_object.h" #include "ui/ozone/platform/wayland/common/wayland_object.h"
class SkBitmap; class SkBitmap;
...@@ -50,6 +51,13 @@ bool DrawBitmap(const SkBitmap& bitmap, ui::WaylandShmBuffer* out_buffer); ...@@ -50,6 +51,13 @@ bool DrawBitmap(const SkBitmap& bitmap, ui::WaylandShmBuffer* out_buffer);
// Helper function to read data from a file. // Helper function to read data from a file.
void ReadDataFromFD(base::ScopedFD fd, std::vector<uint8_t>* contents); 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 } // namespace wl
#endif // UI_OZONE_PLATFORM_WAYLAND_COMMON_WAYLAND_UTIL_H_ #endif // UI_OZONE_PLATFORM_WAYLAND_COMMON_WAYLAND_UTIL_H_
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "ui/events/event_utils.h" #include "ui/events/event_utils.h"
#include "ui/events/ozone/events_ozone.h" #include "ui/events/ozone/events_ozone.h"
#include "ui/gfx/geometry/point_f.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_object_factory.h"
#include "ui/ozone/platform/wayland/host/shell_popup_wrapper.h" #include "ui/ozone/platform/wayland/host/shell_popup_wrapper.h"
#include "ui/ozone/platform/wayland/host/shell_surface_wrapper.h" #include "ui/ozone/platform/wayland/host/shell_surface_wrapper.h"
...@@ -28,26 +29,6 @@ ...@@ -28,26 +29,6 @@
namespace ui { 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, WaylandWindow::WaylandWindow(PlatformWindowDelegate* delegate,
WaylandConnection* connection) WaylandConnection* connection)
: delegate_(delegate), : delegate_(delegate),
...@@ -243,7 +224,7 @@ void WaylandWindow::CreateAndShowTooltipSubSurface() { ...@@ -243,7 +224,7 @@ void WaylandWindow::CreateAndShowTooltipSubSurface() {
const auto parent_bounds_dip = const auto parent_bounds_dip =
gfx::ScaleToRoundedRect(parent_window->GetBounds(), 1.0 / ui_scale_); gfx::ScaleToRoundedRect(parent_window->GetBounds(), 1.0 / ui_scale_);
auto new_bounds_dip = auto new_bounds_dip =
TranslateBoundsToParentCoordinates(bounds_px_, parent_bounds_dip); wl::TranslateBoundsToParentCoordinates(bounds_px_, parent_bounds_dip);
auto bounds_px = auto bounds_px =
gfx::ScaleToRoundedRect(new_bounds_dip, ui_scale_ / buffer_scale_); gfx::ScaleToRoundedRect(new_bounds_dip, ui_scale_ / buffer_scale_);
...@@ -737,7 +718,7 @@ void WaylandWindow::HandlePopupConfigure(const gfx::Rect& bounds_dip) { ...@@ -737,7 +718,7 @@ void WaylandWindow::HandlePopupConfigure(const gfx::Rect& bounds_dip) {
// window, which automatically becomes the same as relative to an origin of // window, which automatically becomes the same as relative to an origin of
// a display. // a display.
new_bounds_dip = gfx::ScaleToRoundedRect( new_bounds_dip = gfx::ScaleToRoundedRect(
TranslateBoundsToTopLevelCoordinates( wl::TranslateBoundsToTopLevelCoordinates(
gfx::ScaleToRoundedRect(new_bounds_dip, buffer_scale_), gfx::ScaleToRoundedRect(new_bounds_dip, buffer_scale_),
parent_window_->GetBounds()), parent_window_->GetBounds()),
1.0 / buffer_scale_); 1.0 / buffer_scale_);
...@@ -962,7 +943,7 @@ gfx::Rect WaylandWindow::AdjustPopupWindowPosition() const { ...@@ -962,7 +943,7 @@ gfx::Rect WaylandWindow::AdjustPopupWindowPosition() const {
const gfx::Rect parent_bounds_dip = const gfx::Rect parent_bounds_dip =
gfx::ScaleToRoundedRect(parent_window_->GetBounds(), 1.0 / ui_scale_); gfx::ScaleToRoundedRect(parent_window_->GetBounds(), 1.0 / ui_scale_);
gfx::Rect new_bounds_dip = 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 // 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 // instead of the right side of parent menu windows when the size of the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment