Skip to content

Commit

Permalink
Move gfx::Display/Screen to display::Display/Screen in aura/events
Browse files Browse the repository at this point in the history
BUG=597761

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

Cr-Commit-Position: refs/heads/master@{#389806}
  • Loading branch information
mitoshima authored and Commit bot committed Apr 26, 2016
1 parent e1f01e9 commit 5245e49
Show file tree
Hide file tree
Showing 44 changed files with 164 additions and 130 deletions.
3 changes: 3 additions & 0 deletions ui/aura/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ component("aura") {
"//ui/base",
"//ui/base/ime",
"//ui/compositor",
"//ui/display",
"//ui/events",
"//ui/events:events_base",
"//ui/events/platform",
Expand Down Expand Up @@ -190,6 +191,7 @@ source_set("test_support") {
"//ui/base:test_support",
"//ui/base/ime",
"//ui/compositor:test_support",
"//ui/display",
"//ui/events",
"//ui/events:events_base",
"//ui/events:test_support",
Expand Down Expand Up @@ -264,6 +266,7 @@ test("aura_unittests") {
"//testing/gtest",
"//ui/base:test_support",
"//ui/compositor:test_support",
"//ui/display:test_support",
"//ui/events:gesture_detection",
"//ui/events:test_support",
"//ui/gfx",
Expand Down
1 change: 1 addition & 0 deletions ui/aura/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ include_rules = [
"+third_party/skia",
"+ui/base",
"+ui/compositor",
"+ui/display",
"+ui/events",
"+ui/gfx",
"+ui/metro_viewer", # TODO(beng): investigate moving remote_root_window_host
Expand Down
1 change: 1 addition & 0 deletions ui/aura/aura.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
'../base/ime/ui_base_ime.gyp:ui_base_ime',
'../base/ui_base.gyp:ui_base',
'../compositor/compositor.gyp:compositor',
'../display/display.gyp:display',
'../events/events.gyp:events',
'../events/events.gyp:events_base',
'../events/platform/events_platform.gyp:events_platform',
Expand Down
6 changes: 5 additions & 1 deletion ui/aura/client/cursor_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ namespace gfx {
class Display;
}

namespace display {
using Display = gfx::Display;
}

namespace ui {
class KeyEvent;
}
Expand Down Expand Up @@ -59,7 +63,7 @@ class AURA_EXPORT CursorClient {
virtual bool IsMouseEventsEnabled() const = 0;

// Sets the display for the cursor.
virtual void SetDisplay(const gfx::Display& display) = 0;
virtual void SetDisplay(const display::Display& display) = 0;

// Locks the cursor change. The cursor type, cursor visibility, and mouse
// events enable state never change as long as lock is held by anyone.
Expand Down
2 changes: 1 addition & 1 deletion ui/aura/client/screen_position_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class AURA_EXPORT ScreenPositionClient {
// for finding out and translating the right coordinates for the |window|.
virtual void SetBounds(Window* window,
const gfx::Rect& bounds,
const gfx::Display& display) = 0;
const display::Display& display) = 0;
};

// Sets/Gets the activation client on the Window.
Expand Down
2 changes: 1 addition & 1 deletion ui/aura/demo/demo_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ int DemoMain() {
env->set_context_factory(context_factory.get());
std::unique_ptr<aura::TestScreen> test_screen(
aura::TestScreen::Create(gfx::Size()));
gfx::Screen::SetScreenInstance(test_screen.get());
display::Screen::SetScreenInstance(test_screen.get());
std::unique_ptr<aura::WindowTreeHost> host(
test_screen->CreateHostForPrimaryDisplay());
std::unique_ptr<DemoWindowTreeClient> window_tree_client(
Expand Down
6 changes: 3 additions & 3 deletions ui/aura/test/aura_test_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "ui/compositor/compositor.h"
#include "ui/compositor/layer_animator.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/gfx/screen.h"
#include "ui/display/screen.h"

#if defined(USE_X11)
#include "ui/aura/window_tree_host_x11.h"
Expand Down Expand Up @@ -93,8 +93,8 @@ void AuraTestHelper::TearDown() {
client::SetFocusClient(root_window(), nullptr);
host_.reset();
ui::GestureRecognizer::Reset();
if (gfx::Screen::GetScreen() == test_screen_.get())
gfx::Screen::SetScreenInstance(nullptr);
if (display::Screen::GetScreen() == test_screen_.get())
display::Screen::SetScreenInstance(nullptr);
test_screen_.reset();

#if defined(USE_X11)
Expand Down
3 changes: 1 addition & 2 deletions ui/aura/test/test_cursor_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ bool TestCursorClient::IsMouseEventsEnabled() const {
return mouse_events_enabled_;
}

void TestCursorClient::SetDisplay(const gfx::Display& display) {
}
void TestCursorClient::SetDisplay(const display::Display& display) {}

void TestCursorClient::LockCursor() {
cursor_lock_count_++;
Expand Down
2 changes: 1 addition & 1 deletion ui/aura/test/test_cursor_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class TestCursorClient : public aura::client::CursorClient {
void EnableMouseEvents() override;
void DisableMouseEvents() override;
bool IsMouseEventsEnabled() const override;
void SetDisplay(const gfx::Display& display) override;
void SetDisplay(const display::Display& display) override;
void LockCursor() override;
void UnlockCursor() override;
bool IsCursorLocked() const override;
Expand Down
38 changes: 19 additions & 19 deletions ui/aura/test/test_screen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
#include "ui/aura/window_event_dispatcher.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/ime/input_method.h"
#include "ui/display/screen.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/size_conversions.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/screen.h"

namespace aura {

namespace {

bool IsRotationPortrait(gfx::Display::Rotation rotation) {
return rotation == gfx::Display::ROTATE_90 ||
rotation == gfx::Display::ROTATE_270;
bool IsRotationPortrait(display::Display::Rotation rotation) {
return rotation == display::Display::ROTATE_90 ||
rotation == display::Display::ROTATE_270;
}

} // namespace
Expand Down Expand Up @@ -56,7 +56,7 @@ void TestScreen::SetDeviceScaleFactor(float device_scale_factor) {
host_->OnHostResized(bounds_in_pixel.size());
}

void TestScreen::SetDisplayRotation(gfx::Display::Rotation rotation) {
void TestScreen::SetDisplayRotation(display::Display::Rotation rotation) {
gfx::Rect bounds_in_pixel(display_.GetSizeInPixel());
gfx::Rect new_bounds(bounds_in_pixel);
if (IsRotationPortrait(rotation) != IsRotationPortrait(display_.rotation())) {
Expand Down Expand Up @@ -84,17 +84,17 @@ void TestScreen::SetWorkAreaInsets(const gfx::Insets& insets) {
gfx::Transform TestScreen::GetRotationTransform() const {
gfx::Transform rotate;
switch (display_.rotation()) {
case gfx::Display::ROTATE_0:
case display::Display::ROTATE_0:
break;
case gfx::Display::ROTATE_90:
case display::Display::ROTATE_90:
rotate.Translate(display_.bounds().height(), 0);
rotate.Rotate(90);
break;
case gfx::Display::ROTATE_270:
case display::Display::ROTATE_270:
rotate.Translate(0, display_.bounds().width());
rotate.Rotate(270);
break;
case gfx::Display::ROTATE_180:
case display::Display::ROTATE_180:
rotate.Translate(display_.bounds().width(),
display_.bounds().height());
rotate.Rotate(180);
Expand Down Expand Up @@ -140,32 +140,32 @@ int TestScreen::GetNumDisplays() const {
return 1;
}

std::vector<gfx::Display> TestScreen::GetAllDisplays() const {
return std::vector<gfx::Display>(1, display_);
std::vector<display::Display> TestScreen::GetAllDisplays() const {
return std::vector<display::Display>(1, display_);
}

gfx::Display TestScreen::GetDisplayNearestWindow(
display::Display TestScreen::GetDisplayNearestWindow(
gfx::NativeWindow window) const {
return display_;
}

gfx::Display TestScreen::GetDisplayNearestPoint(const gfx::Point& point) const {
display::Display TestScreen::GetDisplayNearestPoint(
const gfx::Point& point) const {
return display_;
}

gfx::Display TestScreen::GetDisplayMatching(const gfx::Rect& match_rect) const {
display::Display TestScreen::GetDisplayMatching(
const gfx::Rect& match_rect) const {
return display_;
}

gfx::Display TestScreen::GetPrimaryDisplay() const {
display::Display TestScreen::GetPrimaryDisplay() const {
return display_;
}

void TestScreen::AddObserver(gfx::DisplayObserver* observer) {
}
void TestScreen::AddObserver(display::DisplayObserver* observer) {}

void TestScreen::RemoveObserver(gfx::DisplayObserver* observer) {
}
void TestScreen::RemoveObserver(display::DisplayObserver* observer) {}

TestScreen::TestScreen(const gfx::Rect& screen_bounds)
: host_(NULL),
Expand Down
35 changes: 18 additions & 17 deletions ui/aura/test/test_screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "ui/aura/window_observer.h"
#include "ui/gfx/display.h"
#include "ui/gfx/screen.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"

namespace gfx {
class Insets;
Expand All @@ -21,20 +21,19 @@ namespace aura {
class Window;
class WindowTreeHost;

// A minimal, testing Aura implementation of gfx::Screen.
// A minimal, testing Aura implementation of display::Screen.
// TODO(bruthig): Consider extending gfx::test::TestScreen.
class TestScreen : public gfx::Screen,
public WindowObserver {
class TestScreen : public display::Screen, public WindowObserver {
public:
// Creates a gfx::Screen of the specified size. If no size is specified, then
// creates a 800x600 screen. |size| is in physical pixels.
// Creates a display::Screen of the specified size. If no size is specified,
// then creates a 800x600 screen. |size| is in physical pixels.
static TestScreen* Create(const gfx::Size& size);
~TestScreen() override;

WindowTreeHost* CreateHostForPrimaryDisplay();

void SetDeviceScaleFactor(float device_scale_fator);
void SetDisplayRotation(gfx::Display::Rotation rotation);
void SetDisplayRotation(display::Display::Rotation rotation);
void SetUIScale(float ui_scale);
void SetWorkAreaInsets(const gfx::Insets& insets);

Expand All @@ -48,25 +47,27 @@ class TestScreen : public gfx::Screen,
const gfx::Rect& new_bounds) override;
void OnWindowDestroying(Window* window) override;

// gfx::Screen overrides:
// display::Screen overrides:
gfx::Point GetCursorScreenPoint() override;
gfx::NativeWindow GetWindowUnderCursor() override;
gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override;
int GetNumDisplays() const override;
std::vector<gfx::Display> GetAllDisplays() const override;
gfx::Display GetDisplayNearestWindow(gfx::NativeView view) const override;
gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const override;
gfx::Display GetDisplayMatching(const gfx::Rect& match_rect) const override;
gfx::Display GetPrimaryDisplay() const override;
void AddObserver(gfx::DisplayObserver* observer) override;
void RemoveObserver(gfx::DisplayObserver* observer) override;
std::vector<display::Display> GetAllDisplays() const override;
display::Display GetDisplayNearestWindow(gfx::NativeView view) const override;
display::Display GetDisplayNearestPoint(
const gfx::Point& point) const override;
display::Display GetDisplayMatching(
const gfx::Rect& match_rect) const override;
display::Display GetPrimaryDisplay() const override;
void AddObserver(display::DisplayObserver* observer) override;
void RemoveObserver(display::DisplayObserver* observer) override;

private:
explicit TestScreen(const gfx::Rect& screen_bounds);

aura::WindowTreeHost* host_;

gfx::Display display_;
display::Display display_;

float ui_scale_;

Expand Down
9 changes: 5 additions & 4 deletions ui/aura/window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@
#include "ui/aura/window_tree_host.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/layer.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/events/event_target_iterator.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/path.h"
#include "ui/gfx/scoped_canvas.h"
#include "ui/gfx/screen.h"

namespace aura {

Expand Down Expand Up @@ -67,8 +68,8 @@ class ScopedCursorHider {
if (hid_cursor_) {
client::CursorClient* cursor_client = client::GetCursorClient(window_);
if (cursor_client) {
const gfx::Display& display =
gfx::Screen::GetScreen()->GetDisplayNearestWindow(window_);
const display::Display& display =
display::Screen::GetScreen()->GetDisplayNearestWindow(window_);
cursor_client->SetDisplay(display);
cursor_client->ShowCursor();
}
Expand Down Expand Up @@ -321,7 +322,7 @@ void Window::SetBounds(const gfx::Rect& new_bounds) {
}

void Window::SetBoundsInScreen(const gfx::Rect& new_bounds_in_screen,
const gfx::Display& dst_display) {
const display::Display& dst_display) {
Window* root = GetRootWindow();
if (root) {
aura::client::ScreenPositionClient* screen_position_client =
Expand Down
9 changes: 8 additions & 1 deletion ui/aura/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@

namespace gfx {
class Display;
}

namespace display {
using Display = gfx::Display;
}

namespace gfx {
class Transform;
class Vector2d;
}
Expand Down Expand Up @@ -172,7 +179,7 @@ class AURA_EXPORT Window : public ui::LayerDelegate,
// Changes the bounds of the window in the screen coordintates.
// If present, the window's parent's LayoutManager may adjust the bounds.
void SetBoundsInScreen(const gfx::Rect& new_bounds_in_screen_coords,
const gfx::Display& dst_display);
const display::Display& dst_display);

// Returns the target bounds of the window. If the window's layer is
// not animating, it simply returns the current bounds.
Expand Down
2 changes: 1 addition & 1 deletion ui/aura/window_event_dispatcher_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "ui/aura/window.h"
#include "ui/aura/window_tracker.h"
#include "ui/base/hit_test.h"
#include "ui/display/screen.h"
#include "ui/events/event.h"
#include "ui/events/event_handler.h"
#include "ui/events/event_utils.h"
Expand All @@ -37,7 +38,6 @@
#include "ui/events/test/test_event_handler.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/screen.h"
#include "ui/gfx/transform.h"

namespace aura {
Expand Down
12 changes: 6 additions & 6 deletions ui/aura/window_tree_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@
#include "ui/base/view_prop.h"
#include "ui/compositor/dip_util.h"
#include "ui/compositor/layer.h"
#include "ui/gfx/display.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/point3_f.h"
#include "ui/gfx/geometry/point_conversions.h"
#include "ui/gfx/geometry/size_conversions.h"
#include "ui/gfx/screen.h"

namespace aura {

const char kWindowTreeHostForAcceleratedWidget[] =
"__AURA_WINDOW_TREE_HOST_ACCELERATED_WIDGET__";

float GetDeviceScaleFactorFromDisplay(Window* window) {
gfx::Display display =
gfx::Screen::GetScreen()->GetDisplayNearestWindow(window);
display::Display display =
display::Screen::GetScreen()->GetDisplayNearestWindow(window);
DCHECK(display.is_valid());
return display.device_scale_factor();
}
Expand Down Expand Up @@ -313,8 +313,8 @@ void WindowTreeHost::MoveCursorToInternal(const gfx::Point& root_location,
MoveCursorToNative(host_location);
client::CursorClient* cursor_client = client::GetCursorClient(window());
if (cursor_client) {
const gfx::Display& display =
gfx::Screen::GetScreen()->GetDisplayNearestWindow(window());
const display::Display& display =
display::Screen::GetScreen()->GetDisplayNearestWindow(window());
cursor_client->SetDisplay(display);
}
dispatcher()->OnCursorMovedToRootLocation(root_location);
Expand Down
Loading

0 comments on commit 5245e49

Please sign in to comment.