diff options
author | rolandsteiner@chromium.org <rolandsteiner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-09 06:13:56 +0000 |
---|---|---|
committer | rolandsteiner@chromium.org <rolandsteiner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-09 06:13:56 +0000 |
commit | ad33fd4bdd8b7117e2644b34f553a2f14faea653 (patch) | |
tree | 39577ad11008a0ee24b25b86396079665c136944 | |
parent | 09f1e97c9849196d1675a81f5bb505544d085d53 (diff) | |
download | chromium_src-ad33fd4bdd8b7117e2644b34f553a2f14faea653.zip chromium_src-ad33fd4bdd8b7117e2644b34f553a2f14faea653.tar.gz chromium_src-ad33fd4bdd8b7117e2644b34f553a2f14faea653.tar.bz2 |
Commit issue 243032: First implementation of PlainTextController.
BUG=23285
TEST=LayoutTests/editing/text-iterator/basic-iteration.html
Review URL=http://codereview.chromium.org/243032
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31422 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | webkit/api/public/WebBindings.h | 5 | ||||
-rw-r--r-- | webkit/api/public/WebRange.h | 4 | ||||
-rw-r--r-- | webkit/api/src/WebBindings.cpp | 28 | ||||
-rw-r--r-- | webkit/api/src/WebRange.cpp | 11 | ||||
-rw-r--r-- | webkit/tools/layout_tests/test_expectations.txt | 2 | ||||
-rw-r--r-- | webkit/tools/test_shell/plain_text_controller.cc | 66 | ||||
-rw-r--r-- | webkit/tools/test_shell/plain_text_controller.h | 39 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell.cc | 8 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell.gyp | 2 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell.h | 8 |
10 files changed, 164 insertions, 9 deletions
diff --git a/webkit/api/public/WebBindings.h b/webkit/api/public/WebBindings.h index c8a00216..4e66a8f 100644 --- a/webkit/api/public/WebBindings.h +++ b/webkit/api/public/WebBindings.h @@ -37,6 +37,7 @@ namespace WebKit { class WebDragData; +class WebRange; // A haphazard collection of functions for dealing with plugins. class WebBindings { @@ -133,6 +134,10 @@ public: // data or event_id outputs, just confirm the given npobj is the current & accessible drag event. // This only works with V8. If compiled without V8, it'll always return false. WEBKIT_API static bool isDragEvent(NPObject* event); + + // Return true (success) if the given npobj is a range object. + // If so, return that range as a WebRange object. + WEBKIT_API static bool getRange(NPObject* range, WebRange*); }; } // namespace WebKit diff --git a/webkit/api/public/WebRange.h b/webkit/api/public/WebRange.h index 3f9bbbf..89fc8f6 100644 --- a/webkit/api/public/WebRange.h +++ b/webkit/api/public/WebRange.h @@ -42,6 +42,7 @@ namespace WebKit { class WebNode; class WebRangePrivate; +class WebString; // Provides readonly access to some properties of a DOM range. class WebRange { @@ -66,6 +67,9 @@ public: WEBKIT_API WebNode startContainer(int& exceptionCode) const; WEBKIT_API WebNode endContainer(int& exceptionCode) const; + WEBKIT_API WebString toHTMLText() const; + WEBKIT_API WebString toPlainText() const; + #if WEBKIT_IMPLEMENTATION WebRange(const WTF::PassRefPtr<WebCore::Range>&); WebRange& operator=(const WTF::PassRefPtr<WebCore::Range>&); diff --git a/webkit/api/src/WebBindings.cpp b/webkit/api/src/WebBindings.cpp index deedbdf..0bbb0ca 100644 --- a/webkit/api/src/WebBindings.cpp +++ b/webkit/api/src/WebBindings.cpp @@ -34,6 +34,7 @@ #include "npruntime_impl.h" #include "npruntime_priv.h" #include "webkit/api/public/WebDragData.h" +#include "webkit/api/public/WebRange.h" #if USE(V8) #include "ChromiumDataObject.h" @@ -41,6 +42,8 @@ #include "EventNames.h" #include "MouseEvent.h" #include "NPV8Object.h" // for PrivateIdentifier +#include "Range.h" +#include "V8DOMWrapper.h" #include "V8Helpers.h" #include "V8Proxy.h" #elif USE(JSC) @@ -273,6 +276,21 @@ static bool getDragDataImpl(NPObject* npobj, int* eventId, WebDragData* data) return dataObject != NULL; } +static bool getRangeImpl(NPObject* npobj, WebRange* range) +{ + V8NPObject* v8npobject = reinterpret_cast<V8NPObject*>(npobj); + v8::Handle<v8::Object> v8object(v8npobject->v8Object); + if (V8ClassIndex::RANGE != V8DOMWrapper::domWrapperType(v8object)) + return false; + + Range* native = V8DOMWrapper::convertToNativeObject<WebCore::Range>(V8ClassIndex::RANGE, v8object); + if (!native) + return false; + + *range = WebRange(native); + return true; +} + #endif bool WebBindings::getDragData(NPObject* event, int* eventId, WebDragData* data) @@ -291,4 +309,14 @@ bool WebBindings::isDragEvent(NPObject* event) return getDragData(event, &eventId, NULL); } +bool WebBindings::getRange(NPObject* range, WebRange* webrange) +{ +#if USE(V8) + return getRangeImpl(range, webrange); +#else + // Not supported on other ports (JSC, etc). + return false; +#endif +} + } // namespace WebKit diff --git a/webkit/api/src/WebRange.cpp b/webkit/api/src/WebRange.cpp index ea1f168..bf5ce64 100644 --- a/webkit/api/src/WebRange.cpp +++ b/webkit/api/src/WebRange.cpp @@ -32,6 +32,7 @@ #include "WebRange.h" #include "WebNode.h" +#include "WebString.h" #include "Range.h" #include <wtf/PassRefPtr.h> @@ -76,6 +77,16 @@ WebNode WebRange::endContainer(int& exceptionCode) const return PassRefPtr<Node>(m_private->endContainer(exceptionCode)); } +WebString WebRange::toHTMLText() const +{ + return m_private->toHTML(); +} + +WebString WebRange::toPlainText() const +{ + return m_private->text(); +} + WebRange::WebRange(const WTF::PassRefPtr<WebCore::Range>& range) : m_private(static_cast<WebRangePrivate*>(range.releaseRef())) { diff --git a/webkit/tools/layout_tests/test_expectations.txt b/webkit/tools/layout_tests/test_expectations.txt index 1e781dc..5907f17 100644 --- a/webkit/tools/layout_tests/test_expectations.txt +++ b/webkit/tools/layout_tests/test_expectations.txt @@ -2607,8 +2607,6 @@ BUG11251 WIN LINUX : LayoutTests/fast/forms/textarea-metrics.html = FAIL // Unimplemented test shell features causing editing tests to fail -// window.plainText not implemented -BUG23285 : LayoutTests/editing/text-iterator/basic-iteration.html = FAIL // We don't draw the spelling markers at all in test shell. BUG11577 WIN LINUX : LayoutTests/editing/spelling/inline_spelling_markers.html = FAIL BUG11577 LINUX : LayoutTests/editing/spelling/spellcheck-attribute.html = FAIL diff --git a/webkit/tools/test_shell/plain_text_controller.cc b/webkit/tools/test_shell/plain_text_controller.cc new file mode 100644 index 0000000..954a670 --- /dev/null +++ b/webkit/tools/test_shell/plain_text_controller.cc @@ -0,0 +1,66 @@ +// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This file contains the definition for PlainTextController. + +#include "webkit/tools/test_shell/plain_text_controller.h" +#include "webkit/tools/test_shell/test_shell.h" + +#include "webkit/api/public/WebBindings.h" +#include "webkit/api/public/WebRange.h" +#include "webkit/api/public/WebString.h" + +using WebKit::WebBindings; +using WebKit::WebRange; +using WebKit::WebString; + +TestShell* PlainTextController::shell_ = NULL; + +PlainTextController::PlainTextController(TestShell* shell) { + // Set static shell_ variable. + if (!shell_) + shell_ = shell; + + // 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 EventSendingController). + BindMethod("plainText", &PlainTextController::plainText); + + // The fallback method is called when an unknown method is invoked. + BindFallbackMethod(&PlainTextController::fallbackMethod); +} + +void PlainTextController::plainText( + const CppArgumentList& args, CppVariant* result) { + result->SetNull(); + + if (args.size() < 1 || !args[0].isObject()) + return; + + // Check that passed-in object is, in fact, a range. + NPObject* npobject = NPVARIANT_TO_OBJECT(args[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& args, CppVariant* result) { + std::wstring message( + L"JavaScript ERROR: unknown method called on PlainTextController"); + if (!shell_->layout_test_mode()) { + logging::LogMessage("CONSOLE:", 0).stream() << message; + } else { + printf("CONSOLE MESSAGE: %S\n", message.c_str()); + } + result->SetNull(); +} + diff --git a/webkit/tools/test_shell/plain_text_controller.h b/webkit/tools/test_shell/plain_text_controller.h new file mode 100644 index 0000000..737b275 --- /dev/null +++ b/webkit/tools/test_shell/plain_text_controller.h @@ -0,0 +1,39 @@ +// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// PlainTextController class: +// Bound to a JavaScript window.plainText object using +// CppBoundClass::BindToJavascript(), this allows layout tests that are run in +// the test_shell to extract plain text from the DOM or the selection. +// +// The OSX reference file is in +// WebKit/WebKitTools/DumpRenderTree/PlainTextController.mm + +#ifndef WEBKIT_TOOLS_TEST_SHELL_PLAIN_TEXT_CONTROLLER_H_ +#define WEBKIT_TOOLS_TEST_SHELL_PLAIN_TEXT_CONTROLLER_H_ + +#include "build/build_config.h" +#include "webkit/glue/cpp_bound_class.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(TestShell* shell); + + // JS callback methods. + void plainText(const CppArgumentList& args, CppVariant* result); + + // Fall-back method: called if an unknown method is invoked. + void fallbackMethod(const CppArgumentList& args, CppVariant* result); + + private: + // Non-owning pointer. The LayoutTestController is owned by the host. + static TestShell* shell_; +}; + +#endif // WEBKIT_TOOLS_TEST_SHELL_PLAIN_TEXT_CONTROLLER_H_ + diff --git a/webkit/tools/test_shell/test_shell.cc b/webkit/tools/test_shell/test_shell.cc index 1888202..d4a974d 100644 --- a/webkit/tools/test_shell/test_shell.cc +++ b/webkit/tools/test_shell/test_shell.cc @@ -122,6 +122,7 @@ TestShell::TestShell() popup_delegate_.reset(new TestWebViewDelegate(this)); layout_test_controller_.reset(new LayoutTestController(this)); event_sending_controller_.reset(new EventSendingController(this)); + plain_text_controller_.reset(new PlainTextController(this)); text_input_controller_.reset(new TextInputController(this)); navigation_controller_.reset(new TestNavigationController(this)); @@ -153,7 +154,7 @@ TestShell::~TestShell() { printf("<stats>\n"); if (table != NULL) { int counter_max = table->GetMaxCounters(); - for (int index=0; index < counter_max; index++) { + for (int index = 0; index < counter_max; index++) { std::string name(table->GetRowName(index)); if (name.length() > 0) { int value = table->GetRowValue(index); @@ -466,6 +467,7 @@ void TestShell::BindJSObjectsToWindow(WebFrame* frame) { frame, L"accessibilityController"); layout_test_controller_->BindToJavascript(frame, L"layoutTestController"); event_sending_controller_->BindToJavascript(frame, L"eventSender"); + plain_text_controller_->BindToJavascript(frame, L"plainText"); text_input_controller_->BindToJavascript(frame, L"textInputController"); } } @@ -565,11 +567,11 @@ bool TestShell::Navigate(const TestNavigationEntry& entry, bool reload) { if (reload) { frame->reload(); } else if (!entry.GetContentState().empty()) { - DCHECK(entry.GetPageID() != -1); + DCHECK_NE(entry.GetPageID(), -1); frame->loadHistoryItem( webkit_glue::HistoryItemFromString(entry.GetContentState())); } else { - DCHECK(entry.GetPageID() == -1); + DCHECK_EQ(entry.GetPageID(), -1); frame->loadRequest(WebURLRequest(entry.GetURL())); } diff --git a/webkit/tools/test_shell/test_shell.gyp b/webkit/tools/test_shell/test_shell.gyp index c05a9f2..3d16f49 100644 --- a/webkit/tools/test_shell/test_shell.gyp +++ b/webkit/tools/test_shell/test_shell.gyp @@ -67,6 +67,8 @@ 'layout_test_controller.h', 'mock_webclipboard_impl.cc', 'mock_webclipboard_impl.h', + 'plain_text_controller.cc', + 'plain_text_controller.h', 'resource.h', 'simple_appcache_system.cc', 'simple_appcache_system.h', diff --git a/webkit/tools/test_shell/test_shell.h b/webkit/tools/test_shell/test_shell.h index 6f1e06c..9f5c124 100644 --- a/webkit/tools/test_shell/test_shell.h +++ b/webkit/tools/test_shell/test_shell.h @@ -39,6 +39,7 @@ #include "base/ref_counted.h" #include "webkit/tools/test_shell/event_sending_controller.h" #include "webkit/tools/test_shell/layout_test_controller.h" +#include "webkit/tools/test_shell/plain_text_controller.h" #include "webkit/tools/test_shell/text_input_controller.h" #include "webkit/tools/test_shell/test_webview_delegate.h" #include "webkit/tools/test_shell/webview_host.h" @@ -335,11 +336,9 @@ private: scoped_ptr<AccessibilityController> accessibility_controller_; scoped_ptr<LayoutTestController> layout_test_controller_; - scoped_ptr<EventSendingController> event_sending_controller_; - + scoped_ptr<PlainTextController> plain_text_controller_; scoped_ptr<TextInputController> text_input_controller_; - scoped_ptr<TestNavigationController> navigation_controller_; scoped_ptr<TestWebViewDelegate> delegate_; @@ -368,4 +367,5 @@ private: bool dump_stats_table_on_exit_; }; -#endif // WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_H_ +#endif // WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_H_ + |