Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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_WIN_DISPLAY_MANAGER_H_ | |
| 6 #define UI_GFX_WIN_DISPLAY_MANAGER_H_ | |
| 7 | |
| 8 #include <windows.h> | |
| 9 #include <memory> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/macros.h" | |
| 13 #include "base/memory/singleton.h" | |
| 14 #include "base/observer_list.h" | |
| 15 #include "ui/gfx/display.h" | |
| 16 #include "ui/gfx/gfx_export.h" | |
| 17 | |
| 18 namespace gfx { | |
| 19 | |
| 20 class Point; | |
| 21 class Rect; | |
| 22 class SingletonHwndObserver; | |
| 23 | |
| 24 namespace win { | |
| 25 | |
| 26 class DisplayManagerObserver; | |
| 27 class DisplayInfo; | |
| 28 class ScreenWinDisplay; | |
| 29 | |
| 30 // Holds all of the ScreenWinDisplays available in the system. | |
| 31 // Normally, this means there is a 1:1 correspondence between ScreenWinDisplays | |
| 32 // and HMONITORS. However, in tests, we can't depend on this so we allow | |
| 33 // overrides of system API functions via virtual calls. | |
| 34 class GFX_EXPORT DisplayManager { | |
|
sky
2016/02/02 16:18:20
Why do we need both DisplayManager and ScreenWin?
robliao
2016/02/02 18:08:07
Coming up in a next CL are some static scaling cal
| |
| 35 public: | |
| 36 static DisplayManager* GetInstance(); | |
| 37 | |
| 38 virtual void Initialize(); | |
| 39 | |
| 40 void AddObserver(DisplayManagerObserver* observer); | |
| 41 void RemoveObserver(DisplayManagerObserver* observer); | |
| 42 | |
| 43 const std::vector<ScreenWinDisplay>& GetScreenWinDisplays(); | |
| 44 | |
| 45 // Returns the ScreenWinDisplay closest to or enclosing |hwnd|. | |
| 46 ScreenWinDisplay GetScreenWinDisplayNearestHWND(HWND hwnd) const; | |
| 47 | |
| 48 // Returns the ScreenWinDisplay closest to or enclosing |screen_rect|. | |
| 49 ScreenWinDisplay GetScreenWinDisplayNearestScreenRect( | |
| 50 const Rect& screen_rect) const; | |
| 51 | |
| 52 // Returns the ScreenWinDisplay closest to or enclosing |screen_point|. | |
| 53 ScreenWinDisplay GetScreenWinDisplayNearestScreenPoint( | |
| 54 const Point& screen_point) const; | |
| 55 | |
| 56 // Returns the ScreenWinDisplay corresponding to the primary monitor. | |
| 57 ScreenWinDisplay GetPrimaryScreenWinDisplay() const; | |
| 58 | |
| 59 // Virtual to support mocking by unit tests. | |
| 60 virtual MONITORINFOEX MonitorInfoFromScreenPoint( | |
| 61 const gfx::Point& screen_point) const; | |
| 62 virtual MONITORINFOEX MonitorInfoFromScreenRect(const gfx::Rect& screen_rect) | |
| 63 const; | |
| 64 virtual MONITORINFOEX MonitorInfoFromWindow(HWND hwnd, DWORD default_options) | |
| 65 const; | |
| 66 virtual HWND GetRootWindow(HWND hwnd) const; | |
| 67 | |
| 68 protected: | |
| 69 friend std::default_delete<DisplayManager>; | |
| 70 | |
| 71 static void SetInstanceForTesting(scoped_ptr<DisplayManager> display_manager); | |
| 72 | |
| 73 DisplayManager(); | |
| 74 virtual ~DisplayManager(); | |
| 75 | |
| 76 void UpdateFromDisplayInfos(const std::vector<DisplayInfo>& display_infos); | |
| 77 | |
| 78 private: | |
| 79 ScreenWinDisplay GetScreenWinDisplay(const MONITORINFOEX& monitor_info) const; | |
| 80 void WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); | |
| 81 | |
| 82 scoped_ptr<gfx::SingletonHwndObserver> singleton_hwnd_observer_; | |
| 83 base::ObserverList<DisplayManagerObserver, true> observer_list_; | |
| 84 std::vector<ScreenWinDisplay> screen_win_displays_; | |
| 85 | |
| 86 DISALLOW_COPY_AND_ASSIGN(DisplayManager); | |
| 87 }; | |
| 88 | |
| 89 } // namespace win | |
| 90 } // namespace gfx | |
| 91 | |
| 92 #endif // UI_GFX_WIN_DISPLAY_MANAGER_H_ | |
| OLD | NEW |