summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2017-09-02 20:08:04 +0000
committerTavmjong Bah <tavmjong@free.fr>2017-09-02 20:08:04 +0000
commit039bd1db377db24d13ca472e039838aed4cf3e97 (patch)
tree2df931384ab28fb99172e46cf2a3dab082f3d659 /src
parentImplement CSS 3 pseudo selectors. GSoC project 2017. (diff)
downloadinkscape-039bd1db377db24d13ca472e039838aed4cf3e97.tar.gz
inkscape-039bd1db377db24d13ca472e039838aed4cf3e97.zip
Implement CSS 3 "general sibling" combinator (~).
Diffstat (limited to 'src')
-rw-r--r--src/libcroco/cr-parser.c4
-rw-r--r--src/libcroco/cr-sel-eng.c39
-rw-r--r--src/libcroco/cr-simple-sel.c4
-rw-r--r--src/libcroco/cr-simple-sel.h7
4 files changed, 51 insertions, 3 deletions
diff --git a/src/libcroco/cr-parser.c b/src/libcroco/cr-parser.c
index 454e1c330..449533c6e 100644
--- a/src/libcroco/cr-parser.c
+++ b/src/libcroco/cr-parser.c
@@ -1969,6 +1969,10 @@ cr_parser_parse_simple_sels (CRParser * a_this,
READ_NEXT_CHAR (a_this, &cur_char);
comb = COMB_PLUS;
cr_parser_try_to_skip_spaces_and_comments (a_this);
+ } else if (next_char == '~') {
+ READ_NEXT_CHAR (a_this, &cur_char);
+ comb = COMB_TILDE;
+ cr_parser_try_to_skip_spaces_and_comments (a_this);
} else if (next_char == '>') {
READ_NEXT_CHAR (a_this, &cur_char);
comb = COMB_GT;
diff --git a/src/libcroco/cr-sel-eng.c b/src/libcroco/cr-sel-eng.c
index 3c96ac7c7..ea04bfd2e 100644
--- a/src/libcroco/cr-sel-eng.c
+++ b/src/libcroco/cr-sel-eng.c
@@ -1349,6 +1349,45 @@ sel_matches_node_real (CRSelEng * a_this, CRSimpleSel * a_sel,
goto done;
break;
+ case COMB_TILDE: /* General sibling selector. */
+ {
+ CRXMLNodePtr n = NULL;
+ enum CRStatus status = CR_OK;
+ gboolean matches = FALSE;
+
+ /*
+ * Walk through previous sibing nodes looking for a
+ * node that matches the preceding selector.
+ */
+ for (n = get_prev_element_node (node_iface, cur_node);
+ n;
+ n = get_prev_element_node (node_iface, n)) {
+ status = sel_matches_node_real
+ (a_this, cur_sel->prev,
+ n, &matches, FALSE, TRUE);
+
+ if (status != CR_OK)
+ goto done;
+
+ if (matches == TRUE) {
+ cur_node = n ;
+ break;
+ }
+ }
+
+ if (!n) {
+ /*
+ * Didn't find any previous sibling that matches
+ * the previous simple selector.
+ */
+ goto done;
+ }
+ /*
+ * See note above in COMB_WS section.
+ */
+ break;
+ }
+
case COMB_GT:
cur_node = get_next_parent_element_node (node_iface, cur_node);
if (!cur_node)
diff --git a/src/libcroco/cr-simple-sel.c b/src/libcroco/cr-simple-sel.c
index 4df93fa77..3a4a3b2e2 100644
--- a/src/libcroco/cr-simple-sel.c
+++ b/src/libcroco/cr-simple-sel.c
@@ -125,6 +125,10 @@ cr_simple_sel_to_string (CRSimpleSel const * a_this)
g_string_append (str_buf, "+");
break;
+ case COMB_TILDE:
+ g_string_append (str_buf, "~");
+ break;
+
case COMB_GT:
g_string_append (str_buf, ">");
break;
diff --git a/src/libcroco/cr-simple-sel.h b/src/libcroco/cr-simple-sel.h
index d8edc0025..552e44f00 100644
--- a/src/libcroco/cr-simple-sel.h
+++ b/src/libcroco/cr-simple-sel.h
@@ -40,9 +40,10 @@ G_BEGIN_DECLS
enum Combinator
{
NO_COMBINATOR,
- COMB_WS,/*whitespace: descendent*/
- COMB_PLUS,/*'+': preceded by*/
- COMB_GT/*greater than ('>'): child*/
+ COMB_WS, /*whitespace: descendent*/
+ COMB_PLUS, /*'+': immediately preceded by*/
+ COMB_TILDE, /*'~': preceded by, CSS 3*/
+ COMB_GT /*greater than ('>'): child*/
} ;
enum SimpleSelectorType