| 1 | ##---------------------------------------------------------------------------- | ||||||||||
| 2 | ## HTML Object - ~/lib/HTML/Object/DOM/Element/Style.pm | ||||||||||
| 3 | ## Version v0.2.0 | ||||||||||
| 4 | ## Copyright(c) 2021 DEGUEST Pte. Ltd. | ||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||
| 6 | ## Created 2021/12/23 | ||||||||||
| 7 | ## Modified 2022/09/18 | ||||||||||
| 8 | ## All rights reserved | ||||||||||
| 9 | ## | ||||||||||
| 10 | ## | ||||||||||
| 11 | ## This program is free software; you can redistribute it and/or modify it | ||||||||||
| 12 | ## under the same terms as Perl itself. | ||||||||||
| 13 | ##---------------------------------------------------------------------------- | ||||||||||
| 14 | package HTML::Object::DOM::Element::Style; | ||||||||||
| 15 | BEGIN | ||||||||||
| 16 | { | ||||||||||
| 17 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 1 | ▶ | warnings::register_categories( 'HTML::Object' ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 1 | ▶ | use parent qw( HTML::Object::DOM::Element ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 1 | ▶ | use vars qw( $VERSION ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 1 | ▶ | use HTML::Object::DOM::Element::Shared qw( :style ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | 1 | our $VERSION = 'v0.2.0'; | |||||||||
| 24 | }; | ||||||||||
| 25 | |||||||||||
| 26 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | |||||||||||
| 29 | sub init | ||||||||||
| 30 | { | ||||||||||
| 31 | 0 | ▶ | my $self = shift( @_ ); | ||||||||
|
Subroutine
init: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 32 | 0 | $self->{scoped} = undef; | |||||||||
| 33 | 0 | $self->{_init_strict_use_sub} = 1; | |||||||||
| 34 | 0 | ▶ | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 0 | ▶ | $self->{tag} = 'style' if( !CORE::length( "$self->{tag}" ) ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 0 | return( $self ); | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | # Note: property disabled inherited | ||||||||||
| 40 | |||||||||||
| 41 | # Note: property media | ||||||||||
| 42 | 0 | ▶ | sub media : lvalue { return( shift->_set_get_property( 'media', @_ ) ); } | ||||||||
|
Subroutine
media: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 43 | |||||||||||
| 44 | # Note: property scoped | ||||||||||
| 45 | 0 | ▶ | sub scoped : lvalue { return( shift->_set_get_boolean( 'scoped', @_ ) ); } | ||||||||
|
Subroutine
scoped: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 46 | |||||||||||
| 47 | # Note: property sheet read-only | ||||||||||
| 48 | 0 | ▶ | sub sheet { return; } | ||||||||
|
Subroutine
sheet: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 49 | |||||||||||
| 50 | # Note: property type inherited | ||||||||||
| 51 | |||||||||||
| 52 | 1 | 1; | |||||||||
| 53 | # NOTE: POD | ||||||||||
| 54 | __END__ | ||||||||||
| 55 | |||||||||||
| 56 | =encoding utf-8 | ||||||||||
| 57 | |||||||||||
| 58 | =head1 NAME | ||||||||||
| 59 | |||||||||||
| 60 | HTML::Object::DOM::Element::Style - HTML Object DOM Style Class | ||||||||||
| 61 | |||||||||||
| 62 | =head1 SYNOPSIS | ||||||||||
| 63 | |||||||||||
| 64 | use HTML::Object::DOM::Element::Style; | ||||||||||
| 65 | my $style = HTML::Object::DOM::Element::Style->new || | ||||||||||
| 66 | die( HTML::Object::DOM::Element::Style->error, "\n" ); | ||||||||||
| 67 | |||||||||||
| 68 | =head1 VERSION | ||||||||||
| 69 | |||||||||||
| 70 | v0.2.0 | ||||||||||
| 71 | |||||||||||
| 72 | =head1 DESCRIPTION | ||||||||||
| 73 | |||||||||||
| 74 | This interface represents a C<style> element. It inherits properties and methods from its parent, L<HTML::Object::DOM::Element>. | ||||||||||
| 75 | |||||||||||
| 76 | =head1 INHERITANCE | ||||||||||
| 77 | |||||||||||
| 78 | +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +-----------------------------------+ | ||||||||||
| 79 | | HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::Element | --> | HTML::Object::DOM::Element::Style | | ||||||||||
| 80 | +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +-----------------------------------+ | ||||||||||
| 81 | |||||||||||
| 82 | =head1 PROPERTIES | ||||||||||
| 83 | |||||||||||
| 84 | Inherits properties from its parent L<HTML::Object::DOM::Element> | ||||||||||
| 85 | |||||||||||
| 86 | =head2 disabled | ||||||||||
| 87 | |||||||||||
| 88 | Is a boolean value reflecting the HTML attribute representing whether or not the stylesheet is disabled (true) or not (false). | ||||||||||
| 89 | |||||||||||
| 90 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLStyleElement/disabled> | ||||||||||
| 91 | |||||||||||
| 92 | =head2 media | ||||||||||
| 93 | |||||||||||
| 94 | Is a string representing the intended destination medium for style information. | ||||||||||
| 95 | |||||||||||
| 96 | Example: | ||||||||||
| 97 | |||||||||||
| 98 | <!doctype html> | ||||||||||
| 99 | <html> | ||||||||||
| 100 | <head> | ||||||||||
| 101 | <link id="LinkedStyle" rel="stylesheet" href="document.css" type="text/css" media="screen" /> | ||||||||||
| 102 | <style id="InlineStyle" rel="stylesheet" type="text/css" media="screen, print"> | ||||||||||
| 103 | p { color: blue; } | ||||||||||
| 104 | </style> | ||||||||||
| 105 | </head> | ||||||||||
| 106 | <body> | ||||||||||
| 107 | </body> | ||||||||||
| 108 | </html> | ||||||||||
| 109 | |||||||||||
| 110 | say( 'LinkedStyle: ' . $doc->getElementById( 'LinkedStyle' )->media ); # 'screen' | ||||||||||
| 111 | say( 'InlineStyle: ' . $doc->getElementById( 'InlineStyle' )->media ); # 'screen, print' | ||||||||||
| 112 | |||||||||||
| 113 | Operators that can be used in the C<media> value: | ||||||||||
| 114 | |||||||||||
| 115 | =over 4 | ||||||||||
| 116 | |||||||||||
| 117 | =item * and | ||||||||||
| 118 | |||||||||||
| 119 | Specifies an AND operator | ||||||||||
| 120 | |||||||||||
| 121 | =item * , (comma) | ||||||||||
| 122 | |||||||||||
| 123 | Specifies an OR operator | ||||||||||
| 124 | |||||||||||
| 125 | =item * not | ||||||||||
| 126 | |||||||||||
| 127 | Specifies a NOT operator | ||||||||||
| 128 | |||||||||||
| 129 | =back | ||||||||||
| 130 | |||||||||||
| 131 | Device names (not enforced by this interface) that can be used in the C<media> value: | ||||||||||
| 132 | |||||||||||
| 133 | =over 4 | ||||||||||
| 134 | |||||||||||
| 135 | =item * all | ||||||||||
| 136 | |||||||||||
| 137 | Suitable for all devices. This is the default. | ||||||||||
| 138 | |||||||||||
| 139 | =item * aural | ||||||||||
| 140 | |||||||||||
| 141 | Speech synthesizers | ||||||||||
| 142 | |||||||||||
| 143 | =item * braille | ||||||||||
| 144 | |||||||||||
| 145 | Braille feedback devices -- for the visually impaired | ||||||||||
| 146 | |||||||||||
| 147 | =item * handheld | ||||||||||
| 148 | |||||||||||
| 149 | Handheld devices with small screens and limited bandwidth | ||||||||||
| 150 | |||||||||||
| 151 | =item * projection | ||||||||||
| 152 | |||||||||||
| 153 | Projector devices | ||||||||||
| 154 | |||||||||||
| 155 | =item * print | ||||||||||
| 156 | |||||||||||
| 157 | Printed pages or in print-preview mode | ||||||||||
| 158 | |||||||||||
| 159 | =item * screen | ||||||||||
| 160 | |||||||||||
| 161 | Computer screens | ||||||||||
| 162 | |||||||||||
| 163 | =item * tty | ||||||||||
| 164 | |||||||||||
| 165 | Teletypes and similar devices using a fixed-pitch character grid | ||||||||||
| 166 | |||||||||||
| 167 | =item * tv | ||||||||||
| 168 | |||||||||||
| 169 | Television type devices with low resolution and limited scrolling | ||||||||||
| 170 | |||||||||||
| 171 | =back | ||||||||||
| 172 | |||||||||||
| 173 | Tokens that can be used in the C<media> value: | ||||||||||
| 174 | |||||||||||
| 175 | =over 4 | ||||||||||
| 176 | |||||||||||
| 177 | =item * aspect-ratio (width/height) | ||||||||||
| 178 | |||||||||||
| 179 | Ratio of width/height of the targeted display. Name can be prefixed with min- or max-. | ||||||||||
| 180 | |||||||||||
| 181 | =item * color (integer) | ||||||||||
| 182 | |||||||||||
| 183 | Bits per color of targeted display. Name can be prefixed with min- or max-. | ||||||||||
| 184 | |||||||||||
| 185 | =item * color-index (integer) | ||||||||||
| 186 | |||||||||||
| 187 | Number of colors the targeted display supports. Name can be prefixed with min- or max-. | ||||||||||
| 188 | |||||||||||
| 189 | =item * device-aspect-ratio (width/height) | ||||||||||
| 190 | |||||||||||
| 191 | Ratio of width/height of the device or paper. Name can be prefixed with min- or max-. | ||||||||||
| 192 | |||||||||||
| 193 | =item * device-height (pixels) | ||||||||||
| 194 | |||||||||||
| 195 | Height of the device or paper. Name can be prefixed with min- or max-. | ||||||||||
| 196 | |||||||||||
| 197 | =item * device-width (pixels) | ||||||||||
| 198 | |||||||||||
| 199 | Width of the device or paper. Name can be prefixed with min- or max-. | ||||||||||
| 200 | |||||||||||
| 201 | =item * grid (1 = grid, 0 = otherwise) | ||||||||||
| 202 | |||||||||||
| 203 | Whether output device is a grid or bitmap type. | ||||||||||
| 204 | |||||||||||
| 205 | =item * height (pixels) | ||||||||||
| 206 | |||||||||||
| 207 | Height of targeted display. Name can be prefixed with min- or max-. | ||||||||||
| 208 | |||||||||||
| 209 | =item * monochrome (integer) | ||||||||||
| 210 | |||||||||||
| 211 | Bits per pixel in a monochrome frame buffer. Name can be prefixed with min- or max-. | ||||||||||
| 212 | |||||||||||
| 213 | =item * orientation (landscape, portrait) | ||||||||||
| 214 | |||||||||||
| 215 | Orientation of the device or paper. | ||||||||||
| 216 | |||||||||||
| 217 | =item * resolution (dpi or dpcm) | ||||||||||
| 218 | |||||||||||
| 219 | Pixel density of the targeted display or paper. Name can be prefixed with min- or max-. | ||||||||||
| 220 | |||||||||||
| 221 | =item * scan (progressive interlace) | ||||||||||
| 222 | |||||||||||
| 223 | Scanning method of a tv display. | ||||||||||
| 224 | |||||||||||
| 225 | =item * width (pixels) | ||||||||||
| 226 | |||||||||||
| 227 | Width of targeted display. Name can be prefixed with min- or max-. | ||||||||||
| 228 | |||||||||||
| 229 | =back | ||||||||||
| 230 | |||||||||||
| 231 | Example: | ||||||||||
| 232 | |||||||||||
| 233 | <style media="all and (orientation: portrait)"></style> | ||||||||||
| 234 | <style media="screen and (aspect-ratio: 16/10)"></style> | ||||||||||
| 235 | <style media="screen , (device-height: 540px)"></style> | ||||||||||
| 236 | <style media="screen , (aspect-ratio: 5/4)"></style> | ||||||||||
| 237 | <style media="screen and not (min-color-index: 512)"></style> | ||||||||||
| 238 | <style media="screen and (min-width: 1200px)"></style> | ||||||||||
| 239 | <style media="screen and (max-height: 720px)"></style> | ||||||||||
| 240 | <style media="handheld and (grid: 1)"></style> | ||||||||||
| 241 | <style media="tv and (scan: interlace)"></style> | ||||||||||
| 242 | <style media="print and (resolution: 400dpi)"></style> | ||||||||||
| 243 | <style media="screen and (max-monochrome: 2)"></style> | ||||||||||
| 244 | <style media="screen and not (device-width: 360px)"></style> | ||||||||||
| 245 | <style media="screen , (color: 8)"></style> | ||||||||||
| 246 | |||||||||||
| 247 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLStyleElement/media> | ||||||||||
| 248 | |||||||||||
| 249 | =head2 scoped | ||||||||||
| 250 | |||||||||||
| 251 | Is a boolean value indicating if the element applies to the whole document (false) or only to the parent's sub-tree (true). | ||||||||||
| 252 | |||||||||||
| 253 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLStyleElement/scoped> | ||||||||||
| 254 | |||||||||||
| 255 | =head2 sheet | ||||||||||
| 256 | |||||||||||
| 257 | Under perl, this always returns C<undef>, because processing a stylesheet would be time consuming, and an object is returned only when there is a C<href> HTML attribute set. | ||||||||||
| 258 | |||||||||||
| 259 | Under JavaScript, this returns the C<CSSStyleSheet> object associated with the given element, or C<undef> if there is none | ||||||||||
| 260 | |||||||||||
| 261 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLStyleElement/sheet> | ||||||||||
| 262 | |||||||||||
| 263 | =head2 type | ||||||||||
| 264 | |||||||||||
| 265 | Is a string representing the type of style being applied by this statement. | ||||||||||
| 266 | |||||||||||
| 267 | Example: | ||||||||||
| 268 | |||||||||||
| 269 | if( $newStyle->type != "text/css" ) | ||||||||||
| 270 | { | ||||||||||
| 271 | # not supported! | ||||||||||
| 272 | warnCSS(); | ||||||||||
| 273 | } | ||||||||||
| 274 | |||||||||||
| 275 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLStyleElement/type> | ||||||||||
| 276 | |||||||||||
| 277 | =head1 METHODS | ||||||||||
| 278 | |||||||||||
| 279 | Inherits methods from its parent L<HTML::Object::DOM::Element> | ||||||||||
| 280 | |||||||||||
| 281 | =head1 AUTHOR | ||||||||||
| 282 | |||||||||||
| 283 | Jacques Deguest E<lt>F<jack@deguest.jp>E<gt> | ||||||||||
| 284 | |||||||||||
| 285 | =head1 SEE ALSO | ||||||||||
| 286 | |||||||||||
| 287 | L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLStyleElement>, L<Mozilla documentation on style element|https://developer.mozilla.org/en-US/docs/Web/HTML/Element/style> | ||||||||||
| 288 | |||||||||||
| 289 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 290 | |||||||||||
| 291 | Copyright(c) 2021 DEGUEST Pte. Ltd. | ||||||||||
| 292 | |||||||||||
| 293 | All rights reserved | ||||||||||
| 294 | |||||||||||
| 295 | This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||
| 296 | |||||||||||
| 297 | =cut | ||||||||||