summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/ui/tabs/dock_info_win.cc11
-rw-r--r--chrome/browser/ui/views/tabs/dragged_tab_controller.cc15
-rw-r--r--views/screen.h3
-rw-r--r--views/screen_gtk.cc6
-rw-r--r--views/screen_win.cc22
5 files changed, 44 insertions, 13 deletions
diff --git a/chrome/browser/ui/tabs/dock_info_win.cc b/chrome/browser/ui/tabs/dock_info_win.cc
index 40b9fdf..67ca6e4 100644
--- a/chrome/browser/ui/tabs/dock_info_win.cc
+++ b/chrome/browser/ui/tabs/dock_info_win.cc
@@ -9,6 +9,7 @@
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/tabs/tab.h"
+#include "views/screen.h"
namespace {
@@ -230,12 +231,10 @@ class DockToWindowFinder : public BaseWindowFinder {
const std::set<HWND>& ignore)
: BaseWindowFinder(ignore),
screen_loc_(screen_loc) {
- HMONITOR monitor = MonitorFromPoint(screen_loc.ToPOINT(),
- MONITOR_DEFAULTTONULL);
- MONITORINFO monitor_info = {0};
- monitor_info.cbSize = sizeof(MONITORINFO);
- if (monitor && GetMonitorInfo(monitor, &monitor_info)) {
- result_.set_monitor_bounds(gfx::Rect(monitor_info.rcWork));
+ gfx::Rect work_area = views::Screen::GetMonitorWorkAreaNearestPoint(
+ screen_loc);
+ if (!work_area.IsEmpty()) {
+ result_.set_monitor_bounds(work_area);
EnumThreadWindows(GetCurrentThreadId(), WindowCallbackProc,
reinterpret_cast<LPARAM>(this));
}
diff --git a/chrome/browser/ui/views/tabs/dragged_tab_controller.cc b/chrome/browser/ui/views/tabs/dragged_tab_controller.cc
index 3f61013..611cee3 100644
--- a/chrome/browser/ui/views/tabs/dragged_tab_controller.cc
+++ b/chrome/browser/ui/views/tabs/dragged_tab_controller.cc
@@ -34,6 +34,7 @@
#include "ui/base/animation/slide_animation.h"
#include "ui/base/resource/resource_bundle.h"
#include "views/event.h"
+#include "views/screen.h"
#include "views/widget/root_view.h"
#include "views/widget/widget.h"
#include "views/window/window.h"
@@ -537,6 +538,20 @@ gfx::Point DraggedTabController::GetWindowCreatePoint() const {
// otherwise we may attempt to maximize on the wrong monitor.
return cursor_point;
}
+ // If the cursor is outside the monitor area, move it inside. For example,
+ // dropping a tab onto the task bar on Windows produces this situation.
+ gfx::Rect work_area = views::Screen::GetMonitorWorkAreaNearestPoint(
+ cursor_point);
+ if (!work_area.IsEmpty()) {
+ if (cursor_point.x() < work_area.x())
+ cursor_point.set_x(work_area.x());
+ else if (cursor_point.x() > work_area.right())
+ cursor_point.set_x(work_area.right());
+ if (cursor_point.y() < work_area.y())
+ cursor_point.set_y(work_area.y());
+ else if (cursor_point.y() > work_area.bottom())
+ cursor_point.set_y(work_area.bottom());
+ }
return gfx::Point(cursor_point.x() - window_create_point_.x(),
cursor_point.y() - window_create_point_.y());
}
diff --git a/views/screen.h b/views/screen.h
index 6d6bc89..494f126 100644
--- a/views/screen.h
+++ b/views/screen.h
@@ -25,6 +25,9 @@ class Screen {
// 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);
diff --git a/views/screen_gtk.cc b/views/screen_gtk.cc
index 05076d7..0a01c6c 100644
--- a/views/screen_gtk.cc
+++ b/views/screen_gtk.cc
@@ -76,6 +76,12 @@ gfx::Rect Screen::GetMonitorAreaNearestWindow(gfx::NativeView view) {
}
// 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());
diff --git a/views/screen_win.cc b/views/screen_win.cc
index 4ddb7c1..b24a55c 100644
--- a/views/screen_win.cc
+++ b/views/screen_win.cc
@@ -33,17 +33,25 @@ gfx::Rect Screen::GetMonitorAreaNearestWindow(gfx::NativeWindow window) {
return gfx::Rect(monitor_info.rcMonitor);
}
-// static
-gfx::Rect Screen::GetMonitorAreaNearestPoint(const gfx::Point& point) {
+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);
- if (!monitor)
- return gfx::Rect();
-
MONITORINFO mi = {0};
mi.cbSize = sizeof(mi);
- GetMonitorInfo(monitor, &mi);
- return gfx::Rect(mi.rcMonitor);
+ 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() {