OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
sky
2016/02/24 19:19:08
no (c) and update year.
gsennton
2016/02/25 17:08:04
Done.
| |
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 "base/logging.h" | |
6 #include "base/macros.h" | |
7 #include "ui/android/screen_android.h" | |
8 #include "ui/android/view_android.h" | |
9 #include "ui/android/window_android.h" | |
10 #include "ui/gfx/android/device_display_info.h" | |
11 #include "ui/gfx/display.h" | |
12 | |
13 namespace ui { | |
14 | |
15 namespace { | |
16 | |
17 gfx::Display DisplayFromDeviceDisplayInfo( | |
sky
2016/02/24 19:18:48
If ScreenAndroid only ever returns a single displa
boliu
2016/02/25 05:33:36
Screen implementation would now needs to listen to
gsennton
2016/02/25 17:08:04
Yeah, so at the moment we only support one display
boliu
2016/02/25 18:11:34
Current implementation of ScreenAndroid is just wr
| |
18 const gfx::DeviceDisplayInfo& device_info) { | |
19 const float device_scale_factor = device_info.GetDIPScale(); | |
20 // Note: GetPhysicalDisplayWidth/Height() does not subtract window | |
21 // decorations etc. Use it instead of GetDisplayWidth/Height() when | |
22 // available. | |
23 const gfx::Rect bounds_in_pixels = | |
24 gfx::Rect(device_info.GetPhysicalDisplayWidth() | |
25 ? device_info.GetPhysicalDisplayWidth() | |
26 : device_info.GetDisplayWidth(), | |
27 device_info.GetPhysicalDisplayHeight() | |
28 ? device_info.GetPhysicalDisplayHeight() | |
29 : device_info.GetDisplayHeight()); | |
30 const gfx::Rect bounds_in_dip = gfx::Rect(gfx::ScaleToCeiledSize( | |
31 bounds_in_pixels.size(), 1.0f / device_scale_factor)); | |
32 gfx::Display display(0, bounds_in_dip); | |
33 if (!gfx::Display::HasForceDeviceScaleFactor()) | |
34 display.set_device_scale_factor(device_scale_factor); | |
35 display.SetRotationAsDegree(device_info.GetRotationDegrees()); | |
36 return display; | |
37 } | |
38 | |
39 } // namespace | |
40 | |
41 class ScreenAndroid : public gfx::Screen { | |
42 public: | |
43 ScreenAndroid() {} | |
44 | |
45 gfx::Point GetCursorScreenPoint() override { return gfx::Point(); } | |
46 | |
47 gfx::NativeWindow GetWindowUnderCursor() override { | |
48 NOTIMPLEMENTED(); | |
49 return NULL; | |
sky
2016/02/24 19:18:48
nullptr (here and 54).
gsennton
2016/02/25 17:08:04
Done.
| |
50 } | |
51 | |
52 gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override { | |
53 NOTIMPLEMENTED(); | |
54 return NULL; | |
55 } | |
56 | |
57 gfx::Display GetPrimaryDisplay() const override { | |
58 gfx::DeviceDisplayInfo device_info; | |
59 return DisplayFromDeviceDisplayInfo(device_info); | |
60 } | |
61 | |
62 gfx::Display GetDisplayNearestWindow(gfx::NativeView view) const override { | |
63 if (view) { | |
64 return DisplayFromDeviceDisplayInfo( | |
65 view->GetWindowAndroid()->GetDeviceDisplayInfo()); | |
66 } else { | |
sky
2016/02/24 19:18:48
nit: no else after a return (see style guide).
gsennton
2016/02/25 17:08:04
Done.
| |
67 return GetPrimaryDisplay(); | |
68 } | |
69 } | |
70 | |
71 gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const override { | |
72 return GetPrimaryDisplay(); | |
73 } | |
74 | |
75 int GetNumDisplays() const override { return 1; } | |
76 | |
77 std::vector<gfx::Display> GetAllDisplays() const override { | |
78 return std::vector<gfx::Display>(1, GetPrimaryDisplay()); | |
79 } | |
80 | |
81 gfx::Display GetDisplayMatching(const gfx::Rect& match_rect) const override { | |
82 return GetPrimaryDisplay(); | |
83 } | |
84 | |
85 void AddObserver(gfx::DisplayObserver* observer) override { | |
86 // no display change on Android. | |
87 } | |
88 | |
89 void RemoveObserver(gfx::DisplayObserver* observer) override { | |
90 // no display change on Android. | |
91 } | |
92 | |
93 private: | |
94 DISALLOW_COPY_AND_ASSIGN(ScreenAndroid); | |
95 }; | |
96 | |
97 gfx::Screen* CreateScreenAndroid() { | |
98 return new ScreenAndroid; | |
99 } | |
100 | |
101 } // namespace ui | |
OLD | NEW |