summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryusukes@chromium.org <yusukes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-24 20:53:23 +0000
committeryusukes@chromium.org <yusukes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-24 20:53:23 +0000
commit718b26cd02ffe63b82650e81cb9bb5b0634d62c7 (patch)
treea7b16b40dfe8f344b31b5c575c5acb61cb7f1af7
parenta6b4ee0441f5e7199c583f924056dca14b889208 (diff)
downloadchromium_src-718b26cd02ffe63b82650e81cb9bb5b0634d62c7.zip
chromium_src-718b26cd02ffe63b82650e81cb9bb5b0634d62c7.tar.gz
chromium_src-718b26cd02ffe63b82650e81cb9bb5b0634d62c7.tar.bz2
Move last_mouse_location_ from aura::RootWindow to aura::Env to support multiple root windows.
BUG=136814 TEST=1) the new ash_unittests as well as existing tests passed. 2) ran ash_shell by './out/Release/ash_shell --ash-extended-desktop --aura-host-window-size=100+0-500x500,610+0-300x300 --ash-virtual-screen-coordinates', then move the cursor to the second (right hand side) window, then click the right button. confirmed that the popup menu is shown on the right window. Review URL: https://chromiumcodereview.appspot.com/10781028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148193 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/accelerators/accelerator_controller.cc2
-rw-r--r--ash/extended_desktop_unittest.cc21
-rw-r--r--ash/magnifier/magnification_controller.cc3
-rw-r--r--ash/screen_ash.cc3
-rw-r--r--ash/system/tray/system_tray.cc4
-rw-r--r--ash/wm/shelf_layout_manager.cc3
-rw-r--r--content/browser/web_contents/web_contents_view_aura.cc14
-rw-r--r--ui/aura/env.cc10
-rw-r--r--ui/aura/env.h9
-rw-r--r--ui/aura/root_window.cc61
-rw-r--r--ui/aura/root_window.h8
-rw-r--r--ui/aura/root_window_host.h11
-rw-r--r--ui/aura/root_window_host_linux.cc10
-rw-r--r--ui/aura/root_window_host_linux.h2
-rw-r--r--ui/aura/root_window_host_mac.mm7
-rw-r--r--ui/aura/root_window_host_win.cc9
-rw-r--r--ui/aura/root_window_host_win.h2
-rw-r--r--ui/aura/test/test_screen.cc3
-rw-r--r--ui/aura/window.cc10
-rw-r--r--ui/aura/window.h1
-rw-r--r--ui/aura/window_unittest.cc35
-rw-r--r--ui/views/widget/tooltip_manager_aura.cc4
22 files changed, 159 insertions, 73 deletions
diff --git a/ash/accelerators/accelerator_controller.cc b/ash/accelerators/accelerator_controller.cc
index 7e451bc..b6e4665 100644
--- a/ash/accelerators/accelerator_controller.cc
+++ b/ash/accelerators/accelerator_controller.cc
@@ -248,7 +248,7 @@ bool HandleMagnifyScreen(int delta_index) {
bool HandlePrintLayerHierarchy() {
aura::RootWindow* root_window = Shell::GetPrimaryRootWindow();
ui::PrintLayerHierarchy(root_window->layer(),
- root_window->last_mouse_location());
+ root_window->GetLastMouseLocationInRoot());
return true;
}
diff --git a/ash/extended_desktop_unittest.cc b/ash/extended_desktop_unittest.cc
index 0b0d554..8e346a7 100644
--- a/ash/extended_desktop_unittest.cc
+++ b/ash/extended_desktop_unittest.cc
@@ -18,6 +18,7 @@
#include "ui/aura/window.h"
#include "ui/base/cursor/cursor.h"
#include "ui/gfx/display.h"
+#include "ui/gfx/screen.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
@@ -187,6 +188,26 @@ TEST_F(ExtendedDesktopTest, TestCursor) {
EXPECT_EQ(ui::kCursorCopy, root_windows[1]->last_cursor().native_type());
}
+TEST_F(ExtendedDesktopTest, TestCursorLocation) {
+ UpdateDisplay("0+0-1000x600,1001+0-600x400");
+ Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
+ aura::Window::TestApi root_window0_test_api(root_windows[0]);
+ aura::Window::TestApi root_window1_test_api(root_windows[1]);
+
+ root_windows[0]->MoveCursorTo(gfx::Point(10, 10));
+ EXPECT_EQ("10,10", gfx::Screen::GetCursorScreenPoint().ToString());
+ EXPECT_TRUE(root_window0_test_api.ContainsMouse());
+ EXPECT_FALSE(root_window1_test_api.ContainsMouse());
+ root_windows[1]->MoveCursorTo(gfx::Point(10, 20));
+ EXPECT_EQ("1010,20", gfx::Screen::GetCursorScreenPoint().ToString());
+ EXPECT_FALSE(root_window0_test_api.ContainsMouse());
+ EXPECT_TRUE(root_window1_test_api.ContainsMouse());
+ root_windows[0]->MoveCursorTo(gfx::Point(20, 10));
+ EXPECT_EQ("20,10", gfx::Screen::GetCursorScreenPoint().ToString());
+ EXPECT_TRUE(root_window0_test_api.ContainsMouse());
+ EXPECT_FALSE(root_window1_test_api.ContainsMouse());
+}
+
TEST_F(ExtendedDesktopTest, CycleWindows) {
UpdateDisplay("700x500,500x500");
Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
diff --git a/ash/magnifier/magnification_controller.cc b/ash/magnifier/magnification_controller.cc
index d6d4556..ff2ea92 100644
--- a/ash/magnifier/magnification_controller.cc
+++ b/ash/magnifier/magnification_controller.cc
@@ -12,6 +12,7 @@
#include "ui/aura/window.h"
#include "ui/aura/window_property.h"
#include "ui/gfx/point3.h"
+#include "ui/gfx/screen.h"
#include "ui/compositor/dip_util.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_animation_observer.h"
@@ -343,7 +344,7 @@ void MagnificationControllerImpl::SetScale(float scale, bool animate) {
// Try not to change the point which the mouse cursor indicates to.
const gfx::Rect window_rect = GetWindowRectDIP(scale);
- const gfx::Point mouse = root_window_->last_mouse_location();
+ const gfx::Point mouse = gfx::Screen::GetCursorScreenPoint();
const gfx::Point origin = gfx::Point(mouse.x() * (1.0f - 1.0f / scale),
mouse.y() * (1.0f - 1.0f / scale));
Redraw(origin, scale, animate);
diff --git a/ash/screen_ash.cc b/ash/screen_ash.cc
index 6c39ced..34ce7c6 100644
--- a/ash/screen_ash.cc
+++ b/ash/screen_ash.cc
@@ -78,8 +78,7 @@ gfx::Rect ScreenAsh::ConvertRectFromScreen(aura::Window* window,
}
gfx::Point ScreenAsh::GetCursorScreenPoint() {
- // TODO(oshima): Support multiple root window.
- return Shell::GetPrimaryRootWindow()->last_mouse_location();
+ return aura::Env::GetInstance()->last_mouse_location();
}
gfx::NativeWindow ScreenAsh::GetWindowAtCursorScreenPoint() {
diff --git a/ash/system/tray/system_tray.cc b/ash/system/tray/system_tray.cc
index 56298ce..e70f9a5 100644
--- a/ash/system/tray/system_tray.cc
+++ b/ash/system/tray/system_tray.cc
@@ -41,6 +41,7 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/compositor/layer.h"
#include "ui/gfx/canvas.h"
+#include "ui/gfx/screen.h"
#include "ui/gfx/skia_util.h"
#include "ui/views/border.h"
#include "ui/views/controls/label.h"
@@ -352,9 +353,8 @@ void SystemTray::RemoveBubble(SystemTrayBubble* bubble) {
if (should_show_launcher_) {
// No need to show the launcher if the mouse isn't over the status area
// anymore.
- aura::RootWindow* root = GetWidget()->GetNativeView()->GetRootWindow();
should_show_launcher_ = GetWidget()->GetWindowBoundsInScreen().Contains(
- root->last_mouse_location());
+ gfx::Screen::GetCursorScreenPoint());
if (!should_show_launcher_)
Shell::GetInstance()->shelf()->UpdateAutoHideState();
}
diff --git a/ash/wm/shelf_layout_manager.cc b/ash/wm/shelf_layout_manager.cc
index b00f7f1..717425d 100644
--- a/ash/wm/shelf_layout_manager.cc
+++ b/ash/wm/shelf_layout_manager.cc
@@ -558,10 +558,9 @@ ShelfLayoutManager::AutoHideState ShelfLayoutManager::CalculateAutoHideState(
if (event_filter_.get() && event_filter_->in_mouse_drag())
return AUTO_HIDE_HIDDEN;
- aura::RootWindow* root = launcher_widget()->GetNativeView()->GetRootWindow();
bool mouse_over_launcher =
launcher_widget()->GetWindowBoundsInScreen().Contains(
- root->last_mouse_location());
+ gfx::Screen::GetCursorScreenPoint());
return mouse_over_launcher ? AUTO_HIDE_SHOWN : AUTO_HIDE_HIDDEN;
}
diff --git a/content/browser/web_contents/web_contents_view_aura.cc b/content/browser/web_contents/web_contents_view_aura.cc
index 072c00c..db394bb 100644
--- a/content/browser/web_contents/web_contents_view_aura.cc
+++ b/content/browser/web_contents/web_contents_view_aura.cc
@@ -237,7 +237,7 @@ void WebContentsViewAura::SizeChangedCommon(const gfx::Size& size) {
void WebContentsViewAura::EndDrag(WebKit::WebDragOperationsMask ops) {
aura::RootWindow* root_window = GetNativeView()->GetRootWindow();
- gfx::Point screen_loc = root_window->last_mouse_location();
+ gfx::Point screen_loc = gfx::Screen::GetCursorScreenPoint();
gfx::Point client_loc = screen_loc;
content::RenderViewHost* rvh = web_contents_->GetRenderViewHost();
aura::Window* window = rvh->GetView()->GetNativeView();
@@ -445,11 +445,11 @@ void WebContentsViewAura::StartDragging(
// updates while in the system DoDragDrop loop.
int result_op = 0;
{
- // TODO(sad): Avoid using last_mouse_location here, since the drag may not
+ // TODO(sad): Avoid using GetCursorScreenPoint here, since the drag may not
// always start from a mouse-event (e.g. a touch or gesture event could
// initiate the drag). The location information should be carried over from
// webkit. http://crbug.com/114754
- gfx::Point location(root_window->last_mouse_location());
+ gfx::Point location(gfx::Screen::GetCursorScreenPoint());
MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
result_op = aura::client::GetDragDropClient(root_window)->StartDragAndDrop(
data, location, ConvertFromWeb(operations));
@@ -588,8 +588,7 @@ void WebContentsViewAura::OnDragEntered(const aura::DropTargetEvent& event) {
PrepareWebDropData(&drop_data, event.data());
WebKit::WebDragOperationsMask op = ConvertToWeb(event.source_operations());
- gfx::Point screen_pt =
- GetNativeView()->GetRootWindow()->last_mouse_location();
+ gfx::Point screen_pt = gfx::Screen::GetCursorScreenPoint();
current_rvh_for_drag_ = web_contents_->GetRenderViewHost();
web_contents_->GetRenderViewHost()->DragTargetDragEnter(
drop_data, event.location(), screen_pt, op,
@@ -607,8 +606,7 @@ int WebContentsViewAura::OnDragUpdated(const aura::DropTargetEvent& event) {
OnDragEntered(event);
WebKit::WebDragOperationsMask op = ConvertToWeb(event.source_operations());
- gfx::Point screen_pt =
- GetNativeView()->GetRootWindow()->last_mouse_location();
+ gfx::Point screen_pt = gfx::Screen::GetCursorScreenPoint();
web_contents_->GetRenderViewHost()->DragTargetDragOver(
event.location(), screen_pt, op,
ConvertAuraEventFlagsToWebInputEventModifiers(event.flags()));
@@ -636,7 +634,7 @@ int WebContentsViewAura::OnPerformDrop(const aura::DropTargetEvent& event) {
web_contents_->GetRenderViewHost()->DragTargetDrop(
event.location(),
- GetNativeView()->GetRootWindow()->last_mouse_location(),
+ gfx::Screen::GetCursorScreenPoint(),
ConvertAuraEventFlagsToWebInputEventModifiers(event.flags()));
if (drag_dest_delegate_)
drag_dest_delegate_->OnDrop();
diff --git a/ui/aura/env.cc b/ui/aura/env.cc
index 977e7ca..60bca1a 100644
--- a/ui/aura/env.cc
+++ b/ui/aura/env.cc
@@ -5,6 +5,7 @@
#include "ui/aura/env.h"
#include "base/command_line.h"
+#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/cursor_manager.h"
#include "ui/aura/env_observer.h"
#include "ui/aura/event_filter.h"
@@ -60,6 +61,15 @@ void Env::RemoveObserver(EnvObserver* observer) {
observers_.RemoveObserver(observer);
}
+void Env::SetLastMouseLocation(const Window& window,
+ const gfx::Point& location_in_root) {
+ last_mouse_location_ = location_in_root;
+ client::ScreenPositionClient* client =
+ client::GetScreenPositionClient(window.GetRootWindow());
+ if (client)
+ client->ConvertPointToScreen(&window, &last_mouse_location_);
+}
+
void Env::SetDisplayManager(DisplayManager* display_manager) {
display_manager_.reset(display_manager);
#if defined(USE_X11)
diff --git a/ui/aura/env.h b/ui/aura/env.h
index 0dcc8a8..a6f49ba 100644
--- a/ui/aura/env.h
+++ b/ui/aura/env.h
@@ -11,6 +11,7 @@
#include "ui/aura/aura_export.h"
#include "ui/aura/cursor_manager.h"
#include "ui/aura/client/stacking_client.h"
+#include "ui/gfx/point.h"
namespace aura {
class CursorManager;
@@ -46,6 +47,12 @@ class AURA_EXPORT Env {
mouse_button_flags_ = mouse_button_flags;
}
+ // Gets/sets the last mouse location seen in a mouse event in the screen
+ // coordinates.
+ const gfx::Point& last_mouse_location() const { return last_mouse_location_; }
+ void SetLastMouseLocation(const Window& window,
+ const gfx::Point& location_in_root);
+
// Whether any touch device is currently down.
bool is_touch_down() const { return is_touch_down_; }
void set_touch_down(bool value) { is_touch_down_ = value; }
@@ -95,6 +102,8 @@ class AURA_EXPORT Env {
static Env* instance_;
int mouse_button_flags_;
+ // Location of last mouse event, in screen coordinates.
+ gfx::Point last_mouse_location_;
bool is_touch_down_;
bool render_white_bg_;
client::StackingClient* stacking_client_;
diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc
index 56d2f26..4cc218b 100644
--- a/ui/aura/root_window.cc
+++ b/ui/aura/root_window.cc
@@ -15,6 +15,7 @@
#include "ui/aura/client/activation_client.h"
#include "ui/aura/client/capture_client.h"
#include "ui/aura/client/event_client.h"
+#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/env.h"
#include "ui/aura/event.h"
#include "ui/aura/event_filter.h"
@@ -64,7 +65,7 @@ void GetEventFiltersToNotify(Window* target, EventFilters* filters) {
filters->push_back(Env::GetInstance()->event_filter());
}
-float GetDeviceScaleFactorFromDisplay(const aura::Window* window) {
+float GetDeviceScaleFactorFromDisplay(const Window* window) {
DisplayManager* display_manager = Env::GetInstance()->display_manager();
return display_manager->GetDisplayNearestWindow(window).device_scale_factor();
}
@@ -74,6 +75,11 @@ Window* ConsumerToWindow(ui::GestureConsumer* consumer) {
static_cast<Window*>(consumer) : NULL;
}
+void SetLastMouseLocation(const Window* root_window,
+ const gfx::Point& location) {
+ Env::GetInstance()->SetLastMouseLocation(*root_window, location);
+}
+
} // namespace
CompositorLock::CompositorLock(RootWindow* root_window)
@@ -157,8 +163,11 @@ void RootWindow::Init() {
compositor()->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(this),
host_->GetBounds().size());
Window::Init(ui::LAYER_NOT_DRAWN);
- last_mouse_location_ =
- ui::ConvertPointToDIP(layer(), host_->QueryMouseLocation());
+
+ gfx::Point point;
+ if (host_->QueryMouseLocation(&point))
+ SetLastMouseLocation(this, ui::ConvertPointToDIP(layer(), point));
+
compositor()->SetRootLayer(layer());
SetBounds(
ui::ConvertRectToDIP(layer(), gfx::Rect(host_->GetBounds().size())));
@@ -175,9 +184,12 @@ void RootWindow::SetHostSize(const gfx::Size& size_in_pixel) {
gfx::Rect bounds = host_->GetBounds();
bounds.set_size(size_in_pixel);
host_->SetBounds(bounds);
+
// Requery the location to constrain it within the new root window size.
- last_mouse_location_ =
- ui::ConvertPointToDIP(layer(), host_->QueryMouseLocation());
+ gfx::Point point;
+ if (host_->QueryMouseLocation(&point))
+ SetLastMouseLocation(this, ui::ConvertPointToDIP(layer(), point));
+
synthesize_mouse_move_ = false;
}
@@ -188,9 +200,12 @@ gfx::Size RootWindow::GetHostSize() const {
void RootWindow::SetHostBounds(const gfx::Rect& bounds_in_pixel) {
DispatchHeldMouseMove();
host_->SetBounds(bounds_in_pixel);
+
// Requery the location to constrain it within the new root window size.
- last_mouse_location_ =
- ui::ConvertPointToDIP(layer(), host_->QueryMouseLocation());
+ gfx::Point point;
+ if (host_->QueryMouseLocation(&point))
+ SetLastMouseLocation(this, ui::ConvertPointToDIP(layer(), point));
+
synthesize_mouse_move_ = false;
}
@@ -214,7 +229,7 @@ void RootWindow::MoveCursorTo(const gfx::Point& location_in_dip) {
gfx::Point location = location_in_dip;
layer()->transform().TransformPoint(location);
host_->MoveCursorTo(ui::ConvertPointToPixel(layer(), location));
- last_mouse_location_ = location_in_dip;
+ SetLastMouseLocation(this, location_in_dip);
}
bool RootWindow::ConfineCursorToWindow() {
@@ -285,7 +300,7 @@ bool RootWindow::DispatchScrollEvent(ScrollEvent* event) {
transform.ConcatScale(scale, scale);
event->UpdateForRootTransform(transform);
- last_mouse_location_ = event->location();
+ SetLastMouseLocation(this, event->location());
synthesize_mouse_move_ = false;
Window* target = mouse_pressed_handler_ ?
@@ -407,7 +422,7 @@ void RootWindow::OnWindowDestroying(Window* window) {
OnWindowHidden(window, true);
if (window->IsVisible() &&
- window->ContainsPointInRoot(last_mouse_location_)) {
+ window->ContainsPointInRoot(GetLastMouseLocationInRoot())) {
PostMouseMoveEventAfterWindowChange();
}
}
@@ -416,7 +431,7 @@ void RootWindow::OnWindowBoundsChanged(Window* window,
bool contained_mouse_point) {
if (contained_mouse_point ||
(window->IsVisible() &&
- window->ContainsPointInRoot(last_mouse_location_))) {
+ window->ContainsPointInRoot(GetLastMouseLocationInRoot()))) {
PostMouseMoveEventAfterWindowChange();
}
}
@@ -425,14 +440,14 @@ void RootWindow::OnWindowVisibilityChanged(Window* window, bool is_visible) {
if (!is_visible)
OnWindowHidden(window, false);
- if (window->ContainsPointInRoot(last_mouse_location_))
+ if (window->ContainsPointInRoot(GetLastMouseLocationInRoot()))
PostMouseMoveEventAfterWindowChange();
}
void RootWindow::OnWindowTransformed(Window* window, bool contained_mouse) {
if (contained_mouse ||
(window->IsVisible() &&
- window->ContainsPointInRoot(last_mouse_location_))) {
+ window->ContainsPointInRoot(GetLastMouseLocationInRoot()))) {
PostMouseMoveEventAfterWindowChange();
}
}
@@ -523,6 +538,14 @@ bool RootWindow::GrabSnapshot(const gfx::Rect& snapshot_bounds,
return host_->GrabSnapshot(snapshot_pixels, png_representation);
}
+gfx::Point RootWindow::GetLastMouseLocationInRoot() const {
+ gfx::Point location = Env::GetInstance()->last_mouse_location();
+ client::ScreenPositionClient* client = client::GetScreenPositionClient(this);
+ if (client)
+ client->ConvertPointFromScreen(this, &location);
+ return location;
+}
+
////////////////////////////////////////////////////////////////////////////////
// RootWindow, Window overrides:
@@ -659,7 +682,9 @@ void RootWindow::ReleaseNativeCapture() {
}
gfx::Point RootWindow::QueryMouseLocationForTest() const {
- return host_->QueryMouseLocation();
+ gfx::Point point;
+ host_->QueryMouseLocation(&point);
+ return point;
}
////////////////////////////////////////////////////////////////////////////////
@@ -796,7 +821,7 @@ void RootWindow::OnWindowRemovedFromRootWindow(Window* detached) {
OnWindowHidden(detached, false);
if (detached->IsVisible() &&
- detached->ContainsPointInRoot(last_mouse_location_)) {
+ detached->ContainsPointInRoot(GetLastMouseLocationInRoot())) {
PostMouseMoveEventAfterWindowChange();
}
}
@@ -844,7 +869,7 @@ void RootWindow::OnWindowHidden(Window* invisible, bool destroyed) {
void RootWindow::OnWindowAddedToRootWindow(Window* attached) {
if (attached->IsVisible() &&
- attached->ContainsPointInRoot(last_mouse_location_))
+ attached->ContainsPointInRoot(GetLastMouseLocationInRoot()))
PostMouseMoveEventAfterWindowChange();
}
@@ -905,7 +930,7 @@ bool RootWindow::DispatchMouseEventToTarget(MouseEvent* event,
ui::EF_LEFT_MOUSE_BUTTON |
ui::EF_MIDDLE_MOUSE_BUTTON |
ui::EF_RIGHT_MOUSE_BUTTON;
- last_mouse_location_ = event->location();
+ SetLastMouseLocation(this, event->location());
synthesize_mouse_move_ = false;
switch (event->type()) {
case ui::ET_MOUSE_MOVED:
@@ -963,7 +988,7 @@ void RootWindow::SynthesizeMouseMoveEvent() {
synthesize_mouse_move_ = false;
#if !defined(OS_WIN)
// Temporarily disabled for windows. See crbug.com/112222.
- gfx::Point3f point(last_mouse_location_);
+ gfx::Point3f point(Env::GetInstance()->last_mouse_location());
ui::Transform transform = layer()->transform();
float scale = ui::GetDeviceScaleFactor(layer());
transform.ConcatScale(scale, scale);
diff --git a/ui/aura/root_window.h b/ui/aura/root_window.h
index 81e1ed2..34e15bf 100644
--- a/ui/aura/root_window.h
+++ b/ui/aura/root_window.h
@@ -93,7 +93,6 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate,
}
ui::Compositor* compositor() { return compositor_.get(); }
- gfx::Point last_mouse_location() const { return last_mouse_location_; }
gfx::NativeCursor last_cursor() const { return last_cursor_; }
Window* mouse_pressed_handler() { return mouse_pressed_handler_; }
bool cursor_shown() const { return cursor_shown_; }
@@ -238,6 +237,10 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate,
bool GrabSnapshot(const gfx::Rect& snapshot_bounds,
std::vector<unsigned char>* png_representation);
+ // Gets the last location seen in a mouse event in this root window's
+ // coordinates. This may return a point outside the root window's bounds.
+ gfx::Point GetLastMouseLocationInRoot() const;
+
// Overridden from Window:
virtual RootWindow* GetRootWindow() OVERRIDE;
virtual const RootWindow* GetRootWindow() const OVERRIDE;
@@ -357,9 +360,6 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate,
// Use to post mouse move event.
base::WeakPtrFactory<RootWindow> event_factory_;
- // Last location seen in a mouse event.
- gfx::Point last_mouse_location_;
-
// ui::EventFlags containing the current state of the mouse buttons.
int mouse_button_flags_;
diff --git a/ui/aura/root_window_host.h b/ui/aura/root_window_host.h
index b053a55..7168a31 100644
--- a/ui/aura/root_window_host.h
+++ b/ui/aura/root_window_host.h
@@ -73,11 +73,12 @@ class RootWindowHost {
// Shows or hides the cursor.
virtual void ShowCursor(bool show) = 0;
- // Queries the mouse's current position relative to the host window.
- // The position is constrained within the host window.
- // You should probably call RootWindow::last_mouse_location() instead; this
- // method can be expensive.
- virtual gfx::Point QueryMouseLocation() = 0;
+ // Queries the mouse's current position relative to the host window and sets
+ // it in |location_return|. Returns true if the cursor is within the host
+ // window. The position set to |location_return| is constrained within the
+ // host window.
+ // This method is expensive, instead use gfx::Screen::GetCursorScreenPoint().
+ virtual bool QueryMouseLocation(gfx::Point* location_return) = 0;
// Clips the cursor to the bounds of the root window until UnConfineCursor().
virtual bool ConfineCursorToRootWindow() = 0;
diff --git a/ui/aura/root_window_host_linux.cc b/ui/aura/root_window_host_linux.cc
index 04f7587..f82f6e49 100644
--- a/ui/aura/root_window_host_linux.cc
+++ b/ui/aura/root_window_host_linux.cc
@@ -632,7 +632,7 @@ bool RootWindowHostLinux::Dispatch(const base::NativeEvent& event) {
// moved/resized.
if (pointer_barriers_.get()) {
UnConfineCursor();
- gfx::Point p = root_window_->last_mouse_location();
+ gfx::Point p = gfx::Screen::GetCursorScreenPoint();
XWarpPointer(xdisplay_, None, xwindow_, 0, 0, 0, 0, p.x(), p.y());
ConfineCursorToRootWindow();
}
@@ -866,7 +866,7 @@ void RootWindowHostLinux::ShowCursor(bool show) {
SetCursorInternal(show ? current_cursor_ : ui::kCursorNone);
}
-gfx::Point RootWindowHostLinux::QueryMouseLocation() {
+bool RootWindowHostLinux::QueryMouseLocation(gfx::Point* location_return) {
::Window root_return, child_return;
int root_x_return, root_y_return, win_x_return, win_y_return;
unsigned int mask_return;
@@ -877,8 +877,10 @@ gfx::Point RootWindowHostLinux::QueryMouseLocation() {
&root_x_return, &root_y_return,
&win_x_return, &win_y_return,
&mask_return);
- return gfx::Point(max(0, min(bounds_.width(), win_x_return)),
- max(0, min(bounds_.height(), win_y_return)));
+ *location_return = gfx::Point(max(0, min(bounds_.width(), win_x_return)),
+ max(0, min(bounds_.height(), win_y_return)));
+ return (win_x_return >= 0 && win_x_return < bounds_.width() &&
+ win_y_return >= 0 && win_y_return < bounds_.height());
}
bool RootWindowHostLinux::ConfineCursorToRootWindow() {
diff --git a/ui/aura/root_window_host_linux.h b/ui/aura/root_window_host_linux.h
index 9d045eb..da6f080 100644
--- a/ui/aura/root_window_host_linux.h
+++ b/ui/aura/root_window_host_linux.h
@@ -45,7 +45,7 @@ class RootWindowHostLinux : public RootWindowHost,
virtual void ReleaseCapture() OVERRIDE;
virtual void SetCursor(gfx::NativeCursor cursor_type) OVERRIDE;
virtual void ShowCursor(bool show) OVERRIDE;
- virtual gfx::Point QueryMouseLocation() OVERRIDE;
+ virtual bool QueryMouseLocation(gfx::Point* location_return) OVERRIDE;
virtual bool ConfineCursorToRootWindow() OVERRIDE;
virtual void UnConfineCursor() OVERRIDE;
virtual void MoveCursorTo(const gfx::Point& location) OVERRIDE;
diff --git a/ui/aura/root_window_host_mac.mm b/ui/aura/root_window_host_mac.mm
index 4c9f69a..1ac4f6c 100644
--- a/ui/aura/root_window_host_mac.mm
+++ b/ui/aura/root_window_host_mac.mm
@@ -41,7 +41,7 @@ class RootWindowHostMac : public RootWindowHost,
virtual void ReleaseCapture() OVERRIDE;
virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE;
virtual void ShowCursor(bool show) OVERRIDE;
- virtual gfx::Point QueryMouseLocation() OVERRIDE;
+ virtual bool QueryMouseLocation(gfx::Point* location_return) OVERRIDE;
virtual void MoveCursorTo(const gfx::Point& location) OVERRIDE;
virtual bool ConfineCursorToRootWindow() OVERRIDE;
virtual void UnConfineCursor() OVERRIDE;
@@ -158,8 +158,9 @@ void RootWindowHostMac::SetCursor(gfx::NativeCursor cursor) {
void RootWindowHostMac::ShowCursor(bool show) {
}
-gfx::Point RootWindowHostMac::QueryMouseLocation() {
- return gfx::Point();
+bool RootWindowHostMac::QueryMouseLocation(gfx::Point* location_return) {
+ *location_return = gfx::Point();
+ return true;
}
void RootWindowHostMac::MoveCursorTo(const gfx::Point& location) {
diff --git a/ui/aura/root_window_host_win.cc b/ui/aura/root_window_host_win.cc
index d04b352..1238b78 100644
--- a/ui/aura/root_window_host_win.cc
+++ b/ui/aura/root_window_host_win.cc
@@ -253,13 +253,16 @@ void RootWindowHostWin::ShowCursor(bool show) {
// NOTIMPLEMENTED();
}
-gfx::Point RootWindowHostWin::QueryMouseLocation() {
+bool RootWindowHostWin::QueryMouseLocation(gfx::Point* location_return) {
POINT pt;
GetCursorPos(&pt);
ScreenToClient(hwnd(), &pt);
const gfx::Size size = GetBounds().size();
- return gfx::Point(max(0, min(size.width(), static_cast<int>(pt.x))),
- max(0, min(size.height(), static_cast<int>(pt.y))));
+ *location_return =
+ gfx::Point(max(0, min(size.width(), static_cast<int>(pt.x))),
+ max(0, min(size.height(), static_cast<int>(pt.y))));
+ return (pt.x >= 0 && static_cast<int>(pt.x) < size.width() &&
+ pt.y >= 0 && static_cast<int>(pt.y) < size.height());
}
bool RootWindowHostWin::ConfineCursorToRootWindow() {
diff --git a/ui/aura/root_window_host_win.h b/ui/aura/root_window_host_win.h
index 50a9ee01..c8c49c7 100644
--- a/ui/aura/root_window_host_win.h
+++ b/ui/aura/root_window_host_win.h
@@ -33,7 +33,7 @@ class RootWindowHostWin : public RootWindowHost, public ui::WindowImpl {
virtual void ReleaseCapture() OVERRIDE;
virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE;
virtual void ShowCursor(bool show) OVERRIDE;
- virtual gfx::Point QueryMouseLocation() OVERRIDE;
+ virtual bool QueryMouseLocation(gfx::Point* location_return) OVERRIDE;
virtual bool ConfineCursorToRootWindow() OVERRIDE;
virtual void UnConfineCursor() OVERRIDE;
virtual void MoveCursorTo(const gfx::Point& location) OVERRIDE;
diff --git a/ui/aura/test/test_screen.cc b/ui/aura/test/test_screen.cc
index 5d0a497..b3aaf94 100644
--- a/ui/aura/test/test_screen.cc
+++ b/ui/aura/test/test_screen.cc
@@ -5,6 +5,7 @@
#include "ui/aura/test/test_screen.h"
#include "base/logging.h"
+#include "ui/aura/env.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
#include "ui/gfx/native_widget_types.h"
@@ -20,7 +21,7 @@ TestScreen::~TestScreen() {
}
gfx::Point TestScreen::GetCursorScreenPoint() {
- return root_window_->last_mouse_location();
+ return Env::GetInstance()->last_mouse_location();
}
gfx::NativeWindow TestScreen::GetWindowAtCursorScreenPoint() {
diff --git a/ui/aura/window.cc b/ui/aura/window.cc
index e4a3f38..12e7787 100644
--- a/ui/aura/window.cc
+++ b/ui/aura/window.cc
@@ -53,6 +53,10 @@ bool Window::TestApi::OwnsLayer() const {
return !!window_->layer_owner_.get();
}
+bool Window::TestApi::ContainsMouse() {
+ return window_->ContainsMouse();
+}
+
Window::Window(WindowDelegate* delegate)
: type_(client::WINDOW_TYPE_UNKNOWN),
owned_by_parent_(true),
@@ -261,7 +265,7 @@ gfx::Rect Window::GetBoundsInScreen() const {
void Window::SetTransform(const ui::Transform& transform) {
RootWindow* root_window = GetRootWindow();
bool contained_mouse = IsVisible() && root_window &&
- ContainsPointInRoot(root_window->last_mouse_location());
+ ContainsPointInRoot(root_window->GetLastMouseLocationInRoot());
layer()->SetTransform(transform);
if (root_window)
root_window->OnWindowTransformed(this, contained_mouse);
@@ -918,8 +922,8 @@ bool Window::ContainsMouse() {
bool contains_mouse = false;
if (IsVisible()) {
RootWindow* root_window = GetRootWindow();
- contains_mouse =
- root_window && ContainsPointInRoot(root_window->last_mouse_location());
+ contains_mouse = root_window &&
+ ContainsPointInRoot(root_window->GetLastMouseLocationInRoot());
}
return contains_mouse;
}
diff --git a/ui/aura/window.h b/ui/aura/window.h
index f6a52e1..535cd49 100644
--- a/ui/aura/window.h
+++ b/ui/aura/window.h
@@ -61,6 +61,7 @@ class AURA_EXPORT Window : public ui::LayerDelegate,
explicit TestApi(Window* window);
bool OwnsLayer() const;
+ bool ContainsMouse();
private:
TestApi();
diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc
index e13dcdb..b84157a 100644
--- a/ui/aura/window_unittest.cc
+++ b/ui/aura/window_unittest.cc
@@ -310,15 +310,27 @@ TEST_F(WindowTest, MoveCursorTo) {
RootWindow* root = root_window();
root->MoveCursorTo(gfx::Point(10, 10));
- EXPECT_EQ("10,10", root->last_mouse_location().ToString());
+ EXPECT_EQ("10,10", gfx::Screen::GetCursorScreenPoint().ToString());
w1->MoveCursorTo(gfx::Point(10, 10));
- EXPECT_EQ("20,20", root->last_mouse_location().ToString());
+ EXPECT_EQ("20,20", gfx::Screen::GetCursorScreenPoint().ToString());
w11->MoveCursorTo(gfx::Point(10, 10));
- EXPECT_EQ("25,25", root->last_mouse_location().ToString());
+ EXPECT_EQ("25,25", gfx::Screen::GetCursorScreenPoint().ToString());
w111->MoveCursorTo(gfx::Point(10, 10));
- EXPECT_EQ("30,30", root->last_mouse_location().ToString());
+ EXPECT_EQ("30,30", gfx::Screen::GetCursorScreenPoint().ToString());
w1111->MoveCursorTo(gfx::Point(10, 10));
- EXPECT_EQ("35,35", root->last_mouse_location().ToString());
+ EXPECT_EQ("35,35", gfx::Screen::GetCursorScreenPoint().ToString());
+}
+
+TEST_F(WindowTest, ContainsMouse) {
+ scoped_ptr<Window> w(
+ CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL));
+ w->Show();
+ Window::TestApi w_test_api(w.get());
+ RootWindow* root = root_window();
+ root->MoveCursorTo(gfx::Point(10, 10));
+ EXPECT_TRUE(w_test_api.ContainsMouse());
+ root->MoveCursorTo(gfx::Point(9, 10));
+ EXPECT_FALSE(w_test_api.ContainsMouse());
}
// Test Window::ConvertPointToWindow() with transform to root_window.
@@ -334,7 +346,7 @@ TEST_F(WindowTest, MoveCursorToWithTransformRootWindow) {
// TODO(yoshiki): fix this to build on Windows. See crbug.com/133413.OD
EXPECT_EQ("50,120", root->QueryMouseLocationForTest().ToString());
#endif
- EXPECT_EQ("10,10", root->last_mouse_location().ToString());
+ EXPECT_EQ("10,10", gfx::Screen::GetCursorScreenPoint().ToString());
}
// Tests Window::ConvertPointToWindow() with transform to non-root windows.
@@ -342,24 +354,23 @@ TEST_F(WindowTest, MoveCursorToWithTransformWindow) {
scoped_ptr<Window> w1(
CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL));
- RootWindow* root = root_window();
ui::Transform transform1;
transform1.ConcatScale(2, 2);
w1->SetTransform(transform1);
w1->MoveCursorTo(gfx::Point(10, 10));
- EXPECT_EQ("30,30", root->last_mouse_location().ToString());
+ EXPECT_EQ("30,30", gfx::Screen::GetCursorScreenPoint().ToString());
ui::Transform transform2;
transform2.ConcatTranslate(-10, 20);
w1->SetTransform(transform2);
w1->MoveCursorTo(gfx::Point(10, 10));
- EXPECT_EQ("10,40", root->last_mouse_location().ToString());
+ EXPECT_EQ("10,40", gfx::Screen::GetCursorScreenPoint().ToString());
ui::Transform transform3;
transform3.ConcatRotate(90.0f);
w1->SetTransform(transform3);
w1->MoveCursorTo(gfx::Point(5, 5));
- EXPECT_EQ("5,15", root->last_mouse_location().ToString());
+ EXPECT_EQ("5,15", gfx::Screen::GetCursorScreenPoint().ToString());
ui::Transform transform4;
transform4.ConcatScale(2, 5);
@@ -367,7 +378,7 @@ TEST_F(WindowTest, MoveCursorToWithTransformWindow) {
transform4.ConcatTranslate(100, 100);
w1->SetTransform(transform4);
w1->MoveCursorTo(gfx::Point(10, 10));
- EXPECT_EQ("60,130", root->last_mouse_location().ToString());
+ EXPECT_EQ("60,130", gfx::Screen::GetCursorScreenPoint().ToString());
}
// Test Window::ConvertPointToWindow() with complex transforms to both root and
@@ -400,7 +411,7 @@ TEST_F(WindowTest, MoveCursorToWithComplexTransform) {
// TODO(yoshiki): fix this to build on Windows. See crbug.com/133413.OD
EXPECT_EQ("11,47", root->QueryMouseLocationForTest().ToString());
#endif
- EXPECT_EQ("20,53", root->last_mouse_location().ToString());
+ EXPECT_EQ("20,53", gfx::Screen::GetCursorScreenPoint().ToString());
}
TEST_F(WindowTest, HitTest) {
diff --git a/ui/views/widget/tooltip_manager_aura.cc b/ui/views/widget/tooltip_manager_aura.cc
index 296d33a..c8d6342 100644
--- a/ui/views/widget/tooltip_manager_aura.cc
+++ b/ui/views/widget/tooltip_manager_aura.cc
@@ -54,7 +54,7 @@ void TooltipManagerAura::UpdateTooltip() {
aura::Window* window = native_widget_aura_->GetNativeView();
aura::RootWindow* root_window = window->GetRootWindow();
if (aura::client::GetTooltipClient(root_window)) {
- gfx::Point view_point = root_window->last_mouse_location();
+ gfx::Point view_point = root_window->GetLastMouseLocationInRoot();
aura::Window::ConvertPointToWindow(root_window, window, &view_point);
View* view = GetViewUnderPoint(view_point);
if (view) {
@@ -72,7 +72,7 @@ void TooltipManagerAura::TooltipTextChanged(View* view) {
aura::Window* window = native_widget_aura_->GetNativeView();
aura::RootWindow* root_window = window->GetRootWindow();
if (aura::client::GetTooltipClient(root_window)) {
- gfx::Point view_point = root_window->last_mouse_location();
+ gfx::Point view_point = root_window->GetLastMouseLocationInRoot();
aura::Window::ConvertPointToWindow(root_window, window, &view_point);
View* target = GetViewUnderPoint(view_point);
if (target != view)