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 "ui/gfx/android/device_display_info.h"
9#include "ui/gfx/display.h"
10#include "ui/gfx/size_conversions.h"
11
12namespace gfx {
13
14class ScreenAndroid : public Screen {
15 public:
16  ScreenAndroid() {}
17
18  virtual bool IsDIPEnabled() OVERRIDE { return true; }
19
20  virtual gfx::Point GetCursorScreenPoint() OVERRIDE { return gfx::Point(); }
21
22  virtual gfx::NativeWindow GetWindowUnderCursor() OVERRIDE {
23    NOTIMPLEMENTED();
24    return NULL;
25  }
26
27  virtual gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point)
28      OVERRIDE {
29    NOTIMPLEMENTED();
30    return NULL;
31  }
32
33  virtual gfx::Display GetPrimaryDisplay() const OVERRIDE {
34    gfx::DeviceDisplayInfo device_info;
35    const float device_scale_factor = device_info.GetDIPScale();
36    const gfx::Rect bounds_in_pixels =
37        gfx::Rect(
38            device_info.GetDisplayWidth(),
39            device_info.GetDisplayHeight());
40    const gfx::Rect bounds_in_dip =
41        gfx::Rect(gfx::ToCeiledSize(gfx::ScaleSize(
42            bounds_in_pixels.size(), 1.0f / device_scale_factor)));
43    gfx::Display display(0, bounds_in_dip);
44    if (!gfx::Display::HasForceDeviceScaleFactor())
45      display.set_device_scale_factor(device_scale_factor);
46    return display;
47  }
48
49  virtual gfx::Display GetDisplayNearestWindow(
50      gfx::NativeView view) const OVERRIDE {
51    return GetPrimaryDisplay();
52  }
53
54  virtual gfx::Display GetDisplayNearestPoint(
55      const gfx::Point& point) const OVERRIDE {
56    return GetPrimaryDisplay();
57  }
58
59  virtual int GetNumDisplays() const OVERRIDE { return 1; }
60
61  virtual std::vector<gfx::Display> GetAllDisplays() const OVERRIDE {
62    return std::vector<gfx::Display>(1, GetPrimaryDisplay());
63  }
64
65  virtual gfx::Display GetDisplayMatching(
66      const gfx::Rect& match_rect) const OVERRIDE {
67    return GetPrimaryDisplay();
68  }
69
70  virtual void AddObserver(DisplayObserver* observer) OVERRIDE {
71    // no display change on Android.
72  }
73
74  virtual void RemoveObserver(DisplayObserver* observer) OVERRIDE {
75    // no display change on Android.
76  }
77
78 private:
79  DISALLOW_COPY_AND_ASSIGN(ScreenAndroid);
80};
81
82Screen* CreateNativeScreen() {
83  return new ScreenAndroid;
84}
85
86}  // namespace gfx
87