Skip to content
Permalink
Browse files
2010-10-19 Pavel Feldman <pfeldman@chromium.org>
        Reviewed by Yury Semikhatsky.

        Web Inspector: migrate from legacy Object.properties to Object.keys, remove dead code.
        https://bugs.webkit.org/show_bug.cgi?id=47890

        * inspector/front-end/ConsoleView.js:
        (WebInspector.ConsoleView.prototype._reportCompletions):
        * inspector/front-end/ElementsPanel.js:
        (WebInspector.ElementsPanel):
        * inspector/front-end/ExtensionServer.js:
        (WebInspector.ExtensionServer.prototype._onGetResources):
        * inspector/front-end/HAREntry.js:
        (WebInspector.HARLog.prototype.build):
        * inspector/front-end/StylesSidebarPane.js:
        (WebInspector.StylePropertyTreeElement.prototype.):
        (WebInspector.StylePropertyTreeElement.prototype):
        * inspector/front-end/utilities.js:

Canonical link: https://commits.webkit.org/60609@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@70046 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
pavelfeldman committed Oct 19, 2010
1 parent cd440ed commit 71bc3ad492c3f09d52a2a82a61c9c6ebfa9b0bea
Showing 11 changed files with 29 additions and 140 deletions.
@@ -1,3 +1,23 @@
2010-10-19 Pavel Feldman <pfeldman@chromium.org>

Reviewed by Yury Semikhatsky.

Web Inspector: migrate from legacy Object.properties to Object.keys, remove dead code.
https://bugs.webkit.org/show_bug.cgi?id=47890

* inspector/front-end/ConsoleView.js:
(WebInspector.ConsoleView.prototype._reportCompletions):
* inspector/front-end/ElementsPanel.js:
(WebInspector.ElementsPanel):
* inspector/front-end/ExtensionServer.js:
(WebInspector.ExtensionServer.prototype._onGetResources):
* inspector/front-end/HAREntry.js:
(WebInspector.HARLog.prototype.build):
* inspector/front-end/StylesSidebarPane.js:
(WebInspector.StylePropertyTreeElement.prototype.):
(WebInspector.StylePropertyTreeElement.prototype):
* inspector/front-end/utilities.js:

2010-10-19 Pavel Feldman <pfeldman@chromium.org>

Reviewed by Yury Semikhatsky.
@@ -207,7 +207,7 @@ module core {
[handler=DOM] void getComputedStyle(in long nodeId, out Value style);
[handler=DOM] void getStyleSheet(in long styleSheetId, out Object styleSheet);
[handler=DOM] void getStyleSourceData(in long styleSheetId, out Object styleSourceData);
[handler=DOM] void applyStyleText(in long styleId, in String styleText, in String propertyName, out boolean success, out Value style, out Array changedProperties);
[handler=DOM] void applyStyleText(in long styleId, in String styleText, in String propertyName, out boolean success, out Value style);
[handler=DOM] void setStyleText(in long styleId, in String styleText, out boolean success);
[handler=DOM] void setStyleProperty(in long styleId, in String name, in String value, out boolean success);
[handler=DOM] void toggleStyleEnabled(in long styleId, in String propertyName, in boolean disabled, out Value style);
@@ -1358,7 +1358,7 @@ PassRefPtr<InspectorArray> InspectorDOMAgent::buildArrayForPseudoElements(Elemen
return result.release();
}

void InspectorDOMAgent::applyStyleText(long styleId, const String& styleText, const String& propertyName, bool* success, RefPtr<InspectorValue>* styleObject, RefPtr<InspectorArray>* changedPropertiesArray)
void InspectorDOMAgent::applyStyleText(long styleId, const String& styleText, const String& propertyName, bool* success, RefPtr<InspectorValue>* styleObject)
{
CSSStyleDeclaration* style = cssStore()->styleForId(styleId);
if (!style)
@@ -1395,7 +1395,6 @@ void InspectorDOMAgent::applyStyleText(long styleId, const String& styleText, co

// Notify caller that the property was successfully deleted.
if (!styleTextLength) {
(*changedPropertiesArray)->pushString(propertyName);
*success = true;
return;
}
@@ -1406,7 +1405,6 @@ void InspectorDOMAgent::applyStyleText(long styleId, const String& styleText, co
// Iterate of the properties on the test element's style declaration and
// add them to the real style declaration. We take care to move shorthands.
HashSet<String> foundShorthands;
Vector<String> changedProperties;

for (unsigned i = 0; i < tempStyle->length(); ++i) {
String name = tempStyle->item(i);
@@ -1433,11 +1431,9 @@ void InspectorDOMAgent::applyStyleText(long styleId, const String& styleText, co
// Remove disabled property entry for property with this name.
if (disabledStyle)
disabledStyle->remove(name);
changedProperties.append(name);
}
*success = true;
*styleObject = buildObjectForStyle(style, true);
*changedPropertiesArray = toArray(changedProperties);
}

void InspectorDOMAgent::setStyleText(long styleId, const String& cssText, bool* success)
@@ -131,7 +131,7 @@ namespace WebCore {
void getComputedStyle(long nodeId, RefPtr<InspectorValue>* styles);
void getStyleSheet(long styleSheetId, RefPtr<InspectorObject>* styleSheetObject);
void getStyleSourceData(long styleId, RefPtr<InspectorObject>* dataObject);
void applyStyleText(long styleId, const String& styleText, const String& propertyName, bool* success, RefPtr<InspectorValue>* styleObject, RefPtr<InspectorArray>* changedProperties);
void applyStyleText(long styleId, const String& styleText, const String& propertyName, bool* success, RefPtr<InspectorValue>* styleObject);
void setStyleText(long styleId, const String& cssText, bool* success);
void setStyleProperty(long styleId, const String& name, const String& value, bool* success);
void toggleStyleEnabled(long styleId, const String& propertyName, bool disabled, RefPtr<InspectorValue>* styleObject);
@@ -96,13 +96,13 @@ WebInspector.CSSStyleModel.prototype = {

applyStyleText: function(styleId, styleText, propertyName, successCallback, failureCallback)
{
function callback(success, newPayload, changedProperties)
function callback(success, newPayload)
{
if (!success)
failureCallback();
else {
var newStyle = newPayload ? WebInspector.CSSStyleDeclaration.parseStyle(newPayload) : null;
successCallback(newStyle, changedProperties);
successCallback(newStyle);
}
}

@@ -360,7 +360,7 @@ WebInspector.ConsoleView.prototype = {
}

var results = [];
var properties = Object.sortedProperties(result);
var properties = Object.keys(result).sort();

for (var i = 0; i < properties.length; ++i) {
var property = properties[i];
@@ -107,7 +107,6 @@ WebInspector.ElementsPanel = function()
this.element.appendChild(this.sidebarResizeElement);

this._registerShortcuts();
this._changedStyles = {};

this.reset();
}
@@ -346,115 +345,6 @@ WebInspector.ElementsPanel.prototype = {
// TODO: Implement Shifting the oldSelector, and its contents to a newSelector
},

addStyleChange: function(identifier, style, property)
{
if (!style.parentRule)
return;

var selector = style.parentRule.selectorText;
if (!this._changedStyles[identifier])
this._changedStyles[identifier] = {};

if (!this._changedStyles[identifier][selector])
this._changedStyles[identifier][selector] = {};

if (!this._changedStyles[identifier][selector][property])
WebInspector.styleChanges += 1;

this._changedStyles[identifier][selector][property] = style.getPropertyValue(property);
},

removeStyleChange: function(identifier, style, property)
{
if (!style.parentRule)
return;

var selector = style.parentRule.selectorText;
if (!this._changedStyles[identifier] || !this._changedStyles[identifier][selector])
return;

if (this._changedStyles[identifier][selector][property]) {
delete this._changedStyles[identifier][selector][property];
WebInspector.styleChanges -= 1;
}
},

generateStylesheet: function()
{
if (!WebInspector.styleChanges)
return;

// Merge Down to Just Selectors
var mergedSelectors = {};
for (var identifier in this._changedStyles) {
for (var selector in this._changedStyles[identifier]) {
if (!mergedSelectors[selector])
mergedSelectors[selector] = this._changedStyles[identifier][selector];
else { // merge on selector
var merge = {};
for (var property in mergedSelectors[selector])
merge[property] = mergedSelectors[selector][property];
for (var property in this._changedStyles[identifier][selector]) {
if (!merge[property])
merge[property] = this._changedStyles[identifier][selector][property];
else { // merge on property within a selector, include comment to notify user
var value1 = merge[property];
var value2 = this._changedStyles[identifier][selector][property];

if (value1 === value2)
merge[property] = [value1];
else if (value1 instanceof Array)
merge[property].push(value2);
else
merge[property] = [value1, value2];
}
}
mergedSelectors[selector] = merge;
}
}
}

var builder = [];
builder.push("/**");
builder.push(" * Inspector Generated Stylesheet"); // UIString?
builder.push(" */\n");

var indent = " ";
function displayProperty(property, value, comment) {
if (comment)
return indent + "/* " + property + ": " + value + "; */";
else
return indent + property + ": " + value + ";";
}

for (var selector in mergedSelectors) {
var psuedoStyle = mergedSelectors[selector];
var properties = Object.properties(psuedoStyle);
if (properties.length) {
builder.push(selector + " {");
for (var i = 0; i < properties.length; ++i) {
var property = properties[i];
var value = psuedoStyle[property];
if (!(value instanceof Array))
builder.push(displayProperty(property, value));
else {
if (value.length === 1)
builder.push(displayProperty(property, value) + " /* merged from equivalent edits */"); // UIString?
else {
builder.push(indent + "/* There was a Conflict... There were Multiple Edits for '" + property + "' */"); // UIString?
for (var j = 0; j < value.length; ++j)
builder.push(displayProperty(property, value, true));
}
}
}
builder.push("}\n");
}
}

WebInspector.showConsole();
WebInspector.console.addMessage(WebInspector.ConsoleMessage.createTextMessage(builder.join("\n")));
},

get rootDOMNode()
{
return this.treeOutline.rootDOMNode;
@@ -263,7 +263,7 @@ WebInspector.ExtensionServer.prototype = {
if (request.id)
response = WebInspector.resources[request.id] ? resourceWrapper(request.id) : this._status.E_NOTFOUND(request.id);
else
response = Object.properties(WebInspector.resources).map(resourceWrapper);
response = Object.keys(WebInspector.resources).map(resourceWrapper);
return response;
},

@@ -181,7 +181,7 @@ WebInspector.HARLog.prototype = {
version: webKitVersion ? webKitVersion[1] : "n/a"
},
pages: this._buildPages(),
entries: Object.properties(WebInspector.resources).map(this._convertResource)
entries: Object.keys(WebInspector.resources).map(this._convertResource)
}
},

@@ -1695,17 +1695,13 @@ WebInspector.StylePropertyTreeElement.prototype = {
self.updateTitle();
}

function successCallback(newStyle, changedProperties)
function successCallback(newStyle)
{
elementsPanel.removeStyleChange(section.identifier, self.style, self.name);

if (!styleTextLength) {
// Do remove ourselves from UI when the property removal is confirmed.
self.parent.removeChild(self);
} else {
self.style = newStyle;
for (var i = 0; i < changedProperties.length; ++i)
elementsPanel.addStyleChange(section.identifier, self.style, changedProperties[i]);
self._styleRule.style = self.style;
}

@@ -26,19 +26,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

Object.properties = function(obj)
{
var properties = [];
for (var prop in obj)
properties.push(prop);
return properties;
}

Object.sortedProperties = function(obj, sortFunc)
{
return Object.properties(obj).sort(sortFunc);
}

Function.prototype.bind = function(thisObject)
{
var func = this;

0 comments on commit 71bc3ad

Please sign in to comment.