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

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: Rebasing Created 9 years, 2 months 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 this.style.clip = "rect(0, " + right + "px, " + bottom + "px, 0)"; 128 this.style.clip = "rect(0, " + right + "px, " + bottom + "px, 0)";
127 }, 129 },
128 130
129 /** 131 /**
130 * Adds event listeners for various events. 132 * Adds event listeners for various events.
131 * @private 133 * @private
132 */ 134 */
133 addEventListeners_: function() { 135 addEventListeners_: function() {
134 var uiPairs = this.pairsAsList; 136 var uiPairs = this.pairsAsList;
135 for (var i = 0; i < uiPairs.length; i++) { 137 for (var i = 0; i < uiPairs.length; i++) {
136 uiPairs[i].addEventListener('MarginsLineMouseDown', 138 uiPairs[i].addEventListener(customEvents.MARGINS_LINE_MOUSE_DOWN,
137 this.onMarginLineMouseDown.bind(this)); 139 this.onMarginLineMouseDown.bind(this));
138 } 140 }
139 // After snapping to min/max the MarginUIPair might not receive the 141 // After snapping to min/max the MarginUIPair might not receive the
140 // mouseup event since it is not under the mouse pointer, so it is handled 142 // mouseup event since it is not under the mouse pointer, so it is handled
141 // here. 143 // here.
142 window.document.addEventListener('mouseup', 144 window.document.addEventListener('mouseup',
143 this.onMarginLineMouseUp.bind(this)); 145 this.onMarginLineMouseUp.bind(this));
144 }, 146 },
145 147
146 /** 148 /**
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 uiPair.classList.add('dragging'); 182 uiPair.classList.add('dragging');
181 }, 183 },
182 184
183 /** 185 /**
184 * Executes when a mousemove event occurs. 186 * Executes when a mousemove event occurs.
185 * @param {MouseEvent} e The event that triggered this listener. 187 * @param {MouseEvent} e The event that triggered this listener.
186 */ 188 */
187 onMouseMove_: function(e) { 189 onMouseMove_: function(e) {
188 var point = MarginsUI.convert({ x: e.x, y: e.y }); 190 var point = MarginsUI.convert({ x: e.x, y: e.y });
189 191
190 var dragEvent = new cr.Event('DragEvent'); 192 var dragEvent = new cr.Event(customEvents.DRAG);
191 dragEvent.dragDelta = 193 dragEvent.dragDelta =
192 this.lastClickedMarginsUIPair.getDragDisplacementFrom(point); 194 this.lastClickedMarginsUIPair.getDragDisplacementFrom(point);
193 dragEvent.destinationPoint = point; 195 dragEvent.destinationPoint = point;
194 this.dispatchEvent(dragEvent); 196 this.dispatchEvent(dragEvent);
195 }, 197 },
196 }; 198 };
197 199
198 return { 200 return {
199 MarginsUI: MarginsUI 201 MarginsUI: MarginsUI
200 }; 202 };
201 }); 203 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698