Commit ccf2231b authored by joi@chromium.org's avatar joi@chromium.org

Revert 113183 - Revert 113177 - process all ui events before posting closure...

Revert 113183 - Revert 113177 - process all ui events before posting closure because menu depends on ui events to quit.
 Add new RunClosureAfterAllPendingUIEvents for toolkit views.

BUG=104359
TEST=BookmarkBarViewTest in interactive_ui_tests will pass


Review URL: http://codereview.chromium.org/8799020

Reason for revert: http://build.chromium.org/p/chromium.chromiumos/builders/Linux%20ChromeOS%20Aura/builds/1514
Reason for un-revert: The test succeeded before the original revert, looks like it's just flaky.

TBR=oshima@chromium.org
Review URL: http://codereview.chromium.org/8821012

TBR=joi@chromium.org
Review URL: http://codereview.chromium.org/8820010

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113189 0039d316-1c4b-4281-b951-d872f2087c98
parent 1def7bde
...@@ -97,6 +97,11 @@ void MoveMouseToCenterAndPress( ...@@ -97,6 +97,11 @@ void MoveMouseToCenterAndPress(
int state, int state,
const base::Closure& task); const base::Closure& task);
#if defined(TOOLKIT_VIEWS)
// Runs |closure| after processing all pending ui events.
void RunClosureAfterAllPendingUIEvents(const base::Closure& closure);
#endif
} // ui_controls } // ui_controls
#endif // CHROME_BROWSER_AUTOMATION_UI_CONTROLS_H_ #endif // CHROME_BROWSER_AUTOMATION_UI_CONTROLS_H_
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/browser/automation/ui_controls.h" #include "chrome/browser/automation/ui_controls.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/message_loop.h"
#include "chrome/browser/automation/ui_controls_internal.h" #include "chrome/browser/automation/ui_controls_internal.h"
#include "ui/aura/desktop.h" #include "ui/aura/desktop.h"
#include "ui/views/view.h" #include "ui/views/view.h"
...@@ -69,4 +70,9 @@ void MoveMouseToCenterAndPress(views::View* view, ...@@ -69,4 +70,9 @@ void MoveMouseToCenterAndPress(views::View* view,
SendMouseEventsNotifyWhenDone(button, state, task); SendMouseEventsNotifyWhenDone(button, state, task);
} }
void RunClosureAfterAllPendingUIEvents(const base::Closure& task) {
// On windows, posting UI events is synchronous so just post the closure.
MessageLoopForUI::current()->PostTask(FROM_HERE, task);
}
} // namespace ui_controls } // namespace ui_controls
...@@ -70,22 +70,6 @@ bool Matcher(const base::NativeEvent& event) { ...@@ -70,22 +70,6 @@ bool Matcher(const base::NativeEvent& event) {
event->xclient.message_type == MarkerEventAtom(); event->xclient.message_type == MarkerEventAtom();
} }
void RunClosureAfterEvents(const base::Closure closure) {
if (closure.is_null())
return;
static XEvent* marker_event = NULL;
if (!marker_event) {
marker_event = new XEvent();
marker_event->xclient.type = ClientMessage;
marker_event->xclient.display = NULL;
marker_event->xclient.window = None;
marker_event->xclient.format = 8;
}
marker_event->xclient.message_type = MarkerEventAtom();
aura::Desktop::GetInstance()->PostNativeEvent(marker_event);
new EventWaiter(closure, &Matcher);
}
} // namespace } // namespace
namespace ui_controls { namespace ui_controls {
...@@ -133,9 +117,7 @@ bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window, ...@@ -133,9 +117,7 @@ bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window,
SetMaskAndKeycodeThenSend(&xevent, ShiftMask, XK_Shift_L); SetMaskAndKeycodeThenSend(&xevent, ShiftMask, XK_Shift_L);
if (alt) if (alt)
SetMaskAndKeycodeThenSend(&xevent, Mod1Mask, XK_Alt_L); SetMaskAndKeycodeThenSend(&xevent, Mod1Mask, XK_Alt_L);
xevent.xkey.keycode = xevent.xkey.keycode = ui::XKeysymForWindowsKeyCode(key, shift);
XKeysymToKeycode(base::MessagePumpX::GetDefaultXDisplay(),
ui::XKeysymForWindowsKeyCode(key, shift));
aura::Desktop::GetInstance()->PostNativeEvent(&xevent); aura::Desktop::GetInstance()->PostNativeEvent(&xevent);
// Send key release events. // Send key release events.
...@@ -148,7 +130,7 @@ bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window, ...@@ -148,7 +130,7 @@ bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window,
if (control) if (control)
SetKeycodeAndSendThenUnmask(&xevent, ControlMask, XK_Control_L); SetKeycodeAndSendThenUnmask(&xevent, ControlMask, XK_Control_L);
DCHECK(!xevent.xkey.state); DCHECK(!xevent.xkey.state);
RunClosureAfterEvents(closure); RunClosureAfterAllPendingUIEvents(closure);
return true; return true;
} }
...@@ -165,7 +147,7 @@ bool SendMouseMoveNotifyWhenDone(long x, long y, const base::Closure& closure) { ...@@ -165,7 +147,7 @@ bool SendMouseMoveNotifyWhenDone(long x, long y, const base::Closure& closure) {
xmotion->same_screen = True; xmotion->same_screen = True;
// Desktop will take care of other necessary fields. // Desktop will take care of other necessary fields.
aura::Desktop::GetInstance()->PostNativeEvent(&xevent); aura::Desktop::GetInstance()->PostNativeEvent(&xevent);
RunClosureAfterEvents(closure); RunClosureAfterAllPendingUIEvents(closure);
return false; return false;
} }
...@@ -208,7 +190,7 @@ bool SendMouseEventsNotifyWhenDone(MouseButton type, ...@@ -208,7 +190,7 @@ bool SendMouseEventsNotifyWhenDone(MouseButton type,
xevent.xbutton.type = ButtonRelease; xevent.xbutton.type = ButtonRelease;
desktop->PostNativeEvent(&xevent); desktop->PostNativeEvent(&xevent);
} }
RunClosureAfterEvents(closure); RunClosureAfterAllPendingUIEvents(closure);
return false; return false;
} }
...@@ -226,4 +208,20 @@ void MoveMouseToCenterAndPress(views::View* view, MouseButton button, ...@@ -226,4 +208,20 @@ void MoveMouseToCenterAndPress(views::View* view, MouseButton button,
SendMouseEventsNotifyWhenDone(button, state, closure); SendMouseEventsNotifyWhenDone(button, state, closure);
} }
void RunClosureAfterAllPendingUIEvents(const base::Closure& closure) {
if (closure.is_null())
return;
static XEvent* marker_event = NULL;
if (!marker_event) {
marker_event = new XEvent();
marker_event->xclient.type = ClientMessage;
marker_event->xclient.display = NULL;
marker_event->xclient.window = None;
marker_event->xclient.format = 8;
}
marker_event->xclient.message_type = MarkerEventAtom();
aura::Desktop::GetInstance()->PostNativeEvent(marker_event);
new EventWaiter(closure, &Matcher);
}
} // namespace ui_controls } // namespace ui_controls
...@@ -310,4 +310,13 @@ void MoveMouseToCenterAndPress(GtkWidget* widget, ...@@ -310,4 +310,13 @@ void MoveMouseToCenterAndPress(GtkWidget* widget,
} }
#endif #endif
#if defined(TOOLKIT_VIEWS)
void RunClosureAfterAllPendingUIEvents(const base::Closure& task) {
// Send noop event and run task.
int x, y;
gdk_window_at_pointer(&x, &y);
SendMouseMoveNotifyWhenDone(x, y, task);
}
#endif
} // namespace ui_controls } // namespace ui_controls
...@@ -27,6 +27,7 @@ bool SendMouseMoveImpl(long x, long y, const base::Closure& task); ...@@ -27,6 +27,7 @@ bool SendMouseMoveImpl(long x, long y, const base::Closure& task);
bool SendMouseEventsImpl(MouseButton type, bool SendMouseEventsImpl(MouseButton type,
int state, int state,
const base::Closure& task); const base::Closure& task);
void RunClosureAfterAllPendingUITasksImpl(const base::Closure& task);
#endif #endif
} // namespace internal } // namespace internal
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/browser/automation/ui_controls.h" #include "chrome/browser/automation/ui_controls.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/message_loop.h"
#include "chrome/browser/automation/ui_controls_internal.h" #include "chrome/browser/automation/ui_controls_internal.h"
#include "ui/gfx/point.h" #include "ui/gfx/point.h"
#include "ui/views/view.h" #include "ui/views/view.h"
...@@ -65,4 +66,9 @@ void MoveMouseToCenterAndPress(views::View* view, ...@@ -65,4 +66,9 @@ void MoveMouseToCenterAndPress(views::View* view,
SendMouseEventsNotifyWhenDone(button, state, task); SendMouseEventsNotifyWhenDone(button, state, task);
} }
void RunClosureAfterAllPendingUIEvents(const base::Closure& closure) {
// On windows, posting UI events is synchronous so just post the closure.
MessageLoopForUI::current()->PostTask(FROM_HERE, closure);
}
} // ui_controls } // ui_controls
...@@ -70,9 +70,11 @@ void ViewEventTestBase::Done() { ...@@ -70,9 +70,11 @@ void ViewEventTestBase::Done() {
PostMessage(window_->GetNativeWindow(), WM_USER, 0, 0); PostMessage(window_->GetNativeWindow(), WM_USER, 0, 0);
#endif #endif
// If we're in a nested message loop, as is the case with menus, we need // If we're in a nested message loop, as is the case with menus, we
// to quit twice. The second quit does that for us. // need to quit twice. The second quit does that for us. Finish all
MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); // pending UI events before posting closure because events it may be
// executed before UI events are executed.
ui_controls::RunClosureAfterAllPendingUIEvents(MessageLoop::QuitClosure());
} }
void ViewEventTestBase::SetUp() { void ViewEventTestBase::SetUp() {
......
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