1/* 2 * Copyright (C) 2005, 2009 Apple Computer, Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 14 * its contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#import <WebKit/WebViewFactory.h> 30 31#import <WebKit/WebFrameInternal.h> 32#import <WebKit/WebViewInternal.h> 33#import <WebKit/WebHTMLViewInternal.h> 34#import <WebKit/WebNSUserDefaultsExtras.h> 35#import <WebKit/WebNSObjectExtras.h> 36#import <WebKit/WebNSViewExtras.h> 37#import <WebKitSystemInterface.h> 38#import <wtf/Assertions.h> 39 40@interface NSMenu (WebViewFactoryAdditions) 41- (NSMenuItem *)addItemWithTitle:(NSString *)title action:(SEL)action tag:(int)tag; 42@end 43 44@implementation NSMenu (WebViewFactoryAdditions) 45 46- (NSMenuItem *)addItemWithTitle:(NSString *)title action:(SEL)action tag:(int)tag 47{ 48 NSMenuItem *item = [[[NSMenuItem alloc] initWithTitle:title action:action keyEquivalent:@""] autorelease]; 49 [item setTag:tag]; 50 [self addItem:item]; 51 return item; 52} 53 54@end 55 56@implementation WebViewFactory 57 58+ (void)createSharedFactory 59{ 60 if (![self sharedFactory]) { 61 [[[self alloc] init] release]; 62 } 63 ASSERT([[self sharedFactory] isKindOfClass:self]); 64} 65 66- (BOOL)objectIsTextMarker:(id)object 67{ 68 return object != nil && CFGetTypeID(object) == WKGetAXTextMarkerTypeID(); 69} 70 71- (BOOL)objectIsTextMarkerRange:(id)object 72{ 73 return object != nil && CFGetTypeID(object) == WKGetAXTextMarkerRangeTypeID(); 74} 75 76- (WebCoreTextMarker *)textMarkerWithBytes:(const void *)bytes length:(size_t)length 77{ 78 return WebCFAutorelease(WKCreateAXTextMarker(bytes, length)); 79} 80 81- (BOOL)getBytes:(void *)bytes fromTextMarker:(WebCoreTextMarker *)textMarker length:(size_t)length 82{ 83 return WKGetBytesFromAXTextMarker(textMarker, bytes, length); 84} 85 86- (WebCoreTextMarkerRange *)textMarkerRangeWithStart:(WebCoreTextMarker *)start end:(WebCoreTextMarker *)end 87{ 88 ASSERT(start != nil); 89 ASSERT(end != nil); 90 ASSERT(CFGetTypeID(start) == WKGetAXTextMarkerTypeID()); 91 ASSERT(CFGetTypeID(end) == WKGetAXTextMarkerTypeID()); 92 return WebCFAutorelease(WKCreateAXTextMarkerRange(start, end)); 93} 94 95- (WebCoreTextMarker *)startOfTextMarkerRange:(WebCoreTextMarkerRange *)range 96{ 97 ASSERT(range != nil); 98 ASSERT(CFGetTypeID(range) == WKGetAXTextMarkerRangeTypeID()); 99 return WebCFAutorelease(WKCopyAXTextMarkerRangeStart(range)); 100} 101 102- (WebCoreTextMarker *)endOfTextMarkerRange:(WebCoreTextMarkerRange *)range 103{ 104 ASSERT(range != nil); 105 ASSERT(CFGetTypeID(range) == WKGetAXTextMarkerRangeTypeID()); 106 return WebCFAutorelease(WKCopyAXTextMarkerRangeEnd(range)); 107} 108 109- (void)accessibilityHandleFocusChanged 110{ 111 WKAccessibilityHandleFocusChanged(); 112} 113 114- (AXUIElementRef)AXUIElementForElement:(id)element 115{ 116 return WKCreateAXUIElementRef(element); 117} 118 119- (CGRect)accessibilityConvertScreenRect:(CGRect)bounds 120{ 121 NSArray *screens = [NSScreen screens]; 122 if ([screens count]) { 123 CGFloat screenHeight = NSHeight([[screens objectAtIndex:0] frame]); 124 bounds.origin.y = (screenHeight - (bounds.origin.y + bounds.size.height)); 125 } else 126 bounds = CGRectZero; 127 128 return bounds; 129} 130 131- (void)unregisterUniqueIdForUIElement:(id)element 132{ 133 WKUnregisterUniqueIdForElement(element); 134} 135 136@end 137