Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: ash/wm/drag_window_resizer_unittest.cc

Issue 1992853002: Create a LayerDelegate for recreated layers to draw when their content is invalidated. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "ash/wm/drag_window_resizer.h" 5 #include "ash/wm/drag_window_resizer.h"
6 6
7 #include "ash/display/display_manager.h" 7 #include "ash/display/display_manager.h"
8 #include "ash/display/mouse_cursor_event_filter.h" 8 #include "ash/display/mouse_cursor_event_filter.h"
9 #include "ash/root_window_controller.h" 9 #include "ash/root_window_controller.h"
10 #include "ash/shelf/shelf_layout_manager.h" 10 #include "ash/shelf/shelf_layout_manager.h"
11 #include "ash/shell.h" 11 #include "ash/shell.h"
12 #include "ash/shell_window_ids.h" 12 #include "ash/shell_window_ids.h"
13 #include "ash/test/ash_test_base.h" 13 #include "ash/test/ash_test_base.h"
14 #include "ash/test/cursor_manager_test_api.h" 14 #include "ash/test/cursor_manager_test_api.h"
15 #include "ash/test/display_manager_test_api.h" 15 #include "ash/test/display_manager_test_api.h"
16 #include "ash/wm/aura/wm_window_aura.h" 16 #include "ash/wm/aura/wm_window_aura.h"
17 #include "ash/wm/common/window_positioning_utils.h" 17 #include "ash/wm/common/window_positioning_utils.h"
18 #include "ash/wm/drag_window_controller.h" 18 #include "ash/wm/drag_window_controller.h"
19 #include "ash/wm/window_util.h" 19 #include "ash/wm/window_util.h"
20 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
21 #include "base/strings/stringprintf.h" 21 #include "base/strings/stringprintf.h"
22 #include "ui/aura/client/aura_constants.h" 22 #include "ui/aura/client/aura_constants.h"
23 #include "ui/aura/env.h" 23 #include "ui/aura/env.h"
24 #include "ui/aura/test/test_window_delegate.h" 24 #include "ui/aura/test/test_window_delegate.h"
25 #include "ui/base/hit_test.h" 25 #include "ui/base/hit_test.h"
26 #include "ui/base/ui_base_types.h" 26 #include "ui/base/ui_base_types.h"
27 #include "ui/compositor/layer_delegate.h"
27 #include "ui/compositor/layer_tree_owner.h" 28 #include "ui/compositor/layer_tree_owner.h"
28 #include "ui/display/manager/display_layout.h" 29 #include "ui/display/manager/display_layout.h"
29 #include "ui/display/manager/display_layout_builder.h" 30 #include "ui/display/manager/display_layout_builder.h"
30 #include "ui/gfx/geometry/insets.h" 31 #include "ui/gfx/geometry/insets.h"
31 #include "ui/views/widget/widget.h" 32 #include "ui/views/widget/widget.h"
32 #include "ui/wm/core/window_util.h" 33 #include "ui/wm/core/window_util.h"
33 34
34 namespace ash { 35 namespace ash {
35 namespace { 36 namespace {
36 37
37 const int kRootHeight = 600; 38 const int kRootHeight = 600;
38 39
40 // Used to test if the OnPaintLayer is called by DragWindowLayerDelegate.
41 class TestLayerDelegate : public ui::LayerDelegate {
42 public:
43 TestLayerDelegate() = default;
44 ~TestLayerDelegate() override = default;
45
46 int paint_count() const { return paint_count_; }
47
48 private:
49 // Paint content for the layer to the specified context.
50 void OnPaintLayer(const ui::PaintContext& context) override {
51 paint_count_++;
52 }
53 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {}
54 void OnDeviceScaleFactorChanged(float device_scale_factor) override {}
55 base::Closure PrepareForLayerBoundsChange() override {
56 return base::Closure();
57 }
58
59 int paint_count_ = 0;
60
61 DISALLOW_COPY_AND_ASSIGN(TestLayerDelegate);
62 };
63
39 } // namespace 64 } // namespace
40 65
41 class DragWindowResizerTest : public test::AshTestBase { 66 class DragWindowResizerTest : public test::AshTestBase {
42 public: 67 public:
43 DragWindowResizerTest() : transient_child_(nullptr) {} 68 DragWindowResizerTest() : transient_child_(nullptr) {}
44 ~DragWindowResizerTest() override {} 69 ~DragWindowResizerTest() override {}
45 70
46 void SetUp() override { 71 void SetUp() override {
47 AshTestBase::SetUp(); 72 AshTestBase::SetUp();
48 UpdateDisplay(base::StringPrintf("800x%d", kRootHeight)); 73 UpdateDisplay(base::StringPrintf("800x%d", kRootHeight));
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 363
339 // Verifies the drag window is shown correctly. 364 // Verifies the drag window is shown correctly.
340 TEST_F(DragWindowResizerTest, DragWindowController) { 365 TEST_F(DragWindowResizerTest, DragWindowController) {
341 if (!SupportsMultipleDisplays()) 366 if (!SupportsMultipleDisplays())
342 return; 367 return;
343 368
344 UpdateDisplay("800x600,800x600"); 369 UpdateDisplay("800x600,800x600");
345 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 370 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
346 ASSERT_EQ(2U, root_windows.size()); 371 ASSERT_EQ(2U, root_windows.size());
347 372
373 TestLayerDelegate delegate;
374 window_->layer()->set_delegate(&delegate);
348 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), 375 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60),
349 display::Screen::GetScreen()->GetPrimaryDisplay()); 376 display::Screen::GetScreen()->GetPrimaryDisplay());
350 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); 377 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
351 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); 378 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity());
352 { 379 {
353 // Hold the center of the window so that the window doesn't stick to the 380 // Hold the center of the window so that the window doesn't stick to the
354 // edge when dragging around the edge of the display. 381 // edge when dragging around the edge of the display.
355 std::unique_ptr<WindowResizer> resizer( 382 std::unique_ptr<WindowResizer> resizer(
356 CreateDragWindowResizer(window_.get(), gfx::Point(25, 30), HTCAPTION)); 383 CreateDragWindowResizer(window_.get(), gfx::Point(25, 30), HTCAPTION));
357 ASSERT_TRUE(resizer.get()); 384 ASSERT_TRUE(resizer.get());
(...skipping 14 matching lines...) Expand all
372 const aura::Window* drag_window = controller->GetDragWindowForTest(0); 399 const aura::Window* drag_window = controller->GetDragWindowForTest(0);
373 ASSERT_TRUE(drag_window); 400 ASSERT_TRUE(drag_window);
374 401
375 const ui::Layer* drag_layer = drag_window->layer(); 402 const ui::Layer* drag_layer = drag_window->layer();
376 ASSERT_TRUE(drag_layer); 403 ASSERT_TRUE(drag_layer);
377 // Check if |resizer->layer_| is properly set to the drag widget. 404 // Check if |resizer->layer_| is properly set to the drag widget.
378 const std::vector<ui::Layer*>& layers = drag_layer->children(); 405 const std::vector<ui::Layer*>& layers = drag_layer->children();
379 EXPECT_FALSE(layers.empty()); 406 EXPECT_FALSE(layers.empty());
380 EXPECT_EQ(controller->GetDragLayerOwnerForTest(0)->root(), layers.back()); 407 EXPECT_EQ(controller->GetDragLayerOwnerForTest(0)->root(), layers.back());
381 408
409 // The paint request on a drag window should reach the original delegate.
410 controller->RequestLayerPaintForTest();
411 EXPECT_EQ(1, delegate.paint_count());
412
413 // Invalidating the delegate on the original layer should prevent
414 // calling the OnPaintLayer on the original delegate from new delegate.
415 window_->layer()->set_delegate(nullptr);
416 controller->RequestLayerPaintForTest();
417 EXPECT_EQ(1, delegate.paint_count());
418
382 // |window_| should be opaque since the pointer is still on the primary 419 // |window_| should be opaque since the pointer is still on the primary
383 // root window. The drag window should be semi-transparent. 420 // root window. The drag window should be semi-transparent.
384 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); 421 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity());
385 EXPECT_GT(1.0f, drag_layer->opacity()); 422 EXPECT_GT(1.0f, drag_layer->opacity());
386 423
387 // Enter the pointer to the secondary display. 424 // Enter the pointer to the secondary display.
388 resizer->Drag(CalculateDragPoint(*resizer, 775, 10), 0); 425 resizer->Drag(CalculateDragPoint(*resizer, 775, 10), 0);
389 EXPECT_EQ(1, controller->GetDragWindowsCountForTest()); 426 EXPECT_EQ(1, controller->GetDragWindowsCountForTest());
390 // |window_| should be transparent, and the drag window should be opaque. 427 // |window_| should be transparent, and the drag window should be opaque.
391 EXPECT_GT(1.0f, window_->layer()->opacity()); 428 EXPECT_GT(1.0f, window_->layer()->opacity());
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 ASSERT_TRUE(resizer.get()); 769 ASSERT_TRUE(resizer.get());
733 resizer->Drag(CalculateDragPoint(*resizer, 399, 200), 0); 770 resizer->Drag(CalculateDragPoint(*resizer, 399, 200), 0);
734 EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(399, 200))); 771 EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(399, 200)));
735 EXPECT_EQ("401,200", 772 EXPECT_EQ("401,200",
736 aura::Env::GetInstance()->last_mouse_location().ToString()); 773 aura::Env::GetInstance()->last_mouse_location().ToString());
737 resizer->CompleteDrag(); 774 resizer->CompleteDrag();
738 } 775 }
739 } 776 }
740 777
741 } // namespace ash 778 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/drag_window_controller.cc ('k') | chrome/browser/ui/ash/multi_user/user_switch_animator_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698