Skip to content

Commit

Permalink
DevTools: Convert to Shadow DOM and Custom Elements v1
Browse files Browse the repository at this point in the history
Bug: 685385
Change-Id: I027e84d8003b7799492211d5fcf8348cd91fd799
Reviewed-on: https://chromium-review.googlesource.com/c/1422962
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Commit-Queue: Joel Einbinder <einbinder@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#625513}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: b00e6ea1c9b4db5d743c7c204b1f63abf89e0398
  • Loading branch information
JoelEinbinder authored and Commit Bot committed Jan 24, 2019
1 parent 7d7e3be commit 7fbe24c
Show file tree
Hide file tree
Showing 46 changed files with 192 additions and 261 deletions.
2 changes: 1 addition & 1 deletion front_end/accessibility/AXBreadcrumbsPane.js
Expand Up @@ -112,7 +112,7 @@ Accessibility.AXBreadcrumbsPane = class extends Accessibility.AccessibilitySubPa
_onKeyDown(event) {
if (!this._preselectedBreadcrumb)
return;
if (!event.path.some(element => element === this._preselectedBreadcrumb.element()))
if (!event.composedPath().some(element => element === this._preselectedBreadcrumb.element()))
return;
if (event.shiftKey || event.metaKey || event.ctrlKey)
return;
Expand Down
2 changes: 1 addition & 1 deletion front_end/accessibility/AccessibilityNodeView.js
Expand Up @@ -151,7 +151,7 @@ Accessibility.AXNodePropertyTreeElement = class extends UI.TreeElement {
* @return {!Element}
*/
static createExclamationMark(tooltip) {
const exclamationElement = createElement('label', 'dt-icon-label');
const exclamationElement = createElement('span', 'dt-icon-label');
exclamationElement.type = 'smallicon-warning';
exclamationElement.title = tooltip;
return exclamationElement;
Expand Down
4 changes: 2 additions & 2 deletions front_end/accessibility/accessibilityNode.css
Expand Up @@ -47,7 +47,7 @@ span.ax-value-undefined {
padding-left: 4px;
}

.tree-outline label[is=dt-icon-label] {
.tree-outline span[is=dt-icon-label] {
position: relative;
left: -11px;
}
Expand All @@ -74,7 +74,7 @@ span.ax-value-undefined {
left: -2px;
}

.tree-outline label[is=dt-icon-label] + .ax-name {
.tree-outline span[is=dt-icon-label] + .ax-name {
margin-left: -11px;
}

Expand Down
5 changes: 3 additions & 2 deletions front_end/changes/changesView.css
Expand Up @@ -3,14 +3,15 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
.insertion-point-main{
[slot=insertion-point-main]{
flex-direction: column;
display: flex;
}

.insertion-point-sidebar {
[slot=insertion-point-sidebar] {
overflow: auto;
}

.editor-container{
flex: 1;
}
Expand Down
2 changes: 1 addition & 1 deletion front_end/console/ConsoleViewMessage.js
Expand Up @@ -1328,7 +1328,7 @@ Console.ConsoleViewMessage = class {
return;

if (!this._repeatCountElement) {
this._repeatCountElement = createElementWithClass('label', 'console-message-repeat-count', 'dt-small-bubble');
this._repeatCountElement = createElementWithClass('span', 'console-message-repeat-count', 'dt-small-bubble');
switch (this._message.level) {
case SDK.ConsoleMessage.MessageLevel.Warning:
this._repeatCountElement.type = 'warning';
Expand Down
2 changes: 1 addition & 1 deletion front_end/console_counters/WarningErrorCounter.js
Expand Up @@ -39,7 +39,7 @@ ConsoleCounters.WarningErrorCounter = class {
*/
_createItem(shadowRoot, iconType) {
const item = createElementWithClass('span', 'counter-item');
const icon = item.createChild('label', '', 'dt-icon-label');
const icon = item.createChild('span', '', 'dt-icon-label');
icon.type = iconType;
const text = icon.createChild('span');
shadowRoot.appendChild(item);
Expand Down
4 changes: 0 additions & 4 deletions front_end/console_counters/errorWarningCounter.css
Expand Up @@ -18,10 +18,6 @@
margin-left: 6px;
}

.counter-item label {
cursor: inherit;
}

.counter-item.counter-item-first {
margin-left: 0;
}
32 changes: 13 additions & 19 deletions front_end/dom_extension/DOMExtension.js
Expand Up @@ -270,11 +270,13 @@ Node.prototype.getComponentSelection = function() {
*/
Node.prototype.hasSelection = function() {
// TODO(luoe): use contains(node, {includeShadow: true}) when it is fixed for shadow dom.
const contents = this.querySelectorAll('content');
for (const content of contents) {
if (Array.prototype.some.call(content.getDistributedNodes(), node => node.hasSelection()))
if (this instanceof Element) {
const slots = this.querySelectorAll('slot');
for (const slot of slots) {
if (Array.prototype.some.call(slot.assignedNodes(), node => node.hasSelection()))
return true;
}
}

const selection = this.getComponentSelection();
if (selection.type !== 'Range')
Expand All @@ -299,10 +301,11 @@ Element.prototype.removeChildren = function() {
* @param {string} tagName
* @param {string=} customElementType
* @return {!Element}
* @suppress {checkTypes}
* @suppressGlobalPropertiesCheck
*/
function createElement(tagName, customElementType) {
return document.createElement(tagName, customElementType || '');
return document.createElement(tagName, {is: customElementType});
}

/**
Expand All @@ -318,10 +321,11 @@ function createTextNode(data) {
* @param {string} elementName
* @param {string=} className
* @param {string=} customElementType
* @suppress {checkTypes}
* @return {!Element}
*/
Document.prototype.createElementWithClass = function(elementName, className, customElementType) {
const element = this.createElement(elementName, customElementType || '');
const element = this.createElement(elementName, {is: customElementType});
if (className)
element.className = className;
return element;
Expand Down Expand Up @@ -651,7 +655,7 @@ Node.prototype.traverseNextNode = function(stayWithin) {
if (this.shadowRoot)
return this.shadowRoot;

const distributedNodes = this.getDistributedNodes ? this.getDistributedNodes() : [];
const distributedNodes = this instanceof HTMLSlotElement ? this.assignedNodes() : [];

if (distributedNodes.length)
return distributedNodes[0];
Expand All @@ -668,34 +672,24 @@ Node.prototype.traverseNextNode = function(stayWithin) {
if (sibling)
return sibling;

node = insertionPoint(node) || node.parentNodeOrShadowHost();
node = node.assignedSlot || node.parentNodeOrShadowHost();
}

/**
* @param {!Node} node
* @return {?Node}
*/
function nextSibling(node) {
const parent = insertionPoint(node);
if (!parent)
if (!node.assignedSlot)
return node.nextSibling;
const distributedNodes = parent.getDistributedNodes ? parent.getDistributedNodes() : [];
const distributedNodes = node.assignedSlot.assignedNodes();

const position = Array.prototype.indexOf.call(distributedNodes, node);
if (position + 1 < distributedNodes.length)
return distributedNodes[position + 1];
return null;
}

/**
* @param {!Node} node
* @return {?Node}
*/
function insertionPoint(node) {
const insertionPoints = node.getDestinationInsertionPoints ? node.getDestinationInsertionPoints() : [];
return insertionPoints.length > 0 ? insertionPoints[insertionPoints.length - 1] : null;
}

return null;
};

Expand Down
7 changes: 5 additions & 2 deletions front_end/elements/ElementsSidebarPane.js
Expand Up @@ -5,8 +5,11 @@
* @unrestricted
*/
Elements.ElementsSidebarPane = class extends UI.VBox {
constructor() {
super(true);
/**
* @param {boolean=} delegatesFocus
*/
constructor(delegatesFocus) {
super(true, delegatesFocus);
this.element.classList.add('flex-none');
this._computedStyleModel = new Elements.ComputedStyleModel();
this._computedStyleModel.addEventListener(
Expand Down
5 changes: 2 additions & 3 deletions front_end/elements/StylesSidebarPane.js
Expand Up @@ -29,10 +29,9 @@

Elements.StylesSidebarPane = class extends Elements.ElementsSidebarPane {
constructor() {
super();
super(true /* delegatesFocus */);
this.setMinimumSize(96, 26);
this.registerRequiredCSS('elements/stylesSidebarPane.css');
this.element.tabIndex = -1;

Common.moduleSetting('colorFormat').addChangeListener(this.update.bind(this));
Common.moduleSetting('textEditorIndent').addChangeListener(this.update.bind(this));
Expand Down Expand Up @@ -95,7 +94,7 @@ Elements.StylesSidebarPane = class extends Elements.ElementsSidebarPane {
* @return {!Element}
*/
static createExclamationMark(property) {
const exclamationElement = createElement('label', 'dt-icon-label');
const exclamationElement = createElement('span', 'dt-icon-label');
exclamationElement.className = 'exclamation-mark';
if (!Elements.StylesSidebarPane.ignoreErrorsForProperty(property))
exclamationElement.type = 'smallicon-warning';
Expand Down
2 changes: 1 addition & 1 deletion front_end/elements/classesPaneWidget.css
Expand Up @@ -16,7 +16,7 @@
justify-content: flex-start;
}

.styles-element-classes-pane label {
.styles-element-classes-pane [is=dt-checkbox] {
margin-right: 15px;
}

Expand Down
2 changes: 1 addition & 1 deletion front_end/emulation/DeviceModeView.js
Expand Up @@ -74,7 +74,7 @@ Emulation.DeviceModeView = class extends UI.VBox {
this._bottomResizerElement.title = Common.UIString('Double-click for full height');

this._pageArea = this._screenArea.createChild('div', 'device-mode-page-area');
this._pageArea.createChild('content');
this._pageArea.createChild('slot');
}

_populatePresetsContainer() {
Expand Down
4 changes: 0 additions & 4 deletions front_end/emulation/sensors.css
Expand Up @@ -9,10 +9,6 @@
display: block;
}

.sensors-view label {
margin-bottom: 10px;
}

.sensors-view input {
width: 100%;
max-width: 100px;
Expand Down
2 changes: 1 addition & 1 deletion front_end/inline_editor/CSSShadowEditor.js
Expand Up @@ -68,7 +68,7 @@ InlineEditor.CSSShadowEditor = class extends UI.VBox {
* @return {!Element}
*/
_createSlider(field) {
const slider = UI.createSliderLabel(0, InlineEditor.CSSShadowEditor.maxRange, -1);
const slider = UI.createSlider(0, InlineEditor.CSSShadowEditor.maxRange, -1);
slider.addEventListener('input', this._onSliderInput.bind(this), false);
field.appendChild(slider);
return slider;
Expand Down
72 changes: 27 additions & 45 deletions front_end/inline_editor/ColorSwatch.js
Expand Up @@ -7,6 +7,17 @@
InlineEditor.ColorSwatch = class extends HTMLSpanElement {
constructor() {
super();
const root = UI.createShadowRootWithCoreStyles(this, 'inline_editor/colorSwatch.css');

this._iconElement = root.createChild('span', 'color-swatch');
this._iconElement.title = Common.UIString('Shift-click to change color format');
this._swatchInner = this._iconElement.createChild('span', 'color-swatch-inner');
this._swatchInner.addEventListener('dblclick', e => e.consume(), false);
this._swatchInner.addEventListener('mousedown', e => e.consume(), false);
this._swatchInner.addEventListener('click', this._handleClick.bind(this), true);

root.createChild('slot');
this._colorValueElement = this.createChild('span');
}

/**
Expand All @@ -15,11 +26,11 @@ InlineEditor.ColorSwatch = class extends HTMLSpanElement {
static create() {
if (!InlineEditor.ColorSwatch._constructor) {
InlineEditor.ColorSwatch._constructor =
UI.registerCustomElement('span', 'color-swatch', InlineEditor.ColorSwatch.prototype);
UI.registerCustomElement('span', 'color-swatch', InlineEditor.ColorSwatch);
}


return /** @type {!InlineEditor.ColorSwatch} */ (new InlineEditor.ColorSwatch._constructor());
return /** @type {!InlineEditor.ColorSwatch} */ (InlineEditor.ColorSwatch._constructor());
}

/**
Expand Down Expand Up @@ -133,23 +144,6 @@ InlineEditor.ColorSwatch = class extends HTMLSpanElement {
return this._iconElement;
}

/**
* @override
*/
createdCallback() {
const root = UI.createShadowRootWithCoreStyles(this, 'inline_editor/colorSwatch.css');

this._iconElement = root.createChild('span', 'color-swatch');
this._iconElement.title = Common.UIString('Shift-click to change color format');
this._swatchInner = this._iconElement.createChild('span', 'color-swatch-inner');
this._swatchInner.addEventListener('dblclick', e => e.consume(), false);
this._swatchInner.addEventListener('mousedown', e => e.consume(), false);
this._swatchInner.addEventListener('click', this._handleClick.bind(this), true);

root.createChild('content');
this._colorValueElement = this.createChild('span');
}

/**
* @param {!Event} event
*/
Expand All @@ -168,6 +162,11 @@ InlineEditor.ColorSwatch = class extends HTMLSpanElement {
InlineEditor.BezierSwatch = class extends HTMLSpanElement {
constructor() {
super();
const root = UI.createShadowRootWithCoreStyles(this, 'inline_editor/bezierSwatch.css');
this._iconElement = UI.Icon.create('smallicon-bezier', 'bezier-swatch-icon');
root.appendChild(this._iconElement);
this._textElement = this.createChild('span');
root.createChild('slot');
}

/**
Expand All @@ -176,11 +175,11 @@ InlineEditor.BezierSwatch = class extends HTMLSpanElement {
static create() {
if (!InlineEditor.BezierSwatch._constructor) {
InlineEditor.BezierSwatch._constructor =
UI.registerCustomElement('span', 'bezier-swatch', InlineEditor.BezierSwatch.prototype);
UI.registerCustomElement('span', 'bezier-swatch', InlineEditor.BezierSwatch);
}


return /** @type {!InlineEditor.BezierSwatch} */ (new InlineEditor.BezierSwatch._constructor());
return /** @type {!InlineEditor.BezierSwatch} */ (InlineEditor.BezierSwatch._constructor());
}

/**
Expand Down Expand Up @@ -210,17 +209,6 @@ InlineEditor.BezierSwatch = class extends HTMLSpanElement {
iconElement() {
return this._iconElement;
}

/**
* @override
*/
createdCallback() {
const root = UI.createShadowRootWithCoreStyles(this, 'inline_editor/bezierSwatch.css');
this._iconElement = UI.Icon.create('smallicon-bezier', 'bezier-swatch-icon');
root.appendChild(this._iconElement);
this._textElement = this.createChild('span');
root.createChild('content');
}
};

/**
Expand All @@ -229,6 +217,11 @@ InlineEditor.BezierSwatch = class extends HTMLSpanElement {
InlineEditor.CSSShadowSwatch = class extends HTMLSpanElement {
constructor() {
super();
const root = UI.createShadowRootWithCoreStyles(this, 'inline_editor/cssShadowSwatch.css');
this._iconElement = UI.Icon.create('smallicon-shadow', 'shadow-swatch-icon');
root.appendChild(this._iconElement);
root.createChild('slot');
this._contentElement = this.createChild('span');
}

/**
Expand All @@ -237,10 +230,10 @@ InlineEditor.CSSShadowSwatch = class extends HTMLSpanElement {
static create() {
if (!InlineEditor.CSSShadowSwatch._constructor) {
InlineEditor.CSSShadowSwatch._constructor =
UI.registerCustomElement('span', 'css-shadow-swatch', InlineEditor.CSSShadowSwatch.prototype);
UI.registerCustomElement('span', 'css-shadow-swatch', InlineEditor.CSSShadowSwatch);
}

return /** @type {!InlineEditor.CSSShadowSwatch} */ (new InlineEditor.CSSShadowSwatch._constructor());
return /** @type {!InlineEditor.CSSShadowSwatch} */ (InlineEditor.CSSShadowSwatch._constructor());
}

/**
Expand Down Expand Up @@ -290,15 +283,4 @@ InlineEditor.CSSShadowSwatch = class extends HTMLSpanElement {
colorSwatch() {
return this._colorSwatch;
}

/**
* @override
*/
createdCallback() {
const root = UI.createShadowRootWithCoreStyles(this, 'inline_editor/cssShadowSwatch.css');
this._iconElement = UI.Icon.create('smallicon-shadow', 'shadow-swatch-icon');
root.appendChild(this._iconElement);
root.createChild('content');
this._contentElement = this.createChild('span');
}
};
2 changes: 1 addition & 1 deletion front_end/inspector_main/renderingOptions.css
Expand Up @@ -8,7 +8,7 @@
padding: 12px;
}

label {
[is=dt-checkbox] {
margin: 0px 0px 10px 0px;
flex: none;
}
Expand Down

0 comments on commit 7fbe24c

Please sign in to comment.