OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // This module implements the base attributes of the GuestView tags. | 5 // This module implements the base attributes of the GuestView tags. |
6 | 6 |
7 // ----------------------------------------------------------------------------- | 7 // ----------------------------------------------------------------------------- |
8 // Attribute object. | 8 // Attribute object. |
9 | 9 |
10 // Default implementation of a GuestView attribute. | 10 // Default implementation of a GuestView attribute. |
11 function Attribute(name, view) { | 11 function Attribute(name, view) { |
| 12 this.dirty = false; |
| 13 this.ignoreMutation = false; |
12 this.name = name; | 14 this.name = name; |
13 this.view = view; | 15 this.view = view; |
14 this.ignoreMutation = false; | |
15 | 16 |
16 this.defineProperty(); | 17 this.defineProperty(); |
17 } | 18 } |
18 | 19 |
19 // Retrieves and returns the attribute's value. | 20 // Retrieves and returns the attribute's value. |
20 Attribute.prototype.getValue = function() { | 21 Attribute.prototype.getValue = function() { |
21 return this.view.element.getAttribute(this.name) || ''; | 22 return this.view.element.getAttribute(this.name) || ''; |
22 }; | 23 }; |
23 | 24 |
| 25 // Retrieves and returns the attribute's value if it has been dirtied since |
| 26 // the last time this method was called. Returns null otherwise. |
| 27 Attribute.prototype.getValueIfDirty = function() { |
| 28 if (!this.dirty) |
| 29 return null; |
| 30 this.dirty = false; |
| 31 return this.getValue(); |
| 32 }; |
| 33 |
24 // Sets the attribute's value. | 34 // Sets the attribute's value. |
25 Attribute.prototype.setValue = function(value) { | 35 Attribute.prototype.setValue = function(value) { |
26 this.view.element.setAttribute(this.name, value || ''); | 36 this.view.element.setAttribute(this.name, value || ''); |
27 }; | 37 }; |
28 | 38 |
29 // Changes the attribute's value without triggering its mutation handler. | 39 // Changes the attribute's value without triggering its mutation handler. |
30 Attribute.prototype.setValueIgnoreMutation = function(value) { | 40 Attribute.prototype.setValueIgnoreMutation = function(value) { |
31 this.ignoreMutation = true; | 41 this.ignoreMutation = true; |
32 this.setValue(value); | 42 this.setValue(value); |
33 this.ignoreMutation = false; | 43 this.ignoreMutation = false; |
(...skipping 10 matching lines...) Expand all Loading... |
44 }.bind(this), | 54 }.bind(this), |
45 enumerable: true | 55 enumerable: true |
46 }); | 56 }); |
47 }; | 57 }; |
48 | 58 |
49 // Called when the attribute's value changes. | 59 // Called when the attribute's value changes. |
50 Attribute.prototype.maybeHandleMutation = function(oldValue, newValue) { | 60 Attribute.prototype.maybeHandleMutation = function(oldValue, newValue) { |
51 if (this.ignoreMutation) | 61 if (this.ignoreMutation) |
52 return; | 62 return; |
53 | 63 |
| 64 this.dirty = true; |
54 this.handleMutation(oldValue, newValue); | 65 this.handleMutation(oldValue, newValue); |
55 }; | 66 }; |
56 | 67 |
57 // Called when a change that isn't ignored occurs to the attribute's value. | 68 // Called when a change that isn't ignored occurs to the attribute's value. |
58 Attribute.prototype.handleMutation = function(oldValue, newValue) {}; | 69 Attribute.prototype.handleMutation = function(oldValue, newValue) {}; |
59 | 70 |
60 // Called when the view's element is attached to the DOM tree. | 71 // Called when the view's element is attached to the DOM tree. |
61 Attribute.prototype.attach = function() {}; | 72 Attribute.prototype.attach = function() {}; |
62 | 73 |
63 // Called when the view's element is detached from the DOM tree. | 74 // Called when the view's element is detached from the DOM tree. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 | 133 |
123 var GuestViewAttributes = { | 134 var GuestViewAttributes = { |
124 Attribute: Attribute, | 135 Attribute: Attribute, |
125 BooleanAttribute: BooleanAttribute, | 136 BooleanAttribute: BooleanAttribute, |
126 IntegerAttribute: IntegerAttribute, | 137 IntegerAttribute: IntegerAttribute, |
127 ReadOnlyAttribute: ReadOnlyAttribute | 138 ReadOnlyAttribute: ReadOnlyAttribute |
128 }; | 139 }; |
129 | 140 |
130 // Exports. | 141 // Exports. |
131 exports.GuestViewAttributes = GuestViewAttributes; | 142 exports.GuestViewAttributes = GuestViewAttributes; |
OLD | NEW |