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

Unified Diff: chrome/browser/resources/print_preview/data/margins.js

Issue 10909124: Improves application state persistance. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Updates unit tests. Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/print_preview/data/margins.js
diff --git a/chrome/browser/resources/print_preview/data/margins.js b/chrome/browser/resources/print_preview/data/margins.js
index 18ed90aa141f56e4a1d4ca4190860ab23e15061f..df3af5f681f58116b7486ea9316cb7b7b6a08f6b 100644
--- a/chrome/browser/resources/print_preview/data/margins.js
+++ b/chrome/browser/resources/print_preview/data/margins.js
@@ -30,6 +30,20 @@ cr.define('print_preview', function() {
left;
};
+ /**
+ * Parses a margins object from the given serialized state.
+ * @param {Object} state Serialized representation of the margins created by
+ * the {@code serialize} method.
+ * @return {!print_preview.Margins} New margins instance.
+ */
+ Margins.parse = function(state) {
+ return new print_preview.Margins(
+ state[print_preview.ticket_items.CustomMargins.Orientation.TOP],
+ state[print_preview.ticket_items.CustomMargins.Orientation.RIGHT],
+ state[print_preview.ticket_items.CustomMargins.Orientation.BOTTOM],
+ state[print_preview.ticket_items.CustomMargins.Orientation.LEFT]);
+ };
+
Margins.prototype = {
/**
* @param {!print_preview.ticket_items.CustomMargins.Orientation}
@@ -48,10 +62,7 @@ cr.define('print_preview', function() {
* modification made to the specified margin.
*/
set: function(orientation, value) {
- var newValue = {};
- for (var o in this.value_) {
- newValue[o] = this.value_[o];
- }
+ var newValue = this.clone_();
newValue[orientation] = value;
return new Margins(
newValue[print_preview.ticket_items.CustomMargins.Orientation.TOP],
@@ -75,6 +86,23 @@ cr.define('print_preview', function() {
}
}
return true;
+ },
+
+ /** @return {Object} A serialized representation of the margins. */
+ serialize: function() {
+ return this.clone_();
+ },
+
+ /**
+ * @return {Object} Cloned state of the margins.
+ * @private
+ */
+ clone_: function() {
+ var clone = {};
+ for (var o in this.value_) {
+ clone[o] = this.value_[o];
+ }
+ return clone;
}
};

Powered by Google App Engine
This is Rietveld 408576698