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