Skip to content
Permalink
Browse files
2010-03-08 Kent Tamura <tkent@chromium.org>
        Reviewed by Dimitri Glazkov.

        [DRT/Chromium] Add PlainTextController and TextInputController
        https://bugs.webkit.org/show_bug.cgi?id=35852

        Add PlainTextController and TextInputController classes, which are going
        to be used by DumpRenderTree Chromium port. These files are based on:
        - src/webkit/tools/test_shell/plain_text_controller.{cc,h} and
        - src/webkit/tools/test_shell/text_input_controller.{cc,h}
        of Chromium rev.40492.

        * DumpRenderTree/chromium/PlainTextController.cpp: Added.
        * DumpRenderTree/chromium/PlainTextController.h: Added.
        * DumpRenderTree/chromium/TextInputController.cpp: Added.
        * DumpRenderTree/chromium/TextInputController.h: Added.

Canonical link: https://commits.webkit.org/47009@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@55712 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
tkent-google committed Mar 9, 2010
1 parent fdeea3f commit cf0428d70b7920cc8dff1f74445a0deff5620c42
Showing 5 changed files with 432 additions and 0 deletions.
@@ -1,3 +1,21 @@
2010-03-08 Kent Tamura <tkent@chromium.org>

Reviewed by Dimitri Glazkov.

[DRT/Chromium] Add PlainTextController and TextInputController
https://bugs.webkit.org/show_bug.cgi?id=35852

Add PlainTextController and TextInputController classes, which are going
to be used by DumpRenderTree Chromium port. These files are based on:
- src/webkit/tools/test_shell/plain_text_controller.{cc,h} and
- src/webkit/tools/test_shell/text_input_controller.{cc,h}
of Chromium rev.40492.

* DumpRenderTree/chromium/PlainTextController.cpp: Added.
* DumpRenderTree/chromium/PlainTextController.h: Added.
* DumpRenderTree/chromium/TextInputController.cpp: Added.
* DumpRenderTree/chromium/TextInputController.h: Added.

2010-03-08 Dumitru Daniliuc <dumi@chromium.org>

Unreviewed, Chromium build fix.
@@ -0,0 +1,79 @@
/*
* Copyright (C) 2010 Google Inc. All rights reserved.
* Copyright (C) 2009 Pawel Hajdan (phajdan.jr@chromium.org)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * Neither the name of Google Inc. 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 THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
* OWNER OR 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 "PlainTextController.h"

#include "TestShell.h"
#include "public/WebBindings.h"
#include "public/WebRange.h"
#include "public/WebString.h"

using namespace WebKit;

PlainTextController::PlainTextController()
{
// Initialize the map that associates methods of this class with the names
// they will use when called by JavaScript. The actual binding of those
// names to their methods will be done by calling bindToJavaScript() (defined
// by CppBoundClass, the parent to PlainTextController).
bindMethod("plainText", &PlainTextController::plainText);

// The fallback method is called when an unknown method is invoked.
bindFallbackMethod(&PlainTextController::fallbackMethod);
}

void PlainTextController::plainText(const CppArgumentList& arguments, CppVariant* result)
{
result->setNull();

if (arguments.size() < 1 || !arguments[0].isObject())
return;

// Check that passed-in object is, in fact, a range.
NPObject* npobject = NPVARIANT_TO_OBJECT(arguments[0]);
if (!npobject)
return;
WebRange range;
if (!WebBindings::getRange(npobject, &range))
return;

// Extract the text using the Range's text() method
WebString text = range.toPlainText();
result->set(text.utf8());
}

void PlainTextController::fallbackMethod(const CppArgumentList&, CppVariant* result)
{
printf("CONSOLE MESSAGE: JavaScript ERROR: unknown method called on PlainTextController\n");
result->setNull();
}

@@ -0,0 +1,52 @@
/*
* Copyright (C) 2010 Google 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:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * Neither the name of Google Inc. 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 THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
* OWNER OR 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 PlainTextController_h
#define PlainTextController_h

#include "CppBoundClass.h"

class TestShell;

class PlainTextController : public CppBoundClass {
public:
// Builds the property and method lists needed to bind this class to a JS
// object.
explicit PlainTextController();

// JS callback methods.
void plainText(const CppArgumentList&, CppVariant*);

// Fall-back method: called if an unknown method is invoked.
void fallbackMethod(const CppArgumentList&, CppVariant*);
};

#endif // PlainTextController_h

@@ -0,0 +1,210 @@
/*
* Copyright (C) 2010 Google 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:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * Neither the name of Google Inc. 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 THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
* OWNER OR 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 "TestShell.h"
#include "base/string_util.h"
#include "public/WebFrame.h"
#include "public/WebRange.h"
#include "public/WebString.h"
#include "public/WebView.h"

using namespace WebKit;

TestShell* TextInputController::testShell = 0;

TextInputController::TextInputController(TestShell* shell)
{
// Set static testShell variable. Be careful not to assign testShell to new
// windows which are temporary.
if (!testShell)
testShell = shell;

bindMethod("insertText", &TextInputController::insertText);
bindMethod("doCommand", &TextInputController::doCommand);
bindMethod("setMarkedText", &TextInputController::setMarkedText);
bindMethod("unmarkText", &TextInputController::unmarkText);
bindMethod("hasMarkedText", &TextInputController::hasMarkedText);
bindMethod("conversationIdentifier", &TextInputController::conversationIdentifier);
bindMethod("substringFromRange", &TextInputController::substringFromRange);
bindMethod("attributedSubstringFromRange", &TextInputController::attributedSubstringFromRange);
bindMethod("markedRange", &TextInputController::markedRange);
bindMethod("selectedRange", &TextInputController::selectedRange);
bindMethod("firstRectForCharacterRange", &TextInputController::firstRectForCharacterRange);
bindMethod("characterIndexForPoint", &TextInputController::characterIndexForPoint);
bindMethod("validAttributesForMarkedText", &TextInputController::validAttributesForMarkedText);
bindMethod("makeAttributedString", &TextInputController::makeAttributedString);
}

WebFrame* TextInputController::getMainFrame()
{
return testShell->webView()->mainFrame();
}

void TextInputController::insertText(const CppArgumentList& arguments, CppVariant* result)
{
result->setNull();

WebFrame* mainFrame = getMainFrame();
if (!mainFrame)
return;
if (arguments.size() < 1 || !arguments[0].isString())
return;

if (mainFrame->hasMarkedText()) {
mainFrame->unmarkText();
mainFrame->replaceSelection(WebString());
}
mainFrame->insertText(WebString::fromUTF8(arguments[0].toString()));
}

void TextInputController::doCommand(const CppArgumentList& arguments, CppVariant* result)
{
result->setNull();

WebFrame* mainFrame = getMainFrame();
if (!mainFrame)
return;

if (arguments.size() >= 1 && arguments[0].isString())
mainFrame->executeCommand(WebString::fromUTF8(arguments[0].toString()));
}

void TextInputController::setMarkedText(const CppArgumentList& arguments, CppVariant* result)
{
result->setNull();

WebFrame* mainFrame = getMainFrame();
if (!mainFrame)
return;

if (arguments.size() >= 3 && arguments[0].isString()
&& arguments[1].isNumber() && arguments[2].isNumber()) {
mainFrame->setMarkedText(WebString::fromUTF8(arguments[0].toString()),
arguments[1].toInt32(),
arguments[2].toInt32());
}
}

void TextInputController::unmarkText(const CppArgumentList&, CppVariant* result)
{
result->setNull();

WebFrame* mainFrame = getMainFrame();
if (!mainFrame)
return;

mainFrame->unmarkText();
}

void TextInputController::hasMarkedText(const CppArgumentList&, CppVariant* result)
{
result->setNull();

WebFrame* mainFrame = getMainFrame();
if (!mainFrame)
return;

result->set(mainFrame->hasMarkedText());
}

void TextInputController::conversationIdentifier(const CppArgumentList&, CppVariant* result)
{
// FIXME: Implement this.
result->setNull();
}

void TextInputController::substringFromRange(const CppArgumentList&, CppVariant* result)
{
// FIXME: Implement this.
result->setNull();
}

void TextInputController::attributedSubstringFromRange(const CppArgumentList&, CppVariant* result)
{
// FIXME: Implement this.
result->setNull();
}

void TextInputController::markedRange(const CppArgumentList&, CppVariant* result)
{
result->setNull();

WebFrame* mainFrame = getMainFrame();
if (!mainFrame)
return;

WebRange range = mainFrame->markedRange();
result->set(StringPrintf("%d,%d", range.startOffset(), range.endOffset()));
}

void TextInputController::selectedRange(const CppArgumentList&, CppVariant* result)
{
result->setNull();

WebFrame* mainFrame = getMainFrame();
if (!mainFrame)
return;

WebRange range = mainFrame->selectionRange();
result->set(StringPrintf("%d,%d", range.startOffset(), range.endOffset()));
}

void TextInputController::firstRectForCharacterRange(const CppArgumentList&, CppVariant* result)
{
// FIXME: Implement this.
result->setNull();
}

void TextInputController::characterIndexForPoint(const CppArgumentList&, CppVariant* result)
{
// FIXME: Implement this.
result->setNull();
}

void TextInputController::validAttributesForMarkedText(const CppArgumentList&, CppVariant* result)
{
result->setNull();

WebFrame* mainFrame = getMainFrame();
if (!mainFrame)
return;

result->set("NSUnderline,NSUnderlineColor,NSMarkedClauseSegment,"
"NSTextInputReplacementRangeAttributeName");
}

void TextInputController::makeAttributedString(const CppArgumentList&, CppVariant* result)
{
// FIXME: Implement this.
result->setNull();
}

0 comments on commit cf0428d

Please sign in to comment.