blob: c286e603f2d8b621662a47f7cce4a0755cbd92a0 [file] [log] [blame]
Craig Stoutf8b40b52015-08-13 11:48:01 -07001// 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 "ui/gfx/android/device_display_info.h"
9#include "ui/gfx/display.h"
10#include "ui/gfx/geometry/size_conversions.h"
11
12namespace gfx {
13
14class ScreenAndroid : public Screen {
15 public:
16 ScreenAndroid() {}
17
18 gfx::Point GetCursorScreenPoint() override { return gfx::Point(); }
19
20 gfx::NativeWindow GetWindowUnderCursor() override {
21 NOTIMPLEMENTED();
22 return NULL;
23 }
24
25 gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override {
26 NOTIMPLEMENTED();
27 return NULL;
28 }
29
30 gfx::Display GetPrimaryDisplay() const override {
31 gfx::DeviceDisplayInfo device_info;
32 const float device_scale_factor = device_info.GetDIPScale();
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 }
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
83Screen* CreateNativeScreen() {
84 return new ScreenAndroid;
85}
86
87} // namespace gfx