| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef UI_GFX_SCREEN_H_ | 5 #ifndef UI_GFX_SCREEN_H_ |
| 6 #define UI_GFX_SCREEN_H_ | 6 #define UI_GFX_SCREEN_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "ui/gfx/native_widget_types.h" | 9 #include "ui/gfx/native_widget_types.h" |
| 10 #include "ui/gfx/point.h" | 10 #include "ui/gfx/point.h" |
| 11 #include "ui/gfx/rect.h" | 11 #include "ui/gfx/rect.h" |
| 12 #include "ui/gfx/size.h" | |
| 13 | 12 |
| 14 namespace gfx { | 13 namespace gfx { |
| 15 | 14 |
| 15 class Monitor; |
| 16 class MonitorObserver; |
| 17 class ScreenImpl; |
| 18 |
| 16 // A utility class for getting various info about screen size, monitors, | 19 // A utility class for getting various info about screen size, monitors, |
| 17 // cursor position, etc. | 20 // cursor position, etc. The monitor object returned by Screen's method |
| 18 // TODO(erikkay) add more of those methods here | 21 // is valid only until the next |GetMonitorXXX| method is called. |
| 22 // TODO(oshima): Implment monitor observers on other platforms and |
| 23 // remove above restruction. See crbug.com/122863 for details. |
| 19 class UI_EXPORT Screen { | 24 class UI_EXPORT Screen { |
| 20 public: | 25 public: |
| 21 virtual ~Screen() {} | 26 virtual ~Screen() {} |
| 22 | 27 |
| 23 #if defined(USE_ASH) | 28 #if defined(USE_AURA) |
| 24 // Sets the instance to use. This takes owernship of |screen|, deleting the | 29 // Sets the instance to use. This takes owernship of |screen|, deleting the |
| 25 // old instance. This is used on aura to avoid circular dependencies between | 30 // old instance. This is used on aura to avoid circular dependencies between |
| 26 // ui and aura. | 31 // ui and aura. |
| 27 static void SetInstance(Screen* screen); | 32 static void SetInstance(ScreenImpl* screen); |
| 28 #endif | 33 #endif |
| 29 | 34 |
| 35 static void AddMonitorObserver(MonitorObserver* observer); |
| 36 static void RemoveMonitorObserver(MonitorObserver* observer); |
| 37 |
| 30 // Returns the current absolute position of the mouse pointer. | 38 // Returns the current absolute position of the mouse pointer. |
| 31 static gfx::Point GetCursorScreenPoint(); | 39 static gfx::Point GetCursorScreenPoint(); |
| 32 | 40 |
| 33 // Returns the work area of the monitor nearest the specified window. | |
| 34 static gfx::Rect GetMonitorWorkAreaNearestWindow(gfx::NativeView view); | |
| 35 | |
| 36 // Returns the bounds of the monitor nearest the specified window. | |
| 37 static gfx::Rect GetMonitorAreaNearestWindow(gfx::NativeView view); | |
| 38 | |
| 39 // Returns the work area of the monitor nearest the specified point. | |
| 40 static gfx::Rect GetMonitorWorkAreaNearestPoint(const gfx::Point& point); | |
| 41 | |
| 42 // Returns the monitor area (not the work area, but the complete bounds) of | |
| 43 // the monitor nearest the specified point. | |
| 44 static gfx::Rect GetMonitorAreaNearestPoint(const gfx::Point& point); | |
| 45 | |
| 46 // Returns the bounds of the work area of the primary monitor. | |
| 47 static gfx::Rect GetPrimaryMonitorWorkArea(); | |
| 48 | |
| 49 // Returns the bounds of the primary monitor. | |
| 50 static gfx::Rect GetPrimaryMonitorBounds(); | |
| 51 | |
| 52 // Returns the bounds of the work area of the monitor that most closely | |
| 53 // intersects the provided bounds. | |
| 54 static gfx::Rect GetMonitorWorkAreaMatching( | |
| 55 const gfx::Rect& match_rect); | |
| 56 | |
| 57 // Returns the window under the cursor. | 41 // Returns the window under the cursor. |
| 58 static gfx::NativeWindow GetWindowAtCursorScreenPoint(); | 42 static gfx::NativeWindow GetWindowAtCursorScreenPoint(); |
| 59 | 43 |
| 60 // Returns the dimensions of the primary monitor in pixels. | |
| 61 static gfx::Size GetPrimaryMonitorSize(); | |
| 62 | |
| 63 // Returns the number of monitors. | 44 // Returns the number of monitors. |
| 64 // Mirrored displays are excluded; this method is intended to return the | 45 // Mirrored displays are excluded; this method is intended to return the |
| 65 // number of distinct, usable displays. | 46 // number of distinct, usable displays. |
| 66 static int GetNumMonitors(); | 47 static int GetNumMonitors(); |
| 67 | 48 |
| 68 protected: | 49 // Returns the monitor nearest the specified window. See the comment at the |
| 69 virtual gfx::Point GetCursorScreenPointImpl() = 0; | 50 // top regarding the life sycle of |gfx::Monitor| object. |
| 70 virtual gfx::Rect GetMonitorWorkAreaNearestWindowImpl( | 51 static const gfx::Monitor* GetMonitorNearestWindow(gfx::NativeView view); |
| 71 gfx::NativeView view) = 0; | |
| 72 virtual gfx::Rect GetMonitorAreaNearestWindowImpl( | |
| 73 gfx::NativeView view) = 0; | |
| 74 virtual gfx::Rect GetMonitorWorkAreaNearestPointImpl( | |
| 75 const gfx::Point& point) = 0; | |
| 76 virtual gfx::Rect GetMonitorAreaNearestPointImpl(const gfx::Point& point) = 0; | |
| 77 virtual gfx::NativeWindow GetWindowAtCursorScreenPointImpl() = 0; | |
| 78 virtual gfx::Size GetPrimaryMonitorSizeImpl() = 0; | |
| 79 virtual int GetNumMonitorsImpl() = 0; | |
| 80 | 52 |
| 81 private: | 53 // Returns the the monitor nearest the specified point. See the comment at the |
| 82 #if defined(USE_AURA) | 54 // top regarding the life sycle of |gfx::Monitor| object. |
| 83 // The singleton screen instance. Only used on aura. | 55 static const gfx::Monitor* GetMonitorNearestPoint(const gfx::Point& point); |
| 84 static Screen* instance_; | 56 |
| 85 #endif | 57 // Returns the bounds of the work area of the primary monitor. See |
| 58 // the comment at the top regarding the life sycle of |gfx::Monitor| |
| 59 // object. |
| 60 static const gfx::Monitor* GetPrimaryMonitor(); |
| 61 |
| 62 // Returns the monitor that most closely intersects the provided bounds. See |
| 63 // the comment at the top regarding the life sycle of |gfx::Monitor| |
| 64 // object. |
| 65 static const gfx::Monitor* GetMonitorMatching(const gfx::Rect& match_rect); |
| 66 |
| 67 // Utility functions to get Monitor bounds/WorkArea bounds. |
| 68 static gfx::Rect GetMonitorAreaNearestWindow(gfx::NativeView view); |
| 69 static gfx::Rect GetMonitorWorkAreaNearestWindow(gfx::NativeView view); |
| 70 static gfx::Rect GetMonitorAreaNearestPoint(const gfx::Point& point); |
| 71 static gfx::Rect GetMonitorWorkAreaNearestPoint(const gfx::Point& point); |
| 86 }; | 72 }; |
| 87 | 73 |
| 88 } // namespace gfx | 74 } // namespace gfx |
| 89 | 75 |
| 90 #endif // VIEWS_SCREEN_H_ | 76 #endif // VIEWS_SCREEN_H_ |
| OLD | NEW |