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 // Note: GetPhysicalDisplayWidth/Height() does not subtract window
37 // decorations etc. Use it instead of GetDisplayWidth/Height() when
39 const gfx::Rect bounds_in_pixels
=
40 gfx::Rect(device_info
.GetPhysicalDisplayWidth()
41 ? device_info
.GetPhysicalDisplayWidth()
42 : device_info
.GetDisplayWidth(),
43 device_info
.GetPhysicalDisplayHeight()
44 ? device_info
.GetPhysicalDisplayHeight()
45 : device_info
.GetDisplayHeight());
46 const gfx::Rect bounds_in_dip
=
47 gfx::Rect(gfx::ToCeiledSize(gfx::ScaleSize(
48 bounds_in_pixels
.size(), 1.0f
/ device_scale_factor
)));
49 gfx::Display
display(0, bounds_in_dip
);
50 if (!gfx::Display::HasForceDeviceScaleFactor())
51 display
.set_device_scale_factor(device_scale_factor
);
52 display
.SetRotationAsDegree(device_info
.GetRotationDegrees());
56 virtual gfx::Display
GetDisplayNearestWindow(
57 gfx::NativeView view
) const OVERRIDE
{
58 return GetPrimaryDisplay();
61 virtual gfx::Display
GetDisplayNearestPoint(
62 const gfx::Point
& point
) const OVERRIDE
{
63 return GetPrimaryDisplay();
66 virtual int GetNumDisplays() const OVERRIDE
{ return 1; }
68 virtual std::vector
<gfx::Display
> GetAllDisplays() const OVERRIDE
{
69 return std::vector
<gfx::Display
>(1, GetPrimaryDisplay());
72 virtual gfx::Display
GetDisplayMatching(
73 const gfx::Rect
& match_rect
) const OVERRIDE
{
74 return GetPrimaryDisplay();
77 virtual void AddObserver(DisplayObserver
* observer
) OVERRIDE
{
78 // no display change on Android.
81 virtual void RemoveObserver(DisplayObserver
* observer
) OVERRIDE
{
82 // no display change on Android.
86 DISALLOW_COPY_AND_ASSIGN(ScreenAndroid
);
89 Screen
* CreateNativeScreen() {
90 return new ScreenAndroid
;