IP Library Granted Patent US 9,805,009
Granted Patent B2
US 9,805,009 · App. 13/340,411 · Granted Oct 31, 2017

Method and device for cascading style sheet (CSS) selector matching

Inventor: Rune Lillesveen (Rælingen, NO)
Assignee: OPERA SOFTWARE AS
G06F17/227G06F17/2247G06F17/211G06F17/218G06F17/24G06F17/3089G06F17/30905
View Patent ↗
Loading inventors, assignments & file history…
Monitor This Case
Get email alerts when status or documents change.
Order Certified Copies
Most orders are placed with the USPTO same day — all within 24 business hours.
Order via The Patent Place →
Pre-filled with this patent's details
Quick Facts
Patent No.
US 9,805,009
App. No.
13/340,411
Granted
Oct 31, 2017
Kind
B2
Abstract

The present invention relates to a computer-implemented method for Cascading Style Sheet (CSS) selector matching. The method comprises: generating machine code based on text which includes at least one CSS selector; and executing the machine code to perform the CSS selector matching. The present invention also relates to a corresponding computer device and a computer readable storage medium.

Claims (79)

1. A method for Cascading Style Sheet (CSS) selector matching, which method comprises:

receiving content including markup language text and text which includes at least one CSS selector;

parsing the markup language into a Document Object Model (DOM) tree;

parsing the text which includes at least one CSS selector into a data structure representing the at least one CSS selector;

compiling the data structure into machine code; and

executing the machine code to perform the CSS selector matching,

wherein the executing of the machine code comprises:

for each DOM node from said DOM tree,

invoking the machine code for the at least one CSS selector to determine whether each of the at least one CSS selector matches the DOM node, and

for each of the at least one CSS selector determined to match the DOM node, apply a corresponding CSS property to the DOM node.

2. A method according to claim 1 , wherein the data structure is a byte-code or an Abstract Syntax Tree (AST).

3. A method according to claim 1 , wherein the data structure is compiled into the machine code using Just In Time (JIT) compilation.

4. A method according to claim 1 , wherein the text includes several CSS selectors, and wherein only some selectors are compiled based on use of the selectors.

5. A method according to claim 1 ,

wherein the parsing of the text which includes at least one CSS selector into a data structure representing the at least one CSS selector comprises:

translating each simple constituent of the text which includes at least one CSS selector into one or more byte-code instructions; and

translating combinators of the text which includes at least one CSS selector into control flow instructions and instructions for picking candidate nodes or elements from the DOM for matching.

6. A method according to claim 1 , further comprising:

executing or interpreting the data structure to perform the CSS selector matching.

7. A method according to claim 1 , wherein the executing of the machine code further comprises or is comprised in:

pushing a DOM node onto a call stack,

invoking the machine code for the at least one CSS selector to determine whether each of the at least one CSS selector matches the DOM node on the stack, and

for each of the at least one CSS selector determined to match the DOM node on the stack, apply a corresponding CSS property to the DOM node on the stack.

8. A method according to claim 1 , wherein

the machine code into which the data structure is compiled is a set of instructions directly executable by a computer processor,

the CSS selector matching is performed led by performing the following for each DOM node from said DOM tree:

invoking the computer processor to execute the set of instructions to determine whether each of the at least one CSS selector matches the DOM node, and

for each of the at least one CSS selector determined to match the DOM node, applying the corresponding CSS property to the DOM node.

9. The method according to claim 1 , wherein

the method is performed by a web browser,

as the markup language text and the text which includes at least one CSS selector are retrieved by the web browser using a same Universal Resource Locator (URL), and

when parsing the text which includes at least one CSS selector into the data structure, the web browser translates text written in CSS language into a programming language.

10. A computer device for Cascading Style Sheet (CSS) selector matching, which device comprises:

a CSS parser adapted to parse text which includes at least one CSS selector into a data structure representing the at least one CSS selector;

a compiler adapted to compile the data structure into machine code for the particular architecture of the computer device; and

an execution engine adapted to execute the machine code to perform the CSS selector matching,

wherein the execution engine is adapted to perform the following when executing the machine code:

for each DOM node from said DOM tree,

invoke the machine code for the at least one CSS selector to determine whether each of the at least one CSS selector matches the DOM node, and

for each of the at least one CSS selector determined to match the DOM node, apply a corresponding CSS property to the DOM node.

11. A computer device according to claim 10 ,

wherein said data structure representing the at least one CSS selector is a byte-code or an AST; and

wherein the execution engine is adapted to invoke the machine code for a given CSS selector and a given DOM node or element.

12. A computer device according to claim 10 , wherein the execution engine, when executing the machine code, is further adapted to:

push a DOM node onto a call stack,

invoke the machine code for the at least one CSS selector to determine whether each of the at least one CSS selector matches the DOM node on the stack, and

for each of the at least one CSS selector determined to match the DOM node on the stack, apply a corresponding CSS property to the DOM node on the stack.

13. A computer device according to claim 10 , wherein

the machine code into which the data structure is compiled is a set of instructions directly executable by a computer processor,

when executing the machine code, the execution engine performs the following for each DOM node from said DOM tree:

invokes the computer processor to execute the set of instructions to determine whether each of the at least one CSS selector matches the DOM node, and

for each of the at least one CSS selector determined to match the DOM node, applies the corresponding CSS property to the DOM node.

14. The computer device according to claim 10 , wherein

the CSS parser is implemented in a web browser executed by the computer device,

the text which includes at least one CSS selector is retrieved by the browser using a Universal Resource Locator (URL),

when parsing the text which includes at least one CSS selector into the data structure, the CSS parser translates text written in CSS language into a programming language.

15. A non-transitory computer readable storage medium having code or instructions, which code or instructions when executed on a computer cause(s) a process for Cascading Style Sheet (CSS) selector matching that includes:

receiving content including markup language text and text which includes at least one CSS selector;

parsing the markup language into a Document Object Model (DOM) tree;

parsing the text which includes at least one CSS selector into a data structure representing the at least one CSS selector;

generating machine code by compiling the data structure based on the parsing of the text which includes at least one CSS selector; and

executing the machine code to perform the CSS selector matching,

wherein the executing of the machine code comprises:

for each DOM node from said DOM tree,

invoking the machine code for the at least one CSS selector to determine whether each of the at least one CSS selector matches the DOM node, and

for each of the at least one CSS selector determined to match the DOM node, apply a corresponding CSS property to the DOM node.

16. A non-transitory computer readable storage medium according to claim 15 , wherein the executing of the machine code further comprises or is comprised in:

pushing a DOM node onto a call stack,

invoking the machine code for the at least one CSS selector to determine tine whether each of the at least one CSS selector matches the DOM node on the stack, and

for each of the at least one CSS selector determined to match the DOM node on the stack, apply a corresponding CSS property to the DOM node on the stack.

17. A non-transitory computer readable storage medium according to claim 15 , wherein

the machine code into which the data structure is compiled is a set of instructions directly executable by a computer processor,

the CSS selector matching is performed by performing the following for each DOM node from said DOM tree:

invoking the computer processor to execute the set of instructions to determine whether each of the at least one CSS selector matches the DOM node, and

for each of the at least one CSS selector determined to match the DOM node, applying the corresponding CSS property to the DOM node.

18. A non-transitory computer readable storage medium according to claim 15 , wherein

the process is performed by a web browser executed on the computer,

as the markup language text and the text which includes at least one CSS selector are retrieved by the browser using a same Universal Resource Locator (URL), and

when parsing the text which includes at least one CSS selector into the data structure, the web browser translates text written in CSS language into a programming language.

Assignments (2)
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Jun 21, 2017
From: OPERA SOFTWARE ASA
To: OPERA SOFTWARE AS
Reel/Frame 042769/0384 →
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Mar 19, 2012
From: LILLESVEEN, RUNE
To: OPERA SOFTWARE ASA
Reel/Frame 027888/0232 →
Continuity (2)
Provisional Application 61428247 · Dec 30, 2010
Related Publication 20120173967A1 · Jul 5, 2012