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