Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: webkit/tools/test_shell/test_shell_mac.mm

Issue 255094: [Mac] Properly call setIsActive() when becoming and resigning key window. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/tools/test_shell/mac/webview_host.mm ('k') | webkit/tools/test_shell/webview_host.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <ApplicationServices/ApplicationServices.h> 5 #include <ApplicationServices/ApplicationServices.h>
6 #import <Cocoa/Cocoa.h> 6 #import <Cocoa/Cocoa.h>
7 #import <objc/objc-runtime.h> 7 #import <objc/objc-runtime.h>
8 #include <sys/stat.h> 8 #include <sys/stat.h>
9 9
10 #include "webkit/tools/test_shell/test_shell.h" 10 #include "webkit/tools/test_shell/test_shell.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 PathService::Get(base::DIR_SOURCE_ROOT, &path); 86 PathService::Get(base::DIR_SOURCE_ROOT, &path);
87 path = path.AppendASCII("webkit"); 87 path = path.AppendASCII("webkit");
88 path = path.AppendASCII("tools"); 88 path = path.AppendASCII("tools");
89 path = path.AppendASCII("test_shell"); 89 path = path.AppendASCII("test_shell");
90 return path.AppendASCII("resources"); 90 return path.AppendASCII("resources");
91 } 91 }
92 } 92 }
93 93
94 // Receives notification that the window is closing so that it can start the 94 // Receives notification that the window is closing so that it can start the
95 // tear-down process. Is responsible for deleting itself when done. 95 // tear-down process. Is responsible for deleting itself when done.
96 @interface WindowCloseDelegate : NSObject 96 @interface WindowDelegate : NSObject {
97 @private
98 TestShellWebView* m_webView;
99 }
100 - (id)initWithWebView:(TestShellWebView*)view;
97 @end 101 @end
98 102
99 @implementation WindowCloseDelegate 103 @implementation WindowDelegate
104
105 - (id)initWithWebView:(TestShellWebView*)view {
106 if ((self = [super init])) {
107 m_webView = view;
108 }
109 return self;
110 }
111
112 - (void)windowDidBecomeKey:(NSNotification*)notification {
113 [m_webView setIsActive:YES];
114 }
115
116 - (void)windowDidResignKey:(NSNotification*)notification {
117 [m_webView setIsActive:NO];
118 }
100 119
101 // Called when the window is about to close. Perform the self-destruction 120 // Called when the window is about to close. Perform the self-destruction
102 // sequence by getting rid of the shell and removing it and the window from 121 // sequence by getting rid of the shell and removing it and the window from
103 // the various global lists. Instead of doing it here, however, we fire off 122 // the various global lists. Instead of doing it here, however, we fire off
104 // a delayed call to |-cleanup:| to allow everything to get off the stack 123 // a delayed call to |-cleanup:| to allow everything to get off the stack
105 // before we go deleting objects. By returning YES, we allow the window to be 124 // before we go deleting objects. By returning YES, we allow the window to be
106 // removed from the screen. 125 // removed from the screen.
107 - (BOOL)windowShouldClose:(id)window { 126 - (BOOL)windowShouldClose:(id)window {
127 m_webView = nil;
128
108 // Try to make the window go away, but it may not when running layout 129 // Try to make the window go away, but it may not when running layout
109 // tests due to the quirkyness of autorelease pools and having no main loop. 130 // tests due to the quirkyness of autorelease pools and having no main loop.
110 [window autorelease]; 131 [window autorelease];
111 132
112 // clean ourselves up and do the work after clearing the stack of anything 133 // clean ourselves up and do the work after clearing the stack of anything
113 // that might have the shell on it. 134 // that might have the shell on it.
114 [self performSelectorOnMainThread:@selector(cleanup:) 135 [self performSelectorOnMainThread:@selector(cleanup:)
115 withObject:window 136 withObject:window
116 waitUntilDone:NO]; 137 waitUntilDone:NO];
117 138
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 NSClosableWindowMask | 262 NSClosableWindowMask |
242 NSMiniaturizableWindowMask | 263 NSMiniaturizableWindowMask |
243 NSResizableWindowMask ) 264 NSResizableWindowMask )
244 backing:NSBackingStoreBuffered 265 backing:NSBackingStoreBuffered
245 defer:NO]; 266 defer:NO];
246 [m_mainWnd setTitle:@"TestShell"]; 267 [m_mainWnd setTitle:@"TestShell"];
247 268
248 // Add to our map 269 // Add to our map
249 window_map_.Get()[m_mainWnd] = this; 270 window_map_.Get()[m_mainWnd] = this;
250 271
251 // Create a window delegate to watch for when it's asked to go away. It will
252 // clean itself up so we don't need to hold a reference.
253 [m_mainWnd setDelegate:[[WindowCloseDelegate alloc] init]];
254
255 // Rely on the window delegate to clean us up rather than immediately 272 // Rely on the window delegate to clean us up rather than immediately
256 // releasing when the window gets closed. We use the delegate to do 273 // releasing when the window gets closed. We use the delegate to do
257 // everything from the autorelease pool so the shell isn't on the stack 274 // everything from the autorelease pool so the shell isn't on the stack
258 // during cleanup (ie, a window close from javascript). 275 // during cleanup (ie, a window close from javascript).
259 [m_mainWnd setReleasedWhenClosed:NO]; 276 [m_mainWnd setReleasedWhenClosed:NO];
260 277
261 // Create a webview. Note that |web_view| takes ownership of this shell so we 278 // Create a webview. Note that |web_view| takes ownership of this shell so we
262 // will get cleaned up when it gets destroyed. 279 // will get cleaned up when it gets destroyed.
263 m_webViewHost.reset( 280 m_webViewHost.reset(
264 WebViewHost::Create([m_mainWnd contentView], 281 WebViewHost::Create([m_mainWnd contentView],
265 delegate_.get(), 282 delegate_.get(),
266 *TestShell::web_prefs_)); 283 *TestShell::web_prefs_));
267 delegate_->RegisterDragDrop(); 284 delegate_->RegisterDragDrop();
268 TestShellWebView* web_view = 285 TestShellWebView* web_view =
269 static_cast<TestShellWebView*>(m_webViewHost->view_handle()); 286 static_cast<TestShellWebView*>(m_webViewHost->view_handle());
270 [web_view setShell:this]; 287 [web_view setShell:this];
271 288
289 // Create a window delegate to watch for when it's asked to go away. It will
290 // clean itself up so we don't need to hold a reference.
291 [m_mainWnd setDelegate:[[WindowDelegate alloc] initWithWebView:web_view]];
292
272 // create buttons 293 // create buttons
273 NSRect button_rect = [[m_mainWnd contentView] bounds]; 294 NSRect button_rect = [[m_mainWnd contentView] bounds];
274 button_rect.origin.y = window_rect.size.height - URLBAR_HEIGHT + 295 button_rect.origin.y = window_rect.size.height - URLBAR_HEIGHT +
275 (URLBAR_HEIGHT - BUTTON_HEIGHT) / 2; 296 (URLBAR_HEIGHT - BUTTON_HEIGHT) / 2;
276 button_rect.size.height = BUTTON_HEIGHT; 297 button_rect.size.height = BUTTON_HEIGHT;
277 button_rect.origin.x += BUTTON_MARGIN; 298 button_rect.origin.x += BUTTON_MARGIN;
278 button_rect.size.width = BUTTON_WIDTH; 299 button_rect.size.width = BUTTON_WIDTH;
279 300
280 NSView* content = [m_mainWnd contentView]; 301 NSView* content = [m_mainWnd contentView];
281 302
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 while (test_is_pending_) 440 while (test_is_pending_)
420 MessageLoop::current()->Run(); 441 MessageLoop::current()->Run();
421 442
422 // Tell the watchdog that we're finished. No point waiting to re-join, it'll 443 // Tell the watchdog that we're finished. No point waiting to re-join, it'll
423 // die on its own. 444 // die on its own.
424 [thread cancel]; 445 [thread cancel];
425 [thread release]; 446 [thread release];
426 } 447 }
427 448
428 void TestShell::InteractiveSetFocus(WebWidgetHost* host, bool enable) { 449 void TestShell::InteractiveSetFocus(WebWidgetHost* host, bool enable) {
429 #if 0 450 if (enable) {
430 if (enable) 451 [[host->view_handle() window] makeKeyAndOrderFront:nil];
431 ::SetFocus(host->view_handle()); 452 } else {
432 else if (::GetFocus() == host->view_handle()) 453 // There is no way to resign key window status in Cocoa. Fake it by
433 ::SetFocus(NULL); 454 // ordering the window out (transferring key status to another window) and
434 #endif 455 // then ordering the window back in, but without making it key.
456 [[host->view_handle() window] orderOut:nil];
457 [[host->view_handle() window] orderFront:nil];
458 }
435 } 459 }
436 460
437 // static 461 // static
438 void TestShell::DestroyWindow(gfx::NativeWindow windowHandle) { 462 void TestShell::DestroyWindow(gfx::NativeWindow windowHandle) {
439 // This code is like -cleanup: on our window delegate. This call needs to be 463 // This code is like -cleanup: on our window delegate. This call needs to be
440 // able to force down a window for tests, so it closes down the window making 464 // able to force down a window for tests, so it closes down the window making
441 // sure it cleans up the window delegate and the test shells list of windows 465 // sure it cleans up the window delegate and the test shells list of windows
442 // and map of windows to shells. 466 // and map of windows to shells.
443 467
444 TestShell::RemoveWindowFromList(windowHandle); 468 TestShell::RemoveWindowFromList(windowHandle);
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 return false; 722 return false;
699 } 723 }
700 724
701 void DidLoadPlugin(const std::string& filename) { 725 void DidLoadPlugin(const std::string& filename) {
702 } 726 }
703 727
704 void DidUnloadPlugin(const std::string& filename) { 728 void DidUnloadPlugin(const std::string& filename) {
705 } 729 }
706 730
707 } // namespace webkit_glue 731 } // namespace webkit_glue
OLDNEW
« no previous file with comments | « webkit/tools/test_shell/mac/webview_host.mm ('k') | webkit/tools/test_shell/webview_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698