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

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

Issue 8233030: Print Preview: Making margin lines draggable. (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 'use strict'; 6 'use strict';
7 7
8 /** 8 /**
9 * Creates a Margins object that holds four margin values. The units in which 9 * Creates a Margins object that holds four margin values. The units in which
10 * the values are expressed can be any numeric value. 10 * the values are expressed can be any numeric value.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 * @param {Margins} rhs The Margins object values to be used. 53 * @param {Margins} rhs The Margins object values to be used.
54 */ 54 */
55 copy: function(rhs) { 55 copy: function(rhs) {
56 this[MarginSettings.TOP_GROUP] = rhs[MarginSettings.TOP_GROUP]; 56 this[MarginSettings.TOP_GROUP] = rhs[MarginSettings.TOP_GROUP];
57 this[MarginSettings.LEFT_GROUP] = rhs[MarginSettings.LEFT_GROUP]; 57 this[MarginSettings.LEFT_GROUP] = rhs[MarginSettings.LEFT_GROUP];
58 this[MarginSettings.RIGHT_GROUP] = rhs[MarginSettings.RIGHT_GROUP]; 58 this[MarginSettings.RIGHT_GROUP] = rhs[MarginSettings.RIGHT_GROUP];
59 this[MarginSettings.BOTTOM_GROUP] = rhs[MarginSettings.BOTTOM_GROUP]; 59 this[MarginSettings.BOTTOM_GROUP] = rhs[MarginSettings.BOTTOM_GROUP];
60 }, 60 },
61 61
62 /** 62 /**
63 * Helper method returning an array of the string indices used for accessing
64 * all margins.
65 * @return {array} An array of string indices.
66 * @private
67 */
68 indicesAsArray_: function() {
69 return [MarginSettings.LEFT_GROUP, MarginSettings.TOP_GROUP,
70 MarginSettings.RIGHT_GROUP, MarginSettings.BOTTOM_GROUP];
71 },
72
73 /**
74 * Rounds |this| based on the precision used when displaying the margins in
75 * inches. This is done by converting from points to inches and back to
76 * points.
77 */
78 roundToInches: function() {
79 var indicesAsArray = this.indicesAsArray_();
80 for (var i = 0; i < indicesAsArray.length; i++) {
81 this[indicesAsArray[i]] =
82 print_preview.convertPointsToInchesTextAndBack(
83 this[indicesAsArray[i]]);
84 }
85 },
86
87 /**
63 * Converts |this| to inches and returns the result in a new Margins object. 88 * Converts |this| to inches and returns the result in a new Margins object.
64 * |this| is not affected. It assumes that |this| is currently expressed in 89 * |this| is not affected. It assumes that |this| is currently expressed in
65 * points. 90 * points.
66 * @param {number} The number of decimal points to keep. 91 * @param {number} The number of decimal points to keep.
67 * @return {Margins} The equivalent of |this| in inches. 92 * @return {Margins} The equivalent of |this| in inches.
68 */ 93 */
69 toInches: function(precision) { 94 toInches: function(precision) {
70 return new Margins( 95 return new Margins(
71 Margins.roundToPrecision(convertPointsToInches( 96 Margins.roundToPrecision(convertPointsToInches(
72 this[MarginSettings.LEFT_GROUP]), precision), 97 this[MarginSettings.LEFT_GROUP]), precision),
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 this.lastSelectedOption_ = MarginSettings.MARGINS_VALUE_DEFAULT; 153 this.lastSelectedOption_ = MarginSettings.MARGINS_VALUE_DEFAULT;
129 154
130 // Holds the currently updated default page layout values. 155 // Holds the currently updated default page layout values.
131 this.currentDefaultPageLayout = null; 156 this.currentDefaultPageLayout = null;
132 // Holds the default page layout values when the custom margins was last 157 // Holds the default page layout values when the custom margins was last
133 // selected. 158 // selected.
134 this.previousDefaultPageLayout_ = null; 159 this.previousDefaultPageLayout_ = null;
135 160
136 // True if the margins UI should be shown regardless of mouse position. 161 // True if the margins UI should be shown regardless of mouse position.
137 this.forceDisplayingMarginLines_ = true; 162 this.forceDisplayingMarginLines_ = true;
163
164 // @type {EventTracker} Used to keep track of certain event listeners.
165 this.eventTracker = new EventTracker();
166
138 this.addEventListeners_(); 167 this.addEventListeners_();
139 } 168 }
140 169
141 // Number of points per inch. 170 // Number of points per inch.
142 MarginSettings.POINTS_PER_INCH = 72; 171 MarginSettings.POINTS_PER_INCH = 72;
172 // Minimum allowed distance in points between top-bottom, left-right margins.
173 MarginSettings.MINIMUM_MARGINS_DISTANCE = 36;
143 // Margin list values. 174 // Margin list values.
144 MarginSettings.MARGINS_VALUE_DEFAULT = 0; 175 MarginSettings.MARGINS_VALUE_DEFAULT = 0;
145 MarginSettings.MARGINS_VALUE_NO_MARGINS = 1; 176 MarginSettings.MARGINS_VALUE_NO_MARGINS = 1;
146 MarginSettings.MARGINS_VALUE_CUSTOM = 2; 177 MarginSettings.MARGINS_VALUE_CUSTOM = 2;
147 // Default Margins option index. 178 // Default Margins option index.
148 MarginSettings.DEFAULT_MARGINS_OPTION_INDEX = 0; 179 MarginSettings.DEFAULT_MARGINS_OPTION_INDEX = 0;
149 // Group name corresponding to the top margin. 180 // Group name corresponding to the top margin.
150 MarginSettings.TOP_GROUP = 'top'; 181 MarginSettings.TOP_GROUP = 'top';
151 // Group name corresponding to the left margin. 182 // Group name corresponding to the left margin.
152 MarginSettings.LEFT_GROUP = 'left'; 183 MarginSettings.LEFT_GROUP = 'left';
(...skipping 20 matching lines...) Expand all
173 204
174 /** 205 /**
175 * @return {number} The value of the selected margin option. 206 * @return {number} The value of the selected margin option.
176 */ 207 */
177 get selectedMarginsValue() { 208 get selectedMarginsValue() {
178 var val = this.marginList_.options[this.marginList_.selectedIndex].value; 209 var val = this.marginList_.options[this.marginList_.selectedIndex].value;
179 return parseInt(val, 10); 210 return parseInt(val, 10);
180 }, 211 },
181 212
182 /** 213 /**
214 * @return {number} The total width of the plugin in points.
215 */
216 get totalWidthInPoints() {
217 var pageInformation = previewArea.pageLocationNormalized;
218 return this.pageWidth_ / pageInformation.width;
219 },
220
221 /**
222 * @return {number} The total height of the plugin in points.
223 */
224 get totalHeightInPoints() {
225 var pageInformation = previewArea.pageLocationNormalized;
226 return this.pageHeight_ / pageInformation.height;
227 },
228
229 /**
183 * @return {boolean} True if default margins are selected. 230 * @return {boolean} True if default margins are selected.
184 */ 231 */
185 isDefaultMarginsSelected: function() { 232 isDefaultMarginsSelected: function() {
186 return this.selectedMarginsValue == MarginSettings.MARGINS_VALUE_DEFAULT; 233 return this.selectedMarginsValue == MarginSettings.MARGINS_VALUE_DEFAULT;
187 }, 234 },
188 235
189 /** 236 /**
190 * @return {boolean} True if no margins are selected. 237 * @return {boolean} True if no margins are selected.
191 */ 238 */
192 isNoMarginsSelected: function() { 239 isNoMarginsSelected: function() {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 /** 287 /**
241 * Adds listeners to all margin related controls. 288 * Adds listeners to all margin related controls.
242 * @private 289 * @private
243 */ 290 */
244 addEventListeners_: function() { 291 addEventListeners_: function() {
245 this.marginList_.onchange = this.onMarginsChanged_.bind(this); 292 this.marginList_.onchange = this.onMarginsChanged_.bind(this);
246 document.addEventListener('PDFLoaded', this.onPDFLoaded_.bind(this)); 293 document.addEventListener('PDFLoaded', this.onPDFLoaded_.bind(this));
247 }, 294 },
248 295
249 /** 296 /**
297 * Executes whenever a "DragEvent" occurs.
298 * @param {cr.Event} e The event that triggered this listener.
299 */
300 onDragEvent_: function(e) {
301 var dragDeltaInPoints = this.convertDragDeltaToPoints_(e.dragDelta);
302 this.marginsUI.lastClickedMarginsUIPair.updateWhileDragging(
303 dragDeltaInPoints, e.destinationPoint);
304 },
305
306 /**
307 * @param {number} dragDelta The difference in pixels between the original
308 * and current postion of the last clicked margin line.
309 * @return {number} The difference in points.
310 * @private
311 */
312 convertDragDeltaToPoints_: function(dragDelta) {
313 if (this.marginsUI.lastClickedMarginsUIPair.isTop_() ||
314 this.marginsUI.lastClickedMarginsUIPair.isBottom_()) {
315 return dragDelta * this.totalHeightInPoints;
316 } else {
317 return dragDelta * this.totalWidthInPoints;
318 }
319 },
320
321 /**
250 * @return {boolean} True if the margin settings are valid. 322 * @return {boolean} True if the margin settings are valid.
251 */ 323 */
252 areMarginSettingsValid: function() { 324 areMarginSettingsValid: function() {
253 if (this.marginsUI_ == null) 325 if (this.marginsUI_ == null)
254 return true; 326 return true;
255 327
256 var pairs = this.marginsUI.pairsAsList; 328 var pairs = this.marginsUI.pairsAsList;
257 return pairs.every(function(pair) { return pair.box_.isValid; }); 329 return pairs.every(function(pair) { return pair.box_.isValid; });
258 }, 330 },
259 331
260 /** 332 /**
261 * Calculates the maximum allowable value of the selected margin text for 333 * Calculates the maximum allowable value of the selected margin text for
262 * every margin. 334 * every margin.
263 * @return {array} The maximum allowable value in order top, left, right, 335 * @return {array} The maximum allowable value in points in order top, left,
264 * bottom. 336 * right, bottom.
265 * @private 337 * @private
266 */ 338 */
267 getMarginValueLimits_: function() { 339 getMarginValueLimits_: function() {
268 var marginValueLimits = []; 340 var marginValueLimits = [];
269 marginValueLimits[0] = this.pageHeight_ - this.customMargins_.bottom; 341 marginValueLimits[0] = this.pageHeight_ - this.customMargins_.bottom -
270 marginValueLimits[1] = this.pageWidth_ - this.customMargins_.right; 342 MarginSettings.MINIMUM_MARGINS_DISTANCE;
271 marginValueLimits[2] = this.pageWidth_ - this.customMargins_.left; 343 marginValueLimits[1] = this.pageWidth_ - this.customMargins_.right -
272 marginValueLimits[3] = this.pageHeight_ - this.customMargins_.top; 344 MarginSettings.MINIMUM_MARGINS_DISTANCE;
345 marginValueLimits[2] = this.pageWidth_ - this.customMargins_.left -
346 MarginSettings.MINIMUM_MARGINS_DISTANCE;
347 marginValueLimits[3] = this.pageHeight_ - this.customMargins_.top -
348 MarginSettings.MINIMUM_MARGINS_DISTANCE;
349
350 for (var i = 0; i < marginValueLimits.length; i++) {
351 marginValueLimits[i] = Math.max(marginValueLimits[i], 0);
352 marginValueLimits[i] = print_preview.convertPointsToInchesTextAndBack(
353 marginValueLimits[i]);
354 }
273 return marginValueLimits; 355 return marginValueLimits;
274 }, 356 },
275 357
276 /** 358 /**
359 * @return {array} The margin value limits positions normalized to the total
360 * width and height of the plugin and with respect to the top left
361 * corner of the plugin.
362 */
363 getMarginValueLimitsInPercent_: function() {
364 var pageInformation = previewArea.pageLocationNormalized;
365 var totalWidthInPoints = this.pageWidth_ / pageInformation.width;
366 var totalHeightInPoints = this.pageHeight_ / pageInformation.height;
367 var marginValueLimits = this.getMarginValueLimits_();
368 var marginValueLimitsInPercent = [];
369 marginValueLimitsInPercent[0] = pageInformation.y + marginValueLimits[0] /
370 totalHeightInPoints;
371 marginValueLimitsInPercent[1] = pageInformation.x + marginValueLimits[1] /
372 totalWidthInPoints;
373 marginValueLimitsInPercent[2] = pageInformation.x +
374 pageInformation.width - marginValueLimits[2] / totalWidthInPoints;
375 marginValueLimitsInPercent[3] = pageInformation.y +
376 pageInformation.height - marginValueLimits[3] / totalHeightInPoints;
377 return marginValueLimitsInPercent;
378 },
379
380 /**
277 * When the user stops typing in the margin text box a new print preview is 381 * When the user stops typing in the margin text box a new print preview is
278 * requested, only if 382 * requested, only if
279 * 1) The input is compeletely valid (it can be parsed in its entirety). 383 * 1) The input is compeletely valid (it can be parsed in its entirety).
280 * 2) The newly selected margins differ from the previously selected. 384 * 2) The newly selected margins differ from the previously selected.
281 * @param {cr.Event} event The change event holding information about what 385 * @param {cr.Event} event The change event holding information about what
282 * changed. 386 * changed.
283 * @private 387 * @private
284 */ 388 */
285 onMarginTextValueMayHaveChanged_: function(event) { 389 onMarginTextValueMayHaveChanged_: function(event) {
286 var marginBox = event.target; 390 var marginBox = event.target;
287 var marginBoxValue = convertInchesToPoints(marginBox.margin); 391 var marginBoxValue = convertInchesToPoints(marginBox.margin);
288 this.customMargins_[marginBox.marginGroup] = marginBoxValue; 392 this.customMargins_[marginBox.marginGroup] = marginBoxValue;
289 this.requestPreviewIfNeeded_(); 393 this.requestPreviewIfNeeded_();
290 }, 394 },
291 395
292 /** 396 /**
293 * @type {print_preview.MarginsUI} The object holding the UI for specifying 397 * @type {print_preview.MarginsUI} The object holding the UI for specifying
294 * custom margins. 398 * custom margins.
295 */ 399 */
296 get marginsUI() { 400 get marginsUI() {
297 if (!this.marginsUI_) { 401 if (!this.marginsUI_) {
298 this.marginsUI_ = new print_preview.MarginsUI($('mainview')); 402 this.marginsUI_ = new print_preview.MarginsUI();
403 $('mainview').appendChild(this.marginsUI_);
299 this.marginsUI_.addObserver( 404 this.marginsUI_.addObserver(
300 this.onMarginTextValueMayHaveChanged_.bind(this)); 405 this.onMarginTextValueMayHaveChanged_.bind(this));
301 } 406 }
302 return this.marginsUI_; 407 return this.marginsUI_;
303 }, 408 },
304 409
305 /** 410 /**
306 * Adds listeners when the custom margins option is selected. 411 * Adds listeners when the custom margins option is selected.
307 * @private 412 * @private
308 */ 413 */
309 addCustomMarginEventListeners_: function() { 414 addCustomMarginEventListeners_: function() {
310 $('mainview').onmouseover = this.onMainviewMouseOver_.bind(this); 415 $('mainview').onmouseover = this.onMainviewMouseOver_.bind(this);
311 $('sidebar').onmouseover = this.onSidebarMouseOver_.bind(this); 416 $('sidebar').onmouseover = this.onSidebarMouseOver_.bind(this);
417 this.eventTracker.add(
418 this.marginsUI, 'DragEvent', this.onDragEvent_.bind(this), false);
312 }, 419 },
313 420
314 /** 421 /**
315 * Removes the event listeners associated with the custom margins option. 422 * Removes the event listeners associated with the custom margins option.
316 * @private 423 * @private
317 */ 424 */
318 removeCustomMarginEventListeners_: function() { 425 removeCustomMarginEventListeners_: function() {
319 $('mainview').onmouseover = null; 426 $('mainview').onmouseover = null;
320 $('sidebar').onmouseover = null; 427 $('sidebar').onmouseover = null;
428 this.eventTracker.remove(this.marginsUI, 'DragEvent');
321 this.marginsUI.hide(); 429 this.marginsUI.hide();
322 }, 430 },
323 431
324 /** 432 /**
325 * Updates |this.marginsUI| depending on the specified margins and the 433 * Updates |this.marginsUI| depending on the specified margins and the
326 * position of the page within the plugin. 434 * position of the page within the plugin.
327 * @private 435 * @private
328 */ 436 */
329 drawCustomMarginsUI_: function() { 437 drawCustomMarginsUI_: function() {
330 // TODO(dpapad): find out why passing |!this.areMarginsSettingsValid()| 438 // TODO(dpapad): find out why passing |!this.areMarginsSettingsValid()|
331 // directly produces the opposite value even though 439 // directly produces the opposite value even though
332 // |this.getMarginsRectangleInPercent_()| and 440 // |this.getMarginsRectangleInPercent_()| and
333 // |this.getMarginValueLimits_()| have no side effects. 441 // |this.getMarginValueLimits_()| have no side effects.
442 previewArea.update();
334 var keepDisplayedValue = !this.areMarginSettingsValid(); 443 var keepDisplayedValue = !this.areMarginSettingsValid();
335 this.marginsUI.update(this.getMarginsRectangleInPercent_(), 444 this.marginsUI.update(this.getMarginsRectangleInPercent_(),
336 this.customMargins_, 445 this.customMargins_,
337 this.getMarginValueLimits_(), 446 this.getMarginValueLimits_(),
338 keepDisplayedValue); 447 keepDisplayedValue,
448 this.getMarginValueLimitsInPercent_());
339 this.marginsUI.draw(); 449 this.marginsUI.draw();
340 }, 450 },
341 451
342 /** 452 /**
343 * Called when there is change in the preview position or size. 453 * Called when there is change in the preview position or size.
344 */ 454 */
345 onPreviewPositionChanged: function() { 455 onPreviewPositionChanged: function() {
346 if (this.isCustomMarginsSelected() && previewArea.pdfLoaded && 456 if (this.isCustomMarginsSelected() && previewArea.pdfLoaded &&
347 pageSettings.totalPageCount != undefined) { 457 pageSettings.totalPageCount != undefined) {
348 this.drawCustomMarginsUI_(); 458 this.drawCustomMarginsUI_();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 setDefaultValuesAndRegeneratePreview(false); 496 setDefaultValuesAndRegeneratePreview(false);
387 }, 497 },
388 498
389 /** 499 /**
390 * Executes when the custom margins option is selected. 500 * Executes when the custom margins option is selected.
391 * @private 501 * @private
392 */ 502 */
393 onCustomMarginsSelected_: function() { 503 onCustomMarginsSelected_: function() {
394 this.addCustomMarginEventListeners_(); 504 this.addCustomMarginEventListeners_();
395 505
396 if (this.lastSelectedOption_ == MarginSettings.MARGINS_VALUE_DEFAULT) 506 if (this.lastSelectedOption_ == MarginSettings.MARGINS_VALUE_DEFAULT) {
397 this.customMargins_ = this.currentDefaultPageLayout.margins_; 507 this.customMargins_ = this.currentDefaultPageLayout.margins_;
508 this.customMargins_.roundToInches();
509 }
398 this.previousCustomMargins_.copy(this.customMargins_); 510 this.previousCustomMargins_.copy(this.customMargins_);
399 511
400 if (this.previousDefaultPageLayout_ != this.currentDefaultPageLayout) { 512 if (this.previousDefaultPageLayout_ != this.currentDefaultPageLayout) {
401 this.pageWidth_ = this.currentDefaultPageLayout.pageWidth; 513 this.pageWidth_ = this.currentDefaultPageLayout.pageWidth;
402 this.pageHeight_ = this.currentDefaultPageLayout.pageHeight; 514 this.pageHeight_ = this.currentDefaultPageLayout.pageHeight;
403 } 515 }
404 516
405 this.previousDefaultPageLayout_ = this.currentDefaultPageLayout; 517 this.previousDefaultPageLayout_ = this.currentDefaultPageLayout;
406 this.drawCustomMarginsUI_(); 518 this.drawCustomMarginsUI_();
407 this.marginsUI.show(); 519 this.marginsUI.show();
408 }, 520 },
409 521
410 /** 522 /**
411 * Calculates the coordinates of the four margin lines. These are the 523 * Calculates the coordinates of the four margin lines. These are the
412 * coordinates where the margin lines should be displayed. The coordinates 524 * coordinates where the margin lines should be displayed. The coordinates
413 * are expressed in terms of percentages with respect to the total width 525 * are expressed in terms of percentages with respect to the total width
414 * and height of the plugin. 526 * and height of the plugin.
415 * @return {print_preview.Rect} A rectnangle that describes the position of 527 * @return {print_preview.Rect} A rectnangle that describes the position of
416 * the four margin lines. 528 * the four margin lines.
417 * @private 529 * @private
418 */ 530 */
419 getMarginsRectangleInPercent_: function() { 531 getMarginsRectangleInPercent_: function() {
420 var pageLocation = previewArea.getPageLocationNormalized(); 532 var pageLocation = previewArea.pageLocationNormalized;
421 var marginsInPercent = this.getMarginsInPercent_(); 533 var marginsInPercent = this.getMarginsInPercent_();
422 var leftX = pageLocation.x + marginsInPercent.left; 534 var leftX = pageLocation.x + marginsInPercent.left;
423 var topY = pageLocation.y + marginsInPercent.top; 535 var topY = pageLocation.y + marginsInPercent.top;
424 var contentWidth = pageLocation.width - (marginsInPercent.left + 536 var contentWidth = pageLocation.width - (marginsInPercent.left +
425 marginsInPercent.right); 537 marginsInPercent.right);
426 var contentHeight = pageLocation.height - (marginsInPercent.top + 538 var contentHeight = pageLocation.height - (marginsInPercent.top +
427 marginsInPercent.bottom); 539 marginsInPercent.bottom);
428 return new print_preview.Rect( 540 return new print_preview.Rect(
429 leftX, topY, contentWidth, contentHeight); 541 leftX, topY, contentWidth, contentHeight);
430 }, 542 },
431 543
432 /** 544 /**
433 * @return {print_preview.Margins} The currently selected margin values 545 * @return {print_preview.Margins} The currently selected margin values
434 * normalized to the total width and height of the plugin. 546 * normalized to the total width and height of the plugin.
435 * @private 547 * @private
436 */ 548 */
437 getMarginsInPercent_: function() { 549 getMarginsInPercent_: function() {
438 var pageInformation = previewArea.getPageLocationNormalized(); 550 return this.convertMarginsInPointsToPercent(this.customMargins_);
551 },
552
553 /**
554 * Converts |marginsToConvert| to points and normalizes it to the height and
555 * width of the plugin.
556 * @return {print_preview.Margins} The margins in percent.
557 * @private
558 */
559 convertMarginsInPointsToPercent: function(marginsToConvert) {
560 var pageInformation = previewArea.pageLocationNormalized;
439 var totalWidthInPoints = this.pageWidth_ / pageInformation.width; 561 var totalWidthInPoints = this.pageWidth_ / pageInformation.width;
440 var totalHeightInPoints = this.pageHeight_ / pageInformation.height; 562 var totalHeightInPoints = this.pageHeight_ / pageInformation.height;
441 var marginsInPercent = new Margins( 563 var marginsInPercent = new Margins(
442 this.customMargins_.left / totalWidthInPoints, 564 marginsToConvert.left / totalWidthInPoints,
443 this.customMargins_.top / totalHeightInPoints, 565 marginsToConvert.top / totalHeightInPoints,
444 this.customMargins_.right / totalWidthInPoints, 566 marginsToConvert.right / totalWidthInPoints,
445 this.customMargins_.bottom / totalHeightInPoints); 567 marginsToConvert.bottom / totalHeightInPoints);
446 return marginsInPercent; 568 return marginsInPercent;
447 }, 569 },
448 570
449 /** 571 /**
450 * If custom margins is the currently selected option then change to the 572 * If custom margins is the currently selected option then change to the
451 * default margins option. 573 * default margins option.
452 * @private 574 * @private
453 */ 575 */
454 resetMarginsIfNeeded: function() { 576 resetMarginsIfNeeded: function() {
455 if (this.isCustomMarginsSelected()) { 577 if (this.isCustomMarginsSelected()) {
456 this.marginList_.options[ 578 this.marginList_.options[
457 MarginSettings.DEFAULT_MARGINS_OPTION_INDEX].selected = true; 579 MarginSettings.DEFAULT_MARGINS_OPTION_INDEX].selected = true;
458 this.removeCustomMarginEventListeners_(); 580 this.removeCustomMarginEventListeners_();
581 this.forceDisplayingMarginLines_ = true;
459 this.lastSelectedOption_ = MarginSettings.MARGINS_VALUE_DEFAULT; 582 this.lastSelectedOption_ = MarginSettings.MARGINS_VALUE_DEFAULT;
460 } 583 }
461 }, 584 },
462 585
463 /** 586 /**
464 * Executes when a PDFLoaded event occurs. 587 * Executes when a PDFLoaded event occurs.
465 * @private 588 * @private
466 */ 589 */
467 onPDFLoaded_: function() { 590 onPDFLoaded_: function() {
468 if (!previewModifiable) 591 if (!previewModifiable)
469 fadeOutElement(this.marginsOption_); 592 fadeOutElement(this.marginsOption_);
470 } 593 }
471 }; 594 };
472 595
473 return { 596 return {
474 MarginSettings: MarginSettings, 597 MarginSettings: MarginSettings,
475 PageLayout: PageLayout, 598 PageLayout: PageLayout,
476 }; 599 };
477 }); 600 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/print_preview/margin_line.js ('k') | chrome/browser/resources/print_preview/margin_textbox.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698