| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <map> | 5 #include <map> |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "ui/base/clipboard/clipboard.h" | 12 #include "ui/base/clipboard/clipboard.h" |
| 13 #include "ui/base/keycodes/keyboard_codes.h" | 13 #include "ui/base/keycodes/keyboard_codes.h" |
| 14 #include "ui/base/models/simple_menu_model.h" | 14 #include "ui/base/models/simple_menu_model.h" |
| 15 #include "ui/gfx/canvas_skia.h" | 15 #include "ui/gfx/canvas_skia.h" |
| 16 #include "ui/gfx/compositor/compositor.h" | 16 #include "ui/gfx/compositor/compositor.h" |
| 17 #include "ui/gfx/compositor/layer.h" | 17 #include "ui/gfx/compositor/layer.h" |
| 18 #include "ui/gfx/compositor/layer_animator.h" |
| 18 #include "ui/gfx/compositor/test_compositor.h" | 19 #include "ui/gfx/compositor/test_compositor.h" |
| 19 #include "ui/gfx/compositor/test_texture.h" | 20 #include "ui/gfx/compositor/test_texture.h" |
| 20 #include "ui/gfx/path.h" | 21 #include "ui/gfx/path.h" |
| 21 #include "ui/gfx/transform.h" | 22 #include "ui/gfx/transform.h" |
| 22 #include "views/background.h" | 23 #include "views/background.h" |
| 23 #include "views/controls/button/button_dropdown.h" | 24 #include "views/controls/button/button_dropdown.h" |
| 24 #include "views/controls/button/checkbox.h" | 25 #include "views/controls/button/checkbox.h" |
| 25 #include "views/controls/native/native_view_host.h" | 26 #include "views/controls/native/native_view_host.h" |
| 26 #include "views/controls/scroll_view.h" | 27 #include "views/controls/scroll_view.h" |
| 27 #include "views/controls/textfield/textfield.h" | 28 #include "views/controls/textfield/textfield.h" |
| 28 #include "views/events/event.h" | 29 #include "views/events/event.h" |
| 29 #include "views/focus/accelerator_handler.h" | 30 #include "views/focus/accelerator_handler.h" |
| 30 #include "views/focus/view_storage.h" | 31 #include "views/focus/view_storage.h" |
| 31 #include "views/layer_property_setter.h" | |
| 32 #include "views/test/views_test_base.h" | 32 #include "views/test/views_test_base.h" |
| 33 #include "views/touchui/gesture_manager.h" | 33 #include "views/touchui/gesture_manager.h" |
| 34 #include "views/view.h" | 34 #include "views/view.h" |
| 35 #include "views/views_delegate.h" | 35 #include "views/views_delegate.h" |
| 36 #include "views/widget/native_widget.h" | 36 #include "views/widget/native_widget.h" |
| 37 #include "views/widget/root_view.h" | 37 #include "views/widget/root_view.h" |
| 38 #include "views/window/dialog_delegate.h" | 38 #include "views/window/dialog_delegate.h" |
| 39 | 39 |
| 40 #if defined(OS_WIN) | 40 #if defined(OS_WIN) |
| 41 #include "views/test/test_views_delegate.h" | 41 #include "views/test/test_views_delegate.h" |
| (...skipping 2395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2437 } | 2437 } |
| 2438 | 2438 |
| 2439 //////////////////////////////////////////////////////////////////////////////// | 2439 //////////////////////////////////////////////////////////////////////////////// |
| 2440 // Layers | 2440 // Layers |
| 2441 //////////////////////////////////////////////////////////////////////////////// | 2441 //////////////////////////////////////////////////////////////////////////////// |
| 2442 | 2442 |
| 2443 #if defined(VIEWS_COMPOSITOR) | 2443 #if defined(VIEWS_COMPOSITOR) |
| 2444 | 2444 |
| 2445 namespace { | 2445 namespace { |
| 2446 | 2446 |
| 2447 // Test implementation of LayerPropertySetter; | 2447 // Test implementation of LayerAnimator. |
| 2448 class TestLayerPropertySetter : public LayerPropertySetter { | 2448 class TestLayerAnimator : public ui::LayerAnimator { |
| 2449 public: | 2449 public: |
| 2450 TestLayerPropertySetter(); | 2450 TestLayerAnimator(); |
| 2451 | 2451 |
| 2452 bool installed() const { return installed_; } | |
| 2453 const gfx::Rect& last_bounds() const { return last_bounds_; } | 2452 const gfx::Rect& last_bounds() const { return last_bounds_; } |
| 2454 | 2453 |
| 2455 // LayerPropertySetter: | 2454 // LayerAnimator. |
| 2456 virtual void Installed(ui::Layer* layer) OVERRIDE; | 2455 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE; |
| 2457 virtual void Uninstalled(ui::Layer* layer) OVERRIDE; | |
| 2458 virtual void SetTransform(ui::Layer* layer, | |
| 2459 const ui::Transform& transform) OVERRIDE; | |
| 2460 virtual void SetBounds(ui::Layer* layer, const gfx::Rect& bounds) OVERRIDE; | |
| 2461 | 2456 |
| 2462 private: | 2457 private: |
| 2463 bool installed_; | |
| 2464 gfx::Rect last_bounds_; | 2458 gfx::Rect last_bounds_; |
| 2465 | 2459 |
| 2466 DISALLOW_COPY_AND_ASSIGN(TestLayerPropertySetter); | 2460 DISALLOW_COPY_AND_ASSIGN(TestLayerAnimator); |
| 2467 }; | 2461 }; |
| 2468 | 2462 |
| 2469 TestLayerPropertySetter::TestLayerPropertySetter() : installed_(false) {} | 2463 TestLayerAnimator::TestLayerAnimator() |
| 2470 | 2464 : ui::LayerAnimator(base::TimeDelta::FromMilliseconds(0)) { |
| 2471 void TestLayerPropertySetter::Installed(ui::Layer* layer) { | |
| 2472 installed_ = true; | |
| 2473 } | 2465 } |
| 2474 | 2466 |
| 2475 void TestLayerPropertySetter::Uninstalled(ui::Layer* layer) { | 2467 void TestLayerAnimator::SetBounds(const gfx::Rect& bounds) { |
| 2476 installed_ = false; | |
| 2477 } | |
| 2478 | |
| 2479 void TestLayerPropertySetter::SetTransform(ui::Layer* layer, | |
| 2480 const ui::Transform& transform) { | |
| 2481 } | |
| 2482 | |
| 2483 void TestLayerPropertySetter::SetBounds(ui::Layer* layer, | |
| 2484 const gfx::Rect& bounds) { | |
| 2485 last_bounds_ = bounds; | 2468 last_bounds_ = bounds; |
| 2486 } | 2469 } |
| 2487 | 2470 |
| 2488 } // namespace | 2471 } // namespace |
| 2489 | 2472 |
| 2490 class ViewLayerTest : public ViewsTestBase { | 2473 class ViewLayerTest : public ViewsTestBase { |
| 2491 public: | 2474 public: |
| 2492 ViewLayerTest() : widget_(NULL), old_use_acceleration_(false) {} | 2475 ViewLayerTest() : widget_(NULL), old_use_acceleration_(false) {} |
| 2493 | 2476 |
| 2494 virtual ~ViewLayerTest() { | 2477 virtual ~ViewLayerTest() { |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2669 v3->SetPaintToLayer(true); | 2652 v3->SetPaintToLayer(true); |
| 2670 v2->AddChildView(v3); | 2653 v2->AddChildView(v3); |
| 2671 ASSERT_TRUE(v3->layer() != NULL); | 2654 ASSERT_TRUE(v3->layer() != NULL); |
| 2672 | 2655 |
| 2673 // At this point we have v1-v2-v3. v3 has a layer, v1 and v2 don't. | 2656 // At this point we have v1-v2-v3. v3 has a layer, v1 and v2 don't. |
| 2674 | 2657 |
| 2675 v1->SetPaintToLayer(true); | 2658 v1->SetPaintToLayer(true); |
| 2676 EXPECT_EQ(v1->layer(), v3->layer()->parent()); | 2659 EXPECT_EQ(v1->layer(), v3->layer()->parent()); |
| 2677 } | 2660 } |
| 2678 | 2661 |
| 2679 TEST_F(ViewLayerTest, LayerPropertySetter) { | 2662 TEST_F(ViewLayerTest, LayerAnimator) { |
| 2680 View* content_view = new View; | 2663 View* content_view = new View; |
| 2681 widget()->SetContentsView(content_view); | 2664 widget()->SetContentsView(content_view); |
| 2682 | 2665 |
| 2683 View* v1 = new View; | 2666 View* v1 = new View; |
| 2684 content_view->AddChildView(v1); | 2667 content_view->AddChildView(v1); |
| 2685 v1->SetPaintToLayer(true); | 2668 v1->SetPaintToLayer(true); |
| 2686 TestLayerPropertySetter* setter = new TestLayerPropertySetter; | 2669 EXPECT_TRUE(v1->layer() != NULL); |
| 2687 v1->SetLayerPropertySetter(setter); | |
| 2688 EXPECT_TRUE(setter->installed()); | |
| 2689 | 2670 |
| 2690 // Turn off the layer, which should trigger uninstall. | 2671 TestLayerAnimator* animator = new TestLayerAnimator(); |
| 2691 v1->SetPaintToLayer(false); | 2672 v1->layer()->SetAnimator(animator); |
| 2692 EXPECT_FALSE(setter->installed()); | |
| 2693 | |
| 2694 v1->SetPaintToLayer(true); | |
| 2695 EXPECT_TRUE(setter->installed()); | |
| 2696 | 2673 |
| 2697 gfx::Rect bounds(1, 2, 3, 4); | 2674 gfx::Rect bounds(1, 2, 3, 4); |
| 2698 v1->SetBoundsRect(bounds); | 2675 v1->SetBoundsRect(bounds); |
| 2699 EXPECT_EQ(bounds, setter->last_bounds()); | 2676 EXPECT_EQ(bounds, animator->last_bounds()); |
| 2700 // TestLayerPropertySetter doesn't update the layer. | 2677 // TestLayerAnimator doesn't update the layer. |
| 2701 EXPECT_NE(bounds, v1->layer()->bounds()); | 2678 EXPECT_NE(bounds, v1->layer()->bounds()); |
| 2702 } | 2679 } |
| 2703 | 2680 |
| 2704 // Verifies the bounds of a layer are updated if the bounds of ancestor that | 2681 // Verifies the bounds of a layer are updated if the bounds of ancestor that |
| 2705 // doesn't have a layer change. | 2682 // doesn't have a layer change. |
| 2706 TEST_F(ViewLayerTest, BoundsChangeWithLayer) { | 2683 TEST_F(ViewLayerTest, BoundsChangeWithLayer) { |
| 2707 View* content_view = new View; | 2684 View* content_view = new View; |
| 2708 widget()->SetContentsView(content_view); | 2685 widget()->SetContentsView(content_view); |
| 2709 | 2686 |
| 2710 View* v1 = new View; | 2687 View* v1 = new View; |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3094 ScrambleTree(content); | 3071 ScrambleTree(content); |
| 3095 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); | 3072 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); |
| 3096 | 3073 |
| 3097 ScrambleTree(content); | 3074 ScrambleTree(content); |
| 3098 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); | 3075 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); |
| 3099 } | 3076 } |
| 3100 | 3077 |
| 3101 #endif // VIEWS_COMPOSITOR | 3078 #endif // VIEWS_COMPOSITOR |
| 3102 | 3079 |
| 3103 } // namespace views | 3080 } // namespace views |
| OLD | NEW |