summaryrefslogtreecommitdiffstats
path: root/webkit/glue/cpp_binding_example.cc
diff options
context:
space:
mode:
authordglazkov@chromium.org <dglazkov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-13 20:16:34 +0000
committerdglazkov@chromium.org <dglazkov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-13 20:16:34 +0000
commit55a75d99c6609ed4f6dc7052fcf3d907efaf7137 (patch)
tree39a50ac51abdbee695ce494cfecefbbebfb38248 /webkit/glue/cpp_binding_example.cc
parent4eeb018cc6f4b3a1d6715facaa3a3c54a22b4951 (diff)
downloadchromium_src-55a75d99c6609ed4f6dc7052fcf3d907efaf7137.zip
chromium_src-55a75d99c6609ed4f6dc7052fcf3d907efaf7137.tar.gz
chromium_src-55a75d99c6609ed4f6dc7052fcf3d907efaf7137.tar.bz2
Implement getter/setter-based bound properties for CppBoundClass.
This is necessary for AccessibilityController, which has non-trivial property accessors. R=darin BUG=10322 TEST=CppBoundClassTest.SetAndGetPropertiesWithCallbacks Review URL: http://codereview.chromium.org/243064 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28872 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/cpp_binding_example.cc')
-rw-r--r--webkit/glue/cpp_binding_example.cc33
1 files changed, 31 insertions, 2 deletions
diff --git a/webkit/glue/cpp_binding_example.cc b/webkit/glue/cpp_binding_example.cc
index b71ffd3..79e96e4 100644
--- a/webkit/glue/cpp_binding_example.cc
+++ b/webkit/glue/cpp_binding_example.cc
@@ -2,11 +2,31 @@
// 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 CppBindingExample, a usage example
-// that is not actually used anywhere. See cpp_binding_example.h.
+// This file contains the definition for CppBindingExample, which is used in
+// cpp_bound_class_unittest.
#include "cpp_binding_example.h"
+namespace {
+
+class PropertyCallbackExample : public CppBoundClass::PropertyCallback {
+ public:
+ virtual bool GetValue(CppVariant* value) {
+ value->Set(value_);
+ return true;
+ }
+
+ virtual bool SetValue(const CppVariant& value) {
+ value_.Set(value);
+ return true;
+ }
+
+ private:
+ CppVariant value_;
+};
+
+}
+
CppBindingExample::CppBindingExample() {
// Map properties. It's recommended, but not required, that the JavaScript
// names (used as the keys in this map) match the names of the member
@@ -14,6 +34,11 @@ CppBindingExample::CppBindingExample() {
BindProperty("my_value", &my_value);
BindProperty("my_other_value", &my_other_value);
+ // Bind property with a callback.
+ BindProperty("my_value_with_callback", new PropertyCallbackExample());
+ // Bind property with a getter callback.
+ BindProperty("same", &CppBindingExample::same);
+
// Map methods. See comment above about names.
BindMethod("echoValue", &CppBindingExample::echoValue);
BindMethod("echoType", &CppBindingExample::echoType);
@@ -88,6 +113,10 @@ void CppBindingExample::plus(const CppArgumentList& args,
result->Set(sum);
}
+void CppBindingExample::same(CppVariant* result) {
+ result->Set(42);
+}
+
void CppBindingExample::fallbackMethod(const CppArgumentList& args,
CppVariant* result) {
printf("Error: unknown JavaScript method invoked.\n");