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

Unified Diff: ui/wm/core/default_screen_position_client.cc

Issue 686513004: Creating default implementation for aura::client::ScreenPositionClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Turning GetOrigin() into an object method. Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: ui/wm/core/default_screen_position_client.cc
diff --git a/ui/wm/core/default_screen_position_client.cc b/ui/wm/core/default_screen_position_client.cc
new file mode 100644
index 0000000000000000000000000000000000000000..53ecd25aa795212069226f577e4a0bf5e346d15b
--- /dev/null
+++ b/ui/wm/core/default_screen_position_client.cc
@@ -0,0 +1,59 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/wm/core/default_screen_position_client.h"
+
+#include "ui/aura/window_tree_host.h"
+#include "ui/gfx/display.h"
+#include "ui/gfx/point_conversions.h"
+#include "ui/gfx/screen.h"
+
+namespace wm {
+
+DefaultScreenPositionClient::DefaultScreenPositionClient() {
+}
+
+DefaultScreenPositionClient::~DefaultScreenPositionClient() {
+}
+
+gfx::Point DefaultScreenPositionClient::GetOrigin(
+ const aura::Window* root_window) {
+ gfx::Point origin_in_pixels = root_window->GetHost()->GetBounds().origin();
+ aura::Window* window = const_cast<aura::Window*>(root_window);
+ float scale = gfx::Screen::GetScreenFor(window)->
+ GetDisplayNearestWindow(window).device_scale_factor();
+ return gfx::ToFlooredPoint(gfx::ScalePoint(origin_in_pixels, 1 / scale));
+}
+
+void DefaultScreenPositionClient::ConvertPointToScreen(
+ const aura::Window* window,
+ gfx::Point* point) {
+ const aura::Window* root_window = window->GetRootWindow();
+ aura::Window::ConvertPointToTarget(window, root_window, point);
+ gfx::Point origin = GetOrigin(root_window);
+ point->Offset(origin.x(), origin.y());
+}
+
+void DefaultScreenPositionClient::ConvertPointFromScreen(
+ const aura::Window* window,
+ gfx::Point* point) {
+ const aura::Window* root_window = window->GetRootWindow();
+ gfx::Point origin = GetOrigin(root_window);
+ point->Offset(-origin.x(), -origin.y());
+ aura::Window::ConvertPointToTarget(root_window, window, point);
+}
+
+void DefaultScreenPositionClient::ConvertHostPointToScreen(aura::Window* window,
+ gfx::Point* point) {
+ aura::Window* root_window = window->GetRootWindow();
+ ConvertPointToScreen(root_window, point);
+}
+
+void DefaultScreenPositionClient::SetBounds(aura::Window* window,
+ const gfx::Rect& bounds,
+ const gfx::Display& display) {
+ window->SetBounds(bounds);
+}
+
+} // namespace wm

Powered by Google App Engine
This is Rietveld 408576698