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#import <UIKit/UIKit.h>
8
9#include "base/logging.h"
10#include "ui/gfx/display.h"
11
12namespace {
13
14class ScreenIos : public gfx::Screen {
15  virtual bool IsDIPEnabled() OVERRIDE {
16    return true;
17  }
18
19  virtual gfx::Point GetCursorScreenPoint() OVERRIDE {
20    NOTIMPLEMENTED();
21    return gfx::Point(0, 0);
22  }
23
24  virtual gfx::NativeWindow GetWindowUnderCursor() OVERRIDE {
25    NOTIMPLEMENTED();
26    return gfx::NativeWindow();
27  }
28
29  virtual gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point)
30      OVERRIDE {
31    NOTIMPLEMENTED();
32    return gfx::NativeWindow();
33  }
34
35  virtual int GetNumDisplays() const OVERRIDE {
36#if TARGET_IPHONE_SIMULATOR
37    // UIScreen does not reliably return correct results on the simulator.
38    return 1;
39#else
40    return [[UIScreen screens] count];
41#endif
42  }
43
44  virtual std::vector<gfx::Display> GetAllDisplays() const OVERRIDE {
45    NOTIMPLEMENTED();
46    return std::vector<gfx::Display>(1, GetPrimaryDisplay());
47  }
48
49  // Returns the display nearest the specified window.
50  virtual gfx::Display GetDisplayNearestWindow(
51      gfx::NativeView view) const OVERRIDE {
52    NOTIMPLEMENTED();
53    return gfx::Display();
54  }
55
56  // Returns the the display nearest the specified point.
57  virtual gfx::Display GetDisplayNearestPoint(
58      const gfx::Point& point) const OVERRIDE {
59    NOTIMPLEMENTED();
60    return gfx::Display();
61  }
62
63  // Returns the display that most closely intersects the provided bounds.
64  virtual gfx::Display GetDisplayMatching(
65      const gfx::Rect& match_rect) const OVERRIDE {
66    NOTIMPLEMENTED();
67    return gfx::Display();
68  }
69
70  // Returns the primary display.
71  virtual gfx::Display GetPrimaryDisplay() const OVERRIDE {
72    UIScreen* mainScreen = [UIScreen mainScreen];
73    CHECK(mainScreen);
74    gfx::Display display(0, gfx::Rect(mainScreen.bounds));
75    display.set_device_scale_factor([mainScreen scale]);
76    return display;
77  }
78
79  virtual void AddObserver(gfx::DisplayObserver* observer) OVERRIDE {
80    // no display change on iOS.
81  }
82
83  virtual void RemoveObserver(gfx::DisplayObserver* observer) OVERRIDE {
84    // no display change on iOS.
85  }
86};
87
88}  // namespace
89
90namespace gfx {
91
92Screen* CreateNativeScreen() {
93  return new ScreenIos;
94}
95
96}  // namespace gfx
97