2 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #include "EventSendingController.h"
28 #include "InjectedBundle.h"
29 #include "InjectedBundlePage.h"
30 #include "JSEventSendingController.h"
31 #include <WebKit2/WKBundlePage.h>
32 #include <WebKit2/WKBundlePagePrivate.h>
33 #include <WebKit2/WKBundlePrivate.h>
37 static const float ZoomMultiplierRatio = 1.2f;
39 PassRefPtr<EventSendingController> EventSendingController::create()
41 return adoptRef(new EventSendingController);
44 EventSendingController::EventSendingController()
48 EventSendingController::~EventSendingController()
52 JSClassRef EventSendingController::wrapperClass()
54 return JSEventSendingController::eventSendingControllerClass();
57 static void setExceptionForString(JSContextRef context, JSValueRef* exception, const char* string)
59 JSRetainPtr<JSStringRef> exceptionString(Adopt, JSStringCreateWithUTF8CString(string));
60 *exception = JSValueMakeString(context, exceptionString.get());
63 void EventSendingController::mouseDown(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
65 setExceptionForString(context, exception, "EventSender.mouseDown is not yet supported.");
68 void EventSendingController::mouseUp(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
70 setExceptionForString(context, exception, "EventSender.mouseUp is not yet supported.");
73 void EventSendingController::mouseMoveTo(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
75 setExceptionForString(context, exception, "EventSender.mouseMoveTo is not yet supported.");
78 void EventSendingController::keyDown(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
80 setExceptionForString(context, exception, "EventSender.keyDown is not yet supported.");
83 void EventSendingController::contextClick(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
85 setExceptionForString(context, exception, "EventSender.contextClick is not yet supported.");
88 void EventSendingController::leapForward(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
90 setExceptionForString(context, exception, "EventSender.leapForward is not yet supported.");
93 void EventSendingController::textZoomIn()
95 // Ensure page zoom is reset.
96 WKBundlePageSetPageZoomFactor(InjectedBundle::shared().page()->page(), 1);
98 float zoomFactor = WKBundlePageGetTextZoomFactor(InjectedBundle::shared().page()->page());
99 WKBundlePageSetTextZoomFactor(InjectedBundle::shared().page()->page(), zoomFactor * ZoomMultiplierRatio);
102 void EventSendingController::textZoomOut()
104 // Ensure page zoom is reset.
105 WKBundlePageSetPageZoomFactor(InjectedBundle::shared().page()->page(), 1);
107 float zoomFactor = WKBundlePageGetTextZoomFactor(InjectedBundle::shared().page()->page());
108 WKBundlePageSetTextZoomFactor(InjectedBundle::shared().page()->page(), zoomFactor / ZoomMultiplierRatio);
111 void EventSendingController::zoomPageIn()
113 // Ensure text zoom is reset.
114 WKBundlePageSetTextZoomFactor(InjectedBundle::shared().page()->page(), 1);
116 float zoomFactor = WKBundlePageGetPageZoomFactor(InjectedBundle::shared().page()->page());
117 WKBundlePageSetPageZoomFactor(InjectedBundle::shared().page()->page(), zoomFactor / ZoomMultiplierRatio);
120 void EventSendingController::zoomPageOut()
122 // Ensure text zoom is reset.
123 WKBundlePageSetTextZoomFactor(InjectedBundle::shared().page()->page(), 1);
125 float zoomFactor = WKBundlePageGetPageZoomFactor(InjectedBundle::shared().page()->page());
126 WKBundlePageSetPageZoomFactor(InjectedBundle::shared().page()->page(), zoomFactor / ZoomMultiplierRatio);
131 void EventSendingController::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception)
133 setProperty(context, windowObject, "eventSender", this, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception);