| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2009 Joseph Pecoraro | 3 * Copyright (C) 2009 Joseph Pecoraro |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 { | 325 { |
| 326 var node = this.node(); | 326 var node = this.node(); |
| 327 if (!node) | 327 if (!node) |
| 328 return Promise.resolve(/** @type {?{matched: !WebInspector.SectionCa
scade, pseudo: !Map.<number, !WebInspector.SectionCascade>}} */(null)); | 328 return Promise.resolve(/** @type {?{matched: !WebInspector.SectionCa
scade, pseudo: !Map.<number, !WebInspector.SectionCascade>}} */(null)); |
| 329 if (!this._matchedCascadePromise) | 329 if (!this._matchedCascadePromise) |
| 330 this._matchedCascadePromise = this._matchedStylesForNode(node).then(
buildMatchedCascades.bind(this, node)); | 330 this._matchedCascadePromise = this._matchedStylesForNode(node).then(
buildMatchedCascades.bind(this, node)); |
| 331 return this._matchedCascadePromise; | 331 return this._matchedCascadePromise; |
| 332 | 332 |
| 333 /** | 333 /** |
| 334 * @param {!WebInspector.DOMNode} node | 334 * @param {!WebInspector.DOMNode} node |
| 335 * @param {!WebInspector.StylesSidebarPane.MatchedRulesPayload} payload | 335 * @param {?WebInspector.CSSStyleModel.MatchedStyleResult} matchedStyles |
| 336 * @return {?{matched: !WebInspector.SectionCascade, pseudo: !Map.<numbe
r, !WebInspector.SectionCascade>}} | 336 * @return {?{matched: !WebInspector.SectionCascade, pseudo: !Map.<numbe
r, !WebInspector.SectionCascade>}} |
| 337 * @this {WebInspector.StylesSidebarPane} | 337 * @this {WebInspector.StylesSidebarPane} |
| 338 */ | 338 */ |
| 339 function buildMatchedCascades(node, payload) | 339 function buildMatchedCascades(node, matchedStyles) |
| 340 { | 340 { |
| 341 if (node !== this.node() || !payload.fulfilled()) | 341 if (!matchedStyles || node !== this.node()) |
| 342 return null; |
| 343 if (!matchedStyles.matchedCSSRules || !matchedStyles.pseudoElements
|| !matchedStyles.inherited) |
| 342 return null; | 344 return null; |
| 343 | 345 |
| 344 return { | 346 return { |
| 345 matched: this._buildMatchedRulesSectionCascade(node, payload), | 347 matched: this._buildMatchedRulesSectionCascade(node, matchedStyl
es), |
| 346 pseudo: this._buildPseudoCascades(node, payload) | 348 pseudo: this._buildPseudoCascades(node, matchedStyles) |
| 347 }; | 349 }; |
| 348 } | 350 } |
| 349 }, | 351 }, |
| 350 | 352 |
| 351 /** | 353 /** |
| 352 * @param {!WebInspector.DOMNode} node | 354 * @param {!WebInspector.DOMNode} node |
| 353 * @return {!Promise.<!WebInspector.StylesSidebarPane.MatchedRulesPayload>} | 355 * @return {!Promise.<?WebInspector.CSSStyleModel.MatchedStyleResult>} |
| 354 */ | 356 */ |
| 355 _matchedStylesForNode: function(node) | 357 _matchedStylesForNode: function(node) |
| 356 { | 358 { |
| 357 var payload = new WebInspector.StylesSidebarPane.MatchedRulesPayload(); | |
| 358 var cssModel = this.cssModel(); | 359 var cssModel = this.cssModel(); |
| 359 if (!cssModel) | 360 if (!cssModel) |
| 360 return Promise.resolve(payload); | 361 return Promise.resolve(/** @type {?WebInspector.CSSStyleModel.Matche
dStyleResult} */(null)); |
| 361 | 362 return cssModel.matchedStylesPromise(node.id) |
| 362 var promises = [ | |
| 363 cssModel.inlineStylesPromise(node.id).then(inlineCallback), | |
| 364 cssModel.matchedStylesPromise(node.id).then(matchedCallback) | |
| 365 ]; | |
| 366 return Promise.all(promises).then(returnPayload); | |
| 367 | |
| 368 /** | |
| 369 * @param {?WebInspector.CSSStyleModel.InlineStyleResult} inlineStyleRes
ult | |
| 370 */ | |
| 371 function inlineCallback(inlineStyleResult) | |
| 372 { | |
| 373 if (!inlineStyleResult) | |
| 374 return; | |
| 375 payload.inlineStyle = inlineStyleResult.inlineStyle; | |
| 376 payload.attributesStyle = inlineStyleResult.attributesStyle; | |
| 377 } | |
| 378 | |
| 379 /** | |
| 380 * @param {?WebInspector.CSSStyleModel.MatchedStyleResult} matchedResult | |
| 381 */ | |
| 382 function matchedCallback(matchedResult) | |
| 383 { | |
| 384 if (matchedResult) { | |
| 385 payload.matchedCSSRules = matchedResult.matchedCSSRules; | |
| 386 payload.pseudoElements = matchedResult.pseudoElements; | |
| 387 payload.inherited = matchedResult.inherited; | |
| 388 } | |
| 389 } | |
| 390 | |
| 391 /** | |
| 392 * @return {!WebInspector.StylesSidebarPane.MatchedRulesPayload} | |
| 393 */ | |
| 394 function returnPayload() | |
| 395 { | |
| 396 return payload; | |
| 397 } | |
| 398 }, | 363 }, |
| 399 | 364 |
| 400 /** | 365 /** |
| 401 * @param {boolean} editing | 366 * @param {boolean} editing |
| 402 */ | 367 */ |
| 403 setEditingStyle: function(editing) | 368 setEditingStyle: function(editing) |
| 404 { | 369 { |
| 405 if (this._isEditingStyle === editing) | 370 if (this._isEditingStyle === editing) |
| 406 return; | 371 return; |
| 407 this._isEditingStyle = editing; | 372 this._isEditingStyle = editing; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 } | 443 } |
| 479 | 444 |
| 480 if (this._filterRegex) | 445 if (this._filterRegex) |
| 481 this._updateFilter(); | 446 this._updateFilter(); |
| 482 | 447 |
| 483 this._nodeStylesUpdatedForTest(node, true); | 448 this._nodeStylesUpdatedForTest(node, true); |
| 484 }, | 449 }, |
| 485 | 450 |
| 486 /** | 451 /** |
| 487 * @param {!WebInspector.DOMNode} node | 452 * @param {!WebInspector.DOMNode} node |
| 488 * @param {!WebInspector.StylesSidebarPane.MatchedRulesPayload} styles | 453 * @param {!WebInspector.CSSStyleModel.MatchedStyleResult} styles |
| 489 * @return {!Map<number, !WebInspector.SectionCascade>} | 454 * @return {!Map<number, !WebInspector.SectionCascade>} |
| 490 */ | 455 */ |
| 491 _buildPseudoCascades: function(node, styles) | 456 _buildPseudoCascades: function(node, styles) |
| 492 { | 457 { |
| 493 var pseudoCascades = new Map(); | 458 var pseudoCascades = new Map(); |
| 494 for (var i = 0; i < styles.pseudoElements.length; ++i) { | 459 for (var i = 0; i < styles.pseudoElements.length; ++i) { |
| 495 var pseudoElementCSSRules = styles.pseudoElements[i]; | 460 var pseudoElementCSSRules = styles.pseudoElements[i]; |
| 496 var pseudoId = pseudoElementCSSRules.pseudoId; | 461 var pseudoId = pseudoElementCSSRules.pseudoId; |
| 497 | 462 |
| 498 // Add rules in reverse order to match the cascade order. | 463 // Add rules in reverse order to match the cascade order. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 510 * @param {!WebInspector.DOMNode} node | 475 * @param {!WebInspector.DOMNode} node |
| 511 * @param {boolean} rebuild | 476 * @param {boolean} rebuild |
| 512 */ | 477 */ |
| 513 _nodeStylesUpdatedForTest: function(node, rebuild) | 478 _nodeStylesUpdatedForTest: function(node, rebuild) |
| 514 { | 479 { |
| 515 // For sniffing in tests. | 480 // For sniffing in tests. |
| 516 }, | 481 }, |
| 517 | 482 |
| 518 /** | 483 /** |
| 519 * @param {!WebInspector.DOMNode} node | 484 * @param {!WebInspector.DOMNode} node |
| 520 * @param {!WebInspector.StylesSidebarPane.MatchedRulesPayload} styles | 485 * @param {!WebInspector.CSSStyleModel.MatchedStyleResult} styles |
| 521 * @return {!WebInspector.SectionCascade} | 486 * @return {!WebInspector.SectionCascade} |
| 522 */ | 487 */ |
| 523 _buildMatchedRulesSectionCascade: function(node, styles) | 488 _buildMatchedRulesSectionCascade: function(node, styles) |
| 524 { | 489 { |
| 525 var cascade = new WebInspector.SectionCascade(); | 490 var cascade = new WebInspector.SectionCascade(); |
| 526 | 491 |
| 527 function addAttributesStyle() | 492 function addAttributesStyle() |
| 528 { | 493 { |
| 529 if (!styles.attributesStyle) | 494 if (!styles.attributesStyle) |
| 530 return; | 495 return; |
| (...skipping 2546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3077 var hasResource = hrefUrl && !!WebInspector.resourceForURL(hrefUrl); | 3042 var hasResource = hrefUrl && !!WebInspector.resourceForURL(hrefUrl); |
| 3078 // FIXME: WebInspector.linkifyURLAsNode() should really use baseURI. | 3043 // FIXME: WebInspector.linkifyURLAsNode() should really use baseURI. |
| 3079 container.appendChild(WebInspector.linkifyURLAsNode(hrefUrl || url, url,
undefined, !hasResource)); | 3044 container.appendChild(WebInspector.linkifyURLAsNode(hrefUrl || url, url,
undefined, !hasResource)); |
| 3080 container.createTextChild(")"); | 3045 container.createTextChild(")"); |
| 3081 return container; | 3046 return container; |
| 3082 } | 3047 } |
| 3083 } | 3048 } |
| 3084 | 3049 |
| 3085 /** | 3050 /** |
| 3086 * @constructor | 3051 * @constructor |
| 3087 */ | |
| 3088 WebInspector.StylesSidebarPane.MatchedRulesPayload = function() | |
| 3089 { | |
| 3090 /** @type {?WebInspector.CSSStyleDeclaration} */ | |
| 3091 this.inlineStyle = null; | |
| 3092 /** @type {?WebInspector.CSSStyleDeclaration} */ | |
| 3093 this.attributesStyle = null; | |
| 3094 /** @type {?Array.<!WebInspector.CSSRule>} */ | |
| 3095 this.matchedCSSRules = null; | |
| 3096 /** @type {?Array.<!WebInspector.CSSStyleModel.PseudoElementMatches>} */ | |
| 3097 this.pseudoElements = null; | |
| 3098 /** @type {?Array.<!WebInspector.CSSStyleModel.InheritedMatches>} */ | |
| 3099 this.inherited = null; | |
| 3100 } | |
| 3101 | |
| 3102 WebInspector.StylesSidebarPane.MatchedRulesPayload.prototype = { | |
| 3103 /** | |
| 3104 * @return {boolean} | |
| 3105 */ | |
| 3106 fulfilled: function() | |
| 3107 { | |
| 3108 return !!(this.matchedCSSRules && this.pseudoElements && this.inherited)
; | |
| 3109 } | |
| 3110 } | |
| 3111 | |
| 3112 /** | |
| 3113 * @constructor | |
| 3114 * @extends {WebInspector.Widget} | 3052 * @extends {WebInspector.Widget} |
| 3115 * @param {!WebInspector.ToolbarItem} toolbarItem | 3053 * @param {!WebInspector.ToolbarItem} toolbarItem |
| 3116 */ | 3054 */ |
| 3117 WebInspector.StylesSidebarPane.BaseToolbarPaneWidget = function(toolbarItem) | 3055 WebInspector.StylesSidebarPane.BaseToolbarPaneWidget = function(toolbarItem) |
| 3118 { | 3056 { |
| 3119 WebInspector.Widget.call(this); | 3057 WebInspector.Widget.call(this); |
| 3120 this._toolbarItem = toolbarItem; | 3058 this._toolbarItem = toolbarItem; |
| 3121 WebInspector.context.addFlavorChangeListener(WebInspector.DOMNode, this._nod
eChanged, this); | 3059 WebInspector.context.addFlavorChangeListener(WebInspector.DOMNode, this._nod
eChanged, this); |
| 3122 } | 3060 } |
| 3123 | 3061 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3183 | 3121 |
| 3184 /** | 3122 /** |
| 3185 * @override | 3123 * @override |
| 3186 * @return {?WebInspector.ToolbarItem} | 3124 * @return {?WebInspector.ToolbarItem} |
| 3187 */ | 3125 */ |
| 3188 item: function() | 3126 item: function() |
| 3189 { | 3127 { |
| 3190 return this._button; | 3128 return this._button; |
| 3191 } | 3129 } |
| 3192 } | 3130 } |
| OLD | NEW |