summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorerg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-28 21:00:03 +0000
committererg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-28 21:00:03 +0000
commit5ebe610732ff3d41b2c288e332767ef56d67fcd3 (patch)
treead306d1d45b9dee174640ecbecb9e305220a42e0 /ui
parent3e3f945d8a7b0305b5aaf7a31edb6bb23176229c (diff)
downloadchromium_src-5ebe610732ff3d41b2c288e332767ef56d67fcd3.zip
chromium_src-5ebe610732ff3d41b2c288e332767ef56d67fcd3.tar.gz
chromium_src-5ebe610732ff3d41b2c288e332767ef56d67fcd3.tar.bz2
Desktop aura: Break aura::Window::SetParent in two.
Previously, SetParent will query a global StackingClient object if NULL is passed to it. Since we want different behavior on the desktop and on ash, we need to break that. It has been replaced with two methods: - SetParentTo(), which takes an aura window and does the parenting. - SetDefaultParentByTargetRoot(), which takes a RootWindow as context and asks the StackingClient on said RootWindow where it should parent the window. The problem is that people have relied for a long time on what amounts to a global variable. This is the first of several patches that pass around a context RootWindow. This patch focuses on ash/ unittests mostly. Later patches will focus on threading context through Widget creation. The last patch in this series will pull out the global stacking client interface and add DCHECKs so NULL can't be passed to either of these methods on Window. BUG=161882 Review URL: https://chromiumcodereview.appspot.com/11421006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@170049 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/aura/client/stacking_client.h19
-rw-r--r--ui/aura/demo/demo_main.cc6
-rw-r--r--ui/aura/gestures/gesture_recognizer_unittest.cc86
-rw-r--r--ui/aura/root_window_unittest.cc12
-rw-r--r--ui/aura/test/aura_test_base.cc15
-rw-r--r--ui/aura/test/aura_test_base.h7
-rw-r--r--ui/aura/test/test_windows.cc12
-rw-r--r--ui/aura/test/test_windows.h6
-rw-r--r--ui/aura/window.cc27
-rw-r--r--ui/aura/window.h9
-rw-r--r--ui/aura/window_unittest.cc209
-rw-r--r--ui/views/corewm/compound_event_filter_unittest.cc5
-rw-r--r--ui/views/corewm/focus_controller_unittest.cc6
-rw-r--r--ui/views/corewm/shadow_controller_unittest.cc16
-rw-r--r--ui/views/widget/native_widget_aura.cc43
-rw-r--r--ui/views/widget/widget.h2
16 files changed, 271 insertions, 209 deletions
diff --git a/ui/aura/client/stacking_client.h b/ui/aura/client/stacking_client.h
index 023d8bf..6c0aa59 100644
--- a/ui/aura/client/stacking_client.h
+++ b/ui/aura/client/stacking_client.h
@@ -20,12 +20,15 @@ class AURA_EXPORT StackingClient {
public:
virtual ~StackingClient() {}
- // Called by the Window when its parent is set to NULL, returns the window
- // that |window| should be added to instead. |context| provides a Window
- // (generally a RootWindow) that can be used to determine which desktop type
- // the default parent should be chosen from.
- // NOTE: this may have side effects. It should only be used when |window| is
- // going to be immediately added.
+ // Called by the Window when it looks for a default parent. Returns the
+ // window that |window| should be added to instead. |context| provides a
+ // Window (generally a RootWindow) that can be used to determine which
+ // desktop type the default parent should be chosen from. NOTE: this may
+ // have side effects. It should only be used when |window| is going to be
+ // immediately added.
+ //
+ // TODO(erg): Remove |context|, and maybe after oshima's patch lands,
+ // |bounds|.
virtual Window* GetDefaultParent(
Window* context,
Window* window,
@@ -34,7 +37,7 @@ class AURA_EXPORT StackingClient {
// Set/Get the default stacking client.
AURA_EXPORT void SetStackingClient(StackingClient* stacking_client);
-AURA_EXPORT StackingClient* GetStackingClient();
+StackingClient* GetStackingClient();
// Set/Get a stacking client for a specific window. Setting the stacking client
// sets the stacking client on the window's RootWindow, not the window itself.
@@ -43,7 +46,7 @@ AURA_EXPORT StackingClient* GetStackingClient();
// stacking client is used.
AURA_EXPORT void SetStackingClient(Window* window,
StackingClient* stacking_client);
-AURA_EXPORT StackingClient* GetStackingClient(Window* window);
+StackingClient* GetStackingClient(Window* window);
} // namespace client
} // namespace aura
diff --git a/ui/aura/demo/demo_main.cc b/ui/aura/demo/demo_main.cc
index e8f935f..b1ab577 100644
--- a/ui/aura/demo/demo_main.cc
+++ b/ui/aura/demo/demo_main.cc
@@ -142,7 +142,7 @@ int DemoMain() {
window1.Init(ui::LAYER_TEXTURED);
window1.SetBounds(gfx::Rect(100, 100, 400, 400));
window1.Show();
- window1.SetParent(NULL);
+ window1.SetDefaultParentByRootWindow(root_window.get(), gfx::Rect());
DemoWindowDelegate window_delegate2(SK_ColorRED);
aura::Window window2(&window_delegate2);
@@ -150,7 +150,7 @@ int DemoMain() {
window2.Init(ui::LAYER_TEXTURED);
window2.SetBounds(gfx::Rect(200, 200, 350, 350));
window2.Show();
- window2.SetParent(NULL);
+ window2.SetDefaultParentByRootWindow(root_window.get(), gfx::Rect());
DemoWindowDelegate window_delegate3(SK_ColorGREEN);
aura::Window window3(&window_delegate3);
@@ -158,7 +158,7 @@ int DemoMain() {
window3.Init(ui::LAYER_TEXTURED);
window3.SetBounds(gfx::Rect(10, 10, 50, 50));
window3.Show();
- window3.SetParent(&window2);
+ window2.AddChild(&window3);
root_window->ShowRootWindow();
MessageLoopForUI::current()->Run();
diff --git a/ui/aura/gestures/gesture_recognizer_unittest.cc b/ui/aura/gestures/gesture_recognizer_unittest.cc
index bb3d4bb..76251b8 100644
--- a/ui/aura/gestures/gesture_recognizer_unittest.cc
+++ b/ui/aura/gestures/gesture_recognizer_unittest.cc
@@ -530,7 +530,7 @@ TEST_F(GestureRecognizerTest, GestureEventTap) {
const int kTouchId = 2;
gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
delegate->Reset();
ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
@@ -577,7 +577,7 @@ TEST_F(GestureRecognizerTest, GestureEventTapRegion) {
const int kTouchId = 2;
gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
// Test with no ET_TOUCH_MOVED events.
{
@@ -836,7 +836,7 @@ TEST_F(GestureRecognizerTest, GestureEventScroll) {
const int kTouchId = 5;
gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
delegate->Reset();
ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
@@ -902,7 +902,7 @@ TEST_F(GestureRecognizerTest, GestureEventScrollBoundingBox) {
const int kTouchId = 5;
gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
const int kPositionX = 101;
const int kPositionY = 201;
@@ -953,7 +953,7 @@ TEST_F(GestureRecognizerTest, GestureEventHorizontalRailFling) {
const int kTouchId = 7;
gfx::Rect bounds(0, 0, 1000, 1000);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
kTouchId, GetTime());
@@ -994,7 +994,7 @@ TEST_F(GestureRecognizerTest, GestureEventVerticalRailFling) {
const int kTouchId = 7;
gfx::Rect bounds(0, 0, 1000, 1000);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
kTouchId, GetTime());
@@ -1035,7 +1035,7 @@ TEST_F(GestureRecognizerTest, GestureEventNonRailFling) {
const int kTouchId = 7;
gfx::Rect bounds(0, 0, 1000, 1000);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
kTouchId, GetTime());
@@ -1071,7 +1071,7 @@ TEST_F(GestureRecognizerTest, GestureEventLongPress) {
const int kTouchId = 2;
gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
delegate->Reset();
@@ -1115,7 +1115,7 @@ TEST_F(GestureRecognizerTest, GestureEventLongPressCancelledByScroll) {
const int kTouchId = 6;
gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
delegate->Reset();
@@ -1160,7 +1160,7 @@ TEST_F(GestureRecognizerTest, GestureEventLongTap) {
const int kTouchId = 2;
gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
delegate->Reset();
@@ -1206,7 +1206,7 @@ TEST_F(GestureRecognizerTest, GestureEventLongPressCancelledBySecondTap) {
const int kTouchId2 = 2;
gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
TimerTestGestureRecognizer* gesture_recognizer =
new TimerTestGestureRecognizer(root_window());
@@ -1258,7 +1258,7 @@ TEST_F(GestureRecognizerTest, GestureEventHorizontalRailScroll) {
const int kTouchId = 7;
gfx::Rect bounds(0, 0, 1000, 1000);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
kTouchId, GetTime());
@@ -1306,7 +1306,7 @@ TEST_F(GestureRecognizerTest, GestureEventVerticalRailScroll) {
const int kTouchId = 7;
gfx::Rect bounds(0, 0, 1000, 1000);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
kTouchId, GetTime());
@@ -1353,7 +1353,7 @@ TEST_F(GestureRecognizerTest, GestureTapFollowedByScroll) {
const int kTouchId = 3;
gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
delegate->Reset();
ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
@@ -1467,7 +1467,7 @@ TEST_F(GestureRecognizerTest, AsynchronousGestureRecognition) {
const int kTouchId2 = 4;
gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> queue(CreateTestWindowWithDelegate(
- queued_delegate.get(), -1234, bounds, NULL));
+ queued_delegate.get(), -1234, bounds, root_window()));
queued_delegate->set_window(queue.get());
@@ -1507,7 +1507,7 @@ TEST_F(GestureRecognizerTest, AsynchronousGestureRecognition) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -2345, gfx::Rect(0, 0, 50, 50), NULL));
+ delegate.get(), -2345, gfx::Rect(0, 0, 50, 50), root_window()));
delegate->Reset();
ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 20),
kTouchId2, GetTime());
@@ -1672,7 +1672,7 @@ TEST_F(GestureRecognizerTest, GestureEventPinchFromScroll) {
const int kTouchId2 = 3;
gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
aura::RootWindow* root = root_window();
@@ -1759,7 +1759,7 @@ scoped_ptr<GestureEventConsumeDelegate> delegate(
const int kTouchId2 = 3;
gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 301),
kTouchId1, GetTime());
@@ -1810,7 +1810,7 @@ TEST_F(GestureRecognizerTest, GestureEventPinchFromTap) {
const int kTouchId2 = 5;
gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
aura::RootWindow* root = root_window();
@@ -1920,7 +1920,7 @@ TEST_F(GestureRecognizerTest, GestureEventTouchLockSelectsCorrectWindow) {
for (int i = 0; i < kNumWindows; ++i) {
delegates[i] = new GestureEventConsumeDelegate();
windows[i] = CreateTestWindowWithDelegate(
- delegates[i], i, window_bounds[i], NULL);
+ delegates[i], i, window_bounds[i], root_window());
windows[i]->set_id(i);
ui::TouchEvent press(ui::ET_TOUCH_PRESSED, window_bounds[i].origin(),
i, GetTime());
@@ -1985,7 +1985,7 @@ TEST_F(GestureRecognizerTest, GestureEventOutsideRootWindowTap) {
root_window()->SetGestureRecognizerForTesting(gesture_recognizer);
scoped_ptr<aura::Window> window(CreateTestWindowWithBounds(
- gfx::Rect(-100, -100, 2000, 2000), NULL));
+ gfx::Rect(-100, -100, 2000, 2000), root_window()));
ui::GestureSequence* window_gesture_sequence =
gesture_recognizer->GetGestureSequenceForTesting(window.get());
@@ -2013,7 +2013,7 @@ TEST_F(GestureRecognizerTest, NoTapWithPreventDefaultedRelease) {
const int kTouchId = 2;
gfx::Rect bounds(100, 200, 100, 100);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
delegate->set_window(window.get());
delegate->Reset();
@@ -2041,7 +2041,7 @@ TEST_F(GestureRecognizerTest, PinchScrollWithPreventDefaultedRelease) {
const int kTouchId2 = 5;
gfx::Rect bounds(10, 20, 100, 100);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
delegate->set_window(window.get());
delegate->Reset();
@@ -2127,7 +2127,7 @@ TEST_F(GestureRecognizerTest, CaptureSendsGestureEnd) {
root_window()->SetGestureRecognizerForTesting(gesture_recognizer);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, gfx::Rect(10, 10, 300, 300), NULL));
+ delegate.get(), -1234, gfx::Rect(10, 10, 300, 300), root_window()));
EventGenerator generator(root_window());
generator.MoveMouseRelativeTo(window.get(), gfx::Point(10, 10));
@@ -2137,7 +2137,7 @@ TEST_F(GestureRecognizerTest, CaptureSendsGestureEnd) {
EXPECT_TRUE(delegate->tap_down());
scoped_ptr<aura::Window> capture(CreateTestWindowWithBounds(
- gfx::Rect(10, 10, 200, 200), NULL));
+ gfx::Rect(10, 10, 200, 200), root_window()));
capture->SetCapture();
RunAllPendingInMessageLoop();
@@ -2153,7 +2153,7 @@ TEST_F(GestureRecognizerTest, PressDoesNotCrash) {
root_window()->SetGestureRecognizerForTesting(gesture_recognizer);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, gfx::Rect(10, 10, 300, 300), NULL));
+ delegate.get(), -1234, gfx::Rect(10, 10, 300, 300), root_window()));
ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(45, 45), 7, GetTime());
press.set_radius_x(40);
@@ -2182,7 +2182,7 @@ TEST_F(GestureRecognizerTest, TwoFingerTap) {
const int kTouchId2 = 3;
gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
delegate->Reset();
ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
@@ -2275,7 +2275,7 @@ TEST_F(GestureRecognizerTest, TwoFingerTapExpired) {
const int kTouchId2 = 3;
gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
delegate->Reset();
ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
@@ -2320,7 +2320,7 @@ TEST_F(GestureRecognizerTest, TwoFingerTapChangesToPinch) {
{
gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
delegate->Reset();
ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
@@ -2352,7 +2352,7 @@ TEST_F(GestureRecognizerTest, TwoFingerTapChangesToPinch) {
{
gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
delegate->Reset();
ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
@@ -2389,7 +2389,7 @@ TEST_F(GestureRecognizerTest, MultiFingerSwipe) {
gfx::Rect bounds(5, 10, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
const int kSteps = 15;
const int kTouchPoints = 4;
@@ -2433,7 +2433,7 @@ TEST_F(GestureRecognizerTest, TwoFingerTapCancelled) {
{
gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
delegate->Reset();
ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
@@ -2466,7 +2466,7 @@ TEST_F(GestureRecognizerTest, TwoFingerTapCancelled) {
{
gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
delegate->Reset();
ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
@@ -2505,7 +2505,7 @@ TEST_F(GestureRecognizerTest, VeryWideTwoFingerTouchDownShouldBeAPinch) {
const int kTouchId2 = 3;
gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
delegate->Reset();
ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
@@ -2544,7 +2544,7 @@ TEST_F(GestureRecognizerTest, FlushAllOnHide) {
new GestureEventConsumeDelegate());
gfx::Rect bounds(0, 0, 200, 200);
scoped_ptr<aura::Window> window(
- CreateTestWindowWithDelegate(delegate.get(), 0, bounds, NULL));
+ CreateTestWindowWithDelegate(delegate.get(), 0, bounds, root_window()));
const int kTouchId1 = 8;
const int kTouchId2 = 2;
ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10),
@@ -2566,7 +2566,7 @@ TEST_F(GestureRecognizerTest, LongPressTimerStopsOnPreventDefaultedTouchMoves) {
const int kTouchId = 2;
gfx::Rect bounds(100, 200, 100, 100);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
delegate->set_window(window.get());
TimerTestGestureRecognizer* gesture_recognizer =
@@ -2626,7 +2626,7 @@ TEST_F(GestureRecognizerTest, GestureEventScrollTouchMoveConsumed) {
const int kTouchId = 5;
gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
delegate->Reset();
ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
@@ -2685,7 +2685,7 @@ TEST_F(GestureRecognizerTest, GestureEventScrollTouchMovePartialConsumed) {
const int kTouchId = 5;
gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
delegate->Reset();
ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
@@ -2789,7 +2789,7 @@ TEST_F(GestureRecognizerTest, GestureEventDoubleTap) {
const int kTouchId = 2;
gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
// First tap (tested in GestureEventTap)
ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(104, 201),
@@ -2833,7 +2833,7 @@ TEST_F(GestureRecognizerTest, TwoTapsFarApart) {
const int kTouchId = 2;
gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
// First tap (tested in GestureEventTap)
ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
@@ -2878,7 +2878,7 @@ TEST_F(GestureRecognizerTest, TwoTapsWithDelayBetween) {
const int kTouchId = 2;
gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
// First tap (tested in GestureEventTap)
ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
@@ -2924,7 +2924,7 @@ TEST_F(GestureRecognizerTest, BoundingBoxRadiusChange) {
const int kTouchId = 5, kTouchId2 = 7;
gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
ui::TouchEvent press1(
ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), kTouchId, GetTime());
@@ -2979,7 +2979,7 @@ TEST_F(GestureRecognizerTest, NoDriftInScroll) {
const int kTouchId = 5;
gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
ui::TouchEvent press1(
ui::ET_TOUCH_PRESSED, gfx::Point(101, 208), kTouchId, GetTime());
diff --git a/ui/aura/root_window_unittest.cc b/ui/aura/root_window_unittest.cc
index fdf93f0..7de3bf3 100644
--- a/ui/aura/root_window_unittest.cc
+++ b/ui/aura/root_window_unittest.cc
@@ -96,7 +96,7 @@ Window* CreateWindow(int id, Window* parent, WindowDelegate* delegate) {
test::TestWindowDelegate::CreateSelfDestroyingDelegate());
window->set_id(id);
window->Init(ui::LAYER_TEXTURED);
- window->SetParent(parent);
+ parent->AddChild(window);
window->SetBounds(gfx::Rect(0, 0, 100, 100));
window->Show();
return window;
@@ -120,9 +120,9 @@ TEST_F(RootWindowTest, OnHostMouseEvent) {
gfx::Rect bounds1(100, 200, kWindowWidth, kWindowHeight);
gfx::Rect bounds2(300, 400, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> window1(CreateTestWindowWithDelegate(
- delegate1.get(), -1234, bounds1, NULL));
+ delegate1.get(), -1234, bounds1, root_window()));
scoped_ptr<aura::Window> window2(CreateTestWindowWithDelegate(
- delegate2.get(), -5678, bounds2, NULL));
+ delegate2.get(), -5678, bounds2, root_window()));
// Send a mouse event to window1.
gfx::Point point(101, 201);
@@ -155,7 +155,7 @@ TEST_F(RootWindowTest, HideCursor) {
const int kWindowHeight = 45;
gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, NULL));
+ delegate.get(), -1234, bounds, root_window()));
aura::Window* window_ptr = &*window;
root_window()->OnCursorVisibilityChanged(true);
@@ -241,7 +241,7 @@ TEST_F(RootWindowTest, MouseButtonState) {
TEST_F(RootWindowTest, TranslatedEvent) {
scoped_ptr<Window> w1(test::CreateTestWindowWithDelegate(NULL, 1,
- gfx::Rect(50, 50, 100, 100), NULL));
+ gfx::Rect(50, 50, 100, 100), root_window()));
gfx::Point origin(100, 100);
ui::MouseEvent root(ui::ET_MOUSE_PRESSED, origin, origin, 0);
@@ -548,7 +548,7 @@ TEST_F(RootWindowTest, HoldMouseMove) {
test::TestWindowDelegate delegate;
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- &delegate, 1, gfx::Rect(0, 0, 100, 100), NULL));
+ &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window()));
ui::MouseEvent mouse_move_event(ui::ET_MOUSE_MOVED, gfx::Point(0, 0),
gfx::Point(0, 0), 0);
diff --git a/ui/aura/test/aura_test_base.cc b/ui/aura/test/aura_test_base.cc
index 3544964..6e99dd5 100644
--- a/ui/aura/test/aura_test_base.cc
+++ b/ui/aura/test/aura_test_base.cc
@@ -5,6 +5,7 @@
#include "ui/aura/test/aura_test_base.h"
#include "ui/aura/test/aura_test_helper.h"
+#include "ui/aura/window.h"
#include "ui/base/gestures/gesture_configuration.h"
#include "ui/base/ime/text_input_test_support.h"
@@ -68,6 +69,20 @@ void AuraTestBase::TearDown() {
testing::Test::TearDown();
}
+Window* AuraTestBase::CreateTransientChild(int id, Window* parent) {
+ Window* window = new Window(NULL);
+ window->set_id(id);
+ window->SetType(aura::client::WINDOW_TYPE_NORMAL);
+ window->Init(ui::LAYER_TEXTURED);
+ window->SetDefaultParentByRootWindow(root_window(), gfx::Rect());
+ parent->AddTransientChild(window);
+ return window;
+}
+
+void AuraTestBase::SetDefaultParentByPrimaryRootWindow(aura::Window* window) {
+ window->SetDefaultParentByRootWindow(root_window(), gfx::Rect());
+}
+
void AuraTestBase::RunAllPendingInMessageLoop() {
helper_->RunAllPendingInMessageLoop();
}
diff --git a/ui/aura/test/aura_test_base.h b/ui/aura/test/aura_test_base.h
index 2b8990a..c7daec3 100644
--- a/ui/aura/test/aura_test_base.h
+++ b/ui/aura/test/aura_test_base.h
@@ -13,6 +13,7 @@
namespace aura {
class RootWindow;
+class Window;
namespace test {
// A base class for aura unit tests.
@@ -26,6 +27,12 @@ class AuraTestBase : public testing::Test {
virtual void SetUp() OVERRIDE;
virtual void TearDown() OVERRIDE;
+ // Creates a transient window that is transient to |parent|.
+ aura::Window* CreateTransientChild(int id, aura::Window* parent);
+
+ // Attach |window| to the current shell's root window.
+ void SetDefaultParentByPrimaryRootWindow(aura::Window* window);
+
protected:
void RunAllPendingInMessageLoop();
diff --git a/ui/aura/test/test_windows.cc b/ui/aura/test/test_windows.cc
index 75cd530..f41a034 100644
--- a/ui/aura/test/test_windows.cc
+++ b/ui/aura/test/test_windows.cc
@@ -52,21 +52,11 @@ Window* CreateTestWindowWithDelegateAndType(WindowDelegate* delegate,
window->Init(ui::LAYER_TEXTURED);
window->SetBounds(bounds);
window->Show();
- window->SetParent(parent);
+ parent->AddChild(window);
window->SetProperty(aura::client::kCanMaximizeKey, true);
return window;
}
-Window* CreateTransientChild(int id, Window* parent) {
- Window* window = new Window(NULL);
- window->set_id(id);
- window->SetType(aura::client::WINDOW_TYPE_NORMAL);
- window->Init(ui::LAYER_TEXTURED);
- window->SetParent(NULL);
- parent->AddTransientChild(window);
- return window;
-}
-
template <typename T>
bool ObjectIsAbove(T* upper, T* lower) {
DCHECK_EQ(upper->parent(), lower->parent());
diff --git a/ui/aura/test/test_windows.h b/ui/aura/test/test_windows.h
index 71dba45..94f3ac6 100644
--- a/ui/aura/test/test_windows.h
+++ b/ui/aura/test/test_windows.h
@@ -16,6 +16,9 @@
namespace aura {
namespace test {
+// These functions expect a non-NULL parent. If you want to let the
+// StackingClient determine where to place the windows, there are equivalent
+// methods in AshTestBase.
Window* CreateTestWindowWithId(int id, Window* parent);
Window* CreateTestWindowWithBounds(const gfx::Rect& bounds, Window* parent);
Window* CreateTestWindow(SkColor color,
@@ -32,9 +35,6 @@ Window* CreateTestWindowWithDelegateAndType(WindowDelegate* delegate,
const gfx::Rect& bounds,
Window* parent);
-// Creates a transient child window of |parent|.
-Window* CreateTransientChild(int id, Window* parent);
-
// Returns true if |upper| is above |lower| in the window stacking order.
bool WindowIsAbove(Window* upper, Window* lower);
diff --git a/ui/aura/window.cc b/ui/aura/window.cc
index 5bd9429..5b12793 100644
--- a/ui/aura/window.cc
+++ b/ui/aura/window.cc
@@ -33,19 +33,6 @@
namespace aura {
-namespace {
-
-Window* GetParentForWindow(Window* window, Window* suggested_parent) {
- if (suggested_parent)
- return suggested_parent;
- if (client::GetStackingClient())
- return client::GetStackingClient()->GetDefaultParent(
- window, window, gfx::Rect());
- return NULL;
-}
-
-} // namespace
-
Window::TestApi::TestApi(Window* window) : window_(window) {}
bool Window::TestApi::OwnsLayer() const {
@@ -333,8 +320,18 @@ void Window::SetExternalTexture(ui::Texture* texture) {
WindowObserver, observers_, OnWindowPaintScheduled(this, region));
}
-void Window::SetParent(Window* parent) {
- GetParentForWindow(this, parent)->AddChild(this);
+void Window::SetDefaultParentByRootWindow(RootWindow* root_window,
+ const gfx::Rect& bounds_in_screen) {
+ // TODO(erg): Enable this DCHECK once it is safe.
+ // DCHECK(root_window);
+
+ // Stacking clients are mandatory on RootWindow objects.
+ client::StackingClient* client = client::GetStackingClient(root_window);
+ DCHECK(client);
+
+ aura::Window* default_parent = client->GetDefaultParent(
+ root_window, this, bounds_in_screen);
+ default_parent->AddChild(this);
}
void Window::StackChildAtTop(Window* child) {
diff --git a/ui/aura/window.h b/ui/aura/window.h
index 985391d..3f2192f 100644
--- a/ui/aura/window.h
+++ b/ui/aura/window.h
@@ -170,9 +170,12 @@ class AURA_EXPORT Window : public ui::LayerDelegate,
// Assigns a new external texture to the window's layer.
void SetExternalTexture(ui::Texture* texture);
- // Sets the parent window of the window. If NULL, the window is parented to
- // the root window.
- void SetParent(Window* parent);
+ // Places this window per |root_window|'s stacking client. The final location
+ // may be a RootWindow other than the one passed in. |root_window| may not be
+ // NULL. |bounds_in_screen| may be empty; it is more optional context that
+ // may, but isn't necessarily used.
+ void SetDefaultParentByRootWindow(RootWindow* root_window,
+ const gfx::Rect& bounds_in_screen);
// Stacks the specified child of this Window at the front of the z-order.
void StackChildAtTop(Window* child);
diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc
index 23f16ca..cc7ce9af 100644
--- a/ui/aura/window_unittest.cc
+++ b/ui/aura/window_unittest.cc
@@ -60,6 +60,11 @@ class WindowTest : public AuraTestBase {
set_max_separation_for_gesture_touches_in_pixels(max_separation_);
}
+ // Adds |window| to |root_window_|, through the StackingClient.
+ void SetDefaultParentByPrimaryRootWindow(aura::Window* window) {
+ window->SetDefaultParentByRootWindow(root_window(), gfx::Rect());
+ }
+
private:
int max_separation_;
@@ -253,7 +258,7 @@ class SelfEventHandlingWindowDelegate : public TestWindowDelegate {
} // namespace
TEST_F(WindowTest, GetChildById) {
- scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL));
+ scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window()));
scoped_ptr<Window> w11(CreateTestWindowWithId(11, w1.get()));
scoped_ptr<Window> w111(CreateTestWindowWithId(111, w11.get()));
scoped_ptr<Window> w12(CreateTestWindowWithId(12, w1.get()));
@@ -273,8 +278,8 @@ TEST_F(WindowTest, Contains) {
Window child2(NULL);
child2.Init(ui::LAYER_NOT_DRAWN);
- child1.SetParent(&parent);
- child2.SetParent(&child1);
+ parent.AddChild(&child1);
+ child1.AddChild(&child2);
EXPECT_TRUE(parent.Contains(&parent));
EXPECT_TRUE(parent.Contains(&child1));
@@ -287,7 +292,8 @@ TEST_F(WindowTest, Contains) {
TEST_F(WindowTest, ContainsPointInRoot) {
scoped_ptr<Window> w(
- CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 5, 5), NULL));
+ CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 5, 5),
+ root_window()));
EXPECT_FALSE(w->ContainsPointInRoot(gfx::Point(9, 9)));
EXPECT_TRUE(w->ContainsPointInRoot(gfx::Point(10, 10)));
EXPECT_TRUE(w->ContainsPointInRoot(gfx::Point(14, 14)));
@@ -297,7 +303,8 @@ TEST_F(WindowTest, ContainsPointInRoot) {
TEST_F(WindowTest, ContainsPoint) {
scoped_ptr<Window> w(
- CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 5, 5), NULL));
+ CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 5, 5),
+ root_window()));
EXPECT_TRUE(w->ContainsPoint(gfx::Point(0, 0)));
EXPECT_TRUE(w->ContainsPoint(gfx::Point(4, 4)));
EXPECT_FALSE(w->ContainsPoint(gfx::Point(5, 5)));
@@ -308,7 +315,7 @@ TEST_F(WindowTest, ConvertPointToWindow) {
// Window::ConvertPointToWindow is mostly identical to
// Layer::ConvertPointToLayer, except NULL values for |source| are permitted,
// in which case the function just returns.
- scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL));
+ scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window()));
gfx::Point reference_point(100, 100);
gfx::Point test_point = reference_point;
Window::ConvertPointToTarget(NULL, w1.get(), &test_point);
@@ -317,7 +324,8 @@ TEST_F(WindowTest, ConvertPointToWindow) {
TEST_F(WindowTest, MoveCursorTo) {
scoped_ptr<Window> w1(
- CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL));
+ CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500),
+ root_window()));
scoped_ptr<Window> w11(
CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get()));
scoped_ptr<Window> w111(
@@ -345,7 +353,8 @@ TEST_F(WindowTest, MoveCursorTo) {
TEST_F(WindowTest, ContainsMouse) {
scoped_ptr<Window> w(
- CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL));
+ CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500),
+ root_window()));
w->Show();
Window::TestApi w_test_api(w.get());
RootWindow* root = root_window();
@@ -375,7 +384,8 @@ TEST_F(WindowTest, MoveCursorToWithTransformRootWindow) {
// Tests Window::ConvertPointToWindow() with transform to non-root windows.
TEST_F(WindowTest, MoveCursorToWithTransformWindow) {
scoped_ptr<Window> w1(
- CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL));
+ CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500),
+ root_window()));
gfx::Transform transform1;
transform1.Scale(2, 2);
@@ -412,7 +422,8 @@ TEST_F(WindowTest, MoveCursorToWithTransformWindow) {
// non-root windows.
TEST_F(WindowTest, MoveCursorToWithComplexTransform) {
scoped_ptr<Window> w1(
- CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL));
+ CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500),
+ root_window()));
scoped_ptr<Window> w11(
CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get()));
scoped_ptr<Window> w111(
@@ -456,7 +467,7 @@ TEST_F(WindowTest, HitTest) {
w1.Init(ui::LAYER_TEXTURED);
w1.SetBounds(gfx::Rect(10, 20, 50, 60));
w1.Show();
- w1.SetParent(NULL);
+ SetDefaultParentByPrimaryRootWindow(&w1);
// Points are in the Window's coordinates.
EXPECT_TRUE(w1.HitTest(gfx::Point(1, 1)));
@@ -487,7 +498,7 @@ TEST_F(WindowTest, HitTestMask) {
w1.Init(ui::LAYER_NOT_DRAWN);
w1.SetBounds(gfx::Rect(10, 20, 50, 60));
w1.Show();
- w1.SetParent(NULL);
+ SetDefaultParentByPrimaryRootWindow(&w1);
// Points inside the mask.
EXPECT_TRUE(w1.HitTest(gfx::Point(5, 6))); // top-left
@@ -504,7 +515,8 @@ TEST_F(WindowTest, HitTestMask) {
TEST_F(WindowTest, GetEventHandlerForPoint) {
scoped_ptr<Window> w1(
- CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL));
+ CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500),
+ root_window()));
scoped_ptr<Window> w11(
CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get()));
scoped_ptr<Window> w111(
@@ -535,7 +547,8 @@ TEST_F(WindowTest, GetEventHandlerForPointWithOverride) {
// If our child is flush to our top-left corner he gets events just inside the
// window edges.
scoped_ptr<Window> parent(
- CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 20, 400, 500), NULL));
+ CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 20, 400, 500),
+ root_window()));
scoped_ptr<Window> child(
CreateTestWindow(SK_ColorRED, 2, gfx::Rect(0, 0, 60, 70), parent.get()));
EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0)));
@@ -552,7 +565,7 @@ TEST_F(WindowTest, GetEventHandlerForPointWithOverrideDescendingOrder) {
scoped_ptr<SelfEventHandlingWindowDelegate> parent_delegate(
new SelfEventHandlingWindowDelegate);
scoped_ptr<Window> parent(CreateTestWindowWithDelegate(
- parent_delegate.get(), 1, gfx::Rect(10, 20, 400, 500), NULL));
+ parent_delegate.get(), 1, gfx::Rect(10, 20, 400, 500), root_window()));
scoped_ptr<Window> child(
CreateTestWindow(SK_ColorRED, 2, gfx::Rect(0, 0, 390, 480),
parent.get()));
@@ -568,16 +581,18 @@ TEST_F(WindowTest, GetTopWindowContainingPoint) {
root->SetBounds(gfx::Rect(0, 0, 300, 300));
scoped_ptr<Window> w1(
- CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 100, 100), NULL));
+ CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 100, 100),
+ root_window()));
scoped_ptr<Window> w11(
CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(0, 0, 120, 120), w1.get()));
scoped_ptr<Window> w2(
- CreateTestWindow(SK_ColorRED, 2, gfx::Rect(5, 5, 55, 55), NULL));
+ CreateTestWindow(SK_ColorRED, 2, gfx::Rect(5, 5, 55, 55),
+ root_window()));
scoped_ptr<Window> w3(
CreateTestWindowWithDelegate(
- NULL, 3, gfx::Rect(200, 200, 100, 100), NULL));
+ NULL, 3, gfx::Rect(200, 200, 100, 100), root_window()));
scoped_ptr<Window> w31(
CreateTestWindow(SK_ColorCYAN, 31, gfx::Rect(0, 0, 50, 50), w3.get()));
scoped_ptr<Window> w311(
@@ -632,7 +647,7 @@ class AddedToRootWindowObserver : public WindowObserver {
TEST_F(WindowTest, WindowAddedToRootWindowShouldNotifyChildAndNotParent) {
AddedToRootWindowObserver parent_observer;
AddedToRootWindowObserver child_observer;
- scoped_ptr<Window> parent_window(CreateTestWindowWithId(1, NULL));
+ scoped_ptr<Window> parent_window(CreateTestWindowWithId(1, root_window()));
scoped_ptr<Window> child_window(new Window(NULL));
child_window->Init(ui::LAYER_TEXTURED);
child_window->Show();
@@ -655,7 +670,8 @@ TEST_F(WindowTest, DestroyTest) {
ChildWindowDelegateImpl child_delegate(&parent_delegate);
{
scoped_ptr<Window> parent(
- CreateTestWindowWithDelegate(&parent_delegate, 0, gfx::Rect(), NULL));
+ CreateTestWindowWithDelegate(&parent_delegate, 0, gfx::Rect(),
+ root_window()));
CreateTestWindowWithDelegate(&child_delegate, 0, gfx::Rect(), parent.get());
}
// Both the parent and child should have been destroyed.
@@ -671,7 +687,8 @@ TEST_F(WindowTest, OrphanedBeforeOnDestroyed) {
DestroyOrphanDelegate child_delegate;
{
scoped_ptr<Window> parent(
- CreateTestWindowWithDelegate(&parent_delegate, 0, gfx::Rect(), NULL));
+ CreateTestWindowWithDelegate(&parent_delegate, 0, gfx::Rect(),
+ root_window()));
scoped_ptr<Window> child(CreateTestWindowWithDelegate(&child_delegate, 0,
gfx::Rect(), parent.get()));
child_delegate.set_window(child.get());
@@ -687,8 +704,8 @@ TEST_F(WindowTest, StackChildAtTop) {
Window child2(NULL);
child2.Init(ui::LAYER_NOT_DRAWN);
- child1.SetParent(&parent);
- child2.SetParent(&parent);
+ parent.AddChild(&child1);
+ parent.AddChild(&child2);
ASSERT_EQ(2u, parent.children().size());
EXPECT_EQ(&child1, parent.children()[0]);
EXPECT_EQ(&child2, parent.children()[1]);
@@ -719,9 +736,9 @@ TEST_F(WindowTest, StackChildBelow) {
child3.Init(ui::LAYER_NOT_DRAWN);
child3.set_id(3);
- child1.SetParent(&parent);
- child2.SetParent(&parent);
- child3.SetParent(&parent);
+ parent.AddChild(&child1);
+ parent.AddChild(&child2);
+ parent.AddChild(&child3);
EXPECT_EQ("1 2 3", ChildWindowIDsAsString(&parent));
parent.StackChildBelow(&child1, &child2);
@@ -748,8 +765,8 @@ TEST_F(WindowTest, StackChildAbove) {
Window child3(NULL);
child3.Init(ui::LAYER_NOT_DRAWN);
- child1.SetParent(&parent);
- child2.SetParent(&parent);
+ parent.AddChild(&child1);
+ parent.AddChild(&child2);
// Move 1 in front of 2.
parent.StackChildAbove(&child1, &child2);
@@ -762,7 +779,7 @@ TEST_F(WindowTest, StackChildAbove) {
// Add 3, resulting in order [2, 1, 3], then move 2 in front of 1, resulting
// in [1, 2, 3].
- child3.SetParent(&parent);
+ parent.AddChild(&child3);
parent.StackChildAbove(&child2, &child1);
ASSERT_EQ(3u, parent.children().size());
EXPECT_EQ(&child1, parent.children()[0]);
@@ -800,7 +817,7 @@ TEST_F(WindowTest, StackChildAbove) {
TEST_F(WindowTest, CaptureTests) {
CaptureWindowDelegateImpl delegate;
scoped_ptr<Window> window(CreateTestWindowWithDelegate(
- &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL));
+ &delegate, 0, gfx::Rect(0, 0, 20, 20), root_window()));
EXPECT_FALSE(window->HasCapture());
delegate.ResetCounts();
@@ -851,10 +868,10 @@ TEST_F(WindowTest, CaptureTests) {
TEST_F(WindowTest, TouchCaptureCancelsOtherTouches) {
CaptureWindowDelegateImpl delegate1;
scoped_ptr<Window> w1(CreateTestWindowWithDelegate(
- &delegate1, 0, gfx::Rect(0, 0, 20, 20), NULL));
+ &delegate1, 0, gfx::Rect(0, 0, 20, 20), root_window()));
CaptureWindowDelegateImpl delegate2;
scoped_ptr<Window> w2(CreateTestWindowWithDelegate(
- &delegate2, 0, gfx::Rect(20, 20, 20, 20), NULL));
+ &delegate2, 0, gfx::Rect(20, 20, 20, 20), root_window()));
// Press on w1.
ui::TouchEvent press(
@@ -899,7 +916,7 @@ TEST_F(WindowTest, TouchCaptureCancelsOtherTouches) {
TEST_F(WindowTest, TouchCaptureDoesntCancelCapturedTouches) {
CaptureWindowDelegateImpl delegate;
scoped_ptr<Window> window(CreateTestWindowWithDelegate(
- &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL));
+ &delegate, 0, gfx::Rect(0, 0, 20, 20), root_window()));
ui::TouchEvent press(
ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, getTime());
@@ -927,7 +944,7 @@ TEST_F(WindowTest, TransferCaptureTouchEvents) {
// Touch on |w1|.
CaptureWindowDelegateImpl d1;
scoped_ptr<Window> w1(CreateTestWindowWithDelegate(
- &d1, 0, gfx::Rect(0, 0, 20, 20), NULL));
+ &d1, 0, gfx::Rect(0, 0, 20, 20), root_window()));
ui::TouchEvent p1(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, getTime());
root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&p1);
// We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN.
@@ -937,7 +954,7 @@ TEST_F(WindowTest, TransferCaptureTouchEvents) {
// Touch on |w2| with a different id.
CaptureWindowDelegateImpl d2;
scoped_ptr<Window> w2(CreateTestWindowWithDelegate(
- &d2, 0, gfx::Rect(40, 0, 40, 20), NULL));
+ &d2, 0, gfx::Rect(40, 0, 40, 20), root_window()));
ui::TouchEvent p2(ui::ET_TOUCH_PRESSED, gfx::Point(41, 10), 1, getTime());
root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&p2);
EXPECT_EQ(0, d1.gesture_event_count());
@@ -956,7 +973,7 @@ TEST_F(WindowTest, TransferCaptureTouchEvents) {
CaptureWindowDelegateImpl d3;
scoped_ptr<Window> w3(CreateTestWindowWithDelegate(
- &d3, 0, gfx::Rect(0, 0, 100, 101), NULL));
+ &d3, 0, gfx::Rect(0, 0, 100, 101), root_window()));
// Set capture on w3. No new events should be received.
w3->SetCapture();
EXPECT_EQ(0, d1.gesture_event_count());
@@ -977,10 +994,10 @@ TEST_F(WindowTest, TransferCaptureTouchEvents) {
TEST_F(WindowTest, ChangeCaptureWhileMouseDown) {
CaptureWindowDelegateImpl delegate;
scoped_ptr<Window> window(CreateTestWindowWithDelegate(
- &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL));
+ &delegate, 0, gfx::Rect(0, 0, 20, 20), root_window()));
CaptureWindowDelegateImpl delegate2;
scoped_ptr<Window> w2(CreateTestWindowWithDelegate(
- &delegate2, 0, gfx::Rect(20, 20, 20, 20), NULL));
+ &delegate2, 0, gfx::Rect(20, 20, 20, 20), root_window()));
// Execute the scheduled draws so that mouse events are not
// aggregated.
@@ -1016,7 +1033,7 @@ TEST_F(WindowTest, ChangeCaptureWhileMouseDown) {
TEST_F(WindowTest, ReleaseCaptureOnDestroy) {
CaptureWindowDelegateImpl delegate;
scoped_ptr<Window> window(CreateTestWindowWithDelegate(
- &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL));
+ &delegate, 0, gfx::Rect(0, 0, 20, 20), root_window()));
EXPECT_FALSE(window->HasCapture());
// Do a capture.
@@ -1033,7 +1050,7 @@ TEST_F(WindowTest, ReleaseCaptureOnDestroy) {
TEST_F(WindowTest, GetBoundsInRootWindow) {
scoped_ptr<Window> viewport(CreateTestWindowWithBounds(
- gfx::Rect(0, 0, 300, 300), NULL));
+ gfx::Rect(0, 0, 300, 300), root_window()));
scoped_ptr<Window> child(CreateTestWindowWithBounds(
gfx::Rect(0, 0, 100, 100), viewport.get()));
// Sanity check.
@@ -1089,10 +1106,12 @@ class MouseEnterExitWindowDelegate : public TestWindowDelegate {
TEST_F(WindowTest, MouseEnterExit) {
MouseEnterExitWindowDelegate d1;
scoped_ptr<Window> w1(
- CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50), NULL));
+ CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50),
+ root_window()));
MouseEnterExitWindowDelegate d2;
scoped_ptr<Window> w2(
- CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(70, 70, 50, 50), NULL));
+ CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(70, 70, 50, 50),
+ root_window()));
test::EventGenerator generator(root_window());
generator.MoveMouseToCenterOf(w1.get());
@@ -1115,10 +1134,12 @@ TEST_F(WindowTest, MouseEnterExit) {
TEST_F(WindowTest, MouseEnterExitWithClick) {
MouseEnterExitWindowDelegate d1;
scoped_ptr<Window> w1(
- CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50), NULL));
+ CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50),
+ root_window()));
MouseEnterExitWindowDelegate d2;
scoped_ptr<Window> w2(
- CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(70, 70, 50, 50), NULL));
+ CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(70, 70, 50, 50),
+ root_window()));
test::EventGenerator generator(root_window());
generator.MoveMouseToCenterOf(w1.get());
@@ -1146,7 +1167,8 @@ TEST_F(WindowTest, MouseEnterExitWithClick) {
TEST_F(WindowTest, MouseEnterExitWithDelete) {
MouseEnterExitWindowDelegate d1;
scoped_ptr<Window> w1(
- CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50), NULL));
+ CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50),
+ root_window()));
test::EventGenerator generator(root_window());
generator.MoveMouseToCenterOf(w1.get());
@@ -1156,7 +1178,8 @@ TEST_F(WindowTest, MouseEnterExitWithDelete) {
{
MouseEnterExitWindowDelegate d2;
scoped_ptr<Window> w2(
- CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(10, 10, 50, 50), NULL));
+ CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(10, 10, 50, 50),
+ root_window()));
// Enters / exits can be send asynchronously.
RunAllPendingInMessageLoop();
EXPECT_TRUE(d1.entered());
@@ -1175,7 +1198,8 @@ TEST_F(WindowTest, MouseEnterExitWithDelete) {
TEST_F(WindowTest, MouseEnterExitWithHide) {
MouseEnterExitWindowDelegate d1;
scoped_ptr<Window> w1(
- CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50), NULL));
+ CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50),
+ root_window()));
test::EventGenerator generator(root_window());
generator.MoveMouseToCenterOf(w1.get());
@@ -1184,7 +1208,8 @@ TEST_F(WindowTest, MouseEnterExitWithHide) {
MouseEnterExitWindowDelegate d2;
scoped_ptr<Window> w2(
- CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(10, 10, 50, 50), NULL));
+ CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(10, 10, 50, 50),
+ root_window()));
// Enters / exits can be send asynchronously.
RunAllPendingInMessageLoop();
EXPECT_TRUE(d1.entered());
@@ -1209,7 +1234,7 @@ TEST_F(WindowTest, MouseEnterExitWithHide) {
TEST_F(WindowTest, GetEventHandlerForPoint_NoDelegate) {
TestWindowDelegate d111;
scoped_ptr<Window> w1(CreateTestWindowWithDelegate(NULL, 1,
- gfx::Rect(0, 0, 500, 500), NULL));
+ gfx::Rect(0, 0, 500, 500), root_window()));
scoped_ptr<Window> w11(CreateTestWindowWithDelegate(NULL, 11,
gfx::Rect(0, 0, 500, 500), w1.get()));
scoped_ptr<Window> w111(CreateTestWindowWithDelegate(&d111, 111,
@@ -1253,7 +1278,8 @@ class VisibilityWindowDelegate : public TestWindowDelegate {
TEST_F(WindowTest, Visibility) {
VisibilityWindowDelegate d;
VisibilityWindowDelegate d2;
- scoped_ptr<Window> w1(CreateTestWindowWithDelegate(&d, 1, gfx::Rect(), NULL));
+ scoped_ptr<Window> w1(CreateTestWindowWithDelegate(&d, 1, gfx::Rect(),
+ root_window()));
scoped_ptr<Window> w2(
CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(), w1.get()));
scoped_ptr<Window> w3(CreateTestWindowWithId(3, w2.get()));
@@ -1314,7 +1340,7 @@ TEST_F(WindowTest, IgnoreEventsTest) {
TestWindowDelegate d111;
TestWindowDelegate d121;
scoped_ptr<Window> w1(CreateTestWindowWithDelegate(NULL, 1,
- gfx::Rect(0, 0, 500, 500), NULL));
+ gfx::Rect(0, 0, 500, 500), root_window()));
scoped_ptr<Window> w11(CreateTestWindowWithDelegate(&d11, 11,
gfx::Rect(0, 0, 500, 500), w1.get()));
scoped_ptr<Window> w111(CreateTestWindowWithDelegate(&d111, 111,
@@ -1371,7 +1397,7 @@ TEST_F(WindowTest, TransformGesture) {
scoped_ptr<GestureTrackPositionDelegate> delegate(
new GestureTrackPositionDelegate);
scoped_ptr<Window> window(CreateTestWindowWithDelegate(delegate.get(), -1234,
- gfx::Rect(0, 0, 20, 20), NULL));
+ gfx::Rect(0, 0, 20, 20), root_window()));
// Rotate the root-window clock-wise 90 degrees.
gfx::Transform transform;
@@ -1387,7 +1413,7 @@ TEST_F(WindowTest, TransformGesture) {
// Various assertions for transient children.
TEST_F(WindowTest, TransientChildren) {
- scoped_ptr<Window> parent(CreateTestWindowWithId(0, NULL));
+ scoped_ptr<Window> parent(CreateTestWindowWithId(0, root_window()));
scoped_ptr<Window> w1(CreateTestWindowWithId(1, parent.get()));
scoped_ptr<Window> w3(CreateTestWindowWithId(3, parent.get()));
Window* w2 = CreateTestWindowWithId(2, parent.get());
@@ -1422,7 +1448,7 @@ TEST_F(WindowTest, TransientChildren) {
// Tests that when a focused window is closed, its parent inherits the focus.
TEST_F(WindowTest, FocusedWindowTest) {
- scoped_ptr<Window> parent(CreateTestWindowWithId(0, NULL));
+ scoped_ptr<Window> parent(CreateTestWindowWithId(0, root_window()));
scoped_ptr<Window> child(CreateTestWindowWithId(1, parent.get()));
parent->Show();
@@ -1442,14 +1468,14 @@ TEST_F(WindowTest, OldFocusedWindowTest) {
FocusDelegate delegate1;
scoped_ptr<Window> window1(
- CreateTestWindowWithDelegate(&delegate1, 0, kBounds, NULL));
+ CreateTestWindowWithDelegate(&delegate1, 0, kBounds, root_window()));
window1->Focus();
ASSERT_TRUE(window1->HasFocus());
EXPECT_TRUE(delegate1.previous_focused_window() == NULL);
FocusDelegate delegate2;
scoped_ptr<Window> window2(
- CreateTestWindowWithDelegate(&delegate2, 1, kBounds, NULL));
+ CreateTestWindowWithDelegate(&delegate2, 1, kBounds, root_window()));
window2->Focus();
ASSERT_TRUE(window2->HasFocus());
EXPECT_FALSE(window1->HasFocus());
@@ -1462,7 +1488,7 @@ DEFINE_WINDOW_PROPERTY_KEY(const char*, kStringKey, "squeamish");
}
TEST_F(WindowTest, Property) {
- scoped_ptr<Window> w(CreateTestWindowWithId(0, NULL));
+ scoped_ptr<Window> w(CreateTestWindowWithId(0, root_window()));
static const char native_prop_key[] = "fnord";
@@ -1521,7 +1547,7 @@ DEFINE_OWNED_WINDOW_PROPERTY_KEY(TestProperty, kOwnedKey, NULL);
} // namespace
TEST_F(WindowTest, OwnedProperty) {
- scoped_ptr<Window> w(CreateTestWindowWithId(0, NULL));
+ scoped_ptr<Window> w(CreateTestWindowWithId(0, root_window()));
EXPECT_EQ(NULL, w->GetProperty(kOwnedKey));
TestProperty* p1 = new TestProperty();
w->SetProperty(kOwnedKey, p1);
@@ -1550,7 +1576,7 @@ TEST_F(WindowTest, SetBoundsInternalShouldCheckTargetBounds) {
ui::LayerAnimator::set_disable_animations_for_test(false);
scoped_ptr<Window> w1(
- CreateTestWindowWithBounds(gfx::Rect(0, 0, 100, 100), NULL));
+ CreateTestWindowWithBounds(gfx::Rect(0, 0, 100, 100), root_window()));
EXPECT_FALSE(!w1->layer());
w1->layer()->GetAnimator()->set_disable_timer_for_test(true);
@@ -1680,7 +1706,7 @@ class WindowObserverTest : public WindowTest,
// Various assertions for WindowObserver.
TEST_F(WindowObserverTest, WindowObserver) {
- scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL));
+ scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window()));
w1->AddObserver(this);
// Create a new window as a child of w1, our observer should be notified.
@@ -1693,7 +1719,7 @@ TEST_F(WindowObserverTest, WindowObserver) {
// Create a window that isn't parented to w1, we shouldn't get any
// notification.
- scoped_ptr<Window> w3(CreateTestWindowWithId(3, NULL));
+ scoped_ptr<Window> w3(CreateTestWindowWithId(3, root_window()));
EXPECT_EQ("added=0 removed=0", WindowObserverCountStateAndClear());
// Similarly destroying w3 shouldn't notify us either.
@@ -1705,7 +1731,7 @@ TEST_F(WindowObserverTest, WindowObserver) {
// Test if OnWindowVisibilityChagned is invoked with expected
// parameters.
TEST_F(WindowObserverTest, WindowVisibility) {
- scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL));
+ scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window()));
scoped_ptr<Window> w2(CreateTestWindowWithId(1, w1.get()));
w2->AddObserver(this);
@@ -1747,13 +1773,13 @@ TEST_F(WindowObserverTest, WindowVisibility) {
// Test if OnWindowDestroyed is invoked as expected.
TEST_F(WindowObserverTest, WindowDestroyed) {
// Delete a window should fire a destroyed notification.
- scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL));
+ scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window()));
w1->AddObserver(this);
w1.reset();
EXPECT_EQ(1, DestroyedCountAndClear());
// Observe on child and delete parent window should fire a notification.
- scoped_ptr<Window> parent(CreateTestWindowWithId(1, NULL));
+ scoped_ptr<Window> parent(CreateTestWindowWithId(1, root_window()));
Window* child = CreateTestWindowWithId(1, parent.get()); // owned by parent
child->AddObserver(this);
parent.reset();
@@ -1762,7 +1788,7 @@ TEST_F(WindowObserverTest, WindowDestroyed) {
TEST_F(WindowObserverTest, PropertyChanged) {
// Setting property should fire a property change notification.
- scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL));
+ scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window()));
w1->AddObserver(this);
static const WindowProperty<int> prop = {-2};
@@ -1791,8 +1817,8 @@ TEST_F(WindowObserverTest, PropertyChanged) {
}
TEST_F(WindowTest, AcquireLayer) {
- scoped_ptr<Window> window1(CreateTestWindowWithId(1, NULL));
- scoped_ptr<Window> window2(CreateTestWindowWithId(2, NULL));
+ scoped_ptr<Window> window1(CreateTestWindowWithId(1, root_window()));
+ scoped_ptr<Window> window2(CreateTestWindowWithId(2, root_window()));
ui::Layer* parent = window1->parent()->layer();
EXPECT_EQ(2U, parent->children().size());
@@ -1846,7 +1872,8 @@ TEST_F(WindowTest, RecreateLayer) {
// and that RecreateLayer returns null.
TEST_F(WindowTest, AcquireThenRecreateLayer) {
scoped_ptr<Window> w(
- CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(0, 0, 100, 100), NULL));
+ CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(0, 0, 100, 100),
+ root_window()));
scoped_ptr<ui::Layer>acquired_layer(w->AcquireLayer());
scoped_ptr<ui::Layer>doubly_acquired_layer(w->RecreateLayer());
EXPECT_EQ(NULL, doubly_acquired_layer.get());
@@ -1856,8 +1883,8 @@ TEST_F(WindowTest, AcquireThenRecreateLayer) {
}
TEST_F(WindowTest, StackWindowsWhoseLayersHaveNoDelegate) {
- scoped_ptr<Window> window1(CreateTestWindowWithId(1, NULL));
- scoped_ptr<Window> window2(CreateTestWindowWithId(2, NULL));
+ scoped_ptr<Window> window1(CreateTestWindowWithId(1, root_window()));
+ scoped_ptr<Window> window2(CreateTestWindowWithId(2, root_window()));
// This brings window1 (and its layer) to the front.
root_window()->StackChildAbove(window1.get(), window2.get());
@@ -1880,12 +1907,12 @@ TEST_F(WindowTest, StackTransientsWhoseLayersHaveNoDelegate) {
RootWindow* root = root_window();
// Create a window with several transients, then a couple windows on top.
- scoped_ptr<Window> window1(CreateTestWindowWithId(1, NULL));
+ scoped_ptr<Window> window1(CreateTestWindowWithId(1, root_window()));
scoped_ptr<Window> window11(CreateTransientChild(11, window1.get()));
scoped_ptr<Window> window12(CreateTransientChild(12, window1.get()));
scoped_ptr<Window> window13(CreateTransientChild(13, window1.get()));
- scoped_ptr<Window> window2(CreateTestWindowWithId(2, NULL));
- scoped_ptr<Window> window3(CreateTestWindowWithId(3, NULL));
+ scoped_ptr<Window> window2(CreateTestWindowWithId(2, root_window()));
+ scoped_ptr<Window> window3(CreateTestWindowWithId(3, root_window()));
EXPECT_EQ("1 11 12 13 2 3", ChildWindowIDsAsString(root));
@@ -1929,7 +1956,7 @@ class TestVisibilityClient : public client::VisibilityClient {
TEST_F(WindowTest, VisibilityClientIsVisible) {
TestVisibilityClient client(root_window());
- scoped_ptr<Window> window(CreateTestWindowWithId(1, NULL));
+ scoped_ptr<Window> window(CreateTestWindowWithId(1, root_window()));
EXPECT_TRUE(window->IsVisible());
EXPECT_TRUE(window->layer()->visible());
@@ -2115,7 +2142,7 @@ TEST_F(WindowTest, StackingMadrigal) {
new StackingMadrigalLayoutManager(root_window());
StackingMadrigalVisibilityClient visibility_client(root_window());
- scoped_ptr<Window> window1(CreateTestWindowWithId(1, NULL));
+ scoped_ptr<Window> window1(CreateTestWindowWithId(1, root_window()));
scoped_ptr<Window> window11(CreateTransientChild(11, window1.get()));
visibility_client.set_ignored_window(window11.get());
@@ -2153,9 +2180,9 @@ TEST_F(WindowTest, StackingMadrigal) {
// transient with a NULL layer delegate causes that primary window to be moved,
// but the layer order not changed to match. http://crbug.com/112562
TEST_F(WindowTest, StackOverClosingTransient) {
- scoped_ptr<Window> window1(CreateTestWindowWithId(1, NULL));
+ scoped_ptr<Window> window1(CreateTestWindowWithId(1, root_window()));
scoped_ptr<Window> transient1(CreateTransientChild(11, window1.get()));
- scoped_ptr<Window> window2(CreateTestWindowWithId(2, NULL));
+ scoped_ptr<Window> window2(CreateTestWindowWithId(2, root_window()));
scoped_ptr<Window> transient2(CreateTransientChild(21, window2.get()));
// Both windows and layers are stacked in creation order.
@@ -2212,7 +2239,7 @@ TEST_F(WindowTest, StackOverClosingTransient) {
EXPECT_EQ(root->layer()->children()[2], transient2->layer());
// Open another window on top.
- scoped_ptr<Window> window3(CreateTestWindowWithId(3, NULL));
+ scoped_ptr<Window> window3(CreateTestWindowWithId(3, root_window()));
ASSERT_EQ(4u, root->children().size());
EXPECT_EQ(root->children()[0], window1.get());
@@ -2293,7 +2320,7 @@ TEST_F(WindowTest, RootWindowAttachment) {
w1->Init(ui::LAYER_NOT_DRAWN);
w1->AddObserver(&observer);
- w1->SetParent(NULL);
+ SetDefaultParentByPrimaryRootWindow(w1.get());
EXPECT_EQ(1, observer.added_count());
EXPECT_EQ(0, observer.removed_count());
@@ -2309,11 +2336,11 @@ TEST_F(WindowTest, RootWindowAttachment) {
Window* w11 = new Window(NULL);
w11->Init(ui::LAYER_NOT_DRAWN);
w11->AddObserver(&observer);
- w11->SetParent(w1.get());
+ w1->AddChild(w11);
EXPECT_EQ(0, observer.added_count());
EXPECT_EQ(0, observer.removed_count());
- w1->SetParent(NULL);
+ SetDefaultParentByPrimaryRootWindow(w1.get());
EXPECT_EQ(1, observer.added_count());
EXPECT_EQ(0, observer.removed_count());
@@ -2330,16 +2357,16 @@ TEST_F(WindowTest, RootWindowAttachment) {
w11 = new Window(NULL);
w11->Init(ui::LAYER_NOT_DRAWN);
w11->AddObserver(&observer);
- w11->SetParent(w1.get());
+ w1->AddChild(w11);
Window* w111 = new Window(NULL);
w111->Init(ui::LAYER_NOT_DRAWN);
w111->AddObserver(&observer);
- w111->SetParent(w11);
+ w11->AddChild(w111);
EXPECT_EQ(0, observer.added_count());
EXPECT_EQ(0, observer.removed_count());
- w1->SetParent(NULL);
+ SetDefaultParentByPrimaryRootWindow(w1.get());
EXPECT_EQ(2, observer.added_count());
EXPECT_EQ(0, observer.removed_count());
@@ -2359,7 +2386,7 @@ TEST_F(WindowTest, OwnedByParentFalse) {
scoped_ptr<Window> w2(new Window(NULL));
w2->set_owned_by_parent(false);
w2->Init(ui::LAYER_NOT_DRAWN);
- w2->SetParent(w1.get());
+ w1->AddChild(w2.get());
w1.reset();
@@ -2402,10 +2429,10 @@ TEST_F(WindowTest, DeleteWindowFromOnWindowDestroyed) {
OwningWindowDelegate delegate;
Window* c1 = new Window(&delegate);
c1->Init(ui::LAYER_NOT_DRAWN);
- c1->SetParent(parent.get());
+ parent->AddChild(c1);
Window* c2 = new Window(NULL);
c2->Init(ui::LAYER_NOT_DRAWN);
- c2->SetParent(parent.get());
+ parent->AddChild(c2);
delegate.SetOwnedWindow(c2);
parent.reset();
}
@@ -2448,7 +2475,7 @@ TEST_F(WindowTest, DelegateNotifiedAsBoundsChange) {
scoped_ptr<Window> window(
CreateTestWindowWithDelegate(&delegate, 1,
- gfx::Rect(0, 0, 100, 100), NULL));
+ gfx::Rect(0, 0, 100, 100), root_window()));
window->layer()->GetAnimator()->set_disable_timer_for_test(true);
delegate.clear_bounds_changed();
@@ -2482,7 +2509,7 @@ TEST_F(WindowTest, DelegateNotifiedAsBoundsChangeInHiddenLayer) {
scoped_ptr<Window> window(
CreateTestWindowWithDelegate(&delegate, 1,
- gfx::Rect(0, 0, 100, 100), NULL));
+ gfx::Rect(0, 0, 100, 100), root_window()));
window->layer()->GetAnimator()->set_disable_timer_for_test(true);
delegate.clear_bounds_changed();
@@ -2550,8 +2577,8 @@ class AddChildNotificationsObserver : public WindowObserver {
// Assertions around when root window notifications are sent.
TEST_F(WindowTest, AddChildNotifications) {
AddChildNotificationsObserver observer;
- scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL));
- scoped_ptr<Window> w2(CreateTestWindowWithId(1, NULL));
+ scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window()));
+ scoped_ptr<Window> w2(CreateTestWindowWithId(1, root_window()));
w2->AddObserver(&observer);
w2->Focus();
EXPECT_TRUE(w2->HasFocus());
diff --git a/ui/views/corewm/compound_event_filter_unittest.cc b/ui/views/corewm/compound_event_filter_unittest.cc
index d073200..677d267 100644
--- a/ui/views/corewm/compound_event_filter_unittest.cc
+++ b/ui/views/corewm/compound_event_filter_unittest.cc
@@ -80,7 +80,7 @@ TEST_F(CompoundEventFilterTest, TouchHidesCursor) {
aura::Env::GetInstance()->AddPreTargetHandler(compound_filter.get());
aura::test::TestWindowDelegate delegate;
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(&delegate, 1234,
- gfx::Rect(5, 5, 100, 100), NULL));
+ gfx::Rect(5, 5, 100, 100), root_window()));
window->Show();
window->SetCapture();
@@ -132,8 +132,9 @@ TEST_F(CompoundEventFilterTest, FilterConsumedGesture) {
compound_filter->AddHandler(gesure_handler.get());
aura::Env::GetInstance()->AddPreTargetHandler(compound_filter.get());
aura::test::TestWindowDelegate delegate;
+ DCHECK(root_window());
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(&delegate, 1234,
- gfx::Rect(5, 5, 100, 100), NULL));
+ gfx::Rect(5, 5, 100, 100), root_window()));
window->Show();
EXPECT_TRUE(window->CanFocus());
diff --git a/ui/views/corewm/focus_controller_unittest.cc b/ui/views/corewm/focus_controller_unittest.cc
index 2d0ca22..b54db01 100644
--- a/ui/views/corewm/focus_controller_unittest.cc
+++ b/ui/views/corewm/focus_controller_unittest.cc
@@ -152,7 +152,7 @@ class FocusControllerTestBase : public aura::test::AuraTestBase {
// +-- w3
aura::Window* w1 = aura::test::CreateTestWindowWithDelegate(
aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 1,
- gfx::Rect(0, 0, 50, 50), NULL);
+ gfx::Rect(0, 0, 50, 50), root_window());
aura::test::CreateTestWindowWithDelegate(
aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 11,
gfx::Rect(5, 5, 10, 10), w1);
@@ -161,7 +161,7 @@ class FocusControllerTestBase : public aura::test::AuraTestBase {
gfx::Rect(15, 15, 10, 10), w1);
aura::Window* w2 = aura::test::CreateTestWindowWithDelegate(
aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 2,
- gfx::Rect(75, 75, 50, 50), NULL);
+ gfx::Rect(75, 75, 50, 50), root_window());
aura::Window* w21 = aura::test::CreateTestWindowWithDelegate(
aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 21,
gfx::Rect(5, 5, 10, 10), w2);
@@ -170,7 +170,7 @@ class FocusControllerTestBase : public aura::test::AuraTestBase {
gfx::Rect(1, 1, 5, 5), w21);
aura::test::CreateTestWindowWithDelegate(
aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), 3,
- gfx::Rect(125, 125, 50, 50), NULL);
+ gfx::Rect(125, 125, 50, 50), root_window());
}
virtual void TearDown() OVERRIDE {
root_window()->RemovePreTargetHandler(focus_controller());
diff --git a/ui/views/corewm/shadow_controller_unittest.cc b/ui/views/corewm/shadow_controller_unittest.cc
index 798159a..b9f2eb1 100644
--- a/ui/views/corewm/shadow_controller_unittest.cc
+++ b/ui/views/corewm/shadow_controller_unittest.cc
@@ -54,7 +54,7 @@ TEST_F(ShadowControllerTest, Shadow) {
scoped_ptr<aura::Window> window(new aura::Window(NULL));
window->SetType(aura::client::WINDOW_TYPE_NORMAL);
window->Init(ui::LAYER_TEXTURED);
- window->SetParent(NULL);
+ SetDefaultParentByPrimaryRootWindow(window.get());
// We should create the shadow before the window is visible (the shadow's
// layer won't get drawn yet since it's a child of the window's layer).
@@ -90,7 +90,7 @@ TEST_F(ShadowControllerTest, ShadowBounds) {
scoped_ptr<aura::Window> window(new aura::Window(NULL));
window->SetType(aura::client::WINDOW_TYPE_NORMAL);
window->Init(ui::LAYER_TEXTURED);
- window->SetParent(NULL);
+ SetDefaultParentByPrimaryRootWindow(window.get());
window->Show();
const gfx::Rect kOldBounds(20, 30, 400, 300);
@@ -119,7 +119,7 @@ TEST_F(ShadowControllerTest, ShadowStyle) {
scoped_ptr<aura::Window> window1(new aura::Window(NULL));
window1->SetType(aura::client::WINDOW_TYPE_NORMAL);
window1->Init(ui::LAYER_TEXTURED);
- window1->SetParent(NULL);
+ SetDefaultParentByPrimaryRootWindow(window1.get());
window1->SetBounds(gfx::Rect(10, 20, 300, 400));
window1->Show();
ActivateWindow(window1.get());
@@ -133,7 +133,7 @@ TEST_F(ShadowControllerTest, ShadowStyle) {
scoped_ptr<aura::Window> window2(new aura::Window(NULL));
window2->SetType(aura::client::WINDOW_TYPE_NORMAL);
window2->Init(ui::LAYER_TEXTURED);
- window2->SetParent(NULL);
+ SetDefaultParentByPrimaryRootWindow(window2.get());
window2->SetBounds(gfx::Rect(11, 21, 301, 401));
window2->Show();
ActivateWindow(window2.get());
@@ -152,7 +152,7 @@ TEST_F(ShadowControllerTest, SmallShadowsForTooltipsAndMenus) {
scoped_ptr<aura::Window> tooltip_window(new aura::Window(NULL));
tooltip_window->SetType(aura::client::WINDOW_TYPE_TOOLTIP);
tooltip_window->Init(ui::LAYER_TEXTURED);
- tooltip_window->SetParent(NULL);
+ SetDefaultParentByPrimaryRootWindow(tooltip_window.get());
tooltip_window->SetBounds(gfx::Rect(10, 20, 300, 400));
tooltip_window->Show();
@@ -163,7 +163,7 @@ TEST_F(ShadowControllerTest, SmallShadowsForTooltipsAndMenus) {
scoped_ptr<aura::Window> menu_window(new aura::Window(NULL));
menu_window->SetType(aura::client::WINDOW_TYPE_MENU);
menu_window->Init(ui::LAYER_TEXTURED);
- menu_window->SetParent(NULL);
+ SetDefaultParentByPrimaryRootWindow(menu_window.get());
menu_window->SetBounds(gfx::Rect(10, 20, 300, 400));
menu_window->Show();
@@ -180,7 +180,7 @@ TEST_F(ShadowControllerTest, TransientParentKeepsActiveShadow) {
scoped_ptr<aura::Window> window1(new aura::Window(NULL));
window1->SetType(aura::client::WINDOW_TYPE_NORMAL);
window1->Init(ui::LAYER_TEXTURED);
- window1->SetParent(NULL);
+ SetDefaultParentByPrimaryRootWindow(window1.get());
window1->SetBounds(gfx::Rect(10, 20, 300, 400));
window1->Show();
ActivateWindow(window1.get());
@@ -196,7 +196,7 @@ TEST_F(ShadowControllerTest, TransientParentKeepsActiveShadow) {
scoped_ptr<aura::Window> window2(new aura::Window(NULL));
window2->SetType(aura::client::WINDOW_TYPE_NORMAL);
window2->Init(ui::LAYER_TEXTURED);
- window2->SetParent(NULL);
+ SetDefaultParentByPrimaryRootWindow(window2.get());
window2->SetBounds(gfx::Rect(11, 21, 301, 401));
window1->AddTransientChild(window2.get());
aura::client::SetHideOnDeactivate(window2.get(), true);
diff --git a/ui/views/widget/native_widget_aura.cc b/ui/views/widget/native_widget_aura.cc
index ec9cd7c..53b4b6f 100644
--- a/ui/views/widget/native_widget_aura.cc
+++ b/ui/views/widget/native_widget_aura.cc
@@ -108,24 +108,18 @@ void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) {
delegate_->OnNativeWidgetCreated();
gfx::Rect window_bounds = params.bounds;
- if (params.child) {
- window_->SetParent(params.GetParent());
- } else {
+ gfx::NativeView parent = params.GetParent();
+ if (!params.child) {
// Set up the transient child before the window is added. This way the
// LayoutManager knows the window has a transient parent.
- gfx::NativeView parent = params.GetParent();
if (parent && parent->type() != aura::client::WINDOW_TYPE_UNKNOWN) {
parent->AddTransientChild(window_);
parent = NULL;
}
// SetAlwaysOnTop before SetParent so that always-on-top container is used.
SetAlwaysOnTop(params.keep_on_top);
- // If the parent is not specified, find the default parent for
- // the |window_| using the desired |window_bounds|.
- if (!parent) {
- parent = aura::client::GetStackingClient(params.GetParent())->
- GetDefaultParent(params.context, window_, window_bounds);
- } else if (window_bounds == gfx::Rect()) {
+ // Make sure we have a real |window_bounds|.
+ if (parent && window_bounds == gfx::Rect()) {
// If a parent is specified but no bounds are given,
// use the origin of the parent's display so that the widget
// will be added to the same display as the parent.
@@ -133,7 +127,16 @@ void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) {
GetDisplayNearestWindow(parent).bounds();
window_bounds.set_origin(bounds.origin());
}
- window_->SetParent(parent);
+ }
+
+ if (parent) {
+ parent->AddChild(window_);
+ } else {
+ // TODO(erg): Remove this NULL check once we've made everything in views
+ // actually pass us a context.
+ aura::RootWindow* root_window =
+ params.context ? params.context->GetRootWindow() : NULL;
+ window_->SetDefaultParentByRootWindow(root_window, window_bounds);
}
// Wait to set the bounds until we have a parent. That way we can know our
@@ -1027,7 +1030,23 @@ void NativeWidgetPrivate::ReparentNativeView(gfx::NativeView native_view,
(*it)->NotifyNativeViewHierarchyChanged(false, previous_parent);
}
- native_view->SetParent(new_parent);
+ if (new_parent) {
+ new_parent->AddChild(native_view);
+ } else {
+ // The following looks weird, but it's the equivalent of what aura has
+ // always done. (The previous behaviour of aura::Window::SetParent() used
+ // NULL as a special value that meant ask the StackingClient where things
+ // should go.)
+ //
+ // This probably isn't strictly correct, but its an invariant that a Window
+ // in use will be attached to a RootWindow, so we can't just call
+ // RemoveChild here. The only possible thing that could assign a RootWindow
+ // in this case is the stacking client of the current RootWindow. This
+ // matches our previous behaviour; the global stacking client would almost
+ // always reattach the window to the same RootWindow.
+ native_view->SetDefaultParentByRootWindow(native_view->GetRootWindow(),
+ gfx::Rect());
+ }
// And now, notify them that they have a brand new parent.
for (Widget::Widgets::iterator it = widgets.begin();
diff --git a/ui/views/widget/widget.h b/ui/views/widget/widget.h
index 525402f..139c69a 100644
--- a/ui/views/widget/widget.h
+++ b/ui/views/widget/widget.h
@@ -193,7 +193,7 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,
ui::LayerType layer_type;
// Only used by Aura. Provides additional context (generally a RootWindow)
// during creation to allow the widget to determine which desktop type it
- // will belong to. NULL indicates a normal native desktop.
+ // will belong to. NULL is not allowed if you are using aura.
gfx::NativeView context;
};