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

Side by Side Diff: chrome/browser/resources/print_preview/data/margins.js

Issue 10108001: Refactor print preview web ui (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Resolve conflicts Created 8 years, 7 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
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 cr.define('print_preview', function() {
6 'use strict';
7
8 /**
9 * Creates a Margins object that holds four margin values in points.
10 * @param {number} top The top margin in pts.
11 * @param {number} right The right margin in pts.
12 * @param {number} bottom The bottom margin in pts.
13 * @param {number} left The left margin in pts.
14 * @constructor
15 */
16 function Margins(top, right, bottom, left) {
17 /**
18 * Backing store for the margin values in points.
19 * @type {Object.<
20 * print_preview.ticket_items.CustomMargins.Orientation,
21 * number>}
22 * @private
23 */
24 this.value_ = {};
25 this.value_[print_preview.ticket_items.CustomMargins.Orientation.TOP] = top;
26 this.value_[print_preview.ticket_items.CustomMargins.Orientation.RIGHT] =
27 right;
28 this.value_[print_preview.ticket_items.CustomMargins.Orientation.BOTTOM] =
29 bottom;
30 this.value_[print_preview.ticket_items.CustomMargins.Orientation.LEFT] =
31 left;
32 };
33
34 Margins.prototype = {
35 /**
36 * @param {print_preview.ticket_items.CustomMargins.Orientation} orientation
37 * Specifies the margin value to get.
38 * @return {number} Value of the margin of the given orientation.
39 */
40 get: function(orientation) {
41 return this.value_[orientation];
42 },
43
44 /**
45 * @param {print_preview.ticket_items.CustomMargins.Orientation} orientation
46 * Specifies the margin to set.
47 * @param {number} value Updated value of the margin in points to modify.
48 * @return {!print_preview.Margins} A new copy of |this| with the
49 * modification made to the specified margin.
50 */
51 set: function(orientation, value) {
52 var newValue = {};
53 for (var o in this.value_) {
54 newValue[o] = this.value_[o];
55 }
56 newValue[orientation] = value;
57 return new Margins(
58 newValue[print_preview.ticket_items.CustomMargins.Orientation.TOP],
59 newValue[print_preview.ticket_items.CustomMargins.Orientation.RIGHT],
60 newValue[print_preview.ticket_items.CustomMargins.Orientation.BOTTOM],
61 newValue[print_preview.ticket_items.CustomMargins.Orientation.LEFT]);
62 },
63
64 /**
65 * @param {print_preview.Margins} other The other margins object to compare
66 * against.
67 * @return {boolean} Whether this margins object is equal to another.
68 */
69 equals: function(other) {
70 if (other == null) {
71 return false;
72 }
73 for (var orientation in this.value_) {
74 if (this.value_[orientation] != other.value_[orientation]) {
75 return false;
76 }
77 }
78 return true;
79 }
80 };
81
82 // Export
83 return {
84 Margins: Margins
85 };
86 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698