Skip to content

Commit

Permalink
merge updates from official devtools
Browse files Browse the repository at this point in the history
  • Loading branch information
darwin committed Apr 28, 2017
2 parents f7a3f67 + b0f1d0e commit e8e5824
Show file tree
Hide file tree
Showing 29 changed files with 693 additions and 601 deletions.
4 changes: 1 addition & 3 deletions resources/unpacked/devtools/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -197,19 +197,16 @@ all_devtools_files = [
"front_end/emulation/deviceModeView.css",
"front_end/emulation/DeviceModeView.js",
"front_end/emulation/DeviceModeWrapper.js",
"front_end/emulation/DeviceOrientation.js",
"front_end/emulation/devicesSettingsTab.css",
"front_end/emulation/DevicesSettingsTab.js",
"front_end/emulation/EmulatedDevices.js",
"front_end/emulation/Geolocation.js",
"front_end/emulation/inspectedPagePlaceholder.css",
"front_end/emulation/InspectedPagePlaceholder.js",
"front_end/emulation/mediaQueryInspector.css",
"front_end/emulation/MediaQueryInspector.js",
"front_end/emulation/module.json",
"front_end/emulation/sensors.css",
"front_end/emulation/SensorsView.js",
"front_end/emulation/TouchModel.js",
"front_end/event_listeners/EventListenersUtils.js",
"front_end/event_listeners/eventListenersView.css",
"front_end/event_listeners/EventListenersView.js",
Expand Down Expand Up @@ -469,6 +466,7 @@ all_devtools_files = [
"front_end/sdk/DOMDebuggerModel.js",
"front_end/sdk/DebuggerModel.js",
"front_end/sdk/DOMModel.js",
"front_end/sdk/EmulationModel.js",
"front_end/sdk/FilmStripModel.js",
"front_end/sdk/HeapProfilerModel.js",
"front_end/sdk/LayerTreeBase.js",
Expand Down
40 changes: 25 additions & 15 deletions resources/unpacked/devtools/front_end/common/ParsedURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ Common.ParsedURL = class {
var match = url.match(Common.ParsedURL._urlRegex());
if (match) {
this.isValid = true;
this.scheme = match[1].toLowerCase();
this.host = match[2];
this.port = match[3];
this.path = match[4] || '/';
this.queryParams = match[5] || '';
this.fragment = match[6];
this.scheme = match[2].toLowerCase();
this.host = match[3];
this.port = match[4];
this.path = match[5] || '/';
this.queryParams = match[6] || '';
this.fragment = match[7];
} else {
if (this.url.startsWith('data:')) {
this.scheme = 'data';
Expand Down Expand Up @@ -97,12 +97,13 @@ Common.ParsedURL = class {
if (Common.ParsedURL._urlRegexInstance)
return Common.ParsedURL._urlRegexInstance;
// RegExp groups:
// 1 - scheme (using the RFC3986 grammar)
// 2 - hostname
// 3 - ?port
// 4 - ?path
// 5 - ?query
// 6 - ?fragment
// 1 - scheme, hostname, ?port
// 2 - scheme (using the RFC3986 grammar)
// 3 - hostname
// 4 - ?port
// 5 - ?path
// 6 - ?query
// 7 - ?fragment
var schemeRegex = /([A-Za-z][A-Za-z0-9+.-]*):\/\//;
var hostRegex = /([^\s\/:]*)/;
var portRegex = /(?::([\d]+))?/;
Expand All @@ -111,7 +112,7 @@ Common.ParsedURL = class {
var fragmentRegex = /(?:#(.*))?/;

Common.ParsedURL._urlRegexInstance = new RegExp(
'^' + schemeRegex.source + hostRegex.source + portRegex.source + pathRegex.source + queryRegex.source +
'^(' + schemeRegex.source + hostRegex.source + portRegex.source + ')' + pathRegex.source + queryRegex.source +
fragmentRegex.source + '$');
return Common.ParsedURL._urlRegexInstance;
}
Expand Down Expand Up @@ -210,8 +211,17 @@ Common.ParsedURL = class {
* @return {!{url: string, lineNumber: (number|undefined), columnNumber: (number|undefined)}}
*/
static splitLineAndColumn(string) {
// Only look for line and column numbers in the path to avoid matching port numbers.
var beforePathMatch = string.match(Common.ParsedURL._urlRegex());
var beforePath = '';
var pathAndAfter = string;
if (beforePathMatch) {
beforePath = beforePathMatch[1];
pathAndAfter = string.substring(beforePathMatch[1].length);
}

var lineColumnRegEx = /(?::(\d+))?(?::(\d+))?$/;
var lineColumnMatch = lineColumnRegEx.exec(string);
var lineColumnMatch = lineColumnRegEx.exec(pathAndAfter);
var lineNumber;
var columnNumber;
console.assert(lineColumnMatch);
Expand All @@ -227,7 +237,7 @@ Common.ParsedURL = class {
}

return {
url: string.substring(0, string.length - lineColumnMatch[0].length),
url: beforePath + pathAndAfter.substring(0, pathAndAfter.length - lineColumnMatch[0].length),
lineNumber: lineNumber,
columnNumber: columnNumber
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@
// found in the LICENSE file.

/**
* @implements {SDK.TargetManager.Observer}
* @implements {SDK.SDKModelObserver<!SDK.EmulationModel>}
*/
Components.CPUThrottlingManager = class extends Common.Object {
constructor() {
super();
this._throttlingRate = 1; // No throttling
SDK.targetManager.observeTargets(this, SDK.Target.Capability.Browser);
/** @type {!Set<!UI.ToolbarComboBox>} */
this._controls = new Set();
this._rates = [1, 2, 5, 10, 20];
SDK.targetManager.observeModels(SDK.EmulationModel, this);
}

/**
* @param {number} index
*/
_setRateIndex(index) {
this._throttlingRate = this._rates[index];
SDK.targetManager.targets().forEach(target => target.emulationAgent().setCPUThrottlingRate(this._throttlingRate));
for (var emulationModel of SDK.targetManager.models(SDK.EmulationModel))
emulationModel.setCPUThrottlingRate(this._throttlingRate);
var icon = null;
if (this._throttlingRate !== 1) {
Host.userMetrics.actionTaken(Host.UserMetrics.Action.CpuThrottlingEnabled);
Expand All @@ -42,18 +43,18 @@ Components.CPUThrottlingManager = class extends Common.Object {

/**
* @override
* @param {!SDK.Target} target
* @param {!SDK.EmulationModel} emulationModel
*/
targetAdded(target) {
modelAdded(emulationModel) {
if (this._throttlingRate !== 1)
target.emulationAgent().setCPUThrottlingRate(this._throttlingRate);
emulationModel.setCPUThrottlingRate(this._throttlingRate);
}

/**
* @override
* @param {!SDK.Target} target
* @param {!SDK.EmulationModel} emulationModel
*/
targetRemoved(target) {
modelRemoved(emulationModel) {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Elements.ElementsTreeElement = class extends UI.TreeElement {
this._canAddAttributes = true;
this._searchQuery = null;
this._expandedChildrenLimit = Elements.ElementsTreeElement.InitialChildrenLimit;
this._decorationsThrottler = new Common.Throttler(100);
}

/**
Expand Down Expand Up @@ -1086,10 +1087,21 @@ Elements.ElementsTreeElement = class extends UI.TreeElement {
if (this.isClosingTag())
return;

var node = this._node;
if (node.nodeType() !== Node.ELEMENT_NODE)
if (this._node.nodeType() !== Node.ELEMENT_NODE)
return;

this._decorationsThrottler.schedule(this._updateDecorationsInternal.bind(this));
}

/**
* @return {!Promise}
*/
_updateDecorationsInternal() {
if (!this.treeOutline)
return Promise.resolve();

var node = this._node;

if (!this.treeOutline._decoratorExtensions)
/** @type {!Array.<!Runtime.Extension>} */
this.treeOutline._decoratorExtensions = runtime.extensions(Components.DOMPresentationUtils.MarkerDecorator);
Expand Down Expand Up @@ -1127,7 +1139,7 @@ Elements.ElementsTreeElement = class extends UI.TreeElement {
(n === node ? decorations : descendantDecorations).push(decoration);
}

Promise.all(promises).then(updateDecorationsUI.bind(this));
return Promise.all(promises).then(updateDecorationsUI.bind(this));

/**
* @this {Elements.ElementsTreeElement}
Expand Down
85 changes: 41 additions & 44 deletions resources/unpacked/devtools/front_end/emulation/DeviceModeModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @implements {SDK.TargetManager.Observer}
* @implements {SDK.SDKModelObserver<!SDK.EmulationModel>}
* @unrestricted
*/
Emulation.DeviceModeModel = class {
Expand Down Expand Up @@ -58,11 +58,11 @@ Emulation.DeviceModeModel = class {
/** @type {number} */
this._fitScale = 1;

/** @type {?SDK.Target} */
this._target = null;
/** @type {?SDK.EmulationModel} */
this._emulationModel = null;
/** @type {?function()} */
this._onTargetAvailable = null;
SDK.targetManager.observeTargets(this, SDK.Target.Capability.Browser);
this._onModelAvailable = null;
SDK.targetManager.observeModels(SDK.EmulationModel, this);
}

/**
Expand Down Expand Up @@ -326,33 +326,33 @@ Emulation.DeviceModeModel = class {

/**
* @override
* @param {!SDK.Target} target
*/
targetAdded(target) {
if (!this._target) {
this._target = target;
if (this._onTargetAvailable) {
var callback = this._onTargetAvailable;
this._onTargetAvailable = null;
* @param {!SDK.EmulationModel} emulationModel
*/
modelAdded(emulationModel) {
if (!this._emulationModel && emulationModel.supportsDeviceEmulation()) {
this._emulationModel = emulationModel;
if (this._onModelAvailable) {
var callback = this._onModelAvailable;
this._onModelAvailable = null;
callback();
}
}
}

/**
* @override
* @param {!SDK.Target} target
* @param {!SDK.EmulationModel} emulationModel
*/
targetRemoved(target) {
if (this._target === target)
this._target = null;
modelRemoved(emulationModel) {
if (this._emulationModel === emulationModel)
this._emulationModel = null;
}

/**
* @return {?SDK.Target}
* @return {?string}
*/
target() {
return this._target;
inspectedURL() {
return this._emulationModel ? this._emulationModel.target().inspectedURL() : null;
}

_scaleSettingChanged() {
Expand Down Expand Up @@ -419,8 +419,8 @@ Emulation.DeviceModeModel = class {
* @param {boolean} resetPageScaleFactor
*/
_calculateAndEmulate(resetPageScaleFactor) {
if (!this._target)
this._onTargetAvailable = this._calculateAndEmulate.bind(this, resetPageScaleFactor);
if (!this._emulationModel)
this._onModelAvailable = this._calculateAndEmulate.bind(this, resetPageScaleFactor);
var mobile = this._isMobile();
if (this._type === Emulation.DeviceModeModel.Type.Device) {
var orientation = this._device.orientationByName(this._mode.orientation);
Expand Down Expand Up @@ -472,7 +472,7 @@ Emulation.DeviceModeModel = class {
this._uaSetting.get() === Emulation.DeviceModeModel.UA.Mobile,
this._uaSetting.get() === Emulation.DeviceModeModel.UA.Mobile);
}
var overlayModel = this._target ? this._target.model(SDK.OverlayModel) : null;
var overlayModel = this._emulationModel ? this._emulationModel.overlayModel() : null;
if (overlayModel)
overlayModel.setShowViewportSizeOnResize(this._type === Emulation.DeviceModeModel.Type.None);
this._updateCallback.call(null);
Expand Down Expand Up @@ -590,18 +590,16 @@ Emulation.DeviceModeModel = class {
* @return {!Promise.<?>}
*/
function setDeviceMetricsOverride() {
if (!this._target)
if (!this._emulationModel)
return Promise.resolve();

var clear = !pageWidth && !pageHeight && !mobile && !deviceScaleFactor && scale === 1 && !screenOrientation;
var allPromises = [];
if (resetPageScaleFactor)
allPromises.push(this._target.emulationAgent().resetPageScaleFactor());
var setDevicePromise;
if (clear) {
setDevicePromise = this._target.emulationAgent().clearDeviceMetricsOverride();
} else {
var params = {
allPromises.push(this._emulationModel.resetPageScaleFactor());
var metrics = null;
if (!clear) {
metrics = {
width: pageWidth,
height: pageHeight,
deviceScaleFactor: deviceScaleFactor,
Expand All @@ -614,10 +612,9 @@ Emulation.DeviceModeModel = class {
positionY: positionY
};
if (screenOrientation)
params.screenOrientation = {type: screenOrientation, angle: screenOrientationAngle};
setDevicePromise = this._target.emulationAgent().invoke_setDeviceMetricsOverride(params);
metrics.screenOrientation = {type: screenOrientation, angle: screenOrientationAngle};
}
allPromises.push(setDevicePromise);
allPromises.push(this._emulationModel.emulateDevice(metrics));
return Promise.all(allPromises);
}
}
Expand All @@ -627,7 +624,7 @@ Emulation.DeviceModeModel = class {
* @return {!Promise<?string>}
*/
async captureScreenshot(fullSize) {
var screenCaptureModel = this._target ? this._target.model(SDK.ScreenCaptureModel) : null;
var screenCaptureModel = this._emulationModel ? this._emulationModel.target().model(SDK.ScreenCaptureModel) : null;
if (!screenCaptureModel)
return null;

Expand All @@ -637,21 +634,20 @@ Emulation.DeviceModeModel = class {

if (!this._emulatedPageSize)
this._calculateAndEmulate(false);
var overlayModel = this._target ? this._target.model(SDK.OverlayModel) : null;
var overlayModel = this._emulationModel ? this._emulationModel.overlayModel() : null;
if (overlayModel)
overlayModel.setShowViewportSizeOnResize(false);

var pageSize = fullSize ? new UI.Size(metrics.contentWidth, metrics.contentHeight) : this._emulatedPageSize;
var promises = [];
promises.push(
this._target.emulationAgent().setVisibleSize(Math.floor(pageSize.width), Math.floor(pageSize.height)));
promises.push(this._emulationModel.setVisibleSize(Math.floor(pageSize.width), Math.floor(pageSize.height)));
if (fullSize) {
promises.push(this._target.emulationAgent().forceViewport(0, 0, 1));
promises.push(this._emulationModel.forceViewport({x: 0, y: 0, scale: 1}));
} else {
promises.push(this._target.emulationAgent().forceViewport(
Math.floor(metrics.viewportX), Math.floor(metrics.viewportY), metrics.viewportScale));
promises.push(this._emulationModel.forceViewport(
{x: Math.floor(metrics.viewportX), y: Math.floor(metrics.viewportY), scale: metrics.viewportScale}));
}
promises.push(this._target.emulationAgent().invoke_setDeviceMetricsOverride({
promises.push(this._emulationModel.emulateDevice({
width: 0,
height: 0,
deviceScaleFactor: this._appliedDeviceScaleFactor,
Expand All @@ -662,10 +658,10 @@ Emulation.DeviceModeModel = class {
await Promise.all(promises);

var screenshot = await screenCaptureModel.captureScreenshot('png', 100);
this._target.emulationAgent().setVisibleSize(
this._emulationModel.setVisibleSize(
Math.floor(this._emulatedPageSize.width * this._scale),
Math.floor(this._emulatedPageSize.height * this._scale));
this._target.emulationAgent().resetViewport();
this._emulationModel.forceViewport(null);
this._calculateAndEmulate(false);
return screenshot;
}
Expand All @@ -675,7 +671,8 @@ Emulation.DeviceModeModel = class {
* @param {boolean} mobile
*/
_applyTouch(touchEnabled, mobile) {
Emulation.MultitargetTouchModel.instance().setTouchEnabled(touchEnabled, mobile);
for (var emulationModel of SDK.targetManager.models(SDK.EmulationModel))
emulationModel.emulateTouch(touchEnabled, mobile);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ Emulation.DeviceModeView = class extends UI.VBox {
* @param {!Element} canvas
*/
_saveScreenshot(canvas) {
var url = this._model.target() && this._model.target().inspectedURL();
var url = this._model.inspectedURL();
var fileName = url ? url.trimURL().removeURLFragment() : '';
if (this._model.type() === Emulation.DeviceModeModel.Type.Device)
fileName += Common.UIString('(%s)', this._model.device().title);
Expand Down
Loading

0 comments on commit e8e5824

Please sign in to comment.