Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement spatial navigation #8570

Merged
merged 155 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
155 commits
Select commit Hold shift + click to select a range
bdb7e1c
feat(player): add spatialNavigation feature
bzizmo Nov 8, 2023
b2bb855
feat(player): add spatialNavigation class
CarlosVillasenor Nov 9, 2023
d7c4ba7
feat(player): update spatialNavigation class
CarlosVillasenor Nov 14, 2023
55130bb
feat(player): modify spatialNavigation class & modify component class
CarlosVillasenor Nov 24, 2023
750c72e
Added methods getPositions, handleFocus and handleBLur for spatial na…
bzizmo Nov 29, 2023
359e6cf
Merge branch 'spatial-navigation' of https://github.com/bzizmo/video.…
bzizmo Nov 29, 2023
e1e3a59
feat(player): modify Component class, BigPlayButton class & Clickable…
CarlosVillasenor Nov 29, 2023
60a2d5e
Added import in player.js, Created base methods inside spatial-naviga…
bzizmo Dec 1, 2023
b2f4c51
feat(player): modify Component class & SpatialNavigation class
CarlosVillasenor Dec 1, 2023
3a99013
feat(player): modify Component class
CarlosVillasenor Dec 5, 2023
7e180a8
added keydown event logic for spatial-navigation
bzizmo Dec 5, 2023
713ac98
fixed conflicts on spatial-navigation, removed unused import in compo…
bzizmo Dec 5, 2023
f96e649
feat(player): modify SpatialNavigation class
CarlosVillasenor Dec 5, 2023
f81bcfc
feat(player): modify SpatialNavigation class
CarlosVillasenor Dec 6, 2023
1232d27
feat(player): modify SpatialNavigation class
CarlosVillasenor Dec 6, 2023
241bf09
feat(player): modify SpatialNavigation class
CarlosVillasenor Dec 7, 2023
e2008da
feat(player): modify SpatialNavigation class
CarlosVillasenor Dec 12, 2023
6118b1c
Added logic for moving focus to the best candidate
bzizmo Dec 12, 2023
014d6eb
Implemented move, findBestCandidate, isInDirection, and calculateDist…
bzizmo Dec 18, 2023
1966c3e
Added a new player option enableKeydownListener, Added gap: 1px to co…
bzizmo Dec 20, 2023
2289953
feat(player): modify SpatialNavigation class & Component class
CarlosVillasenor Dec 20, 2023
5b8b08d
Removed enableKeydownListener flag, as user should start the SpatialN…
bzizmo Dec 21, 2023
e8e1dfd
Merge pull request #2 from bzizmo/spatial-navigation-blur-focus
bzizmo Dec 21, 2023
0745420
Added functionality to track changes in the focusableComponents list …
bzizmo Jan 5, 2024
c54953a
feat(player): modify SpatialNavigation class, ModalDialog & Componen…
CarlosVillasenor Jan 5, 2024
2bb76c3
Merge pull request #3 from bzizmo/fix/spatial-navigation-focus-lost
bzizmo Jan 8, 2024
00ac57f
feat(player): modify ModalDialog
CarlosVillasenor Jan 8, 2024
ad6ef57
Refactor SpatialNavigation to use player.spatialNavigation
bzizmo Jan 9, 2024
72b8d8b
Merge pull request #4 from bzizmo/refactor/spatial-navigation-scope
CarlosVillasenor Jan 9, 2024
a6208eb
Added a new custom event endOfFocusableComponents
bzizmo Jan 10, 2024
bc6ca03
Added new styles for focused elements in case spatial navigation is e…
bzizmo Jan 12, 2024
47612fc
feat(player): modify SpatialNavigation class:
CarlosVillasenor Jan 13, 2024
6ba35db
Merge branch 'spatial-navigation' of https://github.com/bzizmo/video.…
CarlosVillasenor Jan 13, 2024
ba994a4
Changed to window.SpatialNabigation to this.player_.spatialNavigation
bzizmo Jan 15, 2024
4011fb5
feat(player): modify text-track-settings, created test-track-settings…
CarlosVillasenor Jan 25, 2024
a96bf43
changed handleKeyDown inside component.js, getComponents method is no…
bzizmo Jan 25, 2024
ed074cc
Merge branch 'spatial-navigation' of https://github.com/bzizmo/video.…
CarlosVillasenor Jan 25, 2024
0202a36
Merge branch 'main' into spatial-navigation
bzizmo Jan 25, 2024
0827c84
feat(player): create TrackSettingsControls Component & Modify TextTra…
CarlosVillasenor Jan 26, 2024
498edc7
feat(player): Modify ModalDialog
CarlosVillasenor Jan 26, 2024
b701a95
getIsFocusable and getIsAvailableToBeFocused methods are now acceptin…
bzizmo Jan 29, 2024
b411f1f
Merge branch 'spatial-navigation' of https://github.com/bzizmo/video.…
bzizmo Jan 29, 2024
d7e8cf2
Merge branch 'spatial-navigation' of https://github.com/bzizmo/video.…
CarlosVillasenor Jan 29, 2024
4127413
feat(player): Modify TextTrackSettings:
CarlosVillasenor Jan 30, 2024
b5c047a
feat(player): Modify CaptionSettingsMenuItem:
CarlosVillasenor Jan 30, 2024
5ee3ba0
Merge branch 'videojs:main' into spatial-navigation
bzizmo Jan 30, 2024
96a5ee9
feat(player): Modify TextTrackSelect & TextTrackFieldset:
CarlosVillasenor Jan 31, 2024
25ec8dc
feat(player): Modify TrackSettingsControls:
CarlosVillasenor Jan 31, 2024
5399c35
feat(player): Modify SpatialNavigation, Component & ModalDialog:
CarlosVillasenor Feb 1, 2024
893e2d7
Merge branch 'spatial-navigation' of https://github.com/bzizmo/video.…
CarlosVillasenor Feb 1, 2024
7bc5a83
Merge pull request #5 from bzizmo/spatial-navigation-modal-as-component
bzizmo Feb 1, 2024
6868c87
Merge branch 'videojs:main' into spatial-navigation
bzizmo Feb 2, 2024
861d8e5
Handle ENTER keydown in Modals when spatial navigation is enabled
bzizmo Feb 2, 2024
f74156d
feat(player): Modify ModalDialog, spatialNavigation, TrackSettingsCon…
CarlosVillasenor Feb 3, 2024
f3eb1cf
Implement additional RCU controls
bzizmo Feb 6, 2024
31c7f1f
Merge pull request #7 from bzizmo/rcu-controls
bzizmo Feb 7, 2024
47b7e14
feat(player): Modify Component class:
CarlosVillasenor Feb 7, 2024
02e3411
feat(player): Modify ModalDialog & CaptionSettingsMenuItem
CarlosVillasenor Feb 8, 2024
4f4b83f
feat(player): Modify SpatialNavigation class:
CarlosVillasenor Feb 9, 2024
9b7cd97
feat(player): Modify SpatialNavigation class:
CarlosVillasenor Feb 9, 2024
3ee07c7
Update src/js/component.js
CarlosVillasenor Feb 15, 2024
45e5748
Update src/js/component.js
CarlosVillasenor Feb 15, 2024
8aba907
feat(player): Modify SpatialNavigation & Component class:
CarlosVillasenor Feb 15, 2024
67d9dd1
feat(player): Modify SpatialNavigation class:
CarlosVillasenor Feb 16, 2024
23c4533
feat(player): Modify SpatialNavigation class:
CarlosVillasenor Feb 16, 2024
08a51b9
Update src/js/spatial-navigation.js
CarlosVillasenor Feb 16, 2024
2479c27
feat(player): Modify ModalDialog class & MenuItem class:
CarlosVillasenor Feb 16, 2024
5538a20
Merge branch 'spatial-navigation' of https://github.com/bzizmo/video.…
CarlosVillasenor Feb 16, 2024
2d7df4a
removed unused property, remove this.focus, which was added for testi…
bzizmo Feb 19, 2024
1780f8a
Merge branch 'spatial-navigation' of https://github.com/bzizmo/video.…
bzizmo Feb 19, 2024
c8e02ad
Merge branch 'spatial-navigation' of https://github.com/bzizmo/video.…
CarlosVillasenor Feb 19, 2024
8d0701e
Changed parameters to private, removed redundant code, removed initia…
bzizmo Feb 19, 2024
05f3008
Merge branch 'spatial-navigation' of https://github.com/bzizmo/video.…
CarlosVillasenor Feb 19, 2024
0f6a160
feat(player): solve remaining conflict:
CarlosVillasenor Feb 19, 2024
87fd178
feat(player): Rename TrackSettingsColors & TrackSettingsFont
CarlosVillasenor Feb 19, 2024
3552329
feat(player): Remove unrequired functions calls from components TextT…
CarlosVillasenor Feb 20, 2024
1972d46
Merge pull request #9 from bzizmo/spatial-nav-refac-focusable
bzizmo Feb 20, 2024
ddd5b12
feat(player): Update spatial-navigation.js's keypress return keyword.
CarlosVillasenor Feb 20, 2024
df799f7
Merge pull request #10 from bzizmo/spatial-nav-refac-keydown
bzizmo Feb 20, 2024
f88ba6e
bind focus and blur just if spatial navigation is enabled, add 1px ga…
bzizmo Feb 20, 2024
e8580e9
Merge branch 'spatial-navigation' of https://github.com/bzizmo/video.…
bzizmo Feb 20, 2024
3ff768d
feat(player): Modify calls on 'isListening' & 'isPaused' for ModalDia…
CarlosVillasenor Feb 20, 2024
deddd0a
Merge branch 'videojs:main' into spatial-navigation
bzizmo Feb 20, 2024
1d84062
feat(player): remove unrequired object on component 'TrackSettingsCon…
CarlosVillasenor Feb 21, 2024
88d66ce
Merge branch 'spatial-navigation' of https://github.com/bzizmo/video.…
CarlosVillasenor Feb 21, 2024
b7f8807
Merge pull request #11 from bzizmo/spatial-navigation
bzizmo Feb 21, 2024
c741e8a
Removed 1px gap
bzizmo Feb 21, 2024
51b0e32
feat(player): Rename function ‘getComponents’ to ‘updateFocusableComp…
CarlosVillasenor Feb 21, 2024
825e7a2
Changed SpatialNavigation class to extend EventTarget, removed redund…
bzizmo Feb 22, 2024
af22e40
Merge branch 'spatial-navigation' of https://github.com/bzizmo/video.…
bzizmo Feb 22, 2024
c310238
fix(player): fix call of 'getIsAvailableToBeFocused' that was throwin…
CarlosVillasenor Feb 22, 2024
05a98db
removed Static maps for key presses and extended keycode with the mis…
bzizmo Feb 22, 2024
004db79
Merge branch 'spatial-navigation' of https://github.com/bzizmo/video.…
bzizmo Feb 22, 2024
23c98f1
refactor(player): Modify functions of 'getIsDisabled', 'getIsExpressl…
CarlosVillasenor Feb 23, 2024
ce0683b
Conditional assignment for keycode.codes.back based on platform, chan…
bzizmo Feb 26, 2024
caf1142
Extend the object for reverse lookup, prenet Up/down keys to open a …
bzizmo Feb 27, 2024
147256b
refactor(player): Refactor 'SpatialNavKeycodes' file to not patch 'ke…
CarlosVillasenor Mar 1, 2024
4fb37ed
fix(pllayer): fix issue related to 'back' not being used properly in…
CarlosVillasenor Mar 1, 2024
46b7e24
Merge pull request #12 from bzizmo/spatial-navigation-refactor-keycodes
bzizmo Mar 4, 2024
01afc9d
feat(player): Rename imports of 'spatial-navigation-keycode' to have…
CarlosVillasenor Mar 4, 2024
4db8df4
feat(player): Add example of use of 'Client app uses a global spatial…
CarlosVillasenor Mar 4, 2024
015a537
feat(player): rename 'spatial-navigation-keycode.js' filename
CarlosVillasenor Mar 5, 2024
a574f1b
Merge pull request #14 from bzizmo/spatial-navigation-rename-keycode-…
bzizmo Mar 8, 2024
68f98f6
Merge branch 'videojs:main' into main
bzizmo Mar 8, 2024
4fa895f
Merge branch 'videojs:main' into spatial-navigation
bzizmo Mar 8, 2024
41e5f1b
Fix on src chnage issue, ESC button closing modal, expand vjs-modal-d…
bzizmo Mar 12, 2024
00a8c4c
Merge pull request #15 from bzizmo/spatial-nav-PR-issues
CarlosVillasenor Mar 12, 2024
3170a42
change file name and object name
bzizmo Mar 13, 2024
20814f7
Merge pull request #16 from bzizmo/change-file-name
bzizmo Mar 13, 2024
cc2afe0
Merge branch 'main' of https://github.com/bzizmo/video.js into spatia…
CarlosVillasenor Mar 13, 2024
91a779c
fix: Update ids of labels to use 'guid' so unit test works properly
CarlosVillasenor Mar 14, 2024
927138f
fix: update localized text in text-track-settings-font & text-track-s…
CarlosVillasenor Mar 14, 2024
4df8344
Mark some methods as private
bzizmo Mar 14, 2024
00e8677
fix: modify content of modal 'text-track-settings' to change language…
CarlosVillasenor Mar 14, 2024
5d972bc
Merge pull request #17 from bzizmo/spatial-navigation-fix-text-track-…
bzizmo Mar 14, 2024
750acdb
Merge branch 'videojs:main' into spatial-navigation
bzizmo Mar 14, 2024
361617c
fix: add missing '.' in jsdoc of text-track components
CarlosVillasenor Mar 15, 2024
d394389
Merge branch 'spatial-navigation' of https://github.com/bzizmo/video.…
CarlosVillasenor Mar 15, 2024
7a7a11b
feature: add unit test for 'text-track-select' component
CarlosVillasenor Mar 19, 2024
69e7c4f
Add test for Spatial Navigation
bzizmo Mar 20, 2024
b33f051
Merge pull request #18 from bzizmo/spatial-navigation-test
CarlosVillasenor Mar 20, 2024
829da01
test(player): Add minor test related to 'handleBlur' & 'handleFocus'
Mar 20, 2024
b8388ef
feat(player): Remove unrequired files from 'react-video-nav-app'
Mar 20, 2024
9604387
test(player): Add small test to check if 'getPositions' returns requi…
Mar 20, 2024
55f8987
test(player): add test to verify 'getPositions()' properties are not …
CarlosVillasenor Mar 21, 2024
27c480b
Add missing tests for performMediaAction_ and move
bzizmo Mar 21, 2024
34224c8
Merge pull request #19 from bzizmo/missing-spatial-navigation-tests
CarlosVillasenor Mar 21, 2024
1b8f08e
test(player): add test to for 'component.js' related to 'handleBlur'
CarlosVillasenor Mar 21, 2024
96fccee
test(player): add minor test in component related to test keypress pr…
CarlosVillasenor Mar 22, 2024
cca5423
test(player): add test for component related to 'getIsAvailableToBeFo…
CarlosVillasenor Mar 22, 2024
3f27e14
test(player): add test for Modal Dialog related to call function of s…
CarlosVillasenor Mar 22, 2024
7a9e843
test(player): add tests for 'spatial-navigation-key-codes'
CarlosVillasenor Mar 22, 2024
4cc49c6
test(player): add tests for keycodes related to 'should return event …
CarlosVillasenor Mar 22, 2024
0e32e50
test(player): add minor test for case when not required parametters a…
CarlosVillasenor Mar 22, 2024
396fd4f
test(player): add test for 'caption-settings-menu-item'
CarlosVillasenor Mar 23, 2024
6661205
feat(player): remove 'react-video-nav-app'
CarlosVillasenor Apr 7, 2024
47fa98c
Merge branch 'videojs:main' into spatial-navigation
bzizmo Apr 11, 2024
c9249a1
Merge branch 'videojs:main' into spatial-navigation
bzizmo Apr 15, 2024
c8e8d60
Move handleFocus and handleBlur from components.js to spatial-navigat…
bzizmo Apr 15, 2024
fd8a355
Merge pull request #20 from bzizmo/update-component
bzizmo Apr 15, 2024
dada396
refactor(player): refactor 'searchForTrackSelect' to be handled in th…
CarlosVillasenor Apr 15, 2024
c89b7cd
remove unrequired code in function 'searchForTrackSelect'
CarlosVillasenor Apr 16, 2024
e4b6ae2
Merge pull request #21 from bzizmo/spatial-navigation-refactor-search…
bzizmo Apr 16, 2024
e38dd44
update documentation comment to be in pair to its current use
CarlosVillasenor Apr 17, 2024
a53b7b4
remove spatial navigation keydown from modal dialog and move it to sp…
bzizmo Apr 17, 2024
19f6606
Merge branch 'videojs:main' into spatial-navigation
bzizmo Apr 17, 2024
ad25ea0
Merge branch 'spatial-navigation' of https://github.com/bzizmo/video.…
bzizmo Apr 17, 2024
791bdf1
remove useless tests
bzizmo Apr 17, 2024
72e3d07
Merge remote-tracking branch 'origin/update-modal-dialog' into update…
bzizmo Apr 17, 2024
6f99e69
Remove caption-settings-menu-item.test.js
bzizmo Apr 17, 2024
0f32adb
Merge pull request #22 from bzizmo/update-modal-dialog
bzizmo Apr 17, 2024
76827b1
Add minor test to 'searchForTrackSelect' in spatial-navigation.test.js
CarlosVillasenor Apr 17, 2024
010c402
Merge branch 'spatial-navigation' of https://github.com/bzizmo/video.…
CarlosVillasenor Apr 17, 2024
36fb9b5
Add unit test for back key and listening to events
bzizmo Apr 17, 2024
351fe23
Merge remote-tracking branch 'origin/spatial-navigation' into spatial…
bzizmo Apr 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/css/components/_button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
appearance: none;
}

// Replacement for focus in case spatial navigation is enabled
.video-js.vjs-spatial-navigation-enabled .vjs-button:focus {
outline: 0.0625em solid rgba($primary-foreground-color, 1);
box-shadow: none;
}

.vjs-control .vjs-button {
width: 100%;
height: 100%;
Expand Down
5 changes: 5 additions & 0 deletions src/css/components/_captions-settings.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
background-color: rgba($primary-background-color, 0.75);
color: $primary-foreground-color;
height: 70%;

// When Spatial Navigation is enabled
.vjs-spatial-navigation-enabled & {
height: 80%;
}
}

// Hide if an error occurs
Expand Down
4 changes: 4 additions & 0 deletions src/css/components/_control-bar.scss
bzizmo marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
@include background-color-with-alpha($primary-background-color, $primary-background-transparency);
}

.video-js.vjs-spatial-navigation-enabled .vjs-control-bar {
gap: 1px;
}

// Locks the display only if:
// - controls are not disabled
// - native controls are not used
Expand Down
5 changes: 5 additions & 0 deletions src/css/components/_slider.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@

@include box-shadow(0 0 1em $primary-foreground-color);
}

// Replacement for focus in case spatial navigation is enabled
.video-js.vjs-spatial-navigation-enabled .vjs-slider:focus {
outline: 0.0625em solid rgba($primary-foreground-color, 1);
}
195 changes: 193 additions & 2 deletions src/js/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,49 @@
return this.currentDimension('height');
}

/**
* Retrieves the position and size information of the component's element.
*
* @return {Object} An object with `boundingClientRect` and `center` properties.
* - `boundingClientRect`: An object with properties `x`, `y`, `width`,
* `height`, `top`, `right`, `bottom`, and `left`, representing
* the bounding rectangle of the element.
* - `center`: An object with properties `x` and `y`, representing
* the center point of the element. `width` and `height` are set to 0.
*/
getPositions() {
const rect = this.el_.getBoundingClientRect();

// Creating objects that mirror DOMRectReadOnly for boundingClientRect and center
const boundingClientRect = {
x: rect.x,
y: rect.y,
width: rect.width,
height: rect.height,
top: rect.top,
right: rect.right,
bottom: rect.bottom,
left: rect.left
};

// Calculating the center position
const center = {
x: rect.left + rect.width / 2,
y: rect.top + rect.height / 2,
width: 0,
height: 0,
top: rect.top + rect.height / 2,
right: rect.left + rect.width / 2,
bottom: rect.top + rect.height / 2,
left: rect.left + rect.width / 2
};

return {
boundingClientRect,
center
};
}

/**
* Set the focus to this component
*/
Expand All @@ -1308,8 +1351,8 @@
if (this.player_) {

// We only stop propagation here because we want unhandled events to fall
// back to the browser. Exclude Tab for focus trapping.
if (!keycode.isEventKey(event, 'Tab')) {
// back to the browser. Exclude Tab for focus trapping, exclude also when spatialNavigation is enabled.
if (!keycode.isEventKey(event, 'Tab') && !(this.player_.options_.playerOptions.spatialNavigation && this.player_.options_.playerOptions.spatialNavigation.enabled)) {
event.stopPropagation();
}
this.player_.handleKeyDown(event);
Expand Down Expand Up @@ -1765,6 +1808,154 @@
});
}

/**
* Decide whether an element is actually disabled or not.
*
* @function isActuallyDisabled
* @param element {Node}
* @return {boolean}
*
* @see {@link https://html.spec.whatwg.org/multipage/semantics-other.html#concept-element-disabled}
*/
getIsDisabled() {
return Boolean(this.el_.disabled);
}

/**
* Decide whether the element is expressly inert or not.
*
* @see {@link https://html.spec.whatwg.org/multipage/interaction.html#expressly-inert}
* @function isExpresslyInert
* @param element {Node}
* @return {boolean}
*/
getIsExpresslyInert() {
return this.el_.inert && !this.el_.ownerDocument.documentElement.inert;
}

/**
* Determine whether or not this component can be considered as focusable component.
*
* @param {HTMLElement} el - The HTML element representing the component.
* @return {boolean}
* If the component can be focused, will be `true`. Otherwise, `false`.
*/
getIsFocusable() {
return this.el_.tabIndex >= 0 && !(this.getIsDisabled() || this.getIsExpresslyInert());
}

/**
* Determine whether or not this component is currently visible/enabled/etc...
*
* @param {HTMLElement} el - The HTML element representing the component.
* @return {boolean}
* If the component can is currently visible & enabled, will be `true`. Otherwise, `false`.
*/
getIsAvailableToBeFocused(el) {
/**
* Decide the style property of this element is specified whether it's visible or not.
*
* @function isVisibleStyleProperty
* @param element {CSSStyleDeclaration}
* @return {boolean}
*/
function isVisibleStyleProperty(element) {
const elementStyle = window.getComputedStyle(element, null);
const thisVisibility = elementStyle.getPropertyValue('visibility');
const thisDisplay = elementStyle.getPropertyValue('display');
const invisibleStyle = ['hidden', 'collapse'];

Check warning on line 1866 in src/js/component.js

View check run for this annotation

Codecov / codecov/patch

src/js/component.js#L1862-L1866

Added lines #L1862 - L1866 were not covered by tests

return (thisDisplay !== 'none' && !invisibleStyle.includes(thisVisibility));

Check warning on line 1868 in src/js/component.js

View check run for this annotation

Codecov / codecov/patch

src/js/component.js#L1868

Added line #L1868 was not covered by tests
}

/**
* Decide whether the element is being rendered or not.
* 1. If an element has the style as "visibility: hidden | collapse" or "display: none", it is not being rendered.
* 2. If an element has the style as "opacity: 0", it is not being rendered.(that is, invisible).
* 3. If width and height of an element are explicitly set to 0, it is not being rendered.
* 4. If a parent element is hidden, an element itself is not being rendered.
* (CSS visibility property and display property are inherited.)
*
* @see {@link https://html.spec.whatwg.org/multipage/rendering.html#being-rendered}
* @function isBeingRendered
* @param element {Node}
* @return {boolean}
*/
function isBeingRendered(element) {
if (!isVisibleStyleProperty(element.parentElement)) {
return false;

Check warning on line 1886 in src/js/component.js

View check run for this annotation

Codecov / codecov/patch

src/js/component.js#L1884-L1886

Added lines #L1884 - L1886 were not covered by tests
}
if (!isVisibleStyleProperty(element) || (element.style.opacity === '0') || (window.getComputedStyle(element).height === '0px' || window.getComputedStyle(element).width === '0px')) {
return false;

Check warning on line 1889 in src/js/component.js

View check run for this annotation

Codecov / codecov/patch

src/js/component.js#L1888-L1889

Added lines #L1888 - L1889 were not covered by tests
}
return true;

Check warning on line 1891 in src/js/component.js

View check run for this annotation

Codecov / codecov/patch

src/js/component.js#L1891

Added line #L1891 was not covered by tests
}

/**
* Determine if the element is visible for the user or not.
* 1. If an element sum of its offsetWidth, offsetHeight, height and width is less than 1 is not visible.
* 2. If elementCenter.x is less than is not visible.
* 3. If elementCenter.x is more than the document's width is not visible.
* 4. If elementCenter.y is less than 0 is not visible.
* 5. If elementCenter.y is the document's height is not visible.
*
* @function isVisible
* @param element {Node}
* @return {boolean}
*/
function isVisible(element) {
if ((element.offsetWidth + element.offsetHeight + element.getBoundingClientRect().height + element.getBoundingClientRect().width) === 0) {
return false;
}

// Define elementCenter object with props of x and y
// x: Left position relative to the viewport plus element's width (no margin) divided between 2.
// y: Top position relative to the viewport plus element's height (no margin) divided between 2.
const elementCenter = {
x: element.getBoundingClientRect().left + element.offsetWidth / 2,
y: element.getBoundingClientRect().top + element.offsetHeight / 2
};

if (elementCenter.x < 0) {
return false;
}
if (elementCenter.x > (document.documentElement.clientWidth || window.innerWidth)) {
return false;

Check warning on line 1923 in src/js/component.js

View check run for this annotation

Codecov / codecov/patch

src/js/component.js#L1922-L1923

Added lines #L1922 - L1923 were not covered by tests
}
if (elementCenter.y < 0) {
return false;

Check warning on line 1926 in src/js/component.js

View check run for this annotation

Codecov / codecov/patch

src/js/component.js#L1925-L1926

Added lines #L1925 - L1926 were not covered by tests
}
if (elementCenter.y > (document.documentElement.clientHeight || window.innerHeight)) {
return false;

Check warning on line 1929 in src/js/component.js

View check run for this annotation

Codecov / codecov/patch

src/js/component.js#L1928-L1929

Added lines #L1928 - L1929 were not covered by tests
}

let pointContainer = document.elementFromPoint(elementCenter.x, elementCenter.y);

Check warning on line 1932 in src/js/component.js

View check run for this annotation

Codecov / codecov/patch

src/js/component.js#L1932

Added line #L1932 was not covered by tests

while (pointContainer) {
if (pointContainer === element) {
return true;

Check warning on line 1936 in src/js/component.js

View check run for this annotation

Codecov / codecov/patch

src/js/component.js#L1934-L1936

Added lines #L1934 - L1936 were not covered by tests
}
if (pointContainer.parentNode) {
pointContainer = pointContainer.parentNode;

Check warning on line 1939 in src/js/component.js

View check run for this annotation

Codecov / codecov/patch

src/js/component.js#L1938-L1939

Added lines #L1938 - L1939 were not covered by tests
} else {
return false;

Check warning on line 1941 in src/js/component.js

View check run for this annotation

Codecov / codecov/patch

src/js/component.js#L1941

Added line #L1941 was not covered by tests
}

}
}

// If no DOM element was passed as argument use this component's element.
if (!el) {
el = this.el();
}

// If element is visible, is being rendered & either does not have a parent element or its tabIndex is not negative.
if (isVisible(el) && isBeingRendered(el) && ((!el.parentElement) || (el.tabIndex >= 0))) {
wseymour15 marked this conversation as resolved.
Show resolved Hide resolved
return true;

Check warning on line 1954 in src/js/component.js

View check run for this annotation

Codecov / codecov/patch

src/js/component.js#L1954

Added line #L1954 was not covered by tests
}
return false;
}

/**
* Register a `Component` with `videojs` given the name and the component.
*
Expand Down
2 changes: 1 addition & 1 deletion src/js/menu/menu-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@
this.menuButton_.focus();
}
// Up Arrow or Down Arrow also 'press' the button to open the menu
} else if (keycode.isEventKey(event, 'Up') || keycode.isEventKey(event, 'Down')) {
} else if ((keycode.isEventKey(event, 'Up') || keycode.isEventKey(event, 'Down')) && !(this.player_.options_.playerOptions.spatialNavigation && this.player_.options_.playerOptions.spatialNavigation.enabled)) {

Check warning on line 311 in src/js/menu/menu-button.js

View check run for this annotation

Codecov / codecov/patch

src/js/menu/menu-button.js#L311

Added line #L311 was not covered by tests
if (!this.buttonPressed_) {
event.preventDefault();
this.pressButton();
Expand Down
15 changes: 12 additions & 3 deletions src/js/modal-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const MODAL_CLASS_NAME = 'vjs-modal-dialog';
class ModalDialog extends Component {

/**
* Create an instance of this class.
* Creates an instance of this class.
*
* @param { import('./player').default } player
* The `Player` that this class should be attached to.
Expand Down Expand Up @@ -236,6 +236,7 @@ class ModalDialog extends Component {
if (!this.opened_) {
return;
}

const player = this.player();

/**
Expand Down Expand Up @@ -265,8 +266,10 @@ class ModalDialog extends Component {
*
* @event ModalDialog#modalclose
* @type {Event}
*
* @property {boolean} [bubbles=true]
*/
this.trigger('modalclose');
this.trigger({type: 'modalclose', bubbles: true});
this.conditionalBlur_();

if (this.options_.temporary) {
Expand Down Expand Up @@ -454,7 +457,13 @@ class ModalDialog extends Component {
* @listens keydown
*/
handleKeyDown(event) {

/**
* Fired a custom keyDown event that bubbles.
*
* @event ModalDialog#modalKeydown
* @type {Event}
*/
this.trigger({type: 'modalKeydown', originalEvent: event, target: this, bubbles: true});
// Do not allow keydowns to reach out of the modal dialog.
event.stopPropagation();

Expand Down
12 changes: 12 additions & 0 deletions src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {hooks} from './utils/hooks';
import {isObject} from './utils/obj';
import keycode from 'keycode';
import icons from '../images/icons.svg';
import SpatialNavigation from './spatial-navigation.js';

// The following imports are used only to ensure that the corresponding modules
// are always included in the video.js package. Importing the modules will
Expand Down Expand Up @@ -562,6 +563,13 @@ class Player extends Component {
this.addClass('vjs-audio');
}

// Check if spatial navigation is enabled in the options.
// If enabled, instantiate the SpatialNavigation class.
if (options.spatialNavigation && options.spatialNavigation.enabled) {
this.spatialNavigation = new SpatialNavigation(this);
this.addClass('vjs-spatial-navigation-enabled');
}

// TODO: Make this smarter. Toggle user state between touching/mousing
// using events, since devices can have both touch and mouse events.
// TODO: Make this check be performed again when the window switches between monitors
Expand Down Expand Up @@ -5447,6 +5455,10 @@ Player.prototype.options_ = {
responsive: false,
audioOnlyMode: false,
audioPosterMode: false,
spatialNavigation: {
enabled: false,
horizontalSeek: false
wseymour15 marked this conversation as resolved.
Show resolved Hide resolved
},
// Default smooth seeking to false
enableSmoothSeeking: false
};
Expand Down
26 changes: 22 additions & 4 deletions src/js/slider/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,32 @@
* @listens keydown
*/
handleKeyDown(event) {

// Left and Down Arrows
if (keycode.isEventKey(event, 'Left') || keycode.isEventKey(event, 'Down')) {
const spatialNavOptions = this.options_.playerOptions.spatialNavigation;
const spatialNavEnabled = spatialNavOptions && spatialNavOptions.enabled;
const horizontalSeek = spatialNavOptions && spatialNavOptions.horizontalSeek;

Check warning on line 313 in src/js/slider/slider.js

View check run for this annotation

Codecov / codecov/patch

src/js/slider/slider.js#L311-L313

Added lines #L311 - L313 were not covered by tests

if (spatialNavEnabled) {
if ((horizontalSeek && keycode.isEventKey(event, 'Left')) ||
(!horizontalSeek && keycode.isEventKey(event, 'Down'))) {
event.preventDefault();
event.stopPropagation();
this.stepBack();
} else if ((horizontalSeek && keycode.isEventKey(event, 'Right')) ||
(!horizontalSeek && keycode.isEventKey(event, 'Up'))) {
event.preventDefault();
event.stopPropagation();
this.stepForward();

Check warning on line 325 in src/js/slider/slider.js

View check run for this annotation

Codecov / codecov/patch

src/js/slider/slider.js#L315-L325

Added lines #L315 - L325 were not covered by tests
} else {
super.handleKeyDown(event);

Check warning on line 327 in src/js/slider/slider.js

View check run for this annotation

Codecov / codecov/patch

src/js/slider/slider.js#L327

Added line #L327 was not covered by tests
}

// Left and Down Arrows
} else if (keycode.isEventKey(event, 'Left') || keycode.isEventKey(event, 'Down')) {

Check warning on line 331 in src/js/slider/slider.js

View check run for this annotation

Codecov / codecov/patch

src/js/slider/slider.js#L331

Added line #L331 was not covered by tests
event.preventDefault();
event.stopPropagation();
this.stepBack();

// Up and Right Arrows
// Up and Right Arrows
} else if (keycode.isEventKey(event, 'Right') || keycode.isEventKey(event, 'Up')) {
event.preventDefault();
event.stopPropagation();
Expand Down
Loading