Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 311 and 402] [Versions 400 and 402] [Versions 401 and 402]

(no description)

File Size: 547 lines (21 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

brickfield_accessibility_css:: (13 methods):
  __construct()
  load_css()
  load_imported_files()
  get_specificity()
  get_style()
  add_selector()
  get_node_style()
  walkup_tree_for_inheritance()
  load_uri()
  format_css()
  get_xpath()
  is_char()
  parse_selector()


Class: brickfield_accessibility_css  - X-Ref

Parse content to check CSS validity.

This class first parses all the CSS in the document and prepares an index of CSS styles to be used by accessibility tests
to determine color and positioning.

First, in loadCSS we get all the inline and linked style sheet information and merge it into a large CSS file string.

Second, in setStyles we use XPath queries to find all the DOM elements which are effected by CSS styles and then
build up an index in style_index of all the CSS styles keyed by an attriute we attach to all DOM objects to lookup
the style quickly.

Most of the second step is to get around the problem where XPath DOMNodeList objects are only marginally referential
to the original elements and cannot be altered directly.

__construct(\DOMDocument &$dom, string $uri, string $type, array $path, bool $cmsmode = false,array $cssfiles = [])   X-Ref
Class constructor. We are just building and importing variables here and then loading the CSS

param: \DOMDocument $dom The DOMDocument object
param: string $uri The URI of the request
param: string $type The type of request
param: array $path
param: bool $cmsmode Whether we are running in CMS mode
param: array $cssfiles An array of additional CSS files to load

load_css()   X-Ref
Loads all the CSS files from the document using LINK elements or @import commands


load_imported_files()   X-Ref
Imports files from the CSS file using @import commands


get_specificity(string $selector)   X-Ref
Returns a specificity count to the given selector.
Higher specificity means it overrides other styles.

param: string $selector The CSS Selector
return: int $specifity

get_style($element)   X-Ref
Interface method for tests to call to lookup the style information for a given DOMNode

param: \stdClass $element A DOMElement/DOMNode object
return: array An array of style information (can be empty)

add_selector(string $key, string $codestr)   X-Ref
Adds a selector to the CSS index

param: string $key The CSS selector
param: string $codestr The CSS Style code string
return: null

get_node_style($element)   X-Ref
Returns the style from the CSS index for a given element by first
looking into its tag bucket then iterating over every item for an
element that matches

param: \stdClass $element
return: array An array of all the style elements that _directly_ apply to that element (ignoring inheritance)

walkup_tree_for_inheritance($element, array $style)   X-Ref
A helper function to walk up the DOM tree to the end to build an array of styles.

param: \stdClass $element The DOMNode object to walk up from
param: array $style The current style built for the node
return: array The array of the DOM element, altered if it was overruled through css inheritance

load_uri(string $rel)   X-Ref
Loads a CSS file from a URI

param: string $rel The URI of the CSS file

format_css()   X-Ref
Formats the CSS to be ready to import into an array of styles

return: bool Whether there were elements imported or not

get_xpath(string $selector)   X-Ref
Converts a CSS selector to an Xpath query

param: string $selector The selector to convert
return: string An Xpath query string

is_char(string $char)   X-Ref
Checks that a string is really a regular character

param: string $char The character
return: bool Whether the string is a character

parse_selector(string $query)   X-Ref
Parses a CSS selector into an array of rules.

param: string $query The CSS Selector query
return: array An array of the CSS Selector parsed into rule segments