diff options
author | oshima@google.com <oshima@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-23 07:02:48 +0000 |
---|---|---|
committer | oshima@google.com <oshima@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-23 07:02:48 +0000 |
commit | ff967dcaae01a2e807bff93e26a4b7c9dffe9ed8 (patch) | |
tree | 682aa27b7afb950f797e8520ac50e0a63c71c838 /views | |
parent | 9349003401f0c97a8931d38df8fc8ff0a24e7492 (diff) | |
download | chromium_src-ff967dcaae01a2e807bff93e26a4b7c9dffe9ed8.zip chromium_src-ff967dcaae01a2e807bff93e26a4b7c9dffe9ed8.tar.gz chromium_src-ff967dcaae01a2e807bff93e26a4b7c9dffe9ed8.tar.bz2 |
2nd try. added UI_API to Screen class.
Move screen.h to ui/gfx because Screen doesn't depend on views, and they're useful outside views.
BUG=none
TEST=none
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=93724
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=93744
Review URL: http://codereview.chromium.org/7483014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93790 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/controls/button/custom_button.cc | 4 | ||||
-rw-r--r-- | views/controls/button/menu_button.cc | 5 | ||||
-rw-r--r-- | views/controls/button/native_button.cc | 6 | ||||
-rw-r--r-- | views/controls/menu/menu_controller.cc | 7 | ||||
-rw-r--r-- | views/mouse_watcher.cc | 6 | ||||
-rw-r--r-- | views/screen.h | 41 | ||||
-rw-r--r-- | views/screen_gtk.cc | 108 | ||||
-rw-r--r-- | views/screen_win.cc | 63 | ||||
-rw-r--r-- | views/views.gyp | 3 | ||||
-rw-r--r-- | views/widget/native_widget_gtk.cc | 4 | ||||
-rw-r--r-- | views/widget/native_widget_win.cc | 4 | ||||
-rw-r--r-- | views/widget/tooltip_manager_gtk.cc | 4 | ||||
-rw-r--r-- | views/widget/tooltip_manager_views.cc | 6 | ||||
-rw-r--r-- | views/widget/tooltip_manager_win.cc | 4 |
14 files changed, 26 insertions, 239 deletions
diff --git a/views/controls/button/custom_button.cc b/views/controls/button/custom_button.cc index 8e6e09c..abeedf3 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 "views/screen.h" +#include "ui/gfx/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(Screen::GetCursorScreenPoint()); + gfx::Point cursor_pos(gfx::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 7701d59..64f4795 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,7 +259,8 @@ int MenuButton::GetMaximumScreenXCoordinate() { } gfx::Rect monitor_bounds = - Screen::GetMonitorWorkAreaNearestWindow(GetWidget()->GetNativeView()); + gfx::Screen::GetMonitorWorkAreaNearestWindow( + GetWidget()->GetTopLevelWidget()->GetNativeView()); return monitor_bounds.right() - 1; } diff --git a/views/controls/button/native_button.cc b/views/controls/button/native_button.cc index 06e6b4c..dace82f 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 "views/screen.h" +#include "ui/gfx/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 = Screen::GetCursorScreenPoint(); + gfx::Point cursor_point = gfx::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 = Screen::GetCursorScreenPoint(); + gfx::Point cursor_point = gfx::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 b2038da..3fae8bc 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 = Screen::GetMonitorWorkAreaNearestPoint( + pending_state_.monitor_bounds = gfx::Screen::GetMonitorWorkAreaNearestPoint( bounds.origin()); } @@ -1064,7 +1064,8 @@ bool MenuController::ShowSiblingMenu(SubmenuView* source, return false; } - gfx::NativeWindow window_under_mouse = Screen::GetWindowAtCursorScreenPoint(); + gfx::NativeWindow window_under_mouse = + gfx::Screen::GetWindowAtCursorScreenPoint(); if (window_under_mouse != owner_) return false; diff --git a/views/mouse_watcher.cc b/views/mouse_watcher.cc index 09aaa8a..810db69 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 "views/screen.h" +#include "ui/gfx/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 = Screen::GetCursorScreenPoint(); + gfx::Point cursor_point = gfx::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 Screen::GetWindowAtCursorScreenPoint() == + return gfx::Screen::GetWindowAtCursorScreenPoint() == widget->GetNativeWindow(); } diff --git a/views/screen.h b/views/screen.h deleted file mode 100644 index 3e65b77..0000000 --- a/views/screen.h +++ /dev/null @@ -1,41 +0,0 @@ -// 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 deleted file mode 100644 index 0a01c6c..0000000 --- a/views/screen_gtk.cc +++ /dev/null @@ -1,108 +0,0 @@ -// 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 deleted file mode 100644 index b24a55c..0000000 --- a/views/screen_win.cc +++ /dev/null @@ -1,63 +0,0 @@ -// 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 613f50f..39593fc 100644 --- a/views/views.gyp +++ b/views/views.gyp @@ -295,9 +295,6 @@ '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 82ac4b33..8399107 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 = Screen::GetMonitorWorkAreaNearestWindow(GetNativeView()); + center_rect = gfx::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 41d38fd..c327330 100644 --- a/views/widget/native_widget_win.cc +++ b/views/widget/native_widget_win.cc @@ -27,6 +27,7 @@ #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" @@ -34,7 +35,6 @@ #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 = - views::Screen::GetMonitorWorkAreaNearestPoint(bounds.origin()); + gfx::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 d88f345..27ef1a2 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 = - Screen::GetMonitorAreaNearestPoint(gfx::Point(x, y)); + gfx::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 98f38dc..4c0a728 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 = - Screen::GetMonitorAreaNearestPoint(gfx::Point(x, y)); + gfx::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 = - Screen::GetMonitorAreaNearestPoint(tooltip_rect.origin()); + gfx::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 68714b9..9e50087 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 "views/screen.h" +#include "ui/gfx/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 = - Screen::GetMonitorAreaNearestPoint(gfx::Point(x, y)); + gfx::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. |