Commit c2a7b561 authored by sadrul@chromium.org's avatar sadrul@chromium.org

views: Do not set capture on a widget if it cannot be activated.

BUG=128566
TEST=views_unittests:WidgetTest.ActivationCapture

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137736 0039d316-1c4b-4281-b951-d872f2087c98
parent c311db8f
...@@ -69,6 +69,7 @@ class NonActivatableSettingsBubble : public views::BubbleDelegateView { ...@@ -69,6 +69,7 @@ class NonActivatableSettingsBubble : public views::BubbleDelegateView {
set_use_focusless(true); set_use_focusless(true);
set_parent_window(ash::Shell::GetInstance()->GetContainer( set_parent_window(ash::Shell::GetInstance()->GetContainer(
ash::internal::kShellWindowId_SettingBubbleContainer)); ash::internal::kShellWindowId_SettingBubbleContainer));
set_close_on_deactivate(false);
SetLayoutManager(new views::FillLayout()); SetLayoutManager(new views::FillLayout());
AddChildView(content); AddChildView(content);
} }
......
...@@ -59,7 +59,7 @@ bool StatusAreaView::CanActivate() const { ...@@ -59,7 +59,7 @@ bool StatusAreaView::CanActivate() const {
// activation when the user is using the keyboard (FocusCycler). // activation when the user is using the keyboard (FocusCycler).
const FocusCycler* focus_cycler = focus_cycler_for_testing_ ? const FocusCycler* focus_cycler = focus_cycler_for_testing_ ?
focus_cycler_for_testing_ : Shell::GetInstance()->focus_cycler(); focus_cycler_for_testing_ : Shell::GetInstance()->focus_cycler();
return focus_cycler->widget_activating() == GetWidget(); return focus_cycler && focus_cycler->widget_activating() == GetWidget();
} }
void StatusAreaView::DeleteDelegate() { void StatusAreaView::DeleteDelegate() {
......
...@@ -518,7 +518,7 @@ void Widget::Show() { ...@@ -518,7 +518,7 @@ void Widget::Show() {
native_widget_->Show(); native_widget_->Show();
} }
if (close_on_deactivate_) { if (CanActivate() && close_on_deactivate_) {
// Set mouse capture on timeout in case this is called from a // Set mouse capture on timeout in case this is called from a
// mouse pressed handler. // mouse pressed handler.
MessageLoopForUI::current()->PostTask(FROM_HERE, base::Bind( MessageLoopForUI::current()->PostTask(FROM_HERE, base::Bind(
......
...@@ -60,6 +60,20 @@ class NativeWidgetCapture : public NativeWidgetPlatform { ...@@ -60,6 +60,20 @@ class NativeWidgetCapture : public NativeWidgetPlatform {
}; };
#endif #endif
class NonActivatableDelegate : public WidgetDelegateView {
public:
NonActivatableDelegate() {}
virtual ~NonActivatableDelegate() {}
// Overridden from WidgetDelegate.
virtual bool CanActivate() const OVERRIDE {
return false;
}
private:
DISALLOW_COPY_AND_ASSIGN(NonActivatableDelegate);
};
// A typedef that inserts our mock-capture NativeWidget implementation for // A typedef that inserts our mock-capture NativeWidget implementation for
// relevant platforms. // relevant platforms.
#if defined(USE_AURA) #if defined(USE_AURA)
...@@ -323,6 +337,27 @@ TEST_F(WidgetTest, Visibility_ChildPopup) { ...@@ -323,6 +337,27 @@ TEST_F(WidgetTest, Visibility_ChildPopup) {
} }
#endif #endif
TEST_F(WidgetTest, ActivationCapture) {
Widget* first = CreateTopLevelPlatformWidget();
first->Show();
first->SetMouseCapture(NULL);
RunPendingMessages();
EXPECT_TRUE(WidgetHasMouseCapture(first));
Widget* second = new Widget;
Widget::InitParams params(Widget::InitParams::TYPE_BUBBLE);
params.transparent = true;
params.close_on_deactivate = true;
params.delegate = new NonActivatableDelegate;
second->Init(params);
second->Show();
RunPendingMessages();
EXPECT_FALSE(WidgetHasMouseCapture(second));
second->CloseNow();
first->CloseNow();
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Widget ownership tests. // Widget ownership tests.
// //
......
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