diff options
Diffstat (limited to 'Tools/DumpRenderTree')
| -rw-r--r-- | Tools/DumpRenderTree/win/DumpRenderTree.vcproj | 12 | ||||
| -rw-r--r-- | Tools/DumpRenderTree/win/EventSender.cpp | 12 | ||||
| -rw-r--r-- | Tools/DumpRenderTree/win/FrameLoadDelegate.cpp | 5 | ||||
| -rw-r--r-- | Tools/DumpRenderTree/win/FrameLoadDelegate.h | 2 | ||||
| -rwxr-xr-x | Tools/DumpRenderTree/win/TextInputController.cpp | 212 | ||||
| -rwxr-xr-x | Tools/DumpRenderTree/win/TextInputController.h | 59 | ||||
| -rwxr-xr-x | Tools/DumpRenderTree/win/TextInputControllerWin.cpp | 170 |
7 files changed, 472 insertions, 0 deletions
diff --git a/Tools/DumpRenderTree/win/DumpRenderTree.vcproj b/Tools/DumpRenderTree/win/DumpRenderTree.vcproj index d22ddfa7d..18137a242 100644 --- a/Tools/DumpRenderTree/win/DumpRenderTree.vcproj +++ b/Tools/DumpRenderTree/win/DumpRenderTree.vcproj @@ -433,6 +433,18 @@ RelativePath=".\LayoutTestControllerWin.cpp" > </File> + <File + RelativePath=".\TextInputController.cpp" + > + </File> + <File + RelativePath=".\TextInputController.h" + > + </File> + <File + RelativePath=".\TextInputControllerWin.cpp" + > + </File> </Filter> <Filter Name="Delegates" diff --git a/Tools/DumpRenderTree/win/EventSender.cpp b/Tools/DumpRenderTree/win/EventSender.cpp index 376c07686..5c0993689 100644 --- a/Tools/DumpRenderTree/win/EventSender.cpp +++ b/Tools/DumpRenderTree/win/EventSender.cpp @@ -475,6 +475,18 @@ static JSValueRef keyDownCallback(JSContextRef context, JSObjectRef function, JS virtualKeyCode = VK_SNAPSHOT; else if (JSStringIsEqualToUTF8CString(character, "menu")) virtualKeyCode = VK_APPS; + else if (JSStringIsEqualToUTF8CString(character, "leftControl")) + virtualKeyCode = VK_LCONTROL; + else if (JSStringIsEqualToUTF8CString(character, "leftShift")) + virtualKeyCode = VK_LSHIFT; + else if (JSStringIsEqualToUTF8CString(character, "leftAlt")) + virtualKeyCode = VK_LMENU; + else if (JSStringIsEqualToUTF8CString(character, "rightControl")) + virtualKeyCode = VK_RCONTROL; + else if (JSStringIsEqualToUTF8CString(character, "rightShift")) + virtualKeyCode = VK_RSHIFT; + else if (JSStringIsEqualToUTF8CString(character, "rightAlt")) + virtualKeyCode = VK_RMENU; else { charCode = JSStringGetCharactersPtr(character)[0]; virtualKeyCode = LOBYTE(VkKeyScan(charCode)); diff --git a/Tools/DumpRenderTree/win/FrameLoadDelegate.cpp b/Tools/DumpRenderTree/win/FrameLoadDelegate.cpp index afc4e5185..dcf5da18c 100644 --- a/Tools/DumpRenderTree/win/FrameLoadDelegate.cpp +++ b/Tools/DumpRenderTree/win/FrameLoadDelegate.cpp @@ -35,6 +35,7 @@ #include "EventSender.h" #include "GCController.h" #include "LayoutTestController.h" +#include "TextInputController.h" #include "WebCoreTestSupport.h" #include "WorkQueueItem.h" #include "WorkQueue.h" @@ -76,6 +77,7 @@ FrameLoadDelegate::FrameLoadDelegate() : m_refCount(1) , m_gcController(adoptPtr(new GCController)) , m_accessibilityController(adoptPtr(new AccessibilityController)) + , m_textInputController(adoptPtr(new TextInputController)) { } @@ -367,6 +369,9 @@ void FrameLoadDelegate::didClearWindowObjectForFrameInStandardWorld(IWebFrame* f m_accessibilityController->makeWindowObject(context, windowObject, &exception); ASSERT(!exception); + m_textInputController->makeWindowObject(context, windowObject, &exception); + ASSERT(!exception); + JSStringRef eventSenderStr = JSStringCreateWithUTF8CString("eventSender"); JSValueRef eventSender = makeEventSender(context, !parentFrame); JSObjectSetProperty(context, windowObject, eventSenderStr, eventSender, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, 0); diff --git a/Tools/DumpRenderTree/win/FrameLoadDelegate.h b/Tools/DumpRenderTree/win/FrameLoadDelegate.h index 4cd5e1148..c842579f1 100644 --- a/Tools/DumpRenderTree/win/FrameLoadDelegate.h +++ b/Tools/DumpRenderTree/win/FrameLoadDelegate.h @@ -33,6 +33,7 @@ #include <wtf/OwnPtr.h> class AccessibilityController; +class TextInputController; class GCController; class FrameLoadDelegate : public IWebFrameLoadDelegate, public IWebFrameLoadDelegatePrivate2 { @@ -170,6 +171,7 @@ private: ULONG m_refCount; OwnPtr<GCController> m_gcController; OwnPtr<AccessibilityController> m_accessibilityController; + OwnPtr<TextInputController> m_textInputController; }; #endif // FrameLoadDelegate_h diff --git a/Tools/DumpRenderTree/win/TextInputController.cpp b/Tools/DumpRenderTree/win/TextInputController.cpp new file mode 100755 index 000000000..c54dd17de --- /dev/null +++ b/Tools/DumpRenderTree/win/TextInputController.cpp @@ -0,0 +1,212 @@ +/* + * Copyright (C) 2007, 2008, 2009, 2011 Apple Inc. All rights reserved. + * Copyright (C) 2010 Joone Hur <joone@kldp.org> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "TextInputController.h" + +#include <JavaScriptCore/JSRetainPtr.h> +#include <wtf/RefPtr.h> + +// Static Functions + +static JSValueRef setMarkedTextCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) +{ + if (argumentCount < 3) + return JSValueMakeUndefined(context); + + JSRetainPtr<JSStringRef> str(Adopt, JSValueToStringCopy(context, arguments[0], exception)); + ASSERT(!*exception); + + double from = JSValueToNumber(context, arguments[1], exception); + ASSERT(!*exception); + + double length = JSValueToNumber(context, arguments[2], exception); + ASSERT(!*exception); + + TextInputController* controller = static_cast<TextInputController*>(JSObjectGetPrivate(thisObject)); + + if (controller) + controller->setMarkedText(str.get(), from, length); + + return JSValueMakeUndefined(context); +} + +static JSValueRef hasMarkedTextCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) +{ + TextInputController* controller = static_cast<TextInputController*>(JSObjectGetPrivate(thisObject)); + + if (controller) + return JSValueMakeBoolean(context, controller->hasMarkedText()); + + return JSValueMakeUndefined(context); +} + +static JSValueRef unmarkTextCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) +{ + TextInputController* controller = static_cast<TextInputController*>(JSObjectGetPrivate(thisObject)); + if (controller) + controller->unmarkText(); + + return JSValueMakeUndefined(context); +} + +static JSValueRef markedRangeCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) +{ + TextInputController* controller = static_cast<TextInputController*>(JSObjectGetPrivate(thisObject)); + if (controller) { + vector<int> range = controller->markedRange(); + if (range.size() == 2) { + JSValueRef argumentsArrayValues[] = { JSValueMakeNumber(context, range[0]), JSValueMakeNumber(context, range[1]) }; + JSObjectRef result = JSObjectMakeArray(context, sizeof(argumentsArrayValues) / sizeof(JSValueRef), argumentsArrayValues, exception); + ASSERT(!*exception); + return result; + } + } + + return JSValueMakeUndefined(context); +} + +static JSValueRef insertTextCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) +{ + if (argumentCount < 1) + return JSValueMakeUndefined(context); + + JSRetainPtr<JSStringRef> str(Adopt, JSValueToStringCopy(context, arguments[0], exception)); + ASSERT(!*exception); + + TextInputController* controller = static_cast<TextInputController*>(JSObjectGetPrivate(thisObject)); + + if (controller) + controller->insertText(str.get()); + + return JSValueMakeUndefined(context); +} + +static JSValueRef firstRectForCharacterRangeCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) +{ + if (argumentCount < 2) + return JSValueMakeUndefined(context); + + double start = JSValueToNumber(context, arguments[0], exception); + ASSERT(!*exception); + + double length = JSValueToNumber(context, arguments[1], exception); + ASSERT(!*exception); + + TextInputController* controller = static_cast<TextInputController*>(JSObjectGetPrivate(thisObject)); + + if (controller) { + vector<int> rect = controller->firstRectForCharacterRange(start, length); + if (rect.size() == 4) { + JSValueRef argumentsArrayValues[] = + { + JSValueMakeNumber(context, rect[0]), + JSValueMakeNumber(context, rect[1]), + JSValueMakeNumber(context, rect[2]), + JSValueMakeNumber(context, rect[3]), + }; + JSObjectRef result = JSObjectMakeArray(context, sizeof(argumentsArrayValues) / sizeof(JSValueRef), argumentsArrayValues, exception); + ASSERT(!*exception); + return result; + } + } + + return JSValueMakeUndefined(context); +} + +static JSValueRef selectedRangeCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) +{ + TextInputController* controller = static_cast<TextInputController*>(JSObjectGetPrivate(thisObject)); + + if (controller) { + vector<int> rect = controller->selectedRange(); + if (rect.size() == 2) { + JSValueRef argumentsArrayValues[] = { + JSValueMakeNumber(context, rect[0]), + JSValueMakeNumber(context, rect[1]), + }; + JSObjectRef result = JSObjectMakeArray(context, sizeof(argumentsArrayValues) / sizeof(JSValueRef), argumentsArrayValues, exception); + ASSERT(!*exception); + return result; + } + } + + return JSValueMakeUndefined(context); +} + +// Object Creation + +void TextInputController::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception) +{ + JSRetainPtr<JSStringRef> textInputContollerStr(Adopt, JSStringCreateWithUTF8CString("textInputController")); + + JSClassRef classRef = getJSClass(); + JSValueRef textInputContollerObject = JSObjectMake(context, classRef, this); + JSClassRelease(classRef); + + JSObjectSetProperty(context, windowObject, textInputContollerStr.get(), textInputContollerObject, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception); +} + +JSClassRef TextInputController::getJSClass() +{ + static JSStaticValue* staticValues = TextInputController::staticValues(); + static JSStaticFunction* staticFunctions = TextInputController::staticFunctions(); + static JSClassDefinition classDefinition = + { + 0, kJSClassAttributeNone, "TextInputController", 0, staticValues, staticFunctions, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; + + return JSClassCreate(&classDefinition); +} + +JSStaticValue* TextInputController::staticValues() +{ + static JSStaticValue staticValues[] = + { + { 0, 0, 0, 0 } + }; + return staticValues; +} + +JSStaticFunction* TextInputController::staticFunctions() +{ + static JSStaticFunction staticFunctions[] = { + { "setMarkedText", setMarkedTextCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, + { "hasMarkedText", hasMarkedTextCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, + { "unmarkText", unmarkTextCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, + { "markedRange", markedRangeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, + { "insertText", insertTextCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, + { "firstRectForCharacterRange", firstRectForCharacterRangeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, + { "selectedRange", selectedRangeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, + { 0, 0, 0 } + }; + + return staticFunctions; +} diff --git a/Tools/DumpRenderTree/win/TextInputController.h b/Tools/DumpRenderTree/win/TextInputController.h new file mode 100755 index 000000000..1c28e60ce --- /dev/null +++ b/Tools/DumpRenderTree/win/TextInputController.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef TextInputController_h +#define TextInputController_h + +#include <JavaScriptCore/JSContextRef.h> +#include <JavaScriptCore/JSObjectRef.h> +#include <JavaScriptCore/JSStringRef.h> +#include <JavaScriptCore/JSValueRef.h> +#include <vector> +#include <wtf/PassRefPtr.h> + +using namespace std; + +class TextInputController { +public: + void makeWindowObject(JSContextRef, JSObjectRef windowObject, JSValueRef* exception); + + void setMarkedText(JSStringRef text, unsigned int from, unsigned int length); + bool hasMarkedText(); + void unmarkText(); + vector<int> markedRange(); + void insertText(JSStringRef text); + vector<int> firstRectForCharacterRange(unsigned int start, unsigned int length); + vector<int> selectedRange(); + +private: + static JSClassRef getJSClass(); + static JSStaticValue* staticValues(); + static JSStaticFunction* staticFunctions(); +}; + +#endif // TextInputController_h diff --git a/Tools/DumpRenderTree/win/TextInputControllerWin.cpp b/Tools/DumpRenderTree/win/TextInputControllerWin.cpp new file mode 100755 index 000000000..f4674e5dd --- /dev/null +++ b/Tools/DumpRenderTree/win/TextInputControllerWin.cpp @@ -0,0 +1,170 @@ +/* + * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "TextInputController.h" + +#include "DumpRenderTree.h" +#include <WebCore/COMPtr.h> +#include <WebKit/WebKit.h> +#include <comutil.h> +#include <string> + +using namespace std; + +void TextInputController::setMarkedText(JSStringRef text, unsigned int from, unsigned int length) +{ + COMPtr<IWebView> webView; + if (FAILED(frame->webView(&webView))) + return; + + COMPtr<IWebViewPrivate> viewPrivate; + if (FAILED(webView->QueryInterface(&viewPrivate))) + return; + + _bstr_t bstr(wstring(JSStringGetCharactersPtr(text), JSStringGetLength(text)).data()); + + viewPrivate->setCompositionForTesting(bstr, from, length); +} + +bool TextInputController::hasMarkedText() +{ + COMPtr<IWebView> webView; + if (FAILED(frame->webView(&webView))) + return false; + + COMPtr<IWebViewPrivate> viewPrivate; + if (FAILED(webView->QueryInterface(&viewPrivate))) + return false; + + BOOL result; + viewPrivate->hasCompositionForTesting(&result); + return result; +} + +void TextInputController::unmarkText() +{ + COMPtr<IWebView> webView; + if (FAILED(frame->webView(&webView))) + return; + + COMPtr<IWebViewPrivate> viewPrivate; + if (FAILED(webView->QueryInterface(&viewPrivate))) + return; + + _bstr_t empty; + viewPrivate->confirmCompositionForTesting(empty); +} + +vector<int> TextInputController::markedRange() +{ + // empty vector + vector<int> result; + + COMPtr<IWebView> webView; + if (FAILED(frame->webView(&webView))) + return result; + + COMPtr<IWebViewPrivate> viewPrivate; + if (FAILED(webView->QueryInterface(&viewPrivate))) + return result; + + unsigned int startPos; + unsigned int length; + if (SUCCEEDED(viewPrivate->compositionRangeForTesting(&startPos, &length))) { + result.resize(2); + result[0] = startPos; + result[1] = length; + } + + return result; +} + +void TextInputController::insertText(JSStringRef text) +{ + COMPtr<IWebView> webView; + if (FAILED(frame->webView(&webView))) + return; + + COMPtr<IWebViewPrivate> viewPrivate; + if (FAILED(webView->QueryInterface(&viewPrivate))) + return; + + _bstr_t bstr(wstring(JSStringGetCharactersPtr(text), JSStringGetLength(text)).data()); + + viewPrivate->confirmCompositionForTesting(bstr); +} + +vector<int> TextInputController::firstRectForCharacterRange(unsigned int start, unsigned int length) +{ + // empty vector + vector<int> result; + + COMPtr<IWebView> webView; + if (FAILED(frame->webView(&webView))) + return result; + + COMPtr<IWebViewPrivate> viewPrivate; + if (FAILED(webView->QueryInterface(&viewPrivate))) + return result; + + RECT resultRECT; + if SUCCEEDED(viewPrivate->firstRectForCharacterRangeForTesting(start, length, &resultRECT)) { + result.resize(4); + result[0] = resultRECT.left; + result[1] = resultRECT.top; + result[2] = resultRECT.right - resultRECT.left; + result[3] = resultRECT.bottom - resultRECT.top; + } + + return result; +} + +vector<int> TextInputController::selectedRange() +{ + // empty vector + vector<int> result; + + COMPtr<IWebView> webView; + if (FAILED(frame->webView(&webView))) + return result; + + COMPtr<IWebViewPrivate> viewPrivate; + if (FAILED(webView->QueryInterface(&viewPrivate))) + return result; + + unsigned int startPos; + unsigned int length; + if (SUCCEEDED(viewPrivate->selectedRangeForTesting(&startPos, &length))) { + result.resize(2); + result[0] = startPos; + result[1] = length; + } + + return result; +} |
