| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2010 Apple 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 * 1. Redistributions of source code must retain the above copyright | |
| 8 * notice, this list of conditions and the following disclaimer. | |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer in the | |
| 11 * documentation and/or other materials provided with the distribution. | |
| 12 * | |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | |
| 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | |
| 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | |
| 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
| 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
| 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
| 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
| 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | |
| 23 * THE POSSIBILITY OF SUCH DAMAGE. | |
| 24 */ | |
| 25 | |
| 26 #import "config.h" | |
| 27 #import "PlatformWebView.h" | |
| 28 | |
| 29 #import <WebKit2/WKViewPrivate.h> | |
| 30 #import <Carbon/Carbon.h> | |
| 31 | |
| 32 @interface ActiveOffscreenWindow : NSWindow | |
| 33 @end | |
| 34 | |
| 35 @implementation ActiveOffscreenWindow | |
| 36 - (BOOL)isKeyWindow | |
| 37 { | |
| 38 return YES; | |
| 39 } | |
| 40 @end | |
| 41 | |
| 42 namespace TestWebKitAPI { | |
| 43 | |
| 44 PlatformWebView::PlatformWebView(WKContextRef contextRef, WKPageGroupRef pageGro
upRef) | |
| 45 { | |
| 46 NSRect rect = NSMakeRect(0, 0, 800, 600); | |
| 47 m_view = [[WKView alloc] initWithFrame:rect contextRef:contextRef pageGroupR
ef:pageGroupRef]; | |
| 48 | |
| 49 NSRect windowRect = NSOffsetRect(rect, -10000, [(NSScreen *)[[NSScreen scree
ns] objectAtIndex:0] frame].size.height - rect.size.height + 10000); | |
| 50 m_window = [[ActiveOffscreenWindow alloc] initWithContentRect:windowRect sty
leMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES]; | |
| 51 [m_window setColorSpace:[[NSScreen mainScreen] colorSpace]]; | |
| 52 [[m_window contentView] addSubview:m_view]; | |
| 53 [m_window orderBack:nil]; | |
| 54 [m_window setAutodisplay:NO]; | |
| 55 [m_window setReleasedWhenClosed:NO]; | |
| 56 } | |
| 57 | |
| 58 PlatformWebView::~PlatformWebView() | |
| 59 { | |
| 60 [m_window close]; | |
| 61 [m_window release]; | |
| 62 [m_view release]; | |
| 63 } | |
| 64 | |
| 65 void PlatformWebView::resizeTo(unsigned width, unsigned height) | |
| 66 { | |
| 67 [m_view setFrame:NSMakeRect(0, 0, width, height)]; | |
| 68 } | |
| 69 | |
| 70 | |
| 71 WKPageRef PlatformWebView::page() const | |
| 72 { | |
| 73 return [m_view pageRef]; | |
| 74 } | |
| 75 | |
| 76 void PlatformWebView::focus() | |
| 77 { | |
| 78 // Implement. | |
| 79 } | |
| 80 | |
| 81 void PlatformWebView::simulateSpacebarKeyPress() | |
| 82 { | |
| 83 NSEvent *event = [NSEvent keyEventWithType:NSKeyDown | |
| 84 location:NSMakePoint(5, 5) | |
| 85 modifierFlags:0 | |
| 86 timestamp:GetCurrentEventTime() | |
| 87 windowNumber:[m_window windowNumber] | |
| 88 context:[NSGraphicsContext currentContext
] | |
| 89 characters:@" " | |
| 90 charactersIgnoringModifiers:@" " | |
| 91 isARepeat:NO | |
| 92 keyCode:0x31]; | |
| 93 | |
| 94 [m_view keyDown:event]; | |
| 95 | |
| 96 event = [NSEvent keyEventWithType:NSKeyUp | |
| 97 location:NSMakePoint(5, 5) | |
| 98 modifierFlags:0 | |
| 99 timestamp:GetCurrentEventTime() | |
| 100 windowNumber:[m_window windowNumber] | |
| 101 context:[NSGraphicsContext currentContext] | |
| 102 characters:@" " | |
| 103 charactersIgnoringModifiers:@" " | |
| 104 isARepeat:NO | |
| 105 keyCode:0x31]; | |
| 106 | |
| 107 [m_view keyUp:event]; | |
| 108 } | |
| 109 | |
| 110 void PlatformWebView::simulateRightClick(unsigned x, unsigned y) | |
| 111 { | |
| 112 NSEvent *event = [NSEvent mouseEventWithType:NSRightMouseDown | |
| 113 location:NSMakePoint(x, y) | |
| 114 modifierFlags:0 | |
| 115 timestamp:GetCurrentEventTime() | |
| 116 windowNumber:[m_window windowNumber] | |
| 117 context:[NSGraphicsContext currentConte
xt] | |
| 118 eventNumber:0 | |
| 119 clickCount:0 | |
| 120 pressure:0]; | |
| 121 | |
| 122 | |
| 123 [m_view rightMouseDown:event]; | |
| 124 | |
| 125 event = [NSEvent mouseEventWithType:NSRightMouseUp | |
| 126 location:NSMakePoint(x, y) | |
| 127 modifierFlags:0 | |
| 128 timestamp:GetCurrentEventTime() | |
| 129 windowNumber:[m_window windowNumber] | |
| 130 context:[NSGraphicsContext currentContext] | |
| 131 eventNumber:0 | |
| 132 clickCount:0 | |
| 133 pressure:0]; | |
| 134 | |
| 135 [m_view rightMouseUp:event]; | |
| 136 | |
| 137 } | |
| 138 | |
| 139 void PlatformWebView::simulateMouseMove(unsigned x, unsigned y) | |
| 140 { | |
| 141 NSEvent *event = [NSEvent mouseEventWithType:NSMouseMoved | |
| 142 location:NSMakePoint(x, y) | |
| 143 modifierFlags:0 | |
| 144 timestamp:GetCurrentEventTime() | |
| 145 windowNumber:[m_window windowNumber] | |
| 146 context:[NSGraphicsContext currentContext] | |
| 147 eventNumber:0 | |
| 148 clickCount:0 | |
| 149 pressure:0]; | |
| 150 | |
| 151 [m_view mouseMoved:event]; | |
| 152 | |
| 153 } | |
| 154 | |
| 155 } // namespace TestWebKitAPI | |
| OLD | NEW |