aboutsummaryrefslogtreecommitdiff
path: root/js/controllers
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-06-21 16:53:46 -0700
committerJose Antonio Marquez2012-06-21 16:53:46 -0700
commit9a568f56b2684e268975231544a80db78497db02 (patch)
tree5e76e47dbec5e5581c9d96beb312c6bbeb910082 /js/controllers
parent1e9af08f42e4ba18fc8c5a8501d8cbecec0f4fe8 (diff)
parent2af33f19de48bb8fe269c51ceddd1bc1f591651f (diff)
downloadninja-9a568f56b2684e268975231544a80db78497db02.tar.gz
Merge branch 'refs/heads/Ninja-Internal' into Color
Diffstat (limited to 'js/controllers')
-rw-r--r--js/controllers/clipboard-controller.js120
-rwxr-xr-xjs/controllers/styles-controller.js66
2 files changed, 173 insertions, 13 deletions
diff --git a/js/controllers/clipboard-controller.js b/js/controllers/clipboard-controller.js
new file mode 100644
index 00000000..259d916e
--- /dev/null
+++ b/js/controllers/clipboard-controller.js
@@ -0,0 +1,120 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */
6
7////////////////////////////////////////////////////////////////////////
8//
9var Montage = require("montage/core/core").Montage,
10 Component = require("montage/ui/component").Component,
11 ElementsClipboardAgent = require("js/clipboard/internal-ops/elements-clipboard-agent").ElementsClipboardAgent,
12 ExternalAppsClipboardAgent= require("js/clipboard/external-apps-clipboard-agent").ExternalAppsClipboardAgent;
13
14var ClipboardController = exports.ClipboardController = Montage.create(Component, {
15
16 deserializedFromTemplate: {
17 value: function() {
18 document.body.addEventListener("copy", this, false);
19 document.body.addEventListener("cut", this, false);
20 document.body.addEventListener("paste", this, false);
21
22 //ninja menu events
23 this.eventManager.addEventListener("executeCut", this, false);
24 this.eventManager.addEventListener("executeCopy", this, false);
25 this.eventManager.addEventListener("executePaste", this, false);
26
27 }
28 },
29
30 clipboardContext:{
31 value : "stage" /* cleanup: formulate better context representation */
32 },
33
34 operationsAgent:{//appropriate agent instant required for execution of cut/copy/paste
35 value: null
36 },
37
38 handleExecuteCopy:{
39 value: function(){document.execCommand('copy',false,null);}
40 },
41
42 handleExecuteCut:{
43 value: function(){document.execCommand('cut',false,null);}
44 },
45
46 handleExecutePaste:{
47 value: function(){document.execCommand('paste',false,null);}
48 },
49
50 handleCopy:{
51 value:function(clipboardEvent){
52 if(!this.application.ninja.currentDocument
53 || (this.application.ninja.currentDocument && this.application.ninja.currentDocument.currentView === "code")){
54
55 return;
56 }//for design view only
57
58 // Don't do anything if an input or other control is focused
59 if(document.activeElement.nodeName !== "BODY") {
60 return;
61 }
62
63 if(this.clipboardContext === "stage"){
64 ElementsClipboardAgent.copy(clipboardEvent);
65 }
66
67 clipboardEvent.preventDefault();
68 }
69 },
70
71 handleCut:{
72 value:function(clipboardEvent){
73 if(this.application.ninja.currentDocument.currentView === "code") return;
74
75 // Don't do anything if an input or other control is focused
76 if(document.activeElement.nodeName !== "BODY") {
77 return;
78 }
79
80 if(this.clipboardContext === "stage"){
81 ElementsClipboardAgent.cut(clipboardEvent);
82 }
83
84 clipboardEvent.preventDefault();
85 }
86 },
87
88 handlePaste:{
89 value:function(clipboardEvent){
90 var clipboardData = clipboardEvent.clipboardData,
91 ninjaData = clipboardData.getData("ninja");
92
93 if(!this.application.ninja.currentDocument
94 || (this.application.ninja.currentDocument && this.application.ninja.currentDocument.currentView === "code")){
95
96 return;
97 }//for design view only
98
99 // Don't do anything if an input or other control is focused
100 if(document.activeElement.nodeName !== "BODY") {
101 return;
102 }
103
104 //TODO: return if stage is not focussed
105
106 if(this.clipboardContext === "stage"){
107 if(ninjaData){
108 ElementsClipboardAgent.pasteInternal();
109 }
110 else{
111 ExternalAppsClipboardAgent.paste(clipboardEvent);
112 }
113 }
114
115 clipboardEvent.preventDefault();
116 }
117 }
118
119
120}); \ No newline at end of file
diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js
index a25a05df..1c1e75ed 100755
--- a/js/controllers/styles-controller.js
+++ b/js/controllers/styles-controller.js
@@ -426,7 +426,8 @@ var stylesController = exports.StylesController = Montage.create(Component, {
426 ///// rule to the calling method 426 ///// rule to the calling method
427 return { 427 return {
428 useImportant : useImportant, 428 useImportant : useImportant,
429 ruleToOverride : dominantRule 429 ruleToOverride : dominantRule,
430 singleTargetBackup : this._getFirstSingleTargetRule(matchedRules.slice(1), doc)
430 }; 431 };
431 } 432 }
432 433
@@ -674,6 +675,8 @@ var stylesController = exports.StylesController = Montage.create(Component, {
674 if(sheetAIndex === sheetBIndex) { 675 if(sheetAIndex === sheetBIndex) {
675 ruleAIndex = this.getRuleIndex(ruleA); ruleBIndex = this.getRuleIndex(ruleB); 676 ruleAIndex = this.getRuleIndex(ruleA); ruleBIndex = this.getRuleIndex(ruleB);
676 return ruleAIndex < ruleBIndex ? 1 : (ruleAIndex > ruleBIndex) ? -1 : 0; 677 return ruleAIndex < ruleBIndex ? 1 : (ruleAIndex > ruleBIndex) ? -1 : 0;
678 } else {
679 return sheetAIndex < sheetBIndex ? 1 : (sheetAIndex > sheetBIndex) ? -1 : 0;
677 } 680 }
678 } 681 }
679 682
@@ -737,6 +740,40 @@ var stylesController = exports.StylesController = Montage.create(Component, {
737 console.error('StylesController::_getMostSpecificSelectorForElement - no matching selectors in specificity array.'); 740 console.error('StylesController::_getMostSpecificSelectorForElement - no matching selectors in specificity array.');
738 } 741 }
739 }, 742 },
743
744
745 ///// Has Greater Specificity
746 ///// A method that returns true if the first argument has higher
747 ///// specificity than the second argument
748 ///// An element has to be supplied to determine which selector
749 ///// to evaluate within grouped selectors
750 hasGreaterSpecificity : {
751 value: function(rule1, rule2, element) {
752 var a = this._getMostSpecificSelectorForElement(element, rule1[this.CONST.SPECIFICITY_KEY]),
753 b = this._getMostSpecificSelectorForElement(element, rule2[this.CONST.SPECIFICITY_KEY]),
754 win = element.ownerDocument.defaultView,
755 order;
756
757 order = this.compareSpecificity(a.specificity, b.specificity);
758
759 if(order === 0) {
760 /// Tie. Sway one way or other based on stylesheet/rule order
761 sheetAIndex = nj.toArray(win.document.styleSheets).indexOf(rule1.parentStyleSheet);
762 sheetBIndex = nj.toArray(win.document.styleSheets).indexOf(rule2.parentStyleSheet);
763 /// If tied again (same sheet), determine which is further down in the sheet
764 if(sheetAIndex === sheetBIndex) {
765 ruleAIndex = this.getRuleIndex(rule1); ruleBIndex = this.getRuleIndex(rule2);
766 return ruleAIndex < ruleBIndex ? 1 : (ruleAIndex > ruleBIndex) ? -1 : 0;
767 } else {
768 return sheetAIndex < sheetBIndex ? 1 : (sheetAIndex > sheetBIndex) ? -1 : 0;
769 }
770 }
771
772 return (order < 0);
773
774 }
775 },
776
740 777
741 ///// Get First Single Target Rule 778 ///// Get First Single Target Rule
742 ///// Loops through the array of rules sequentially, returning the first 779 ///// Loops through the array of rules sequentially, returning the first
@@ -1035,6 +1072,10 @@ var stylesController = exports.StylesController = Montage.create(Component, {
1035 1072
1036 } 1073 }
1037 1074
1075 if(cacheMatchesMany) {
1076 dominantRule = this.getDominantRuleForElement(element, property, true, isStageElement);
1077 }
1078
1038 ///// Did we find a dominant rule? 1079 ///// Did we find a dominant rule?
1039 if(!dominantRule) { 1080 if(!dominantRule) {
1040 ///// No. This means there was no rule with this property, and no 1081 ///// No. This means there was no rule with this property, and no
@@ -1047,18 +1088,17 @@ var stylesController = exports.StylesController = Montage.create(Component, {
1047 1088
1048 } else if(dominantRule.ruleToOverride) { 1089 } else if(dominantRule.ruleToOverride) {
1049 ///// Do we have to override a rule? 1090 ///// Do we have to override a rule?
1050 ////// Yes. The override object has the rule we need to override 1091 ///// Well, let's first see if a higher-specificity, single-target
1051 override = this.createOverrideRule(dominantRule.ruleToOverride, element); 1092 ///// rule exists
1052 useImportant = dominantRule.useImportant; 1093 if(dominantRule.singleTargetBackup && this.hasGreaterSpecificity(dominantRule.singleTargetBackup, dominantRule.ruleToOverride, element)) {
1053 dominantRule = override.rule; 1094 dominantRule = dominantRule.singleTargetBackup;
1054 this.addClass(element, override.className); 1095 } else {
1055 } else if(cacheMatchesMany) { 1096 ///// No. The override object has the rule we need to override
1056 ///// Only happens when the cached rule applies to multiple 1097 override = this.createOverrideRule(dominantRule.ruleToOverride, element);
1057 ///// elements - we must create override 1098