Commit ffdd8ad5 authored by Fergal Daly's avatar Fergal Daly Committed by Commit Bot

Reformat all of our .mjs files with clang-format --style=file

Tweak space-before-function-paren rules to be comatible with clang-format.

Change-Id: I686766972996f652a8ffe15f724227279117bbb6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1767284
Commit-Queue: Fergal Daly <fergal@chromium.org>
Reviewed-by: default avatarDomenic Denicola <domenic@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#690266}
parent d20f64b9
...@@ -272,7 +272,8 @@ module.exports = { ...@@ -272,7 +272,8 @@ module.exports = {
'space-before-function-paren': [ 'space-before-function-paren': [
'error', 'error',
{ {
anonymous: 'always', anonymous: 'never',
asyncArrow: 'always',
named: 'never' named: 'never'
} }
], ],
......
...@@ -37,7 +37,7 @@ function installGetter(proto, propName, getter) { ...@@ -37,7 +37,7 @@ function installGetter(proto, propName, getter) {
export function installPropertiesAndFunctions(proto, internals) { export function installPropertiesAndFunctions(proto, internals) {
reflection.installBool(proto, 'disabled'); reflection.installBool(proto, 'disabled');
reflection.installString(proto, 'name'); reflection.installString(proto, 'name');
installGetter(proto, 'type', function () { installGetter(proto, 'type', function() {
if (!(this instanceof proto.constructor)) { if (!(this instanceof proto.constructor)) {
throw new TypeError( throw new TypeError(
'The context object is not an instance of ' + proto.contructor.name); 'The context object is not an instance of ' + proto.contructor.name);
...@@ -45,28 +45,28 @@ export function installPropertiesAndFunctions(proto, internals) { ...@@ -45,28 +45,28 @@ export function installPropertiesAndFunctions(proto, internals) {
return this.localName; return this.localName;
}); });
installGetter(proto, 'form', function () { installGetter(proto, 'form', function() {
return this[internals].form; return this[internals].form;
}); });
installGetter(proto, 'willValidate', function () { installGetter(proto, 'willValidate', function() {
return this[internals].willValidate; return this[internals].willValidate;
}); });
installGetter(proto, 'validity', function () { installGetter(proto, 'validity', function() {
return this[internals].validity; return this[internals].validity;
}); });
installGetter(proto, 'validationMessage', function () { installGetter(proto, 'validationMessage', function() {
return this[internals].validationMessage; return this[internals].validationMessage;
}); });
installGetter(proto, 'labels', function () { installGetter(proto, 'labels', function() {
return this[internals].labels; return this[internals].labels;
}); });
proto.checkValidity = function () { proto.checkValidity = function() {
return this[internals].checkValidity(); return this[internals].checkValidity();
}; };
proto.reportValidity = function () { proto.reportValidity = function() {
return this[internals].reportValidity(); return this[internals].reportValidity();
}; };
proto.setCustomValidity = function (error) { proto.setCustomValidity = function(error) {
if (error === undefined) { if (error === undefined) {
throw new TypeError('Too few arguments'); throw new TypeError('Too few arguments');
} }
......
...@@ -2,10 +2,11 @@ ...@@ -2,10 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import * as face from './face_utils.mjs';
import * as reflection from '../internal/reflection.mjs'; import * as reflection from '../internal/reflection.mjs';
import {SwitchTrack} from './track.mjs';
import * as face from './face_utils.mjs';
import * as style from './style.mjs'; import * as style from './style.mjs';
import {SwitchTrack} from './track.mjs';
const generateStyleSheet = style.styleSheetFactory(); const generateStyleSheet = style.styleSheetFactory();
...@@ -33,8 +34,9 @@ export class StdSwitchElement extends HTMLElement { ...@@ -33,8 +34,9 @@ export class StdSwitchElement extends HTMLElement {
constructor() { constructor() {
super(); super();
if (new.target !== StdSwitchElement) { if (new.target !== StdSwitchElement) {
throw new TypeError('Illegal constructor: StdSwitchElement is not ' + throw new TypeError(
'extensible for now'); 'Illegal constructor: StdSwitchElement is not ' +
'extensible for now');
} }
this[_internals] = this.attachInternals(); this[_internals] = this.attachInternals();
this._initializeDOM(); this._initializeDOM();
......
...@@ -114,8 +114,8 @@ export class StdToastElement extends HTMLElement { ...@@ -114,8 +114,8 @@ export class StdToastElement extends HTMLElement {
get action() { get action() {
return this.#actionSlot.assignedNodes().length !== 0 ? return this.#actionSlot.assignedNodes().length !== 0 ?
this.#actionSlot.assignedNodes()[0] : this.#actionSlot.assignedNodes()[0] :
null; null;
} }
set action(val) { set action(val) {
...@@ -173,8 +173,9 @@ export class StdToastElement extends HTMLElement { ...@@ -173,8 +173,9 @@ export class StdToastElement extends HTMLElement {
show({duration = DEFAULT_DURATION} = {}) { show({duration = DEFAULT_DURATION} = {}) {
if (duration <= 0) { if (duration <= 0) {
throw new RangeError(`Invalid Argument: duration must be greater ` + throw new RangeError(
`than 0 [${duration} given]`); `Invalid Argument: duration must be greater ` +
`than 0 [${duration} given]`);
} }
this.setAttribute('open', ''); this.setAttribute('open', '');
...@@ -224,12 +225,7 @@ delete StdToastElement.prototype.connectedCallback; ...@@ -224,12 +225,7 @@ delete StdToastElement.prototype.connectedCallback;
export function showToast(message, options = {}) { export function showToast(message, options = {}) {
const toast = new StdToastElement(message); const toast = new StdToastElement(message);
const { const {action, closeButton, type, ...showOptions} = options;
action,
closeButton,
type,
...showOptions
} = options;
if (isElement(action)) { if (isElement(action)) {
toast.action = action; toast.action = action;
...@@ -258,8 +254,7 @@ export function showToast(message, options = {}) { ...@@ -258,8 +254,7 @@ export function showToast(message, options = {}) {
return toast; return toast;
} }
const idGetter = const idGetter = Object.getOwnPropertyDescriptor(Element.prototype, 'id').get;
Object.getOwnPropertyDescriptor(Element.prototype, 'id').get;
function isElement(value) { function isElement(value) {
try { try {
idGetter.call(value); idGetter.call(value);
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* *
* @param {!Set} a A set of elements. * @param {!Set} a A set of elements.
* @param {!Set} b A set of elements. * @param {!Set} b A set of elements.
*/ */
export function difference(a, b) { export function difference(a, b) {
const result = new Set(); const result = new Set();
for (const element of a) { for (const element of a) {
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
* element. * element.
* @package * @package
*/ */
import * as sets from './sets.mjs';
import * as findElement from './find-element.mjs'; import * as findElement from './find-element.mjs';
import * as sets from './sets.mjs';
// This controls how much above and below the current screen we // This controls how much above and below the current screen we
...@@ -61,7 +61,7 @@ const EMPTY_ELEMENT_BOUNDS = new ElementBounds(null, null); ...@@ -61,7 +61,7 @@ const EMPTY_ELEMENT_BOUNDS = new ElementBounds(null, null);
* *
* This tracks an average measured element size as elements are added * This tracks an average measured element size as elements are added
* and removed. * and removed.
*/ */
class SizeManager { class SizeManager {
#sizes = new WeakMap(); #sizes = new WeakMap();
...@@ -97,11 +97,12 @@ class SizeManager { ...@@ -97,11 +97,12 @@ class SizeManager {
return size === undefined ? this.#getAverageSize() : size; return size === undefined ? this.#getAverageSize() : size;
} }
#getAverageSize = () => { #getAverageSize =
return this.#measuredCount > 0 ? () => {
this.#totalMeasuredSize / this.#measuredCount : return this.#measuredCount > 0 ?
DEFAULT_HEIGHT_ESTIMATE_PX; this.#totalMeasuredSize / this.#measuredCount :
} DEFAULT_HEIGHT_ESTIMATE_PX;
}
/** /**
* Removes all data related to |element| from the manager. * Removes all data related to |element| from the manager.
...@@ -127,7 +128,7 @@ class SizeManager { ...@@ -127,7 +128,7 @@ class SizeManager {
* It uses resize and intersection observers on all of the visible * It uses resize and intersection observers on all of the visible
* elements to ensure that changes that impact visibility cause us to * elements to ensure that changes that impact visibility cause us to
* recalulate things (e.g. scrolling, restyling). * recalulate things (e.g. scrolling, restyling).
*/ */
export class VisibilityManager { export class VisibilityManager {
#sizeManager = new SizeManager(); #sizeManager = new SizeManager();
#elements; #elements;
...@@ -163,51 +164,52 @@ export class VisibilityManager { ...@@ -163,51 +164,52 @@ export class VisibilityManager {
* Attempts to unlock a range of elements suitable for the current * Attempts to unlock a range of elements suitable for the current
* viewport. This causes one forced layout. * viewport. This causes one forced layout.
*/ */
#sync = () => { #sync =
if (this.#elements.length === 0) { () => {
return; if (this.#elements.length === 0) {
} return;
}
// The basic idea is ... // The basic idea is ...
// The forced layout occurs at the start. We then use the laid out // The forced layout occurs at the start. We then use the laid out
// coordinates (which are based on a mix of real sizes for // coordinates (which are based on a mix of real sizes for
// unlocked elements and the estimated sizes at the time of // unlocked elements and the estimated sizes at the time of
// locking for locked elements) to calculate a set of elements // locking for locked elements) to calculate a set of elements
// which should be revealed. We use unlock/lock to move to this // which should be revealed. We use unlock/lock to move to this
// new set of revealed elements. We will check in the next frame // new set of revealed elements. We will check in the next frame
// whether we got it correct. // whether we got it correct.
// This causes a forced layout and takes measurements of all // This causes a forced layout and takes measurements of all
// currently revealed elements. // currently revealed elements.
this.#measureRevealed(); this.#measureRevealed();
// Compute the pixel bounds of what we would like to reveal. Then // Compute the pixel bounds of what we would like to reveal. Then
// find the elements corresponding to these bounds. // find the elements corresponding to these bounds.
// TODO(fergal): Use nearest scrolling ancestor? // TODO(fergal): Use nearest scrolling ancestor?
const desiredLow = 0 - window.innerHeight * BUFFER; const desiredLow = 0 - window.innerHeight * BUFFER;
const desiredHigh = window.innerHeight + window.innerHeight * BUFFER; const desiredHigh = window.innerHeight + window.innerHeight * BUFFER;
const newBounds = this.#findElementBounds(desiredLow, desiredHigh); const newBounds = this.#findElementBounds(desiredLow, desiredHigh);
const newRevealed = newBounds.elementSet(); const newRevealed = newBounds.elementSet();
// TODO(fergal): We need to observe 1 element off the end of the // TODO(fergal): We need to observe 1 element off the end of the
// list, to cope with e.g. the scrolling region suddenly growing. // list, to cope with e.g. the scrolling region suddenly growing.
// Lock and unlock the minimal set of elements to get us to the // Lock and unlock the minimal set of elements to get us to the
// new state. // new state.
const toHide = sets.difference(this.#revealed, newRevealed); const toHide = sets.difference(this.#revealed, newRevealed);
toHide.forEach(e => this.#hide(e)); toHide.forEach(e => this.#hide(e));
const toReveal = sets.difference(newRevealed, this.#revealed); const toReveal = sets.difference(newRevealed, this.#revealed);
toReveal.forEach(e => this.#reveal(e)); toReveal.forEach(e => this.#reveal(e));
// Now we have revealed what we hope will fill the screen. It // Now we have revealed what we hope will fill the screen. It
// could be incorrect. Rather than measuring now and correcting it // could be incorrect. Rather than measuring now and correcting it
// which would involve an unknown number of forced layouts, we // which would involve an unknown number of forced layouts, we
// come back next frame and try to make it better. We know we can // come back next frame and try to make it better. We know we can
// stop when we didn't hide or reveal any elements. // stop when we didn't hide or reveal any elements.
if (toHide.size > 0 || toReveal.size > 0) { if (toHide.size > 0 || toReveal.size > 0) {
this.scheduleSync(); this.scheduleSync();
} }
} }
/** /**
* Searches within the managed elements and returns an ElementBounds * Searches within the managed elements and returns an ElementBounds
...@@ -218,34 +220,36 @@ export class VisibilityManager { ...@@ -218,34 +220,36 @@ export class VisibilityManager {
* @param {!number} low The lower bound to locate. * @param {!number} low The lower bound to locate.
* @param {!number} high The upper bound to locate. * @param {!number} high The upper bound to locate.
*/ */
#findElementBounds = (low, high) => { #findElementBounds =
const lowElement = findElement.findElement( (low, high) => {
this.#elements, low, findElement.BIAS_LOW); const lowElement =
const highElement = findElement.findElement( findElement.findElement(this.#elements, low, findElement.BIAS_LOW);
this.#elements, high, findElement.BIAS_HIGH); const highElement = findElement.findElement(
this.#elements, high, findElement.BIAS_HIGH);
if (lowElement === null) {
if (highElement === null) { if (lowElement === null) {
return EMPTY_ELEMENT_BOUNDS; if (highElement === null) {
} else { return EMPTY_ELEMENT_BOUNDS;
return new ElementBounds(this.#elements[0], highElement); } else {
return new ElementBounds(this.#elements[0], highElement);
}
} else if (highElement === null) {
return new ElementBounds(
lowElement, this.#elements[this.#elements.length - 1]);
}
return new ElementBounds(lowElement, highElement);
} }
} else if (highElement === null) {
return new ElementBounds(
lowElement, this.#elements[this.#elements.length - 1]);
}
return new ElementBounds(lowElement, highElement);
}
/** /**
* Updates the size manager with all of the currently revealed * Updates the size manager with all of the currently revealed
* elements' sizes. This will cause a forced layout. * elements' sizes. This will cause a forced layout.
*/ */
#measureRevealed = () => { #measureRevealed =
for (const element of this.#revealed) { () => {
this.#sizeManager.measure(element); for (const element of this.#revealed) {
} this.#sizeManager.measure(element);
} }
}
/** /**
* Reveals |element| so that it can be rendered. This includes * Reveals |element| so that it can be rendered. This includes
...@@ -253,31 +257,36 @@ export class VisibilityManager { ...@@ -253,31 +257,36 @@ export class VisibilityManager {
* *
* @param {!Element} element The element to reveal. * @param {!Element} element The element to reveal.
*/ */
#reveal = element => { #reveal =
this.#revealed.add(element); element => {
this.#elementIntersectionObserver.observe(element); this.#revealed.add(element);
this.#elementResizeObserver.observe(element); this.#elementIntersectionObserver.observe(element);
this.#unlock(element); this.#elementResizeObserver.observe(element);
} this.#unlock(element);
}
#logLockingError = (operation, reason, element) => { #logLockingError =
// TODO: Figure out the LAPIs error/warning logging story. (operation, reason, element) => {
console.error('Rejected: ', operation, element, reason); // eslint-disable-line no-console // TODO: Figure out the LAPIs error/warning logging story.
} console.error( // eslint-disable-line no-console
'Rejected: ', operation, element,
reason);
}
/** /**
* Unlocks |element|. * Unlocks |element|.
* *
* @param {!Element} element The element to unlock. * @param {!Element} element The element to unlock.
*/ */
#unlock = element => { #unlock =
element.displayLock.commit().catch(reason => { element => {
// Only warn if the unlocked failed and we should be revealed. element.displayLock.commit().catch(reason => {
if (this.#revealed.has(element)) { // Only warn if the unlocked failed and we should be revealed.
this.#logLockingError('Commit', reason, element); if (this.#revealed.has(element)) {
this.#logLockingError('Commit', reason, element);
}
});
} }
});
}
/** /**
* Hides |element| so that it cannot be rendered. This includes * Hides |element| so that it cannot be rendered. This includes
...@@ -285,21 +294,25 @@ export class VisibilityManager { ...@@ -285,21 +294,25 @@ export class VisibilityManager {
* *
* @param {!Element} element The element to hide. * @param {!Element} element The element to hide.
*/ */
#hide = element => { #hide =
this.#revealed.delete(element); element => {
this.#elementIntersectionObserver.unobserve(element); this.#revealed.delete(element);
this.#elementResizeObserver.unobserve(element); this.#elementIntersectionObserver.unobserve(element);
element.displayLock.acquire({ this.#elementResizeObserver.unobserve(element);
timeout: Infinity, element.displayLock
activatable: true, .acquire({
size: [LOCKED_WIDTH_PX, this.#sizeManager.getHopefulSize(element)], timeout: Infinity,
}).catch(reason => { activatable: true,
// Only warn if the lock failed and we should be locked. size:
if (!this.#revealed.has(element)) { [LOCKED_WIDTH_PX, this.#sizeManager.getHopefulSize(element)],
this.#logLockingError('Acquire', reason, element); })
.catch(reason => {
// Only warn if the lock failed and we should be locked.
if (!this.#revealed.has(element)) {
this.#logLockingError('Acquire', reason, element);
}
});
} }
});
}
/** /**
* Notify the manager that |element| has been added to the list of * Notify the manager that |element| has been added to the list of
...@@ -307,13 +320,14 @@ export class VisibilityManager { ...@@ -307,13 +320,14 @@ export class VisibilityManager {
* *
* @param {!Element} element The element that was added. * @param {!Element} element The element that was added.
*/ */
#didAdd = element => { #didAdd =
// Added children should be invisible initially. We want to make them element => {
// invisible at this MutationObserver timing, so that there is no // Added children should be invisible initially. We want to make them
// frame where the browser is asked to render all of the children // invisible at this MutationObserver timing, so that there is no
// (which could be a lot). // frame where the browser is asked to render all of the children
this.#hide(element); // (which could be a lot).
} this.#hide(element);
}
/** /**
* Notify the manager that |element| has been removed from the list * Notify the manager that |element| has been removed from the list
...@@ -321,23 +335,24 @@ export class VisibilityManager { ...@@ -321,23 +335,24 @@ export class VisibilityManager {
* *
* @param {!Element} element The element that was removed. * @param {!Element} element The element that was removed.
*/ */
#didRemove = element => { #didRemove =
// Removed children should be made visible again. We should stop element => {
// observing them and discard any size info we have for them as it // Removed children should be made visible again. We should stop
// may have become incorrect. // observing them and discard any size info we have for them as it
// // may have become incorrect.
// TODO(fergal): Decide whether to also unlock if //
// displayLock.locked is true. That would only be necessary if we // TODO(fergal): Decide whether to also unlock if
// got out of sync between this.#revealed and the locked state. So // displayLock.locked is true. That would only be necessary if we
// for now, assume are not buggy. // got out of sync between this.#revealed and the locked state. So
if (this.#revealed.has(element)) { // for now, assume are not buggy.
this.#unlock(element); if (this.#revealed.has(element)) {
} this.#unlock(element);
this.#revealed.delete(element); }
this.#elementIntersectionObserver.unobserve(element); this.#revealed.delete(element);
this.#elementResizeObserver.unobserve(element); this.#elementIntersectionObserver.unobserve(element);
this.#sizeManager.remove(element); this.#elementResizeObserver.unobserve(element);
} this.#sizeManager.remove(element);
}
/** /**
* Ensures that @see #sync() will be called at the next animation frame. * Ensures that @see #sync() will be called at the next animation frame.
...@@ -404,4 +419,3 @@ export class VisibilityManager { ...@@ -404,4 +419,3 @@ export class VisibilityManager {
} }
} }
} }
...@@ -45,10 +45,8 @@ const StorageAreaAsyncIteratorPrototype = { ...@@ -45,10 +45,8 @@ const StorageAreaAsyncIteratorPrototype = {
}; };
Object.defineProperty( Object.defineProperty(
StorageAreaAsyncIteratorPrototype, StorageAreaAsyncIteratorPrototype, Symbol.toStringTag,
Symbol.toStringTag, {writable: false, enumerable: false});
{writable: false, enumerable: false}
);
function getNextIterResult(iter, performDatabaseOperation) { function getNextIterResult(iter, performDatabaseOperation) {
return performDatabaseOperation(async (transaction, store) => { return performDatabaseOperation(async (transaction, store) => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment