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 bool IsDIPEnabled() OVERRIDE
{
22 gfx::Point
GetCursorScreenPoint() OVERRIDE
{
26 gfx::NativeWindow
GetWindowAtCursorScreenPoint() OVERRIDE
{
31 gfx::Display
GetPrimaryDisplay() const OVERRIDE
{
32 gfx::DeviceDisplayInfo device_info
;
33 const float device_scale_factor
= device_info
.GetDIPScale();
34 const gfx::Rect bounds_in_pixels
=
36 device_info
.GetDisplayWidth(),
37 device_info
.GetDisplayHeight());
38 const gfx::Rect bounds_in_dip
=
39 gfx::Rect(gfx::ToCeiledSize(gfx::ScaleSize(
40 bounds_in_pixels
.size(), 1.0f
/ device_scale_factor
)));
41 gfx::Display
display(0, bounds_in_dip
);
42 display
.set_device_scale_factor(device_scale_factor
);
46 gfx::Display
GetDisplayNearestWindow(gfx::NativeView view
) const OVERRIDE
{
47 return GetPrimaryDisplay();
50 gfx::Display
GetDisplayNearestPoint(const gfx::Point
& point
) const OVERRIDE
{
51 return GetPrimaryDisplay();
54 int GetNumDisplays() OVERRIDE
{
58 virtual gfx::Display
GetDisplayMatching(
59 const gfx::Rect
& match_rect
) const OVERRIDE
{
60 return GetPrimaryDisplay();
63 virtual void AddObserver(DisplayObserver
* observer
) OVERRIDE
{
64 // no display change on Android.
67 virtual void RemoveObserver(DisplayObserver
* observer
) OVERRIDE
{
68 // no display change on Android.
72 DISALLOW_COPY_AND_ASSIGN(ScreenAndroid
);
75 Screen
* CreateNativeScreen() {
76 return new ScreenAndroid
;