Commit c3d931fd authored by ananta@chromium.org's avatar ananta@chromium.org

Fixed tab dragging which was broken on high DPI windows for scales other than 100%.

The tab dragging code uses the GetCursorPos API to determine the tab strip to be used
to drag the tab into. This API returns values in pixel. We need to convert to DIP and
vice versa wherever needed.

Changes as below:-
1. window_finder_win.cc :- The cursor position after my changes now comes in as DIP.
                           We need to convert to pixel as this class uses PtInRect
                           and other APIs which need values in pixel.
2. screen_win.cc :- The GetCursorScreenPoint now returns values in DIP which is what is
                    expected. These values are passed to views and other places which
                    expect values in DIP.
3. apps_grid_view.cc :- Converted cursor position to DIP before passing it to the views code.

Looked at other usages of this API. They seem to be in order. Thought about adding helpers for
this for Windows. Decided against it as it is very hard to enforce given that it is a popular
API.

BUG=364969
R=sky@chromium.org, sky

Review URL: https://codereview.chromium.org/256923002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266744 0039d316-1c4b-4281-b951-d872f2087c98
parent 5d03a6a3
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/win/windows_version.h" #include "base/win/windows_version.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/gfx/screen.h" #include "ui/gfx/screen.h"
#include "ui/gfx/win/dpi.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h" #include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h"
#include "ui/views/win/hwnd_util.h" #include "ui/views/win/hwnd_util.h"
...@@ -126,16 +127,16 @@ class TopMostFinder : public BaseWindowFinder { ...@@ -126,16 +127,16 @@ class TopMostFinder : public BaseWindowFinder {
const std::set<HWND>& ignore) const std::set<HWND>& ignore)
: BaseWindowFinder(ignore), : BaseWindowFinder(ignore),
target_(window), target_(window),
screen_loc_(screen_loc),
is_top_most_(false), is_top_most_(false),
tmp_region_(CreateRectRgn(0, 0, 0, 0)) { tmp_region_(CreateRectRgn(0, 0, 0, 0)) {
screen_loc_ = gfx::win::DIPToScreenPoint(screen_loc);
EnumWindows(WindowCallbackProc, as_lparam()); EnumWindows(WindowCallbackProc, as_lparam());
} }
// The window we're looking for. // The window we're looking for.
HWND target_; HWND target_;
// Location of window to find. // Location of window to find in pixel coordinates.
gfx::Point screen_loc_; gfx::Point screen_loc_;
// Is target_ the top most window? This is initially false but set to true // Is target_ the top most window? This is initially false but set to true
...@@ -165,7 +166,8 @@ class LocalProcessWindowFinder : public BaseWindowFinder { ...@@ -165,7 +166,8 @@ class LocalProcessWindowFinder : public BaseWindowFinder {
if (finder.result_ && if (finder.result_ &&
((base::win::OSInfo::GetInstance()->version() >= ((base::win::OSInfo::GetInstance()->version() >=
base::win::VERSION_WIN8) || base::win::VERSION_WIN8) ||
TopMostFinder::IsTopMostWindowAtPoint(finder.result_, screen_loc, TopMostFinder::IsTopMostWindowAtPoint(finder.result_,
screen_loc,
ignore))) { ignore))) {
return views::DesktopWindowTreeHostWin::GetContentWindowForHWND( return views::DesktopWindowTreeHostWin::GetContentWindowForHWND(
finder.result_); finder.result_);
...@@ -188,12 +190,12 @@ class LocalProcessWindowFinder : public BaseWindowFinder { ...@@ -188,12 +190,12 @@ class LocalProcessWindowFinder : public BaseWindowFinder {
LocalProcessWindowFinder(const gfx::Point& screen_loc, LocalProcessWindowFinder(const gfx::Point& screen_loc,
const std::set<HWND>& ignore) const std::set<HWND>& ignore)
: BaseWindowFinder(ignore), : BaseWindowFinder(ignore),
screen_loc_(screen_loc),
result_(NULL) { result_(NULL) {
screen_loc_ = gfx::win::DIPToScreenPoint(screen_loc);
EnumThreadWindows(GetCurrentThreadId(), WindowCallbackProc, as_lparam()); EnumThreadWindows(GetCurrentThreadId(), WindowCallbackProc, as_lparam());
} }
// Position of the mouse. // Position of the mouse in pixel coordinates.
gfx::Point screen_loc_; gfx::Point screen_loc_;
// The resulting window. This is initially null but set to true in // The resulting window. This is initially null but set to true in
......
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
#include "ui/base/dragdrop/drop_target_win.h" #include "ui/base/dragdrop/drop_target_win.h"
#include "ui/base/dragdrop/os_exchange_data.h" #include "ui/base/dragdrop/os_exchange_data.h"
#include "ui/base/dragdrop/os_exchange_data_provider_win.h" #include "ui/base/dragdrop/os_exchange_data_provider_win.h"
#include "ui/gfx/win/dpi.h"
#endif #endif
namespace app_list { namespace app_list {
...@@ -294,6 +295,7 @@ class SynchronousDrag : public ui::DragSourceWin { ...@@ -294,6 +295,7 @@ class SynchronousDrag : public ui::DragSourceWin {
GetCursorPos(&p); GetCursorPos(&p);
ScreenToClient(GetGridViewHWND(), &p); ScreenToClient(GetGridViewHWND(), &p);
gfx::Point grid_view_pt(p.x, p.y); gfx::Point grid_view_pt(p.x, p.y);
grid_view_pt = gfx::win::ScreenToDIPPoint(grid_view_pt);
views::View::ConvertPointFromWidget(grid_view_, &grid_view_pt); views::View::ConvertPointFromWidget(grid_view_, &grid_view_pt);
return grid_view_pt; return grid_view_pt;
} }
......
...@@ -65,7 +65,8 @@ bool ScreenWin::IsDIPEnabled() { ...@@ -65,7 +65,8 @@ bool ScreenWin::IsDIPEnabled() {
gfx::Point ScreenWin::GetCursorScreenPoint() { gfx::Point ScreenWin::GetCursorScreenPoint() {
POINT pt; POINT pt;
GetCursorPos(&pt); GetCursorPos(&pt);
return gfx::Point(pt); gfx::Point cursor_pos_pixels(pt);
return gfx::win::ScreenToDIPPoint(cursor_pos_pixels);
} }
gfx::NativeWindow ScreenWin::GetWindowUnderCursor() { gfx::NativeWindow ScreenWin::GetWindowUnderCursor() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment