| 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/android/view_android.h" |
| 9 #include "ui/android/window_android.h" |
| 8 #include "ui/gfx/android/device_display_info.h" | 10 #include "ui/gfx/android/device_display_info.h" |
| 9 #include "ui/gfx/display.h" | 11 #include "ui/gfx/display.h" |
| 10 #include "ui/gfx/geometry/size_conversions.h" | 12 #include "ui/gfx/geometry/size_conversions.h" |
| 11 | 13 |
| 12 namespace gfx { | 14 namespace gfx { |
| 13 | 15 |
| 16 gfx::Display DisplayFromDeviceDisplayInfo( |
| 17 const gfx::DeviceDisplayInfo& device_info) { |
| 18 const float device_scale_factor = device_info.GetDIPScale(); |
| 19 // Note: GetPhysicalDisplayWidth/Height() does not subtract window |
| 20 // decorations etc. Use it instead of GetDisplayWidth/Height() when |
| 21 // available. |
| 22 const gfx::Rect bounds_in_pixels = |
| 23 gfx::Rect(device_info.GetPhysicalDisplayWidth() |
| 24 ? device_info.GetPhysicalDisplayWidth() |
| 25 : device_info.GetDisplayWidth(), |
| 26 device_info.GetPhysicalDisplayHeight() |
| 27 ? device_info.GetPhysicalDisplayHeight() |
| 28 : device_info.GetDisplayHeight()); |
| 29 const gfx::Rect bounds_in_dip = gfx::Rect(gfx::ScaleToCeiledSize( |
| 30 bounds_in_pixels.size(), 1.0f / device_scale_factor)); |
| 31 gfx::Display display(0, bounds_in_dip); |
| 32 if (!gfx::Display::HasForceDeviceScaleFactor()) |
| 33 display.set_device_scale_factor(device_scale_factor); |
| 34 display.SetRotationAsDegree(device_info.GetRotationDegrees()); |
| 35 return display; |
| 36 } |
| 37 |
| 14 class ScreenAndroid : public Screen { | 38 class ScreenAndroid : public Screen { |
| 15 public: | 39 public: |
| 16 ScreenAndroid() {} | 40 ScreenAndroid() {} |
| 17 | 41 |
| 18 gfx::Point GetCursorScreenPoint() override { return gfx::Point(); } | 42 gfx::Point GetCursorScreenPoint() override { return gfx::Point(); } |
| 19 | 43 |
| 20 gfx::NativeWindow GetWindowUnderCursor() override { | 44 gfx::NativeWindow GetWindowUnderCursor() override { |
| 21 NOTIMPLEMENTED(); | 45 NOTIMPLEMENTED(); |
| 22 return NULL; | 46 return NULL; |
| 23 } | 47 } |
| 24 | 48 |
| 25 gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override { | 49 gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override { |
| 26 NOTIMPLEMENTED(); | 50 NOTIMPLEMENTED(); |
| 27 return NULL; | 51 return NULL; |
| 28 } | 52 } |
| 29 | 53 |
| 30 gfx::Display GetPrimaryDisplay() const override { | 54 gfx::Display GetPrimaryDisplay() const override { |
| 31 gfx::DeviceDisplayInfo device_info; | 55 gfx::DeviceDisplayInfo device_info; |
| 32 const float device_scale_factor = device_info.GetDIPScale(); | 56 return DisplayFromDeviceDisplayInfo(device_info); |
| 33 // Note: GetPhysicalDisplayWidth/Height() does not subtract window | |
| 34 // decorations etc. Use it instead of GetDisplayWidth/Height() when | |
| 35 // available. | |
| 36 const gfx::Rect bounds_in_pixels = | |
| 37 gfx::Rect(device_info.GetPhysicalDisplayWidth() | |
| 38 ? device_info.GetPhysicalDisplayWidth() | |
| 39 : device_info.GetDisplayWidth(), | |
| 40 device_info.GetPhysicalDisplayHeight() | |
| 41 ? device_info.GetPhysicalDisplayHeight() | |
| 42 : device_info.GetDisplayHeight()); | |
| 43 const gfx::Rect bounds_in_dip = gfx::Rect(gfx::ScaleToCeiledSize( | |
| 44 bounds_in_pixels.size(), 1.0f / device_scale_factor)); | |
| 45 gfx::Display display(0, bounds_in_dip); | |
| 46 if (!gfx::Display::HasForceDeviceScaleFactor()) | |
| 47 display.set_device_scale_factor(device_scale_factor); | |
| 48 display.SetRotationAsDegree(device_info.GetRotationDegrees()); | |
| 49 return display; | |
| 50 } | 57 } |
| 51 | 58 |
| 52 gfx::Display GetDisplayNearestWindow(gfx::NativeView view) const override { | 59 gfx::Display GetDisplayNearestWindow(gfx::NativeView view) const override { |
| 53 return GetPrimaryDisplay(); | 60 if (view) { |
| 61 return DisplayFromDeviceDisplayInfo( |
| 62 view->GetWindowAndroid()->GetDeviceDisplayInfo()); |
| 63 } else { |
| 64 return GetPrimaryDisplay(); |
| 65 } |
| 54 } | 66 } |
| 55 | 67 |
| 56 gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const override { | 68 gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const override { |
| 57 return GetPrimaryDisplay(); | 69 return GetPrimaryDisplay(); |
| 58 } | 70 } |
| 59 | 71 |
| 60 int GetNumDisplays() const override { return 1; } | 72 int GetNumDisplays() const override { return 1; } |
| 61 | 73 |
| 62 std::vector<gfx::Display> GetAllDisplays() const override { | 74 std::vector<gfx::Display> GetAllDisplays() const override { |
| 63 return std::vector<gfx::Display>(1, GetPrimaryDisplay()); | 75 return std::vector<gfx::Display>(1, GetPrimaryDisplay()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 77 | 89 |
| 78 private: | 90 private: |
| 79 DISALLOW_COPY_AND_ASSIGN(ScreenAndroid); | 91 DISALLOW_COPY_AND_ASSIGN(ScreenAndroid); |
| 80 }; | 92 }; |
| 81 | 93 |
| 82 Screen* CreateNativeScreen() { | 94 Screen* CreateNativeScreen() { |
| 83 return new ScreenAndroid; | 95 return new ScreenAndroid; |
| 84 } | 96 } |
| 85 | 97 |
| 86 } // namespace gfx | 98 } // namespace gfx |
| OLD | NEW |