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_WIN_H_ | 5 #ifndef UI_GFX_SCREEN_WIN_H_ |
6 #define UI_GFX_SCREEN_WIN_H_ | 6 #define UI_GFX_SCREEN_WIN_H_ |
7 | 7 |
8 #include <windows.h> | 8 #include "base/compiler_specific.h" |
9 | 9 #include "base/gtest_prod_util.h" |
10 #include <vector> | |
11 | |
12 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/scoped_ptr.h" |
13 #include "ui/gfx/display_change_notifier.h" | 12 #include "ui/gfx/display_change_notifier.h" |
14 #include "ui/gfx/gfx_export.h" | 13 #include "ui/gfx/gfx_export.h" |
15 #include "ui/gfx/native_widget_types.h" | |
16 #include "ui/gfx/screen.h" | 14 #include "ui/gfx/screen.h" |
17 #include "ui/gfx/win/singleton_hwnd_observer.h" | 15 #include "ui/gfx/win/singleton_hwnd_observer.h" |
18 | 16 |
19 namespace gfx { | 17 namespace gfx { |
20 | 18 |
21 class Display; | |
22 class Point; | |
23 class Rect; | |
24 | |
25 namespace win { | |
26 | |
27 struct DisplayInfo; | |
28 struct ScreenWinDisplay; | |
29 | |
30 } // namespace win | |
31 | |
32 class GFX_EXPORT ScreenWin : public Screen { | 19 class GFX_EXPORT ScreenWin : public Screen { |
33 public: | 20 public: |
34 ScreenWin(); | 21 ScreenWin(); |
35 ~ScreenWin() override; | 22 ~ScreenWin() override; |
36 | 23 |
37 // Returns the HWND associated with the NativeView. | 24 // Returns the HWND associated with the NativeView. |
38 virtual HWND GetHWNDFromNativeView(NativeView window) const; | 25 virtual HWND GetHWNDFromNativeView(NativeView window) const; |
39 | 26 |
40 // Returns the NativeView associated with the HWND. | 27 // Returns the NativeView associated with the HWND. |
41 virtual NativeWindow GetNativeWindowFromHWND(HWND hwnd) const; | 28 virtual NativeWindow GetNativeWindowFromHWND(HWND hwnd) const; |
42 | 29 |
43 protected: | 30 protected: |
44 // gfx::Screen: | 31 // Overridden from gfx::Screen: |
45 gfx::Point GetCursorScreenPoint() override; | 32 gfx::Point GetCursorScreenPoint() override; |
46 gfx::NativeWindow GetWindowUnderCursor() override; | 33 gfx::NativeWindow GetWindowUnderCursor() override; |
47 gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override; | 34 gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override; |
48 int GetNumDisplays() const override; | 35 int GetNumDisplays() const override; |
49 std::vector<gfx::Display> GetAllDisplays() const override; | 36 std::vector<gfx::Display> GetAllDisplays() const override; |
50 gfx::Display GetDisplayNearestWindow(gfx::NativeView window) const override; | 37 gfx::Display GetDisplayNearestWindow(gfx::NativeView window) const override; |
51 gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const override; | 38 gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const override; |
52 gfx::Display GetDisplayMatching(const gfx::Rect& match_rect) const override; | 39 gfx::Display GetDisplayMatching(const gfx::Rect& match_rect) const override; |
53 gfx::Display GetPrimaryDisplay() const override; | 40 gfx::Display GetPrimaryDisplay() const override; |
54 void AddObserver(DisplayObserver* observer) override; | 41 void AddObserver(DisplayObserver* observer) override; |
55 void RemoveObserver(DisplayObserver* observer) override; | 42 void RemoveObserver(DisplayObserver* observer) override; |
56 | 43 |
57 void UpdateFromDisplayInfos( | 44 private: |
58 const std::vector<const gfx::win::DisplayInfo>& display_infos); | 45 FRIEND_TEST_ALL_PREFIXES(ScreenWinTest, SingleDisplay1x); |
| 46 FRIEND_TEST_ALL_PREFIXES(ScreenWinTest, SingleDisplay2x); |
59 | 47 |
60 // Virtual to support mocking by unit tests. | |
61 virtual void Initialize(); | |
62 virtual MONITORINFOEX MonitorInfoFromScreenPoint( | |
63 const gfx::Point& screen_point) const; | |
64 virtual MONITORINFOEX MonitorInfoFromScreenRect(const gfx::Rect& screen_rect) | |
65 const; | |
66 virtual MONITORINFOEX MonitorInfoFromWindow(HWND hwnd, DWORD default_options) | |
67 const; | |
68 virtual HWND GetRootWindow(HWND hwnd) const; | |
69 | |
70 private: | |
71 void OnWndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); | 48 void OnWndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); |
72 | 49 |
73 // Returns the ScreenWinDisplay closest to or enclosing |hwnd|. | 50 static std::vector<gfx::Display> GetDisplaysForMonitorInfos( |
74 gfx::win::ScreenWinDisplay GetScreenWinDisplayNearestHWND(HWND hwnd) const; | 51 const std::vector<MONITORINFOEX>& monitor_infos); |
75 | |
76 // Returns the ScreenWinDisplay closest to or enclosing |screen_rect|. | |
77 gfx::win::ScreenWinDisplay GetScreenWinDisplayNearestScreenRect( | |
78 const Rect& screen_rect) const; | |
79 | |
80 // Returns the ScreenWinDisplay closest to or enclosing |screen_point|. | |
81 gfx::win::ScreenWinDisplay GetScreenWinDisplayNearestScreenPoint( | |
82 const Point& screen_point) const; | |
83 | |
84 // Returns the ScreenWinDisplay corresponding to the primary monitor. | |
85 gfx::win::ScreenWinDisplay GetPrimaryScreenWinDisplay() const; | |
86 | |
87 gfx::win::ScreenWinDisplay GetScreenWinDisplay( | |
88 const MONITORINFOEX& monitor_info) const; | |
89 | 52 |
90 // Helper implementing the DisplayObserver handling. | 53 // Helper implementing the DisplayObserver handling. |
91 gfx::DisplayChangeNotifier change_notifier_; | 54 gfx::DisplayChangeNotifier change_notifier_; |
92 | 55 |
93 scoped_ptr<SingletonHwndObserver> singleton_hwnd_observer_; | 56 scoped_ptr<SingletonHwndObserver> singleton_hwnd_observer_; |
94 | 57 |
95 // Current list of ScreenWinDisplays. | 58 // Current list of displays. |
96 std::vector<const gfx::win::ScreenWinDisplay> screen_win_displays_; | 59 std::vector<gfx::Display> displays_; |
97 | 60 |
98 DISALLOW_COPY_AND_ASSIGN(ScreenWin); | 61 DISALLOW_COPY_AND_ASSIGN(ScreenWin); |
99 }; | 62 }; |
100 | 63 |
101 } // namespace gfx | 64 } // namespace gfx |
102 | 65 |
103 #endif // UI_GFX_SCREEN_WIN_H_ | 66 #endif // UI_GFX_SCREEN_WIN_H_ |
OLD | NEW |