Chromium Code Reviews| 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 "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "ui/gfx/display_change_notifier.h" | 10 #include "ui/gfx/display_change_notifier.h" |
| 11 #include "ui/gfx/geometry/point.h" | |
|
sky
2015/10/29 15:51:51
you should be able to forward declare the types.
robliao
2015/11/07 00:56:40
Indeed! Done.
| |
| 12 #include "ui/gfx/geometry/rect.h" | |
| 13 #include "ui/gfx/geometry/size.h" | |
| 11 #include "ui/gfx/gfx_export.h" | 14 #include "ui/gfx/gfx_export.h" |
| 12 #include "ui/gfx/screen.h" | 15 #include "ui/gfx/screen.h" |
| 13 #include "ui/gfx/win/singleton_hwnd_observer.h" | 16 #include "ui/gfx/win/singleton_hwnd_observer.h" |
| 14 | 17 |
| 15 namespace gfx { | 18 namespace gfx { |
| 16 | 19 |
| 17 class GFX_EXPORT ScreenWin : public Screen { | 20 class GFX_EXPORT ScreenWin : public Screen { |
| 18 public: | 21 public: |
| 19 ScreenWin(); | 22 ScreenWin(); |
| 20 ~ScreenWin() override; | 23 ~ScreenWin() override; |
| 21 | 24 |
| 25 // Converts a screen pixel point to a DIP point. | |
| 26 // The DPI scale is performed relative to the display containing the screen | |
| 27 // pixel point maintaining a constant origin on both Screen and DIP (same as | |
| 28 // Windows). | |
| 29 static Point ScreenToDIPPoint(const Point& pixel_point); | |
| 30 | |
| 31 // Converts a DIP point to a screen pixel point. | |
| 32 // The DPI scale is performed relative to the display containing the DIP point | |
| 33 // maintaining a constant origin on both Screen and DIP (same as Windows). | |
| 34 static Point DIPToScreenPoint(const Point& dip_point); | |
| 35 | |
| 36 // Converts a client pixel point relative to |hwnd| to a DIP point. | |
| 37 // The DPI scale is performed relative to |hwnd| using an origin of (0, 0). | |
| 38 static Point ClientToDIPPoint(HWND hwnd, const Point& client_point); | |
|
sky
2015/10/29 15:51:51
What is a client point?
robliao
2015/11/07 00:56:40
It's generally a point in an HWND's coordinate sys
| |
| 39 | |
| 40 // Converts a client DIP point relative to |hwnd| to a client pixel point. | |
| 41 // The DPI scale is performed relative to |hwnd| using an origin of (0, 0). | |
| 42 static Point DIPToClientPoint(HWND hwnd, const Point& dip_point); | |
| 43 | |
| 44 // WARNING: there is no right way to scale sizes and rects. The implementation | |
| 45 // of these strives to maintain a constant size by scaling the size | |
| 46 // independent of the origin. An alternative is to get the enclosing rect, | |
| 47 // which is the right way for some situations. Understand which you need | |
| 48 // before blindly assuming this is the right way. | |
| 49 | |
| 50 // Converts a screen rect to a DIP rect. | |
| 51 // The DPI scale is performed relative to the display nearest to |hwnd| | |
| 52 // maintaining a constant origin on both Screen and DIP (same as Windows). | |
| 53 // If |hwnd| is null, scaling will be performed to the display nearest to | |
| 54 // |pixel_bounds|. | |
| 55 static Rect ScreenToDIPRect(HWND hwnd, const Rect& pixel_bounds); | |
| 56 | |
| 57 // Converts a DIP rect to a screen rect. | |
| 58 // The DPI scale is performed relative to the display nearest to |hwnd| | |
| 59 // maintaining a constant origin on both Screen and DIP (same as Windows). | |
| 60 // If |hwnd| is null, scaling will be performed to the display nearest to | |
| 61 // |dip_bounds|. | |
| 62 static Rect DIPToScreenRect(HWND hwnd, const Rect& dip_bounds); | |
| 63 | |
| 64 // Converts a client rect to a DIP rect. | |
| 65 // The DPI scale is performed relative to |hwnd| using an origin of (0, 0). | |
| 66 static Rect ClientToDIPRect(HWND hwnd, const Rect& pixel_bounds); | |
| 67 | |
| 68 // Converts a DIP rect to a client rect. | |
| 69 // The DPI scale is performed relative to |hwnd| using an origin of (0, 0). | |
| 70 static Rect DIPToClientRect(HWND hwnd, const Rect& dip_bounds); | |
| 71 | |
| 72 // Converts a screen size to a DIP size. | |
| 73 // The DPI scale is performed relative to the display nearest to |hwnd|. | |
| 74 static Size ScreenToDIPSize(HWND hwnd, const Size& size_in_pixels); | |
| 75 | |
| 76 // Converts a DIP size to a screen size. | |
| 77 // The DPI scale is performed relative to the display nearest to |hwnd|. | |
| 78 static Size DIPToScreenSize(HWND hwnd, const Size& dip_size); | |
| 79 | |
| 22 protected: | 80 protected: |
| 23 // Overridden from gfx::Screen: | 81 // Overridden from gfx::Screen: |
| 24 gfx::Point GetCursorScreenPoint() override; | 82 gfx::Point GetCursorScreenPoint() override; |
| 25 gfx::NativeWindow GetWindowUnderCursor() override; | 83 gfx::NativeWindow GetWindowUnderCursor() override; |
| 26 gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override; | 84 gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override; |
| 27 int GetNumDisplays() const override; | 85 int GetNumDisplays() const override; |
| 28 std::vector<gfx::Display> GetAllDisplays() const override; | 86 std::vector<gfx::Display> GetAllDisplays() const override; |
| 29 gfx::Display GetDisplayNearestWindow(gfx::NativeView window) const override; | 87 gfx::Display GetDisplayNearestWindow(gfx::NativeView window) const override; |
| 30 gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const override; | 88 gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const override; |
| 31 gfx::Display GetDisplayMatching(const gfx::Rect& match_rect) const override; | 89 gfx::Display GetDisplayMatching(const gfx::Rect& match_rect) const override; |
| 32 gfx::Display GetPrimaryDisplay() const override; | 90 gfx::Display GetPrimaryDisplay() const override; |
| 33 void AddObserver(DisplayObserver* observer) override; | 91 void AddObserver(DisplayObserver* observer) override; |
| 34 void RemoveObserver(DisplayObserver* observer) override; | 92 void RemoveObserver(DisplayObserver* observer) override; |
| 35 | 93 |
| 36 // Returns the HWND associated with the NativeView. | 94 // Returns the HWND associated with the NativeView. |
| 37 virtual HWND GetHWNDFromNativeView(NativeView window) const; | 95 virtual HWND GetHWNDFromNativeView(NativeView window) const; |
| 38 | 96 |
| 39 // Returns the NativeView associated with the HWND. | 97 // Returns the NativeView associated with the HWND. |
| 40 virtual NativeWindow GetNativeWindowFromHWND(HWND hwnd) const; | 98 virtual NativeWindow GetNativeWindowFromHWND(HWND hwnd) const; |
| 41 | 99 |
| 42 private: | 100 private: |
| 101 static gfx::Display GetDisplayNearestHWND(HWND hwnd); | |
| 102 static gfx::Display GetDisplayNearestRect(const Rect& rect); | |
| 103 static gfx::Display GetDisplayNearestScreenPoint(const Point& screen_point); | |
| 104 static float GetScaleFactorForHWND(HWND hwnd); | |
| 105 static float GetScaleFactorForScreenPoint(const Point& screen_point); | |
| 106 | |
| 43 void OnWndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); | 107 void OnWndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); |
| 44 | 108 |
| 45 // Helper implementing the DisplayObserver handling. | 109 // Helper implementing the DisplayObserver handling. |
| 46 gfx::DisplayChangeNotifier change_notifier_; | 110 gfx::DisplayChangeNotifier change_notifier_; |
| 47 | 111 |
| 48 scoped_ptr<SingletonHwndObserver> singleton_hwnd_observer_; | 112 scoped_ptr<SingletonHwndObserver> singleton_hwnd_observer_; |
| 49 | 113 |
| 50 // Current list of displays. | 114 // Current list of displays. |
| 51 std::vector<gfx::Display> displays_; | 115 std::vector<gfx::Display> displays_; |
| 52 | 116 |
| 53 DISALLOW_COPY_AND_ASSIGN(ScreenWin); | 117 DISALLOW_COPY_AND_ASSIGN(ScreenWin); |
| 54 }; | 118 }; |
| 55 | 119 |
| 56 } // namespace gfx | 120 } // namespace gfx |
| 57 | 121 |
| 58 #endif // UI_GFX_SCREEN_WIN_H_ | 122 #endif // UI_GFX_SCREEN_WIN_H_ |
| OLD | NEW |