1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/gfx/screen.h"
7 #include "base/logging.h"
8 #include "ui/gfx/android/device_display_info.h"
9 #include "ui/gfx/display.h"
10 #include "ui/gfx/size_conversions.h"
14 class ScreenAndroid
: public Screen
{
18 virtual bool IsDIPEnabled() OVERRIDE
{ return true; }
20 virtual gfx::Point
GetCursorScreenPoint() OVERRIDE
{ return gfx::Point(); }
22 virtual gfx::NativeWindow
GetWindowUnderCursor() OVERRIDE
{
27 virtual gfx::NativeWindow
GetWindowAtScreenPoint(const gfx::Point
& point
)
33 virtual gfx::Display
GetPrimaryDisplay() const OVERRIDE
{
34 gfx::DeviceDisplayInfo device_info
;
35 const float device_scale_factor
= device_info
.GetDIPScale();
36 const gfx::Rect bounds_in_pixels
=
38 device_info
.GetDisplayWidth(),
39 device_info
.GetDisplayHeight());
40 const gfx::Rect bounds_in_dip
=
41 gfx::Rect(gfx::ToCeiledSize(gfx::ScaleSize(
42 bounds_in_pixels
.size(), 1.0f
/ device_scale_factor
)));
43 gfx::Display
display(0, bounds_in_dip
);
44 if (!gfx::Display::HasForceDeviceScaleFactor())
45 display
.set_device_scale_factor(device_scale_factor
);
46 display
.SetRotationAsDegree(device_info
.GetRotationDegrees());
50 virtual gfx::Display
GetDisplayNearestWindow(
51 gfx::NativeView view
) const OVERRIDE
{
52 return GetPrimaryDisplay();
55 virtual gfx::Display
GetDisplayNearestPoint(
56 const gfx::Point
& point
) const OVERRIDE
{
57 return GetPrimaryDisplay();
60 virtual int GetNumDisplays() const OVERRIDE
{ return 1; }
62 virtual std::vector
<gfx::Display
> GetAllDisplays() const OVERRIDE
{
63 return std::vector
<gfx::Display
>(1, GetPrimaryDisplay());
66 virtual gfx::Display
GetDisplayMatching(
67 const gfx::Rect
& match_rect
) const OVERRIDE
{
68 return GetPrimaryDisplay();
71 virtual void AddObserver(DisplayObserver
* observer
) OVERRIDE
{
72 // no display change on Android.
75 virtual void RemoveObserver(DisplayObserver
* observer
) OVERRIDE
{
76 // no display change on Android.
80 DISALLOW_COPY_AND_ASSIGN(ScreenAndroid
);
83 Screen
* CreateNativeScreen() {
84 return new ScreenAndroid
;