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" | |
boliu
2015/07/15 06:38:47
Instead of moving this file, ui/android should jus
| |
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( | |
boliu
2015/07/15 06:38:47
out of scope of this CL, but...
Feels like either
| |
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::ToCeiledSize( | |
30 gfx::ScaleSize(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 = | |
44 gfx::Rect(gfx::ToCeiledSize(gfx::ScaleSize( | |
45 bounds_in_pixels.size(), 1.0f / device_scale_factor))); | |
46 gfx::Display display(0, bounds_in_dip); | |
47 if (!gfx::Display::HasForceDeviceScaleFactor()) | |
48 display.set_device_scale_factor(device_scale_factor); | |
49 display.SetRotationAsDegree(device_info.GetRotationDegrees()); | |
50 return display; | |
51 } | 57 } |
52 | 58 |
53 gfx::Display GetDisplayNearestWindow(gfx::NativeView view) const override { | 59 gfx::Display GetDisplayNearestWindow(gfx::NativeView view) const override { |
54 return GetPrimaryDisplay(); | 60 if (view) { |
61 return DisplayFromDeviceDisplayInfo( | |
62 view->GetWindowAndroid()->GetDeviceDisplayInfo()); | |
63 } else { | |
64 return GetPrimaryDisplay(); | |
65 } | |
55 } | 66 } |
56 | 67 |
57 gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const override { | 68 gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const override { |
58 return GetPrimaryDisplay(); | 69 return GetPrimaryDisplay(); |
59 } | 70 } |
60 | 71 |
61 int GetNumDisplays() const override { return 1; } | 72 int GetNumDisplays() const override { return 1; } |
62 | 73 |
63 std::vector<gfx::Display> GetAllDisplays() const override { | 74 std::vector<gfx::Display> GetAllDisplays() const override { |
64 return std::vector<gfx::Display>(1, GetPrimaryDisplay()); | 75 return std::vector<gfx::Display>(1, GetPrimaryDisplay()); |
(...skipping 13 matching lines...) Expand all Loading... | |
78 | 89 |
79 private: | 90 private: |
80 DISALLOW_COPY_AND_ASSIGN(ScreenAndroid); | 91 DISALLOW_COPY_AND_ASSIGN(ScreenAndroid); |
81 }; | 92 }; |
82 | 93 |
83 Screen* CreateNativeScreen() { | 94 Screen* CreateNativeScreen() { |
84 return new ScreenAndroid; | 95 return new ScreenAndroid; |
85 } | 96 } |
86 | 97 |
87 } // namespace gfx | 98 } // namespace gfx |
OLD | NEW |