diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-22 22:09:08 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-22 22:09:08 +0000 |
commit | a5e71c95acee9dce58d009ad60fabfba2bfc5db9 (patch) | |
tree | 4f908bfc8d913cee290189b264a8c8fed20181f4 /ui/aura | |
parent | 64c7184cbc0095b18dd2ae0f92074c35ac884df3 (diff) | |
download | chromium_src-a5e71c95acee9dce58d009ad60fabfba2bfc5db9.zip chromium_src-a5e71c95acee9dce58d009ad60fabfba2bfc5db9.tar.gz chromium_src-a5e71c95acee9dce58d009ad60fabfba2bfc5db9.tar.bz2 |
Update capture on all root windows
This is necessary to properly forward all events on all root windows
to the captured window and release when capture is cleared.
Original plan was is to do native capture, but it turns out to be difficult
(at least on chromeos/X11) because we need to warp the pointer to other window and handle mouse event there to support multiple displays layouts (see http://codereview.chromium.org/10581008/)
This also update Window::ConvertPointToWindow so that it accepts
windows on different root windows.
BUG=123160
TEST=ExtendedDesktopText.{Capture|ConvertPoint}
Review URL: https://chromiumcodereview.appspot.com/10638008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@143722 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/aura')
-rw-r--r-- | ui/aura/root_window.cc | 16 | ||||
-rw-r--r-- | ui/aura/test/test_window_delegate.cc | 80 | ||||
-rw-r--r-- | ui/aura/test/test_window_delegate.h | 35 | ||||
-rw-r--r-- | ui/aura/window.cc | 17 | ||||
-rw-r--r-- | ui/aura/window_unittest.cc | 89 |
5 files changed, 164 insertions, 73 deletions
diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc index ba23cd8..6b82209 100644 --- a/ui/aura/root_window.cc +++ b/ui/aura/root_window.cc @@ -626,10 +626,8 @@ FocusManager* RootWindow::GetFocusManager() { void RootWindow::UpdateCapture(Window* old_capture, Window* new_capture) { - DCHECK(!new_capture || new_capture->GetRootWindow() == this); - DCHECK(!old_capture || old_capture->GetRootWindow() == this); - - if (old_capture && old_capture->delegate()) { + if (old_capture && old_capture->GetRootWindow() == this && + old_capture->delegate()) { // Send a capture changed event with bogus location data. MouseEvent event( ui::ET_MOUSE_CAPTURE_CHANGED, gfx::Point(), gfx::Point(), 0); @@ -638,11 +636,19 @@ void RootWindow::UpdateCapture(Window* old_capture, old_capture->delegate()->OnCaptureLost(); } + // Reset the mouse_moved_handler_ if the mouse_moved_handler_ belongs + // to another root window when losing the capture. + if (mouse_moved_handler_ && old_capture && + old_capture->Contains(mouse_moved_handler_) && + old_capture->GetRootWindow() != this) { + mouse_moved_handler_ = NULL; + } + if (new_capture) { // Make all subsequent mouse events and touch go to the capture window. We // shouldn't need to send an event here as OnCaptureLost should take care of // that. - if (mouse_moved_handler_ || mouse_button_flags_ != 0) + if (mouse_moved_handler_ || Env::GetInstance()->is_mouse_button_down()) mouse_moved_handler_ = new_capture; } else { // Make sure mouse_moved_handler gets updated. diff --git a/ui/aura/test/test_window_delegate.cc b/ui/aura/test/test_window_delegate.cc index 4be062d..8fc11ed 100644 --- a/ui/aura/test/test_window_delegate.cc +++ b/ui/aura/test/test_window_delegate.cc @@ -4,6 +4,7 @@ #include "ui/aura/test/test_window_delegate.h" +#include "base/stringprintf.h" #include "ui/aura/event.h" #include "ui/aura/window.h" #include "ui/base/hit_test.h" @@ -133,5 +134,84 @@ void MaskedWindowDelegate::GetHitTestMask(gfx::Path* mask) const { mask->addRect(RectToSkRect(mask_rect_)); } +//////////////////////////////////////////////////////////////////////////////// +// EventCountDelegate + +EventCountDelegate::EventCountDelegate() + : mouse_enter_count_(0), + mouse_move_count_(0), + mouse_leave_count_(0), + mouse_press_count_(0), + mouse_release_count_(0), + key_press_count_(0), + key_release_count_(0) { +} + +bool EventCountDelegate::OnMouseEvent(MouseEvent* event) { + switch (event->type()) { + case ui::ET_MOUSE_MOVED: + mouse_move_count_++; + break; + case ui::ET_MOUSE_ENTERED: + mouse_enter_count_++; + break; + case ui::ET_MOUSE_EXITED: + mouse_leave_count_++; + break; + case ui::ET_MOUSE_PRESSED: + mouse_press_count_++; + break; + case ui::ET_MOUSE_RELEASED: + mouse_release_count_++; + break; + default: + break; + } + return false; +} + +bool EventCountDelegate::OnKeyEvent(KeyEvent* event) { + switch (event->type()) { + case ui::ET_KEY_PRESSED: + key_press_count_++; + break; + case ui::ET_KEY_RELEASED: + key_release_count_++; + default: + break; + } + return false; +} + +std::string EventCountDelegate::GetMouseMotionCountsAndReset() { + std::string result = StringPrintf("%d %d %d", + mouse_enter_count_, + mouse_move_count_, + mouse_leave_count_); + mouse_enter_count_ = 0; + mouse_move_count_ = 0; + mouse_leave_count_ = 0; + return result; +} + +std::string EventCountDelegate::GetMouseButtonCountsAndReset() { + std::string result = StringPrintf("%d %d", + mouse_press_count_, + mouse_release_count_); + mouse_press_count_ = 0; + mouse_release_count_ = 0; + return result; +} + + +std::string EventCountDelegate::GetKeyCountsAndReset() { + std::string result = StringPrintf("%d %d", + key_press_count_, + key_release_count_); + key_press_count_ = 0; + key_release_count_ = 0; + return result; +} + } // namespace test } // namespace aura diff --git a/ui/aura/test/test_window_delegate.h b/ui/aura/test/test_window_delegate.h index 4eb8e2d..29be9fa 100644 --- a/ui/aura/test/test_window_delegate.h +++ b/ui/aura/test/test_window_delegate.h @@ -6,6 +6,8 @@ #define UI_AURA_TEST_TEST_WINDOW_DELEGATE_H_ #pragma once +#include <string> + #include "base/compiler_specific.h" #include "third_party/skia/include/core/SkColor.h" #include "ui/aura/window_delegate.h" @@ -91,6 +93,39 @@ class MaskedWindowDelegate : public TestWindowDelegate { DISALLOW_COPY_AND_ASSIGN(MaskedWindowDelegate); }; +// Keeps track of mouse/key events. +class EventCountDelegate : public TestWindowDelegate { + public: + EventCountDelegate(); + + // Overridden from TestWindowDelegate: + virtual bool OnMouseEvent(MouseEvent* event) OVERRIDE; + virtual bool OnKeyEvent(KeyEvent* event) OVERRIDE; + + // Returns the counts of mouse motion events in the + // form of "<enter> <move> <leave>". + std::string GetMouseMotionCountsAndReset(); + + // Returns the counts of mouse button events in the + // form of "<press> <release>". + std::string GetMouseButtonCountsAndReset(); + + // Returns the counts of key events in the form of + // "<press> <release>". + std::string GetKeyCountsAndReset(); + + private: + int mouse_enter_count_; + int mouse_move_count_; + int mouse_leave_count_; + int mouse_press_count_; + int mouse_release_count_; + int key_press_count_; + int key_release_count_; + + DISALLOW_COPY_AND_ASSIGN(EventCountDelegate); +}; + } // namespace test } // namespace aura diff --git a/ui/aura/window.cc b/ui/aura/window.cc index 6d6230c..f010a7a 100644 --- a/ui/aura/window.cc +++ b/ui/aura/window.cc @@ -405,7 +405,22 @@ void Window::ConvertPointToWindow(const Window* source, gfx::Point* point) { if (!source) return; - ui::Layer::ConvertPointToLayer(source->layer(), target->layer(), point); + if (source->GetRootWindow() != target->GetRootWindow()) { + const gfx::Point source_origin = + gfx::Screen::GetDisplayNearestWindow( + const_cast<Window*>(source)).bounds().origin(); + const gfx::Point target_origin = + gfx::Screen::GetDisplayNearestWindow( + const_cast<Window*>(target)).bounds().origin(); + ui::Layer::ConvertPointToLayer( + source->layer(), source->GetRootWindow()->layer(), point); + const gfx::Point offset = source_origin.Subtract(target_origin); + point->Offset(offset.x(), offset.y()); + ui::Layer::ConvertPointToLayer( + target->GetRootWindow()->layer(), target->layer(), point); + } else { + ui::Layer::ConvertPointToLayer(source->layer(), target->layer(), point); + } } void Window::MoveCursorTo(const gfx::Point& point_in_window) { diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc index cd6384e..d955719 100644 --- a/ui/aura/window_unittest.cc +++ b/ui/aura/window_unittest.cc @@ -229,51 +229,6 @@ class GestureTrackPositionDelegate : public TestWindowDelegate { DISALLOW_COPY_AND_ASSIGN(GestureTrackPositionDelegate); }; -// Keeps track of mouse events. -class MouseTrackingDelegate : public TestWindowDelegate { - public: - MouseTrackingDelegate() - : mouse_enter_count_(0), - mouse_move_count_(0), - mouse_leave_count_(0) { - } - - virtual bool OnMouseEvent(MouseEvent* event) OVERRIDE { - switch (event->type()) { - case ui::ET_MOUSE_MOVED: - mouse_move_count_++; - break; - case ui::ET_MOUSE_ENTERED: - mouse_enter_count_++; - break; - case ui::ET_MOUSE_EXITED: - mouse_leave_count_++; - break; - default: - break; - } - return false; - } - - std::string GetMouseCountsAndReset() { - std::string result = StringPrintf("%d %d %d", - mouse_enter_count_, - mouse_move_count_, - mouse_leave_count_); - mouse_enter_count_ = 0; - mouse_move_count_ = 0; - mouse_leave_count_ = 0; - return result; - } - - private: - int mouse_enter_count_; - int mouse_move_count_; - int mouse_leave_count_; - - DISALLOW_COPY_AND_ASSIGN(MouseTrackingDelegate); -}; - base::TimeDelta getTime() { return base::Time::NowFromSystemTime() - base::Time(); } @@ -1900,73 +1855,73 @@ TEST_F(WindowTest, MouseEventsOnWindowChange) { EventGenerator generator(root_window()); generator.MoveMouseTo(50, 50); - MouseTrackingDelegate d1; + EventCountDelegate d1; scoped_ptr<Window> w1(CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(0, 0, 100, 100), root_window())); RunAllPendingInMessageLoop(); // The format of result is "Enter/Mouse/Leave". - EXPECT_EQ("1 1 0", d1.GetMouseCountsAndReset()); + EXPECT_EQ("1 1 0", d1.GetMouseMotionCountsAndReset()); // Adding new window. - MouseTrackingDelegate d11; + EventCountDelegate d11; scoped_ptr<Window> w11(CreateTestWindowWithDelegate( &d11, 1, gfx::Rect(0, 0, 100, 100), w1.get())); RunAllPendingInMessageLoop(); - EXPECT_EQ("0 0 1", d1.GetMouseCountsAndReset()); - EXPECT_EQ("1 1 0", d11.GetMouseCountsAndReset()); + EXPECT_EQ("0 0 1", d1.GetMouseMotionCountsAndReset()); + EXPECT_EQ("1 1 0", d11.GetMouseMotionCountsAndReset()); // Move bounds. w11->SetBounds(gfx::Rect(0, 0, 10, 10)); RunAllPendingInMessageLoop(); - EXPECT_EQ("1 1 0", d1.GetMouseCountsAndReset()); - EXPECT_EQ("0 0 1", d11.GetMouseCountsAndReset()); + EXPECT_EQ("1 1 0", d1.GetMouseMotionCountsAndReset()); + EXPECT_EQ("0 0 1", d11.GetMouseMotionCountsAndReset()); w11->SetBounds(gfx::Rect(0, 0, 60, 60)); RunAllPendingInMessageLoop(); - EXPECT_EQ("0 0 1", d1.GetMouseCountsAndReset()); - EXPECT_EQ("1 1 0", d11.GetMouseCountsAndReset()); + EXPECT_EQ("0 0 1", d1.GetMouseMotionCountsAndReset()); + EXPECT_EQ("1 1 0", d11.GetMouseMotionCountsAndReset()); // Detach, then re-attach. w1->RemoveChild(w11.get()); RunAllPendingInMessageLoop(); - EXPECT_EQ("1 1 0", d1.GetMouseCountsAndReset()); + EXPECT_EQ("1 1 0", d1.GetMouseMotionCountsAndReset()); // Window is detached, so no event is set. - EXPECT_EQ("0 0 0", d11.GetMouseCountsAndReset()); + EXPECT_EQ("0 0 0", d11.GetMouseMotionCountsAndReset()); w1->AddChild(w11.get()); RunAllPendingInMessageLoop(); - EXPECT_EQ("0 0 1", d1.GetMouseCountsAndReset()); + EXPECT_EQ("0 0 1", d1.GetMouseMotionCountsAndReset()); // Window is detached, so no event is set. - EXPECT_EQ("1 1 0", d11.GetMouseCountsAndReset()); + EXPECT_EQ("1 1 0", d11.GetMouseMotionCountsAndReset()); // Visibility Change w11->Hide(); RunAllPendingInMessageLoop(); - EXPECT_EQ("1 1 0", d1.GetMouseCountsAndReset()); - EXPECT_EQ("0 0 0", d11.GetMouseCountsAndReset()); + EXPECT_EQ("1 1 0", d1.GetMouseMotionCountsAndReset()); + EXPECT_EQ("0 0 0", d11.GetMouseMotionCountsAndReset()); w11->Show(); RunAllPendingInMessageLoop(); - EXPECT_EQ("0 0 1", d1.GetMouseCountsAndReset()); - EXPECT_EQ("1 1 0", d11.GetMouseCountsAndReset()); + EXPECT_EQ("0 0 1", d1.GetMouseMotionCountsAndReset()); + EXPECT_EQ("1 1 0", d11.GetMouseMotionCountsAndReset()); // Transform: move d11 by 100 100. ui::Transform transform; transform.ConcatTranslate(100, 100); w11->SetTransform(transform); RunAllPendingInMessageLoop(); - EXPECT_EQ("1 1 0", d1.GetMouseCountsAndReset()); - EXPECT_EQ("0 0 1", d11.GetMouseCountsAndReset()); + EXPECT_EQ("1 1 0", d1.GetMouseMotionCountsAndReset()); + EXPECT_EQ("0 0 1", d11.GetMouseMotionCountsAndReset()); w11->SetTransform(ui::Transform()); RunAllPendingInMessageLoop(); - EXPECT_EQ("0 0 1", d1.GetMouseCountsAndReset()); - EXPECT_EQ("1 1 0", d11.GetMouseCountsAndReset()); + EXPECT_EQ("0 0 1", d1.GetMouseMotionCountsAndReset()); + EXPECT_EQ("1 1 0", d11.GetMouseMotionCountsAndReset()); // Closing a window. w11.reset(); RunAllPendingInMessageLoop(); - EXPECT_EQ("1 1 0", d1.GetMouseCountsAndReset()); + EXPECT_EQ("1 1 0", d1.GetMouseMotionCountsAndReset()); } #endif |