Move two utility functions from ash/screen_util.h to ui/wm/core/coordinate_conversion.h
|ash::ScreenUtil::ConvertRectToScreen| and
|ash::ScreenUtil::ConvertRectFromScreen| are moved.
BUG=624521
TEST=Added an unit test.
Review-Url: https://codereview.chromium.org/2660873002
Cr-Commit-Position: refs/heads/master@{#452450}
diff --git a/ash/BUILD.gn b/ash/BUILD.gn
index 3554cc5..ebb51f7 100644
--- a/ash/BUILD.gn
+++ b/ash/BUILD.gn
@@ -1046,6 +1046,7 @@
"//ui/views",
"//ui/views:test_support",
"//ui/views/examples:views_examples_lib",
+ "//ui/wm",
]
}
diff --git a/ash/common/wm/dock/docked_window_layout_manager.cc b/ash/common/wm/dock/docked_window_layout_manager.cc
index 3148ab7..3e620c3f 100644
--- a/ash/common/wm/dock/docked_window_layout_manager.cc
+++ b/ash/common/wm/dock/docked_window_layout_manager.cc
@@ -21,7 +21,6 @@
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/resources/grit/ash_resources.h"
#include "ash/root_window_controller.h"
-#include "ash/screen_util.h"
#include "ash/wm/window_state_aura.h"
#include "base/auto_reset.h"
#include "base/metrics/histogram_macros.h"
@@ -31,6 +30,7 @@
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/views/background.h"
+#include "ui/wm/core/coordinate_conversion.h"
#include "ui/wm/core/window_animations.h"
namespace ash {
@@ -333,8 +333,8 @@
void OnWindowBoundsChanged(aura::Window* window,
const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) override {
- shelf_bounds_in_screen_ =
- ScreenUtil::ConvertRectToScreen(window->parent(), new_bounds);
+ shelf_bounds_in_screen_ = new_bounds;
+ ::wm::ConvertRectToScreen(window->parent(), &shelf_bounds_in_screen_);
// When the shelf is auto-hidden, it has an invisible height of 3px used
// as a hit region which is specific to Chrome OS MD (for non-MD, the 3
diff --git a/ash/common/wm_window.cc b/ash/common/wm_window.cc
index 0fbde9b..0162092 100644
--- a/ash/common/wm_window.cc
+++ b/ash/common/wm_window.cc
@@ -15,7 +15,6 @@
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/public/cpp/window_properties.h"
#include "ash/root_window_controller.h"
-#include "ash/screen_util.h"
#include "ash/shell.h"
#include "ash/wm/resize_handle_window_targeter.h"
#include "ash/wm/resize_shadow_controller.h"
@@ -244,11 +243,15 @@
}
gfx::Rect WmWindow::ConvertRectToScreen(const gfx::Rect& rect) const {
- return ScreenUtil::ConvertRectToScreen(window_, rect);
+ gfx::Rect result(rect);
+ ::wm::ConvertRectToScreen(window_, &result);
+ return result;
}
gfx::Rect WmWindow::ConvertRectFromScreen(const gfx::Rect& rect) const {
- return ScreenUtil::ConvertRectFromScreen(window_, rect);
+ gfx::Rect result(rect);
+ ::wm::ConvertRectFromScreen(window_, &result);
+ return result;
}
gfx::Size WmWindow::GetMinimumSize() const {
diff --git a/ash/magnifier/magnification_controller.cc b/ash/magnifier/magnification_controller.cc
index 9a32419..aa8295b 100644
--- a/ash/magnifier/magnification_controller.cc
+++ b/ash/magnifier/magnification_controller.cc
@@ -15,7 +15,6 @@
#include "ash/host/ash_window_tree_host.h"
#include "ash/host/root_window_transformer.h"
#include "ash/root_window_controller.h"
-#include "ash/screen_util.h"
#include "ash/shell.h"
#include "base/command_line.h"
#include "base/synchronization/waitable_event.h"
@@ -440,8 +439,8 @@
if (node_bounds_in_screen.IsEmpty())
return;
- gfx::Rect node_bounds_in_root =
- ScreenUtil::ConvertRectFromScreen(root_window_, node_bounds_in_screen);
+ gfx::Rect node_bounds_in_root = node_bounds_in_screen;
+ ::wm::ConvertRectFromScreen(root_window_, &node_bounds_in_root);
if (GetViewportRect().Contains(node_bounds_in_root))
return;
diff --git a/ash/screen_util.cc b/ash/screen_util.cc
index 29baadf4..ea11d87 100644
--- a/ash/screen_util.cc
+++ b/ash/screen_util.cc
@@ -14,6 +14,7 @@
#include "ui/display/manager/display_manager.h"
#include "ui/display/screen.h"
#include "ui/gfx/geometry/size_conversions.h"
+#include "ui/wm/core/coordinate_conversion.h"
namespace ash {
@@ -28,37 +29,18 @@
// static
gfx::Rect ScreenUtil::GetDisplayBoundsInParent(aura::Window* window) {
- return ConvertRectFromScreen(
- window->parent(),
- display::Screen::GetScreen()->GetDisplayNearestWindow(window).bounds());
+ gfx::Rect result =
+ display::Screen::GetScreen()->GetDisplayNearestWindow(window).bounds();
+ ::wm::ConvertRectFromScreen(window->parent(), &result);
+ return result;
}
// static
gfx::Rect ScreenUtil::GetDisplayWorkAreaBoundsInParent(aura::Window* window) {
- return ConvertRectFromScreen(window->parent(),
- display::Screen::GetScreen()
- ->GetDisplayNearestWindow(window)
- .work_area());
+ gfx::Rect result =
+ display::Screen::GetScreen()->GetDisplayNearestWindow(window).work_area();
+ ::wm::ConvertRectFromScreen(window->parent(), &result);
+ return result;
}
-// static
-gfx::Rect ScreenUtil::ConvertRectToScreen(aura::Window* window,
- const gfx::Rect& rect) {
- gfx::Point point = rect.origin();
- aura::client::GetScreenPositionClient(window->GetRootWindow())
- ->ConvertPointToScreen(window, &point);
- return gfx::Rect(point, rect.size());
-}
-
-// static
-gfx::Rect ScreenUtil::ConvertRectFromScreen(aura::Window* window,
- const gfx::Rect& rect) {
- gfx::Point point = rect.origin();
- aura::client::GetScreenPositionClient(window->GetRootWindow())
- ->ConvertPointFromScreen(window, &point);
- return gfx::Rect(point, rect.size());
-}
-
-// static
-
} // namespace ash
diff --git a/ash/screen_util.h b/ash/screen_util.h
index c0c3ce9..36ca242 100644
--- a/ash/screen_util.h
+++ b/ash/screen_util.h
@@ -30,16 +30,6 @@
// Returns the display's work area bounds in parent coordinates.
static gfx::Rect GetDisplayWorkAreaBoundsInParent(aura::Window* window);
- // TODO(oshima): Move following two to wm/coordinate_conversion.h
- // Converts |rect| from |window|'s coordinates to the virtual screen
- // coordinates.
- static gfx::Rect ConvertRectToScreen(aura::Window* window,
- const gfx::Rect& rect);
-
- // Converts |rect| from virtual screen coordinates to the |window|'s
- // coordinates.
- static gfx::Rect ConvertRectFromScreen(aura::Window* window,
- const gfx::Rect& rect);
private:
ScreenUtil() {}
~ScreenUtil() {}
diff --git a/ash/screen_util_unittest.cc b/ash/screen_util_unittest.cc
index 71f470e..7090555 100644
--- a/ash/screen_util_unittest.cc
+++ b/ash/screen_util_unittest.cc
@@ -16,6 +16,7 @@
#include "ui/display/manager/display_manager.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
+#include "ui/wm/core/coordinate_conversion.h"
namespace ash {
namespace test {
@@ -86,23 +87,21 @@
NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100));
secondary->Show();
- EXPECT_EQ("0,0 100x100",
- ScreenUtil::ConvertRectFromScreen(primary->GetNativeView(),
- gfx::Rect(10, 10, 100, 100))
- .ToString());
- EXPECT_EQ("10,10 100x100",
- ScreenUtil::ConvertRectFromScreen(secondary->GetNativeView(),
- gfx::Rect(620, 20, 100, 100))
- .ToString());
+ gfx::Rect r1(10, 10, 100, 100);
+ ::wm::ConvertRectFromScreen(primary->GetNativeView(), &r1);
+ EXPECT_EQ("0,0 100x100", r1.ToString());
- EXPECT_EQ("40,40 100x100",
- ScreenUtil::ConvertRectToScreen(primary->GetNativeView(),
- gfx::Rect(30, 30, 100, 100))
- .ToString());
- EXPECT_EQ("650,50 100x100",
- ScreenUtil::ConvertRectToScreen(secondary->GetNativeView(),
- gfx::Rect(40, 40, 100, 100))
- .ToString());
+ gfx::Rect r2(620, 20, 100, 100);
+ ::wm::ConvertRectFromScreen(secondary->GetNativeView(), &r2);
+ EXPECT_EQ("10,10 100x100", r2.ToString());
+
+ gfx::Rect r3(30, 30, 100, 100);
+ ::wm::ConvertRectToScreen(primary->GetNativeView(), &r3);
+ EXPECT_EQ("40,40 100x100", r3.ToString());
+
+ gfx::Rect r4(40, 40, 100, 100);
+ ::wm::ConvertRectToScreen(secondary->GetNativeView(), &r4);
+ EXPECT_EQ("650,50 100x100", r4.ToString());
}
TEST_F(ScreenUtilTest, ShelfDisplayBoundsInUnifiedDesktop) {
diff --git a/ash/shell/panel_window.cc b/ash/shell/panel_window.cc
index e10c68c..5566a024 100644
--- a/ash/shell/panel_window.cc
+++ b/ash/shell/panel_window.cc
@@ -6,12 +6,12 @@
#include "ash/common/wm/panels/panel_frame_view.h"
#include "ash/public/cpp/window_properties.h"
-#include "ash/screen_util.h"
#include "ash/shell.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/aura/window.h"
#include "ui/gfx/canvas.h"
#include "ui/views/widget/widget.h"
+#include "ui/wm/core/coordinate_conversion.h"
namespace {
const int kMinWidth = 100;
@@ -44,8 +44,7 @@
params().bounds.set_width(kDefaultWidth);
if (params().bounds.height() == 0)
params().bounds.set_height(kDefaultHeight);
- params().bounds = ScreenUtil::ConvertRectToScreen(
- Shell::GetTargetRootWindow(), params().bounds);
+ ::wm::ConvertRectToScreen(Shell::GetTargetRootWindow(), ¶ms().bounds);
widget->Init(params());
widget->GetNativeView()->SetName(name_);
diff --git a/ash/wm/drag_window_controller.cc b/ash/wm/drag_window_controller.cc
index 698f0d9..365ce2f 100644
--- a/ash/wm/drag_window_controller.cc
+++ b/ash/wm/drag_window_controller.cc
@@ -8,7 +8,6 @@
#include "ash/display/window_tree_host_manager.h"
#include "ash/public/cpp/shell_window_ids.h"
-#include "ash/screen_util.h"
#include "ash/shell.h"
#include "ash/wm/window_util.h"
#include "base/memory/ptr_util.h"
@@ -24,6 +23,7 @@
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
+#include "ui/wm/core/coordinate_conversion.h"
#include "ui/wm/core/shadow_types.h"
#include "ui/wm/core/window_util.h"
@@ -59,8 +59,8 @@
if (!drag_window_)
CreateDragWindow(original_window, bounds_in_screen);
- gfx::Rect bounds_in_root = ScreenUtil::ConvertRectFromScreen(
- drag_window_->parent(), bounds_in_screen);
+ gfx::Rect bounds_in_root = bounds_in_screen;
+ ::wm::ConvertRectFromScreen(drag_window_->parent(), &bounds_in_root);
drag_window_->SetBounds(bounds_in_root);
if (root_bounds_in_screen.Contains(drag_location_in_screen)) {
SetOpacity(original_window, 1.f);
diff --git a/ash/wm/drag_window_resizer.cc b/ash/wm/drag_window_resizer.cc
index d4cf8aae..0ccaf949 100644
--- a/ash/wm/drag_window_resizer.cc
+++ b/ash/wm/drag_window_resizer.cc
@@ -8,7 +8,6 @@
#include "ash/common/wm/window_state.h"
#include "ash/common/wm_window.h"
#include "ash/display/mouse_cursor_event_filter.h"
-#include "ash/screen_util.h"
#include "ash/shell.h"
#include "ash/wm/drag_window_controller.h"
#include "ash/wm/window_util.h"
@@ -91,8 +90,8 @@
if (bounds.height() > size.height())
bounds.set_height(size.height());
- gfx::Rect dst_bounds =
- ScreenUtil::ConvertRectToScreen(GetAuraTarget()->parent(), bounds);
+ gfx::Rect dst_bounds = bounds;
+ ::wm::ConvertRectToScreen(GetAuraTarget()->parent(), &dst_bounds);
// Adjust the position so that the cursor is on the window.
if (!dst_bounds.Contains(last_mouse_location_in_screen)) {
@@ -144,8 +143,8 @@
if (!drag_window_controller_)
drag_window_controller_.reset(new DragWindowController(GetAuraTarget()));
- const gfx::Rect bounds_in_screen = ScreenUtil::ConvertRectToScreen(
- GetAuraTarget()->parent(), bounds_in_parent);
+ gfx::Rect bounds_in_screen = bounds_in_parent;
+ ::wm::ConvertRectToScreen(GetAuraTarget()->parent(), &bounds_in_screen);
gfx::Rect root_bounds_in_screen =
GetAuraTarget()->GetRootWindow()->GetBoundsInScreen();
diff --git a/ash/wm/overview/window_selector_unittest.cc b/ash/wm/overview/window_selector_unittest.cc
index d3cc05a..61f5d17 100644
--- a/ash/wm/overview/window_selector_unittest.cc
+++ b/ash/wm/overview/window_selector_unittest.cc
@@ -31,7 +31,6 @@
#include "ash/drag_drop/drag_drop_controller.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/root_window_controller.h"
-#include "ash/screen_util.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/shelf_view_test_api.h"
@@ -71,6 +70,7 @@
#include "ui/views/controls/label.h"
#include "ui/views/widget/native_widget_aura.h"
#include "ui/views/widget/widget_delegate.h"
+#include "ui/wm/core/coordinate_conversion.h"
#include "ui/wm/core/window_util.h"
#include "ui/wm/public/activation_delegate.h"
@@ -199,8 +199,9 @@
}
gfx::Rect GetTransformedBounds(aura::Window* window) {
- gfx::RectF bounds(ScreenUtil::ConvertRectToScreen(
- window->parent(), window->layer()->bounds()));
+ gfx::Rect bounds_in_screen = window->layer()->bounds();
+ ::wm::ConvertRectToScreen(window->parent(), &bounds_in_screen);
+ gfx::RectF bounds(bounds_in_screen);
gfx::Transform transform(gfx::TransformAboutPivot(
gfx::ToFlooredPoint(bounds.origin()), window->layer()->transform()));
transform.TransformRect(&bounds);
@@ -208,8 +209,9 @@
}
gfx::Rect GetTransformedTargetBounds(aura::Window* window) {
- gfx::RectF bounds(ScreenUtil::ConvertRectToScreen(
- window->parent(), window->layer()->GetTargetBounds()));
+ gfx::Rect bounds_in_screen = window->layer()->GetTargetBounds();
+ ::wm::ConvertRectToScreen(window->parent(), &bounds_in_screen);
+ gfx::RectF bounds(bounds_in_screen);
gfx::Transform transform(
gfx::TransformAboutPivot(gfx::ToFlooredPoint(bounds.origin()),
window->layer()->GetTargetTransform()));
diff --git a/ash/wm/window_animations.cc b/ash/wm/window_animations.cc
index 190a8e8..c36a0c6 100644
--- a/ash/wm/window_animations.cc
+++ b/ash/wm/window_animations.cc
@@ -13,7 +13,6 @@
#include "ash/common/wm/window_animation_types.h"
#include "ash/common/wm/workspace_controller.h"
#include "ash/common/wm_window.h"
-#include "ash/screen_util.h"
#include "ash/wm/window_util.h"
#include "base/i18n/rtl.h"
#include "base/logging.h"
@@ -35,6 +34,7 @@
#include "ui/display/screen.h"
#include "ui/gfx/interpolated_transform.h"
#include "ui/gfx/transform.h"
+#include "ui/wm/core/coordinate_conversion.h"
#include "ui/wm/core/window_util.h"
namespace ash {
@@ -93,8 +93,7 @@
// moved while the window was minimized.
gfx::Rect bounds = window->bounds();
gfx::Rect target_bounds = GetMinimizeAnimationTargetBoundsInScreen(window);
- target_bounds =
- ScreenUtil::ConvertRectFromScreen(window->parent(), target_bounds);
+ ::wm::ConvertRectFromScreen(window->parent(), &target_bounds);
float scale_x = static_cast<float>(target_bounds.width()) / bounds.width();
float scale_y = static_cast<float>(target_bounds.height()) / bounds.height();