aboutsummaryrefslogtreecommitdiff
path: root/js/controllers/styles-controller.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/controllers/styles-controller.js')
-rwxr-xr-xjs/controllers/styles-controller.js56
1 files changed, 48 insertions, 8 deletions
diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js
index e25ed20c..1030acb4 100755
--- a/js/controllers/styles-controller.js
+++ b/js/controllers/styles-controller.js
@@ -1,7 +1,31 @@
1/* <copyright> 1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/> 2Copyright (c) 2012, Motorola Mobility, Inc
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> 3All Rights Reserved.
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. 4BSD License.
5
6Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met:
8
9 - Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11 - Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
14 - Neither the name of Motorola Mobility nor the names of its contributors
15 may be used to endorse or promote products derived from this software
16 without specific prior written permission.
17
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28POSSIBILITY OF SUCH DAMAGE.
5</copyright> */ 29</copyright> */
6 30
7var Montage = require("montage/core/core").Montage, 31var Montage = require("montage/core/core").Montage,
@@ -632,7 +656,7 @@ var stylesController = exports.StylesController = Montage.create(Component, {
632 if(!rule) { 656 if(!rule) {
633 ///// This should never be hit if providing cssText from existing rule (like those 657 ///// This should never be hit if providing cssText from existing rule (like those
634 ///// returned from getMatchedCSSRules() 658 ///// returned from getMatchedCSSRules()
635 console.warn('StylesController::_getRuleWithCSSText - No rule found with given cssText.'); 659 //console.warn('StylesController::_getRuleWithCSSText - No rule found with given cssText.');
636 } 660 }
637 661
638 return rule; 662 return rule;
@@ -646,16 +670,31 @@ var stylesController = exports.StylesController = Montage.create(Component, {
646 getMatchingRules : { //TODO: Remove omitPseudos from here and usages 670 getMatchingRules : { //TODO: Remove omitPseudos from here and usages
647 value: function(element, omitPseudos, useStageStyleSheet) { 671 value: function(element, omitPseudos, useStageStyleSheet) {
648 var rules, 672 var rules,
673 matchedRules,
649 mappedRules, 674 mappedRules,
650 doc = element.ownerDocument, 675 doc = element.ownerDocument,
651 win = doc.defaultView; 676 win = doc.defaultView;
652 677
678 if(!element.parentNode) {
679 //console.warn('StylesController::getMatchingRules - Un-attached element queried');
680 return [];
681 }
682
653 try { 683 try {
654 mappedRules = nj.toArray(win.getMatchedCSSRules(element)).map(function(rule) { 684 matchedRules = win.getMatchedCSSRules(element);
685
686 if(!matchedRules) {
687 //console.warn('StylesController::getMatchingRules - matched rules are null');
688 return [];
689 }
690
691 mappedRules = nj.toArray(matchedRules).map(function(rule) {
655 return this._getRuleWithCSSText(rule.cssText, doc); 692 return this._getRuleWithCSSText(rule.cssText, doc);
656 }, this); 693 }, this);
657 694
658 rules = mappedRules.filter(function(rule) { 695 rules = mappedRules.filter(function(rule) {
696 if(!rule) { return false; }
697
659 //// useStageStyleSheet flag indicates whether to only return rules from the stylesheet, 698 //// useStageStyleSheet flag indicates whether to only return rules from the stylesheet,
660 //// or only use rules for other stylesheets 699 //// or only use rules for other stylesheets
661 700
@@ -676,7 +715,8 @@ var stylesController = exports.StylesController = Montage.create(Component, {
676 }, this); 715 }, this);
677 716
678 } catch(ERROR) { 717 } catch(ERROR) {
679 console.warn('StylesController::getMatchingRules - Un-attached element queried.'); 718 //console.warn('StylesController::getMatchingRules - getMatchedCSSRules Exception.');
719 return [];
680 } 720 }
681 ///// Function for sorting by specificity values 721 ///// Function for sorting by specificity values
682 function sorter(ruleA, ruleB) { 722 function sorter(ruleA, ruleB) {
@@ -1440,11 +1480,11 @@ var stylesController = exports.StylesController = Montage.create(Component, {
1440 1480
1441 ///// Dispatch modified event 1481 ///// Dispatch modified event
1442 NJevent('styleSheetModified', eventData); 1482 NJevent('styleSheetModified', eventData);
1483 this.currentDocument.model.needsSave = true;
1443 1484
1444 ///// If the sheet doesn't already exist in the list of modified 1485 ///// If the sheet doesn't already exist in the list of modified
1445 ///// sheets, dispatch dirty event and add the sheet to the list 1486 ///// sheets, dispatch dirty event and add the sheet to the list
1446 if(sheetSearch.length === 0) { 1487 if(sheetSearch.length === 0) {
1447 this.currentDocument.model.needsSave = true;
1448 this.dirtyStyleSheets.push({ 1488 this.dirtyStyleSheets.push({
1449 document : sheet.ownerNode.ownerDocument, 1489 document : sheet.ownerNode.ownerDocument,
1450 stylesheet : sheet 1490 stylesheet : sheet
@@ -1794,4 +1834,4 @@ var stylesController = exports.StylesController = Montage.create(Component, {
1794 } 1834 }
1795 } 1835 }
1796 1836
1797}); \ No newline at end of file 1837});