1/* 2 * Copyright (C) 2005, 2006, 2007 Apple, Inc. All rights reserved. 3 * (C) 2007 Graham Dennis (graham.dennis@gmail.com) 4 * (C) 2007 Eric Seidel <eric@webkit.org> 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 16 * its contributors may be used to endorse or promote products derived 17 * from this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31#import "config.h" 32#import "DumpRenderTreeWindow.h" 33 34#import "DumpRenderTree.h" 35 36// FIXME: This file is ObjC++ only because of this include. :( 37#import "LayoutTestController.h" 38#import <WebKit/WebViewPrivate.h> 39#import <WebKit/WebTypesInternal.h> 40 41CFMutableArrayRef openWindowsRef = 0; 42 43static CFArrayCallBacks NonRetainingArrayCallbacks = { 44 0, 45 NULL, 46 NULL, 47 CFCopyDescription, 48 CFEqual 49}; 50 51@implementation DumpRenderTreeWindow 52 53+ (NSArray *)openWindows 54{ 55 return [[(NSArray *)openWindowsRef copy] autorelease]; 56} 57 58- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation 59{ 60 if (!openWindowsRef) 61 openWindowsRef = CFArrayCreateMutable(NULL, 0, &NonRetainingArrayCallbacks); 62 63 CFArrayAppendValue(openWindowsRef, self); 64 65 return [super initWithContentRect:contentRect styleMask:styleMask backing:bufferingType defer:deferCreation]; 66} 67 68- (void)close 69{ 70 [[NSNotificationCenter defaultCenter] removeObserver:self]; 71 72 CFRange arrayRange = CFRangeMake(0, CFArrayGetCount(openWindowsRef)); 73 CFIndex i = CFArrayGetFirstIndexOfValue(openWindowsRef, arrayRange, self); 74 if (i != kCFNotFound) 75 CFArrayRemoveValueAtIndex(openWindowsRef, i); 76 77 [super close]; 78} 79 80- (BOOL)isKeyWindow 81{ 82 return gLayoutTestController ? gLayoutTestController->windowIsKey() : YES; 83} 84 85- (void)keyDown:(NSEvent *)event 86{ 87 // Do nothing, avoiding the beep we'd otherwise get from NSResponder, 88 // once we get to the end of the responder chain. 89} 90 91- (WebView *)webView 92{ 93 NSView *firstView = nil; 94 if ([[[self contentView] subviews] count] > 0) { 95 firstView = [[[self contentView] subviews] objectAtIndex:0]; 96 if ([firstView isKindOfClass:[WebView class]]) 97 return static_cast<WebView *>(firstView); 98 } 99 return nil; 100} 101 102- (void)startListeningForAcceleratedCompositingChanges 103{ 104 [[self webView] _setPostsAcceleratedCompositingNotifications:YES]; 105 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(webViewStartedAcceleratedCompositing:) 106 name:_WebViewDidStartAcceleratedCompositingNotification object:nil]; 107} 108 109- (void)webViewStartedAcceleratedCompositing:(NSNotification *)notification 110{ 111 // If the WebView has gone into compositing mode, turn on window autodisplay. This is necessary for CA 112 // to update layers and start animations. 113 // We only ever turn autodisplay on here, because we turn it off before every test. 114 if ([[self webView] _isUsingAcceleratedCompositing]) 115 [self setAutodisplay:YES]; 116} 117 118@end 119