widget->StackAtTop();
widget->IsClosed();
widget->Close();
- widget->Show();
widget->Hide();
widget->Activate();
widget->Deactivate();
// widget->CenterWindow(gfx::Size(50, 60));
// widget->GetRestoredBounds();
// widget->ShowInactive();
+ // widget->Show();
}
private:
const gfx::Rect screen_bounds(widget->GetWindowBoundsInScreen());
ui::MouseEvent move_event(ui::ET_MOUSE_MOVED, screen_bounds.CenterPoint(),
screen_bounds.CenterPoint(), 0, 0);
- aura::WindowTreeHostDelegate* rwhd =
- widget->GetNativeWindow()->GetDispatcher()->AsWindowTreeHostDelegate();
- rwhd->OnHostMouseEvent(&move_event);
- if (last_event_type == ui::ET_MOUSE_ENTERED)
+ aura::WindowEventDispatcher* dispatcher =
+ widget->GetNativeWindow()->GetDispatcher();
+ ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move_event);
+ if (last_event_type == ui::ET_MOUSE_ENTERED || details.dispatcher_destroyed)
return;
- rwhd->OnHostMouseEvent(&move_event);
- if (last_event_type == ui::ET_MOUSE_MOVED)
+ details = dispatcher->OnEventFromSource(&move_event);
+ if (last_event_type == ui::ET_MOUSE_MOVED || details.dispatcher_destroyed)
return;
ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, screen_bounds.CenterPoint(),
screen_bounds.CenterPoint(), 0, 0);
- rwhd->OnHostMouseEvent(&press_event);
- if (last_event_type == ui::ET_MOUSE_PRESSED)
+ details = dispatcher->OnEventFromSource(&press_event);
+ if (last_event_type == ui::ET_MOUSE_PRESSED || details.dispatcher_destroyed)
return;
gfx::Point end_point(screen_bounds.CenterPoint());
end_point.Offset(1, 1);
ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, end_point, end_point, 0, 0);
- rwhd->OnHostMouseEvent(&drag_event);
- if (last_event_type == ui::ET_MOUSE_DRAGGED)
+ details = dispatcher->OnEventFromSource(&drag_event);
+ if (last_event_type == ui::ET_MOUSE_DRAGGED || details.dispatcher_destroyed)
return;
ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, end_point, end_point, 0,
0);
- rwhd->OnHostMouseEvent(&release_event);
+ details = dispatcher->OnEventFromSource(&release_event);
+ if (details.dispatcher_destroyed)
+ return;
}
// Creates a widget and invokes GenerateMouseEvents() with |last_event_type|.
cursor_location_main,
ui::EF_NONE,
ui::EF_NONE);
- top_level_widget.GetNativeView()->GetDispatcher()->
- AsWindowTreeHostDelegate()->OnHostMouseEvent(&move_main);
+ ui::EventDispatchDetails details = top_level_widget.GetNativeView()->
+ GetDispatcher()->OnEventFromSource(&move_main);
+ ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_EQ(1, widget_view->GetEventCount(ui::ET_MOUSE_ENTERED));
widget_view->ResetCounts();
cursor_location_dialog,
ui::EF_NONE,
ui::EF_NONE);
- top_level_widget.GetNativeView()->GetDispatcher()->
- AsWindowTreeHostDelegate()->OnHostMouseEvent(&mouse_down_dialog);
+ details = top_level_widget.GetNativeView()->GetDispatcher()->
+ OnEventFromSource(&mouse_down_dialog);
+ ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_EQ(1, dialog_widget_view->GetEventCount(ui::ET_MOUSE_PRESSED));
// Send a mouse move message to the main window. It should not be received by
cursor_location_main2,
ui::EF_NONE,
ui::EF_NONE);
- top_level_widget.GetNativeView()->GetDispatcher()->
- AsWindowTreeHostDelegate()->OnHostMouseEvent(&mouse_down_main);
+ details = top_level_widget.GetNativeView()->GetDispatcher()->
+ OnEventFromSource(&mouse_down_main);
+ ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_EQ(0, widget_view->GetEventCount(ui::ET_MOUSE_MOVED));
modal_dialog_widget->CloseNow();
widget->CloseNow();
}
-#if defined(OS_WIN) && defined(USE_AURA)
+#if defined(USE_AURA) && !defined(OS_CHROMEOS)
TEST_F(WidgetTest, InactiveWidgetDoesNotGrabActivation) {
Widget* widget = CreateTopLevelPlatformWidget();
widget->Show();
widget->CloseNow();
}
+#if !defined(OS_CHROMEOS)
+namespace {
+
+// Trivial WidgetObserverTest that invokes Widget::IsActive() from
+// OnWindowDestroying.
+class IsActiveFromDestroyObserver : public WidgetObserver {
+ public:
+ IsActiveFromDestroyObserver() {}
+ virtual ~IsActiveFromDestroyObserver() {}
+ virtual void OnWidgetDestroying(Widget* widget) OVERRIDE {
+ widget->IsActive();
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(IsActiveFromDestroyObserver);
+};
+
+} // namespace
+
+// Verifies Widget::IsActive() invoked from
+// WidgetObserver::OnWidgetDestroying() in a child widget doesn't crash.
+TEST_F(WidgetTest, IsActiveFromDestroy) {
+ // Create two widgets, one a child of the other.
+ IsActiveFromDestroyObserver observer;
+ Widget parent_widget;
+ Widget::InitParams parent_params =
+ CreateParams(Widget::InitParams::TYPE_POPUP);
+ parent_params.native_widget = new DesktopNativeWidgetAura(&parent_widget);
+ parent_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
+ parent_widget.Init(parent_params);
+ parent_widget.Show();
+
+ Widget child_widget;
+ Widget::InitParams child_params =
+ CreateParams(Widget::InitParams::TYPE_POPUP);
+ child_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
+ child_params.context = parent_widget.GetNativeView();
+ child_widget.Init(child_params);
+ child_widget.AddObserver(&observer);
+ child_widget.Show();
+
+ parent_widget.CloseNow();
+}
+#endif
+
} // namespace test
} // namespace views