Skip to content

Commit

Permalink
[DevTools] Do not enable touch emulation when inspect mode is already…
Browse files Browse the repository at this point in the history
… engaged.

We already disable touch when togging inspect mode. But if it was enabled
before entering device mode, touch was enabled anyway.

BUG=586060

Review URL: https://codereview.chromium.org/1693493003

Cr-Commit-Position: refs/heads/master@{#375052}
  • Loading branch information
dgozman authored and Commit bot committed Feb 12, 2016
1 parent 5bf7edd commit 78c4dd4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 25 deletions.
51 changes: 27 additions & 24 deletions front_end/emulation/DeviceModeModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,42 +335,30 @@ WebInspector.DeviceModeModel.prototype = {
if (!this._target) {
this._target = target;
var domModel = WebInspector.DOMModel.fromTarget(this._target);
domModel.addEventListener(WebInspector.DOMModel.Events.InspectModeWillBeToggled, this._inspectModeWillBeToggled, this);
if (domModel)
domModel.addEventListener(WebInspector.DOMModel.Events.InspectModeWillBeToggled, this._reapplyTouch, this);
if (this._onTargetAvailable) {
var callback = this._onTargetAvailable;
this._onTargetAvailable = null;
callback();
} else {
this._reapplyTouch();
}
}
},

/**
* @param {!WebInspector.Event} event
*/
_inspectModeWillBeToggled: function(event)
{
var inspectModeEnabled = /** @type {boolean} */ (event.data);
if (inspectModeEnabled) {
this._applyTouch(false, false);
return;
}

if (this._type === WebInspector.DeviceModeModel.Type.Device)
this._applyTouch(this._device.touch(), this._device.mobile());
else if (this._type === WebInspector.DeviceModeModel.Type.None)
this._applyTouch(false, false);
else if (this._type === WebInspector.DeviceModeModel.Type.Responsive)
this._applyTouch(this._uaSetting.get() !== WebInspector.DeviceModeModel.UA.Desktop, this._uaSetting.get() === WebInspector.DeviceModeModel.UA.Mobile);
},

/**
* @override
* @param {!WebInspector.Target} target
*/
targetRemoved: function(target)
{
if (this._target === target)
if (this._target === target) {
var domModel = WebInspector.DOMModel.fromTarget(this._target);
if (domModel)
domModel.removeEventListener(WebInspector.DOMModel.Events.InspectModeWillBeToggled, this._reapplyTouch, this);
this._target = null;
}
},

_scaleSettingChanged: function()
Expand Down Expand Up @@ -427,13 +415,11 @@ WebInspector.DeviceModeModel.prototype = {
this._fitScale = this._calculateFitScale(orientation.width, orientation.height);
this._applyDeviceMetrics(new Size(orientation.width, orientation.height), this._mode.insets, this._scaleSetting.get(), this._device.deviceScaleFactor, this._device.mobile(), resetPageScaleFactor);
this._applyUserAgent(this._device.userAgent);
this._applyTouch(this._device.touch(), this._device.mobile());
this._applyScreenOrientation(this._mode.orientation == WebInspector.EmulatedDevice.Horizontal ? "landscapePrimary" : "portraitPrimary");
} else if (this._type === WebInspector.DeviceModeModel.Type.None) {
this._fitScale = this._calculateFitScale(this._availableSize.width, this._availableSize.height);
this._applyDeviceMetrics(this._availableSize, new Insets(0, 0, 0, 0), 1, 0, false, resetPageScaleFactor);
this._applyUserAgent("");
this._applyTouch(false, false);
this._applyScreenOrientation("");
} else if (this._type === WebInspector.DeviceModeModel.Type.Responsive) {
var screenWidth = this._widthSetting.get();
Expand All @@ -447,9 +433,9 @@ WebInspector.DeviceModeModel.prototype = {
this._fitScale = this._calculateFitScale(this._widthSetting.get(), this._heightSetting.get());
this._applyDeviceMetrics(new Size(screenWidth, screenHeight), new Insets(0, 0, 0, 0), this._scaleSetting.get(), this._deviceScaleFactorSetting.get() || defaultDeviceScaleFactor, mobile, resetPageScaleFactor);
this._applyUserAgent(mobile ? WebInspector.DeviceModeModel._defaultMobileUserAgent : "");
this._applyTouch(this._uaSetting.get() !== WebInspector.DeviceModeModel.UA.Desktop, mobile);
this._applyScreenOrientation(screenHeight >= screenWidth ? "portraitPrimary" : "landscapePrimary");
}
this._reapplyTouch();
this._updateCallback.call(null);
},

Expand All @@ -474,6 +460,23 @@ WebInspector.DeviceModeModel.prototype = {
this.setWidth(width);
},

_reapplyTouch: function()
{
var domModel = this._target ? WebInspector.DOMModel.fromTarget(this._target) : null;
var inspectModeEnabled = domModel ? domModel.inspectModeEnabled() : false;
if (inspectModeEnabled) {
this._applyTouch(false, false);
return;
}

if (this._type === WebInspector.DeviceModeModel.Type.Device)
this._applyTouch(this._device.touch(), this._device.mobile());
else if (this._type === WebInspector.DeviceModeModel.Type.None)
this._applyTouch(false, false);
else if (this._type === WebInspector.DeviceModeModel.Type.Responsive)
this._applyTouch(this._uaSetting.get() !== WebInspector.DeviceModeModel.UA.Desktop, this._uaSetting.get() === WebInspector.DeviceModeModel.UA.Mobile);
},

/**
* @param {string} userAgent
*/
Expand Down
12 changes: 11 additions & 1 deletion front_end/sdk/DOMModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,7 @@ WebInspector.DOMModel = function(target) {

this._showRulers = false;
this._showExtensionLines = false;
this._inspectModeEnabled = false;

this._defaultHighlighter = new WebInspector.DefaultDOMNodeHighlighter(this._agent);
this._highlighter = this._defaultHighlighter;
Expand Down Expand Up @@ -1786,12 +1787,21 @@ WebInspector.DOMModel.prototype = {
*/
function onDocumentAvailable()
{
this.dispatchEventToListeners(WebInspector.DOMModel.Events.InspectModeWillBeToggled, mode !== DOMAgent.InspectMode.None);
this._inspectModeEnabled = mode !== DOMAgent.InspectMode.None;
this.dispatchEventToListeners(WebInspector.DOMModel.Events.InspectModeWillBeToggled, this._inspectModeEnabled);
this._highlighter.setInspectMode(mode, this._buildHighlightConfig(), callback);
}
this.requestDocument(onDocumentAvailable.bind(this));
},

/**
* @return {boolean}
*/
inspectModeEnabled: function()
{
return this._inspectModeEnabled;
},

/**
* @param {boolean} showRulers
* @param {boolean} showExtensionLines
Expand Down

0 comments on commit 78c4dd4

Please sign in to comment.