diff options
Diffstat (limited to 'js/controllers')
-rw-r--r-- | js/controllers/clipboard-controller.js | 120 | ||||
-rwxr-xr-x | js/controllers/elements/body-controller.js | 20 | ||||
-rwxr-xr-x | js/controllers/styles-controller.js | 66 |
3 files changed, 191 insertions, 15 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> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No 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 | // | ||
9 | var 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 | |||
14 | var 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/elements/body-controller.js b/js/controllers/elements/body-controller.js index 0ca6c417..604b22d0 100755 --- a/js/controllers/elements/body-controller.js +++ b/js/controllers/elements/body-controller.js | |||
@@ -19,6 +19,14 @@ exports.BodyController = Montage.create(ElementController, { | |||
19 | el.elementModel.props3D.matrix3d = mat; | 19 | el.elementModel.props3D.matrix3d = mat; |
20 | el.elementModel.props3D.perspectiveDist = dist; | 20 | el.elementModel.props3D.perspectiveDist = dist; |
21 | 21 | ||
22 | if(this.application.ninja.currentDocument.model.views.design._template) { | ||
23 | if(!MathUtils.isIdentityMatrix(mat)) { | ||
24 | el.parentNode.style.backgroundColor = "transparent"; | ||
25 | } else { | ||
26 | el.parentNode.style.removeProperty("background-color"); | ||
27 | } | ||
28 | } | ||
29 | |||
22 | this.application.ninja.stage.updatedStage = true; | 30 | this.application.ninja.stage.updatedStage = true; |
23 | 31 | ||
24 | if(update3DModel) { | 32 | if(update3DModel) { |
@@ -32,7 +40,11 @@ exports.BodyController = Montage.create(ElementController, { | |||
32 | switch(p) { | 40 | switch(p) { |
33 | case "background" : | 41 | case "background" : |
34 | case "background-color": | 42 | case "background-color": |
35 | return this.application.ninja.colorController.getColorObjFromCss(this.application.ninja.stylesController.getElementStyle(el, "background-color")); | 43 | if(this.application.ninja.currentDocument.model.views.design._template) { |
44 | return this.application.ninja.colorController.getColorObjFromCss(this.application.ninja.stylesController.getElementStyle(el.parentNode, "background-color")); | ||
45 | } else { | ||
46 | return this.application.ninja.colorController.getColorObjFromCss(this.application.ninja.stylesController.getElementStyle(el, "background-color")); | ||
47 | } | ||
36 | case "border": | 48 | case "border": |
37 | return 0; | 49 | return 0; |
38 | case "height": | 50 | case "height": |
@@ -51,7 +63,11 @@ exports.BodyController = Montage.create(ElementController, { | |||
51 | switch(p) { | 63 | switch(p) { |
52 | case "background": | 64 | case "background": |
53 | case "background-color": | 65 | case "background-color": |
54 | this.application.ninja.stylesController.setElementStyle(el, "background-color", value); | 66 | if(this.application.ninja.currentDocument.model.views.design._template) { |
67 | this.application.ninja.stylesController.setElementStyle(el.parentNode, "background-color", value); | ||
68 | } else { | ||
69 | this.application.ninja.stylesController.setElementStyle(el, "background-color", value); | ||
70 | } | ||
55 | break; | 71 | break; |
56 | case "overflow": | 72 | case "overflow": |
57 | case "width": | 73 | case "width": |
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); | ||