Home | History | Annotate | Download | only in gfx
      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 
     12 namespace {
     13 
     14 class 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 GetWindowAtCursorScreenPoint() OVERRIDE {
     25     NOTIMPLEMENTED();
     26     return gfx::NativeWindow();
     27   }
     28 
     29   virtual int GetNumDisplays() OVERRIDE {
     30 #if TARGET_IPHONE_SIMULATOR
     31     // UIScreen does not reliably return correct results on the simulator.
     32     return 1;
     33 #else
     34     return [[UIScreen screens] count];
     35 #endif
     36   }
     37 
     38   // Returns the display nearest the specified window.
     39   virtual gfx::Display GetDisplayNearestWindow(
     40       gfx::NativeView view) const OVERRIDE {
     41     NOTIMPLEMENTED();
     42     return gfx::Display();
     43   }
     44 
     45   // Returns the the display nearest the specified point.
     46   virtual gfx::Display GetDisplayNearestPoint(
     47       const gfx::Point& point) const OVERRIDE {
     48     NOTIMPLEMENTED();
     49     return gfx::Display();
     50   }
     51 
     52   // Returns the display that most closely intersects the provided bounds.
     53   virtual gfx::Display GetDisplayMatching(
     54       const gfx::Rect& match_rect) const OVERRIDE {
     55     NOTIMPLEMENTED();
     56     return gfx::Display();
     57   }
     58 
     59   // Returns the primary display.
     60   virtual gfx::Display GetPrimaryDisplay() const OVERRIDE {
     61     UIScreen* mainScreen = [[UIScreen screens] objectAtIndex:0];
     62     gfx::Display display(0, gfx::Rect(mainScreen.bounds));
     63     display.set_device_scale_factor([mainScreen scale]);
     64     return display;
     65   }
     66 
     67   virtual void AddObserver(gfx::DisplayObserver* observer) OVERRIDE {
     68     // no display change on iOS.
     69   }
     70 
     71   virtual void RemoveObserver(gfx::DisplayObserver* observer) OVERRIDE {
     72     // no display change on iOS.
     73   }
     74 };
     75 
     76 }  // namespace
     77 
     78 namespace gfx {
     79 
     80 Screen* CreateNativeScreen() {
     81   return new ScreenIos;
     82 }
     83 
     84 }  // namespace gfx
     85