Modified: trunk/Source/WebKit/gtk/WebCoreSupport/DumpRenderTreeSupportGtk.cpp (88497 => 88498)
--- trunk/Source/WebKit/gtk/WebCoreSupport/DumpRenderTreeSupportGtk.cpp 2011-06-09 23:04:51 UTC (rev 88497)
+++ trunk/Source/WebKit/gtk/WebCoreSupport/DumpRenderTreeSupportGtk.cpp 2011-06-09 23:33:49 UTC (rev 88498)
@@ -512,7 +512,7 @@
return core(webView)->focusController()->focusedOrMainFrame()->editor()->command(name).isEnabled();
}
-void DumpRenderTreeSupportGtk::setComposition(WebKitWebView* webView, const char* text, int start, int end)
+void DumpRenderTreeSupportGtk::setComposition(WebKitWebView* webView, const char* text, int start, int length)
{
g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
g_return_if_fail(text);
@@ -522,17 +522,47 @@
return;
Editor* editor = frame->editor();
- if (!editor)
+ if (!editor || (!editor->canEdit() && !editor->hasComposition()))
return;
- if (!editor->canEdit() && !editor->hasComposition())
- return;
String compositionString = String::fromUTF8(text);
Vector<CompositionUnderline> underlines;
underlines.append(CompositionUnderline(0, compositionString.length(), Color(0, 0, 0), false));
- editor->setComposition(compositionString, underlines, start, end);
+ editor->setComposition(compositionString, underlines, start, start + length);
}
+bool DumpRenderTreeSupportGtk::hasComposition(WebKitWebView* webView)
+{
+ g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), false);
+ Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
+ if (!frame)
+ return false;
+ Editor* editor = frame->editor();
+ if (!editor)
+ return false;
+
+ return editor->hasComposition();
+}
+
+bool DumpRenderTreeSupportGtk::compositionRange(WebKitWebView* webView, int* start, int* length)
+{
+ g_return_val_if_fail(start && length, false);
+ *start = *length = 0;
+
+ g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), false);
+ Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
+ if (!frame)
+ return false;
+
+ Editor* editor = frame->editor();
+ if (!editor || !editor->hasComposition())
+ return false;
+
+ *start = editor->compositionStart();
+ *length = editor->compositionEnd() - *start;
+ return true;
+}
+
void DumpRenderTreeSupportGtk::confirmComposition(WebKitWebView* webView, const char* text)
{
g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
@@ -542,16 +572,18 @@
return;
Editor* editor = frame->editor();
- if (!editor || (!editor->hasComposition() && !text))
+ if (!editor)
return;
- if (editor->hasComposition()) {
- if (text)
- editor->confirmComposition(String::fromUTF8(text));
- else
- editor->confirmComposition();
- } else
+ if (!editor->hasComposition()) {
editor->insertText(String::fromUTF8(text), 0);
+ return;
+ }
+ if (text) {
+ editor->confirmComposition(String::fromUTF8(text));
+ return;
+ }
+ editor->confirmComposition();
}
bool DumpRenderTreeSupportGtk::firstRectForCharacterRange(WebKitWebView* webView, int location, int length, GdkRectangle* rect)
@@ -577,21 +609,21 @@
return false;
*rect = editor->firstRectForRange(range.get());
-
return true;
}
-bool DumpRenderTreeSupportGtk::selectedRange(WebKitWebView* webView, int* start, int* end)
+bool DumpRenderTreeSupportGtk::selectedRange(WebKitWebView* webView, int* start, int* length)
{
g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), false);
- g_return_val_if_fail(start, false);
- g_return_val_if_fail(end, false);
+ g_return_val_if_fail(start && length, false);
Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
if (!frame)
return false;
RefPtr<Range> range = frame->selection()->toNormalizedRange().get();
+ if (!range)
+ return false;
Element* selectionRoot = frame->selection()->rootEditableElement();
Element* scope = selectionRoot ? selectionRoot : frame->document()->documentElement();
@@ -603,7 +635,7 @@
ExceptionCode ec;
testRange->setEnd(range->endContainer(), range->endOffset(), ec);
ASSERT(testRange->startContainer() == scope);
- *end = TextIterator::rangeLength(testRange.get());
+ *length = TextIterator::rangeLength(testRange.get());
return true;
}
Modified: trunk/Source/WebKit/gtk/WebCoreSupport/DumpRenderTreeSupportGtk.h (88497 => 88498)
--- trunk/Source/WebKit/gtk/WebCoreSupport/DumpRenderTreeSupportGtk.h 2011-06-09 23:04:51 UTC (rev 88497)
+++ trunk/Source/WebKit/gtk/WebCoreSupport/DumpRenderTreeSupportGtk.h 2011-06-09 23:33:49 UTC (rev 88498)
@@ -97,10 +97,6 @@
static void executeCoreCommandByName(WebKitWebView*, const gchar* name, const gchar* value);
static bool isCommandEnabled(WebKitWebView*, const gchar* name);
static bool findString(WebKitWebView*, const gchar*, WebKitFindOptions);
- static void setComposition(WebKitWebView*, const char* text, int start, int end);
- static void confirmComposition(WebKitWebView*, const char* text);
- static bool firstRectForCharacterRange(WebKitWebView*, int location, int length, GdkRectangle*);
- static bool selectedRange(WebKitWebView*, int* start, int* end);
static double defaultMinimumTimerInterval(); // Not really tied to WebView
static void setMinimumTimerInterval(WebKitWebView*, double);
static void rectangleForSelection(WebKitWebFrame*, GdkRectangle*);
@@ -111,6 +107,14 @@
static void incrementAccessibilityValue(AtkObject*);
static void decrementAccessibilityValue(AtkObject*);
+ // TextInputController
+ static void setComposition(WebKitWebView*, const char*, int start, int length);
+ static bool hasComposition(WebKitWebView*);
+ static bool compositionRange(WebKitWebView*, int* start, int* length);
+ static void confirmComposition(WebKitWebView*, const char*);
+ static bool firstRectForCharacterRange(WebKitWebView*, int location, int length, GdkRectangle*);
+ static bool selectedRange(WebKitWebView*, int* start, int* length);
+
// GC
static void gcCollectJavascriptObjects();
static void gcCollectJavascriptObjectsOnAlternateThread(bool waitUntilDone);
Modified: trunk/Tools/DumpRenderTree/gtk/TextInputController.cpp (88497 => 88498)
--- trunk/Tools/DumpRenderTree/gtk/TextInputController.cpp 2011-06-09 23:04:51 UTC (rev 88497)
+++ trunk/Tools/DumpRenderTree/gtk/TextInputController.cpp 2011-06-09 23:33:49 UTC (rev 88498)
@@ -41,14 +41,12 @@
static JSValueRef setMarkedTextCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
- if (!view)
- return JSValueMakeUndefined(context);
-
+ ASSERT(view);
if (argumentCount < 3)
return JSValueMakeUndefined(context);
JSStringRef string = JSValueToStringCopy(context, arguments[0], exception);
- g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context));
+ ASSERT(!exception || !*exception);
size_t bufferSize = JSStringGetMaximumUTF8CStringSize(string);
GOwnPtr<gchar> stringBuffer(static_cast<gchar*>(g_malloc(bufferSize)));
@@ -56,27 +54,49 @@
JSStringRelease(string);
int start = static_cast<int>(JSValueToNumber(context, arguments[1], exception));
- g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context));
+ ASSERT(!exception || !*exception);
- int end = static_cast<int>(JSValueToNumber(context, arguments[2], exception));
- g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context));
+ int length = static_cast<int>(JSValueToNumber(context, arguments[2], exception));
+ ASSERT(!exception || !*exception);
- DumpRenderTreeSupportGtk::setComposition(view, stringBuffer.get(), start, end);
-
+ DumpRenderTreeSupportGtk::setComposition(view, stringBuffer.get(), start, length);
return JSValueMakeUndefined(context);
}
-static JSValueRef insertTextCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+static JSValueRef hasMarkedTextCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
- if (!view)
+ ASSERT(view);
+ return JSValueMakeBoolean(context, DumpRenderTreeSupportGtk::hasComposition(view));
+}
+
+static JSValueRef markedRangeCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
+ ASSERT(view);
+
+ int start, length;
+ if (!DumpRenderTreeSupportGtk::compositionRange(view, &start, &length))
return JSValueMakeUndefined(context);
+ JSValueRef arrayValues[2];
+ arrayValues[0] = JSValueMakeNumber(context, start);
+ arrayValues[1] = JSValueMakeNumber(context, length);
+ JSObjectRef arrayObject = JSObjectMakeArray(context, 2, arrayValues, exception);
+ ASSERT(!exception || !*exception);
+ return arrayObject;
+}
+
+static JSValueRef insertTextCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
+ ASSERT(view);
+
if (argumentCount < 1)
return JSValueMakeUndefined(context);
JSStringRef string = JSValueToStringCopy(context, arguments[0], exception);
- g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context));
+ ASSERT(!exception || !*exception);
size_t bufferSize = JSStringGetMaximumUTF8CStringSize(string);
GOwnPtr<gchar> stringBuffer(static_cast<gchar*>(g_malloc(bufferSize)));
@@ -84,15 +104,13 @@
JSStringRelease(string);
DumpRenderTreeSupportGtk::confirmComposition(view, stringBuffer.get());
-
return JSValueMakeUndefined(context);
}
static JSValueRef unmarkTextCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
- if (!view)
- return JSValueMakeUndefined(context);
+ ASSERT(view);
DumpRenderTreeSupportGtk::confirmComposition(view, 0);
return JSValueMakeUndefined(context);
@@ -101,17 +119,15 @@
static JSValueRef firstRectForCharacterRangeCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
- if (!view)
- return JSValueMakeUndefined(context);
-
+ ASSERT(view);
if (argumentCount < 2)
return JSValueMakeUndefined(context);
int location = static_cast<int>(JSValueToNumber(context, arguments[0], exception));
- g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context));
+ ASSERT(!exception || !*exception);
int length = static_cast<int>(JSValueToNumber(context, arguments[1], exception));
- g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context));
+ ASSERT(!exception || !*exception);
GdkRectangle rect;
if (!DumpRenderTreeSupportGtk::firstRectForCharacterRange(view, location, length, &rect))
@@ -123,7 +139,7 @@
arrayValues[2] = JSValueMakeNumber(context, rect.width);
arrayValues[3] = JSValueMakeNumber(context, rect.height);
JSObjectRef arrayObject = JSObjectMakeArray(context, 4, arrayValues, exception);
- g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context));
+ ASSERT(!exception || !*exception);
return arrayObject;
}
@@ -131,24 +147,25 @@
static JSValueRef selectedRangeCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
- if (!view)
- return JSValueMakeUndefined(context);
+ ASSERT(view);
- int start, end;
- if (!DumpRenderTreeSupportGtk::selectedRange(view, &start, &end))
+ int start, length;
+ if (!DumpRenderTreeSupportGtk::selectedRange(view, &start, &length))
return JSValueMakeUndefined(context);
JSValueRef arrayValues[2];
arrayValues[0] = JSValueMakeNumber(context, start);
- arrayValues[1] = JSValueMakeNumber(context, end);
+ arrayValues[1] = JSValueMakeNumber(context, length);
JSObjectRef arrayObject = JSObjectMakeArray(context, 2, arrayValues, exception);
- g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context));
+ ASSERT(!exception || !*exception);
return arrayObject;
}
static JSStaticFunction staticFunctions[] = {
{ "setMarkedText", setMarkedTextCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
+ { "hasMarkedText", hasMarkedTextCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
+ { "markedRange", markedRangeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
{ "insertText", insertTextCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
{ "unmarkText", unmarkTextCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
{ "firstRectForCharacterRange", firstRectForCharacterRangeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },