| 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/aura/window.h" | 5 #include "ui/aura/window.h" |
| 6 | 6 |
| 7 #include <limits.h> | 7 #include <limits.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 1753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1764 } | 1764 } |
| 1765 | 1765 |
| 1766 // Return a tuple of the arguments passed in OnPropertyChanged callback. | 1766 // Return a tuple of the arguments passed in OnPropertyChanged callback. |
| 1767 PropertyChangeInfo PropertyChangeInfoAndClear() { | 1767 PropertyChangeInfo PropertyChangeInfoAndClear() { |
| 1768 PropertyChangeInfo result(property_key_, old_property_value_); | 1768 PropertyChangeInfo result(property_key_, old_property_value_); |
| 1769 property_key_ = NULL; | 1769 property_key_ = NULL; |
| 1770 old_property_value_ = -3; | 1770 old_property_value_ = -3; |
| 1771 return result; | 1771 return result; |
| 1772 } | 1772 } |
| 1773 | 1773 |
| 1774 std::string TransformNotificationsAndClear() { | |
| 1775 std::string result; | |
| 1776 for (std::vector<std::pair<int, int> >::iterator it = | |
| 1777 transform_notifications_.begin(); | |
| 1778 it != transform_notifications_.end(); | |
| 1779 ++it) { | |
| 1780 base::StringAppendF(&result, "(%d,%d)", it->first, it->second); | |
| 1781 } | |
| 1782 transform_notifications_.clear(); | |
| 1783 return result; | |
| 1784 } | |
| 1785 | |
| 1786 private: | 1774 private: |
| 1787 void OnWindowAdded(Window* new_window) override { added_count_++; } | 1775 void OnWindowAdded(Window* new_window) override { added_count_++; } |
| 1788 | 1776 |
| 1789 void OnWillRemoveWindow(Window* window) override { removed_count_++; } | 1777 void OnWillRemoveWindow(Window* window) override { removed_count_++; } |
| 1790 | 1778 |
| 1791 void OnWindowVisibilityChanged(Window* window, bool visible) override { | 1779 void OnWindowVisibilityChanged(Window* window, bool visible) override { |
| 1792 if (!visibility_info_) { | 1780 if (!visibility_info_) { |
| 1793 visibility_info_.reset(new VisibilityInfo); | 1781 visibility_info_.reset(new VisibilityInfo); |
| 1794 visibility_info_->changed_count = 0; | 1782 visibility_info_->changed_count = 0; |
| 1795 } | 1783 } |
| 1796 visibility_info_->window_visible = window->IsVisible(); | 1784 visibility_info_->window_visible = window->IsVisible(); |
| 1797 visibility_info_->visible_param = visible; | 1785 visibility_info_->visible_param = visible; |
| 1798 visibility_info_->changed_count++; | 1786 visibility_info_->changed_count++; |
| 1799 } | 1787 } |
| 1800 | 1788 |
| 1801 void OnWindowDestroyed(Window* window) override { | 1789 void OnWindowDestroyed(Window* window) override { |
| 1802 EXPECT_FALSE(window->parent()); | 1790 EXPECT_FALSE(window->parent()); |
| 1803 destroyed_count_++; | 1791 destroyed_count_++; |
| 1804 } | 1792 } |
| 1805 | 1793 |
| 1806 void OnWindowPropertyChanged(Window* window, | 1794 void OnWindowPropertyChanged(Window* window, |
| 1807 const void* key, | 1795 const void* key, |
| 1808 intptr_t old) override { | 1796 intptr_t old) override { |
| 1809 property_key_ = key; | 1797 property_key_ = key; |
| 1810 old_property_value_ = old; | 1798 old_property_value_ = old; |
| 1811 } | 1799 } |
| 1812 | 1800 |
| 1813 void OnAncestorWindowTransformed(Window* source, Window* window) override { | |
| 1814 transform_notifications_.push_back( | |
| 1815 std::make_pair(source->id(), window->id())); | |
| 1816 } | |
| 1817 | |
| 1818 int added_count_; | 1801 int added_count_; |
| 1819 int removed_count_; | 1802 int removed_count_; |
| 1820 int destroyed_count_; | 1803 int destroyed_count_; |
| 1821 std::unique_ptr<VisibilityInfo> visibility_info_; | 1804 std::unique_ptr<VisibilityInfo> visibility_info_; |
| 1822 const void* property_key_; | 1805 const void* property_key_; |
| 1823 intptr_t old_property_value_; | 1806 intptr_t old_property_value_; |
| 1824 std::vector<std::pair<int, int> > transform_notifications_; | 1807 std::vector<std::pair<int, int> > transform_notifications_; |
| 1825 | 1808 |
| 1826 DISALLOW_COPY_AND_ASSIGN(WindowObserverTest); | 1809 DISALLOW_COPY_AND_ASSIGN(WindowObserverTest); |
| 1827 }; | 1810 }; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1942 w1->SetNativeWindowProperty(native_prop_key, NULL); | 1925 w1->SetNativeWindowProperty(native_prop_key, NULL); |
| 1943 EXPECT_EQ(PropertyChangeInfo(native_prop_key, | 1926 EXPECT_EQ(PropertyChangeInfo(native_prop_key, |
| 1944 reinterpret_cast<intptr_t>(&*w1)), | 1927 reinterpret_cast<intptr_t>(&*w1)), |
| 1945 PropertyChangeInfoAndClear()); | 1928 PropertyChangeInfoAndClear()); |
| 1946 | 1929 |
| 1947 // Sanity check to see if |PropertyChangeInfoAndClear| really clears. | 1930 // Sanity check to see if |PropertyChangeInfoAndClear| really clears. |
| 1948 EXPECT_EQ(PropertyChangeInfo( | 1931 EXPECT_EQ(PropertyChangeInfo( |
| 1949 reinterpret_cast<const void*>(NULL), -3), PropertyChangeInfoAndClear()); | 1932 reinterpret_cast<const void*>(NULL), -3), PropertyChangeInfoAndClear()); |
| 1950 } | 1933 } |
| 1951 | 1934 |
| 1952 TEST_P(WindowObserverTest, AncestorTransformed) { | |
| 1953 // Create following window hierarchy: | |
| 1954 // root_window | |
| 1955 // +-- w1 | |
| 1956 // +-- w2 | |
| 1957 // +-- w3 | |
| 1958 // +-- w4 | |
| 1959 // Then, apply a transform to |w1| and ensure all its descendants are | |
| 1960 // notified. | |
| 1961 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); | |
| 1962 w1->AddObserver(this); | |
| 1963 std::unique_ptr<Window> w2(CreateTestWindowWithId(2, w1.get())); | |
| 1964 w2->AddObserver(this); | |
| 1965 std::unique_ptr<Window> w3(CreateTestWindowWithId(3, w1.get())); | |
| 1966 w3->AddObserver(this); | |
| 1967 std::unique_ptr<Window> w4(CreateTestWindowWithId(4, w3.get())); | |
| 1968 w4->AddObserver(this); | |
| 1969 | |
| 1970 EXPECT_EQ(std::string(), TransformNotificationsAndClear()); | |
| 1971 | |
| 1972 gfx::Transform transform; | |
| 1973 transform.Translate(10, 10); | |
| 1974 w1->SetTransform(transform); | |
| 1975 | |
| 1976 EXPECT_EQ("(1,1)(1,2)(1,3)(1,4)", TransformNotificationsAndClear()); | |
| 1977 } | |
| 1978 | |
| 1979 TEST_P(WindowTest, AcquireLayer) { | 1935 TEST_P(WindowTest, AcquireLayer) { |
| 1980 std::unique_ptr<Window> window1(CreateTestWindowWithId(1, root_window())); | 1936 std::unique_ptr<Window> window1(CreateTestWindowWithId(1, root_window())); |
| 1981 std::unique_ptr<Window> window2(CreateTestWindowWithId(2, root_window())); | 1937 std::unique_ptr<Window> window2(CreateTestWindowWithId(2, root_window())); |
| 1982 ui::Layer* parent = window1->parent()->layer(); | 1938 ui::Layer* parent = window1->parent()->layer(); |
| 1983 EXPECT_EQ(2U, parent->children().size()); | 1939 EXPECT_EQ(2U, parent->children().size()); |
| 1984 | 1940 |
| 1985 WindowTestApi window1_test_api(window1.get()); | 1941 WindowTestApi window1_test_api(window1.get()); |
| 1986 WindowTestApi window2_test_api(window2.get()); | 1942 WindowTestApi window2_test_api(window2.get()); |
| 1987 | 1943 |
| 1988 EXPECT_TRUE(window1_test_api.OwnsLayer()); | 1944 EXPECT_TRUE(window1_test_api.OwnsLayer()); |
| (...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2899 ::testing::Values(BackendType::CLASSIC, | 2855 ::testing::Values(BackendType::CLASSIC, |
| 2900 BackendType::MUS)); | 2856 BackendType::MUS)); |
| 2901 | 2857 |
| 2902 INSTANTIATE_TEST_CASE_P(/* no prefix */, | 2858 INSTANTIATE_TEST_CASE_P(/* no prefix */, |
| 2903 WindowObserverTest, | 2859 WindowObserverTest, |
| 2904 ::testing::Values(BackendType::CLASSIC, | 2860 ::testing::Values(BackendType::CLASSIC, |
| 2905 BackendType::MUS)); | 2861 BackendType::MUS)); |
| 2906 | 2862 |
| 2907 } // namespace test | 2863 } // namespace test |
| 2908 } // namespace aura | 2864 } // namespace aura |
| OLD | NEW |