Commit 235ca91a authored by mfomitchev's avatar mfomitchev Committed by Commit bot

Creating default implementation for aura::client::ScreenPositionClient

Making all implementations except for ash's use the new default base class.

I left the ash's implementation as is, since I am not sure if the display origin
is always the same as the root window origin. My suspicion is that it's not..

BUG=NONE

Review URL: https://codereview.chromium.org/686513004

Cr-Commit-Position: refs/heads/master@{#302502}
parent 7eeb0478
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "ui/gfx/screen.h" #include "ui/gfx/screen.h"
#include "ui/wm/core/base_focus_rules.h" #include "ui/wm/core/base_focus_rules.h"
#include "ui/wm/core/capture_controller.h" #include "ui/wm/core/capture_controller.h"
#include "ui/wm/core/default_screen_position_client.h"
#include "ui/wm/core/focus_controller.h" #include "ui/wm/core/focus_controller.h"
#include "ui/wm/core/window_util.h" #include "ui/wm/core/window_util.h"
...@@ -120,7 +121,7 @@ class AthenaFocusRules : public wm::BaseFocusRules { ...@@ -120,7 +121,7 @@ class AthenaFocusRules : public wm::BaseFocusRules {
DISALLOW_COPY_AND_ASSIGN(AthenaFocusRules); DISALLOW_COPY_AND_ASSIGN(AthenaFocusRules);
}; };
class AthenaScreenPositionClient : public aura::client::ScreenPositionClient { class AthenaScreenPositionClient : public wm::DefaultScreenPositionClient {
public: public:
AthenaScreenPositionClient() { AthenaScreenPositionClient() {
} }
...@@ -128,30 +129,12 @@ class AthenaScreenPositionClient : public aura::client::ScreenPositionClient { ...@@ -128,30 +129,12 @@ class AthenaScreenPositionClient : public aura::client::ScreenPositionClient {
private: private:
// aura::client::ScreenPositionClient: // aura::client::ScreenPositionClient:
virtual void ConvertPointToScreen(const aura::Window* window, void ConvertHostPointToScreen(aura::Window* window,
gfx::Point* point) override { gfx::Point* point) override {
const aura::Window* root = window->GetRootWindow();
aura::Window::ConvertPointToTarget(window, root, point);
}
virtual void ConvertPointFromScreen(const aura::Window* window,
gfx::Point* point) override {
const aura::Window* root = window->GetRootWindow();
aura::Window::ConvertPointToTarget(root, window, point);
}
virtual void ConvertHostPointToScreen(aura::Window* window,
gfx::Point* point) override {
// TODO(oshima): Implement this when adding multiple display support. // TODO(oshima): Implement this when adding multiple display support.
NOTREACHED(); NOTREACHED();
} }
virtual void SetBounds(aura::Window* window,
const gfx::Rect& bounds,
const gfx::Display& display) override {
window->SetBounds(bounds);
}
DISALLOW_COPY_AND_ASSIGN(AthenaScreenPositionClient); DISALLOW_COPY_AND_ASSIGN(AthenaScreenPositionClient);
}; };
......
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#include "ui/events/gesture_detection/gesture_configuration.h" #include "ui/events/gesture_detection/gesture_configuration.h"
#include "ui/events/test/event_generator.h" #include "ui/events/test/event_generator.h"
#include "ui/wm/core/default_activation_client.h" #include "ui/wm/core/default_activation_client.h"
#include "ui/wm/core/default_screen_position_client.h"
#include "ui/wm/core/window_util.h" #include "ui/wm/core/window_util.h"
using testing::_; using testing::_;
...@@ -70,34 +71,6 @@ using blink::WebTouchPoint; ...@@ -70,34 +71,6 @@ using blink::WebTouchPoint;
namespace content { namespace content {
namespace { namespace {
// Simple screen position client to test coordinate system conversion.
class TestScreenPositionClient
: public aura::client::ScreenPositionClient {
public:
TestScreenPositionClient() {}
~TestScreenPositionClient() override {}
// aura::client::ScreenPositionClient overrides:
void ConvertPointToScreen(const aura::Window* window,
gfx::Point* point) override {
point->Offset(-1, -1);
}
void ConvertPointFromScreen(const aura::Window* window,
gfx::Point* point) override {
point->Offset(1, 1);
}
void ConvertHostPointToScreen(aura::Window* window,
gfx::Point* point) override {
ConvertPointToScreen(window, point);
}
void SetBounds(aura::Window* window,
const gfx::Rect& bounds,
const gfx::Display& display) override {}
};
class TestOverscrollDelegate : public OverscrollControllerDelegate { class TestOverscrollDelegate : public OverscrollControllerDelegate {
public: public:
explicit TestOverscrollDelegate(RenderWidgetHostView* view) explicit TestOverscrollDelegate(RenderWidgetHostView* view)
...@@ -706,7 +679,7 @@ TEST_F(RenderWidgetHostViewAuraTest, FocusFullscreen) { ...@@ -706,7 +679,7 @@ TEST_F(RenderWidgetHostViewAuraTest, FocusFullscreen) {
// Checks that a popup is positioned correctly relative to its parent using // Checks that a popup is positioned correctly relative to its parent using
// screen coordinates. // screen coordinates.
TEST_F(RenderWidgetHostViewAuraTest, PositionChildPopup) { TEST_F(RenderWidgetHostViewAuraTest, PositionChildPopup) {
TestScreenPositionClient screen_position_client; wm::DefaultScreenPositionClient screen_position_client;
aura::Window* window = parent_view_->GetNativeView(); aura::Window* window = parent_view_->GetNativeView();
aura::Window* root = window->GetRootWindow(); aura::Window* root = window->GetRootWindow();
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "ui/views/widget/tooltip_manager.h" #include "ui/views/widget/tooltip_manager.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
#include "ui/wm/core/default_activation_client.h" #include "ui/wm/core/default_activation_client.h"
#include "ui/wm/core/default_screen_position_client.h"
#include "ui/wm/core/wm_state.h" #include "ui/wm/core/wm_state.h"
#include "ui/wm/public/tooltip_client.h" #include "ui/wm/public/tooltip_client.h"
#include "ui/wm/public/window_types.h" #include "ui/wm/public/window_types.h"
...@@ -411,30 +412,6 @@ int IndexInParent(const aura::Window* window) { ...@@ -411,30 +412,6 @@ int IndexInParent(const aura::Window* window) {
static_cast<int>(i - window->parent()->children().begin()); static_cast<int>(i - window->parent()->children().begin());
} }
class TestScreenPositionClient : public aura::client::ScreenPositionClient {
public:
TestScreenPositionClient() {}
~TestScreenPositionClient() override {}
// ScreenPositionClient overrides:
void ConvertPointToScreen(const aura::Window* window,
gfx::Point* point) override {}
void ConvertPointFromScreen(const aura::Window* window,
gfx::Point* point) override {}
void ConvertHostPointToScreen(aura::Window* root_gwindow,
gfx::Point* point) override {
NOTREACHED();
}
void SetBounds(aura::Window* window,
const gfx::Rect& bounds,
const gfx::Display& display) override {
window->SetBounds(bounds);
}
private:
DISALLOW_COPY_AND_ASSIGN(TestScreenPositionClient);
};
} // namespace } // namespace
class TooltipControllerCaptureTest : public TooltipControllerTest { class TooltipControllerCaptureTest : public TooltipControllerTest {
...@@ -463,7 +440,7 @@ class TooltipControllerCaptureTest : public TooltipControllerTest { ...@@ -463,7 +440,7 @@ class TooltipControllerCaptureTest : public TooltipControllerTest {
} }
private: private:
TestScreenPositionClient screen_position_client_; wm::DefaultScreenPositionClient screen_position_client_;
scoped_ptr<gfx::Screen> desktop_screen_; scoped_ptr<gfx::Screen> desktop_screen_;
DISALLOW_COPY_AND_ASSIGN(TooltipControllerCaptureTest); DISALLOW_COPY_AND_ASSIGN(TooltipControllerCaptureTest);
......
...@@ -4,26 +4,14 @@ ...@@ -4,26 +4,14 @@
#include "ui/views/widget/desktop_aura/desktop_screen_position_client.h" #include "ui/views/widget/desktop_aura/desktop_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"
#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
namespace views { namespace views {
namespace { namespace {
gfx::Point GetOrigin(const aura::Window* root_window) { // Returns true if bounds passed to window in SetBounds should be treated as
gfx::Point origin_in_pixels = root_window->GetHost()->GetBounds().origin(); // though they are in screen coordinates.
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));
}
// Returns true if bounds passed to window are treated as though they are in
// screen coordinates.
bool PositionWindowInScreenCoordinates(aura::Window* window) { bool PositionWindowInScreenCoordinates(aura::Window* window) {
if (window->type() == ui::wm::WINDOW_TYPE_POPUP) if (window->type() == ui::wm::WINDOW_TYPE_POPUP)
return true; return true;
...@@ -36,7 +24,7 @@ bool PositionWindowInScreenCoordinates(aura::Window* window) { ...@@ -36,7 +24,7 @@ bool PositionWindowInScreenCoordinates(aura::Window* window) {
DesktopScreenPositionClient::DesktopScreenPositionClient( DesktopScreenPositionClient::DesktopScreenPositionClient(
aura::Window* root_window) aura::Window* root_window)
: root_window_(root_window) { : wm::DefaultScreenPositionClient(), root_window_(root_window) {
aura::client::SetScreenPositionClient(root_window_, this); aura::client::SetScreenPositionClient(root_window_, this);
} }
...@@ -44,34 +32,10 @@ DesktopScreenPositionClient::~DesktopScreenPositionClient() { ...@@ -44,34 +32,10 @@ DesktopScreenPositionClient::~DesktopScreenPositionClient() {
aura::client::SetScreenPositionClient(root_window_, NULL); aura::client::SetScreenPositionClient(root_window_, NULL);
} }
void DesktopScreenPositionClient::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 DesktopScreenPositionClient::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 DesktopScreenPositionClient::ConvertHostPointToScreen(aura::Window* window,
gfx::Point* point) {
aura::Window* root_window = window->GetRootWindow();
ConvertPointToScreen(root_window, point);
}
void DesktopScreenPositionClient::SetBounds(aura::Window* window, void DesktopScreenPositionClient::SetBounds(aura::Window* window,
const gfx::Rect& bounds, const gfx::Rect& bounds,
const gfx::Display& display) { const gfx::Display& display) {
// TODO: Use the 3rd parameter, |display|. // TODO(jam): Use the 3rd parameter, |display|.
aura::Window* root = window->GetRootWindow(); aura::Window* root = window->GetRootWindow();
// This method assumes that |window| does not have an associated // This method assumes that |window| does not have an associated
...@@ -89,7 +53,7 @@ void DesktopScreenPositionClient::SetBounds(aura::Window* window, ...@@ -89,7 +53,7 @@ void DesktopScreenPositionClient::SetBounds(aura::Window* window,
gfx::Point origin = bounds.origin(); gfx::Point origin = bounds.origin();
aura::Window::ConvertPointToTarget(window->parent(), root, &origin); aura::Window::ConvertPointToTarget(window->parent(), root, &origin);
gfx::Point host_origin = GetOrigin(root); gfx::Point host_origin = GetOriginInScreen(root);
origin.Offset(-host_origin.x(), -host_origin.y()); origin.Offset(-host_origin.x(), -host_origin.y());
window->SetBounds(gfx::Rect(origin, bounds.size())); window->SetBounds(gfx::Rect(origin, bounds.size()));
return; return;
......
...@@ -5,26 +5,20 @@ ...@@ -5,26 +5,20 @@
#ifndef UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_SCREEN_POSITION_CLIENT_H_ #ifndef UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_SCREEN_POSITION_CLIENT_H_
#define UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_SCREEN_POSITION_CLIENT_H_ #define UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_SCREEN_POSITION_CLIENT_H_
#include "ui/aura/client/screen_position_client.h"
#include "ui/views/views_export.h" #include "ui/views/views_export.h"
#include "ui/wm/core/default_screen_position_client.h"
namespace views { namespace views {
// Client that always offsets by the toplevel RootWindow of the passed // Client that always offsets by the toplevel RootWindow of the passed
// in child NativeWidgetAura. // in child NativeWidgetAura.
class VIEWS_EXPORT DesktopScreenPositionClient class VIEWS_EXPORT DesktopScreenPositionClient
: public aura::client::ScreenPositionClient { : public wm::DefaultScreenPositionClient {
public: public:
explicit DesktopScreenPositionClient(aura::Window* root_window); explicit DesktopScreenPositionClient(aura::Window* root_window);
~DesktopScreenPositionClient() override; ~DesktopScreenPositionClient() override;
// aura::client::ScreenPositionClient overrides: // aura::client::DefaultScreenPositionClient:
void ConvertPointToScreen(const aura::Window* window,
gfx::Point* point) override;
void ConvertPointFromScreen(const aura::Window* window,
gfx::Point* point) override;
void ConvertHostPointToScreen(aura::Window* window,
gfx::Point* point) override;
void SetBounds(aura::Window* window, void SetBounds(aura::Window* window,
const gfx::Rect& bounds, const gfx::Rect& bounds,
const gfx::Display& display) override; const gfx::Display& display) override;
......
...@@ -19,6 +19,8 @@ component("wm") { ...@@ -19,6 +19,8 @@ component("wm") {
"core/cursor_manager.h", "core/cursor_manager.h",
"core/default_activation_client.cc", "core/default_activation_client.cc",
"core/default_activation_client.h", "core/default_activation_client.h",
"core/default_screen_position_client.cc",
"core/default_screen_position_client.h",
"core/easy_resize_window_targeter.cc", "core/easy_resize_window_targeter.cc",
"core/easy_resize_window_targeter.h", "core/easy_resize_window_targeter.h",
"core/focus_controller.cc", "core/focus_controller.cc",
......
// Copyright 2014 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::GetOriginInScreen(
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.0f / 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 = GetOriginInScreen(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 = GetOriginInScreen(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
// Copyright 2014 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.
#ifndef UI_WM_CORE_DEFAULT_SCREEN_POSITION_CLIENT_H_
#define UI_WM_CORE_DEFAULT_SCREEN_POSITION_CLIENT_H_
#include "ui/aura/client/screen_position_client.h"
#include "ui/wm/wm_export.h"
namespace wm {
// Client that always offsets by the toplevel RootWindow of the passed
// in child NativeWidgetAura.
class WM_EXPORT DefaultScreenPositionClient
: public aura::client::ScreenPositionClient {
public:
DefaultScreenPositionClient();
~DefaultScreenPositionClient() override;
// aura::client::ScreenPositionClient overrides:
void ConvertPointToScreen(const aura::Window* window,
gfx::Point* point) override;
void ConvertPointFromScreen(const aura::Window* window,
gfx::Point* point) override;
void ConvertHostPointToScreen(aura::Window* window,
gfx::Point* point) override;
void SetBounds(aura::Window* window,
const gfx::Rect& bounds,
const gfx::Display& display) override;
protected:
// Returns the origin of the host platform-window in system pixel coordinates.
gfx::Point GetOriginInScreen(const aura::Window* root_window);
private:
DISALLOW_COPY_AND_ASSIGN(DefaultScreenPositionClient);
};
} // namespace wm
#endif // UI_WM_CORE_DEFAULT_SCREEN_POSITION_CLIENT_H_
...@@ -45,6 +45,8 @@ ...@@ -45,6 +45,8 @@
'core/cursor_manager.h', 'core/cursor_manager.h',
'core/default_activation_client.cc', 'core/default_activation_client.cc',
'core/default_activation_client.h', 'core/default_activation_client.h',
'core/default_screen_position_client.cc',
'core/default_screen_position_client.h',
'core/easy_resize_window_targeter.cc', 'core/easy_resize_window_targeter.cc',
'core/easy_resize_window_targeter.h', 'core/easy_resize_window_targeter.h',
'core/focus_controller.cc', 'core/focus_controller.cc',
......
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