| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "ash/accessibility_delegate.h" | 7 #include "ash/accessibility_delegate.h" |
| 8 #include "ash/drag_drop/drag_drop_controller.h" | 8 #include "ash/drag_drop/drag_drop_controller.h" |
| 9 #include "ash/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
| 10 #include "ash/screen_util.h" | 10 #include "ash/screen_util.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 #include "ui/aura/test/test_window_delegate.h" | 39 #include "ui/aura/test/test_window_delegate.h" |
| 40 #include "ui/aura/test/test_windows.h" | 40 #include "ui/aura/test/test_windows.h" |
| 41 #include "ui/aura/window.h" | 41 #include "ui/aura/window.h" |
| 42 #include "ui/aura/window_event_dispatcher.h" | 42 #include "ui/aura/window_event_dispatcher.h" |
| 43 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 43 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
| 44 #include "ui/events/test/event_generator.h" | 44 #include "ui/events/test/event_generator.h" |
| 45 #include "ui/gfx/geometry/point_conversions.h" | 45 #include "ui/gfx/geometry/point_conversions.h" |
| 46 #include "ui/gfx/geometry/rect_conversions.h" | 46 #include "ui/gfx/geometry/rect_conversions.h" |
| 47 #include "ui/gfx/transform.h" | 47 #include "ui/gfx/transform.h" |
| 48 #include "ui/gfx/transform_util.h" | 48 #include "ui/gfx/transform_util.h" |
| 49 #include "ui/views/controls/label.h" | 49 #include "ui/views/controls/button/label_button.h" |
| 50 #include "ui/views/widget/native_widget_aura.h" | 50 #include "ui/views/widget/native_widget_aura.h" |
| 51 #include "ui/views/widget/widget_delegate.h" | 51 #include "ui/views/widget/widget_delegate.h" |
| 52 #include "ui/wm/core/window_util.h" | 52 #include "ui/wm/core/window_util.h" |
| 53 #include "ui/wm/public/activation_delegate.h" | 53 #include "ui/wm/public/activation_delegate.h" |
| 54 | 54 |
| 55 namespace ash { | 55 namespace ash { |
| 56 namespace { | 56 namespace { |
| 57 | 57 |
| 58 class NonActivatableActivationDelegate | 58 class NonActivatableActivationDelegate |
| 59 : public aura::client::ActivationDelegate { | 59 : public aura::client::ActivationDelegate { |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 WindowSelector* ws = ash::Shell::GetInstance()-> | 207 WindowSelector* ws = ash::Shell::GetInstance()-> |
| 208 window_selector_controller()->window_selector_.get(); | 208 window_selector_controller()->window_selector_.get(); |
| 209 return ws->text_filter_widget_->GetNativeWindow()->layer()-> | 209 return ws->text_filter_widget_->GetNativeWindow()->layer()-> |
| 210 GetTargetTransform().IsIdentity(); | 210 GetTargetTransform().IsIdentity(); |
| 211 } | 211 } |
| 212 | 212 |
| 213 views::Widget* GetCloseButton(ash::WindowSelectorItem* window) { | 213 views::Widget* GetCloseButton(ash::WindowSelectorItem* window) { |
| 214 return &(window->close_button_widget_); | 214 return &(window->close_button_widget_); |
| 215 } | 215 } |
| 216 | 216 |
| 217 views::Label* GetLabelView(ash::WindowSelectorItem* window) { | 217 views::LabelButton* GetLabelButtonView(ash::WindowSelectorItem* window) { |
| 218 return window->window_label_view_; | 218 return static_cast<views::LabelButton*>( |
| 219 window->window_label_->GetContentsView()); |
| 219 } | 220 } |
| 220 | 221 |
| 221 // Tests that a window is contained within a given WindowSelectorItem, and | 222 // Tests that a window is contained within a given WindowSelectorItem, and |
| 222 // that both the window and its matching close button are within the same | 223 // that both the window and its matching close button are within the same |
| 223 // screen. | 224 // screen. |
| 224 void IsWindowAndCloseButtonInScreen(aura::Window* window, | 225 void IsWindowAndCloseButtonInScreen(aura::Window* window, |
| 225 WindowSelectorItem* window_item) { | 226 WindowSelectorItem* window_item) { |
| 226 aura::Window* root_window = window_item->root_window(); | 227 aura::Window* root_window = window_item->root_window(); |
| 227 EXPECT_TRUE(window_item->Contains(window)); | 228 EXPECT_TRUE(window_item->Contains(window)); |
| 228 EXPECT_TRUE(root_window->GetBoundsInScreen().Contains( | 229 EXPECT_TRUE(root_window->GetBoundsInScreen().Contains( |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 gfx::Rect bounds = | 340 gfx::Rect bounds = |
| 340 gfx::ToEnclosingRect(GetTransformedBoundsInRootWindow(window.get())); | 341 gfx::ToEnclosingRect(GetTransformedBoundsInRootWindow(window.get())); |
| 341 ui::test::EventGenerator event_generator(window->GetRootWindow(), | 342 ui::test::EventGenerator event_generator(window->GetRootWindow(), |
| 342 bounds.CenterPoint()); | 343 bounds.CenterPoint()); |
| 343 | 344 |
| 344 // Press down on the window. | 345 // Press down on the window. |
| 345 const int kTouchId = 19; | 346 const int kTouchId = 19; |
| 346 event_generator.PressTouchId(kTouchId); | 347 event_generator.PressTouchId(kTouchId); |
| 347 | 348 |
| 348 // Tap on the desktop, which should not cause a crash. Overview mode should | 349 // Tap on the desktop, which should not cause a crash. Overview mode should |
| 349 // remain engaged because the transparent widget over the window has capture. | 350 // be disengaged. |
| 350 event_generator.GestureTapAt(gfx::Point(0, 0)); | 351 event_generator.GestureTapAt(gfx::Point(0, 0)); |
| 351 EXPECT_TRUE(IsSelecting()); | 352 EXPECT_FALSE(IsSelecting()); |
| 352 | 353 |
| 353 event_generator.ReleaseTouchId(kTouchId); | 354 event_generator.ReleaseTouchId(kTouchId); |
| 354 } | 355 } |
| 355 | 356 |
| 356 // Tests that we do not crash and a window is selected when appropriate when | 357 // Tests that we do not crash and a window is selected when appropriate when |
| 357 // we click on a window during touch. | 358 // we click on a window during touch. |
| 358 TEST_F(WindowSelectorTest, ClickOnWindowDuringTouch) { | 359 TEST_F(WindowSelectorTest, ClickOnWindowDuringTouch) { |
| 359 gfx::Rect bounds(0, 0, 400, 400); | 360 gfx::Rect bounds(0, 0, 400, 400); |
| 360 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); | 361 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); |
| 361 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); | 362 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); |
| 362 wm::ActivateWindow(window2.get()); | 363 wm::ActivateWindow(window2.get()); |
| 363 EXPECT_FALSE(wm::IsActiveWindow(window1.get())); | 364 EXPECT_FALSE(wm::IsActiveWindow(window1.get())); |
| 364 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); | 365 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); |
| 365 | 366 |
| 366 ToggleOverview(); | 367 ToggleOverview(); |
| 367 | 368 |
| 368 gfx::Rect window1_bounds = | 369 gfx::Rect window1_bounds = |
| 369 gfx::ToEnclosingRect(GetTransformedBoundsInRootWindow(window1.get())); | 370 gfx::ToEnclosingRect(GetTransformedBoundsInRootWindow(window1.get())); |
| 370 ui::test::EventGenerator event_generator(window1->GetRootWindow(), | 371 ui::test::EventGenerator event_generator(window1->GetRootWindow(), |
| 371 window1_bounds.CenterPoint()); | 372 window1_bounds.CenterPoint()); |
| 372 | 373 |
| 373 // Clicking on |window2| while touching on |window1| should not cause a | 374 // Clicking on |window2| while touching on |window1| should not cause a |
| 374 // crash, and overview mode should remain engaged because |window1| | 375 // crash, and |window2| should be selected. |
| 375 // has capture. | |
| 376 const int kTouchId = 19; | 376 const int kTouchId = 19; |
| 377 event_generator.PressTouchId(kTouchId); | 377 event_generator.PressTouchId(kTouchId); |
| 378 event_generator.MoveMouseToCenterOf(window2.get()); | 378 event_generator.MoveMouseToCenterOf(window2.get()); |
| 379 event_generator.ClickLeftButton(); | 379 event_generator.ClickLeftButton(); |
| 380 EXPECT_TRUE(IsSelecting()); | 380 EXPECT_FALSE(IsSelecting()); |
| 381 event_generator.ReleaseTouchId(kTouchId); | 381 event_generator.ReleaseTouchId(kTouchId); |
| 382 | 382 |
| 383 ToggleOverview(); |
| 384 |
| 383 // Clicking on |window1| while touching on |window1| should not cause | 385 // Clicking on |window1| while touching on |window1| should not cause |
| 384 // a crash, overview mode should be disengaged, and |window1| should | 386 // a crash, overview mode should be disengaged, and |window1| should |
| 385 // be active. | 387 // be active. |
| 386 event_generator.MoveMouseToCenterOf(window1.get()); | 388 event_generator.MoveMouseToCenterOf(window1.get()); |
| 387 event_generator.PressTouchId(kTouchId); | 389 event_generator.PressTouchId(kTouchId); |
| 388 event_generator.ClickLeftButton(); | 390 event_generator.ClickLeftButton(); |
| 389 EXPECT_FALSE(IsSelecting()); | 391 EXPECT_FALSE(IsSelecting()); |
| 390 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); | 392 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); |
| 391 EXPECT_FALSE(wm::IsActiveWindow(window2.get())); | 393 EXPECT_FALSE(wm::IsActiveWindow(window2.get())); |
| 392 event_generator.ReleaseTouchId(kTouchId); | 394 event_generator.ReleaseTouchId(kTouchId); |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 RunAllPendingInMessageLoop(); | 905 RunAllPendingInMessageLoop(); |
| 904 } | 906 } |
| 905 | 907 |
| 906 // Test that a label is created under the window on entering overview mode. | 908 // Test that a label is created under the window on entering overview mode. |
| 907 TEST_F(WindowSelectorTest, CreateLabelUnderWindow) { | 909 TEST_F(WindowSelectorTest, CreateLabelUnderWindow) { |
| 908 scoped_ptr<aura::Window> window(CreateWindow(gfx::Rect(0, 0, 100, 100))); | 910 scoped_ptr<aura::Window> window(CreateWindow(gfx::Rect(0, 0, 100, 100))); |
| 909 base::string16 window_title = base::UTF8ToUTF16("My window"); | 911 base::string16 window_title = base::UTF8ToUTF16("My window"); |
| 910 window->SetTitle(window_title); | 912 window->SetTitle(window_title); |
| 911 ToggleOverview(); | 913 ToggleOverview(); |
| 912 WindowSelectorItem* window_item = GetWindowItemsForRoot(0).back(); | 914 WindowSelectorItem* window_item = GetWindowItemsForRoot(0).back(); |
| 913 views::Label* label = GetLabelView(window_item); | 915 views::LabelButton* label = GetLabelButtonView(window_item); |
| 914 // Has the label view been created? | 916 // Has the label view been created? |
| 915 ASSERT_TRUE(label); | 917 ASSERT_TRUE(label); |
| 916 | 918 |
| 917 // Verify the label matches the window title. | 919 // Verify the label matches the window title. |
| 918 EXPECT_EQ(label->text(), window_title); | 920 EXPECT_EQ(label->GetText(), window_title); |
| 919 | 921 |
| 920 // Update the window title and check that the label is updated, too. | 922 // Update the window title and check that the label is updated, too. |
| 921 base::string16 updated_title = base::UTF8ToUTF16("Updated title"); | 923 base::string16 updated_title = base::UTF8ToUTF16("Updated title"); |
| 922 window->SetTitle(updated_title); | 924 window->SetTitle(updated_title); |
| 923 EXPECT_EQ(label->text(), updated_title); | 925 EXPECT_EQ(label->GetText(), updated_title); |
| 924 | 926 |
| 925 // Labels are located based on target_bounds, not the actual window item | 927 // Labels are located based on target_bounds, not the actual window item |
| 926 // bounds. | 928 // bounds. |
| 927 gfx::Rect target_bounds(window_item->target_bounds()); | 929 gfx::Rect target_bounds(window_item->target_bounds()); |
| 928 gfx::Rect expected_label_bounds(target_bounds.x(), | 930 gfx::Rect expected_label_bounds(target_bounds.x(), |
| 929 target_bounds.bottom() - label-> | 931 target_bounds.bottom() - label-> |
| 930 GetPreferredSize().height(), | 932 GetPreferredSize().height(), |
| 931 target_bounds.width(), | 933 target_bounds.width(), |
| 932 label->GetPreferredSize().height()); | 934 label->GetPreferredSize().height()); |
| 933 gfx::Rect real_label_bounds = label->GetWidget()->GetNativeWindow()->bounds(); | 935 gfx::Rect real_label_bounds = label->GetWidget()->GetNativeWindow()->bounds(); |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1244 // Switch to overview mode. | 1246 // Switch to overview mode. |
| 1245 ToggleOverview(); | 1247 ToggleOverview(); |
| 1246 ASSERT_TRUE(IsSelecting()); | 1248 ASSERT_TRUE(IsSelecting()); |
| 1247 | 1249 |
| 1248 // Tap should now exit overview mode. | 1250 // Tap should now exit overview mode. |
| 1249 generator.GestureTapAt(point_in_background_page); | 1251 generator.GestureTapAt(point_in_background_page); |
| 1250 EXPECT_FALSE(IsSelecting()); | 1252 EXPECT_FALSE(IsSelecting()); |
| 1251 } | 1253 } |
| 1252 | 1254 |
| 1253 } // namespace ash | 1255 } // namespace ash |
| OLD | NEW |