[gxml] Semi-Implement CssSelectorParser E:enable E:disable E:checked selectors
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] Semi-Implement CssSelectorParser E:enable E:disable E:checked selectors
- Date: Fri, 8 Sep 2017 17:04:15 +0000 (UTC)
commit aba2fae02777f66b37d2b22f9273623168f4b09d
Author: Daniel Espinosa <esodan gmail com>
Date: Fri Sep 8 08:56:47 2017 -0700
Semi-Implement CssSelectorParser E:enable E:disable E:checked selectors
This selectors are for UI, potentialy useful for GTK+ XML ui definitions,
but oriented to HTML documents. Please add tags supporting this attributes
gxml/CssSelectorParser.vala | 12 ++++++++++++
gxml/Html.vala | 2 +-
test/CssSelectorTest.vala | 34 +++++++++++++++++++++++++++++++++-
3 files changed, 46 insertions(+), 2 deletions(-)
---
diff --git a/gxml/CssSelectorParser.vala b/gxml/CssSelectorParser.vala
index 8be1b14..bf4df62 100644
--- a/gxml/CssSelectorParser.vala
+++ b/gxml/CssSelectorParser.vala
@@ -366,6 +366,18 @@ public class GXml.CssSelectorParser : GLib.Object {
!=
(element.owner_document.document_element as GNode).get_internal_node ()) return false;
if (element.node_name.down () ==
element.owner_document.document_element.node_name.down ()) return true;
}
+ if (s.data.down () == "checked") {
+ if (!(element.owner_document is DomHtmlDocument)) return false;
+ // FIXME: check for tags UI allowed to have this state you can use
E[checked="true"] instead
+ }
+ if (s.data.down () == "enable") {
+ if (!(element.owner_document is DomHtmlDocument)) return false;
+ // FIXME: check for tags UI allowed to have this state you can use
E[enable="true"] instead
+ }
+ if (s.data.down () == "disabled") {
+ if (!(element.owner_document is DomHtmlDocument)) return false;
+ // FIXME: check for tags UI allowed to have this state you can use
E[disable="true"] instead
+ }
}
if (s.selector_type == CssSelectorType.CLASS) {
var p = element.get_attribute ("class");
diff --git a/gxml/Html.vala b/gxml/Html.vala
index 32c45d1..9338847 100644
--- a/gxml/Html.vala
+++ b/gxml/Html.vala
@@ -24,7 +24,7 @@
/**
* Interface for HTML handling implementation
*/
-public interface DomHtmlDocument : Object, GXml.DomDocument {
+public interface GXml.DomHtmlDocument : Object, GXml.DomDocument {
/**
* This method reads HTML documents using default parser
*/
diff --git a/test/CssSelectorTest.vala b/test/CssSelectorTest.vala
index 6d30ae9..fbec172 100644
--- a/test/CssSelectorTest.vala
+++ b/test/CssSelectorTest.vala
@@ -374,7 +374,7 @@ class CssSelectorTest : GXmlTest {
warning ("ERROR: "+e.message);
}
});
- Test.add_func ("/gxml/css-selector/element/pseudo/root", () => {
+ Test.add_func ("/gxml/css-selector/pseudo/root", () => {
try {
var cp = new CssSelectorParser ();
cp.parse ("toplevel:root");
@@ -433,5 +433,37 @@ class CssSelectorTest : GXmlTest {
warning ("ERROR: "+e.message);
}
});
+ Test.add_func ("/gxml/css-selector/pseudo/non-hmtl/enable-disable-checked", () => {
+ try {
+ var cp = new CssSelectorParser ();
+ cp.parse ("radio[enable=\"true\"]");
+ foreach (CssSelectorData sel in cp.selectors) {
+ message ("Type: "+sel.selector_type.to_string ()+" : "+sel.data+" :
"+sel.value);
+ }
+ assert (cp.selectors.size == 3);
+ var s = cp.selectors[0];
+ assert (s != null);
+ assert (s.selector_type == CssSelectorType.ELEMENT);
+ var si = cp.selectors[1];
+ assert (si != null);
+ assert (si.selector_type == CssSelectorType.INSIDE);
+ var sa = cp.selectors[2];
+ assert (sa != null);
+ assert (sa.selector_type == CssSelectorType.ATTRIBUTE_EQUAL);
+ var d = new GomDocument ();
+ var r = d.create_element ("HTML");
+ d.append_child (r);
+ var c1 = d.create_element ("BODY");
+ r.append_child (c1);
+ var c2 = d.create_element ("radio");
+ c2.set_attribute ("enable", "true");
+ r.append_child (c2);
+ assert (!cp.match (r));
+ assert (!cp.match (c1));
+ assert (!cp.match (c2));
+ } catch (GLib.Error e){
+ warning ("ERROR: "+e.message);
+ }
+ });
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]