Commit 8ec76011 authored by apavlov@chromium.org's avatar apavlov@chromium.org
Browse files

2010-06-04 Alexander Pavlov <apavlov@chromium.org>

        Reviewed by Pavel Feldman.

        Web Inspector: Eliminate direct dependency of StylesSidebarPane on InspectorBackend
        https://bugs.webkit.org/show_bug.cgi?id=40069

        No new tests are needed, as this is a refactoring.

        * inspector/front-end/CSSStyleModel.js: Added.
        (WebInspector.CSSStyleModel):
        (WebInspector.CSSStyleModel.prototype.getStylesAsync):
        (WebInspector.CSSStyleModel.prototype.getComputedStyleAsync):
        (WebInspector.CSSStyleModel.prototype.setRuleSelector):
        (WebInspector.CSSStyleModel.prototype.addRule):
        (WebInspector.CSSStyleModel.prototype.toggleStyleEnabled):
        (WebInspector.CSSStyleModel.prototype.setCSSText):
        (WebInspector.CSSStyleModel.prototype.applyStyleText):
        * inspector/front-end/StylesSidebarPane.js:
        (WebInspector.StylesSidebarPane.prototype.update.stylesCallback):
        (WebInspector.StylesSidebarPane.prototype.update.computedStyleCallback):
        (WebInspector.StylesSidebarPane.prototype.update):
        (WebInspector.StylesSidebarPane.prototype._arrayContainsInheritedProperty):
        (WebInspector.StylePropertiesSection.prototype.editingSelectorCommitted.successCallback):
        (WebInspector.StylePropertiesSection.prototype.editingSelectorCommitted):
        (WebInspector.BlankStylePropertiesSection.prototype.editingSelectorCommitted.successCallback):
        (WebInspector.BlankStylePropertiesSection.prototype.editingSelectorCommitted):
        (WebInspector.StylePropertyTreeElement.prototype.):
        (WebInspector.StylePropertyTreeElement.prototype):
        * inspector/front-end/inspector.html:
        * inspector/front-end/inspector.js:
        (WebInspector.loaded):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@60680 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 2b50586e
2010-06-04 Alexander Pavlov <apavlov@chromium.org>
Reviewed by Pavel Feldman.
Web Inspector: Eliminate direct dependency of StylesSidebarPane on InspectorBackend
https://bugs.webkit.org/show_bug.cgi?id=40069
No new tests are needed, as this is a refactoring.
* inspector/front-end/CSSStyleModel.js: Added.
(WebInspector.CSSStyleModel):
(WebInspector.CSSStyleModel.prototype.getStylesAsync):
(WebInspector.CSSStyleModel.prototype.getComputedStyleAsync):
(WebInspector.CSSStyleModel.prototype.setRuleSelector):
(WebInspector.CSSStyleModel.prototype.addRule):
(WebInspector.CSSStyleModel.prototype.toggleStyleEnabled):
(WebInspector.CSSStyleModel.prototype.setCSSText):
(WebInspector.CSSStyleModel.prototype.applyStyleText):
* inspector/front-end/StylesSidebarPane.js:
(WebInspector.StylesSidebarPane.prototype.update.stylesCallback):
(WebInspector.StylesSidebarPane.prototype.update.computedStyleCallback):
(WebInspector.StylesSidebarPane.prototype.update):
(WebInspector.StylesSidebarPane.prototype._arrayContainsInheritedProperty):
(WebInspector.StylePropertiesSection.prototype.editingSelectorCommitted.successCallback):
(WebInspector.StylePropertiesSection.prototype.editingSelectorCommitted):
(WebInspector.BlankStylePropertiesSection.prototype.editingSelectorCommitted.successCallback):
(WebInspector.BlankStylePropertiesSection.prototype.editingSelectorCommitted):
(WebInspector.StylePropertyTreeElement.prototype.):
(WebInspector.StylePropertyTreeElement.prototype):
* inspector/front-end/inspector.html:
* inspector/front-end/inspector.js:
(WebInspector.loaded):
2010-06-04 Simon Hausmann <simon.hausmann@nokia.com>
Reviewed by Tor Arne Vestbø.
......
/*
* Copyright (C) 2010 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
WebInspector.CSSStyleModel = function()
{
}
WebInspector.CSSStyleModel.prototype = {
getStylesAsync: function(nodeId, authOnly, userCallback)
{
InspectorBackend.getStyles(WebInspector.Callback.wrap(userCallback), nodeId, authOnly);
},
getComputedStyleAsync: function(nodeId, userCallback)
{
InspectorBackend.getComputedStyle(WebInspector.Callback.wrap(userCallback), nodeId);
},
setRuleSelector: function(ruleId, newContent, nodeId, successCallback, failureCallback)
{
function callback(newRulePayload, doesAffectSelectedNode)
{
if (!newRulePayload)
failureCallback();
else
successCallback(WebInspector.CSSStyleDeclaration.parseRule(newRulePayload), doesAffectSelectedNode);
}
InspectorBackend.setRuleSelector(WebInspector.Callback.wrap(callback), ruleId, newContent, nodeId);
},
addRule: function(nodeId, newContent, successCallback, failureCallback)
{
function callback(rule, doesAffectSelectedNode)
{
if (!rule) {
// Invalid syntax for a selector
failureCallback();
} else {
var styleRule = WebInspector.CSSStyleDeclaration.parseRule(rule);
styleRule.rule = rule;
successCallback(styleRule, doesAffectSelectedNode);
}
}
InspectorBackend.addRule(WebInspector.Callback.wrap(callback), newContent, nodeId);
},
toggleStyleEnabled: function(styleId, propertyName, disabled, userCallback)
{
function callback(newPayload)
{
if (!newPayload) {
userCallback(null);
return;
}
var newStyle = WebInspector.CSSStyleDeclaration.parseStyle(newPayload);
userCallback(newStyle);
}
InspectorBackend.toggleStyleEnabled(WebInspector.Callback.wrap(callback), styleId, propertyName, disabled);
},
setCSSText: function(styleId, cssText)
{
InspectorBackend.setStyleText(WebInspector.Callback.wrap(null), styleId, cssText);
},
applyStyleText: function(styleId, styleText, propertyName, successCallback, failureCallback)
{
function callback(success, newPayload, changedProperties)
{
if (!success)
failureCallback();
else {
var newStyle = newPayload ? WebInspector.CSSStyleDeclaration.parseStyle(newPayload) : null;
successCallback(newStyle, changedProperties);
}
}
InspectorBackend.applyStyleText(WebInspector.Callback.wrap(callback), styleId, styleText, propertyName);
}
}
......@@ -133,22 +133,22 @@ WebInspector.StylesSidebarPane.prototype = {
return;
}
function getStylesCallback(styles)
function stylesCallback(styles)
{
if (styles)
this._rebuildUpdate(node, styles);
}
function getComputedStyleCallback(computedStyle)
function computedStyleCallback(computedStyle)
{
if (computedStyle)
this._refreshUpdate(node, computedStyle, editedSection);
};
if (refresh)
InspectorBackend.getComputedStyle(WebInspector.Callback.wrap(getComputedStyleCallback.bind(this)), node.id);
WebInspector.cssModel.getComputedStyleAsync(node.id, computedStyleCallback.bind(this));
else
InspectorBackend.getStyles(WebInspector.Callback.wrap(getStylesCallback.bind(this)), node.id, !WebInspector.settings.showUserAgentStyles);
WebInspector.cssModel.getStylesAsync(node.id, !WebInspector.settings.showUserAgentStyles, stylesCallback.bind(this));
},
_refreshUpdate: function(node, computedStyle, editedSection)
......@@ -466,7 +466,7 @@ WebInspector.StylesSidebarPane.prototype = {
{
for (var i = 0; i < properties.length; ++i) {
var property = properties[i];
// Does this style contain non-overriden inherited property?
// Does this style contain non-overridden inherited property?
if (property.name in WebInspector.StylesSidebarPane.InheritedProperties)
return true;
}
......@@ -600,7 +600,7 @@ WebInspector.ComputedStyleSidebarPane = function()
showInheritedCheckbox.addEventListener(showInheritedToggleFunction.bind(this));
}
WebInspector.ComputedStyleSidebarPane.prototype.__proto__ = WebInspector.SidebarPane.prototype;
WebInspector.StylePropertiesSection = function(styleRule, subtitle, computedStyle, usedProperties, editable, isInherited, isFirstSection)
......@@ -882,14 +882,9 @@ WebInspector.StylePropertiesSection.prototype = {
return moveToNextIfNeeded.call(this);
var self = this;
function callback(newRulePayload, doesAffectSelectedNode)
{
if (!newRulePayload) {
// Invalid Syntax for a Selector
moveToNextIfNeeded.call(self);
return;
}
function successCallback(newRule, doesAffectSelectedNode)
{
if (!doesAffectSelectedNode) {
self.noAffect = true;
self.element.addStyleClass("no-affect");
......@@ -898,7 +893,6 @@ WebInspector.StylePropertiesSection.prototype = {
self.element.removeStyleClass("no-affect");
}
var newRule = WebInspector.CSSStyleDeclaration.parseRule(newRulePayload);
self.rule = newRule;
self.styleRule = { section: self, style: newRule.style, selectorText: newRule.selectorText, parentStyleSheet: newRule.parentStyleSheet, rule: newRule };
......@@ -912,7 +906,7 @@ WebInspector.StylePropertiesSection.prototype = {
moveToNextIfNeeded.call(self);
}
InspectorBackend.setRuleSelector(WebInspector.Callback.wrap(callback), this.rule.id, newContent, this.pane.node.id);
WebInspector.cssModel.setRuleSelector(this.rule.id, newContent, this.pane.node.id, successCallback, moveToNextIfNeeded.bind(this));
},
editingSelectorCancelled: function()
......@@ -939,17 +933,8 @@ WebInspector.BlankStylePropertiesSection.prototype = {
editingSelectorCommitted: function(element, newContent, oldContent, context)
{
var self = this;
function callback(rule, doesSelectorAffectSelectedNode)
function successCallback(styleRule, doesSelectorAffectSelectedNode)
{
if (!rule) {
// Invalid Syntax for a Selector
self.editingSelectorCancelled();
return;
}
var styleRule = WebInspector.CSSStyleDeclaration.parseRule(rule);
styleRule.rule = rule;
self.makeNormal(styleRule);
if (!doesSelectorAffectSelectedNode) {
......@@ -963,7 +948,7 @@ WebInspector.BlankStylePropertiesSection.prototype = {
self.addNewBlankProperty().startEditing();
}
InspectorBackend.addRule(WebInspector.Callback.wrap(callback), newContent, this.pane.node.id);
WebInspector.cssModel.addRule(this.pane.node.id, newContent, successCallback, this.editingSelectorCancelled.bind(this));
},
editingSelectorCancelled: function()
......@@ -1220,6 +1205,9 @@ WebInspector.StylePropertyTreeElement.prototype = {
this.listItemElement.removeChildren();
if (!this.treeOutline)
return;
// Append the checkbox for root elements of an editable section.
if (this.treeOutline.section && this.treeOutline.section.editable && this.parent.root)
this.listItemElement.appendChild(enabledCheckboxElement);
......@@ -1254,12 +1242,12 @@ WebInspector.StylePropertyTreeElement.prototype = {
var disabled = !event.target.checked;
var self = this;
function callback(newPayload)
function callback(newStyle)
{
if (!newPayload)
if (!newStyle)
return;
self.style = WebInspector.CSSStyleDeclaration.parseStyle(newPayload);
self.style = newStyle;
self._styleRule.style = self.style;
// Set the disabled property here, since the code above replies on it not changing
......@@ -1272,7 +1260,7 @@ WebInspector.StylePropertyTreeElement.prototype = {
self.updateAll(true);
}
InspectorBackend.toggleStyleEnabled(WebInspector.Callback.wrap(callback), this.style.id, this.name, disabled);
WebInspector.cssModel.toggleStyleEnabled(this.style.id, this.name, disabled, callback);
},
updateState: function()
......@@ -1434,7 +1422,7 @@ WebInspector.StylePropertyTreeElement.prototype = {
} else {
// Restore the original CSS text before applying user changes. This is needed to prevent
// new properties from sticking around if the user adds one, then removes it.
InspectorBackend.setStyleText(WebInspector.Callback.wrap(null), this.style.id, this.originalCSSText);
WebInspector.cssModel.setCSSText(this.style.id, this.originalCSSText);
}
this.applyStyleText(this.listItemElement.textContent);
......@@ -1454,7 +1442,7 @@ WebInspector.StylePropertyTreeElement.prototype = {
if (this._newProperty)
this.treeOutline.removeChild(this);
else if (this.originalCSSText) {
InspectorBackend.setStyleText(WebInspector.Callback.wrap(null), this.style.id, this.originalCSSText);
WebInspector.cssModel.setCSSText(this.style.id, this.originalCSSText);
if (this.treeOutline.section && this.treeOutline.section.pane)
this.treeOutline.section.pane.dispatchEventToListeners("style edited");
......@@ -1541,28 +1529,29 @@ WebInspector.StylePropertyTreeElement.prototype = {
}
var self = this;
function callback(success, newPayload, changedProperties)
function failureCallback()
{
if (!success) {
// The user typed something, but it didn't parse. Just abort and restore
// the original title for this property. If this was a new attribute and
// we couldn't parse, then just remove it.
if (self._newProperty) {
self.parent.removeChild(self);
return;
}
if (updateInterface)
self.updateTitle();
// The user typed something, but it didn't parse. Just abort and restore
// the original title for this property. If this was a new attribute and
// we couldn't parse, then just remove it.
if (self._newProperty) {
self.parent.removeChild(self);
return;
}
if (updateInterface)
self.updateTitle();
}
function successCallback(newStyle, changedProperties)
{
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 = WebInspector.CSSStyleDeclaration.parseStyle(newPayload);
self.style = newStyle;
for (var i = 0; i < changedProperties.length; ++i)
elementsPanel.addStyleChange(section.identifier, self.style, changedProperties[i]);
self._styleRule.style = self.style;
......@@ -1574,7 +1563,8 @@ WebInspector.StylePropertyTreeElement.prototype = {
if (updateInterface)
self.updateAll(true);
}
InspectorBackend.applyStyleText(WebInspector.Callback.wrap(callback), this.style.id, styleText, this.name);
WebInspector.cssModel.applyStyleText(this.style.id, styleText, this.name, successCallback, failureCallback);
}
}
......
......@@ -41,6 +41,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<script type="text/javascript" src="InspectorFrontendHostStub.js"></script>
<script type="text/javascript" src="Object.js"></script>
<script type="text/javascript" src="Settings.js"></script>
<script type="text/javascript" src="CSSStyleModel.js"></script>
<script type="text/javascript" src="Checkbox.js"></script>
<script type="text/javascript" src="ContextMenu.js"></script>
<script type="text/javascript" src="KeyboardShortcut.js"></script>
......
......@@ -466,6 +466,7 @@ WebInspector.loaded = function()
};
this.breakpointManager = new WebInspector.BreakpointManager();
this.cssModel = new WebInspector.CSSStyleModel();
this.panels = {};
this._createPanels();
......
Supports Markdown
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