This source file includes following definitions.
- GetTopmostTransientParent
- browser_view_with_modal_dialog_
- ShouldStopPropagationTo
- OnKeyEvent
- OnMouseEvent
- OnScrollEvent
- OnTouchEvent
#include "chrome/browser/ui/views/javascript_app_modal_event_blocker_x11.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "ui/aura/env.h"
#include "ui/aura/window.h"
#include "ui/events/event.h"
#include "ui/wm/core/window_animations.h"
#include "ui/wm/core/window_util.h"
namespace {
aura::Window* GetTopmostTransientParent(aura::Window* window) {
aura::Window* topmost = wm::GetToplevelWindow(window);
while (topmost && wm::GetTransientParent(topmost))
topmost = wm::GetToplevelWindow(wm::GetTransientParent(topmost));
return topmost;
}
}
JavascriptAppModalEventBlockerX11::JavascriptAppModalEventBlockerX11(
aura::Window* modal_window)
: modal_window_(modal_window),
browser_view_with_modal_dialog_(NULL) {
aura::Window* topmost_transient_parent =
GetTopmostTransientParent(modal_window);
browser_view_with_modal_dialog_ =
BrowserView::GetBrowserViewForNativeWindow(topmost_transient_parent);
aura::Env::GetInstance()->PrependPreTargetHandler(this);
}
JavascriptAppModalEventBlockerX11::~JavascriptAppModalEventBlockerX11() {
aura::Env::GetInstance()->RemovePreTargetHandler(this);
}
bool JavascriptAppModalEventBlockerX11::ShouldStopPropagationTo(
ui::EventTarget* target) {
aura::Window* window =
GetTopmostTransientParent(static_cast<aura::Window*>(target));
if (!window)
return false;
BrowserView* browser_view =
BrowserView::GetBrowserViewForNativeWindow(window);
return browser_view && browser_view != browser_view_with_modal_dialog_;
}
void JavascriptAppModalEventBlockerX11::OnKeyEvent(ui::KeyEvent* event) {
if (ShouldStopPropagationTo(event->target()))
event->StopPropagation();
}
void JavascriptAppModalEventBlockerX11::OnMouseEvent(ui::MouseEvent* event) {
if (event->type() != ui::ET_MOUSE_CAPTURE_CHANGED &&
ShouldStopPropagationTo(event->target())) {
if (event->type() == ui::ET_MOUSE_PRESSED)
wm::AnimateWindow(modal_window_, wm::WINDOW_ANIMATION_TYPE_BOUNCE);
event->StopPropagation();
}
}
void JavascriptAppModalEventBlockerX11::OnScrollEvent(ui::ScrollEvent* event) {
if (ShouldStopPropagationTo(event->target()))
event->StopPropagation();
}
void JavascriptAppModalEventBlockerX11::OnTouchEvent(ui::TouchEvent* event) {
if (event->type() != ui::ET_TOUCH_CANCELLED &&
ShouldStopPropagationTo(event->target())) {
if (event->type() == ui::ET_TOUCH_PRESSED)
wm::AnimateWindow(modal_window_, wm::WINDOW_ANIMATION_TYPE_BOUNCE);
event->StopPropagation();
}
}