| 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string16.h" | 8 #include "base/string16.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 OleInitialize(NULL); | 109 OleInitialize(NULL); |
| 110 #endif | 110 #endif |
| 111 } | 111 } |
| 112 | 112 |
| 113 ~FocusManagerTest() { | 113 ~FocusManagerTest() { |
| 114 #if defined(OS_WIN) | 114 #if defined(OS_WIN) |
| 115 OleUninitialize(); | 115 OleUninitialize(); |
| 116 #endif | 116 #endif |
| 117 } | 117 } |
| 118 | 118 |
| 119 virtual void SetUp() { | 119 virtual void SetUp() OVERRIDE { |
| 120 window_ = Widget::CreateWindowWithBounds(this, bounds()); | 120 window_ = Widget::CreateWindowWithBounds(this, bounds()); |
| 121 InitContentView(); | 121 InitContentView(); |
| 122 window_->Show(); | 122 window_->Show(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 virtual void TearDown() { | 125 virtual void TearDown() OVERRIDE { |
| 126 if (focus_change_listener_) | 126 if (focus_change_listener_) |
| 127 GetFocusManager()->RemoveFocusChangeListener(focus_change_listener_); | 127 GetFocusManager()->RemoveFocusChangeListener(focus_change_listener_); |
| 128 window_->Close(); | 128 window_->Close(); |
| 129 | 129 |
| 130 // Flush the message loop to make Purify happy. | 130 // Flush the message loop to make Purify happy. |
| 131 message_loop()->RunAllPending(); | 131 message_loop()->RunAllPending(); |
| 132 } | 132 } |
| 133 | 133 |
| 134 FocusManager* GetFocusManager() { | 134 FocusManager* GetFocusManager() { |
| 135 return window_->GetFocusManager(); | 135 return window_->GetFocusManager(); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void FocusNativeView(gfx::NativeView native_view) { | 138 void FocusNativeView(gfx::NativeView native_view) { |
| 139 #if defined(OS_WIN) | 139 #if defined(OS_WIN) |
| 140 ::SendMessage(native_view, WM_SETFOCUS, NULL, NULL); | 140 ::SendMessage(native_view, WM_SETFOCUS, NULL, NULL); |
| 141 #else | 141 #else |
| 142 gint return_val; | 142 gint return_val; |
| 143 GdkEventFocus event; | 143 GdkEventFocus event; |
| 144 event.type = GDK_FOCUS_CHANGE; | 144 event.type = GDK_FOCUS_CHANGE; |
| 145 event.window = | 145 event.window = |
| 146 gtk_widget_get_root_window(GTK_WIDGET(window_->GetNativeWindow())); | 146 gtk_widget_get_root_window(GTK_WIDGET(window_->GetNativeWindow())); |
| 147 event.send_event = TRUE; | 147 event.send_event = TRUE; |
| 148 event.in = TRUE; | 148 event.in = TRUE; |
| 149 gtk_signal_emit_by_name(GTK_OBJECT(native_view), "focus-in-event", | 149 gtk_signal_emit_by_name(GTK_OBJECT(native_view), "focus-in-event", |
| 150 &event, &return_val); | 150 &event, &return_val); |
| 151 #endif | 151 #endif |
| 152 } | 152 } |
| 153 | 153 |
| 154 // WidgetDelegate Implementation. | 154 // WidgetDelegate Implementation. |
| 155 virtual View* GetContentsView() { | 155 virtual View* GetContentsView() OVERRIDE { |
| 156 if (!content_view_) | 156 if (!content_view_) |
| 157 content_view_ = new View(); | 157 content_view_ = new View(); |
| 158 return content_view_; | 158 return content_view_; |
| 159 } | 159 } |
| 160 virtual Widget* GetWidget() OVERRIDE { |
| 161 return content_view_->GetWidget(); |
| 162 } |
| 163 virtual const Widget* GetWidget() const OVERRIDE { |
| 164 return content_view_->GetWidget(); |
| 165 } |
| 160 | 166 |
| 161 virtual void InitContentView() { | 167 virtual void InitContentView() { |
| 162 } | 168 } |
| 163 | 169 |
| 164 protected: | 170 protected: |
| 165 virtual gfx::Rect bounds() { | 171 virtual gfx::Rect bounds() { |
| 166 return gfx::Rect(0, 0, 500, 500); | 172 return gfx::Rect(0, 0, 500, 500); |
| 167 } | 173 } |
| 168 | 174 |
| 169 // Mocks activating/deactivating the window. | 175 // Mocks activating/deactivating the window. |
| (...skipping 1551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1721 ASSERT_EQ(3, static_cast<int>(dtor_tracker_.size())); | 1727 ASSERT_EQ(3, static_cast<int>(dtor_tracker_.size())); |
| 1722 | 1728 |
| 1723 // Focus manager should be the last one to destruct. | 1729 // Focus manager should be the last one to destruct. |
| 1724 ASSERT_STREQ("FocusManagerDtorTracked", dtor_tracker_[2].c_str()); | 1730 ASSERT_STREQ("FocusManagerDtorTracked", dtor_tracker_[2].c_str()); |
| 1725 | 1731 |
| 1726 // Clear window_ so that we don't try to close it again. | 1732 // Clear window_ so that we don't try to close it again. |
| 1727 window_ = NULL; | 1733 window_ = NULL; |
| 1728 } | 1734 } |
| 1729 | 1735 |
| 1730 } // namespace views | 1736 } // namespace views |
| OLD | NEW |