OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "webkit/tools/test_shell/test_shell.h" | 5 #include "webkit/tools/test_shell/test_shell.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <fontconfig/fontconfig.h> | 9 #include <fontconfig/fontconfig.h> |
10 #include <gtk/gtk.h> | 10 #include <gtk/gtk.h> |
(...skipping 140 matching lines...) Loading... |
151 if (TestShell::windowList()->empty() || shell->is_modal()) { | 151 if (TestShell::windowList()->empty() || shell->is_modal()) { |
152 MessageLoop::current()->PostTask(FROM_HERE, | 152 MessageLoop::current()->PostTask(FROM_HERE, |
153 new MessageLoop::QuitTask()); | 153 new MessageLoop::QuitTask()); |
154 } | 154 } |
155 | 155 |
156 delete shell; | 156 delete shell; |
157 | 157 |
158 return FALSE; // Don't stop this message. | 158 return FALSE; // Don't stop this message. |
159 } | 159 } |
160 | 160 |
| 161 gboolean MainWindowLostFocus(GtkWidget* widget, GdkEventFocus* event, |
| 162 TestShell* shell) { |
| 163 shell->ClosePopup(); |
| 164 return FALSE; |
| 165 } |
| 166 |
161 // Callback for when you click the back button. | 167 // Callback for when you click the back button. |
162 void BackButtonClicked(GtkButton* button, TestShell* shell) { | 168 void BackButtonClicked(GtkButton* button, TestShell* shell) { |
163 shell->GoBackOrForward(-1); | 169 shell->GoBackOrForward(-1); |
164 } | 170 } |
165 | 171 |
166 // Callback for when you click the forward button. | 172 // Callback for when you click the forward button. |
167 void ForwardButtonClicked(GtkButton* button, TestShell* shell) { | 173 void ForwardButtonClicked(GtkButton* button, TestShell* shell) { |
168 shell->GoBackOrForward(1); | 174 shell->GoBackOrForward(1); |
169 } | 175 } |
170 | 176 |
171 // Callback for when you click the stop button. | 177 // Callback for when you click the stop button. |
172 void StopButtonClicked(GtkButton* button, TestShell* shell) { | 178 void StopButtonClicked(GtkButton* button, TestShell* shell) { |
173 shell->webView()->StopLoading(); | 179 shell->webView()->StopLoading(); |
174 } | 180 } |
175 | 181 |
176 // Callback for when you click the reload button. | 182 // Callback for when you click the reload button. |
177 void ReloadButtonClicked(GtkButton* button, TestShell* shell) { | 183 void ReloadButtonClicked(GtkButton* button, TestShell* shell) { |
178 shell->Reload(); | 184 shell->Reload(); |
179 } | 185 } |
180 | 186 |
181 // Callback for when you press enter in the URL box. | 187 // Callback for when you press enter in the URL box. |
182 void URLEntryActivate(GtkEntry* entry, TestShell* shell) { | 188 void URLEntryActivate(GtkEntry* entry, TestShell* shell) { |
183 const gchar* url = gtk_entry_get_text(entry); | 189 const gchar* url = gtk_entry_get_text(entry); |
184 shell->LoadURL(UTF8ToWide(url).c_str()); | 190 shell->LoadURL(UTF8ToWide(url).c_str()); |
185 } | 191 } |
186 | 192 |
187 }; | 193 } |
188 | 194 |
189 bool TestShell::Initialize(const std::wstring& startingURL) { | 195 bool TestShell::Initialize(const std::wstring& startingURL) { |
190 m_mainWnd = gtk_window_new(GTK_WINDOW_TOPLEVEL); | 196 m_mainWnd = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
191 gtk_window_set_title(GTK_WINDOW(m_mainWnd), "Test Shell"); | 197 gtk_window_set_title(GTK_WINDOW(m_mainWnd), "Test Shell"); |
192 gtk_window_set_default_size(GTK_WINDOW(m_mainWnd), 640, 480); | 198 gtk_window_set_default_size(GTK_WINDOW(m_mainWnd), 640, 480); |
193 g_signal_connect(G_OBJECT(m_mainWnd), "destroy", | 199 g_signal_connect(G_OBJECT(m_mainWnd), "destroy", |
194 G_CALLBACK(MainWindowDestroyed), this); | 200 G_CALLBACK(MainWindowDestroyed), this); |
195 | 201 g_signal_connect(G_OBJECT(m_mainWnd), "focus-out-event", |
| 202 G_CALLBACK(MainWindowLostFocus), this); |
196 g_object_set_data(G_OBJECT(m_mainWnd), "test-shell", this); | 203 g_object_set_data(G_OBJECT(m_mainWnd), "test-shell", this); |
197 | 204 |
198 GtkWidget* vbox = gtk_vbox_new(FALSE, 0); | 205 GtkWidget* vbox = gtk_vbox_new(FALSE, 0); |
199 | 206 |
200 GtkWidget* toolbar = gtk_toolbar_new(); | 207 GtkWidget* toolbar = gtk_toolbar_new(); |
201 // Turn off the labels on the toolbar buttons. | 208 // Turn off the labels on the toolbar buttons. |
202 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS); | 209 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS); |
203 | 210 |
204 GtkToolItem* back = gtk_tool_button_new_from_stock(GTK_STOCK_GO_BACK); | 211 GtkToolItem* back = gtk_tool_button_new_from_stock(GTK_STOCK_GO_BACK); |
205 g_signal_connect(G_OBJECT(back), "clicked", | 212 g_signal_connect(G_OBJECT(back), "clicked", |
(...skipping 107 matching lines...) Loading... |
313 gtk_widget_destroy(windowHandle); | 320 gtk_widget_destroy(windowHandle); |
314 } | 321 } |
315 | 322 |
316 WebWidget* TestShell::CreatePopupWidget(WebView* webview) { | 323 WebWidget* TestShell::CreatePopupWidget(WebView* webview) { |
317 GtkWidget* popupwindow = gtk_window_new(GTK_WINDOW_POPUP); | 324 GtkWidget* popupwindow = gtk_window_new(GTK_WINDOW_POPUP); |
318 GtkWidget* vbox = gtk_vbox_new(FALSE, 0); | 325 GtkWidget* vbox = gtk_vbox_new(FALSE, 0); |
319 WebWidgetHost* host = WebWidgetHost::Create(vbox, delegate_); | 326 WebWidgetHost* host = WebWidgetHost::Create(vbox, delegate_); |
320 gtk_container_add(GTK_CONTAINER(popupwindow), vbox); | 327 gtk_container_add(GTK_CONTAINER(popupwindow), vbox); |
321 m_popupHost = host; | 328 m_popupHost = host; |
322 | 329 |
| 330 // Grab all input to the test shell and funnel it to the popup. |
| 331 // The popup will detect if mouseclicks are outside its bounds and destroy |
| 332 // itself if so. Clicks that are outside the test_shell window will destroy |
| 333 // the popup by taking focus away from the main window. |
| 334 gtk_grab_add(host->view_handle()); |
| 335 |
323 return host->webwidget(); | 336 return host->webwidget(); |
324 } | 337 } |
325 | 338 |
326 void TestShell::ClosePopup() { | 339 void TestShell::ClosePopup() { |
327 DCHECK(m_popupHost); | 340 if (!m_popupHost) |
| 341 return; |
328 GtkWidget* drawing_area = m_popupHost->view_handle(); | 342 GtkWidget* drawing_area = m_popupHost->view_handle(); |
| 343 // gtk_widget_destroy will recursively call ClosePopup, so to avoid GTK |
| 344 // warnings set m_popupHost to null here before making the call. |
| 345 m_popupHost = NULL; |
329 GtkWidget* window = | 346 GtkWidget* window = |
330 gtk_widget_get_parent(gtk_widget_get_parent(drawing_area)); | 347 gtk_widget_get_parent(gtk_widget_get_parent(drawing_area)); |
331 gtk_widget_destroy(window); | 348 gtk_widget_destroy(window); |
332 m_popupHost = NULL; | |
333 } | 349 } |
334 | 350 |
335 void TestShell::ResizeSubViews() { | 351 void TestShell::ResizeSubViews() { |
336 // This function is used on Windows to re-layout the window on a resize. | 352 // This function is used on Windows to re-layout the window on a resize. |
337 // GTK manages layout for us so we do nothing. | 353 // GTK manages layout for us so we do nothing. |
338 } | 354 } |
339 | 355 |
340 /* static */ void TestShell::DumpBackForwardList(std::wstring* result) { | 356 /* static */ void TestShell::DumpBackForwardList(std::wstring* result) { |
341 result->clear(); | 357 result->clear(); |
342 for (WindowList::iterator iter = TestShell::windowList()->begin(); | 358 for (WindowList::iterator iter = TestShell::windowList()->begin(); |
(...skipping 373 matching lines...) Loading... |
716 // of NOTIMPLEMENTED into our layout test diffs. | 732 // of NOTIMPLEMENTED into our layout test diffs. |
717 // NOTIMPLEMENTED(); | 733 // NOTIMPLEMENTED(); |
718 return false; | 734 return false; |
719 } | 735 } |
720 | 736 |
721 ScreenInfo GetScreenInfo(gfx::NativeView window) { | 737 ScreenInfo GetScreenInfo(gfx::NativeView window) { |
722 return GetScreenInfoHelper(window); | 738 return GetScreenInfoHelper(window); |
723 } | 739 } |
724 | 740 |
725 } // namespace webkit_glue | 741 } // namespace webkit_glue |
OLD | NEW |