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: ScreenAndroid()16 ScreenAndroid() {} 17 IsDIPEnabled()18 virtual bool IsDIPEnabled() OVERRIDE { return true; } 19 GetCursorScreenPoint()20 virtual gfx::Point GetCursorScreenPoint() OVERRIDE { return gfx::Point(); } 21 GetWindowUnderCursor()22 virtual gfx::NativeWindow GetWindowUnderCursor() OVERRIDE { 23 NOTIMPLEMENTED(); 24 return NULL; 25 } 26 GetWindowAtScreenPoint(const gfx::Point & point)27 virtual gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) 28 OVERRIDE { 29 NOTIMPLEMENTED(); 30 return NULL; 31 } 32 GetPrimaryDisplay() const33 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 = 37 gfx::Rect( 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()); 47 return display; 48 } 49 GetDisplayNearestWindow(gfx::NativeView view) const50 virtual gfx::Display GetDisplayNearestWindow( 51 gfx::NativeView view) const OVERRIDE { 52 return GetPrimaryDisplay(); 53 } 54 GetDisplayNearestPoint(const gfx::Point & point) const55 virtual gfx::Display GetDisplayNearestPoint( 56 const gfx::Point& point) const OVERRIDE { 57 return GetPrimaryDisplay(); 58 } 59 GetNumDisplays() const60 virtual int GetNumDisplays() const OVERRIDE { return 1; } 61 GetAllDisplays() const62 virtual std::vector<gfx::Display> GetAllDisplays() const OVERRIDE { 63 return std::vector<gfx::Display>(1, GetPrimaryDisplay()); 64 } 65 GetDisplayMatching(const gfx::Rect & match_rect) const66 virtual gfx::Display GetDisplayMatching( 67 const gfx::Rect& match_rect) const OVERRIDE { 68 return GetPrimaryDisplay(); 69 } 70 AddObserver(DisplayObserver * observer)71 virtual void AddObserver(DisplayObserver* observer) OVERRIDE { 72 // no display change on Android. 73 } 74 RemoveObserver(DisplayObserver * observer)75 virtual void RemoveObserver(DisplayObserver* observer) OVERRIDE { 76 // no display change on Android. 77 } 78 79 private: 80 DISALLOW_COPY_AND_ASSIGN(ScreenAndroid); 81 }; 82 CreateNativeScreen()83Screen* CreateNativeScreen() { 84 return new ScreenAndroid; 85 } 86 87 } // namespace gfx 88