Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Side by Side Diff: chrome/browser/resources/print_preview/margins_ui.js

Issue 8357009: Print Preview Cleanup: Creating enum with all custom events used. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Renaming, nts Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 cr.define('print_preview', function() { 5 cr.define('print_preview', function() {
6 'strict'; 6 'strict';
7 7
8 function MarginsUI() { 8 function MarginsUI() {
9 var marginsUI = document.createElement('div'); 9 var marginsUI = document.createElement('div');
10 marginsUI.__proto__ = MarginsUI.prototype; 10 marginsUI.__proto__ = MarginsUI.prototype;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 MarginsUI.convert = function(point) { 51 MarginsUI.convert = function(point) {
52 var mainview = $('mainview'); 52 var mainview = $('mainview');
53 return { x: point.x - mainview.offsetLeft, 53 return { x: point.x - mainview.offsetLeft,
54 y: point.y - mainview.offsetTop }; 54 y: point.y - mainview.offsetTop };
55 } 55 }
56 56
57 MarginsUI.prototype = { 57 MarginsUI.prototype = {
58 __proto__: HTMLDivElement.prototype, 58 __proto__: HTMLDivElement.prototype,
59 59
60 /** 60 /**
61 * Adds an observer for |MarginsMayHaveChanged| event. 61 * Adds an observer for |customEvents.MARGINS_MAY_HAVE_CHANGED| event.
62 * @param {function} func A callback function to be called when 62 * @param {function} func A callback function to be called when
63 * |MarginsMayHaveChanged| event occurs. 63 * |customEvents.MARGINS_MAY_HAVE_CHANGED| event occurs.
64 */ 64 */
65 addObserver: function(func) { 65 addObserver: function(func) {
66 var uiPairs = this.pairsAsList; 66 var uiPairs = this.pairsAsList;
67 for (var i = 0; i < uiPairs.length; i++) 67 for (var i = 0; i < uiPairs.length; i++) {
68 uiPairs[i].box_.addEventListener('MarginsMayHaveChanged', func); 68 uiPairs[i].box_.addEventListener(
69 customEvents.MARGINS_MAY_HAVE_CHANGED, func);
70 }
69 }, 71 },
70 72
71 /** 73 /**
72 * @return {array} An array including all |MarginUIPair| objects. 74 * @return {array} An array including all |MarginUIPair| objects.
73 */ 75 */
74 get pairsAsList() { 76 get pairsAsList() {
75 return [this.topPair_, this.leftPair_, this.rightPair_, this.bottomPair_]; 77 return [this.topPair_, this.leftPair_, this.rightPair_, this.bottomPair_];
76 }, 78 },
77 79
78 /** 80 /**
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 this.style.clip = "rect(0, " + right + "px, " + bottom + "px, 0)"; 132 this.style.clip = "rect(0, " + right + "px, " + bottom + "px, 0)";
131 }, 133 },
132 134
133 /** 135 /**
134 * Adds event listeners for various events. 136 * Adds event listeners for various events.
135 * @private 137 * @private
136 */ 138 */
137 addEventListeners_: function() { 139 addEventListeners_: function() {
138 var uiPairs = this.pairsAsList; 140 var uiPairs = this.pairsAsList;
139 for (var i = 0; i < uiPairs.length; i++) { 141 for (var i = 0; i < uiPairs.length; i++) {
140 uiPairs[i].addEventListener('MarginsLineMouseDown', 142 uiPairs[i].addEventListener(customEvents.MARGIN_LINE_MOUSE_DOWN,
141 this.onMarginLineMouseDown.bind(this)); 143 this.onMarginLineMouseDown.bind(this));
142 } 144 }
143 // After snapping to min/max the MarginUIPair might not receive the 145 // After snapping to min/max the MarginUIPair might not receive the
144 // mouseup event since it is not under the mouse pointer, so it is handled 146 // mouseup event since it is not under the mouse pointer, so it is handled
145 // here. 147 // here.
146 window.document.addEventListener('mouseup', 148 window.document.addEventListener('mouseup',
147 this.onMarginLineMouseUp.bind(this)); 149 this.onMarginLineMouseUp.bind(this));
148 }, 150 },
149 151
150 /** 152 /**
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 uiPair.classList.add('dragging'); 186 uiPair.classList.add('dragging');
185 }, 187 },
186 188
187 /** 189 /**
188 * Executes when a mousemove event occurs. 190 * Executes when a mousemove event occurs.
189 * @param {MouseEvent} e The event that triggered this listener. 191 * @param {MouseEvent} e The event that triggered this listener.
190 */ 192 */
191 onMouseMove_: function(e) { 193 onMouseMove_: function(e) {
192 var point = MarginsUI.convert({ x: e.x, y: e.y }); 194 var point = MarginsUI.convert({ x: e.x, y: e.y });
193 195
194 var dragEvent = new cr.Event('DragEvent'); 196 var dragEvent = new cr.Event(customEvents.MARGIN_LINE_DRAG);
195 dragEvent.dragDelta = 197 dragEvent.dragDelta =
196 this.lastClickedMarginsUIPair.getDragDisplacementFrom(point); 198 this.lastClickedMarginsUIPair.getDragDisplacementFrom(point);
197 dragEvent.destinationPoint = point; 199 dragEvent.destinationPoint = point;
198 this.dispatchEvent(dragEvent); 200 this.dispatchEvent(dragEvent);
199 }, 201 },
200 }; 202 };
201 203
202 return { 204 return {
203 MarginsUI: MarginsUI 205 MarginsUI: MarginsUI
204 }; 206 };
205 }); 207 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/print_preview/margin_textbox.js ('k') | chrome/browser/resources/print_preview/margins_ui_pair.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698