Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
49 changes: 49 additions & 0 deletions resources/perf.webkit.org/public/v3/components/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,66 @@ class ComponentBase extends CommonComponentBase {
{
if (!ComponentBase._componentsToRenderOnResize) {
ComponentBase._componentsToRenderOnResize = new Set;
ComponentBase._mediaQueryLists = [];

// Set up window resize listener
window.addEventListener('resize', () => {
const resized = this._resizedComponents(ComponentBase._componentsToRenderOnResize);
for (const component of resized)
component.enqueueToRender();
});

// Set up media query listeners for common breakpoints
const mediaQueries = [
'(max-width: 767px)',
'(min-width: 768px) and (max-width: 1199px)'
];

for (const query of mediaQueries) {
const mediaQueryList = window.matchMedia(query);

// Add change listener for the media query (compatible with both modern and older browsers)
const mediaQueryHandler = (event) => {
// When media query state changes, update all components that respond to resize
for (const component of ComponentBase._componentsToRenderOnResize)
component.enqueueToRender();
};

// Try modern addEventListener first, fall back to older addListener if needed
if (mediaQueryList.addEventListener) {
mediaQueryList.addEventListener('change', mediaQueryHandler);
} else if (mediaQueryList.addListener) {
// Older implementation (for IE and older browsers)
mediaQueryList.addListener(mediaQueryHandler);
}

ComponentBase._mediaQueryLists.push({
query: mediaQueryList,
handler: mediaQueryHandler
});
}
}
ComponentBase._componentsToRenderOnResize.add(component);
}

static _disconnectedComponentToRenderOnResize(component)
{
ComponentBase._componentsToRenderOnResize.delete(component);

// If no more components need resize monitoring, clean up the media query listeners
if (ComponentBase._componentsToRenderOnResize.size === 0 && ComponentBase._mediaQueryLists) {
// In a real application, we might want to remove the event listeners here
// For browsers that support it, we could do:
// for (const item of ComponentBase._mediaQueryLists) {
// if (item.query.removeEventListener) {
// item.query.removeEventListener('change', item.handler);
// } else if (item.query.removeListener) {
// item.query.removeListener(item.handler);
// }
// }
// But for benchmarking purposes, we'll just set to null
ComponentBase._mediaQueryLists = null;
}
}

_ensureShadowTree()
Expand Down Expand Up @@ -272,3 +320,4 @@ ComponentBase._componentByClass = new Map;
ComponentBase._currentlyConstructedByInterface = new Map;
ComponentBase._componentsToRender = null;
ComponentBase._componentsToRenderOnResize = null;
ComponentBase._mediaQueryLists = null;
1 change: 1 addition & 0 deletions resources/perf.webkit.org/public/v3/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class SpinningPage extends Page {
function main() {
const requiredFeatures = {
'Shadow DOM API': () => { return !!Element.prototype.attachShadow; },
'matchMedia API': () => { return !!window.matchMedia; },
};

for (const name in requiredFeatures) {
Expand Down
Loading