| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/widget/native_widget_aura.h" | 5 #include "ui/views/widget/native_widget_aura.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 view->clear_got_gesture_event(); | 308 view->clear_got_gesture_event(); |
| 309 EXPECT_FALSE(widget->HasCapture()); | 309 EXPECT_FALSE(widget->HasCapture()); |
| 310 | 310 |
| 311 // Work around for bug in NativeWidgetAura. | 311 // Work around for bug in NativeWidgetAura. |
| 312 // TODO: fix bug and remove this. | 312 // TODO: fix bug and remove this. |
| 313 widget->Close(); | 313 widget->Close(); |
| 314 } | 314 } |
| 315 | 315 |
| 316 // Verifies views with layers are targeted for events properly. | 316 // Verifies views with layers are targeted for events properly. |
| 317 TEST_F(NativeWidgetAuraTest, PreferViewLayersToChildWindows) { | 317 TEST_F(NativeWidgetAuraTest, PreferViewLayersToChildWindows) { |
| 318 // Create two widget, |parent_root| and |child|. |child| is a child of | 318 // Create two widgets: |parent| and |child|. |child| is a child of |parent|. |
| 319 // |parent_root|. | |
| 320 views::View* parent_root = new views::View; | 319 views::View* parent_root = new views::View; |
| 321 scoped_ptr<Widget> parent(new Widget()); | 320 scoped_ptr<Widget> parent(new Widget()); |
| 322 Widget::InitParams parent_params(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 321 Widget::InitParams parent_params(Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 323 parent_params.ownership = | 322 parent_params.ownership = |
| 324 views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 323 views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 325 parent_params.context = root_window(); | 324 parent_params.context = root_window(); |
| 326 parent->Init(parent_params); | 325 parent->Init(parent_params); |
| 327 parent->SetContentsView(parent_root); | 326 parent->SetContentsView(parent_root); |
| 328 parent->SetBounds(gfx::Rect(0, 0, 400, 400)); | 327 parent->SetBounds(gfx::Rect(0, 0, 400, 400)); |
| 329 parent->Show(); | 328 parent->Show(); |
| 330 | 329 |
| 331 scoped_ptr<Widget> child(new Widget()); | 330 scoped_ptr<Widget> child(new Widget()); |
| 332 Widget::InitParams child_params(Widget::InitParams::TYPE_CONTROL); | 331 Widget::InitParams child_params(Widget::InitParams::TYPE_CONTROL); |
| 333 child_params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 332 child_params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 334 child_params.parent = parent->GetNativeWindow(); | 333 child_params.parent = parent->GetNativeWindow(); |
| 335 child->Init(child_params); | 334 child->Init(child_params); |
| 336 child->SetBounds(gfx::Rect(0, 0, 200, 200)); | 335 child->SetBounds(gfx::Rect(0, 0, 200, 200)); |
| 337 child->Show(); | 336 child->Show(); |
| 338 | 337 |
| 339 // Point is over |child|. | 338 // Point is over |child|. |
| 340 EXPECT_EQ(child->GetNativeWindow(), | 339 EXPECT_EQ(child->GetNativeWindow(), |
| 341 parent->GetNativeWindow()->GetEventHandlerForPoint( | 340 parent->GetNativeWindow()->GetEventHandlerForPoint( |
| 342 gfx::Point(50, 50))); | 341 gfx::Point(50, 50))); |
| 343 | 342 |
| 344 // Create a view with a layer and stack it at the top (above |child|). | 343 // Create a view with a layer and stack it at the bottom (below |child|). |
| 345 views::View* view_with_layer = new views::View; | 344 views::View* view_with_layer = new views::View; |
| 346 parent_root->AddChildView(view_with_layer); | 345 parent_root->AddChildView(view_with_layer); |
| 347 view_with_layer->SetBounds(0, 0, 50, 50); | 346 view_with_layer->SetBounds(0, 0, 50, 50); |
| 348 view_with_layer->SetPaintToLayer(true); | 347 view_with_layer->SetPaintToLayer(true); |
| 349 | 348 |
| 350 // Point is over |view_with_layer|, it should get the event. | 349 // Make sure that |child| still gets the event. |
| 350 EXPECT_EQ(child->GetNativeWindow(), |
| 351 parent->GetNativeWindow()->GetEventHandlerForPoint( |
| 352 gfx::Point(20, 20))); |
| 353 |
| 354 // Move |view_with_layer| to the top and make sure it gets the |
| 355 // event when the point is within |view_with_layer|'s bounds. |
| 356 view_with_layer->layer()->parent()->StackAtTop( |
| 357 view_with_layer->layer()); |
| 351 EXPECT_EQ(parent->GetNativeWindow(), | 358 EXPECT_EQ(parent->GetNativeWindow(), |
| 352 parent->GetNativeWindow()->GetEventHandlerForPoint( | 359 parent->GetNativeWindow()->GetEventHandlerForPoint( |
| 353 gfx::Point(20, 20))); | 360 gfx::Point(20, 20))); |
| 354 | 361 |
| 355 // Point is over |child|, it should get the event. | 362 // Point is over |child|, it should get the event. |
| 356 EXPECT_EQ(child->GetNativeWindow(), | 363 EXPECT_EQ(child->GetNativeWindow(), |
| 357 parent->GetNativeWindow()->GetEventHandlerForPoint( | 364 parent->GetNativeWindow()->GetEventHandlerForPoint( |
| 358 gfx::Point(70, 70))); | 365 gfx::Point(70, 70))); |
| 359 | 366 |
| 360 // Move |child| to the top and make sure it gets the event. | |
| 361 child->GetNativeWindow()->layer()->parent()->StackAtTop( | |
| 362 child->GetNativeWindow()->layer()); | |
| 363 EXPECT_EQ(child->GetNativeWindow(), | |
| 364 parent->GetNativeWindow()->GetEventHandlerForPoint( | |
| 365 gfx::Point(20, 20))); | |
| 366 | |
| 367 delete view_with_layer; | 367 delete view_with_layer; |
| 368 view_with_layer = NULL; | 368 view_with_layer = NULL; |
| 369 | 369 |
| 370 EXPECT_EQ(child->GetNativeWindow(), | 370 EXPECT_EQ(child->GetNativeWindow(), |
| 371 parent->GetNativeWindow()->GetEventHandlerForPoint( | 371 parent->GetNativeWindow()->GetEventHandlerForPoint( |
| 372 gfx::Point(20, 20))); | 372 gfx::Point(20, 20))); |
| 373 | 373 |
| 374 // Work around for bug in NativeWidgetAura. | 374 // Work around for bug in NativeWidgetAura. |
| 375 // TODO: fix bug and remove this. | 375 // TODO: fix bug and remove this. |
| 376 parent->Close(); | 376 parent->Close(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 403 scoped_ptr<Widget> widget(new Widget()); | 403 scoped_ptr<Widget> widget(new Widget()); |
| 404 NativeWidgetAura* window = Init(parent.get(), widget.get()); | 404 NativeWidgetAura* window = Init(parent.get(), widget.get()); |
| 405 window->Show(); | 405 window->Show(); |
| 406 window->Close(); | 406 window->Close(); |
| 407 base::MessageLoop::current()->RunUntilIdle(); | 407 base::MessageLoop::current()->RunUntilIdle(); |
| 408 widget->GetNativeTheme(); // Shouldn't crash. | 408 widget->GetNativeTheme(); // Shouldn't crash. |
| 409 } | 409 } |
| 410 | 410 |
| 411 } // namespace | 411 } // namespace |
| 412 } // namespace views | 412 } // namespace views |
| OLD | NEW |