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. 4 5 #include "ui/gfx/screen.h" 6 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" 11 12 namespace gfx { 13 14 class ScreenAndroid : public Screen { 15 public: 16 ScreenAndroid() {} 17 18 virtual bool IsDIPEnabled() OVERRIDE { return true; } 19 20 virtual gfx::Point GetCursorScreenPoint() OVERRIDE { return gfx::Point(); } 21 22 virtual gfx::NativeWindow GetWindowAtCursorScreenPoint() OVERRIDE { 23 NOTIMPLEMENTED(); 24 return NULL; 25 } 26 27 virtual gfx::Display GetPrimaryDisplay() const OVERRIDE { 28 gfx::DeviceDisplayInfo device_info; 29 const float device_scale_factor = device_info.GetDIPScale(); 30 const gfx::Rect bounds_in_pixels = 31 gfx::Rect( 32 device_info.GetDisplayWidth(), 33 device_info.GetDisplayHeight()); 34 const gfx::Rect bounds_in_dip = 35 gfx::Rect(gfx::ToCeiledSize(gfx::ScaleSize( 36 bounds_in_pixels.size(), 1.0f / device_scale_factor))); 37 gfx::Display display(0, bounds_in_dip); 38 if (!gfx::Display::HasForceDeviceScaleFactor()) 39 display.set_device_scale_factor(device_scale_factor); 40 return display; 41 } 42 43 virtual gfx::Display GetDisplayNearestWindow( 44 gfx::NativeView view) const OVERRIDE { 45 return GetPrimaryDisplay(); 46 } 47 48 virtual gfx::Display GetDisplayNearestPoint( 49 const gfx::Point& point) const OVERRIDE { 50 return GetPrimaryDisplay(); 51 } 52 53 virtual int GetNumDisplays() OVERRIDE { return 1; } 54 55 virtual gfx::Display GetDisplayMatching( 56 const gfx::Rect& match_rect) const OVERRIDE { 57 return GetPrimaryDisplay(); 58 } 59 60 virtual void AddObserver(DisplayObserver* observer) OVERRIDE { 61 // no display change on Android. 62 } 63 64 virtual void RemoveObserver(DisplayObserver* observer) OVERRIDE { 65 // no display change on Android. 66 } 67 68 private: 69 DISALLOW_COPY_AND_ASSIGN(ScreenAndroid); 70 }; 71 72 Screen* CreateNativeScreen() { 73 return new ScreenAndroid; 74 } 75 76 } // namespace gfx 77