Commit 08ec2170 authored by sadrul@chromium.org's avatar sadrul@chromium.org

ash: Fix touch-event handling for modal windows.

As long as touch-events are processed correctly for modal windows, the
gesture-events should automatically do the right thing. So gesture-events should
not need similar treatment.

BUG=136360
TEST=ash_unittests

Review URL: https://chromiumcodereview.appspot.com/10763004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@146008 0039d316-1c4b-4281-b951-d872f2087c98
parent 807aeeb1
...@@ -81,17 +81,14 @@ bool WindowModalityController::PreHandleKeyEvent(aura::Window* target, ...@@ -81,17 +81,14 @@ bool WindowModalityController::PreHandleKeyEvent(aura::Window* target,
bool WindowModalityController::PreHandleMouseEvent(aura::Window* target, bool WindowModalityController::PreHandleMouseEvent(aura::Window* target,
aura::MouseEvent* event) { aura::MouseEvent* event) {
aura::Window* modal_transient_child = wm::GetWindowModalTransient(target); return ProcessLocatedEvent(target, event);
if (modal_transient_child && event->type() == ui::ET_MOUSE_PRESSED)
wm::ActivateWindow(modal_transient_child);
return !!modal_transient_child;
} }
ui::TouchStatus WindowModalityController::PreHandleTouchEvent( ui::TouchStatus WindowModalityController::PreHandleTouchEvent(
aura::Window* target, aura::Window* target,
aura::TouchEvent* event) { aura::TouchEvent* event) {
// TODO: make touch work with modals. return ProcessLocatedEvent(target, event) ? ui::TOUCH_STATUS_CONTINUE :
return ui::TOUCH_STATUS_UNKNOWN; ui::TOUCH_STATUS_UNKNOWN;
} }
ui::GestureStatus WindowModalityController::PreHandleGestureEvent( ui::GestureStatus WindowModalityController::PreHandleGestureEvent(
...@@ -124,5 +121,15 @@ void WindowModalityController::OnWindowDestroyed(aura::Window* window) { ...@@ -124,5 +121,15 @@ void WindowModalityController::OnWindowDestroyed(aura::Window* window) {
window->RemoveObserver(this); window->RemoveObserver(this);
} }
bool WindowModalityController::ProcessLocatedEvent(aura::Window* target,
aura::LocatedEvent* event) {
aura::Window* modal_transient_child = wm::GetWindowModalTransient(target);
if (modal_transient_child && (event->type() == ui::ET_MOUSE_PRESSED ||
event->type() == ui::ET_TOUCH_PRESSED)) {
wm::ActivateWindow(modal_transient_child);
}
return !!modal_transient_child;
}
} // namespace internal } // namespace internal
} // namespace ash } // namespace ash
...@@ -14,6 +14,10 @@ ...@@ -14,6 +14,10 @@
#include "ui/aura/event_filter.h" #include "ui/aura/event_filter.h"
#include "ui/aura/window_observer.h" #include "ui/aura/window_observer.h"
namespace aura {
class LocatedEvent;
}
namespace ash { namespace ash {
namespace wm { namespace wm {
...@@ -54,6 +58,11 @@ class WindowModalityController : public aura::EventFilter, ...@@ -54,6 +58,11 @@ class WindowModalityController : public aura::EventFilter,
virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE; virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE;
private: private:
// Processes a mouse/touch event, and returns true if the event should be
// consumed.
bool ProcessLocatedEvent(aura::Window* target,
aura::LocatedEvent* event);
std::vector<aura::Window*> windows_; std::vector<aura::Window*> windows_;
DISALLOW_COPY_AND_ASSIGN(WindowModalityController); DISALLOW_COPY_AND_ASSIGN(WindowModalityController);
......
...@@ -281,6 +281,66 @@ TEST_F(WindowModalityControllerTest, ChangeCapture) { ...@@ -281,6 +281,66 @@ TEST_F(WindowModalityControllerTest, ChangeCapture) {
EXPECT_FALSE(view->got_press()); EXPECT_FALSE(view->got_press());
} }
class TouchTrackerWindowDelegate : public aura::test::TestWindowDelegate {
public:
TouchTrackerWindowDelegate() : received_touch_(false) {}
virtual ~TouchTrackerWindowDelegate() {}
void reset() {
received_touch_ = false;
}
bool received_touch() const { return received_touch_; }
private:
// Overridden from aura::test::TestWindowDelegate.
virtual ui::TouchStatus OnTouchEvent(aura::TouchEvent* event) OVERRIDE {
received_touch_ = true;
return aura::test::TestWindowDelegate::OnTouchEvent(event);
}
bool received_touch_;
DISALLOW_COPY_AND_ASSIGN(TouchTrackerWindowDelegate);
};
// Modality should prevent events from being passed to the transient parent.
TEST_F(WindowModalityControllerTest, TouchEvent) {
TouchTrackerWindowDelegate d1;
scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate(&d1,
-1, gfx::Rect(0, 0, 100, 100), NULL));
TouchTrackerWindowDelegate d11;
scoped_ptr<aura::Window> w11(aura::test::CreateTestWindowWithDelegate(&d11,
-11, gfx::Rect(20, 20, 50, 50), NULL));
w1->AddTransientChild(w11.get());
d1.reset();
d11.reset();
{
// Clicking a point within w1 should activate that window.
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
gfx::Point(10, 10));
generator.PressMoveAndReleaseTouchTo(gfx::Point(10, 10));
EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
EXPECT_TRUE(d1.received_touch());
EXPECT_FALSE(d11.received_touch());
}
w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
d1.reset();
d11.reset();
{
// Clicking a point within w1 should activate w11.
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
gfx::Point(10, 10));
generator.PressMoveAndReleaseTouchTo(gfx::Point(10, 10));
EXPECT_TRUE(wm::IsActiveWindow(w11.get()));
EXPECT_FALSE(d1.received_touch());
EXPECT_FALSE(d11.received_touch());
}
}
} // namespace internal } // namespace internal
} // namespace ash } // namespace ash
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