Commit 1f909ee8 authored by pkotwicz's avatar pkotwicz Committed by Commit bot

Close the select box when the parent RWHVA loses focus

BUG=422264,414550
TEST=RenderWidgetHostViewAuraTest.PopupClosesWhenParentLosesFocus

Review URL: https://codereview.chromium.org/652793003

Cr-Commit-Position: refs/heads/master@{#301108}
parent 3ce5e8c9
...@@ -387,8 +387,7 @@ void RenderWidgetHostViewAura::ApplyEventFilterForPopupExit( ...@@ -387,8 +387,7 @@ void RenderWidgetHostViewAura::ApplyEventFilterForPopupExit(
target != popup_parent_host_view_->window_)) { target != popup_parent_host_view_->window_)) {
// Note: popup_parent_host_view_ may be NULL when there are multiple // Note: popup_parent_host_view_ may be NULL when there are multiple
// popup children per view. See: RenderWidgetHostViewAura::InitAsPopup(). // popup children per view. See: RenderWidgetHostViewAura::InitAsPopup().
in_shutdown_ = true; Shutdown();
host_->Shutdown();
} }
} }
...@@ -1828,10 +1827,7 @@ void RenderWidgetHostViewAura::OnKeyEvent(ui::KeyEvent* event) { ...@@ -1828,10 +1827,7 @@ void RenderWidgetHostViewAura::OnKeyEvent(ui::KeyEvent* event) {
} }
} }
} }
if (!in_shutdown_) { Shutdown();
in_shutdown_ = true;
host_->Shutdown();
}
} else { } else {
if (event->key_code() == ui::VKEY_RETURN) { if (event->key_code() == ui::VKEY_RETURN) {
// Do not forward return key release events if no press event was handled. // Do not forward return key release events if no press event was handled.
...@@ -2221,9 +2217,15 @@ void RenderWidgetHostViewAura::OnWindowFocused(aura::Window* gained_focus, ...@@ -2221,9 +2217,15 @@ void RenderWidgetHostViewAura::OnWindowFocused(aura::Window* gained_focus,
return; return;
} }
#endif #endif
in_shutdown_ = true; Shutdown();
host_->Shutdown(); return;
} }
// Close the child popup window if we lose focus (e.g. due to a JS alert or
// system modal dialog). This is particularly important if
// |popup_child_host_view_| has mouse capture.
if (popup_child_host_view_)
popup_child_host_view_->Shutdown();
} }
} }
...@@ -2314,6 +2316,13 @@ ui::InputMethod* RenderWidgetHostViewAura::GetInputMethod() const { ...@@ -2314,6 +2316,13 @@ ui::InputMethod* RenderWidgetHostViewAura::GetInputMethod() const {
return root_window->GetProperty(aura::client::kRootWindowInputMethodKey); return root_window->GetProperty(aura::client::kRootWindowInputMethodKey);
} }
void RenderWidgetHostViewAura::Shutdown() {
if (!in_shutdown_) {
in_shutdown_ = true;
host_->Shutdown();
}
}
bool RenderWidgetHostViewAura::NeedsInputGrab() { bool RenderWidgetHostViewAura::NeedsInputGrab() {
return popup_type_ == blink::WebPopupTypeSelect; return popup_type_ == blink::WebPopupTypeSelect;
} }
......
...@@ -418,6 +418,9 @@ class CONTENT_EXPORT RenderWidgetHostViewAura ...@@ -418,6 +418,9 @@ class CONTENT_EXPORT RenderWidgetHostViewAura
ui::InputMethod* GetInputMethod() const; ui::InputMethod* GetInputMethod() const;
// Sends shutdown request.
void Shutdown();
// Returns whether the widget needs an input grab to work properly. // Returns whether the widget needs an input grab to work properly.
bool NeedsInputGrab(); bool NeedsInputGrab();
......
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#include "ui/events/gestures/gesture_configuration.h" #include "ui/events/gestures/gesture_configuration.h"
#include "ui/events/test/event_generator.h" #include "ui/events/test/event_generator.h"
#include "ui/wm/core/default_activation_client.h" #include "ui/wm/core/default_activation_client.h"
#include "ui/wm/core/window_util.h"
using testing::_; using testing::_;
...@@ -845,6 +846,35 @@ TEST_F(RenderWidgetHostViewAuraTest, PopupRetainsCaptureAfterMouseRelease) { ...@@ -845,6 +846,35 @@ TEST_F(RenderWidgetHostViewAuraTest, PopupRetainsCaptureAfterMouseRelease) {
} }
#endif #endif
// Test that select boxes close when their parent window loses focus (e.g. due
// to an alert or system modal dialog).
TEST_F(RenderWidgetHostViewAuraTest, PopupClosesWhenParentLosesFocus) {
parent_view_->SetBounds(gfx::Rect(10, 10, 400, 400));
parent_view_->Focus();
EXPECT_TRUE(parent_view_->HasFocus());
ui::test::EventGenerator generator(
parent_view_->GetNativeView()->GetRootWindow(), gfx::Point(300, 300));
generator.PressLeftButton();
view_->SetPopupType(blink::WebPopupTypeSelect);
view_->InitAsPopup(parent_view_, gfx::Rect(10, 10, 100, 100));
aura::Window* popup_window = view_->GetNativeView();
TestWindowObserver observer(popup_window);
aura::test::TestWindowDelegate delegate;
scoped_ptr<aura::Window> dialog_window(new aura::Window(&delegate));
dialog_window->Init(aura::WINDOW_LAYER_TEXTURED);
aura::client::ParentWindowWithContext(
dialog_window.get(), popup_window, gfx::Rect());
dialog_window->Show();
wm::ActivateWindow(dialog_window.get());
ASSERT_TRUE(wm::IsActiveWindow(dialog_window.get()));
EXPECT_TRUE(observer.destroyed());
}
// Checks that IME-composition-event state is maintained correctly. // Checks that IME-composition-event state is maintained correctly.
TEST_F(RenderWidgetHostViewAuraTest, SetCompositionText) { TEST_F(RenderWidgetHostViewAuraTest, SetCompositionText) {
view_->InitAsChild(NULL); view_->InitAsChild(NULL);
......
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