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 #ifndef UI_GFX_SCREEN_H_ 6 #define UI_GFX_SCREEN_H_ 7 8 #include "base/basictypes.h" 9 #include "ui/base/ui_export.h" 10 #include "ui/gfx/display.h" 11 #include "ui/gfx/native_widget_types.h" 12 #include "ui/gfx/point.h" 13 #include "ui/gfx/screen_type_delegate.h" 14 15 namespace gfx { 16 class DisplayObserver; 17 class Rect; 18 19 // A utility class for getting various info about screen size, displays, 20 // cursor position, etc. 21 class UI_EXPORT Screen { 22 public: 23 // Retrieves the Screen that the specified NativeView belongs to. A value of 24 // NULL is treated as |SCREEN_TYPE_NATIVE|. 25 static Screen* GetScreenFor(NativeView view); 26 27 // Returns the SCREEN_TYPE_NATIVE Screen. This should be used with caution, 28 // as it is likely to be incorrect for code that runs on Windows. 29 static Screen* GetNativeScreen(); 30 31 // Sets the global screen for a particular screen type. Only the _NATIVE 32 // ScreenType must be provided. 33 static void SetScreenInstance(ScreenType type, Screen* instance); 34 35 // Returns the global screen for a particular type. Types other than _NATIVE 36 // may be NULL. 37 static Screen* GetScreenByType(ScreenType type); 38 39 // Sets the global ScreenTypeDelegate. May be left unset if the platform 40 // uses only the _NATIVE ScreenType. 41 static void SetScreenTypeDelegate(ScreenTypeDelegate* delegate); 42 43 Screen(); 44 virtual ~Screen(); 45 46 // Returns true if DIP is enabled. 47 virtual bool IsDIPEnabled() = 0; 48 49 // Returns the current absolute position of the mouse pointer. 50 virtual gfx::Point GetCursorScreenPoint() = 0; 51 52 // Returns the window under the cursor. 53 virtual gfx::NativeWindow GetWindowAtCursorScreenPoint() = 0; 54 55 // Returns the number of displays. 56 // Mirrored displays are excluded; this method is intended to return the 57 // number of distinct, usable displays. 58 virtual int GetNumDisplays() = 0; 59 60 // Returns the display nearest the specified window. 61 virtual gfx::Display GetDisplayNearestWindow(NativeView view) const = 0; 62 63 // Returns the the display nearest the specified point. 64 virtual gfx::Display GetDisplayNearestPoint( 65 const gfx::Point& point) const = 0; 66 67 // Returns the display that most closely intersects the provided bounds. 68 virtual gfx::Display GetDisplayMatching( 69 const gfx::Rect& match_rect) const = 0; 70 71 // Returns the primary display. 72 virtual gfx::Display GetPrimaryDisplay() const = 0; 73 74 // Adds/Removes display observers. 75 virtual void AddObserver(DisplayObserver* observer) = 0; 76 virtual void RemoveObserver(DisplayObserver* observer) = 0; 77 78 private: 79 DISALLOW_COPY_AND_ASSIGN(Screen); 80 }; 81 82 Screen* CreateNativeScreen(); 83 84 } // namespace gfx 85 86 #endif // UI_GFX_SCREEN_H_ 87