DumpRenderTreeWindow.mm 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. #import "config.h"
  31. #import "DumpRenderTreeWindow.h"
  32. #import "DumpRenderTree.h"
  33. // FIXME: This file is ObjC++ only because of this include. :(
  34. #import "TestRunner.h"
  35. #import <WebKit/WebViewPrivate.h>
  36. #import <WebKit/WebTypesInternal.h>
  37. CFMutableArrayRef openWindowsRef = 0;
  38. static CFArrayCallBacks NonRetainingArrayCallbacks = {
  39. 0,
  40. NULL,
  41. NULL,
  42. CFCopyDescription,
  43. CFEqual
  44. };
  45. @implementation DumpRenderTreeWindow
  46. + (NSArray *)openWindows
  47. {
  48. return [[(NSArray *)openWindowsRef copy] autorelease];
  49. }
  50. - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation
  51. {
  52. if (!openWindowsRef)
  53. openWindowsRef = CFArrayCreateMutable(NULL, 0, &NonRetainingArrayCallbacks);
  54. CFArrayAppendValue(openWindowsRef, self);
  55. return [super initWithContentRect:contentRect styleMask:styleMask backing:bufferingType defer:deferCreation];
  56. }
  57. - (void)close
  58. {
  59. [[NSNotificationCenter defaultCenter] removeObserver:self];
  60. CFRange arrayRange = CFRangeMake(0, CFArrayGetCount(openWindowsRef));
  61. CFIndex i = CFArrayGetFirstIndexOfValue(openWindowsRef, arrayRange, self);
  62. if (i != kCFNotFound)
  63. CFArrayRemoveValueAtIndex(openWindowsRef, i);
  64. [super close];
  65. }
  66. - (BOOL)isKeyWindow
  67. {
  68. return gTestRunner ? gTestRunner->windowIsKey() : YES;
  69. }
  70. - (BOOL)_hasKeyAppearance
  71. {
  72. return [self isKeyWindow];
  73. }
  74. - (void)keyDown:(NSEvent *)event
  75. {
  76. // Do nothing, avoiding the beep we'd otherwise get from NSResponder,
  77. // once we get to the end of the responder chain.
  78. }
  79. - (WebView *)webView
  80. {
  81. NSView *firstView = nil;
  82. if ([[[self contentView] subviews] count] > 0) {
  83. firstView = [[[self contentView] subviews] objectAtIndex:0];
  84. if ([firstView isKindOfClass:[WebView class]])
  85. return static_cast<WebView *>(firstView);
  86. }
  87. return nil;
  88. }
  89. - (void)startListeningForAcceleratedCompositingChanges
  90. {
  91. [[self webView] _setPostsAcceleratedCompositingNotifications:YES];
  92. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(webViewStartedAcceleratedCompositing:)
  93. name:_WebViewDidStartAcceleratedCompositingNotification object:nil];
  94. }
  95. - (void)webViewStartedAcceleratedCompositing:(NSNotification *)notification
  96. {
  97. // If the WebView has gone into compositing mode, turn on window autodisplay. This is necessary for CA
  98. // to update layers and start animations.
  99. // We only ever turn autodisplay on here, because we turn it off before every test.
  100. if ([[self webView] _isUsingAcceleratedCompositing])
  101. [self setAutodisplay:YES];
  102. }
  103. - (CGFloat)backingScaleFactor
  104. {
  105. return 1;
  106. }
  107. @end