netsurf: branch master updated. release/3.10-331-g550900b
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/550900b1cbfffcd3ceb5c...
...commit http://git.netsurf-browser.org/netsurf.git/commit/550900b1cbfffcd3ceb5c00...
...tree http://git.netsurf-browser.org/netsurf.git/tree/550900b1cbfffcd3ceb5c0063...
The branch, master has been updated
via 550900b1cbfffcd3ceb5c00631bcbae2b453443c (commit)
via f29f12a5df255f252987e8acf92994e40125aff6 (commit)
via 7bcd4fd2465631f4a17e1920594e9c2536b6f057 (commit)
from 764fca4f3abfc7437003f496d52039ad7e6b779d (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
-----------------------------------------------------------------------
Summary of changes:
.../javascript/duktape/DOMSettableTokenList.bnd | 44 ++++++
.../handlers/javascript/duktape/DOMTokenList.bnd | 163 ++++++++++++++++++++
content/handlers/javascript/duktape/Element.bnd | 31 ++++
content/handlers/javascript/duktape/netsurf.bnd | 2 +
content/handlers/javascript/duktape/polyfill.js | 18 +++
docs/UnimplementedJavascript.md | 17 +-
test/js/class-list.html | 29 ++++
test/js/index.html | 1 +
8 files changed, 289 insertions(+), 16 deletions(-)
create mode 100644 content/handlers/javascript/duktape/DOMSettableTokenList.bnd
create mode 100644 content/handlers/javascript/duktape/DOMTokenList.bnd
create mode 100644 test/js/class-list.html
diff --git a/content/handlers/javascript/duktape/DOMSettableTokenList.bnd b/content/handlers/javascript/duktape/DOMSettableTokenList.bnd
new file mode 100644
index 0000000..ac5c706
--- /dev/null
+++ b/content/handlers/javascript/duktape/DOMSettableTokenList.bnd
@@ -0,0 +1,44 @@
+/* DOMTokenList binding for browser using duktape and libdom
+ *
+ * Copyright 2015 Vincent Sanders <vince(a)netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * Released under the terms of the MIT License,
+ * http://www.opensource.org/licenses/mit-license
+ */
+
+class DOMSettableTokenList {
+};
+
+init DOMSettableTokenList(struct dom_tokenlist *tokens::tokens);
+
+getter DOMSettableTokenList::value()
+%{
+ dom_exception exc;
+ dom_string *value;
+
+ exc = dom_tokenlist_get_value(priv->parent.tokens, &value);
+ if (exc != DOM_NO_ERR) return 0; /* coerced to undefined */
+
+ duk_push_lstring(ctx, dom_string_data(value), dom_string_length(value));
+ dom_string_unref(value);
+
+ return 1;
+%}
+
+setter DOMSettableTokenList::value()
+%{
+ dom_exception exc;
+ dom_string *value;
+ duk_size_t slen;
+ const char *s = duk_require_lstring(ctx, 0, &slen);
+
+ exc = dom_string_create_interned((const uint8_t *)s, slen, &value);
+ if (exc != DOM_NO_ERR) return 0;
+
+ exc = dom_tokenlist_set_value(priv->parent.tokens, value);
+ dom_string_unref(value);
+
+ return 0;
+%}
\ No newline at end of file
diff --git a/content/handlers/javascript/duktape/DOMTokenList.bnd b/content/handlers/javascript/duktape/DOMTokenList.bnd
new file mode 100644
index 0000000..928d9ef
--- /dev/null
+++ b/content/handlers/javascript/duktape/DOMTokenList.bnd
@@ -0,0 +1,163 @@
+/* DOMTokenList binding for browser using duktape and libdom
+ *
+ * Copyright 2015 Vincent Sanders <vince(a)netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * Released under the terms of the MIT License,
+ * http://www.opensource.org/licenses/mit-license
+ */
+
+class DOMTokenList {
+ private struct dom_tokenlist *tokens;
+};
+
+init DOMTokenList(struct dom_tokenlist *tokens)
+%{
+ priv->tokens = tokens;
+ dom_tokenlist_ref(tokens);
+%}
+
+fini DOMTokenList()
+%{
+ dom_tokenlist_unref(priv->tokens);
+%}
+
+getter DOMTokenList::length()
+%{
+ dom_exception err;
+ uint32_t len;
+
+ err = dom_tokenlist_get_length(priv->tokens, &len);
+
+ if (err != DOM_NO_ERR) return 0; /* coerced to undefined */
+
+ duk_push_uint(ctx, (duk_uint_t)len);
+
+ return 1;
+%}
+
+method DOMTokenList::item()
+%{
+ unsigned long i = duk_to_uint(ctx, 0);
+ dom_exception err;
+ dom_string *value;
+
+ err = dom_tokenlist_item(priv->tokens, i, &value);
+
+ if (err != DOM_NO_ERR) return 0; /* coerced to undefined */
+
+ if (value == NULL) {
+ duk_push_null(ctx);
+ return 1;
+ }
+
+ duk_push_lstring(ctx, dom_string_data(value), dom_string_length(value));
+ dom_string_unref(value);
+
+ return 1;
+%}
+
+method DOMTokenList::add()
+%{
+ dom_exception exc;
+ dom_string *value;
+ duk_size_t slen;
+ const char *s;
+ duk_idx_t spos;
+
+ for (spos = 0; spos < duk_get_top(ctx); ++spos) {
+ s = duk_safe_to_lstring(ctx, spos, &slen);
+
+ duk_safe_to_lstring(ctx, 0, &slen);
+
+ exc = dom_string_create_interned((const uint8_t *)s, slen, &value);
+ if (exc != DOM_NO_ERR) return 0;
+
+ exc = dom_tokenlist_add(priv->tokens, value);
+ dom_string_unref(value);
+ }
+
+ return 0;
+%}
+
+method DOMTokenList::remove()
+%{
+ dom_exception exc;
+ dom_string *value;
+ duk_size_t slen;
+ const char *s;
+ duk_idx_t spos;
+
+ for (spos = 0; spos < duk_get_top(ctx); ++spos) {
+ s = duk_safe_to_lstring(ctx, spos, &slen);
+
+ duk_safe_to_lstring(ctx, 0, &slen);
+
+ exc = dom_string_create_interned((const uint8_t *)s, slen, &value);
+ if (exc != DOM_NO_ERR) return 0;
+
+ exc = dom_tokenlist_remove(priv->tokens, value);
+ dom_string_unref(value);
+ }
+
+ return 0;
+%}
+
+method DOMTokenList::contains()
+%{
+ dom_exception exc;
+ dom_string *value;
+ duk_size_t slen;
+ const char *s = duk_safe_to_lstring(ctx, 0, &slen);
+ bool present = false;
+
+ exc = dom_string_create_interned((const uint8_t *)s, slen, &value);
+ if (exc != DOM_NO_ERR) return 0;
+
+ exc = dom_tokenlist_contains(priv->tokens, value, &present);
+ dom_string_unref(value);
+ if (exc != DOM_NO_ERR) return 0;
+
+ duk_push_boolean(ctx, present);
+
+ return 1;
+%}
+
+method DOMTokenList::toggle()
+%{
+ dom_exception exc;
+ dom_string *value;
+ duk_size_t slen;
+ const char *s = duk_require_lstring(ctx, 0, &slen);
+ bool toggle_set = duk_get_top(ctx) > 1;
+ bool toggle = duk_opt_boolean(ctx, 1, 0);
+ bool present;
+
+ exc = dom_string_create_interned((const uint8_t *)s, slen, &value);
+ if (exc != DOM_NO_ERR) return 0;
+
+ exc = dom_tokenlist_contains(priv->tokens, value, &present);
+ if (exc != DOM_NO_ERR) {
+ dom_string_unref(value);
+ return 0;
+ }
+
+ /* Decision matrix is based on present, toggle_set, and toggle */
+ if (toggle_set) {
+ if (toggle) {
+ exc = dom_tokenlist_add(priv->tokens, value);
+ } else {
+ exc = dom_tokenlist_remove(priv->tokens, value);
+ }
+ } else {
+ if (present) {
+ exc = dom_tokenlist_add(priv->tokens, value);
+ } else {
+ exc = dom_tokenlist_remove(priv->tokens, value);
+ }
+ }
+ dom_string_unref(value);
+
+ return 0;
+%}
\ No newline at end of file
diff --git a/content/handlers/javascript/duktape/Element.bnd b/content/handlers/javascript/duktape/Element.bnd
index a965a6c..ff0686f 100644
--- a/content/handlers/javascript/duktape/Element.bnd
+++ b/content/handlers/javascript/duktape/Element.bnd
@@ -392,6 +392,37 @@ setter Element::className ()
return 0;
%}
+getter Element::classList ()
+%{
+ dom_exception exc;
+ dom_tokenlist *tokens;
+
+ duk_set_top(ctx, 0);
+ duk_push_this(ctx);
+ duk_get_prop_string(ctx, 0, MAGIC(classList));
+
+ if (duk_is_undefined(ctx, -1)) {
+ duk_pop(ctx);
+ exc = dom_tokenlist_create((dom_element *)priv->parent.node, corestring_dom_class, &tokens);
+ if (exc != DOM_NO_ERR) return 0; /* Coerced to undefined */
+
+ /* Create a settable tokenlist - While the IDL says this isn't settable, all browsers
+ * seem to make it settable, so we'll permit it too
+ */
+ duk_push_pointer(ctx, tokens);
+ if (dukky_create_object(ctx, PROTO_NAME(DOMSETTABLETOKENLIST), 1) != DUK_EXEC_SUCCESS) {
+ dom_tokenlist_unref(tokens);
+ NSLOG(dukky, DEBUG, "Unable to create DOMSettableTokenList object");
+ return 0; /* Coerced to undefined */
+ }
+ dom_tokenlist_unref(tokens);
+ duk_dup(ctx, -1);
+ duk_put_prop_string(ctx, 0, MAGIC(classList));
+ }
+
+ return 1;
+%}
+
getter Element::innerHTML()
%{
duk_push_lstring(ctx, "", 0);
diff --git a/content/handlers/javascript/duktape/netsurf.bnd b/content/handlers/javascript/duktape/netsurf.bnd
index 651c2fd..483f347 100644
--- a/content/handlers/javascript/duktape/netsurf.bnd
+++ b/content/handlers/javascript/duktape/netsurf.bnd
@@ -60,6 +60,8 @@ struct dom_html_br_element;
#include "Document.bnd"
#include "Node.bnd"
#include "NodeList.bnd"
+#include "DOMTokenList.bnd"
+#include "DOMSettableTokenList.bnd"
#include "NamedNodeMap.bnd"
#include "Element.bnd"
#include "HTMLCollection.bnd"
diff --git a/content/handlers/javascript/duktape/polyfill.js b/content/handlers/javascript/duktape/polyfill.js
index 5f02156..6c85ce1 100644
--- a/content/handlers/javascript/duktape/polyfill.js
+++ b/content/handlers/javascript/duktape/polyfill.js
@@ -83,3 +83,21 @@ if (!Array.from) {
};
}());
}
+
+// DOMTokenList formatter, in theory we can remove this if we do the stringifier IDL support
+
+DOMTokenList.prototype.toString = function () {
+ if (this.length == 0) {
+ return "";
+ }
+
+ var ret = this.item(0);
+ for (var index = 1; index < this.length; index++) {
+ ret = ret + " " + this.item(index);
+ }
+
+ return ret;
+}
+
+// Inherit the same toString for settable lists
+DOMSettableTokenList.prototype.toString = DOMTokenList.prototype.toString;
\ No newline at end of file
diff --git a/docs/UnimplementedJavascript.md b/docs/UnimplementedJavascript.md
index 4a2f02e..0d21dc8 100644
--- a/docs/UnimplementedJavascript.md
+++ b/docs/UnimplementedJavascript.md
@@ -170,7 +170,6 @@ getter | Element::namespaceURI(string);
getter | Element::prefix(string);
getter | Element::localName(string);
getter | Element::tagName(string);
-getter | Element::classList(user);
getter | Element::outerHTML(string);
setter | Element::outerHTML(string);
getter | Element::children(user);
@@ -597,10 +596,6 @@ method | CanvasRenderingContext2D::arcTo();
method | CanvasRenderingContext2D::rect();
method | CanvasRenderingContext2D::arc();
method | CanvasRenderingContext2D::ellipse();
-getter | CanvasRenderingContext2D::width(unsigned long);
-setter | CanvasRenderingContext2D::width(unsigned long);
-getter | CanvasRenderingContext2D::height(unsigned long);
-setter | CanvasRenderingContext2D::height(unsigned long);
getter | CanvasRenderingContext2D::currentTransform(user);
setter | CanvasRenderingContext2D::currentTransform(user);
getter | CanvasRenderingContext2D::globalAlpha(double);
@@ -647,8 +642,6 @@ method | HTMLCanvasElement::setContext();
method | HTMLCanvasElement::transferControlToProxy();
method | HTMLCanvasElement::toDataURL();
method | HTMLCanvasElement::toBlob();
-setter | HTMLCanvasElement::width(unsigned long);
-setter | HTMLCanvasElement::height(unsigned long);
getter | HTMLTemplateElement::content(user);
getter | HTMLScriptElement::async(boolean);
setter | HTMLScriptElement::async(boolean);
@@ -1344,14 +1337,6 @@ method | HTMLAllCollection::namedItem();
getter | HTMLAllCollection::length(unsigned long);
method | XMLSerializer::serializeToString();
method | DOMParser::parseFromString();
-method | DOMTokenList::item();
-method | DOMTokenList::contains();
-method | DOMTokenList::add();
-method | DOMTokenList::remove();
-method | DOMTokenList::toggle();
-getter | DOMTokenList::length(unsigned long);
-getter | DOMSettableTokenList::value(string);
-setter | DOMSettableTokenList::value(string);
method | NodeFilter::acceptNode();
method | TreeWalker::parentNode();
method | TreeWalker::firstChild();
@@ -1560,5 +1545,5 @@ method | EventListener::handleEvent();
method | CustomEvent::initCustomEvent();
getter | CustomEvent::detail(any);
- 1554 unimplemented bindings
+ 1539 unimplemented bindings
diff --git a/test/js/class-list.html b/test/js/class-list.html
new file mode 100644
index 0000000..4c73283
--- /dev/null
+++ b/test/js/class-list.html
@@ -0,0 +1,29 @@
+<html>
+ <head>
+ <title>Class List (and other token lists?)</title>
+ <style>
+ .bad { background-color: red; }
+ .ok { background-color: green; }
+ </style>
+ </head>
+ <body>
+ <h1>This is a set of demonstrators for the token list Element.classList</h1>
+ <h2>This first is taken from the MDN for DOMTokenList</h2>
+ <span id="demo1" class=" d d e f bad"></span>
+ <script>
+ var span = document.getElementById("demo1");
+ var classes = span.classList;
+ classes.add("x", "d", "g");
+ classes.remove("e", "g");
+ classes.toggle("d"); // Toggles d off
+ classes.toggle("q", false); // Forces q off (won't be present)
+ classes.toggle("d"); // Toggles d on
+ classes.toggle("d", true); // Forces d on (won't toggle it off again)
+ if (classes.contains("d")) {
+ classes.add("ok")
+ classes.remove("bad")
+ span.textContent = "span classList is \"" + classes + '"';
+ }
+ </script>
+ </body>
+</html>
diff --git a/test/js/index.html b/test/js/index.html
index 0329467..6d2c654 100644
--- a/test/js/index.html
+++ b/test/js/index.html
@@ -104,6 +104,7 @@
<li><a href="assorted-log-doc-write.html">console.log and document.write</a></li>
<li><a href="wikipedia-lcm.html">Example from wikipedia</a></li>
<li><a href="verify-instanceofness.html">Check instanceof behaviour</a></li>
+<li><a href="class-list.html">Class list (and other token lists?)</a></li>
<li><a href="mandelbrot.html">Canvas/ImageData Mandelbrot ploter</a></li>
<li><a href="life.html">Game of Life</a></li>
</ul>
--
NetSurf Browser
4 months
libdom: branch master updated. release/0.4.1-22-gad4cdc9
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libdom.git/shortlog/ad4cdc900f197c0f373615...
...commit http://git.netsurf-browser.org/libdom.git/commit/ad4cdc900f197c0f373615d4...
...tree http://git.netsurf-browser.org/libdom.git/tree/ad4cdc900f197c0f373615d454...
The branch, master has been updated
via ad4cdc900f197c0f373615d454275f38a9c4d181 (commit)
via 14f1b4abd5f395555e8d96e18c5db844bff17fde (commit)
from 2e61b186ea44241fd8adfc626802f01f2dfbffed (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
-----------------------------------------------------------------------
Summary of changes:
.clang-format | 120 +++++
Makefile | 2 +-
include/dom/core/tokenlist.h | 43 ++
include/dom/dom.h | 1 +
src/core/Makefile | 2 +-
src/core/tokenlist.c | 547 ++++++++++++++++++++
.../dom/core/entity_ref.h => src/core/tokenlist.h | 11 +-
7 files changed, 721 insertions(+), 5 deletions(-)
create mode 100644 .clang-format
create mode 100644 include/dom/core/tokenlist.h
create mode 100644 src/core/tokenlist.c
copy include/dom/core/entity_ref.h => src/core/tokenlist.h (55%)
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..75df82a
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,120 @@
+---
+Language: Cpp
+AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlines: Right
+AlignOperands: true
+AlignTrailingComments: false
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: MultiLine
+BinPackArguments: false
+BinPackParameters: false
+BraceWrapping:
+ AfterClass: true
+ AfterControlStatement: false
+ AfterEnum: false
+ AfterFunction: true
+ AfterNamespace: true
+ AfterObjCDeclaration: false
+ AfterStruct: false
+ AfterUnion: false
+ AfterExternBlock: false
+ BeforeCatch: false
+ BeforeElse: false
+ IndentBraces: false
+ SplitEmptyFunction: true
+ SplitEmptyRecord: true
+ SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Linux
+BreakBeforeInheritanceComma: false
+BreakInheritanceList: BeforeColon
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeColon
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: false
+ColumnLimit: 80
+CommentPragmas: '^ IWYU pragma:'
+CompactNamespaces: false
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 8
+ContinuationIndentWidth: 8
+Cpp11BracedListStyle: true
+DerivePointerAlignment: false
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: true
+ForEachMacros:
+ - foreach
+ - Q_FOREACH
+ - BOOST_FOREACH
+IncludeBlocks: Preserve
+IncludeCategories:
+ - Regex: '^(<.*/)'
+ Priority: 3
+ - Regex: '^(<(nsutils)/)'
+ Priority: 2
+ - Regex: '"utils/'
+ Priority: 4
+ - Regex: '"netsurf/'
+ Priority: 5
+ - Regex: '.*'
+ Priority: 6
+IncludeIsMainRegex: '(Test)?$'
+IndentCaseLabels: false
+IndentPPDirectives: None
+IndentWidth: 8
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 2
+NamespaceIndentation: None
+ObjCBinPackProtocolList: Auto
+ObjCBlockIndentWidth: 2
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakAssignment: 100
+PenaltyBreakBeforeFirstCallParameter: 50
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyBreakTemplateDeclaration: 10
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 19
+PointerAlignment: Right
+ReflowComments: true
+SortIncludes: false
+SortUsingDeclarations: true
+SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCpp11BracedList: false
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeParens: ControlStatements
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Cpp11
+TabWidth: 8
+UseTab: Always
+...
+
diff --git a/Makefile b/Makefile
index 8d9df61..a539ff7 100644
--- a/Makefile
+++ b/Makefile
@@ -69,7 +69,7 @@ INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/entity_ref.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/element.h;$(Is)/exceptions.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/implementation.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/namednodemap.h;$(Is)/node.h
-INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/nodelist.h;$(Is)/string.h
+INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/nodelist.h;$(Is)/tokenlist.h;$(Is)/string.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/pi.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/text.h;$(Is)/typeinfo.h
diff --git a/include/dom/core/tokenlist.h b/include/dom/core/tokenlist.h
new file mode 100644
index 0000000..718d3a5
--- /dev/null
+++ b/include/dom/core/tokenlist.h
@@ -0,0 +1,43 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2022 Daniel Silverstone <dsilvers(a)netsurf-browser.org>
+ */
+
+#ifndef dom_core_tokenlist_h_
+#define dom_core_tokenlist_h_
+
+#include <dom/core/exceptions.h>
+
+struct dom_element;
+struct dom_string;
+
+typedef struct dom_tokenlist dom_tokenlist;
+
+void dom_tokenlist_ref(struct dom_tokenlist *list);
+void dom_tokenlist_unref(struct dom_tokenlist *list);
+
+dom_exception dom_tokenlist_create(struct dom_element *ele, struct dom_string *attr, dom_tokenlist **list);
+
+dom_exception dom_tokenlist_get_length(struct dom_tokenlist *list,
+ uint32_t *length);
+dom_exception _dom_tokenlist_item(struct dom_tokenlist *list,
+ uint32_t index, struct dom_string **value);
+
+#define dom_tokenlist_item(l, i, n) _dom_tokenlist_item((dom_tokenlist *) (l), \
+ (uint32_t) (i), (struct dom_string **) (n))
+
+dom_exception dom_tokenlist_get_value(struct dom_tokenlist *list,
+ struct dom_string **value);
+
+dom_exception dom_tokenlist_set_value(struct dom_tokenlist *list,
+ struct dom_string *value);
+
+dom_exception dom_tokenlist_contains(struct dom_tokenlist *list, struct dom_string *value, bool *contains);
+
+dom_exception dom_tokenlist_add(struct dom_tokenlist *list, struct dom_string *value);
+
+dom_exception dom_tokenlist_remove(struct dom_tokenlist *list, struct dom_string *value);
+
+#endif
diff --git a/include/dom/dom.h b/include/dom/dom.h
index c10e5a6..00bf3d9 100644
--- a/include/dom/dom.h
+++ b/include/dom/dom.h
@@ -32,6 +32,7 @@
#include <dom/core/doc_fragment.h>
#include <dom/core/entity_ref.h>
#include <dom/core/nodelist.h>
+#include <dom/core/tokenlist.h>
#include <dom/core/string.h>
#include <dom/core/text.h>
#include <dom/core/pi.h>
diff --git a/src/core/Makefile b/src/core/Makefile
index 41fd51f..5d9c969 100644
--- a/src/core/Makefile
+++ b/src/core/Makefile
@@ -6,6 +6,6 @@ DIR_SOURCES := \
text.c typeinfo.c comment.c \
namednodemap.c nodelist.c \
cdatasection.c document_type.c entity_ref.c pi.c \
- doc_fragment.c document.c
+ doc_fragment.c document.c tokenlist.c
include $(NSBUILD)/Makefile.subdir
diff --git a/src/core/tokenlist.c b/src/core/tokenlist.c
new file mode 100644
index 0000000..c227b31
--- /dev/null
+++ b/src/core/tokenlist.c
@@ -0,0 +1,547 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2022 Daniel Silverstone <dsilvers(a)digital-scurf.org>
+ */
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <dom/core/element.h>
+#include <dom/core/nodelist.h>
+#include <dom/core/tokenlist.h>
+#include <dom/core/string.h>
+#include <dom/events/event.h>
+#include <dom/events/event_target.h>
+#include <dom/events/event_listener.h>
+#include <dom/events/mutation_event.h>
+
+#include "core/element.h"
+#include "core/document.h"
+
+#include "utils/utils.h"
+
+#define DOM_TOKENLIST_GROW_INCREMENT 4
+
+struct dom_tokenlist {
+ uint32_t refcnt;
+ dom_element *ele;
+ dom_string *attr;
+ dom_event_listener *listener;
+ dom_string *last_set;
+ bool needs_parse;
+ /* Parsed content, for optimal access */
+ dom_string **entries;
+ uint32_t len;
+ uint32_t alloc;
+};
+
+/* Handle a DOMAttrModified event which might be to do with our attribute */
+
+static void _dom_tokenlist_handle_attrmodified(dom_event *evt, void *pw)
+{
+ dom_mutation_event *mutevt = (dom_mutation_event *)evt;
+ dom_tokenlist *list = (dom_tokenlist *)pw;
+ dom_exception exc;
+ dom_string *value;
+
+ {
+ dom_node *target;
+ exc = dom_event_get_target(mutevt, &target);
+ if (exc != DOM_NO_ERR)
+ return;
+ dom_node_unref(target);
+ if (target != (dom_node *)list->ele)
+ return;
+ }
+
+ {
+ dom_string *attr;
+ exc = dom_mutation_event_get_attr_name(mutevt, &attr);
+ if (exc != DOM_NO_ERR)
+ return;
+ if (!dom_string_isequal(attr, list->attr)) {
+ dom_string_unref(attr);
+ return;
+ }
+ dom_string_unref(attr);
+ }
+
+ /* At this point we know that this is a mutation of our attribute on our
+ * node */
+
+ exc = dom_mutation_event_get_new_value(mutevt, &value);
+ if (exc != DOM_NO_ERR)
+ return;
+
+ if (list->last_set != NULL &&
+ dom_string_isequal(list->last_set, value)) {
+ /* We've just seen the mutation event for one of our own set
+ * operations */
+ dom_string_unref(value);
+ return;
+ }
+
+ /* Mark that we need to re-parse the tokenlist on the next request */
+ list->needs_parse = true;
+
+ dom_string_unref(value);
+}
+
+static dom_exception _dom_tokenlist_make_room(dom_tokenlist *list)
+{
+ if (list->len == list->alloc) {
+ uint32_t new_alloc = list->alloc + DOM_TOKENLIST_GROW_INCREMENT;
+ dom_string **new_entries = realloc(
+ list->entries, new_alloc * sizeof(dom_string *));
+ if (new_entries == NULL)
+ return DOM_NO_MEM_ERR;
+ list->alloc = new_alloc;
+ list->entries = new_entries;
+ }
+
+ return DOM_NO_ERR;
+}
+
+static dom_exception _dom_tokenlist_reparse(dom_tokenlist *list)
+{
+ dom_exception exc;
+ dom_string *value;
+ const char *pos;
+ uint32_t remaining, check;
+ uint32_t n_entries = 0;
+ dom_string *temp;
+ bool found;
+
+ if (!list->needs_parse)
+ return DOM_NO_ERR;
+
+ /* Clean down the current entries */
+ while (list->len-- > 0)
+ dom_string_unref(list->entries[list->len]);
+ list->len = 0;
+
+ /* Get the "new" attribute value */
+ exc = dom_element_get_attribute(list->ele, list->attr, &value);
+ if (exc != DOM_NO_ERR)
+ return exc;
+
+ /* If there is no value, we're an empty list and we're done */
+ if (value == NULL) {
+ list->needs_parse = false;
+ return DOM_NO_ERR;
+ }
+
+ /* OK, there's something here to do, so let's do it... */
+
+ /* Count number of entries */
+ for (pos = dom_string_data(value), remaining = dom_string_length(value);
+ remaining > 0;) {
+ if (*pos != ' ') {
+ while (*pos != ' ' && remaining > 0) {
+ remaining--;
+ pos++;
+ }
+ n_entries++;
+ } else {
+ while (*pos == ' ' && remaining > 0) {
+ remaining--;
+ pos++;
+ }
+ }
+ }
+
+ /* If there are no entries (all whitespace) just bail here */
+ if (n_entries == 0) {
+ list->needs_parse = false;
+ dom_string_unref(value);
+ return DOM_NO_ERR;
+ }
+
+ /* If we need more room, reallocate the buffer */
+ if (list->alloc < n_entries) {
+ dom_string **new_alloc = realloc(
+ list->entries, n_entries * sizeof(dom_string *));
+ if (new_alloc == NULL) {
+ dom_string_unref(value);
+ return DOM_NO_MEM_ERR;
+ }
+ list->entries = new_alloc;
+ list->alloc = n_entries;
+ }
+
+ /* And now parse those entries into the buffer */
+ for (pos = dom_string_data(value),
+ remaining = dom_string_length(value),
+ n_entries = 0;
+ remaining > 0;) {
+ if (*pos != ' ') {
+ const char *s = pos;
+ while (*pos != ' ' && remaining > 0) {
+ pos++;
+ remaining--;
+ }
+ exc = dom_string_create_interned((const uint8_t *)s,
+ pos - s,
+ &temp);
+ if (exc != DOM_NO_ERR) {
+ dom_string_unref(value);
+ return exc;
+ }
+ found = false;
+ for (check = 0; check < list->len; check++) {
+ if (dom_string_isequal(temp,
+ list->entries[check])) {
+ found = true;
+ break;
+ }
+ }
+ if (found == true) {
+ dom_string_unref(temp);
+ } else {
+ list->entries[list->len] = temp;
+ list->len++;
+ }
+ } else {
+ while (*pos == ' ' && remaining > 0) {
+ pos++;
+ remaining--;
+ }
+ }
+ }
+
+ dom_string_unref(value);
+ list->needs_parse = false;
+
+ return DOM_NO_ERR;
+}
+
+static dom_exception _dom_tokenlist_reify(dom_tokenlist *list)
+{
+ dom_exception exc;
+ uint32_t nchars = 0, n;
+ char *buffer, *next;
+ dom_string *output;
+
+ if (list->len == 0) {
+ if (list->last_set != NULL) {
+ dom_node_unref(list->last_set);
+ }
+ list->last_set = dom_string_ref(
+ list->ele->base.owner->_memo_empty);
+ return dom_element_set_attribute(list->ele,
+ list->attr,
+ list->last_set);
+ }
+
+ for (n = 0; n < list->len; ++n)
+ nchars += dom_string_length(list->entries[n]);
+
+ buffer = calloc(1, nchars + list->len);
+ if (buffer == NULL)
+ return DOM_NO_MEM_ERR;
+
+ for (next = buffer, n = 0; n < list->len; ++n) {
+ uint32_t slen = dom_string_length(list->entries[n]);
+ memcpy(next, dom_string_data(list->entries[n]), slen);
+ next[slen] = ' ';
+ next += slen + 1;
+ }
+
+ exc = dom_string_create_interned((const uint8_t *)buffer,
+ nchars + list->len - 1,
+ &output);
+ free(buffer);
+ if (exc != DOM_NO_ERR)
+ return exc;
+
+ if (list->last_set != NULL) {
+ dom_string_unref(list->last_set);
+ }
+ list->last_set = output;
+
+ return dom_element_set_attribute(list->ele, list->attr, list->last_set);
+}
+
+/**********************************************************************************/
+
+/**
+ * Create a tokenlist
+ *
+ * \param ele The element which owns the tokenlist attribute
+ * \param attr The name of the attribute we are treating as a tokenlist
+ * \param list The tokenlist output which is set on success
+ * \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion
+ *
+ * The returned list will already be referenced, so the client need not
+ * do so explicitly. The client must unref the list once finished with it.
+ *
+ * This list will take its own references to ::ele and ::attr
+ */
+dom_exception
+dom_tokenlist_create(dom_element *ele, dom_string *attr, dom_tokenlist **list)
+{
+ dom_tokenlist *l;
+ dom_exception exc;
+
+ l = calloc(1, sizeof(dom_tokenlist));
+ if (l == NULL)
+ return DOM_NO_MEM_ERR;
+
+ l->refcnt = 1;
+ l->ele = (dom_element *)dom_node_ref(ele);
+ l->attr = dom_string_ref(attr);
+ l->needs_parse = true;
+
+ exc = dom_event_listener_create(_dom_tokenlist_handle_attrmodified,
+ l,
+ &l->listener);
+ if (exc != DOM_NO_ERR)
+ goto fail;
+
+ exc = dom_event_target_add_event_listener(
+ ele,
+ ele->base.owner->_memo_domattrmodified,
+ l->listener,
+ false);
+
+ if (exc != DOM_NO_ERR)
+ goto fail;
+
+ *list = l;
+
+ return DOM_NO_ERR;
+
+fail:
+ if (l->listener != NULL)
+ dom_event_listener_unref(l->listener);
+ dom_node_unref(l->ele);
+ dom_string_unref(l->attr);
+ free(l);
+ return exc;
+}
+
+/**
+ * Claim a ref on a tokenlist
+ *
+ * \param list The tokenlist to claim a ref on
+ */
+void dom_tokenlist_ref(dom_tokenlist *list)
+{
+ assert(list != NULL);
+ list->refcnt++;
+}
+
+/**
+ * Release a ref on a tokenlist
+ *
+ * \param list The list to release the reference of
+ *
+ * If you release the last ref, this cleans up the tokenlist
+ */
+void dom_tokenlist_unref(dom_tokenlist *list)
+{
+ assert(list != NULL);
+
+ if (--list->refcnt > 0)
+ return;
+
+ if (list->alloc > 0) {
+ while (list->len-- > 0)
+ dom_string_unref(list->entries[list->len]);
+ free(list->entries);
+ }
+
+ dom_event_target_remove_event_listener(
+ list->ele,
+ list->ele->base.owner->_memo_domattrmodified,
+ list->listener,
+ false);
+
+ dom_event_listener_unref(list->listener);
+
+ if (list->last_set != NULL)
+ dom_string_unref(list->last_set);
+
+ dom_string_unref(list->attr);
+ dom_node_unref(list->ele);
+
+ free(list);
+}
+
+/**
+ * Get the length of the tokenlist
+ *
+ * \param list The list to get the length of
+ * \param length Length of the list outputs here
+ * \return DOM_NO_ERR on success, otherwise the failure code
+ */
+dom_exception dom_tokenlist_get_length(dom_tokenlist *list, uint32_t *length)
+{
+ dom_exception exc;
+ assert(list != NULL);
+
+ exc = _dom_tokenlist_reparse(list);
+ if (exc != DOM_NO_ERR)
+ return exc;
+
+ *length = list->len;
+
+ return DOM_NO_ERR;
+}
+
+/**
+ * Get a particular item from the tokenlist
+ *
+ * \param list The list to retrieve the item from
+ * \param index The index of the item to retrieve
+ * \param value The value of the item returns here
+ * \return DOM_NO_ERR on success, otherwise the failure code
+ */
+dom_exception
+_dom_tokenlist_item(dom_tokenlist *list, uint32_t index, dom_string **value)
+{
+ dom_exception exc;
+ assert(list != NULL);
+
+ exc = _dom_tokenlist_reparse(list);
+ if (exc != DOM_NO_ERR)
+ return exc;
+
+ if (index >= list->len) {
+ *value = NULL;
+ return DOM_NO_ERR;
+ }
+
+ *value = dom_string_ref(list->entries[index]);
+ return DOM_NO_ERR;
+}
+
+/**
+ * Retrieve the value of the tokenlist as a string
+ *
+ * \param list The list to retrieve the value of
+ * \param value The value of the list returns here
+ * \return DOM_NO_ERR on success, otherwise the failure code
+ */
+dom_exception dom_tokenlist_get_value(dom_tokenlist *list, dom_string **value)
+{
+ assert(list != NULL);
+
+ return dom_element_get_attribute(list->ele, list->attr, value);
+}
+
+/**
+ * Set the value of the tokenlist as a string
+ *
+ * \param list The list to set the value of
+ * \param value The value to set
+ * \return DOM_NO_ERR on success, otherwise the failure code
+ *
+ */
+dom_exception dom_tokenlist_set_value(dom_tokenlist *list, dom_string *value)
+{
+ assert(list != NULL);
+
+ return dom_element_set_attribute(list->ele, list->attr, value);
+}
+
+/**
+ * Check if the given value is in the tokenlist
+ *
+ * \param list The list to scan for the given value
+ * \param value The value to look for in the token list
+ * \param contains This will be set based on whether or not the value is present
+ * \return DOM_NO_ERR on success, otherwise the failure code
+ */
+dom_exception
+dom_tokenlist_contains(dom_tokenlist *list, dom_string *value, bool *contains)
+{
+ dom_exception exc;
+ uint32_t n;
+
+ assert(list != NULL);
+
+ exc = _dom_tokenlist_reparse(list);
+ if (exc != DOM_NO_ERR)
+ return exc;
+
+ *contains = false;
+
+ for (n = 0; n < list->len; n++) {
+ if (dom_string_isequal(value, list->entries[n])) {
+ *contains = true;
+ break;
+ }
+ }
+
+ return DOM_NO_ERR;
+}
+
+/**
+ * Add the given value to the tokenlist
+ *
+ * \param list The list to add to
+ * \param value The value to add
+ * \return DOM_NO_ERR on success, otherwise the failure code
+ */
+dom_exception dom_tokenlist_add(dom_tokenlist *list, dom_string *value)
+{
+ dom_exception exc;
+ bool present = false;
+
+ assert(list != NULL);
+
+ exc = dom_tokenlist_contains(list, value, &present);
+ if (exc != DOM_NO_ERR)
+ return exc;
+
+ if (present == true)
+ return DOM_NO_ERR;
+
+ exc = _dom_tokenlist_make_room(list);
+ if (exc != DOM_NO_ERR)
+ return exc;
+
+ list->entries[list->len++] = dom_string_ref(value);
+
+ exc = _dom_tokenlist_reify(list);
+
+ return exc;
+}
+
+/**
+ * Remove the given value from the tokenlist
+ *
+ * \param list The list to remove from
+ * \param value The value to remove
+ * \return DOM_NO_ERR on success, otherwise the failure code
+ */
+dom_exception dom_tokenlist_remove(dom_tokenlist *list, dom_string *value)
+{
+ dom_exception exc;
+ uint32_t n, m;
+
+ assert(list != NULL);
+
+ exc = _dom_tokenlist_reparse(list);
+ if (exc != DOM_NO_ERR)
+ return false;
+
+ for (n = 0; n < list->len; ++n) {
+ if (dom_string_isequal(value, list->entries[n])) {
+ dom_string_unref(list->entries[n]);
+ for (m = n + 1; m < list->len; ++m) {
+ list->entries[m - 1] = list->entries[m];
+ }
+ list->len--;
+ break;
+ }
+ }
+
+ exc = _dom_tokenlist_reify(list);
+
+ return exc;
+}
diff --git a/include/dom/core/entity_ref.h b/src/core/tokenlist.h
similarity index 55%
copy from include/dom/core/entity_ref.h
copy to src/core/tokenlist.h
index 4a1d64e..325d726 100644
--- a/include/dom/core/entity_ref.h
+++ b/src/core/tokenlist.h
@@ -5,9 +5,14 @@
* Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
*/
-#ifndef dom_core_entityreference_h_
-#define dom_core_entityreference_h_
+#ifndef dom_internal_core_tokenlist_h_
+#define dom_internal_core_tokenlist_h_
-typedef struct dom_entity_reference dom_entity_reference;
+#include <stdbool.h>
+
+#include <dom/core/tokenlist.h>
+
+struct dom_element;
+struct dom_string;
#endif
--
Document Object Model library
4 months
libcss: branch tlsa/calc-wip created. release/0.9.1-86-gac9d68a
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libcss.git/shortlog/ac9d68a38c4aad45ad4ebf...
...commit http://git.netsurf-browser.org/libcss.git/commit/ac9d68a38c4aad45ad4ebf3d...
...tree http://git.netsurf-browser.org/libcss.git/tree/ac9d68a38c4aad45ad4ebf3db2...
The branch, tlsa/calc-wip has been created
at ac9d68a38c4aad45ad4ebf3db2c3b5a7cb971cd1 (commit)
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/libcss.git/commit/?id=ac9d68a38c4aad45ad4e...
commit ac9d68a38c4aad45ad4ebf3db2c3b5a7cb971cd1
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
WIP: Update computed styles for calc
diff --git a/include/libcss/types.h b/include/libcss/types.h
index 3fb28d3..c0b19da 100644
--- a/include/libcss/types.h
+++ b/include/libcss/types.h
@@ -109,7 +109,9 @@ typedef enum css_unit {
CSS_UNIT_S = 0x1a,
CSS_UNIT_HZ = 0x1b,
- CSS_UNIT_KHZ = 0x1c
+ CSS_UNIT_KHZ = 0x1c,
+
+ CSS_UNIT_CALC = 0x1d /**< Un-resolved calc() */
} css_unit;
/**
diff --git a/src/parse/properties/font.c b/src/parse/properties/font.c
index 7ce9701..b77e65c 100644
--- a/src/parse/properties/font.c
+++ b/src/parse/properties/font.c
@@ -45,6 +45,7 @@ static inline uint32_t css__to_parse_unit(css_unit u)
case CSS_UNIT_S: return UNIT_S;
case CSS_UNIT_HZ: return UNIT_HZ;
case CSS_UNIT_KHZ: return UNIT_KHZ;
+ case CSS_UNIT_CALC: assert(0);
}
return 0;
diff --git a/src/select/autogenerated_computed.h b/src/select/autogenerated_computed.h
index b26560d..62fc731 100644
--- a/src/select/autogenerated_computed.h
+++ b/src/select/autogenerated_computed.h
@@ -20,7 +20,7 @@ struct css_computed_style_i {
* background_repeat 3
* border_bottom_color 2 4
* border_bottom_style 4
- * border_bottom_width 3 + 5 4
+ * border_bottom_width 3 + 5 4 + sizeof(ptr)
* border_collapse 2
* border_left_color 2 4
* border_left_style 4
@@ -32,7 +32,7 @@ struct css_computed_style_i {
* border_top_color 2 4
* border_top_style 4
* border_top_width 3 + 5 4
- * bottom 2 + 5 4
+ * bottom 2 + 5 4 + sizeof(ptr)
* box_sizing 2
* break_after 4
* break_before 4
@@ -140,9 +140,9 @@ struct css_computed_style_i {
* quotes 1 sizeof(ptr)
*
* --- --- ---
- * 462 bits 228 + 8sizeof(ptr) bytes
+ * 462 bits 228 + 10sizeof(ptr) bytes
* ===================
- * 286 + 8sizeof(ptr) bytes
+ * 286 + 10sizeof(ptr) bytes
*
* Bit allocations:
*
@@ -209,7 +209,10 @@ struct css_computed_style_i {
css_fixed background_position_a;
css_fixed background_position_b;
css_color border_bottom_color;
- css_fixed border_bottom_width;
+ union {
+ css_fixed value;
+ lwc_string *calc;
+ } border_bottom_width;
css_color border_left_color;
css_fixed border_left_width;
css_color border_right_color;
@@ -218,7 +221,10 @@ struct css_computed_style_i {
css_fixed border_spacing_b;
css_color border_top_color;
css_fixed border_top_width;
- css_fixed bottom;
+ union {
+ css_fixed value;
+ lwc_string *calc;
+ } bottom;
css_fixed clip_a;
css_fixed clip_b;
css_fixed clip_c;
diff --git a/src/select/autogenerated_propget.h b/src/select/autogenerated_propget.h
index cf82c86..2751a18 100644
--- a/src/select/autogenerated_propget.h
+++ b/src/select/autogenerated_propget.h
@@ -202,7 +202,7 @@ static inline uint8_t get_border_bottom_width(const css_computed_style *style,
/* 8bits: uuuuuttt : unit | type */
if ((bits & 0x7) == CSS_BORDER_WIDTH_WIDTH) {
- *length = style->i.border_bottom_width;
+ *length = style->i.border_bottom_width.value;
*unit = bits >> 3;
}
@@ -431,32 +431,21 @@ static inline uint8_t get_border_top_width(const css_computed_style *style,
#define BOTTOM_INDEX 3
#define BOTTOM_SHIFT 11
#define BOTTOM_MASK 0x3f800
-static inline uint8_t get_bottom(
- const css_computed_style *style,
- css_fixed *length, css_unit *unit)
+static inline uint8_t get_bottom(const css_computed_style *style, css_fixed
+ *length, css_unit *unit)
{
uint32_t bits = style->i.bits[BOTTOM_INDEX];
bits &= BOTTOM_MASK;
bits >>= BOTTOM_SHIFT;
-
- /* 7bits: uuuuutt : units | type */
+
+ /* 7bits: uuuuutt : unit | type */
if ((bits & 0x3) == CSS_BOTTOM_SET) {
- *length = style->i.bottom;
+ *length = style->i.bottom.value;
*unit = bits >> 2;
}
-
+
return (bits & 0x3);
}
-static inline uint8_t get_bottom_bits(
- const css_computed_style *style)
-{
- uint32_t bits = style->i.bits[BOTTOM_INDEX];
- bits &= BOTTOM_MASK;
- bits >>= BOTTOM_SHIFT;
-
- /* 7bits: uuuuutt : units | type */
- return bits;
-}
#undef BOTTOM_INDEX
#undef BOTTOM_SHIFT
#undef BOTTOM_MASK
diff --git a/src/select/autogenerated_propset.h b/src/select/autogenerated_propset.h
index 036c2ba..317fb2a 100644
--- a/src/select/autogenerated_propset.h
+++ b/src/select/autogenerated_propset.h
@@ -244,6 +244,17 @@ static inline css_error set_border_bottom_style(css_computed_style *style,
static inline css_error set_border_bottom_width(css_computed_style *style,
uint8_t type, css_fixed length, css_unit unit)
{
+ uint32_t orig_bits = style->i.bits[BORDER_BOTTOM_WIDTH_INDEX];
+ orig_bits &= BORDER_BOTTOM_WIDTH_MASK;
+ orig_bits >>= BORDER_BOTTOM_WIDTH_SHIFT;
+
+ /* 8bits: uuuuuttt : unit | type */
+ if ((orig_bits & 0x7) == CSS_BORDER_WIDTH_WIDTH) {
+ if ((orig_bits & 0xf8) >> 3 == CSS_UNIT_CALC) {
+ lwc_string_unref(style->i.border_bottom_width.calc);
+ }
+ }
+
uint32_t *bits;
bits = &style->i.bits[BORDER_BOTTOM_WIDTH_INDEX];
@@ -252,7 +263,7 @@ static inline css_error set_border_bottom_width(css_computed_style *style,
*bits = (*bits & ~BORDER_BOTTOM_WIDTH_MASK) | ((((uint32_t)type & 0x7)
| (unit << 3)) << BORDER_BOTTOM_WIDTH_SHIFT);
- style->i.border_bottom_width = length;
+ style->i.border_bottom_width.value = length;
return CSS_OK;
}
@@ -515,6 +526,17 @@ static inline css_error set_border_top_width(css_computed_style *style, uint8_t
static inline css_error set_bottom(css_computed_style *style, uint8_t type,
css_fixed length, css_unit unit)
{
+ uint32_t orig_bits = style->i.bits[BOTTOM_INDEX];
+ orig_bits &= BOTTOM_MASK;
+ orig_bits >>= BOTTOM_SHIFT;
+
+ /* 7bits: uuuuutt : unit | type */
+ if ((orig_bits & 0x3) == CSS_BOTTOM_SET) {
+ if ((orig_bits & 0x7c) >> 2 == CSS_UNIT_CALC) {
+ lwc_string_unref(style->i.bottom.calc);
+ }
+ }
+
uint32_t *bits;
bits = &style->i.bits[BOTTOM_INDEX];
@@ -523,7 +545,7 @@ static inline css_error set_bottom(css_computed_style *style, uint8_t type,
*bits = (*bits & ~BOTTOM_MASK) | ((((uint32_t)type & 0x3) | (unit <<
2)) << BOTTOM_SHIFT);
- style->i.bottom = length;
+ style->i.bottom.value = length;
return CSS_OK;
}
diff --git a/src/select/overrides.py b/src/select/overrides.py
index b4d349a..1336976 100644
--- a/src/select/overrides.py
+++ b/src/select/overrides.py
@@ -213,5 +213,5 @@ static inline uint8_t get_{0}_bits(
}}'''
overrides['get']['top'] = get_side.format('top', 'TOP')
overrides['get']['right'] = get_side.format('right', 'RIGHT')
-overrides['get']['bottom'] = get_side.format('bottom', 'BOTTOM')
+#overrides['get']['bottom'] = get_side.format('bottom', 'BOTTOM')
overrides['get']['left'] = get_side.format('left', 'LEFT')
diff --git a/src/select/select_config.py b/src/select/select_config.py
index fd9e765..6e1ebeb 100644
--- a/src/select/select_config.py
+++ b/src/select/select_config.py
@@ -13,6 +13,7 @@ values = {
('integer', 'int32_t', 4, '0'),
('fixed', 'css_fixed', 4, '0'),
('color', 'css_color', 4, '0'),
+ ('calc', 'lwc_string*'),
('string', 'lwc_string*'),
('string_arr', 'lwc_string**'),
('counter_arr', 'css_computed_counter*'),
@@ -72,11 +73,11 @@ style = {
('border_left_color', 2, 'color'),
('border_top_width', 3, 'length', 'CSS_BORDER_WIDTH_WIDTH'),
('border_right_width', 3, 'length', 'CSS_BORDER_WIDTH_WIDTH'),
- ('border_bottom_width', 3, 'length', 'CSS_BORDER_WIDTH_WIDTH'),
+ ('border_bottom_width', 3, (('length',), ('calc',)), 'CSS_BORDER_WIDTH_WIDTH'),
('border_left_width', 3, 'length', 'CSS_BORDER_WIDTH_WIDTH'),
('top', 2, 'length', 'CSS_TOP_SET', None, None, 'get'),
('right', 2, 'length', 'CSS_RIGHT_SET', None, None, 'get'),
- ('bottom', 2, 'length', 'CSS_BOTTOM_SET', None, None, 'get'),
+ ('bottom', 2, (('length',), ('calc',)), 'CSS_BOTTOM_SET', None, None, 'get'),
('left', 2, 'length', 'CSS_LEFT_SET', None, None, 'get'),
('color', 1, 'color'),
('flex_basis', 2, 'length', 'CSS_FLEX_BASIS_SET'),
diff --git a/src/select/select_generator.py b/src/select/select_generator.py
index ece7a91..4f6ee68 100644
--- a/src/select/select_generator.py
+++ b/src/select/select_generator.py
@@ -223,6 +223,13 @@ class CSSProperty:
def make_values(self, vals):
"""Make list of values for this property."""
+ self.has_calc = False
+
+ if vals is not None and any(val[0] == 'calc' for val in vals):
+ self.has_calc = True
+
+ print(f"name: {self.name}, {vals}, has calc: {self.has_calc}")
+
if vals is None:
return []
elif type(vals) is str:
@@ -235,7 +242,10 @@ class CSSProperty:
value = CSSValue(*x)
if len(v) == 2:
value.defaults = v[1]
- if len(vals) > 1:
+ subtraction = 0
+ if self.has_calc:
+ subtraction = 1
+ if len(vals) - subtraction > 1 and v[0] != 'calc':
value.suffix = '_' + string.ascii_lowercase[i]
val_list.append(value)
break
@@ -322,6 +332,8 @@ class CSSProperty:
"""
vals = []
for v in self.values:
+ if v.name == 'calc':
+ continue
vt, vn = shift_star(v.type, v.name)
vn += v.suffix
if pointer:
@@ -608,6 +620,29 @@ class CSSGroup:
t.append('{')
t.indent(1)
+ # Ensure any existing calc() values are freed
+ if p.has_calc:
+ t.append('uint32_t orig_bits = style{}->{}bits[{}_INDEX];'.format(
+ grp, i_dot, p.name.upper()))
+ t.append('orig_bits &= {}_MASK;'.format(p.name.upper()))
+ t.append('orig_bits >>= {}_SHIFT;'.format(p.name.upper()))
+ t.append()
+
+ type_mask, shift_list, bits_comment = p.get_bits()
+ t.append(bits_comment)
+ t.append('if ((orig_bits & {}) == {}) {{'.format(type_mask, p.condition))
+ t.indent(1)
+ for i, v in enumerate(list(reversed(shift_list))):
+ t.append('if ((orig_bits & 0x{:x}) >> {} == CSS_UNIT_CALC) {{'.format(v[2], v[1]))
+ t.indent(1)
+ this_idot = i_dot
+ t.append('lwc_string_unref(style->{}{}.calc);'.format(this_idot, p.name))
+ t.indent(-1)
+ t.append('}')
+ t.indent(-1)
+ t.append('}')
+ t.append()
+
t.append('uint32_t *bits;')
t.append()
@@ -633,6 +668,9 @@ class CSSGroup:
t.append()
for v in p.values:
+ if v.name == 'calc':
+ continue
+
old_n = 'old_' + v.name + v.suffix
old_t, old_n_shift = shift_star(v.type, old_n)
@@ -693,8 +731,9 @@ class CSSGroup:
t.append('}')
elif not v.is_ptr:
- t.append('style{}->{}{} = {};'.format(
- grp, i_dot, p.name + v.suffix, v.name + v.suffix))
+ dot_value = '.value' if p.has_calc else ''
+ t.append('style->{}{}{} = {};'.format(
+ i_dot, p.name + v.suffix, dot_value, v.name + v.suffix))
else:
raise ValueError('Cannot handle value ' + v.name +'!')
@@ -750,9 +789,13 @@ class CSSGroup:
t.indent(1)
for v in p.values:
+ print(f"name: {p.name}, has_calc: {p.has_calc}, v.name: {v.name}")
+ if v.name == 'calc':
+ continue
this_idot = '' if v.is_ptr and v.name != 'string' else i_dot
- t.append('*{} = style{}->{}{};'.format(
- v.name + v.suffix, grp, this_idot, p.name + v.suffix))
+ dot_value = '.value' if p.has_calc else ''
+ t.append('*{} = style->{}{}{};'.format(
+ v.name + v.suffix, this_idot, p.name + v.suffix, dot_value))
for i, v in enumerate(list(reversed(shift_list))):
if i == 0:
t.append('*{} = bits >> {};'.format(v[0], v[1]))
@@ -796,13 +839,31 @@ class CSSGroup:
r = []
for p in sorted(self.props, key=(lambda x: x.name)):
if bool(p.comments) == for_commented:
- for v in p.values:
- if defaults:
+ if defaults:
+ for v in p.values:
r.append('.{}{} = {}'.format(p.name, v.suffix,
v.defaults))
+ else:
+ if (p.values == None or len(p.values) == 0):
+ continue
+ if p.has_calc == True:
+ calc = None
+ for v in p.values:
+ if v.name == 'calc':
+ calc = v
+ for v in p.values:
+ if v.name != 'calc':
+ r.append('union {')
+ v_type, v_name = shift_star(v.type, "value")
+ r.append('\t{} {};'.format(v_type, v_name))
+ if calc != None:
+ v_type, v_name = shift_star(calc.type, calc.name)
+ r.append('\t{} {}{};'.format(v_type, v_name, calc.suffix))
+ r.append('}} {}{};'.format(p.name, v.suffix))
else:
- v_type, v_name = shift_star(v.type, p.name)
- r.append('{} {}{};'.format(v_type, v_name, v.suffix))
+ for v in p.values:
+ v_type, v_name = shift_star(v.type, p.name)
+ r.append('{} {}{};'.format(v_type, v_name, v.suffix))
return r
def make_text(self, filename):
-----------------------------------------------------------------------
--
Cascading Style Sheets library
4 months
netsurf: branch dsilvers/tokenlist updated. release/3.10-331-g550900b
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/550900b1cbfffcd3ceb5c...
...commit http://git.netsurf-browser.org/netsurf.git/commit/550900b1cbfffcd3ceb5c00...
...tree http://git.netsurf-browser.org/netsurf.git/tree/550900b1cbfffcd3ceb5c0063...
The branch, dsilvers/tokenlist has been updated
via 550900b1cbfffcd3ceb5c00631bcbae2b453443c (commit)
from f29f12a5df255f252987e8acf92994e40125aff6 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=550900b1cbfffcd3ceb...
commit 550900b1cbfffcd3ceb5c00631bcbae2b453443c
Author: Daniel Silverstone <dsilvers(a)digital-scurf.org>
Commit: Daniel Silverstone <dsilvers(a)digital-scurf.org>
(Element): Honour [SameObject] for ::classList getter
Signed-off-by: Daniel Silverstone <dsilvers(a)digital-scurf.org>
diff --git a/content/handlers/javascript/duktape/Element.bnd b/content/handlers/javascript/duktape/Element.bnd
index 677a957..ff0686f 100644
--- a/content/handlers/javascript/duktape/Element.bnd
+++ b/content/handlers/javascript/duktape/Element.bnd
@@ -397,19 +397,29 @@ getter Element::classList ()
dom_exception exc;
dom_tokenlist *tokens;
- exc = dom_tokenlist_create((dom_element *)priv->parent.node, corestring_dom_class, &tokens);
- if (exc != DOM_NO_ERR) return 0; /* Coerced to undefined */
+ duk_set_top(ctx, 0);
+ duk_push_this(ctx);
+ duk_get_prop_string(ctx, 0, MAGIC(classList));
- /* Create a settable tokenlist - While the IDL says this isn't settable, all browsers
- * seem to make it settable, so we'll permit it too
- */
- duk_push_pointer(ctx, tokens);
- if (dukky_create_object(ctx, PROTO_NAME(DOMSETTABLETOKENLIST), 1) != DUK_EXEC_SUCCESS) {
+ if (duk_is_undefined(ctx, -1)) {
+ duk_pop(ctx);
+ exc = dom_tokenlist_create((dom_element *)priv->parent.node, corestring_dom_class, &tokens);
+ if (exc != DOM_NO_ERR) return 0; /* Coerced to undefined */
+
+ /* Create a settable tokenlist - While the IDL says this isn't settable, all browsers
+ * seem to make it settable, so we'll permit it too
+ */
+ duk_push_pointer(ctx, tokens);
+ if (dukky_create_object(ctx, PROTO_NAME(DOMSETTABLETOKENLIST), 1) != DUK_EXEC_SUCCESS) {
+ dom_tokenlist_unref(tokens);
+ NSLOG(dukky, DEBUG, "Unable to create DOMSettableTokenList object");
+ return 0; /* Coerced to undefined */
+ }
dom_tokenlist_unref(tokens);
- NSLOG(dukky, DEBUG, "Unable to create DOMSettableTokenList object");
- return 0; /* Coerced to undefined */
+ duk_dup(ctx, -1);
+ duk_put_prop_string(ctx, 0, MAGIC(classList));
}
- dom_tokenlist_unref(tokens);
+
return 1;
%}
-----------------------------------------------------------------------
Summary of changes:
content/handlers/javascript/duktape/Element.bnd | 30 +++++++++++++++--------
1 file changed, 20 insertions(+), 10 deletions(-)
diff --git a/content/handlers/javascript/duktape/Element.bnd b/content/handlers/javascript/duktape/Element.bnd
index 677a957..ff0686f 100644
--- a/content/handlers/javascript/duktape/Element.bnd
+++ b/content/handlers/javascript/duktape/Element.bnd
@@ -397,19 +397,29 @@ getter Element::classList ()
dom_exception exc;
dom_tokenlist *tokens;
- exc = dom_tokenlist_create((dom_element *)priv->parent.node, corestring_dom_class, &tokens);
- if (exc != DOM_NO_ERR) return 0; /* Coerced to undefined */
+ duk_set_top(ctx, 0);
+ duk_push_this(ctx);
+ duk_get_prop_string(ctx, 0, MAGIC(classList));
- /* Create a settable tokenlist - While the IDL says this isn't settable, all browsers
- * seem to make it settable, so we'll permit it too
- */
- duk_push_pointer(ctx, tokens);
- if (dukky_create_object(ctx, PROTO_NAME(DOMSETTABLETOKENLIST), 1) != DUK_EXEC_SUCCESS) {
+ if (duk_is_undefined(ctx, -1)) {
+ duk_pop(ctx);
+ exc = dom_tokenlist_create((dom_element *)priv->parent.node, corestring_dom_class, &tokens);
+ if (exc != DOM_NO_ERR) return 0; /* Coerced to undefined */
+
+ /* Create a settable tokenlist - While the IDL says this isn't settable, all browsers
+ * seem to make it settable, so we'll permit it too
+ */
+ duk_push_pointer(ctx, tokens);
+ if (dukky_create_object(ctx, PROTO_NAME(DOMSETTABLETOKENLIST), 1) != DUK_EXEC_SUCCESS) {
+ dom_tokenlist_unref(tokens);
+ NSLOG(dukky, DEBUG, "Unable to create DOMSettableTokenList object");
+ return 0; /* Coerced to undefined */
+ }
dom_tokenlist_unref(tokens);
- NSLOG(dukky, DEBUG, "Unable to create DOMSettableTokenList object");
- return 0; /* Coerced to undefined */
+ duk_dup(ctx, -1);
+ duk_put_prop_string(ctx, 0, MAGIC(classList));
}
- dom_tokenlist_unref(tokens);
+
return 1;
%}
--
NetSurf Browser
4 months
netsurf: branch dsilvers/tokenlist updated. release/3.10-330-gf29f12a
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/f29f12a5df255f252987e...
...commit http://git.netsurf-browser.org/netsurf.git/commit/f29f12a5df255f252987e8a...
...tree http://git.netsurf-browser.org/netsurf.git/tree/f29f12a5df255f252987e8acf...
The branch, dsilvers/tokenlist has been updated
via f29f12a5df255f252987e8acf92994e40125aff6 (commit)
from 7bcd4fd2465631f4a17e1920594e9c2536b6f057 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=f29f12a5df255f25298...
commit f29f12a5df255f252987e8acf92994e40125aff6
Author: Daniel Silverstone <dsilvers(a)digital-scurf.org>
Commit: Daniel Silverstone <dsilvers(a)digital-scurf.org>
(docs): Update the unimplemented JS bits list
Signed-off-by: Daniel Silverstone <dsilvers(a)digital-scurf.org>
diff --git a/docs/UnimplementedJavascript.md b/docs/UnimplementedJavascript.md
index 4a2f02e..0d21dc8 100644
--- a/docs/UnimplementedJavascript.md
+++ b/docs/UnimplementedJavascript.md
@@ -170,7 +170,6 @@ getter | Element::namespaceURI(string);
getter | Element::prefix(string);
getter | Element::localName(string);
getter | Element::tagName(string);
-getter | Element::classList(user);
getter | Element::outerHTML(string);
setter | Element::outerHTML(string);
getter | Element::children(user);
@@ -597,10 +596,6 @@ method | CanvasRenderingContext2D::arcTo();
method | CanvasRenderingContext2D::rect();
method | CanvasRenderingContext2D::arc();
method | CanvasRenderingContext2D::ellipse();
-getter | CanvasRenderingContext2D::width(unsigned long);
-setter | CanvasRenderingContext2D::width(unsigned long);
-getter | CanvasRenderingContext2D::height(unsigned long);
-setter | CanvasRenderingContext2D::height(unsigned long);
getter | CanvasRenderingContext2D::currentTransform(user);
setter | CanvasRenderingContext2D::currentTransform(user);
getter | CanvasRenderingContext2D::globalAlpha(double);
@@ -647,8 +642,6 @@ method | HTMLCanvasElement::setContext();
method | HTMLCanvasElement::transferControlToProxy();
method | HTMLCanvasElement::toDataURL();
method | HTMLCanvasElement::toBlob();
-setter | HTMLCanvasElement::width(unsigned long);
-setter | HTMLCanvasElement::height(unsigned long);
getter | HTMLTemplateElement::content(user);
getter | HTMLScriptElement::async(boolean);
setter | HTMLScriptElement::async(boolean);
@@ -1344,14 +1337,6 @@ method | HTMLAllCollection::namedItem();
getter | HTMLAllCollection::length(unsigned long);
method | XMLSerializer::serializeToString();
method | DOMParser::parseFromString();
-method | DOMTokenList::item();
-method | DOMTokenList::contains();
-method | DOMTokenList::add();
-method | DOMTokenList::remove();
-method | DOMTokenList::toggle();
-getter | DOMTokenList::length(unsigned long);
-getter | DOMSettableTokenList::value(string);
-setter | DOMSettableTokenList::value(string);
method | NodeFilter::acceptNode();
method | TreeWalker::parentNode();
method | TreeWalker::firstChild();
@@ -1560,5 +1545,5 @@ method | EventListener::handleEvent();
method | CustomEvent::initCustomEvent();
getter | CustomEvent::detail(any);
- 1554 unimplemented bindings
+ 1539 unimplemented bindings
-----------------------------------------------------------------------
Summary of changes:
docs/UnimplementedJavascript.md | 17 +----------------
1 file changed, 1 insertion(+), 16 deletions(-)
diff --git a/docs/UnimplementedJavascript.md b/docs/UnimplementedJavascript.md
index 4a2f02e..0d21dc8 100644
--- a/docs/UnimplementedJavascript.md
+++ b/docs/UnimplementedJavascript.md
@@ -170,7 +170,6 @@ getter | Element::namespaceURI(string);
getter | Element::prefix(string);
getter | Element::localName(string);
getter | Element::tagName(string);
-getter | Element::classList(user);
getter | Element::outerHTML(string);
setter | Element::outerHTML(string);
getter | Element::children(user);
@@ -597,10 +596,6 @@ method | CanvasRenderingContext2D::arcTo();
method | CanvasRenderingContext2D::rect();
method | CanvasRenderingContext2D::arc();
method | CanvasRenderingContext2D::ellipse();
-getter | CanvasRenderingContext2D::width(unsigned long);
-setter | CanvasRenderingContext2D::width(unsigned long);
-getter | CanvasRenderingContext2D::height(unsigned long);
-setter | CanvasRenderingContext2D::height(unsigned long);
getter | CanvasRenderingContext2D::currentTransform(user);
setter | CanvasRenderingContext2D::currentTransform(user);
getter | CanvasRenderingContext2D::globalAlpha(double);
@@ -647,8 +642,6 @@ method | HTMLCanvasElement::setContext();
method | HTMLCanvasElement::transferControlToProxy();
method | HTMLCanvasElement::toDataURL();
method | HTMLCanvasElement::toBlob();
-setter | HTMLCanvasElement::width(unsigned long);
-setter | HTMLCanvasElement::height(unsigned long);
getter | HTMLTemplateElement::content(user);
getter | HTMLScriptElement::async(boolean);
setter | HTMLScriptElement::async(boolean);
@@ -1344,14 +1337,6 @@ method | HTMLAllCollection::namedItem();
getter | HTMLAllCollection::length(unsigned long);
method | XMLSerializer::serializeToString();
method | DOMParser::parseFromString();
-method | DOMTokenList::item();
-method | DOMTokenList::contains();
-method | DOMTokenList::add();
-method | DOMTokenList::remove();
-method | DOMTokenList::toggle();
-getter | DOMTokenList::length(unsigned long);
-getter | DOMSettableTokenList::value(string);
-setter | DOMSettableTokenList::value(string);
method | NodeFilter::acceptNode();
method | TreeWalker::parentNode();
method | TreeWalker::firstChild();
@@ -1560,5 +1545,5 @@ method | EventListener::handleEvent();
method | CustomEvent::initCustomEvent();
getter | CustomEvent::detail(any);
- 1554 unimplemented bindings
+ 1539 unimplemented bindings
--
NetSurf Browser
4 months
netsurf: branch dsilvers/tokenlist created. release/3.10-329-g7bcd4fd
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/7bcd4fd2465631f4a17e1...
...commit http://git.netsurf-browser.org/netsurf.git/commit/7bcd4fd2465631f4a17e192...
...tree http://git.netsurf-browser.org/netsurf.git/tree/7bcd4fd2465631f4a17e19205...
The branch, dsilvers/tokenlist has been created
at 7bcd4fd2465631f4a17e1920594e9c2536b6f057 (commit)
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=7bcd4fd2465631f4a17...
commit 7bcd4fd2465631f4a17e1920594e9c2536b6f057
Author: Daniel Silverstone <dsilvers(a)digital-scurf.org>
Commit: Daniel Silverstone <dsilvers(a)digital-scurf.org>
DOMTokenList: Add support and testing for this
We add both DOMTokenList and DOMSettableTokenList and introduce
polyfills for stringifying it until nsgenbind can do that.
We also bring in a test to demonstrate all that we have.
Note: This does not implement the extra methods that exist according
to MDN, we may need a polyfill to bring that up to snuff.
Signed-off-by: Daniel Silverstone <dsilvers(a)digital-scurf.org>
diff --git a/content/handlers/javascript/duktape/DOMSettableTokenList.bnd b/content/handlers/javascript/duktape/DOMSettableTokenList.bnd
new file mode 100644
index 0000000..ac5c706
--- /dev/null
+++ b/content/handlers/javascript/duktape/DOMSettableTokenList.bnd
@@ -0,0 +1,44 @@
+/* DOMTokenList binding for browser using duktape and libdom
+ *
+ * Copyright 2015 Vincent Sanders <vince(a)netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * Released under the terms of the MIT License,
+ * http://www.opensource.org/licenses/mit-license
+ */
+
+class DOMSettableTokenList {
+};
+
+init DOMSettableTokenList(struct dom_tokenlist *tokens::tokens);
+
+getter DOMSettableTokenList::value()
+%{
+ dom_exception exc;
+ dom_string *value;
+
+ exc = dom_tokenlist_get_value(priv->parent.tokens, &value);
+ if (exc != DOM_NO_ERR) return 0; /* coerced to undefined */
+
+ duk_push_lstring(ctx, dom_string_data(value), dom_string_length(value));
+ dom_string_unref(value);
+
+ return 1;
+%}
+
+setter DOMSettableTokenList::value()
+%{
+ dom_exception exc;
+ dom_string *value;
+ duk_size_t slen;
+ const char *s = duk_require_lstring(ctx, 0, &slen);
+
+ exc = dom_string_create_interned((const uint8_t *)s, slen, &value);
+ if (exc != DOM_NO_ERR) return 0;
+
+ exc = dom_tokenlist_set_value(priv->parent.tokens, value);
+ dom_string_unref(value);
+
+ return 0;
+%}
\ No newline at end of file
diff --git a/content/handlers/javascript/duktape/DOMTokenList.bnd b/content/handlers/javascript/duktape/DOMTokenList.bnd
new file mode 100644
index 0000000..928d9ef
--- /dev/null
+++ b/content/handlers/javascript/duktape/DOMTokenList.bnd
@@ -0,0 +1,163 @@
+/* DOMTokenList binding for browser using duktape and libdom
+ *
+ * Copyright 2015 Vincent Sanders <vince(a)netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * Released under the terms of the MIT License,
+ * http://www.opensource.org/licenses/mit-license
+ */
+
+class DOMTokenList {
+ private struct dom_tokenlist *tokens;
+};
+
+init DOMTokenList(struct dom_tokenlist *tokens)
+%{
+ priv->tokens = tokens;
+ dom_tokenlist_ref(tokens);
+%}
+
+fini DOMTokenList()
+%{
+ dom_tokenlist_unref(priv->tokens);
+%}
+
+getter DOMTokenList::length()
+%{
+ dom_exception err;
+ uint32_t len;
+
+ err = dom_tokenlist_get_length(priv->tokens, &len);
+
+ if (err != DOM_NO_ERR) return 0; /* coerced to undefined */
+
+ duk_push_uint(ctx, (duk_uint_t)len);
+
+ return 1;
+%}
+
+method DOMTokenList::item()
+%{
+ unsigned long i = duk_to_uint(ctx, 0);
+ dom_exception err;
+ dom_string *value;
+
+ err = dom_tokenlist_item(priv->tokens, i, &value);
+
+ if (err != DOM_NO_ERR) return 0; /* coerced to undefined */
+
+ if (value == NULL) {
+ duk_push_null(ctx);
+ return 1;
+ }
+
+ duk_push_lstring(ctx, dom_string_data(value), dom_string_length(value));
+ dom_string_unref(value);
+
+ return 1;
+%}
+
+method DOMTokenList::add()
+%{
+ dom_exception exc;
+ dom_string *value;
+ duk_size_t slen;
+ const char *s;
+ duk_idx_t spos;
+
+ for (spos = 0; spos < duk_get_top(ctx); ++spos) {
+ s = duk_safe_to_lstring(ctx, spos, &slen);
+
+ duk_safe_to_lstring(ctx, 0, &slen);
+
+ exc = dom_string_create_interned((const uint8_t *)s, slen, &value);
+ if (exc != DOM_NO_ERR) return 0;
+
+ exc = dom_tokenlist_add(priv->tokens, value);
+ dom_string_unref(value);
+ }
+
+ return 0;
+%}
+
+method DOMTokenList::remove()
+%{
+ dom_exception exc;
+ dom_string *value;
+ duk_size_t slen;
+ const char *s;
+ duk_idx_t spos;
+
+ for (spos = 0; spos < duk_get_top(ctx); ++spos) {
+ s = duk_safe_to_lstring(ctx, spos, &slen);
+
+ duk_safe_to_lstring(ctx, 0, &slen);
+
+ exc = dom_string_create_interned((const uint8_t *)s, slen, &value);
+ if (exc != DOM_NO_ERR) return 0;
+
+ exc = dom_tokenlist_remove(priv->tokens, value);
+ dom_string_unref(value);
+ }
+
+ return 0;
+%}
+
+method DOMTokenList::contains()
+%{
+ dom_exception exc;
+ dom_string *value;
+ duk_size_t slen;
+ const char *s = duk_safe_to_lstring(ctx, 0, &slen);
+ bool present = false;
+
+ exc = dom_string_create_interned((const uint8_t *)s, slen, &value);
+ if (exc != DOM_NO_ERR) return 0;
+
+ exc = dom_tokenlist_contains(priv->tokens, value, &present);
+ dom_string_unref(value);
+ if (exc != DOM_NO_ERR) return 0;
+
+ duk_push_boolean(ctx, present);
+
+ return 1;
+%}
+
+method DOMTokenList::toggle()
+%{
+ dom_exception exc;
+ dom_string *value;
+ duk_size_t slen;
+ const char *s = duk_require_lstring(ctx, 0, &slen);
+ bool toggle_set = duk_get_top(ctx) > 1;
+ bool toggle = duk_opt_boolean(ctx, 1, 0);
+ bool present;
+
+ exc = dom_string_create_interned((const uint8_t *)s, slen, &value);
+ if (exc != DOM_NO_ERR) return 0;
+
+ exc = dom_tokenlist_contains(priv->tokens, value, &present);
+ if (exc != DOM_NO_ERR) {
+ dom_string_unref(value);
+ return 0;
+ }
+
+ /* Decision matrix is based on present, toggle_set, and toggle */
+ if (toggle_set) {
+ if (toggle) {
+ exc = dom_tokenlist_add(priv->tokens, value);
+ } else {
+ exc = dom_tokenlist_remove(priv->tokens, value);
+ }
+ } else {
+ if (present) {
+ exc = dom_tokenlist_add(priv->tokens, value);
+ } else {
+ exc = dom_tokenlist_remove(priv->tokens, value);
+ }
+ }
+ dom_string_unref(value);
+
+ return 0;
+%}
\ No newline at end of file
diff --git a/content/handlers/javascript/duktape/Element.bnd b/content/handlers/javascript/duktape/Element.bnd
index a965a6c..677a957 100644
--- a/content/handlers/javascript/duktape/Element.bnd
+++ b/content/handlers/javascript/duktape/Element.bnd
@@ -392,6 +392,27 @@ setter Element::className ()
return 0;
%}
+getter Element::classList ()
+%{
+ dom_exception exc;
+ dom_tokenlist *tokens;
+
+ exc = dom_tokenlist_create((dom_element *)priv->parent.node, corestring_dom_class, &tokens);
+ if (exc != DOM_NO_ERR) return 0; /* Coerced to undefined */
+
+ /* Create a settable tokenlist - While the IDL says this isn't settable, all browsers
+ * seem to make it settable, so we'll permit it too
+ */
+ duk_push_pointer(ctx, tokens);
+ if (dukky_create_object(ctx, PROTO_NAME(DOMSETTABLETOKENLIST), 1) != DUK_EXEC_SUCCESS) {
+ dom_tokenlist_unref(tokens);
+ NSLOG(dukky, DEBUG, "Unable to create DOMSettableTokenList object");
+ return 0; /* Coerced to undefined */
+ }
+ dom_tokenlist_unref(tokens);
+ return 1;
+%}
+
getter Element::innerHTML()
%{
duk_push_lstring(ctx, "", 0);
diff --git a/content/handlers/javascript/duktape/netsurf.bnd b/content/handlers/javascript/duktape/netsurf.bnd
index 651c2fd..483f347 100644
--- a/content/handlers/javascript/duktape/netsurf.bnd
+++ b/content/handlers/javascript/duktape/netsurf.bnd
@@ -60,6 +60,8 @@ struct dom_html_br_element;
#include "Document.bnd"
#include "Node.bnd"
#include "NodeList.bnd"
+#include "DOMTokenList.bnd"
+#include "DOMSettableTokenList.bnd"
#include "NamedNodeMap.bnd"
#include "Element.bnd"
#include "HTMLCollection.bnd"
diff --git a/content/handlers/javascript/duktape/polyfill.js b/content/handlers/javascript/duktape/polyfill.js
index 5f02156..6c85ce1 100644
--- a/content/handlers/javascript/duktape/polyfill.js
+++ b/content/handlers/javascript/duktape/polyfill.js
@@ -83,3 +83,21 @@ if (!Array.from) {
};
}());
}
+
+// DOMTokenList formatter, in theory we can remove this if we do the stringifier IDL support
+
+DOMTokenList.prototype.toString = function () {
+ if (this.length == 0) {
+ return "";
+ }
+
+ var ret = this.item(0);
+ for (var index = 1; index < this.length; index++) {
+ ret = ret + " " + this.item(index);
+ }
+
+ return ret;
+}
+
+// Inherit the same toString for settable lists
+DOMSettableTokenList.prototype.toString = DOMTokenList.prototype.toString;
\ No newline at end of file
diff --git a/test/js/class-list.html b/test/js/class-list.html
new file mode 100644
index 0000000..4c73283
--- /dev/null
+++ b/test/js/class-list.html
@@ -0,0 +1,29 @@
+<html>
+ <head>
+ <title>Class List (and other token lists?)</title>
+ <style>
+ .bad { background-color: red; }
+ .ok { background-color: green; }
+ </style>
+ </head>
+ <body>
+ <h1>This is a set of demonstrators for the token list Element.classList</h1>
+ <h2>This first is taken from the MDN for DOMTokenList</h2>
+ <span id="demo1" class=" d d e f bad"></span>
+ <script>
+ var span = document.getElementById("demo1");
+ var classes = span.classList;
+ classes.add("x", "d", "g");
+ classes.remove("e", "g");
+ classes.toggle("d"); // Toggles d off
+ classes.toggle("q", false); // Forces q off (won't be present)
+ classes.toggle("d"); // Toggles d on
+ classes.toggle("d", true); // Forces d on (won't toggle it off again)
+ if (classes.contains("d")) {
+ classes.add("ok")
+ classes.remove("bad")
+ span.textContent = "span classList is \"" + classes + '"';
+ }
+ </script>
+ </body>
+</html>
diff --git a/test/js/index.html b/test/js/index.html
index 0329467..6d2c654 100644
--- a/test/js/index.html
+++ b/test/js/index.html
@@ -104,6 +104,7 @@
<li><a href="assorted-log-doc-write.html">console.log and document.write</a></li>
<li><a href="wikipedia-lcm.html">Example from wikipedia</a></li>
<li><a href="verify-instanceofness.html">Check instanceof behaviour</a></li>
+<li><a href="class-list.html">Class list (and other token lists?)</a></li>
<li><a href="mandelbrot.html">Canvas/ImageData Mandelbrot ploter</a></li>
<li><a href="life.html">Game of Life</a></li>
</ul>
-----------------------------------------------------------------------
--
NetSurf Browser
4 months
libdom: branch dsilvers/tokenlist created. release/0.4.1-22-gad4cdc9
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libdom.git/shortlog/ad4cdc900f197c0f373615...
...commit http://git.netsurf-browser.org/libdom.git/commit/ad4cdc900f197c0f373615d4...
...tree http://git.netsurf-browser.org/libdom.git/tree/ad4cdc900f197c0f373615d454...
The branch, dsilvers/tokenlist has been created
at ad4cdc900f197c0f373615d454275f38a9c4d181 (commit)
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/libdom.git/commit/?id=ad4cdc900f197c0f3736...
commit ad4cdc900f197c0f373615d454275f38a9c4d181
Author: Daniel Silverstone <dsilvers(a)digital-scurf.org>
Commit: Daniel Silverstone <dsilvers(a)digital-scurf.org>
DOMTokenList: Initial implementation.
We cover the core behaviours of DOMTokenList and also
DOMSettableTokenList so that the IDL can be implemented in NetSurf.
Signed-off-by: Daniel Silverstone <dsilvers(a)digital-scurf.org>
diff --git a/Makefile b/Makefile
index 8d9df61..a539ff7 100644
--- a/Makefile
+++ b/Makefile
@@ -69,7 +69,7 @@ INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/entity_ref.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/element.h;$(Is)/exceptions.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/implementation.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/namednodemap.h;$(Is)/node.h
-INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/nodelist.h;$(Is)/string.h
+INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/nodelist.h;$(Is)/tokenlist.h;$(Is)/string.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/pi.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/text.h;$(Is)/typeinfo.h
diff --git a/include/dom/core/tokenlist.h b/include/dom/core/tokenlist.h
new file mode 100644
index 0000000..718d3a5
--- /dev/null
+++ b/include/dom/core/tokenlist.h
@@ -0,0 +1,43 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2022 Daniel Silverstone <dsilvers(a)netsurf-browser.org>
+ */
+
+#ifndef dom_core_tokenlist_h_
+#define dom_core_tokenlist_h_
+
+#include <dom/core/exceptions.h>
+
+struct dom_element;
+struct dom_string;
+
+typedef struct dom_tokenlist dom_tokenlist;
+
+void dom_tokenlist_ref(struct dom_tokenlist *list);
+void dom_tokenlist_unref(struct dom_tokenlist *list);
+
+dom_exception dom_tokenlist_create(struct dom_element *ele, struct dom_string *attr, dom_tokenlist **list);
+
+dom_exception dom_tokenlist_get_length(struct dom_tokenlist *list,
+ uint32_t *length);
+dom_exception _dom_tokenlist_item(struct dom_tokenlist *list,
+ uint32_t index, struct dom_string **value);
+
+#define dom_tokenlist_item(l, i, n) _dom_tokenlist_item((dom_tokenlist *) (l), \
+ (uint32_t) (i), (struct dom_string **) (n))
+
+dom_exception dom_tokenlist_get_value(struct dom_tokenlist *list,
+ struct dom_string **value);
+
+dom_exception dom_tokenlist_set_value(struct dom_tokenlist *list,
+ struct dom_string *value);
+
+dom_exception dom_tokenlist_contains(struct dom_tokenlist *list, struct dom_string *value, bool *contains);
+
+dom_exception dom_tokenlist_add(struct dom_tokenlist *list, struct dom_string *value);
+
+dom_exception dom_tokenlist_remove(struct dom_tokenlist *list, struct dom_string *value);
+
+#endif
diff --git a/include/dom/dom.h b/include/dom/dom.h
index c10e5a6..00bf3d9 100644
--- a/include/dom/dom.h
+++ b/include/dom/dom.h
@@ -32,6 +32,7 @@
#include <dom/core/doc_fragment.h>
#include <dom/core/entity_ref.h>
#include <dom/core/nodelist.h>
+#include <dom/core/tokenlist.h>
#include <dom/core/string.h>
#include <dom/core/text.h>
#include <dom/core/pi.h>
diff --git a/src/core/Makefile b/src/core/Makefile
index 41fd51f..5d9c969 100644
--- a/src/core/Makefile
+++ b/src/core/Makefile
@@ -6,6 +6,6 @@ DIR_SOURCES := \
text.c typeinfo.c comment.c \
namednodemap.c nodelist.c \
cdatasection.c document_type.c entity_ref.c pi.c \
- doc_fragment.c document.c
+ doc_fragment.c document.c tokenlist.c
include $(NSBUILD)/Makefile.subdir
diff --git a/src/core/tokenlist.c b/src/core/tokenlist.c
new file mode 100644
index 0000000..c227b31
--- /dev/null
+++ b/src/core/tokenlist.c
@@ -0,0 +1,547 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2022 Daniel Silverstone <dsilvers(a)digital-scurf.org>
+ */
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <dom/core/element.h>
+#include <dom/core/nodelist.h>
+#include <dom/core/tokenlist.h>
+#include <dom/core/string.h>
+#include <dom/events/event.h>
+#include <dom/events/event_target.h>
+#include <dom/events/event_listener.h>
+#include <dom/events/mutation_event.h>
+
+#include "core/element.h"
+#include "core/document.h"
+
+#include "utils/utils.h"
+
+#define DOM_TOKENLIST_GROW_INCREMENT 4
+
+struct dom_tokenlist {
+ uint32_t refcnt;
+ dom_element *ele;
+ dom_string *attr;
+ dom_event_listener *listener;
+ dom_string *last_set;
+ bool needs_parse;
+ /* Parsed content, for optimal access */
+ dom_string **entries;
+ uint32_t len;
+ uint32_t alloc;
+};
+
+/* Handle a DOMAttrModified event which might be to do with our attribute */
+
+static void _dom_tokenlist_handle_attrmodified(dom_event *evt, void *pw)
+{
+ dom_mutation_event *mutevt = (dom_mutation_event *)evt;
+ dom_tokenlist *list = (dom_tokenlist *)pw;
+ dom_exception exc;
+ dom_string *value;
+
+ {
+ dom_node *target;
+ exc = dom_event_get_target(mutevt, &target);
+ if (exc != DOM_NO_ERR)
+ return;
+ dom_node_unref(target);
+ if (target != (dom_node *)list->ele)
+ return;
+ }
+
+ {
+ dom_string *attr;
+ exc = dom_mutation_event_get_attr_name(mutevt, &attr);
+ if (exc != DOM_NO_ERR)
+ return;
+ if (!dom_string_isequal(attr, list->attr)) {
+ dom_string_unref(attr);
+ return;
+ }
+ dom_string_unref(attr);
+ }
+
+ /* At this point we know that this is a mutation of our attribute on our
+ * node */
+
+ exc = dom_mutation_event_get_new_value(mutevt, &value);
+ if (exc != DOM_NO_ERR)
+ return;
+
+ if (list->last_set != NULL &&
+ dom_string_isequal(list->last_set, value)) {
+ /* We've just seen the mutation event for one of our own set
+ * operations */
+ dom_string_unref(value);
+ return;
+ }
+
+ /* Mark that we need to re-parse the tokenlist on the next request */
+ list->needs_parse = true;
+
+ dom_string_unref(value);
+}
+
+static dom_exception _dom_tokenlist_make_room(dom_tokenlist *list)
+{
+ if (list->len == list->alloc) {
+ uint32_t new_alloc = list->alloc + DOM_TOKENLIST_GROW_INCREMENT;
+ dom_string **new_entries = realloc(
+ list->entries, new_alloc * sizeof(dom_string *));
+ if (new_entries == NULL)
+ return DOM_NO_MEM_ERR;
+ list->alloc = new_alloc;
+ list->entries = new_entries;
+ }
+
+ return DOM_NO_ERR;
+}
+
+static dom_exception _dom_tokenlist_reparse(dom_tokenlist *list)
+{
+ dom_exception exc;
+ dom_string *value;
+ const char *pos;
+ uint32_t remaining, check;
+ uint32_t n_entries = 0;
+ dom_string *temp;
+ bool found;
+
+ if (!list->needs_parse)
+ return DOM_NO_ERR;
+
+ /* Clean down the current entries */
+ while (list->len-- > 0)
+ dom_string_unref(list->entries[list->len]);
+ list->len = 0;
+
+ /* Get the "new" attribute value */
+ exc = dom_element_get_attribute(list->ele, list->attr, &value);
+ if (exc != DOM_NO_ERR)
+ return exc;
+
+ /* If there is no value, we're an empty list and we're done */
+ if (value == NULL) {
+ list->needs_parse = false;
+ return DOM_NO_ERR;
+ }
+
+ /* OK, there's something here to do, so let's do it... */
+
+ /* Count number of entries */
+ for (pos = dom_string_data(value), remaining = dom_string_length(value);
+ remaining > 0;) {
+ if (*pos != ' ') {
+ while (*pos != ' ' && remaining > 0) {
+ remaining--;
+ pos++;
+ }
+ n_entries++;
+ } else {
+ while (*pos == ' ' && remaining > 0) {
+ remaining--;
+ pos++;
+ }
+ }
+ }
+
+ /* If there are no entries (all whitespace) just bail here */
+ if (n_entries == 0) {
+ list->needs_parse = false;
+ dom_string_unref(value);
+ return DOM_NO_ERR;
+ }
+
+ /* If we need more room, reallocate the buffer */
+ if (list->alloc < n_entries) {
+ dom_string **new_alloc = realloc(
+ list->entries, n_entries * sizeof(dom_string *));
+ if (new_alloc == NULL) {
+ dom_string_unref(value);
+ return DOM_NO_MEM_ERR;
+ }
+ list->entries = new_alloc;
+ list->alloc = n_entries;
+ }
+
+ /* And now parse those entries into the buffer */
+ for (pos = dom_string_data(value),
+ remaining = dom_string_length(value),
+ n_entries = 0;
+ remaining > 0;) {
+ if (*pos != ' ') {
+ const char *s = pos;
+ while (*pos != ' ' && remaining > 0) {
+ pos++;
+ remaining--;
+ }
+ exc = dom_string_create_interned((const uint8_t *)s,
+ pos - s,
+ &temp);
+ if (exc != DOM_NO_ERR) {
+ dom_string_unref(value);
+ return exc;
+ }
+ found = false;
+ for (check = 0; check < list->len; check++) {
+ if (dom_string_isequal(temp,
+ list->entries[check])) {
+ found = true;
+ break;
+ }
+ }
+ if (found == true) {
+ dom_string_unref(temp);
+ } else {
+ list->entries[list->len] = temp;
+ list->len++;
+ }
+ } else {
+ while (*pos == ' ' && remaining > 0) {
+ pos++;
+ remaining--;
+ }
+ }
+ }
+
+ dom_string_unref(value);
+ list->needs_parse = false;
+
+ return DOM_NO_ERR;
+}
+
+static dom_exception _dom_tokenlist_reify(dom_tokenlist *list)
+{
+ dom_exception exc;
+ uint32_t nchars = 0, n;
+ char *buffer, *next;
+ dom_string *output;
+
+ if (list->len == 0) {
+ if (list->last_set != NULL) {
+ dom_node_unref(list->last_set);
+ }
+ list->last_set = dom_string_ref(
+ list->ele->base.owner->_memo_empty);
+ return dom_element_set_attribute(list->ele,
+ list->attr,
+ list->last_set);
+ }
+
+ for (n = 0; n < list->len; ++n)
+ nchars += dom_string_length(list->entries[n]);
+
+ buffer = calloc(1, nchars + list->len);
+ if (buffer == NULL)
+ return DOM_NO_MEM_ERR;
+
+ for (next = buffer, n = 0; n < list->len; ++n) {
+ uint32_t slen = dom_string_length(list->entries[n]);
+ memcpy(next, dom_string_data(list->entries[n]), slen);
+ next[slen] = ' ';
+ next += slen + 1;
+ }
+
+ exc = dom_string_create_interned((const uint8_t *)buffer,
+ nchars + list->len - 1,
+ &output);
+ free(buffer);
+ if (exc != DOM_NO_ERR)
+ return exc;
+
+ if (list->last_set != NULL) {
+ dom_string_unref(list->last_set);
+ }
+ list->last_set = output;
+
+ return dom_element_set_attribute(list->ele, list->attr, list->last_set);
+}
+
+/**********************************************************************************/
+
+/**
+ * Create a tokenlist
+ *
+ * \param ele The element which owns the tokenlist attribute
+ * \param attr The name of the attribute we are treating as a tokenlist
+ * \param list The tokenlist output which is set on success
+ * \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion
+ *
+ * The returned list will already be referenced, so the client need not
+ * do so explicitly. The client must unref the list once finished with it.
+ *
+ * This list will take its own references to ::ele and ::attr
+ */
+dom_exception
+dom_tokenlist_create(dom_element *ele, dom_string *attr, dom_tokenlist **list)
+{
+ dom_tokenlist *l;
+ dom_exception exc;
+
+ l = calloc(1, sizeof(dom_tokenlist));
+ if (l == NULL)
+ return DOM_NO_MEM_ERR;
+
+ l->refcnt = 1;
+ l->ele = (dom_element *)dom_node_ref(ele);
+ l->attr = dom_string_ref(attr);
+ l->needs_parse = true;
+
+ exc = dom_event_listener_create(_dom_tokenlist_handle_attrmodified,
+ l,
+ &l->listener);
+ if (exc != DOM_NO_ERR)
+ goto fail;
+
+ exc = dom_event_target_add_event_listener(
+ ele,
+ ele->base.owner->_memo_domattrmodified,
+ l->listener,
+ false);
+
+ if (exc != DOM_NO_ERR)
+ goto fail;
+
+ *list = l;
+
+ return DOM_NO_ERR;
+
+fail:
+ if (l->listener != NULL)
+ dom_event_listener_unref(l->listener);
+ dom_node_unref(l->ele);
+ dom_string_unref(l->attr);
+ free(l);
+ return exc;
+}
+
+/**
+ * Claim a ref on a tokenlist
+ *
+ * \param list The tokenlist to claim a ref on
+ */
+void dom_tokenlist_ref(dom_tokenlist *list)
+{
+ assert(list != NULL);
+ list->refcnt++;
+}
+
+/**
+ * Release a ref on a tokenlist
+ *
+ * \param list The list to release the reference of
+ *
+ * If you release the last ref, this cleans up the tokenlist
+ */
+void dom_tokenlist_unref(dom_tokenlist *list)
+{
+ assert(list != NULL);
+
+ if (--list->refcnt > 0)
+ return;
+
+ if (list->alloc > 0) {
+ while (list->len-- > 0)
+ dom_string_unref(list->entries[list->len]);
+ free(list->entries);
+ }
+
+ dom_event_target_remove_event_listener(
+ list->ele,
+ list->ele->base.owner->_memo_domattrmodified,
+ list->listener,
+ false);
+
+ dom_event_listener_unref(list->listener);
+
+ if (list->last_set != NULL)
+ dom_string_unref(list->last_set);
+
+ dom_string_unref(list->attr);
+ dom_node_unref(list->ele);
+
+ free(list);
+}
+
+/**
+ * Get the length of the tokenlist
+ *
+ * \param list The list to get the length of
+ * \param length Length of the list outputs here
+ * \return DOM_NO_ERR on success, otherwise the failure code
+ */
+dom_exception dom_tokenlist_get_length(dom_tokenlist *list, uint32_t *length)
+{
+ dom_exception exc;
+ assert(list != NULL);
+
+ exc = _dom_tokenlist_reparse(list);
+ if (exc != DOM_NO_ERR)
+ return exc;
+
+ *length = list->len;
+
+ return DOM_NO_ERR;
+}
+
+/**
+ * Get a particular item from the tokenlist
+ *
+ * \param list The list to retrieve the item from
+ * \param index The index of the item to retrieve
+ * \param value The value of the item returns here
+ * \return DOM_NO_ERR on success, otherwise the failure code
+ */
+dom_exception
+_dom_tokenlist_item(dom_tokenlist *list, uint32_t index, dom_string **value)
+{
+ dom_exception exc;
+ assert(list != NULL);
+
+ exc = _dom_tokenlist_reparse(list);
+ if (exc != DOM_NO_ERR)
+ return exc;
+
+ if (index >= list->len) {
+ *value = NULL;
+ return DOM_NO_ERR;
+ }
+
+ *value = dom_string_ref(list->entries[index]);
+ return DOM_NO_ERR;
+}
+
+/**
+ * Retrieve the value of the tokenlist as a string
+ *
+ * \param list The list to retrieve the value of
+ * \param value The value of the list returns here
+ * \return DOM_NO_ERR on success, otherwise the failure code
+ */
+dom_exception dom_tokenlist_get_value(dom_tokenlist *list, dom_string **value)
+{
+ assert(list != NULL);
+
+ return dom_element_get_attribute(list->ele, list->attr, value);
+}
+
+/**
+ * Set the value of the tokenlist as a string
+ *
+ * \param list The list to set the value of
+ * \param value The value to set
+ * \return DOM_NO_ERR on success, otherwise the failure code
+ *
+ */
+dom_exception dom_tokenlist_set_value(dom_tokenlist *list, dom_string *value)
+{
+ assert(list != NULL);
+
+ return dom_element_set_attribute(list->ele, list->attr, value);
+}
+
+/**
+ * Check if the given value is in the tokenlist
+ *
+ * \param list The list to scan for the given value
+ * \param value The value to look for in the token list
+ * \param contains This will be set based on whether or not the value is present
+ * \return DOM_NO_ERR on success, otherwise the failure code
+ */
+dom_exception
+dom_tokenlist_contains(dom_tokenlist *list, dom_string *value, bool *contains)
+{
+ dom_exception exc;
+ uint32_t n;
+
+ assert(list != NULL);
+
+ exc = _dom_tokenlist_reparse(list);
+ if (exc != DOM_NO_ERR)
+ return exc;
+
+ *contains = false;
+
+ for (n = 0; n < list->len; n++) {
+ if (dom_string_isequal(value, list->entries[n])) {
+ *contains = true;
+ break;
+ }
+ }
+
+ return DOM_NO_ERR;
+}
+
+/**
+ * Add the given value to the tokenlist
+ *
+ * \param list The list to add to
+ * \param value The value to add
+ * \return DOM_NO_ERR on success, otherwise the failure code
+ */
+dom_exception dom_tokenlist_add(dom_tokenlist *list, dom_string *value)
+{
+ dom_exception exc;
+ bool present = false;
+
+ assert(list != NULL);
+
+ exc = dom_tokenlist_contains(list, value, &present);
+ if (exc != DOM_NO_ERR)
+ return exc;
+
+ if (present == true)
+ return DOM_NO_ERR;
+
+ exc = _dom_tokenlist_make_room(list);
+ if (exc != DOM_NO_ERR)
+ return exc;
+
+ list->entries[list->len++] = dom_string_ref(value);
+
+ exc = _dom_tokenlist_reify(list);
+
+ return exc;
+}
+
+/**
+ * Remove the given value from the tokenlist
+ *
+ * \param list The list to remove from
+ * \param value The value to remove
+ * \return DOM_NO_ERR on success, otherwise the failure code
+ */
+dom_exception dom_tokenlist_remove(dom_tokenlist *list, dom_string *value)
+{
+ dom_exception exc;
+ uint32_t n, m;
+
+ assert(list != NULL);
+
+ exc = _dom_tokenlist_reparse(list);
+ if (exc != DOM_NO_ERR)
+ return false;
+
+ for (n = 0; n < list->len; ++n) {
+ if (dom_string_isequal(value, list->entries[n])) {
+ dom_string_unref(list->entries[n]);
+ for (m = n + 1; m < list->len; ++m) {
+ list->entries[m - 1] = list->entries[m];
+ }
+ list->len--;
+ break;
+ }
+ }
+
+ exc = _dom_tokenlist_reify(list);
+
+ return exc;
+}
diff --git a/src/core/tokenlist.h b/src/core/tokenlist.h
new file mode 100644
index 0000000..325d726
--- /dev/null
+++ b/src/core/tokenlist.h
@@ -0,0 +1,18 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
+ */
+
+#ifndef dom_internal_core_tokenlist_h_
+#define dom_internal_core_tokenlist_h_
+
+#include <stdbool.h>
+
+#include <dom/core/tokenlist.h>
+
+struct dom_element;
+struct dom_string;
+
+#endif
commitdiff http://git.netsurf-browser.org/libdom.git/commit/?id=14f1b4abd5f395555e8d...
commit 14f1b4abd5f395555e8d96e18c5db844bff17fde
Author: Daniel Silverstone <dsilvers(a)digital-scurf.org>
Commit: Daniel Silverstone <dsilvers(a)digital-scurf.org>
(chore): Add .clang-format from NetSurf to ease development
Signed-off-by: Daniel Silverstone <dsilvers(a)digital-scurf.org>
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..75df82a
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,120 @@
+---
+Language: Cpp
+AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlines: Right
+AlignOperands: true
+AlignTrailingComments: false
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: MultiLine
+BinPackArguments: false
+BinPackParameters: false
+BraceWrapping:
+ AfterClass: true
+ AfterControlStatement: false
+ AfterEnum: false
+ AfterFunction: true
+ AfterNamespace: true
+ AfterObjCDeclaration: false
+ AfterStruct: false
+ AfterUnion: false
+ AfterExternBlock: false
+ BeforeCatch: false
+ BeforeElse: false
+ IndentBraces: false
+ SplitEmptyFunction: true
+ SplitEmptyRecord: true
+ SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Linux
+BreakBeforeInheritanceComma: false
+BreakInheritanceList: BeforeColon
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeColon
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: false
+ColumnLimit: 80
+CommentPragmas: '^ IWYU pragma:'
+CompactNamespaces: false
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 8
+ContinuationIndentWidth: 8
+Cpp11BracedListStyle: true
+DerivePointerAlignment: false
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: true
+ForEachMacros:
+ - foreach
+ - Q_FOREACH
+ - BOOST_FOREACH
+IncludeBlocks: Preserve
+IncludeCategories:
+ - Regex: '^(<.*/)'
+ Priority: 3
+ - Regex: '^(<(nsutils)/)'
+ Priority: 2
+ - Regex: '"utils/'
+ Priority: 4
+ - Regex: '"netsurf/'
+ Priority: 5
+ - Regex: '.*'
+ Priority: 6
+IncludeIsMainRegex: '(Test)?$'
+IndentCaseLabels: false
+IndentPPDirectives: None
+IndentWidth: 8
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 2
+NamespaceIndentation: None
+ObjCBinPackProtocolList: Auto
+ObjCBlockIndentWidth: 2
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakAssignment: 100
+PenaltyBreakBeforeFirstCallParameter: 50
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyBreakTemplateDeclaration: 10
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 19
+PointerAlignment: Right
+ReflowComments: true
+SortIncludes: false
+SortUsingDeclarations: true
+SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCpp11BracedList: false
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeParens: ControlStatements
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Cpp11
+TabWidth: 8
+UseTab: Always
+...
+
-----------------------------------------------------------------------
--
Document Object Model library
4 months
netsurf: branch master updated. release/3.10-328-g764fca4
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/764fca4f3abfc7437003f...
...commit http://git.netsurf-browser.org/netsurf.git/commit/764fca4f3abfc7437003f49...
...tree http://git.netsurf-browser.org/netsurf.git/tree/764fca4f3abfc7437003f496d...
The branch, master has been updated
via 764fca4f3abfc7437003f496d52039ad7e6b779d (commit)
from 0c25ae5e8eb38b3b888a9bfdc0fcc6d53af17b04 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=764fca4f3abfc743700...
commit 764fca4f3abfc7437003f496d52039ad7e6b779d
Author: Daniel Silverstone <dsilvers(a)digital-scurf.org>
Commit: Daniel Silverstone <dsilvers(a)digital-scurf.org>
utils/utf8.c: Fix missing format string for snprintf
Signed-off-by: Daniel Silverstone <dsilvers(a)digital-scurf.org>
diff --git a/utils/utf8.c b/utils/utf8.c
index 84918cc..7091ad4 100644
--- a/utils/utf8.c
+++ b/utils/utf8.c
@@ -185,7 +185,7 @@ get_cached_cd(const char *enc_from, const char *enc_to, iconv_t *cd_out)
}
/* and safely copy the to/from/cd data into last_cd */
- snprintf(last_cd.from, sizeof(last_cd.from), enc_from);
+ snprintf(last_cd.from, sizeof(last_cd.from), "%s", enc_from);
snprintf(last_cd.to, sizeof(last_cd.to), "%s", enc_to);
*cd_out = last_cd.cd = cd;
-----------------------------------------------------------------------
Summary of changes:
utils/utf8.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/utils/utf8.c b/utils/utf8.c
index 84918cc..7091ad4 100644
--- a/utils/utf8.c
+++ b/utils/utf8.c
@@ -185,7 +185,7 @@ get_cached_cd(const char *enc_from, const char *enc_to, iconv_t *cd_out)
}
/* and safely copy the to/from/cd data into last_cd */
- snprintf(last_cd.from, sizeof(last_cd.from), enc_from);
+ snprintf(last_cd.from, sizeof(last_cd.from), "%s", enc_from);
snprintf(last_cd.to, sizeof(last_cd.to), "%s", enc_to);
*cd_out = last_cd.cd = cd;
--
NetSurf Browser
4 months