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 { |
sadrul
2015/11/03 18:14:27
namespace ui
boliu
2015/12/08 08:21:54
screen_android.h header is still under gfx. This i
Ted C
2015/12/13 00:29:38
I would follow what other files of similar nature
no sievers
2016/02/29 18:16:03
Note that ui/android/java containts java code for
| |
13 | 15 |
16 gfx::Display DisplayFromDeviceDisplayInfo( | |
boliu
2015/12/08 08:21:54
should this be in an anonymous namespace?
gsennton
2015/12/10 12:29:54
Yup, will update in next PS.
gsennton
2015/12/14 18:10:32
Done.
| |
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 = | |
boliu
2015/12/08 08:21:54
existing code but a bit weird, all display on andr
gsennton
2015/12/10 12:29:54
Up until N we haven't been able to move applicatio
boliu
2015/12/10 16:38:20
Think of a desktop with two monitors, each 1000x10
| |
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); |
Ted C
2015/11/05 23:15:58
What is gfx::Display used for? How do they get no
gsennton
2015/11/06 16:52:14
In all of the cases I have seen gfx::Display in us
Ted C
2015/11/25 19:35:52
I must say much of my skepticism is around my lack
gsennton
2015/12/02 15:37:05
So there are two different sizes that can be fetch
Ted C
2015/12/03 04:23:56
I think the "easiest" thing would be to actually n
boliu
2015/12/08 08:21:54
Maybe as an aspirational end goal after all the ot
gsennton
2015/12/10 12:29:54
@Bo now I'm a bit lost here, what would be the asp
boliu
2015/12/10 16:38:20
Tradeoffs.. perf comes after correctness and havin
gsennton
2015/12/14 18:10:32
Alright
| |
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 |