Don't crash when SimpleCache index is corrupt.
[chromium-blink-merge.git] / ui / gfx / screen.h
blob9410d028889bb4cadaafa37039159030171acc17
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 #ifndef UI_GFX_SCREEN_H_
6 #define UI_GFX_SCREEN_H_
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"
15 namespace gfx {
16 class DisplayObserver;
17 class Rect;
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);
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();
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);
35 // Returns the global screen for a particular type. Types other than _NATIVE
36 // may be NULL.
37 static Screen* GetScreenByType(ScreenType type);
39 // Sets the global ScreenTypeDelegate. May be left unset if the platform
40 // uses only the _NATIVE ScreenType.
41 static void SetScreenTypeDelegate(ScreenTypeDelegate* delegate);
43 Screen();
44 virtual ~Screen();
46 // Returns true if DIP is enabled.
47 virtual bool IsDIPEnabled() = 0;
49 // Returns the current absolute position of the mouse pointer.
50 virtual gfx::Point GetCursorScreenPoint() = 0;
52 // Returns the window under the cursor.
53 virtual gfx::NativeWindow GetWindowAtCursorScreenPoint() = 0;
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;
60 // Returns the display nearest the specified window.
61 virtual gfx::Display GetDisplayNearestWindow(NativeView view) const = 0;
63 // Returns the the display nearest the specified point.
64 virtual gfx::Display GetDisplayNearestPoint(
65 const gfx::Point& point) const = 0;
67 // Returns the display that most closely intersects the provided bounds.
68 virtual gfx::Display GetDisplayMatching(
69 const gfx::Rect& match_rect) const = 0;
71 // Returns the primary display.
72 virtual gfx::Display GetPrimaryDisplay() const = 0;
74 // Adds/Removes display observers.
75 virtual void AddObserver(DisplayObserver* observer) = 0;
76 virtual void RemoveObserver(DisplayObserver* observer) = 0;
78 private:
79 DISALLOW_COPY_AND_ASSIGN(Screen);
82 Screen* CreateNativeScreen();
84 } // namespace gfx
86 #endif // UI_GFX_SCREEN_H_