summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorpkotwicz@chromium.org <pkotwicz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-30 03:19:34 +0000
committerpkotwicz@chromium.org <pkotwicz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-30 03:19:34 +0000
commita18f9e660efaf0200d6a44741b5a98bc5a7a2b80 (patch)
tree884f3fd0508bb748f1b4347856e25a48bd26d02d /ui
parent3fb63aefda36c25de37d1b2cb37defc5d16b91e8 (diff)
downloadchromium_src-a18f9e660efaf0200d6a44741b5a98bc5a7a2b80.zip
chromium_src-a18f9e660efaf0200d6a44741b5a98bc5a7a2b80.tar.gz
chromium_src-a18f9e660efaf0200d6a44741b5a98bc5a7a2b80.tar.bz2
Remove duplicated code by making desktop_screen_win inherit from screen_win
BUG=None Test=None Review URL: https://chromiumcodereview.appspot.com/11269054 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@164823 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/aura/desktop/desktop_screen_win.cc59
-rw-r--r--ui/aura/desktop/desktop_screen_win.h18
-rw-r--r--ui/gfx/screen_win.cc144
-rw-r--r--ui/gfx/screen_win.h45
-rw-r--r--ui/ui.gyp2
5 files changed, 142 insertions, 126 deletions
diff --git a/ui/aura/desktop/desktop_screen_win.cc b/ui/aura/desktop/desktop_screen_win.cc
index 13bd248..a351ec7 100644
--- a/ui/aura/desktop/desktop_screen_win.cc
+++ b/ui/aura/desktop/desktop_screen_win.cc
@@ -40,67 +40,24 @@ DesktopScreenWin::~DesktopScreenWin() {
}
////////////////////////////////////////////////////////////////////////////////
-// DesktopScreenWin, gfx::Screen implementation:
+// DesktopScreenWin, gfx::ScreenWin implementation:
bool DesktopScreenWin::IsDIPEnabled() {
return true;
}
-gfx::Point DesktopScreenWin::GetCursorScreenPoint() {
- POINT pt;
- GetCursorPos(&pt);
- return gfx::Point(pt);
-}
-
-gfx::NativeWindow DesktopScreenWin::GetWindowAtCursorScreenPoint() {
- POINT location;
- gfx::AcceleratedWidget accelerated_widget =
- GetCursorPos(&location) ? WindowFromPoint(location) : NULL;
- RootWindow* window = NULL;
- if (::IsWindow(accelerated_widget))
- window = RootWindow::GetForAcceleratedWidget(accelerated_widget);
- return window;
-}
-
-int DesktopScreenWin::GetNumDisplays() {
- return GetSystemMetrics(SM_CMONITORS);
-}
-
-gfx::Display DesktopScreenWin::GetDisplayNearestWindow(
- gfx::NativeView window) const {
- gfx::AcceleratedWidget accelerated_window =
- window->GetRootWindow()->GetAcceleratedWidget();
- MONITORINFO monitor_info;
- monitor_info.cbSize = sizeof(monitor_info);
- GetMonitorInfo(MonitorFromWindow(accelerated_window,
- MONITOR_DEFAULTTONEAREST),
- &monitor_info);
- return GetDisplay(monitor_info);
-}
-
-gfx::Display DesktopScreenWin::GetDisplayNearestPoint(
- const gfx::Point& point) const {
- POINT initial_loc = { point.x(), point.y() };
- HMONITOR monitor = MonitorFromPoint(initial_loc, MONITOR_DEFAULTTONEAREST);
- MONITORINFO mi = {0};
- mi.cbSize = sizeof(mi);
- if (monitor && GetMonitorInfo(monitor, &mi))
- return GetDisplay(mi);
- return gfx::Display();
-}
-
gfx::Display DesktopScreenWin::GetDisplayMatching(
const gfx::Rect& match_rect) const {
return GetDisplayNearestPoint(match_rect.CenterPoint());
}
-gfx::Display DesktopScreenWin::GetPrimaryDisplay() const {
- MONITORINFO mi = GetMonitorInfoForMonitor(
- MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY));
- gfx::Display display = GetDisplay(mi);
- DCHECK_EQ(GetSystemMetrics(SM_CXSCREEN), display.size().width());
- DCHECK_EQ(GetSystemMetrics(SM_CYSCREEN), display.size().height());
- return display;
+HWND DesktopScreenWin::GetHWNDFromNativeView(gfx::NativeView window) const {
+ return window->GetRootWindow()->GetAcceleratedWidget();
+}
+
+gfx::NativeWindow DesktopScreenWin::GetNativeWindowFromHWND(HWND hwnd) const {
+ return (::IsWindow(hwnd)) ?
+ RootWindow::GetForAcceleratedWidget(hwnd) : NULL;
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/ui/aura/desktop/desktop_screen_win.h b/ui/aura/desktop/desktop_screen_win.h
index 2ec08a9..5ebf886 100644
--- a/ui/aura/desktop/desktop_screen_win.h
+++ b/ui/aura/desktop/desktop_screen_win.h
@@ -6,29 +6,23 @@
#define UI_AURA_DESKTOP_DESKTOP_SCREEN_WIN_H_
#include "ui/aura/aura_export.h"
-#include "ui/gfx/screen.h"
+#include "ui/gfx/screen_win.h"
namespace aura {
-class AURA_EXPORT DesktopScreenWin : public gfx::Screen {
+class AURA_EXPORT DesktopScreenWin : public gfx::ScreenWin {
public:
DesktopScreenWin();
virtual ~DesktopScreenWin();
- // Overridden from gfx::Screen:
+ private:
+ // Overridden from gfx::ScreenWin:
virtual bool IsDIPEnabled() OVERRIDE;
- virtual gfx::Point GetCursorScreenPoint() OVERRIDE;
- virtual gfx::NativeWindow GetWindowAtCursorScreenPoint() OVERRIDE;
- virtual int GetNumDisplays() OVERRIDE;
- virtual gfx::Display GetDisplayNearestWindow(
- gfx::NativeView window) const OVERRIDE;
- virtual gfx::Display GetDisplayNearestPoint(
- const gfx::Point& point) const OVERRIDE;
virtual gfx::Display GetDisplayMatching(
const gfx::Rect& match_rect) const OVERRIDE;
- virtual gfx::Display GetPrimaryDisplay() const OVERRIDE;
+ virtual HWND GetHWNDFromNativeView(gfx::NativeView window) const OVERRIDE;
+ virtual gfx::NativeWindow GetNativeWindowFromHWND(HWND hwnd) const OVERRIDE;
- private:
DISALLOW_COPY_AND_ASSIGN(DesktopScreenWin);
};
diff --git a/ui/gfx/screen_win.cc b/ui/gfx/screen_win.cc
index 58844ac..072f47a 100644
--- a/ui/gfx/screen_win.cc
+++ b/ui/gfx/screen_win.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "ui/gfx/screen.h"
+#include "ui/gfx/screen_win.h"
#include <windows.h>
@@ -25,73 +25,93 @@ gfx::Display GetDisplay(MONITORINFO& monitor_info) {
return display;
}
-class ScreenWin : public gfx::Screen {
- public:
- ScreenWin() {}
-
- bool IsDIPEnabled() OVERRIDE {
- return false;
- }
-
- gfx::Point GetCursorScreenPoint() OVERRIDE {
- POINT pt;
- GetCursorPos(&pt);
- return gfx::Point(pt);
- }
-
- gfx::NativeWindow GetWindowAtCursorScreenPoint() OVERRIDE {
- POINT location;
- return GetCursorPos(&location) ? WindowFromPoint(location) : NULL;
- }
-
- int GetNumDisplays() OVERRIDE {
- return GetSystemMetrics(SM_CMONITORS);
- }
-
- gfx::Display GetDisplayNearestWindow(gfx::NativeView window) const OVERRIDE {
- MONITORINFO monitor_info;
- monitor_info.cbSize = sizeof(monitor_info);
- GetMonitorInfo(MonitorFromWindow(window, MONITOR_DEFAULTTONEAREST),
- &monitor_info);
- return GetDisplay(monitor_info);
- }
-
- gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const OVERRIDE {
- POINT initial_loc = { point.x(), point.y() };
- HMONITOR monitor = MonitorFromPoint(initial_loc, MONITOR_DEFAULTTONEAREST);
- MONITORINFO mi = {0};
- mi.cbSize = sizeof(mi);
- if (monitor && GetMonitorInfo(monitor, &mi))
- return GetDisplay(mi);
- return gfx::Display();
- }
-
- gfx::Display GetDisplayMatching(const gfx::Rect& match_rect) const OVERRIDE {
- RECT other_bounds_rect = match_rect.ToRECT();
- MONITORINFO monitor_info = GetMonitorInfoForMonitor(MonitorFromRect(
- &other_bounds_rect, MONITOR_DEFAULTTONEAREST));
- return GetDisplay(monitor_info);
- }
-
- gfx::Display GetPrimaryDisplay() const OVERRIDE {
- MONITORINFO mi = GetMonitorInfoForMonitor(
- MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY));
- gfx::Display display = GetDisplay(mi);
- DCHECK_EQ(GetSystemMetrics(SM_CXSCREEN), display.size().width());
- DCHECK_EQ(GetSystemMetrics(SM_CYSCREEN), display.size().height());
- return display;
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(ScreenWin);
-};
-
} // namespace
namespace gfx {
+ScreenWin::ScreenWin() {
+}
+
+ScreenWin::~ScreenWin() {
+}
+
+bool ScreenWin::IsDIPEnabled() {
+ return false;
+}
+
+gfx::Point ScreenWin::GetCursorScreenPoint() {
+ POINT pt;
+ GetCursorPos(&pt);
+ return gfx::Point(pt);
+}
+
+gfx::NativeWindow ScreenWin::GetWindowAtCursorScreenPoint() {
+ POINT location;
+ HWND window_hwnd = GetCursorPos(&location) ? WindowFromPoint(location) : NULL;
+ return GetNativeWindowFromHWND(window_hwnd);
+}
+
+int ScreenWin::GetNumDisplays() {
+ return GetSystemMetrics(SM_CMONITORS);
+}
+
+gfx::Display ScreenWin::GetDisplayNearestWindow(gfx::NativeView window) const {
+ HWND window_hwnd = GetHWNDFromNativeView(window);
+ MONITORINFO monitor_info;
+ monitor_info.cbSize = sizeof(monitor_info);
+ GetMonitorInfo(MonitorFromWindow(window_hwnd, MONITOR_DEFAULTTONEAREST),
+ &monitor_info);
+ return GetDisplay(monitor_info);
+}
+
+gfx::Display ScreenWin::GetDisplayNearestPoint(const gfx::Point& point) const {
+ POINT initial_loc = { point.x(), point.y() };
+ HMONITOR monitor = MonitorFromPoint(initial_loc, MONITOR_DEFAULTTONEAREST);
+ MONITORINFO mi = {0};
+ mi.cbSize = sizeof(mi);
+ if (monitor && GetMonitorInfo(monitor, &mi))
+ return GetDisplay(mi);
+ return gfx::Display();
+}
+
+gfx::Display ScreenWin::GetDisplayMatching(const gfx::Rect& match_rect) const {
+ RECT other_bounds_rect = match_rect.ToRECT();
+ MONITORINFO monitor_info = GetMonitorInfoForMonitor(MonitorFromRect(
+ &other_bounds_rect, MONITOR_DEFAULTTONEAREST));
+ return GetDisplay(monitor_info);
+}
+
+gfx::Display ScreenWin::GetPrimaryDisplay() const {
+ MONITORINFO mi = GetMonitorInfoForMonitor(
+ MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY));
+ gfx::Display display = GetDisplay(mi);
+ DCHECK_EQ(GetSystemMetrics(SM_CXSCREEN), display.size().width());
+ DCHECK_EQ(GetSystemMetrics(SM_CYSCREEN), display.size().height());
+ return display;
+}
+
+HWND ScreenWin::GetHWNDFromNativeView(NativeView window) const {
+#if defined(USE_AURA)
+ NOTREACHED();
+ return NULL;
+#else
+ return window;
+#endif // USE_AURA
+}
+
+NativeWindow ScreenWin::GetNativeWindowFromHWND(HWND hwnd) const {
+#if defined(USE_AURA)
+ NOTREACHED();
+ return NULL;
+#else
+ return hwnd;
+#endif // USE_AURA
+}
+
+#if !defined(USE_AURA)
Screen* CreateNativeScreen() {
return new ScreenWin;
}
+#endif // !USE_AURA
} // namespace gfx
diff --git a/ui/gfx/screen_win.h b/ui/gfx/screen_win.h
new file mode 100644
index 0000000..7cfc265
--- /dev/null
+++ b/ui/gfx/screen_win.h
@@ -0,0 +1,45 @@
+// Copyright (c) 2012 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_SCREEN_WIN_H_
+#define UI_GFX_SCREEN_WIN_H_
+
+#include "base/compiler_specific.h"
+#include "ui/base/ui_export.h"
+#include "ui/gfx/screen.h"
+
+namespace gfx {
+
+class UI_EXPORT ScreenWin : public gfx::Screen {
+ public:
+ ScreenWin();
+ virtual ~ScreenWin();
+
+ protected:
+ // Overridden from gfx::Screen:
+ virtual bool IsDIPEnabled() OVERRIDE;
+ virtual gfx::Point GetCursorScreenPoint() OVERRIDE;
+ virtual gfx::NativeWindow GetWindowAtCursorScreenPoint() OVERRIDE;
+ virtual int GetNumDisplays() OVERRIDE;
+ virtual gfx::Display GetDisplayNearestWindow(
+ gfx::NativeView window) const OVERRIDE;
+ virtual gfx::Display GetDisplayNearestPoint(
+ const gfx::Point& point) const OVERRIDE;
+ virtual gfx::Display GetDisplayMatching(
+ const gfx::Rect& match_rect) const OVERRIDE;
+ virtual gfx::Display GetPrimaryDisplay() const OVERRIDE;
+
+ // Returns the HWND associated with the NativeView.
+ virtual HWND GetHWNDFromNativeView(NativeView window) const;
+
+ // Returns the NativeView associated with the HWND.
+ virtual NativeWindow GetNativeWindowFromHWND(HWND hwnd) const;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ScreenWin);
+};
+
+} // namespace gfx
+
+#endif // UI_GFX_SCREEN_WIN_H_
diff --git a/ui/ui.gyp b/ui/ui.gyp
index a62a275..2fcaaca 100644
--- a/ui/ui.gyp
+++ b/ui/ui.gyp
@@ -479,6 +479,7 @@
'gfx/screen_ios.mm',
'gfx/screen_mac.mm',
'gfx/screen_win.cc',
+ 'gfx/screen_win.h',
'gfx/scrollbar_size.cc',
'gfx/scrollbar_size.h',
'gfx/selection_model.cc',
@@ -570,7 +571,6 @@
['exclude', 'gfx/gtk_util.cc'],
['exclude', 'gfx/gtk_util.h'],
['exclude', 'gfx/screen_gtk.cc'],
- ['exclude', 'gfx/screen_win.cc'],
['exclude', 'base/dialogs/select_file_dialog_mac.mm'],
['exclude', 'base/dialogs/select_file_dialog_win.cc'],
['exclude', 'base/dragdrop/drag_utils_win.cc'],