File Coverage

lib/HTML/Object/DOM/Screen.pm
Criterion Covered Total %
statement 23 38 60.5
branch 1 2 50.0
condition n/a
subroutine 8 23 34.7
pod 16 16 100.0
total 48 79 60.7


line stmt bran cond sub pod time code
1             ##----------------------------------------------------------------------------
2             ## HTML Object - ~/lib/HTML/Object/DOM/Screen.pm
3             ## Version v0.2.0
4             ## Copyright(c) 2021 DEGUEST Pte. Ltd.
5             ## Author: Jacques Deguest <jack@deguest.jp>
6             ## Created 2021/12/31
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::Screen;
15             BEGIN
16             {
17 28     28   207 use strict;
  28         72  
  28         860  
18 28     28   161 use warnings;
  28         89  
  28         785  
19 28     28   142 use parent qw( HTML::Object::EventTarget );
  28         61  
  28         146  
20 28     28   1789 use vars qw( $VERSION );
  28         56  
  28         1218  
21 28     28   485 our $VERSION = 'v0.2.0';
22             };
23              
24 28     28   146 use strict;
  28         62  
  28         541  
25 28     28   135 use warnings;
  28         52  
  28         9574  
26              
27             sub init
28             {
29 28     28 1 3743 my $self = shift( @_ );
30 28         2795 $self->{_init_strict_use_sub} = 1;
31 28 50       250 $self->SUPER::init( @_ ) || return( $self->pass_error );
32 28         87 return( $self );
33             }
34              
35             # Note: property availHeight
36 0     0 1   sub availHeight : lvalue { return( shift->_set_get_number( 'availheight', @_ ) ); }
37              
38             # Note: property availLeft
39 0     0 1   sub availLeft : lvalue { return( shift->_set_get_number( 'availleft', @_ ) ); }
40              
41             # Note: property availTop
42 0     0 1   sub availTop : lvalue { return( shift->_set_get_number( 'availtop', @_ ) ); }
43              
44             # Note: property availWidth
45 0     0 1   sub availWidth : lvalue { return( shift->_set_get_number( 'availwidth', @_ ) ); }
46              
47             # Note: property colorDepth
48 0     0 1   sub colorDepth : lvalue { return( shift->_set_get_number( 'colordepth', @_ ) ); }
49              
50             # Note: property height
51 0     0 1   sub height : lvalue { return( shift->_set_get_number( 'height', @_ ) ); }
52              
53             # Note: property left
54 0     0 1   sub left : lvalue { return( shift->_set_get_number( 'left', @_ ) ); }
55              
56 0     0 1   sub lockOrientation { return( shift->_set_get_scalar_as_object( 'lockorientation', @_ ) ); }
57              
58             # Note: property mozBrightness
59 0     0 1   sub mozBrightness : lvalue { return( shift->_set_get_number( 'mozbrightness', @_ ) ); }
60              
61             # Note: property mozEnabled
62 0     0 1   sub mozEnabled : lvalue { return( shift->_set_get_boolean( 'mozenabled', @_ ) ); }
63              
64             # Note: property orientation
65 0     0 1   sub orientation : lvalue { return( shift->_set_get_scalar_as_object( 'orientation', @_ ) ); }
66              
67             # Note: property pixelDepth
68 0     0 1   sub pixelDepth : lvalue { return( shift->_set_get_number( 'pixeldepth', @_ ) ); }
69              
70             # Note: property top
71 0     0 1   sub top : lvalue { return( shift->_set_get_number( 'top', @_ ) ); }
72              
73 0     0 1   sub unlockOrientation { return; }
74              
75             # Note: property width
76 0     0 1   sub width : lvalue { return( shift->_set_get_number( 'width', @_ ) ); }
77              
78             1;
79             # NOTE: POD
80             __END__
81              
82             =encoding utf-8
83              
84             =head1 NAME
85              
86             HTML::Object::DOM::Screen - HTML Object DOM Screen Class
87              
88             =head1 SYNOPSIS
89              
90             use HTML::Object::DOM::Screen;
91             my $screen = HTML::Object::DOM::Screen->new ||
92             die( HTML::Object::DOM::Screen->error, "\n" );
93              
94             =head1 VERSION
95              
96             v0.2.0
97              
98             =head1 DESCRIPTION
99              
100             The C<Screen> interface represents the screen, the only one, under perl, on which the current L<window object|HTML::Object::DOM::Window> exists, and is obtained using L<HTML::Object::DOM::Window/screen>.
101              
102             =head1 INHERITANCE
103              
104             +-----------------------+ +---------------------------+ +---------------------------+
105             | HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Screen |
106             +-----------------------+ +---------------------------+ +---------------------------+
107              
108             =head1 PROPERTIES
109              
110             Inherits properties from its parent L<HTML::Object::EventTarget>
111              
112             =head2 availHeight
113              
114             Normally this returns C<undef> under perl, but you can set whatever number value you want.
115              
116             Under JavaScript, this specifies the height of the screen, in pixels, minus permanent or semipermanent user interface features displayed by the operating system, such as the Taskbar on Windows.
117              
118             Example:
119              
120             use HTML::Object::DOM qw( screen window );
121             my $availHeight = window->screen->availHeight;
122              
123             my $paletteWindow = window->open( "panels.html", "Panels", "left=0, top=0, width=200" );
124              
125             Another example:
126              
127             window->outerHeight = window->screen->availHeight;
128              
129             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Screen/availHeight>
130              
131             =head2 availLeft
132              
133             Normally this returns C<undef> under perl, but you can set whatever number value you want.
134              
135             Under JavaScript, this returns the first available pixel available from the left side of the screen.
136              
137             Example:
138              
139             use HTML::Object::DOM qw( screen window );
140             my $availLeft = window->screen->availLeft;
141              
142             my $setX = window->screen->width - window->screen->availLeft;
143             my $setY = window->screen->height - window->screen->availTop;
144             # The following does absolutely nothing in perl, obviously
145             window->moveTo( $setX, $setY );
146              
147             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Screen/availLeft>
148              
149             =head2 availTop
150              
151             Normally this returns C<undef> under perl, but you can set whatever number value you want.
152              
153             Under JavaScript, this specifies the y-coordinate of the first pixel that is not allocated to permanent or semipermanent user interface features.
154              
155             Example:
156              
157             my $availTop = window->screen->availTop;
158              
159             my $setX = window->screen->width - window->screen->availLeft;
160             my $setY = window->screen->height - window->screen->availTop;
161             # The following does absolutely nothing in perl, obviously
162             window->moveTo( $setX, $setY );
163              
164             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Screen/availTop>
165              
166             =head2 availWidth
167              
168             Normally this returns C<undef> under perl, but you can set whatever number value you want.
169              
170             Under JavaScript, this returns the amount of horizontal space in pixels available to the window.
171              
172             Example:
173              
174             my $width = window->screen->availWidth
175              
176             my $screenAvailWidth = window->screen->availWidth;
177              
178             say( $screenAvailWidth );
179              
180             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Screen/availWidth>
181              
182             =head2 colorDepth
183              
184             Normally this returns C<undef> under perl, but you can set whatever number value you want.
185              
186             Under JavaScript, this returns the color depth of the screen.
187              
188             Example:
189              
190             use HTML::Object::DOM qw( screen window );
191             # Check the color depth of the screen
192             if( window->screen->colorDepth < 8 )
193             {
194             # Use low-color version of page
195             }
196             else
197             {
198             # Use regular, colorful page
199             }
200              
201             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Screen/colorDepth>
202              
203             =head2 height
204              
205             Normally this returns C<undef> under perl, but you can set whatever number value you want.
206              
207             Under JavaScript, this returns the height of the screen in pixels.
208              
209             Example:
210              
211             my $height = window->screen->height
212              
213             use HTML::Object::DOM qw( screen window );
214             if( window->screen->availHeight !== window->screen->height )
215             {
216             # Something is occupying some screen real estate!
217             }
218              
219             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Screen/height>
220              
221             =head2 left
222              
223             Normally this returns C<undef> under perl, but you can set whatever number value you want.
224              
225             Under JavaScript, this returns the distance in pixels from the left side of the main screen to the left side of the current screen.
226              
227             Example:
228              
229             use HTML::Object::DOM qw( screen window );
230             my $left = window->screen->left;
231              
232             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Screen/left>
233              
234             =head2 lockOrientation
235              
236             Under perl environment this returns C<undef> by default, but you can set whatever value you want.
237              
238             Under JavaScript, this locks the screen into a specified orientation into which to lock the screen. This is either a string or an array of strings. Passing several strings lets the screen rotate only in the selected orientations.
239              
240             Possible values that are not enforced under this perl interface are:
241              
242             =over 4
243              
244             =item portrait-primary
245              
246             It represents the orientation of the screen when it is in its primary portrait mode. A screen is considered in its primary portrait mode if the device is held in its normal position and that position is in portrait, or if the normal position of the device is in landscape and the device held turned by 90° clockwise. The normal position is device dependant.
247              
248             =item portrait-secondary
249              
250             It represents the orientation of the screen when it is in its secondary portrait mode. A screen is considered in its secondary portrait mode if the device is held 180° from its normal position and that position is in portrait, or if the normal position of the device is in landscape and the device held is turned by 90° counterclockwise. The normal position is device dependant.
251              
252             =item landscape-primary
253              
254             It represents the orientation of the screen when it is in its primary landscape mode. A screen is considered in its primary landscape mode if the device is held in its normal position and that position is in landscape, or if the normal position of the device is in portrait and the device held is turned by 90° clockwise. The normal position is device dependant.
255              
256             =item landscape-secondary
257              
258             It represents the orientation of the screen when it is in its secondary landscape mode. A screen is considered in its secondary landscape mode if the device held is 180° from its normal position and that position is in landscape, or if the normal position of the device is in portrait and the device held is turned by 90° counterclockwise. The normal position is device dependant.
259              
260             =item portrait
261              
262             It represents both portrait-primary and portrait-secondary.
263              
264             =item landscape
265              
266             It represents both landscape-primary and landscape-secondary.
267              
268             =item default
269              
270             It represents either portrait-primary and landscape-primary depends on natural orientation of devices. For example, if the panel resolution is 1280*800, default will make it landscape, if the resolution is 800*1280, default will make it to portrait.
271              
272             =back
273              
274             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Screen/lockOrientation>
275              
276             =head2 mozBrightness
277              
278             Normally this returns C<undef> under perl, but you can set whatever number value you want.
279              
280             Under JavaScript, this Controls the brightness of a device's screen. A double between 0 and 1.0 is expected.
281              
282             Example:
283              
284             use HTML::Object::DOM qw( screen window );
285             my $screenBrightness = window->screen->mozBrightness;
286              
287             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Screen/mozBrightness>
288              
289             =head2 mozEnabled
290              
291             Normally this is read-only, but under perl you can set whatever boolean value you want.
292              
293             Under JavaScript, when this is set to false, it will turn off the device's screen.
294              
295             Example:
296              
297             use HTML::Object::DOM qw( screen window );
298             my $screenEnabled = window->screen->mozEnabled
299              
300             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Screen/mozEnabled>
301              
302             =head2 orientation
303              
304             Normally this returns C<undef> under perl, but you can set whatever string value you want. This returns a L<scalar object|Module::Generic::Scalar>
305              
306             Under JavaScript, this returns the C<ScreenOrientation> instance associated with this screen.
307              
308             Example:
309              
310             use HTML::Object::DOM qw( screen window );
311             my $orientation = screen->$orientation;
312              
313             my $orientation = screen->orientation;
314              
315             if( $orientation == "landscape-primary" )
316             {
317             say( "That looks good." );
318             }
319             elsif( $orientation == "landscape-secondary" )
320             {
321             say( "Mmmh... the screen is upside down!" );
322             }
323             elsif( $orientation == "portrait-secondary" || $orientation == "portrait-primary" )
324             {
325             say( "Mmmh... you should rotate your device to landscape" );
326             }
327             elsif( $orientation == undefined )
328             {
329             say( "The orientation API is not supported in this browser :(" );
330             }
331              
332             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Screen/orientation>
333              
334             =head2 pixelDepth
335              
336             Normally this returns C<undef> under perl, but you can set whatever number value you want.
337              
338             Under JavaScript, this gets the bit depth of the screen.
339              
340             Example:
341              
342             use HTML::Object::DOM qw( screen window );
343             my $depth = window->screen->pixelDepth
344              
345             # if there is not adequate bit depth
346             # choose a simpler color
347             if( window->screen->pixelDepth > 8 )
348             {
349             $doc->style->color = "#FAEBD7";
350             }
351             else
352             {
353             $doc->style->color = "#FFFFFF";
354             }
355              
356             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Screen/pixelDepth>
357              
358             =head2 top
359              
360             Normally this returns C<undef> under perl, but you can set whatever number value you want.
361              
362             Under JavaScript, this returns the distance in pixels from the top side of the current screen.
363              
364             Example:
365              
366             use HTML::Object::DOM qw( screen window );
367             my $top = window->screen->top;
368              
369             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Screen/top>
370              
371             =head2 width
372              
373             Normally this returns C<undef> under perl, but you can set whatever number value you want.
374              
375             Under JavaScript, this returns the width of the screen.
376              
377             Example:
378              
379             use HTML::Object::DOM qw( screen window );
380             my $lWidth = window->screen->width
381              
382             # Crude way to check that the screen is at least 1024x768
383             if( window->screen->width >= 1024 && window->screen->height >= 768 )
384             {
385             # Resolution is 1024x768 or above
386             }
387              
388             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Screen/width>
389              
390             =head1 METHODS
391              
392             Inherits methods from its parent L<HTML::Object::EventTarget>
393              
394             =head2 unlockOrientation
395              
396             This always returns C<undef> under perl.
397              
398             Normally, under JavaScript, this unlocks the screen orientation (only works in fullscreen or for installed apps)
399              
400             See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Screen/unlockOrientation>
401              
402             =head1 AUTHOR
403              
404             Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
405              
406             =head1 SEE ALSO
407              
408             L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/Window>
409              
410             =head1 COPYRIGHT & LICENSE
411              
412             Copyright(c) 2021 DEGUEST Pte. Ltd.
413              
414             All rights reserved
415              
416             This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
417              
418             =cut