EventSendingController.cpp revision f05b935882198ccf7d81675736e3aeb089c5113a
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#include "EventSendingController.h"
27
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>
34
35namespace WTR {
36
37static const float ZoomMultiplierRatio = 1.2f;
38
39PassRefPtr<EventSendingController> EventSendingController::create()
40{
41    return adoptRef(new EventSendingController);
42}
43
44EventSendingController::EventSendingController()
45{
46}
47
48EventSendingController::~EventSendingController()
49{
50}
51
52JSClassRef EventSendingController::wrapperClass()
53{
54    return JSEventSendingController::eventSendingControllerClass();
55}
56
57static void setExceptionForString(JSContextRef context, JSValueRef* exception, const char* string)
58{
59    JSRetainPtr<JSStringRef> exceptionString(Adopt, JSStringCreateWithUTF8CString(string));
60    *exception = JSValueMakeString(context, exceptionString.get());
61}
62
63void EventSendingController::mouseDown(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
64{
65    setExceptionForString(context, exception, "EventSender.mouseDown is not yet supported.");
66}
67
68void EventSendingController::mouseUp(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
69{
70    setExceptionForString(context, exception, "EventSender.mouseUp is not yet supported.");
71}
72
73void EventSendingController::mouseMoveTo(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
74{
75    setExceptionForString(context, exception, "EventSender.mouseMoveTo is not yet supported.");
76}
77
78void EventSendingController::keyDown(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
79{
80    setExceptionForString(context, exception, "EventSender.keyDown is not yet supported.");
81}
82
83void EventSendingController::contextClick(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
84{
85    setExceptionForString(context, exception, "EventSender.contextClick is not yet supported.");
86}
87
88void EventSendingController::leapForward(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
89{
90    setExceptionForString(context, exception, "EventSender.leapForward is not yet supported.");
91}
92
93void EventSendingController::textZoomIn()
94{
95    // Ensure page zoom is reset.
96    WKBundlePageSetPageZoomFactor(InjectedBundle::shared().page()->page(), 1);
97
98    double zoomFactor = WKBundlePageGetTextZoomFactor(InjectedBundle::shared().page()->page());
99    WKBundlePageSetTextZoomFactor(InjectedBundle::shared().page()->page(), zoomFactor * ZoomMultiplierRatio);
100}
101
102void EventSendingController::textZoomOut()
103{
104    // Ensure page zoom is reset.
105    WKBundlePageSetPageZoomFactor(InjectedBundle::shared().page()->page(), 1);
106
107    double zoomFactor = WKBundlePageGetTextZoomFactor(InjectedBundle::shared().page()->page());
108    WKBundlePageSetTextZoomFactor(InjectedBundle::shared().page()->page(), zoomFactor / ZoomMultiplierRatio);
109}
110
111void EventSendingController::zoomPageIn()
112{
113    // Ensure text zoom is reset.
114    WKBundlePageSetTextZoomFactor(InjectedBundle::shared().page()->page(), 1);
115
116    double zoomFactor = WKBundlePageGetPageZoomFactor(InjectedBundle::shared().page()->page());
117    WKBundlePageSetPageZoomFactor(InjectedBundle::shared().page()->page(), zoomFactor * ZoomMultiplierRatio);
118}
119
120void EventSendingController::zoomPageOut()
121{
122    // Ensure text zoom is reset.
123    WKBundlePageSetTextZoomFactor(InjectedBundle::shared().page()->page(), 1);
124
125    double zoomFactor = WKBundlePageGetPageZoomFactor(InjectedBundle::shared().page()->page());
126    WKBundlePageSetPageZoomFactor(InjectedBundle::shared().page()->page(), zoomFactor / ZoomMultiplierRatio);
127}
128
129// Object Creation
130
131void EventSendingController::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception)
132{
133    setProperty(context, windowObject, "eventSender", this, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception);
134}
135
136} // namespace WTR
137