OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ui/gfx/screen.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "base/macros.h" | |
9 #include "ui/gfx/android/device_display_info.h" | |
10 #include "ui/gfx/display.h" | |
11 #include "ui/gfx/geometry/size_conversions.h" | |
12 | |
13 namespace gfx { | |
14 | |
15 class ScreenAndroid : public Screen { | |
16 public: | |
17 ScreenAndroid() {} | |
18 | |
19 gfx::Point GetCursorScreenPoint() override { return gfx::Point(); } | |
20 | |
21 bool IsWindowUnderCursor(gfx::NativeWindow window) override { | |
22 NOTIMPLEMENTED(); | |
23 return false; | |
24 } | |
25 | |
26 gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override { | |
27 NOTIMPLEMENTED(); | |
28 return NULL; | |
29 } | |
30 | |
31 gfx::Display GetPrimaryDisplay() const override { | |
32 gfx::DeviceDisplayInfo device_info; | |
33 const float device_scale_factor = device_info.GetDIPScale(); | |
34 // Note: GetPhysicalDisplayWidth/Height() does not subtract window | |
35 // decorations etc. Use it instead of GetDisplayWidth/Height() when | |
36 // available. | |
37 const gfx::Rect bounds_in_pixels = | |
38 gfx::Rect(device_info.GetPhysicalDisplayWidth() | |
39 ? device_info.GetPhysicalDisplayWidth() | |
40 : device_info.GetDisplayWidth(), | |
41 device_info.GetPhysicalDisplayHeight() | |
42 ? device_info.GetPhysicalDisplayHeight() | |
43 : device_info.GetDisplayHeight()); | |
44 const gfx::Rect bounds_in_dip = gfx::Rect(gfx::ScaleToCeiledSize( | |
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 } | |
52 | |
53 gfx::Display GetDisplayNearestWindow(gfx::NativeView view) const override { | |
54 return GetPrimaryDisplay(); | |
55 } | |
56 | |
57 gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const override { | |
58 return GetPrimaryDisplay(); | |
59 } | |
60 | |
61 int GetNumDisplays() const override { return 1; } | |
62 | |
63 std::vector<gfx::Display> GetAllDisplays() const override { | |
64 return std::vector<gfx::Display>(1, GetPrimaryDisplay()); | |
65 } | |
66 | |
67 gfx::Display GetDisplayMatching(const gfx::Rect& match_rect) const override { | |
68 return GetPrimaryDisplay(); | |
69 } | |
70 | |
71 void AddObserver(DisplayObserver* observer) override { | |
72 // no display change on Android. | |
73 } | |
74 | |
75 void RemoveObserver(DisplayObserver* observer) override { | |
76 // no display change on Android. | |
77 } | |
78 | |
79 private: | |
80 DISALLOW_COPY_AND_ASSIGN(ScreenAndroid); | |
81 }; | |
82 | |
83 Screen* CreateNativeScreen() { | |
84 return new ScreenAndroid; | |
85 } | |
86 | |
87 } // namespace gfx | |
OLD | NEW |