| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/gfx/screen.h" | 5 #include "ui/gfx/screen.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ui/gfx/android/device_display_info.h" | 8 #include "ui/gfx/android/device_display_info.h" |
| 9 #include "ui/gfx/display.h" | 9 #include "ui/gfx/display.h" |
| 10 #include "ui/gfx/geometry/size_conversions.h" | 10 #include "ui/gfx/geometry/size_conversions.h" |
| 11 | 11 |
| 12 namespace gfx { | 12 namespace gfx { |
| 13 | 13 |
| 14 class ScreenAndroid : public Screen { | 14 class ScreenAndroid : public Screen { |
| 15 public: | 15 public: |
| 16 ScreenAndroid() {} | 16 ScreenAndroid() {} |
| 17 | 17 |
| 18 virtual gfx::Point GetCursorScreenPoint() override { return gfx::Point(); } | 18 gfx::Point GetCursorScreenPoint() override { return gfx::Point(); } |
| 19 | 19 |
| 20 virtual gfx::NativeWindow GetWindowUnderCursor() override { | 20 gfx::NativeWindow GetWindowUnderCursor() override { |
| 21 NOTIMPLEMENTED(); | 21 NOTIMPLEMENTED(); |
| 22 return NULL; | 22 return NULL; |
| 23 } | 23 } |
| 24 | 24 |
| 25 virtual gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) | 25 gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override { |
| 26 override { | |
| 27 NOTIMPLEMENTED(); | 26 NOTIMPLEMENTED(); |
| 28 return NULL; | 27 return NULL; |
| 29 } | 28 } |
| 30 | 29 |
| 31 virtual gfx::Display GetPrimaryDisplay() const override { | 30 gfx::Display GetPrimaryDisplay() const override { |
| 32 gfx::DeviceDisplayInfo device_info; | 31 gfx::DeviceDisplayInfo device_info; |
| 33 const float device_scale_factor = device_info.GetDIPScale(); | 32 const float device_scale_factor = device_info.GetDIPScale(); |
| 34 // Note: GetPhysicalDisplayWidth/Height() does not subtract window | 33 // Note: GetPhysicalDisplayWidth/Height() does not subtract window |
| 35 // decorations etc. Use it instead of GetDisplayWidth/Height() when | 34 // decorations etc. Use it instead of GetDisplayWidth/Height() when |
| 36 // available. | 35 // available. |
| 37 const gfx::Rect bounds_in_pixels = | 36 const gfx::Rect bounds_in_pixels = |
| 38 gfx::Rect(device_info.GetPhysicalDisplayWidth() | 37 gfx::Rect(device_info.GetPhysicalDisplayWidth() |
| 39 ? device_info.GetPhysicalDisplayWidth() | 38 ? device_info.GetPhysicalDisplayWidth() |
| 40 : device_info.GetDisplayWidth(), | 39 : device_info.GetDisplayWidth(), |
| 41 device_info.GetPhysicalDisplayHeight() | 40 device_info.GetPhysicalDisplayHeight() |
| 42 ? device_info.GetPhysicalDisplayHeight() | 41 ? device_info.GetPhysicalDisplayHeight() |
| 43 : device_info.GetDisplayHeight()); | 42 : device_info.GetDisplayHeight()); |
| 44 const gfx::Rect bounds_in_dip = | 43 const gfx::Rect bounds_in_dip = |
| 45 gfx::Rect(gfx::ToCeiledSize(gfx::ScaleSize( | 44 gfx::Rect(gfx::ToCeiledSize(gfx::ScaleSize( |
| 46 bounds_in_pixels.size(), 1.0f / device_scale_factor))); | 45 bounds_in_pixels.size(), 1.0f / device_scale_factor))); |
| 47 gfx::Display display(0, bounds_in_dip); | 46 gfx::Display display(0, bounds_in_dip); |
| 48 if (!gfx::Display::HasForceDeviceScaleFactor()) | 47 if (!gfx::Display::HasForceDeviceScaleFactor()) |
| 49 display.set_device_scale_factor(device_scale_factor); | 48 display.set_device_scale_factor(device_scale_factor); |
| 50 display.SetRotationAsDegree(device_info.GetRotationDegrees()); | 49 display.SetRotationAsDegree(device_info.GetRotationDegrees()); |
| 51 return display; | 50 return display; |
| 52 } | 51 } |
| 53 | 52 |
| 54 virtual gfx::Display GetDisplayNearestWindow( | 53 gfx::Display GetDisplayNearestWindow(gfx::NativeView view) const override { |
| 55 gfx::NativeView view) const override { | |
| 56 return GetPrimaryDisplay(); | 54 return GetPrimaryDisplay(); |
| 57 } | 55 } |
| 58 | 56 |
| 59 virtual gfx::Display GetDisplayNearestPoint( | 57 gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const override { |
| 60 const gfx::Point& point) const override { | |
| 61 return GetPrimaryDisplay(); | 58 return GetPrimaryDisplay(); |
| 62 } | 59 } |
| 63 | 60 |
| 64 virtual int GetNumDisplays() const override { return 1; } | 61 int GetNumDisplays() const override { return 1; } |
| 65 | 62 |
| 66 virtual std::vector<gfx::Display> GetAllDisplays() const override { | 63 std::vector<gfx::Display> GetAllDisplays() const override { |
| 67 return std::vector<gfx::Display>(1, GetPrimaryDisplay()); | 64 return std::vector<gfx::Display>(1, GetPrimaryDisplay()); |
| 68 } | 65 } |
| 69 | 66 |
| 70 virtual gfx::Display GetDisplayMatching( | 67 gfx::Display GetDisplayMatching(const gfx::Rect& match_rect) const override { |
| 71 const gfx::Rect& match_rect) const override { | |
| 72 return GetPrimaryDisplay(); | 68 return GetPrimaryDisplay(); |
| 73 } | 69 } |
| 74 | 70 |
| 75 virtual void AddObserver(DisplayObserver* observer) override { | 71 void AddObserver(DisplayObserver* observer) override { |
| 76 // no display change on Android. | 72 // no display change on Android. |
| 77 } | 73 } |
| 78 | 74 |
| 79 virtual void RemoveObserver(DisplayObserver* observer) override { | 75 void RemoveObserver(DisplayObserver* observer) override { |
| 80 // no display change on Android. | 76 // no display change on Android. |
| 81 } | 77 } |
| 82 | 78 |
| 83 private: | 79 private: |
| 84 DISALLOW_COPY_AND_ASSIGN(ScreenAndroid); | 80 DISALLOW_COPY_AND_ASSIGN(ScreenAndroid); |
| 85 }; | 81 }; |
| 86 | 82 |
| 87 Screen* CreateNativeScreen() { | 83 Screen* CreateNativeScreen() { |
| 88 return new ScreenAndroid; | 84 return new ScreenAndroid; |
| 89 } | 85 } |
| 90 | 86 |
| 91 } // namespace gfx | 87 } // namespace gfx |
| OLD | NEW |