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.
5 #include "ui/gfx/screen.h"
7 #import <UIKit/UIKit.h>
9 #include "base/logging.h"
10 #include "ui/gfx/display.h"
14 class ScreenIos : public gfx::Screen {
15 virtual gfx::Point GetCursorScreenPoint() override {
17 return gfx::Point(0, 0);
20 virtual gfx::NativeWindow GetWindowUnderCursor() override {
22 return gfx::NativeWindow();
25 virtual gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point)
28 return gfx::NativeWindow();
31 virtual int GetNumDisplays() const override {
32 #if TARGET_IPHONE_SIMULATOR
33 // UIScreen does not reliably return correct results on the simulator.
36 return [[UIScreen screens] count];
40 virtual std::vector<gfx::Display> GetAllDisplays() const override {
42 return std::vector<gfx::Display>(1, GetPrimaryDisplay());
45 // Returns the display nearest the specified window.
46 virtual gfx::Display GetDisplayNearestWindow(
47 gfx::NativeView view) const override {
49 return gfx::Display();
52 // Returns the the display nearest the specified point.
53 virtual gfx::Display GetDisplayNearestPoint(
54 const gfx::Point& point) const override {
56 return gfx::Display();
59 // Returns the display that most closely intersects the provided bounds.
60 virtual gfx::Display GetDisplayMatching(
61 const gfx::Rect& match_rect) const override {
63 return gfx::Display();
66 // Returns the primary display.
67 virtual gfx::Display GetPrimaryDisplay() const override {
68 UIScreen* mainScreen = [UIScreen mainScreen];
70 gfx::Display display(0, gfx::Rect(mainScreen.bounds));
71 display.set_device_scale_factor([mainScreen scale]);
75 virtual void AddObserver(gfx::DisplayObserver* observer) override {
76 // no display change on iOS.
79 virtual void RemoveObserver(gfx::DisplayObserver* observer) override {
80 // no display change on iOS.
88 Screen* CreateNativeScreen() {