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 <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 private: | 195 private: |
196 int capture_changed_event_count_; | 196 int capture_changed_event_count_; |
197 int capture_lost_count_; | 197 int capture_lost_count_; |
198 int mouse_event_count_; | 198 int mouse_event_count_; |
199 int touch_event_count_; | 199 int touch_event_count_; |
200 int gesture_event_count_; | 200 int gesture_event_count_; |
201 | 201 |
202 DISALLOW_COPY_AND_ASSIGN(CaptureWindowDelegateImpl); | 202 DISALLOW_COPY_AND_ASSIGN(CaptureWindowDelegateImpl); |
203 }; | 203 }; |
204 | 204 |
205 // aura::WindowDelegate that tracks the window that was reported as having the | |
206 // focus before us. | |
207 class FocusDelegate : public TestWindowDelegate, | |
208 public aura::client::FocusChangeObserver { | |
209 public: | |
210 FocusDelegate() : previous_focused_window_(NULL) { | |
211 } | |
212 | |
213 aura::Window* previous_focused_window() const { | |
214 return previous_focused_window_; | |
215 } | |
216 | |
217 // Overridden from client::FocusChangeObserver: | |
218 virtual void OnWindowFocused(Window* gained_focus, | |
219 Window* lost_focus) OVERRIDE { | |
220 previous_focused_window_ = lost_focus; | |
221 } | |
222 | |
223 private: | |
224 aura::Window* previous_focused_window_; | |
225 | |
226 DISALLOW_COPY_AND_ASSIGN(FocusDelegate); | |
227 }; | |
228 | |
229 // Keeps track of the location of the gesture. | 205 // Keeps track of the location of the gesture. |
230 class GestureTrackPositionDelegate : public TestWindowDelegate { | 206 class GestureTrackPositionDelegate : public TestWindowDelegate { |
231 public: | 207 public: |
232 GestureTrackPositionDelegate() {} | 208 GestureTrackPositionDelegate() {} |
233 | 209 |
234 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { | 210 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { |
235 position_ = event->location(); | 211 position_ = event->location(); |
236 event->StopPropagation(); | 212 event->StopPropagation(); |
237 } | 213 } |
238 | 214 |
(...skipping 1536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1775 | 1751 |
1776 parent->StackChildBelow(w1.get(), w2.get()); | 1752 parent->StackChildBelow(w1.get(), w2.get()); |
1777 EXPECT_EQ(w212, parent->children().back()); | 1753 EXPECT_EQ(w212, parent->children().back()); |
1778 EXPECT_EQ("1 11 2 22 21 213 211 212", ChildWindowIDsAsString(parent.get())); | 1754 EXPECT_EQ("1 11 2 22 21 213 211 212", ChildWindowIDsAsString(parent.get())); |
1779 | 1755 |
1780 parent->StackChildBelow(w213, w11); | 1756 parent->StackChildBelow(w213, w11); |
1781 EXPECT_EQ(w11, parent->children().back()); | 1757 EXPECT_EQ(w11, parent->children().back()); |
1782 EXPECT_EQ("2 22 21 213 211 212 1 11", ChildWindowIDsAsString(parent.get())); | 1758 EXPECT_EQ("2 22 21 213 211 212 1 11", ChildWindowIDsAsString(parent.get())); |
1783 } | 1759 } |
1784 | 1760 |
1785 // Tests that when a focused window is closed, its parent inherits the focus. | |
1786 TEST_F(WindowTest, FocusedWindowTest) { | |
1787 scoped_ptr<Window> parent(CreateTestWindowWithId(0, root_window())); | |
1788 scoped_ptr<Window> child(CreateTestWindowWithId(1, parent.get())); | |
1789 | |
1790 parent->Show(); | |
1791 | |
1792 child->Focus(); | |
1793 EXPECT_TRUE(child->HasFocus()); | |
1794 EXPECT_FALSE(parent->HasFocus()); | |
1795 | |
1796 child.reset(); | |
1797 EXPECT_TRUE(parent->HasFocus()); | |
1798 } | |
1799 | |
1800 // Tests that the previously-focused window is passed to OnWindowFocused. | |
1801 // TODO(beng): Remove once the FocusController lands. | |
1802 TEST_F(WindowTest, OldFocusedWindowTest) { | |
1803 const gfx::Rect kBounds(0, 0, 100, 100); | |
1804 | |
1805 FocusDelegate delegate1; | |
1806 scoped_ptr<Window> window1( | |
1807 CreateTestWindowWithDelegate(&delegate1, 0, kBounds, root_window())); | |
1808 client::SetFocusChangeObserver(window1.get(), &delegate1); | |
1809 window1->Focus(); | |
1810 ASSERT_TRUE(window1->HasFocus()); | |
1811 EXPECT_TRUE(delegate1.previous_focused_window() == NULL); | |
1812 | |
1813 FocusDelegate delegate2; | |
1814 scoped_ptr<Window> window2( | |
1815 CreateTestWindowWithDelegate(&delegate2, 1, kBounds, root_window())); | |
1816 client::SetFocusChangeObserver(window2.get(), &delegate2); | |
1817 window2->Focus(); | |
1818 ASSERT_TRUE(window2->HasFocus()); | |
1819 EXPECT_FALSE(window1->HasFocus()); | |
1820 EXPECT_EQ(window1.get(), delegate2.previous_focused_window()); | |
1821 } | |
1822 | |
1823 namespace { | 1761 namespace { |
1824 DEFINE_WINDOW_PROPERTY_KEY(int, kIntKey, -2); | 1762 DEFINE_WINDOW_PROPERTY_KEY(int, kIntKey, -2); |
1825 DEFINE_WINDOW_PROPERTY_KEY(const char*, kStringKey, "squeamish"); | 1763 DEFINE_WINDOW_PROPERTY_KEY(const char*, kStringKey, "squeamish"); |
1826 } | 1764 } |
1827 | 1765 |
1828 TEST_F(WindowTest, Property) { | 1766 TEST_F(WindowTest, Property) { |
1829 scoped_ptr<Window> w(CreateTestWindowWithId(0, root_window())); | 1767 scoped_ptr<Window> w(CreateTestWindowWithId(0, root_window())); |
1830 | 1768 |
1831 static const char native_prop_key[] = "fnord"; | 1769 static const char native_prop_key[] = "fnord"; |
1832 | 1770 |
(...skipping 1397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3230 parent->AddTransientChild(transient); | 3168 parent->AddTransientChild(transient); |
3231 parent.reset(); | 3169 parent.reset(); |
3232 | 3170 |
3233 ASSERT_EQ(2u, destruction_order.size()); | 3171 ASSERT_EQ(2u, destruction_order.size()); |
3234 EXPECT_EQ("transient", destruction_order[0]); | 3172 EXPECT_EQ("transient", destruction_order[0]); |
3235 EXPECT_EQ("parent", destruction_order[1]); | 3173 EXPECT_EQ("parent", destruction_order[1]); |
3236 } | 3174 } |
3237 | 3175 |
3238 } // namespace test | 3176 } // namespace test |
3239 } // namespace aura | 3177 } // namespace aura |
OLD | NEW |