summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authoroshima@google.com <oshima@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-22 23:09:32 +0000
committeroshima@google.com <oshima@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-22 23:09:32 +0000
commitd8e6018fb0b2d37104326a5c87b8d50e5ef8fa0e (patch)
treeb0310cc9c6304810256c781dd89a617cc26a5f9f /views
parent2f6f4a6eb6c982ff297f8c468465a64c7716593c (diff)
downloadchromium_src-d8e6018fb0b2d37104326a5c87b8d50e5ef8fa0e.zip
chromium_src-d8e6018fb0b2d37104326a5c87b8d50e5ef8fa0e.tar.gz
chromium_src-d8e6018fb0b2d37104326a5c87b8d50e5ef8fa0e.tar.bz2
Revert 93724
"Move screen.h to ui/gfx because Screen doesn't depend on views, and they're useful outside views." This reverts commit 4b6b4b0a2a3d46f25ffe37d612742aba14c39462. TBR=jcivelli@chromium.org BUG=none TEST=none Review URL: http://codereview.chromium.org/7495019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93733 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/controls/button/custom_button.cc4
-rw-r--r--views/controls/button/menu_button.cc5
-rw-r--r--views/controls/button/native_button.cc6
-rw-r--r--views/controls/menu/menu_controller.cc7
-rw-r--r--views/mouse_watcher.cc6
-rw-r--r--views/screen.h41
-rw-r--r--views/screen_gtk.cc108
-rw-r--r--views/screen_win.cc63
-rw-r--r--views/views.gyp3
-rw-r--r--views/widget/native_widget_gtk.cc4
-rw-r--r--views/widget/native_widget_win.cc4
-rw-r--r--views/widget/tooltip_manager_gtk.cc4
-rw-r--r--views/widget/tooltip_manager_views.cc6
-rw-r--r--views/widget/tooltip_manager_win.cc4
14 files changed, 239 insertions, 26 deletions
diff --git a/views/controls/button/custom_button.cc b/views/controls/button/custom_button.cc
index abeedf3..8e6e09c 100644
--- a/views/controls/button/custom_button.cc
+++ b/views/controls/button/custom_button.cc
@@ -7,7 +7,7 @@
#include "ui/base/accessibility/accessible_view_state.h"
#include "ui/base/animation/throb_animation.h"
#include "ui/base/keycodes/keyboard_codes.h"
-#include "ui/gfx/screen.h"
+#include "views/screen.h"
#include "views/widget/widget.h"
namespace views {
@@ -69,7 +69,7 @@ bool CustomButton::IsMouseHovered() const {
if (!GetWidget())
return false;
- gfx::Point cursor_pos(gfx::Screen::GetCursorScreenPoint());
+ gfx::Point cursor_pos(Screen::GetCursorScreenPoint());
ConvertPointToView(NULL, this, &cursor_pos);
return HitTest(cursor_pos);
}
diff --git a/views/controls/button/menu_button.cc b/views/controls/button/menu_button.cc
index 64f4795..7701d59 100644
--- a/views/controls/button/menu_button.cc
+++ b/views/controls/button/menu_button.cc
@@ -12,10 +12,10 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h"
-#include "ui/gfx/screen.h"
#include "views/controls/button/button.h"
#include "views/controls/menu/view_menu_delegate.h"
#include "views/events/event.h"
+#include "views/screen.h"
#include "views/widget/root_view.h"
#include "views/widget/widget.h"
@@ -259,8 +259,7 @@ int MenuButton::GetMaximumScreenXCoordinate() {
}
gfx::Rect monitor_bounds =
- gfx::Screen::GetMonitorWorkAreaNearestWindow(
- GetWidget()->GetTopLevelWidget()->GetNativeView());
+ Screen::GetMonitorWorkAreaNearestWindow(GetWidget()->GetNativeView());
return monitor_bounds.right() - 1;
}
diff --git a/views/controls/button/native_button.cc b/views/controls/button/native_button.cc
index dace82f..06e6b4c 100644
--- a/views/controls/button/native_button.cc
+++ b/views/controls/button/native_button.cc
@@ -12,7 +12,7 @@
#include "ui/gfx/platform_font_win.h"
#elif defined(OS_LINUX)
#include <gdk/gdkkeysyms.h>
-#include "ui/gfx/screen.h"
+#include "views/screen.h"
#endif
@@ -114,7 +114,7 @@ void NativeButton::ButtonPressed() {
POINTS points = MAKEPOINTS(pos);
gfx::Point cursor_point(points.x, points.y);
#elif defined(OS_LINUX)
- gfx::Point cursor_point = gfx::Screen::GetCursorScreenPoint();
+ gfx::Point cursor_point = Screen::GetCursorScreenPoint();
#endif
views::MouseEvent event(ui::ET_MOUSE_RELEASED,
@@ -192,7 +192,7 @@ bool NativeButton::AcceleratorPressed(const Accelerator& accelerator) {
POINTS points = MAKEPOINTS(pos);
gfx::Point cursor_point(points.x, points.y);
#elif defined(OS_LINUX)
- gfx::Point cursor_point = gfx::Screen::GetCursorScreenPoint();
+ gfx::Point cursor_point = Screen::GetCursorScreenPoint();
#endif
views::MouseEvent event(ui::ET_MOUSE_RELEASED,
cursor_point.x(), cursor_point.y(),
diff --git a/views/controls/menu/menu_controller.cc b/views/controls/menu/menu_controller.cc
index 3fae8bc..b2038da 100644
--- a/views/controls/menu/menu_controller.cc
+++ b/views/controls/menu/menu_controller.cc
@@ -12,11 +12,11 @@
#include "ui/base/keycodes/keyboard_codes.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/canvas_skia.h"
-#include "ui/gfx/screen.h"
#include "views/controls/button/menu_button.h"
#include "views/controls/menu/menu_scroll_view_container.h"
#include "views/controls/menu/submenu_view.h"
#include "views/drag_utils.h"
+#include "views/screen.h"
#include "views/view_constants.h"
#include "views/views_delegate.h"
#include "views/widget/root_view.h"
@@ -1036,7 +1036,7 @@ void MenuController::UpdateInitialLocation(
// Calculate the bounds of the monitor we'll show menus on. Do this once to
// avoid repeated system queries for the info.
- pending_state_.monitor_bounds = gfx::Screen::GetMonitorWorkAreaNearestPoint(
+ pending_state_.monitor_bounds = Screen::GetMonitorWorkAreaNearestPoint(
bounds.origin());
}
@@ -1064,8 +1064,7 @@ bool MenuController::ShowSiblingMenu(SubmenuView* source,
return false;
}
- gfx::NativeWindow window_under_mouse =
- gfx::Screen::GetWindowAtCursorScreenPoint();
+ gfx::NativeWindow window_under_mouse = Screen::GetWindowAtCursorScreenPoint();
if (window_under_mouse != owner_)
return false;
diff --git a/views/mouse_watcher.cc b/views/mouse_watcher.cc
index 810db69..09aaa8a 100644
--- a/views/mouse_watcher.cc
+++ b/views/mouse_watcher.cc
@@ -7,7 +7,7 @@
#include "base/compiler_specific.h"
#include "base/message_loop.h"
#include "base/task.h"
-#include "ui/gfx/screen.h"
+#include "views/screen.h"
#include "views/view.h"
#include "views/widget/widget.h"
@@ -89,7 +89,7 @@ class MouseWatcher::Observer : public MessageLoopForUI::Observer {
bounds.width() + mouse_watcher_->hot_zone_insets_.width(),
bounds.height() + mouse_watcher_->hot_zone_insets_.height());
- gfx::Point cursor_point = gfx::Screen::GetCursorScreenPoint();
+ gfx::Point cursor_point = Screen::GetCursorScreenPoint();
return bounds.Contains(cursor_point.x(), cursor_point.y());
}
@@ -100,7 +100,7 @@ class MouseWatcher::Observer : public MessageLoopForUI::Observer {
if (!widget)
return false;
- return gfx::Screen::GetWindowAtCursorScreenPoint() ==
+ return Screen::GetWindowAtCursorScreenPoint() ==
widget->GetNativeWindow();
}
diff --git a/views/screen.h b/views/screen.h
new file mode 100644
index 0000000..3e65b77
--- /dev/null
+++ b/views/screen.h
@@ -0,0 +1,41 @@
+// Copyright (c) 2009 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 VIEWS_SCREEN_H_
+#define VIEWS_SCREEN_H_
+#pragma once
+
+#include "ui/gfx/native_widget_types.h"
+#include "ui/gfx/point.h"
+#include "ui/gfx/rect.h"
+
+namespace views {
+
+// A utility class for getting various info about screen size, monitors,
+// cursor position, etc.
+// TODO(erikkay) add more of those methods here
+class Screen {
+ public:
+ static gfx::Point GetCursorScreenPoint();
+
+ // Returns the work area of the monitor nearest the specified window.
+ static gfx::Rect GetMonitorWorkAreaNearestWindow(gfx::NativeView view);
+
+ // Returns the bounds of the monitor nearest the specified window.
+ static gfx::Rect GetMonitorAreaNearestWindow(gfx::NativeView view);
+
+ // Returns the work area of the monitor nearest the specified point.
+ static gfx::Rect GetMonitorWorkAreaNearestPoint(const gfx::Point& point);
+
+ // Returns the monitor area (not the work area, but the complete bounds) of
+ // the monitor nearest the specified point.
+ static gfx::Rect GetMonitorAreaNearestPoint(const gfx::Point& point);
+
+ // Returns the window under the cursor.
+ static gfx::NativeWindow GetWindowAtCursorScreenPoint();
+};
+
+} // namespace views
+
+#endif // VIEWS_SCREEN_H_
diff --git a/views/screen_gtk.cc b/views/screen_gtk.cc
new file mode 100644
index 0000000..0a01c6c
--- /dev/null
+++ b/views/screen_gtk.cc
@@ -0,0 +1,108 @@
+// Copyright (c) 2009 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.
+
+#include "views/screen.h"
+
+#include <gdk/gdkx.h>
+#include <gtk/gtk.h>
+
+#include "base/logging.h"
+
+namespace views {
+
+// static
+gfx::Point Screen::GetCursorScreenPoint() {
+ gint x, y;
+ gdk_display_get_pointer(gdk_display_get_default(), NULL, &x, &y, NULL);
+ return gfx::Point(x, y);
+}
+
+gfx::Rect static GetPrimaryMonitorBounds() {
+ guchar* raw_data = NULL;
+ gint data_len = 0;
+ gboolean success = gdk_property_get(gdk_get_default_root_window(),
+ gdk_atom_intern("_NET_WORKAREA", FALSE),
+ gdk_atom_intern("CARDINAL", FALSE),
+ 0, 0xFF, false, NULL, NULL, &data_len,
+ &raw_data);
+ int top_left_x = 0;
+ int top_left_y = 0;
+ int width = 0;
+ int height = 0;
+
+ if (success) {
+ glong* data = reinterpret_cast<glong*>(raw_data);
+ top_left_x = data[0];
+ top_left_y = data[1];
+ width = data[2];
+ height = data[3];
+ g_free(raw_data);
+ } else {
+ // If there's no window manager, we can ask X for Monitor info directly.
+ XWindowAttributes attributes;
+ Status status = XGetWindowAttributes(gdk_x11_get_default_xdisplay(),
+ gdk_x11_get_default_root_xwindow(),
+ &attributes);
+ if (status) {
+ top_left_x = attributes.x;
+ top_left_y = attributes.y;
+ width = attributes.width;
+ height = attributes.height;
+ success = true;
+ }
+ }
+ DCHECK(success);
+ return gfx::Rect(top_left_x, top_left_y, width, height);
+}
+
+// static
+gfx::Rect Screen::GetMonitorWorkAreaNearestWindow(gfx::NativeView view) {
+ // TODO(beng): use |view|.
+ return GetPrimaryMonitorBounds();
+}
+
+// static
+gfx::Rect Screen::GetMonitorAreaNearestWindow(gfx::NativeView view) {
+ GtkWidget* top_level = gtk_widget_get_toplevel(view);
+ DCHECK(GTK_IS_WINDOW(top_level));
+ GtkWindow* window = GTK_WINDOW(top_level);
+ GdkScreen* screen = gtk_window_get_screen(window);
+ gint monitor_num = gdk_screen_get_monitor_at_window(screen,
+ top_level->window);
+ GdkRectangle bounds;
+ gdk_screen_get_monitor_geometry(screen, monitor_num, &bounds);
+ return gfx::Rect(bounds);
+}
+
+// static
+gfx::Rect Screen::GetMonitorWorkAreaNearestPoint(const gfx::Point& point) {
+ // TODO(jamiewalch): Restrict this to the work area of the monitor.
+ return GetMonitorAreaNearestPoint(point);
+}
+
+// static
+gfx::Rect Screen::GetMonitorAreaNearestPoint(const gfx::Point& point) {
+ GdkScreen* screen = gdk_screen_get_default();
+ gint monitor = gdk_screen_get_monitor_at_point(screen, point.x(), point.y());
+ GdkRectangle bounds;
+ gdk_screen_get_monitor_geometry(screen, monitor, &bounds);
+ return gfx::Rect(bounds);
+}
+
+gfx::NativeWindow Screen::GetWindowAtCursorScreenPoint() {
+ GdkWindow* window = gdk_window_at_pointer(NULL, NULL);
+ if (!window)
+ return NULL;
+
+ gpointer data = NULL;
+ gdk_window_get_user_data(window, &data);
+ GtkWidget* widget = reinterpret_cast<GtkWidget*>(data);
+ if (!widget)
+ return NULL;
+ widget = gtk_widget_get_toplevel(widget);
+ return GTK_IS_WINDOW(widget) ? GTK_WINDOW(widget) : NULL;
+}
+
+} // namespace
+
diff --git a/views/screen_win.cc b/views/screen_win.cc
new file mode 100644
index 0000000..b24a55c
--- /dev/null
+++ b/views/screen_win.cc
@@ -0,0 +1,63 @@
+// Copyright (c) 2009 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.
+
+#include "views/screen.h"
+
+#include <windows.h>
+
+namespace views {
+
+// static
+gfx::Point Screen::GetCursorScreenPoint() {
+ POINT pt;
+ GetCursorPos(&pt);
+ return gfx::Point(pt);
+}
+
+// static
+gfx::Rect Screen::GetMonitorWorkAreaNearestWindow(gfx::NativeWindow window) {
+ MONITORINFO monitor_info;
+ monitor_info.cbSize = sizeof(monitor_info);
+ GetMonitorInfo(MonitorFromWindow(window, MONITOR_DEFAULTTONEAREST),
+ &monitor_info);
+ return gfx::Rect(monitor_info.rcWork);
+}
+
+// static
+gfx::Rect Screen::GetMonitorAreaNearestWindow(gfx::NativeWindow window) {
+ MONITORINFO monitor_info;
+ monitor_info.cbSize = sizeof(monitor_info);
+ GetMonitorInfo(MonitorFromWindow(window, MONITOR_DEFAULTTONEAREST),
+ &monitor_info);
+ return gfx::Rect(monitor_info.rcMonitor);
+}
+
+static gfx::Rect GetMonitorAreaOrWorkAreaNearestPoint(const gfx::Point& point,
+ bool work_area) {
+ 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 gfx::Rect(work_area ? mi.rcWork : mi.rcMonitor);
+ return gfx::Rect();
+}
+
+// static
+gfx::Rect Screen::GetMonitorWorkAreaNearestPoint(const gfx::Point& point) {
+ return GetMonitorAreaOrWorkAreaNearestPoint(point, true);
+}
+
+// static
+gfx::Rect Screen::GetMonitorAreaNearestPoint(const gfx::Point& point) {
+ return GetMonitorAreaOrWorkAreaNearestPoint(point, false);
+}
+
+gfx::NativeWindow Screen::GetWindowAtCursorScreenPoint() {
+ POINT location;
+ return GetCursorPos(&location) ? WindowFromPoint(location) : NULL;
+}
+
+} // namespace
+
diff --git a/views/views.gyp b/views/views.gyp
index 39593fc..613f50f 100644
--- a/views/views.gyp
+++ b/views/views.gyp
@@ -295,6 +295,9 @@
'painter.h',
'repeat_controller.cc',
'repeat_controller.h',
+ 'screen.h',
+ 'screen_gtk.cc',
+ 'screen_win.cc',
'touchui/gesture_manager.cc',
'touchui/gesture_manager.h',
'touchui/touch_factory.cc',
diff --git a/views/widget/native_widget_gtk.cc b/views/widget/native_widget_gtk.cc
index 8399107..82ac4b33 100644
--- a/views/widget/native_widget_gtk.cc
+++ b/views/widget/native_widget_gtk.cc
@@ -28,10 +28,10 @@
#include "ui/gfx/compositor/compositor.h"
#include "ui/gfx/gtk_util.h"
#include "ui/gfx/path.h"
-#include "ui/gfx/screen.h"
#include "views/controls/textfield/native_textfield_views.h"
#include "views/focus/view_storage.h"
#include "views/ime/input_method_gtk.h"
+#include "views/screen.h"
#include "views/views_delegate.h"
#include "views/widget/drop_target_gtk.h"
#include "views/widget/gtk_views_fixed.h"
@@ -1005,7 +1005,7 @@ void NativeWidgetGtk::CenterWindow(const gfx::Size& size) {
center_rect = gfx::Rect(parent_x, parent_y, parent_w, parent_h);
} else {
// We have no parent window, center over the screen.
- center_rect = gfx::Screen::GetMonitorWorkAreaNearestWindow(GetNativeView());
+ center_rect = Screen::GetMonitorWorkAreaNearestWindow(GetNativeView());
}
gfx::Rect bounds(center_rect.x() + (center_rect.width() - size.width()) / 2,
center_rect.y() + (center_rect.height() - size.height()) / 2,
diff --git a/views/widget/native_widget_win.cc b/views/widget/native_widget_win.cc
index c327330..41d38fd 100644
--- a/views/widget/native_widget_win.cc
+++ b/views/widget/native_widget_win.cc
@@ -27,7 +27,6 @@
#include "ui/gfx/icon_util.h"
#include "ui/gfx/native_theme_win.h"
#include "ui/gfx/path.h"
-#include "ui/gfx/screen.h"
#include "views/accessibility/native_view_accessibility_win.h"
#include "views/controls/native_control_win.h"
#include "views/controls/textfield/native_textfield_views.h"
@@ -35,6 +34,7 @@
#include "views/focus/focus_util_win.h"
#include "views/focus/view_storage.h"
#include "views/ime/input_method_win.h"
+#include "views/screen.h"
#include "views/views_delegate.h"
#include "views/widget/aero_tooltip_manager.h"
#include "views/widget/child_window_message_processor.h"
@@ -191,7 +191,7 @@ void SetChildBounds(HWND child_window,
window = insert_after_window;
gfx::Rect work_area =
- gfx::Screen::GetMonitorWorkAreaNearestPoint(bounds.origin());
+ views::Screen::GetMonitorWorkAreaNearestPoint(bounds.origin());
if (!work_area.IsEmpty())
parent_rect = work_area.ToRECT();
}
diff --git a/views/widget/tooltip_manager_gtk.cc b/views/widget/tooltip_manager_gtk.cc
index 27ef1a2..d88f345 100644
--- a/views/widget/tooltip_manager_gtk.cc
+++ b/views/widget/tooltip_manager_gtk.cc
@@ -7,8 +7,8 @@
#include "base/logging.h"
#include "base/utf_string_conversions.h"
#include "ui/gfx/font.h"
-#include "ui/gfx/screen.h"
#include "views/focus/focus_manager.h"
+#include "views/screen.h"
#include "views/view.h"
#include "views/widget/native_widget_gtk.h"
@@ -64,7 +64,7 @@ const std::wstring& TooltipManager::GetLineSeparator() {
// static
int TooltipManager::GetMaxWidth(int x, int y) {
gfx::Rect monitor_bounds =
- gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point(x, y));
+ Screen::GetMonitorAreaNearestPoint(gfx::Point(x, y));
// GtkLabel (gtk_label_ensure_layout) forces wrapping at this size. We mirror
// the size here otherwise tooltips wider than the size used by gtklabel end
// up with extraneous empty lines.
diff --git a/views/widget/tooltip_manager_views.cc b/views/widget/tooltip_manager_views.cc
index 4c0a728..98f38dc 100644
--- a/views/widget/tooltip_manager_views.cc
+++ b/views/widget/tooltip_manager_views.cc
@@ -13,10 +13,10 @@
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/font.h"
-#include "ui/gfx/screen.h"
#include "views/background.h"
#include "views/border.h"
#include "views/focus/focus_manager.h"
+#include "views/screen.h"
#include "views/view.h"
#include "views/widget/native_widget.h"
#include "views/widget/root_view.h"
@@ -57,7 +57,7 @@ int TooltipManager::GetMaxWidth(int x, int y) {
// We always display the tooltip inside the root view. So the max width is
// the width of the view.
gfx::Rect monitor_bounds =
- gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point(x, y));
+ Screen::GetMonitorAreaNearestPoint(gfx::Point(x, y));
// GtkLabel (gtk_label_ensure_layout) forces wrapping at this size. We mirror
// the size here otherwise tooltips wider than the size used by gtklabel end
// up with extraneous empty lines.
@@ -179,7 +179,7 @@ void TooltipManagerViews::SetTooltipBounds(gfx::Point mouse_pos,
tooltip_rect.Offset(kCursorOffsetX, kCursorOffsetY);
gfx::Rect monitor_bounds =
- gfx::Screen::GetMonitorAreaNearestPoint(tooltip_rect.origin());
+ Screen::GetMonitorAreaNearestPoint(tooltip_rect.origin());
tooltip_widget_->SetBounds(tooltip_rect.AdjustToFit(monitor_bounds));
}
diff --git a/views/widget/tooltip_manager_win.cc b/views/widget/tooltip_manager_win.cc
index 9e50087..68714b9 100644
--- a/views/widget/tooltip_manager_win.cc
+++ b/views/widget/tooltip_manager_win.cc
@@ -13,7 +13,7 @@
#include "ui/base/l10n/l10n_util_win.h"
#include "ui/base/win/hwnd_util.h"
#include "ui/gfx/font.h"
-#include "ui/gfx/screen.h"
+#include "views/screen.h"
#include "views/view.h"
#include "views/widget/monitor_win.h"
#include "views/widget/widget.h"
@@ -63,7 +63,7 @@ const std::wstring& TooltipManager::GetLineSeparator() {
// static
int TooltipManager::GetMaxWidth(int x, int y) {
gfx::Rect monitor_bounds =
- gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point(x, y));
+ Screen::GetMonitorAreaNearestPoint(gfx::Point(x, y));
// Allow the tooltip to be almost as wide as the screen.
// Otherwise, we would truncate important text, since we're not word-wrapping
// the text onto multiple lines.