Chromium Code Reviews| Index: ui/gfx/win/display_manager.h |
| diff --git a/ui/gfx/win/display_manager.h b/ui/gfx/win/display_manager.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ab9eac71715cb224f37e3ed34eec0c2b0d99c48c |
| --- /dev/null |
| +++ b/ui/gfx/win/display_manager.h |
| @@ -0,0 +1,92 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef UI_GFX_WIN_DISPLAY_MANAGER_H_ |
| +#define UI_GFX_WIN_DISPLAY_MANAGER_H_ |
| + |
| +#include <windows.h> |
| +#include <memory> |
| +#include <vector> |
| + |
| +#include "base/macros.h" |
| +#include "base/memory/singleton.h" |
| +#include "base/observer_list.h" |
| +#include "ui/gfx/display.h" |
| +#include "ui/gfx/gfx_export.h" |
| + |
| +namespace gfx { |
| + |
| +class Point; |
| +class Rect; |
| +class SingletonHwndObserver; |
| + |
| +namespace win { |
| + |
| +class DisplayManagerObserver; |
| +class DisplayInfo; |
| +class ScreenWinDisplay; |
| + |
| +// Holds all of the ScreenWinDisplays available in the system. |
| +// Normally, this means there is a 1:1 correspondence between ScreenWinDisplays |
| +// and HMONITORS. However, in tests, we can't depend on this so we allow |
| +// overrides of system API functions via virtual calls. |
| +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
|
| + public: |
| + static DisplayManager* GetInstance(); |
| + |
| + virtual void Initialize(); |
| + |
| + void AddObserver(DisplayManagerObserver* observer); |
| + void RemoveObserver(DisplayManagerObserver* observer); |
| + |
| + const std::vector<ScreenWinDisplay>& GetScreenWinDisplays(); |
| + |
| + // Returns the ScreenWinDisplay closest to or enclosing |hwnd|. |
| + ScreenWinDisplay GetScreenWinDisplayNearestHWND(HWND hwnd) const; |
| + |
| + // Returns the ScreenWinDisplay closest to or enclosing |screen_rect|. |
| + ScreenWinDisplay GetScreenWinDisplayNearestScreenRect( |
| + const Rect& screen_rect) const; |
| + |
| + // Returns the ScreenWinDisplay closest to or enclosing |screen_point|. |
| + ScreenWinDisplay GetScreenWinDisplayNearestScreenPoint( |
| + const Point& screen_point) const; |
| + |
| + // Returns the ScreenWinDisplay corresponding to the primary monitor. |
| + ScreenWinDisplay GetPrimaryScreenWinDisplay() const; |
| + |
| + // Virtual to support mocking by unit tests. |
| + virtual MONITORINFOEX MonitorInfoFromScreenPoint( |
| + const gfx::Point& screen_point) const; |
| + virtual MONITORINFOEX MonitorInfoFromScreenRect(const gfx::Rect& screen_rect) |
| + const; |
| + virtual MONITORINFOEX MonitorInfoFromWindow(HWND hwnd, DWORD default_options) |
| + const; |
| + virtual HWND GetRootWindow(HWND hwnd) const; |
| + |
| + protected: |
| + friend std::default_delete<DisplayManager>; |
| + |
| + static void SetInstanceForTesting(scoped_ptr<DisplayManager> display_manager); |
| + |
| + DisplayManager(); |
| + virtual ~DisplayManager(); |
| + |
| + void UpdateFromDisplayInfos(const std::vector<DisplayInfo>& display_infos); |
| + |
| + private: |
| + ScreenWinDisplay GetScreenWinDisplay(const MONITORINFOEX& monitor_info) const; |
| + void WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); |
| + |
| + scoped_ptr<gfx::SingletonHwndObserver> singleton_hwnd_observer_; |
| + base::ObserverList<DisplayManagerObserver, true> observer_list_; |
| + std::vector<ScreenWinDisplay> screen_win_displays_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DisplayManager); |
| +}; |
| + |
| +} // namespace win |
| +} // namespace gfx |
| + |
| +#endif // UI_GFX_WIN_DISPLAY_MANAGER_H_ |