diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ccf7a7..9ae66c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -132,7 +132,7 @@ set(SOURCES src/application_cache.cc if ($ENV{ENABLE_EMSCRIPTEN}) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Oz -g -std=c++11 --memory-init-file 0 --llvm-lto 1 --bind -s DEMANGLE_SUPPORT=1 -s WASM=0 -s NO_FILESYSTEM=1 -DENABLE_EMSCRIPTEN=1 -DPROPERTY_TRACE=1") - add_library(html5 STATIC bind.cc ${SOURCES}) + add_library(html5 STATIC ${SOURCES}) else() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g -std=c++11") add_library(html5 STATIC ${SOURCES}) diff --git a/bind.cc b/bind.cc deleted file mode 100644 index 63d3729..0000000 --- a/bind.cc +++ /dev/null @@ -1,24 +0,0 @@ -#include "libhtml5.h" -#include "class.h" - -USING_NAMESPACE_HTML5; - -static emscripten::val toString(intptr_t ptr) -{ - return emscripten::val(std::string((char *)ptr)); -} - -static bool g_initialized = false; - -void HTML5_INIT() -{ - if (g_initialized) return; - - window = Window::create(); - window->retain(); - g_initialized = true; -} - -EMSCRIPTEN_BINDINGS(html5) { - function("toString", &toString, emscripten::allow_raw_pointers()); -} diff --git a/examples/array.cc b/examples/array.cc index 88543b1..ca23822 100644 --- a/examples/array.cc +++ b/examples/array.cc @@ -1,11 +1,8 @@ #include "libhtml5.h" -#include "class.h" #include static void arrayTest() { - HTML5_INIT(); - html5::array subarray; html5::array array = { 1, M_PI, "hello", subarray, html5::Object::create(), diff --git a/examples/image.cc b/examples/image.cc index 3a826a0..e14c6df 100644 --- a/examples/image.cc +++ b/examples/image.cc @@ -1,17 +1,15 @@ #include "libhtml5.h" -#include "class.h" #include static void createImage(std::string url) { - HTML5_INIT(); for (html5::StyleSheet *sheet : *html5::window->document->styleSheets) { html5::window->console->log(sheet); } html5::HTMLImageElement *image = html5::HTMLImageElement::create(); static html5::EventHandler onload = [image](html5::Event *e){ - html5::window->console->trace(); std::cout << "callback. onload" << std::endl; + html5::window->console->trace(); std::cout << "width = " << image->width << std::endl; std::cout << "height = " << image->height << std::endl; std::cout << "naturalWidth = " << image->naturalWidth << std::endl; diff --git a/examples/promise.cc b/examples/promise.cc index b8fbd27..1a2ede3 100644 --- a/examples/promise.cc +++ b/examples/promise.cc @@ -1,10 +1,7 @@ #include "libhtml5.h" -#include "class.h" static void promiseTest() { - HTML5_INIT(); - auto promise = html5::Promise::create([](std::function resolve, std::function reject) { html5::window->setTimeout([resolve](){ resolve("foo"); }, 300); }); @@ -20,7 +17,6 @@ static void promiseTest() static void fetchImageTest(const std::string &imageURL) { - HTML5_INIT(); html5::fetch(imageURL)->then([](html5::Response *response) { return response->blob(); })->then([](html5::Blob *blob) { diff --git a/examples/string.cc b/examples/string.cc index e1af411..fb8ef83 100644 --- a/examples/string.cc +++ b/examples/string.cc @@ -1,10 +1,7 @@ #include "libhtml5.h" -#include "class.h" static void stringTest() { - HTML5_INIT(); - { html5::string s = "hello world"; std::cout << s << std::endl; diff --git a/examples/style_sheet.cc b/examples/style_sheet.cc index 8a08bff..0b9f7b3 100644 --- a/examples/style_sheet.cc +++ b/examples/style_sheet.cc @@ -1,12 +1,9 @@ #include "libhtml5.h" -#include "class.h" #include using namespace html5; static void addStyleSheet() { - HTML5_INIT(); - auto document = window->document; auto sheets = window->document->styleSheets; if (sheets->length == 0) { diff --git a/examples/test_exec.cc b/examples/test_exec.cc index e8ad15a..bcf470e 100644 --- a/examples/test_exec.cc +++ b/examples/test_exec.cc @@ -1,5 +1,4 @@ #include "libhtml5.h" -#include "class.h" #include "image.cc" #include "style_sheet.cc" diff --git a/examples/video.cc b/examples/video.cc index 4f342a2..31fcd9b 100644 --- a/examples/video.cc +++ b/examples/video.cc @@ -1,10 +1,8 @@ #include "libhtml5.h" -#include "class.h" #include static void createVideo(std::string url) { - HTML5_INIT(); html5::HTMLVideoElement *video = html5::HTMLVideoElement::create(); html5::HTMLSourceElement *source = html5::HTMLSourceElement::create(); source->src = url; diff --git a/include/array_buffer.h b/include/array_buffer.h index 69f9c1f..3dcaf72 100644 --- a/include/array_buffer.h +++ b/include/array_buffer.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/array_buffer_view.h b/include/array_buffer_view.h index 2f5921d..0e1530d 100644 --- a/include/array_buffer_view.h +++ b/include/array_buffer_view.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/attr.h b/include/attr.h index 14b55f7..6de6202 100644 --- a/include/attr.h +++ b/include/attr.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/audio_track.h b/include/audio_track.h index b511355..1549d49 100644 --- a/include/audio_track.h +++ b/include/audio_track.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/auto_release_pool.h b/include/auto_release_pool.h index 8552a54..8199fa2 100644 --- a/include/auto_release_pool.h +++ b/include/auto_release_pool.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" #include NAMESPACE_HTML5_BEGIN; diff --git a/include/bar_prop.h b/include/bar_prop.h index 2fd367b..f9707fc 100644 --- a/include/bar_prop.h +++ b/include/bar_prop.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/blob.h b/include/blob.h index cd70ae7..e707d38 100644 --- a/include/blob.h +++ b/include/blob.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/canvas_gradient.h b/include/canvas_gradient.h index 12ca8e4..d77d0a2 100644 --- a/include/canvas_gradient.h +++ b/include/canvas_gradient.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/canvas_pattern.h b/include/canvas_pattern.h index 09c235e..424fa4d 100644 --- a/include/canvas_pattern.h +++ b/include/canvas_pattern.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/console.h b/include/console.h index 7db005b..419e57b 100644 --- a/include/console.h +++ b/include/console.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" #include "html5_string.h" #include "array.h" diff --git a/include/css_rule.h b/include/css_rule.h index 9b3eaf6..e3b8542 100644 --- a/include/css_rule.h +++ b/include/css_rule.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/css_rule_list.h b/include/css_rule_list.h index 34cfc77..0054d9e 100644 --- a/include/css_rule_list.h +++ b/include/css_rule_list.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/css_style_declaration.h b/include/css_style_declaration.h index 7f27a3c..06363bd 100644 --- a/include/css_style_declaration.h +++ b/include/css_style_declaration.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/date.h b/include/date.h index 257136f..f6b9a35 100644 --- a/include/date.h +++ b/include/date.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/document.h b/include/document.h index 52ec162..a4cc783 100644 --- a/include/document.h +++ b/include/document.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" #include "node.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/document_type.h b/include/document_type.h index 66e0c5d..b95eb76 100644 --- a/include/document_type.h +++ b/include/document_type.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/dom_error.h b/include/dom_error.h index bcc0ab7..d7caa5f 100644 --- a/include/dom_error.h +++ b/include/dom_error.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/dom_implementation.h b/include/dom_implementation.h index 396b573..5fb0322 100644 --- a/include/dom_implementation.h +++ b/include/dom_implementation.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/dom_token_list.h b/include/dom_token_list.h index 1e075fa..3b80158 100644 --- a/include/dom_token_list.h +++ b/include/dom_token_list.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" #include NAMESPACE_HTML5_BEGIN; diff --git a/include/event.h b/include/event.h index 5dbd560..9c6eaf3 100644 --- a/include/event.h +++ b/include/event.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" #include NAMESPACE_HTML5_BEGIN; diff --git a/include/event_target.h b/include/event_target.h index a4c0c5c..cef65a9 100644 --- a/include/event_target.h +++ b/include/event_target.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" #include #include diff --git a/include/export.h b/include/export.h index 23e523f..95bd665 100644 --- a/include/export.h +++ b/include/export.h @@ -33,8 +33,6 @@ class Performance; class WindowProxy; class Console; -extern Window *window; - extern void alert(std::string message); extern std::string atob(std::string atob); extern void blur(); @@ -65,5 +63,3 @@ extern long setTimeout(std::function *handler, long timeout); extern void stop(); NAMESPACE_HTML5_END; - -extern void HTML5_INIT(); diff --git a/include/external.h b/include/external.h index 056ac09..f918ccb 100644 --- a/include/external.h +++ b/include/external.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/history.h b/include/history.h index d095361..b0d777b 100644 --- a/include/history.h +++ b/include/history.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/hit_region_options.h b/include/hit_region_options.h index 159aacf..e0f80d2 100644 --- a/include/hit_region_options.h +++ b/include/hit_region_options.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" #include "canvas_fill_rule.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/html5.h b/include/html5.h new file mode 100644 index 0000000..ac8e254 --- /dev/null +++ b/include/html5.h @@ -0,0 +1,480 @@ +#pragma once + +#define NAMESPACE_HTML5_BEGIN namespace html5 { +#define NAMESPACE_HTML5_END } +#define USING_NAMESPACE_HTML5 using namespace html5 + +#include + +#if PROPERTY_TRACE + +#include + +#define HTML5_PROPERTY_TRACE_PRINT(prefix, content) (std::cout << prefix << " " << content << std::endl) + +#else + +#define HTML5_PROPERTY_TRACE_PRINT(prefix, content) + +#endif + + +#if ENABLE_EMSCRIPTEN + +#include +#include +#include + +#include "object.h" + +#define GL_GLEXT_PROTOTYPES +#include +#include + +#define HTML5_STATIC_PRIMITIVE_INSTANCE(type, ...) (emscripten::val::global(#type)) +#define HTML5_NEW_PRIMITIVE_INSTANCE(type, ...) (emscripten::val::global(#type).new_(__VA_ARGS__)) + +inline std::string __html5_val_to_string__(emscripten::val v) +{ + if (v == emscripten::val::null()) { + return ""; + } else if (v == emscripten::val::undefined()) { + return ""; + } + return v.as(); +} + +template T __html5_property_get__(std::string o, emscripten::val v) +{ + return __html5_val_to_string__(v); +} + +template T *__html5_property_get__(html5::NativeObject *o, emscripten::val v) +{ + if (v == emscripten::val::null()) { + return nullptr; + } else if (v == emscripten::val::undefined()) { + return nullptr; + } + return T::create(v); +} + +template T __html5_property_get__(T o, emscripten::val v) +{ + return v.as(); +} + +#define HTML5_PROPERTY_GET(pname, type) (__html5_property_get__(this->_ ## pname, this->v[#pname])) + +#define HTML5_CALL(v, method, ...) v.call(#method, ## __VA_ARGS__) +#define HTML5_CALLi(v, method, rtype, ...) v.call(#method, ## __VA_ARGS__) +#define HTML5_CALLf(v, method, rtype, ...) v.call(#method, ## __VA_ARGS__) +#define HTML5_CALLb(v, method, ...) v.call(#method, ## __VA_ARGS__) +#define HTML5_CALLs(v, method, ...) __html5_val_to_string__(v.call(#method, ## __VA_ARGS__)) +#define HTML5_CALLv(v, method, ...) v.call(#method, ## __VA_ARGS__) + +template emscripten::val toJSArray(std::vector array) +{ + emscripten::val v = emscripten::val::array(); + for (size_t i = 0; i < array.size(); i++) { + v.set(i, array[i]); + } + return v; +} + +template std::vector toArray(emscripten::val v) +{ + return emscripten::vecFromJSArray(v); +} + +template std::vector toObjectArray(emscripten::val v) +{ + std::vector ret; + std::vector arr = emscripten::vecFromJSArray(v); + for (size_t i = 0; arr.size(); i++) { + ret.push_back(T::create(arr[i])); + } + return ret; +} + +#define __to_text__(text) #text + +#define HTML5_BIND_CLASS(klassname) \ + static klassname *to ## klassname(intptr_t ptr) \ + { \ + return (klassname *)ptr; \ + } \ + static emscripten::class_ klass = emscripten::class_(#klassname); \ + EMSCRIPTEN_BINDINGS(klassname ## _to ## klassname) { function(__to_text__(to ## klassname), &to ## klassname, emscripten::allow_raw_pointers()); } \ + EMSCRIPTEN_BINDINGS(klassname ## _getsetValue) { klass.property("_value", &klassname::getValue, &klassname::setValue); } + +#define HTML5_BIND_METHOD(klassname, method) EMSCRIPTEN_BINDINGS(klassname ## method) { klass.function(#method, &klassname::method); } + +#else + +#if defined __APPLE__ + +#include + +#endif + +namespace emscripten { + + class val { + public: + void set(std::string name, double value) {}; + void set(std::string name, std::string value) {}; + void set(std::string name, val value) {}; + void set(size_t index, double value) {}; + void set(size_t index, std::string value) {}; + void set(size_t index, val value) {}; + }; + +}; + +#include "object.h" + +#define EM_ASM_(block, ...) +#define EM_ASM_INT(block, ...) (0) + +#define HTML5_STATIC_PRIMITIVE_INSTANCE(type, ...) emscripten::val() +#define HTML5_NEW_PRIMITIVE_INSTANCE(type, ...) emscripten::val() +#define HTML5_PROPERTY_GET(pname, type) this->_ ## pname +#define HTML5_CALL(v, method, ...) +#define HTML5_CALLi(v, method, rtype, ...) (0) +#define HTML5_CALLf(v, method, rtype, ...) (0) +#define HTML5_CALLb(v, method, ...) (false) +#define HTML5_CALLs(v, method, ...) ("") +#define HTML5_CALLv(v, method, ...) emscripten::val() + +template emscripten::val toJSArray(std::vector array) +{ + return emscripten::val(); +} + +template std::vector toArray(emscripten::val v) +{ + std::vector ret; + return ret; +} + +template std::vector toObjectArray(emscripten::val v) +{ + std::vector ret; + return ret; +} + +#define HTML5_BIND_CLASS(klassname) +#define HTML5_BIND_METHOD(klassname, method) + +#endif + +#define HTML5_DELETE(o) do { \ + if (o) { \ + delete o; \ + o = NULL; \ + } \ + } while (0) + +#define HTML5_RELEASE(o) do { \ + if (o && o->isAutoRelease()) { \ + o->release(); \ + } else { \ + HTML5_DELETE(o); \ + } \ + } while (0) + +#define HTML5_PROPERTY_SET(pname, value) do { \ + this->_ ## pname = value; \ + this->v.set(#pname, value); \ + } while (0) + +#define HTML5_PROPERTY_OBJECT_SET(pname, value) do { \ + if (this->_ ## pname && this->_ ## pname->isAutoRelease()) { \ + this->_ ## pname->release(); \ + } \ + if (value && value->isAutoRelease()) { \ + value->retain(); \ + } \ + this->_ ## pname = value; \ + this->v.set(#pname, value->v); \ + } while (0) + +#define HTML5_CLASS_FACTORY(klass) static std::map> classFactories = + +#define HTML5_SUBCLASS_FACTORY(name) { #name, [](emscripten::val v){ auto klass = name::create(v); klass->autorelease(); return klass; } } + +#if ENABLE_EMSCRIPTEN + +#define HTML5_CREATE_IMPL(klass) \ + klass *klass::create(emscripten::val v) \ + { \ + std::string className = v["constructor"]["name"].as(); \ + if (className == #klass) { \ + klass *instance = new klass(v); \ + instance->autorelease(); \ + return instance; \ + } else if (classFactories.find(className) == classFactories.end()) { \ + std::cout << "cannot find " << className << " in classFactories" << std::endl; \ + return nullptr; \ + } \ + return classFactories[className](v); \ + } + +#else + +#define HTML5_CREATE_IMPL(klass) \ + klass *klass::create(emscripten::val v) \ + { \ + klass *e = new klass(v); \ + e->autorelease(); \ + return e; \ + } + +#endif + +#define HTML5_PROPERTY(klass, type, name) \ + type _ ## name; \ + struct { \ + klass &self; \ + void operator=(type value) { self.set_ ## name(value); }; \ + operator type() { return self.get_ ## name(); }; \ + } name{*this}; \ + type get_ ## name() const; \ + void set_ ## name(type value); + +#define HTML5_READONLY_PROPERTY(klass, type, name) \ + type _ ## name; \ + struct { \ + klass &self; \ + operator type() { return self.get_ ## name(); }; \ + } name{*this}; \ + type get_ ## name() const; + +#define HTML5_PROPERTY_OBJECT(klass, type, name) \ + type *_ ## name; \ + struct { \ + klass &self; \ + void operator=(type *value) { self.set_ ## name(value); }; \ + operator type*() { return self.get_ ## name(); }; \ + type *operator->() { return self.get_ ## name(); }; \ + } name{*this}; \ + type *get_ ## name() const; \ + void set_ ## name(type *value); + +#define HTML5_READONLY_PROPERTY_OBJECT(klass, type, name) \ + type *_ ## name; \ + struct { \ + klass &self; \ + operator type*() { return self.get_ ## name(); }; \ + type *operator->() { return self.get_ ## name(); }; \ + } name{*this}; \ + type *get_ ## name() const; + +#define HTML5_VIRTUAL_PROPERTY(klass, type, name) \ + virtual type get_ ## name() const; \ + virtual void set_ ## name(type value); + +#define HTML5_VIRTUAL_READONLY_PROPERTY(klass, type, name) \ + virtual type get_ ## name() const; + +#define HTML5_VIRTUAL_PROPERTY_OBJECT(klass, type, name) \ + virtual type *get_ ## name() const; \ + virtual void set_ ## name(type *value); + +#define HTML5_VIRTUAL_READONLY_PROPERTY_OBJECT(klass, type, name) \ + virtual type *get_ ## name() const; + +#define HTML5_PURE_VIRTUAL_PROPERTY(klass, type, name) \ + type _ ## name; \ + struct { \ + klass &self; \ + void operator=(type value) { self.set_ ## name(value); }; \ + operator type() { return self.get_ ## name(); }; \ + } name{*this}; \ + type get_ ## name() const = 0; \ + void set_ ## name(type value) = 0; + +#define HTML5_PURE_VIRTUAL_PROPERTY_OBJECT(klass, type, name) \ + type *_ ## name; \ + struct { \ + klass &self; \ + void operator=(type *value) { self.set_ ## name(value); }; \ + operator type*() { return self.get_ ## name(); }; \ + type *operator->() { return self.get_ ## name(); }; \ + } name{*this}; \ + virtual type *get_ ## name() const = 0; \ + virtual void set_ ## name(type *value) = 0; + +#define HTML5_PURE_VIRTUAL_READONLY_PROPERTY(klass, type, name) \ + type _ ## name; \ + struct { \ + klass &self; \ + operator type() { return self.get_ ## name(); }; \ + } name{*this}; \ + virtual type get_ ## name() const = 0; + +#define HTML5_PURE_VIRTUAL_READONLY_PROPERTY_OBJECT(klass, type, name) \ + type *_ ## name; \ + struct { \ + klass &self; \ + operator type*() { return self.get_ ## name(); }; \ + } name{*this}; \ + virtual type *get_ ## name() const = 0; + +#define HTML5_EVENT_HANDLER_PROPERTY(klass, type, name) \ + HTML5_PROPERTY(klass, type, name); \ + void callback_ ## name(emscripten::val e); + +#define HTML5_ERROR_HANDLER_PROPERTY(klass, type, name) \ + HTML5_PROPERTY(klass, type, name); \ + void callback_ ## name(emscripten::val e, std::string source, unsigned long lineno, unsigned long colno, emscripten::val error); + +#define HTML5_PROPERTY_TRACE_GETTER(name) HTML5_PROPERTY_TRACE_PRINT("[property:getter]", #name) +#define HTML5_PROPERTY_TRACE_SETTER(name) HTML5_PROPERTY_TRACE_PRINT("[property:setter]", #name) + +#define HTML5_PROPERTY_IMPL(klass, type, name) \ + type klass::get_ ## name() const \ + { \ + HTML5_PROPERTY_TRACE_GETTER(name); \ + return HTML5_PROPERTY_GET(name, type); \ + } \ + \ + void klass::set_ ## name(type value) \ + { \ + HTML5_PROPERTY_TRACE_SETTER(name); \ + HTML5_PROPERTY_SET(name, value); \ + } + +#define HTML5_EVENT_HANDLER_PROPERTY_IMPL(klass, type, name) \ + type klass::get_ ## name() const \ + { \ + HTML5_PROPERTY_TRACE_GETTER(name); \ + return this->_ ## name; \ + } \ + \ + void klass::set_ ## name(type value) \ + { \ + HTML5_PROPERTY_TRACE_SETTER(name); \ + this->_ ## name = value; \ + const char *key = __to_text__(to ## klass); \ + const char *callbackFnName = __to_text__(callback_ ## name); \ + EM_ASM_({ \ + var key = Pointer_stringify($1); \ + var callbackFnName = Pointer_stringify($2); \ + var elem = Module[key]($0); \ + elem['_value'][#name] = function(e) { elem[callbackFnName](e); }; \ + }, this, key, callbackFnName); \ + } \ + void klass::callback_ ## name(emscripten::val e) \ + { \ + if (!this->_ ## name) return; \ + (*this->_ ## name)(Event::create(e)); \ + } \ + HTML5_BIND_METHOD(klass, callback_ ## name); + +#define HTML5_EVENT_HANDLER_PROPERTY_IMPL_NEW(klass, type, name) \ + type klass::get_ ## name() const \ + { \ + HTML5_PROPERTY_TRACE_GETTER(name); \ + return this->_ ## name; \ + } \ + \ + void klass::set_ ## name(type value) \ + { \ + HTML5_PROPERTY_TRACE_SETTER(name); \ + this->_ ## name = value; \ + const char *key = __to_text__(to ## klass); \ + const char *callbackFnName = __to_text__(callback_ ## name); \ + EM_ASM_({ \ + var key = Pointer_stringify($1); \ + var callbackFnName = Pointer_stringify($2); \ + var elem = Module[key]($0); \ + elem['_value'][#name] = function(e) { elem[callbackFnName](e); }; \ + }, this, key, callbackFnName); \ + } \ + void klass::callback_ ## name(emscripten::val e) \ + { \ + if (!this->_ ## name) return; \ + (this->_ ## name)(Event::create(e)); \ + } \ + HTML5_BIND_METHOD(klass, callback_ ## name); + +#define HTML5_ERROR_HANDLER_PROPERTY_IMPL(klass, type, name) \ + type klass::get_ ## name() const \ + { \ + HTML5_PROPERTY_TRACE_GETTER(name); \ + return this->_ ## name; \ + } \ + \ + void klass::set_ ## name(type value) \ + { \ + HTML5_PROPERTY_TRACE_SETTER(name); \ + this->_ ## name = value; \ + const char *key = __to_text__(to ## klass); \ + const char *callbackFnName = __to_text__(callback_ ## name); \ + EM_ASM_({ \ + var key = Pointer_stringify($1); \ + var callbackFnName = Pointer_stringify($2); \ + var elem = Module[key]($0); \ + elem['_value'][#name] = function(event, source, lineno, colno, error) { \ + elem[callbackFnName](event, source, lineno, colno, error); \ + }; \ + }, this, key, callbackFnName); \ + } \ + void klass::callback_ ## name(emscripten::val e, std::string source, unsigned long lineno, unsigned long colno, emscripten::val error) \ + { \ + if (!this->_ ## name) return; \ + (*this->_ ## name)(Event::create(e), source, lineno, colno, NULL); \ + } \ + HTML5_BIND_METHOD(klass, callback_ ## name); + + +#define HTML5_READONLY_PROPERTY_IMPL(klass, type, name) \ + type klass::get_ ## name() const \ + { \ + HTML5_PROPERTY_TRACE_GETTER(name); \ + return HTML5_PROPERTY_GET(name, type); \ + } + +#define HTML5_PROPERTY_OBJECT_IMPL(klass, type, name) \ + type *klass::get_ ## name() const \ + { \ + HTML5_PROPERTY_TRACE_GETTER(name); \ + return HTML5_PROPERTY_GET(name, type); \ + } \ + \ + void klass::set_ ## name(type *value) \ + { \ + HTML5_PROPERTY_TRACE_SETTER(name); \ + HTML5_PROPERTY_OBJECT_SET(name, value); \ + } + +#define HTML5_READONLY_PROPERTY_OBJECT_IMPL(klass, type, name) \ + type *klass::get_ ## name() const \ + { \ + HTML5_PROPERTY_TRACE_GETTER(name); \ + return HTML5_PROPERTY_GET(name, type); \ + } + +#define HTML5_DEFINE_ITERATOR(klass, subclass) \ + class iterator { \ + public: \ + iterator(klass *list, unsigned long index = 0) : \ + _list(list), \ + _index(index){}; \ + virtual ~iterator() {}; \ + subclass *operator*() { return this->_list->item(this->_index); }; \ + iterator& operator++() { \ + this->_index++; \ + return *this; \ + }; \ + bool operator!=(const iterator& v) { return this->_index != v._index; }; \ + private: \ + unsigned long _index; \ + klass *_list; \ + }; \ + iterator begin() { return iterator(this); }; \ + iterator end() { return iterator(this, this->length); }; \ + +#include "export.h" diff --git a/include/html_base_element.h b/include/html_base_element.h index dc42f5f..a5f38e5 100644 --- a/include/html_base_element.h +++ b/include/html_base_element.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" #include "html_element.h" NAMESPACE_HTML5_BEGIN; @@ -17,4 +17,4 @@ class HTMLBaseElement : public HTMLElement { }; -NAMESPACE_HTML5_END; \ No newline at end of file +NAMESPACE_HTML5_END; diff --git a/include/html_body_element.h b/include/html_body_element.h index 1735c49..df664b8 100644 --- a/include/html_body_element.h +++ b/include/html_body_element.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" #include "event_handler.h" #include "html_element.h" @@ -28,4 +28,4 @@ class HTMLBodyElement : public HTMLElement { static HTMLBodyElement *create(emscripten::val v); }; -NAMESPACE_HTML5_END; \ No newline at end of file +NAMESPACE_HTML5_END; diff --git a/include/html_canvas_element.h b/include/html_canvas_element.h index b46ba7c..cb90446 100644 --- a/include/html_canvas_element.h +++ b/include/html_canvas_element.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" #include "html_element.h" #include "rendering_context.h" diff --git a/include/html_collection.h b/include/html_collection.h index 00f5e19..088ee6b 100644 --- a/include/html_collection.h +++ b/include/html_collection.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/html_element.h b/include/html_element.h index 92bade6..1d22abe 100644 --- a/include/html_element.h +++ b/include/html_element.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" #include "element.h" #include "event_handler.h" #include diff --git a/include/html_menu_element.h b/include/html_menu_element.h index 8be121b..303a5bf 100644 --- a/include/html_menu_element.h +++ b/include/html_menu_element.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" #include "html_element.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/idb_environment.h b/include/idb_environment.h index 9a9ac70..5758501 100644 --- a/include/idb_environment.h +++ b/include/idb_environment.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/idb_factory.h b/include/idb_factory.h index 6bd4e70..25b5de0 100644 --- a/include/idb_factory.h +++ b/include/idb_factory.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/idb_index.h b/include/idb_index.h index 545fc6f..9a9134a 100644 --- a/include/idb_index.h +++ b/include/idb_index.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/idb_index_parameters.h b/include/idb_index_parameters.h index f0ebeb8..0004427 100644 --- a/include/idb_index_parameters.h +++ b/include/idb_index_parameters.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/idb_object_store.h b/include/idb_object_store.h index 7b406ac..f84d60f 100644 --- a/include/idb_object_store.h +++ b/include/idb_object_store.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/image_bitmap.h b/include/image_bitmap.h index 0e58e73..edf2518 100644 --- a/include/image_bitmap.h +++ b/include/image_bitmap.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/image_data.h b/include/image_data.h index 162817f..4ebbbb1 100644 --- a/include/image_data.h +++ b/include/image_data.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/libhtml5.h b/include/libhtml5.h index b08193d..0587a2b 100644 --- a/include/libhtml5.h +++ b/include/libhtml5.h @@ -1,480 +1,10 @@ #pragma once -#define NAMESPACE_HTML5_BEGIN namespace html5 { -#define NAMESPACE_HTML5_END } -#define USING_NAMESPACE_HTML5 using namespace html5 +#include "html5.h" +#include "class.h" -#include +NAMESPACE_HTML5_BEGIN; -#if PROPERTY_TRACE +extern Window *window; -#include - -#define HTML5_PROPERTY_TRACE_PRINT(prefix, content) (std::cout << prefix << " " << content << std::endl) - -#else - -#define HTML5_PROPERTY_TRACE_PRINT(prefix, content) - -#endif - - -#if ENABLE_EMSCRIPTEN - -#include -#include -#include - -#include "object.h" - -#define GL_GLEXT_PROTOTYPES -#include -#include - -#define HTML5_STATIC_PRIMITIVE_INSTANCE(type, ...) (emscripten::val::global(#type)) -#define HTML5_NEW_PRIMITIVE_INSTANCE(type, ...) (emscripten::val::global(#type).new_(__VA_ARGS__)) - -inline std::string __html5_val_to_string__(emscripten::val v) -{ - if (v == emscripten::val::null()) { - return ""; - } else if (v == emscripten::val::undefined()) { - return ""; - } - return v.as(); -} - -template T __html5_property_get__(std::string o, emscripten::val v) -{ - return __html5_val_to_string__(v); -} - -template T *__html5_property_get__(html5::NativeObject *o, emscripten::val v) -{ - if (v == emscripten::val::null()) { - return nullptr; - } else if (v == emscripten::val::undefined()) { - return nullptr; - } - return T::create(v); -} - -template T __html5_property_get__(T o, emscripten::val v) -{ - return v.as(); -} - -#define HTML5_PROPERTY_GET(pname, type) (__html5_property_get__(this->_ ## pname, this->v[#pname])) - -#define HTML5_CALL(v, method, ...) v.call(#method, ## __VA_ARGS__) -#define HTML5_CALLi(v, method, rtype, ...) v.call(#method, ## __VA_ARGS__) -#define HTML5_CALLf(v, method, rtype, ...) v.call(#method, ## __VA_ARGS__) -#define HTML5_CALLb(v, method, ...) v.call(#method, ## __VA_ARGS__) -#define HTML5_CALLs(v, method, ...) __html5_val_to_string__(v.call(#method, ## __VA_ARGS__)) -#define HTML5_CALLv(v, method, ...) v.call(#method, ## __VA_ARGS__) - -template emscripten::val toJSArray(std::vector array) -{ - emscripten::val v = emscripten::val::array(); - for (size_t i = 0; i < array.size(); i++) { - v.set(i, array[i]); - } - return v; -} - -template std::vector toArray(emscripten::val v) -{ - return emscripten::vecFromJSArray(v); -} - -template std::vector toObjectArray(emscripten::val v) -{ - std::vector ret; - std::vector arr = emscripten::vecFromJSArray(v); - for (size_t i = 0; arr.size(); i++) { - ret.push_back(T::create(arr[i])); - } - return ret; -} - -#define __to_text__(text) #text - -#define HTML5_BIND_CLASS(klassname) \ - static klassname *to ## klassname(intptr_t ptr) \ - { \ - return (klassname *)ptr; \ - } \ - static emscripten::class_ klass = emscripten::class_(#klassname); \ - EMSCRIPTEN_BINDINGS(klassname ## _to ## klassname) { function(__to_text__(to ## klassname), &to ## klassname, emscripten::allow_raw_pointers()); } \ - EMSCRIPTEN_BINDINGS(klassname ## _getsetValue) { klass.property("_value", &klassname::getValue, &klassname::setValue); } - -#define HTML5_BIND_METHOD(klassname, method) EMSCRIPTEN_BINDINGS(klassname ## method) { klass.function(#method, &klassname::method); } - -#else - -#if defined __APPLE__ - -#include - -#endif - -namespace emscripten { - - class val { - public: - void set(std::string name, double value) {}; - void set(std::string name, std::string value) {}; - void set(std::string name, val value) {}; - void set(size_t index, double value) {}; - void set(size_t index, std::string value) {}; - void set(size_t index, val value) {}; - }; - -}; - -#include "object.h" - -#define EM_ASM_(block, ...) -#define EM_ASM_INT(block, ...) (0) - -#define HTML5_STATIC_PRIMITIVE_INSTANCE(type, ...) emscripten::val() -#define HTML5_NEW_PRIMITIVE_INSTANCE(type, ...) emscripten::val() -#define HTML5_PROPERTY_GET(pname, type) this->_ ## pname -#define HTML5_CALL(v, method, ...) -#define HTML5_CALLi(v, method, rtype, ...) (0) -#define HTML5_CALLf(v, method, rtype, ...) (0) -#define HTML5_CALLb(v, method, ...) (false) -#define HTML5_CALLs(v, method, ...) ("") -#define HTML5_CALLv(v, method, ...) emscripten::val() - -template emscripten::val toJSArray(std::vector array) -{ - return emscripten::val(); -} - -template std::vector toArray(emscripten::val v) -{ - std::vector ret; - return ret; -} - -template std::vector toObjectArray(emscripten::val v) -{ - std::vector ret; - return ret; -} - -#define HTML5_BIND_CLASS(klassname) -#define HTML5_BIND_METHOD(klassname, method) - -#endif - -#define HTML5_DELETE(o) do { \ - if (o) { \ - delete o; \ - o = NULL; \ - } \ - } while (0) - -#define HTML5_RELEASE(o) do { \ - if (o && o->isAutoRelease()) { \ - o->release(); \ - } else { \ - HTML5_DELETE(o); \ - } \ - } while (0) - -#define HTML5_PROPERTY_SET(pname, value) do { \ - this->_ ## pname = value; \ - this->v.set(#pname, value); \ - } while (0) - -#define HTML5_PROPERTY_OBJECT_SET(pname, value) do { \ - if (this->_ ## pname && this->_ ## pname->isAutoRelease()) { \ - this->_ ## pname->release(); \ - } \ - if (value && value->isAutoRelease()) { \ - value->retain(); \ - } \ - this->_ ## pname = value; \ - this->v.set(#pname, value->v); \ - } while (0) - -#define HTML5_CLASS_FACTORY(klass) static std::map> classFactories = - -#define HTML5_SUBCLASS_FACTORY(name) { #name, [](emscripten::val v){ auto klass = name::create(v); klass->autorelease(); return klass; } } - -#if ENABLE_EMSCRIPTEN - -#define HTML5_CREATE_IMPL(klass) \ - klass *klass::create(emscripten::val v) \ - { \ - std::string className = v["constructor"]["name"].as(); \ - if (className == #klass) { \ - klass *instance = new klass(v); \ - instance->autorelease(); \ - return instance; \ - } else if (classFactories.find(className) == classFactories.end()) { \ - std::cout << "cannot find " << className << " in classFactories" << std::endl; \ - return nullptr; \ - } \ - return classFactories[className](v); \ - } - -#else - -#define HTML5_CREATE_IMPL(klass) \ - klass *klass::create(emscripten::val v) \ - { \ - klass *e = new klass(v); \ - e->autorelease(); \ - return e; \ - } - -#endif - -#define HTML5_PROPERTY(klass, type, name) \ - type _ ## name; \ - struct { \ - klass &self; \ - void operator=(type value) { self.set_ ## name(value); }; \ - operator type() { return self.get_ ## name(); }; \ - } name{*this}; \ - type get_ ## name() const; \ - void set_ ## name(type value); - -#define HTML5_READONLY_PROPERTY(klass, type, name) \ - type _ ## name; \ - struct { \ - klass &self; \ - operator type() { return self.get_ ## name(); }; \ - } name{*this}; \ - type get_ ## name() const; - -#define HTML5_PROPERTY_OBJECT(klass, type, name) \ - type *_ ## name; \ - struct { \ - klass &self; \ - void operator=(type *value) { self.set_ ## name(value); }; \ - operator type*() { return self.get_ ## name(); }; \ - type *operator->() { return self.get_ ## name(); }; \ - } name{*this}; \ - type *get_ ## name() const; \ - void set_ ## name(type *value); - -#define HTML5_READONLY_PROPERTY_OBJECT(klass, type, name) \ - type *_ ## name; \ - struct { \ - klass &self; \ - operator type*() { return self.get_ ## name(); }; \ - type *operator->() { return self.get_ ## name(); }; \ - } name{*this}; \ - type *get_ ## name() const; - -#define HTML5_VIRTUAL_PROPERTY(klass, type, name) \ - virtual type get_ ## name() const; \ - virtual void set_ ## name(type value); - -#define HTML5_VIRTUAL_READONLY_PROPERTY(klass, type, name) \ - virtual type get_ ## name() const; - -#define HTML5_VIRTUAL_PROPERTY_OBJECT(klass, type, name) \ - virtual type *get_ ## name() const; \ - virtual void set_ ## name(type *value); - -#define HTML5_VIRTUAL_READONLY_PROPERTY_OBJECT(klass, type, name) \ - virtual type *get_ ## name() const; - -#define HTML5_PURE_VIRTUAL_PROPERTY(klass, type, name) \ - type _ ## name; \ - struct { \ - klass &self; \ - void operator=(type value) { self.set_ ## name(value); }; \ - operator type() { return self.get_ ## name(); }; \ - } name{*this}; \ - type get_ ## name() const = 0; \ - void set_ ## name(type value) = 0; - -#define HTML5_PURE_VIRTUAL_PROPERTY_OBJECT(klass, type, name) \ - type *_ ## name; \ - struct { \ - klass &self; \ - void operator=(type *value) { self.set_ ## name(value); }; \ - operator type*() { return self.get_ ## name(); }; \ - type *operator->() { return self.get_ ## name(); }; \ - } name{*this}; \ - virtual type *get_ ## name() const = 0; \ - virtual void set_ ## name(type *value) = 0; - -#define HTML5_PURE_VIRTUAL_READONLY_PROPERTY(klass, type, name) \ - type _ ## name; \ - struct { \ - klass &self; \ - operator type() { return self.get_ ## name(); }; \ - } name{*this}; \ - virtual type get_ ## name() const = 0; - -#define HTML5_PURE_VIRTUAL_READONLY_PROPERTY_OBJECT(klass, type, name) \ - type *_ ## name; \ - struct { \ - klass &self; \ - operator type*() { return self.get_ ## name(); }; \ - } name{*this}; \ - virtual type *get_ ## name() const = 0; - -#define HTML5_EVENT_HANDLER_PROPERTY(klass, type, name) \ - HTML5_PROPERTY(klass, type, name); \ - void callback_ ## name(emscripten::val e); - -#define HTML5_ERROR_HANDLER_PROPERTY(klass, type, name) \ - HTML5_PROPERTY(klass, type, name); \ - void callback_ ## name(emscripten::val e, std::string source, unsigned long lineno, unsigned long colno, emscripten::val error); - -#define HTML5_PROPERTY_TRACE_GETTER(name) HTML5_PROPERTY_TRACE_PRINT("[property:getter]", #name) -#define HTML5_PROPERTY_TRACE_SETTER(name) HTML5_PROPERTY_TRACE_PRINT("[property:setter]", #name) - -#define HTML5_PROPERTY_IMPL(klass, type, name) \ - type klass::get_ ## name() const \ - { \ - HTML5_PROPERTY_TRACE_GETTER(name); \ - return HTML5_PROPERTY_GET(name, type); \ - } \ - \ - void klass::set_ ## name(type value) \ - { \ - HTML5_PROPERTY_TRACE_SETTER(name); \ - HTML5_PROPERTY_SET(name, value); \ - } - -#define HTML5_EVENT_HANDLER_PROPERTY_IMPL(klass, type, name) \ - type klass::get_ ## name() const \ - { \ - HTML5_PROPERTY_TRACE_GETTER(name); \ - return this->_ ## name; \ - } \ - \ - void klass::set_ ## name(type value) \ - { \ - HTML5_PROPERTY_TRACE_SETTER(name); \ - this->_ ## name = value; \ - const char *key = __to_text__(to ## klass); \ - const char *callbackFnName = __to_text__(callback_ ## name); \ - EM_ASM_({ \ - var key = Module['toString']($1); \ - var callbackFnName = Module['toString']($2); \ - var elem = Module[key]($0); \ - elem['_value'][#name] = function(e) { elem[callbackFnName](e); }; \ - }, this, key, callbackFnName); \ - } \ - void klass::callback_ ## name(emscripten::val e) \ - { \ - if (!this->_ ## name) return; \ - (*this->_ ## name)(Event::create(e)); \ - } \ - HTML5_BIND_METHOD(klass, callback_ ## name); - -#define HTML5_EVENT_HANDLER_PROPERTY_IMPL_NEW(klass, type, name) \ - type klass::get_ ## name() const \ - { \ - HTML5_PROPERTY_TRACE_GETTER(name); \ - return this->_ ## name; \ - } \ - \ - void klass::set_ ## name(type value) \ - { \ - HTML5_PROPERTY_TRACE_SETTER(name); \ - this->_ ## name = value; \ - const char *key = __to_text__(to ## klass); \ - const char *callbackFnName = __to_text__(callback_ ## name); \ - EM_ASM_({ \ - var key = Module['toString']($1); \ - var callbackFnName = Module['toString']($2); \ - var elem = Module[key]($0); \ - elem['_value'][#name] = function(e) { elem[callbackFnName](e); }; \ - }, this, key, callbackFnName); \ - } \ - void klass::callback_ ## name(emscripten::val e) \ - { \ - if (!this->_ ## name) return; \ - (this->_ ## name)(Event::create(e)); \ - } \ - HTML5_BIND_METHOD(klass, callback_ ## name); - -#define HTML5_ERROR_HANDLER_PROPERTY_IMPL(klass, type, name) \ - type klass::get_ ## name() const \ - { \ - HTML5_PROPERTY_TRACE_GETTER(name); \ - return this->_ ## name; \ - } \ - \ - void klass::set_ ## name(type value) \ - { \ - HTML5_PROPERTY_TRACE_SETTER(name); \ - this->_ ## name = value; \ - const char *key = __to_text__(to ## klass); \ - const char *callbackFnName = __to_text__(callback_ ## name); \ - EM_ASM_({ \ - var key = Module['toString']($1); \ - var callbackFnName = Module['toString']($2); \ - var elem = Module[key]($0); \ - elem['_value'][#name] = function(event, source, lineno, colno, error) { \ - elem[callbackFnName](event, source, lineno, colno, error); \ - }; \ - }, this, key, callbackFnName); \ - } \ - void klass::callback_ ## name(emscripten::val e, std::string source, unsigned long lineno, unsigned long colno, emscripten::val error) \ - { \ - if (!this->_ ## name) return; \ - (*this->_ ## name)(Event::create(e), source, lineno, colno, NULL); \ - } \ - HTML5_BIND_METHOD(klass, callback_ ## name); - - -#define HTML5_READONLY_PROPERTY_IMPL(klass, type, name) \ - type klass::get_ ## name() const \ - { \ - HTML5_PROPERTY_TRACE_GETTER(name); \ - return HTML5_PROPERTY_GET(name, type); \ - } - -#define HTML5_PROPERTY_OBJECT_IMPL(klass, type, name) \ - type *klass::get_ ## name() const \ - { \ - HTML5_PROPERTY_TRACE_GETTER(name); \ - return HTML5_PROPERTY_GET(name, type); \ - } \ - \ - void klass::set_ ## name(type *value) \ - { \ - HTML5_PROPERTY_TRACE_SETTER(name); \ - HTML5_PROPERTY_OBJECT_SET(name, value); \ - } - -#define HTML5_READONLY_PROPERTY_OBJECT_IMPL(klass, type, name) \ - type *klass::get_ ## name() const \ - { \ - HTML5_PROPERTY_TRACE_GETTER(name); \ - return HTML5_PROPERTY_GET(name, type); \ - } - -#define HTML5_DEFINE_ITERATOR(klass, subclass) \ - class iterator { \ - public: \ - iterator(klass *list, unsigned long index = 0) : \ - _list(list), \ - _index(index){}; \ - virtual ~iterator() {}; \ - subclass *operator*() { return this->_list->item(this->_index); }; \ - iterator& operator++() { \ - this->_index++; \ - return *this; \ - }; \ - bool operator!=(const iterator& v) { return this->_index != v._index; }; \ - private: \ - unsigned long _index; \ - klass *_list; \ - }; \ - iterator begin() { return iterator(this); }; \ - iterator end() { return iterator(this, this->length); }; \ - -#include "export.h" +NAMESPACE_HTML5_END; diff --git a/include/link_style.h b/include/link_style.h index 4c7894f..a7205d2 100644 --- a/include/link_style.h +++ b/include/link_style.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" #include "style_sheet.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/location.h b/include/location.h index 07c34ba..2882a05 100644 --- a/include/location.h +++ b/include/location.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/media_error.h b/include/media_error.h index 3daa57e..5ac5703 100644 --- a/include/media_error.h +++ b/include/media_error.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/media_list.h b/include/media_list.h index 4a6b3fb..8939ad9 100644 --- a/include/media_list.h +++ b/include/media_list.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/mime_type.h b/include/mime_type.h index ca15ead..665d5a1 100644 --- a/include/mime_type.h +++ b/include/mime_type.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/mime_type_array.h b/include/mime_type_array.h index 77d863f..586e302 100644 --- a/include/mime_type_array.h +++ b/include/mime_type_array.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/native_object.h b/include/native_object.h index e56826e..7a7a698 100644 --- a/include/native_object.h +++ b/include/native_object.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/navigator.h b/include/navigator.h index ba3c50d..048ee74 100644 --- a/include/navigator.h +++ b/include/navigator.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/node.h b/include/node.h index ccf3a78..1df3fbf 100644 --- a/include/node.h +++ b/include/node.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" #include "event_target.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/node_filter.h b/include/node_filter.h index b090e31..dff9397 100644 --- a/include/node_filter.h +++ b/include/node_filter.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/node_iterator.h b/include/node_iterator.h index 8b5df07..7e45b75 100644 --- a/include/node_iterator.h +++ b/include/node_iterator.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/object.h b/include/object.h index 6d711a8..4164522 100644 --- a/include/object.h +++ b/include/object.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" #include "native_object.h" #include diff --git a/include/path2d.h b/include/path2d.h index c7ef793..4a3462c 100644 --- a/include/path2d.h +++ b/include/path2d.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/performance.h b/include/performance.h index 6652273..51ebca3 100644 --- a/include/performance.h +++ b/include/performance.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" #include "event_handler.h" #include diff --git a/include/performance_entry.h b/include/performance_entry.h index 5015cc5..d5d042d 100644 --- a/include/performance_entry.h +++ b/include/performance_entry.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/performance_navigation.h b/include/performance_navigation.h index 6f6aaa7..812bf11 100644 --- a/include/performance_navigation.h +++ b/include/performance_navigation.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/performance_timing.h b/include/performance_timing.h index baaef86..4c778c4 100644 --- a/include/performance_timing.h +++ b/include/performance_timing.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/plugin.h b/include/plugin.h index c2d7a1d..586dbb6 100644 --- a/include/plugin.h +++ b/include/plugin.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/plugin_array.h b/include/plugin_array.h index a99b4a3..3d342ee 100644 --- a/include/plugin_array.h +++ b/include/plugin_array.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/promise.h b/include/promise.h index d2d0404..98952ba 100644 --- a/include/promise.h +++ b/include/promise.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" #include NAMESPACE_HTML5_BEGIN; diff --git a/include/range.h b/include/range.h index 6798b5e..4cf9c52 100644 --- a/include/range.h +++ b/include/range.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/rendering_context.h b/include/rendering_context.h index a6f5b32..1294009 100644 --- a/include/rendering_context.h +++ b/include/rendering_context.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/response.h b/include/response.h index c692053..2c1e750 100644 --- a/include/response.h +++ b/include/response.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/storage.h b/include/storage.h index 9433c2c..5f9406f 100644 --- a/include/storage.h +++ b/include/storage.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/style_sheet.h b/include/style_sheet.h index 0b66940..5d08a1e 100644 --- a/include/style_sheet.h +++ b/include/style_sheet.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/style_sheet_list.h b/include/style_sheet_list.h index 1a03cb7..676514e 100644 --- a/include/style_sheet_list.h +++ b/include/style_sheet_list.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" #include "style_sheet.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/svgmatrix.h b/include/svgmatrix.h index 9e0e564..2dae7d5 100644 --- a/include/svgmatrix.h +++ b/include/svgmatrix.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/text_metrics.h b/include/text_metrics.h index 6af82cf..8d30498 100644 --- a/include/text_metrics.h +++ b/include/text_metrics.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/text_track_cue_list.h b/include/text_track_cue_list.h index 8db6bf1..cf38ae6 100644 --- a/include/text_track_cue_list.h +++ b/include/text_track_cue_list.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/time_ranges.h b/include/time_ranges.h index 35e1c4e..ad4d51e 100644 --- a/include/time_ranges.h +++ b/include/time_ranges.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/tree_walker.h b/include/tree_walker.h index 91e0f69..f959071 100644 --- a/include/tree_walker.h +++ b/include/tree_walker.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/video_track.h b/include/video_track.h index 5020504..0e131e2 100644 --- a/include/video_track.h +++ b/include/video_track.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/webgl_active_info.h b/include/webgl_active_info.h index 534271d..7cec1e0 100644 --- a/include/webgl_active_info.h +++ b/include/webgl_active_info.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/webgl_context_attributes.h b/include/webgl_context_attributes.h index 737d85c..460abe8 100644 --- a/include/webgl_context_attributes.h +++ b/include/webgl_context_attributes.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/webgl_extension.h b/include/webgl_extension.h index cce521f..bf12d17 100644 --- a/include/webgl_extension.h +++ b/include/webgl_extension.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/webgl_object.h b/include/webgl_object.h index a8d182a..2c71a42 100644 --- a/include/webgl_object.h +++ b/include/webgl_object.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/webgl_shader_precision_format.h b/include/webgl_shader_precision_format.h index ea1b2be..c7e0f88 100644 --- a/include/webgl_shader_precision_format.h +++ b/include/webgl_shader_precision_format.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/webgl_uniform_location.h b/include/webgl_uniform_location.h index 4bbbf82..ef0b205 100644 --- a/include/webgl_uniform_location.h +++ b/include/webgl_uniform_location.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" NAMESPACE_HTML5_BEGIN; diff --git a/include/window.h b/include/window.h index f3f96ea..96155f6 100644 --- a/include/window.h +++ b/include/window.h @@ -1,6 +1,6 @@ #pragma once -#include "libhtml5.h" +#include "html5.h" #include "event_target.h" NAMESPACE_HTML5_BEGIN; diff --git a/src/export.cc b/src/export.cc index be0ee41..7375f91 100644 --- a/src/export.cc +++ b/src/export.cc @@ -3,6 +3,23 @@ NAMESPACE_HTML5_BEGIN; +Window *window; + +static bool g_initialized = false; + +class __runtime__ { +public: + __runtime__() { + if (g_initialized) return; + + window = Window::create(); + window->retain(); + g_initialized = true; + } +}; + +static __runtime__ r; + void alert(std::string message) { return window->alert(message);