OLD | NEW |
| (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 'use strict'; | |
6 | |
7 base.require('model.constants'); | |
8 | |
9 base.exportTo('ccfv.model', function() { | |
10 | |
11 /** | |
12 * Represents a cc::Tile over the course of its lifetime. | |
13 * | |
14 * @constructor | |
15 */ | |
16 function TileHistory(id) { | |
17 this.id = id; | |
18 this.tilesBySnapshotNumber = {}; | |
19 this.layerID = undefined; | |
20 this.picturePile = undefined; | |
21 this.contentsScale = undefined; | |
22 | |
23 this.selected = false; | |
24 } | |
25 | |
26 TileHistory.prototype = { | |
27 get title() { | |
28 return 'TileHistory ' + this.id; | |
29 }, | |
30 | |
31 getOrCreateTileForLTHI: function(lthi) { | |
32 if (!this.tilesBySnapshotNumber[lthi.snapshotNumber]) | |
33 this.tilesBySnapshotNumber[lthi.snapshotNumber] = new Tile(this); | |
34 return this.tilesBySnapshotNumber[lthi.snapshotNumber]; | |
35 }, | |
36 | |
37 dumpToSimpleObject: function(obj) { | |
38 obj.id = this.id; | |
39 obj.layerID = this.layerID; | |
40 obj.picturePile = this.picturePile; | |
41 obj.contentsScale = this.contentsScale; | |
42 } | |
43 }; | |
44 | |
45 /** | |
46 * Represents a cc::Tile at an instant in time. | |
47 * | |
48 * @constructor | |
49 */ | |
50 function Tile(history) { | |
51 this.history = history; | |
52 this.managedState = undefined; | |
53 this.priority = [undefined, undefined]; | |
54 } | |
55 | |
56 Tile.prototype = { | |
57 get id() { | |
58 return this.history.id; | |
59 }, | |
60 | |
61 get contentsScale() { | |
62 return this.history.contents_scale; | |
63 }, | |
64 | |
65 get picturePile() { | |
66 return this.history.picture_pile; | |
67 }, | |
68 | |
69 get title() { | |
70 return 'Tile ' + this.id; | |
71 }, | |
72 | |
73 get selected() { | |
74 return this.history.selected; | |
75 }, | |
76 | |
77 set selected(s) { | |
78 this.history.selected = s; | |
79 }, | |
80 | |
81 dumpToSimpleObject: function(obj) { | |
82 obj.history = {}; | |
83 this.history.dumpToSimpleObject(obj.history); | |
84 obj.managedState = this.managedState; | |
85 obj.priority = [{}, {}]; | |
86 dumpAllButQuadToSimpleObject.call(this.priority[0], obj.priority[0]); | |
87 dumpAllButQuadToSimpleObject.call(this.priority[1], obj.priority[1]); | |
88 }, | |
89 }; | |
90 | |
91 // Called with priority object as context. | |
92 function dumpAllButQuadToSimpleObject(obj) { | |
93 for (var k in this) { | |
94 if (k == 'current_screen_quad') | |
95 continue; | |
96 obj[k] = this[k]; | |
97 } | |
98 } | |
99 | |
100 return { | |
101 Tile: Tile, | |
102 TileHistory: TileHistory | |
103 } | |
104 }); | |
105 | |
OLD | NEW |