OLD | NEW |
---|---|
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('ntp4', function() { | 5 cr.define('ntp4', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 var TilePage = ntp4.TilePage; | 8 var TilePage = ntp4.TilePage; |
9 | 9 |
10 /** | 10 /** |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 onClick_: function(e) { | 72 onClick_: function(e) { |
73 // Tell chrome to launch the app. | 73 // Tell chrome to launch the app. |
74 var NTP_APPS_MAXIMIZED = 0; | 74 var NTP_APPS_MAXIMIZED = 0; |
75 chrome.send('launchApp', [this.appData.id, NTP_APPS_MAXIMIZED]); | 75 chrome.send('launchApp', [this.appData.id, NTP_APPS_MAXIMIZED]); |
76 | 76 |
77 // Don't allow the click to trigger a link or anything | 77 // Don't allow the click to trigger a link or anything |
78 e.preventDefault(); | 78 e.preventDefault(); |
79 }, | 79 }, |
80 }; | 80 }; |
81 | 81 |
82 /** | |
83 * Creates a new Link object. This is a stub implementation for now. | |
84 * @param {Object} data The url and title. | |
85 * @constructor | |
86 * @extends {HTMLAnchorElement} | |
87 */ | |
88 function Link(data) { | |
89 var el = cr.doc.createElement('a'); | |
90 el.__proto__ = Link.prototype; | |
91 el.data = data; | |
92 el.initialize(); | |
93 | |
94 return el; | |
95 }; | |
96 | |
97 Link.prototype = { | |
98 __proto__: HTMLAnchorElement.prototype, | |
99 | |
100 initialize: function() { | |
101 this.className = 'link'; | |
102 var thumbnailDiv = this.ownerDocument.createElement('div'); | |
103 this.appendChild(thumbnailDiv); | |
104 | |
105 var title = cr.doc.createElement('span'); | |
arv (Not doing code reviews)
2011/05/20 23:49:07
Use this.ownerDocument here too
Evan Stade
2011/05/21 00:20:06
Done.
| |
106 title.textContent = this.data.title; | |
107 this.appendChild(title); | |
108 }, | |
109 | |
110 /** | |
111 * Set the size and position of the link tile. | |
112 * @param {number} size The total size of |this|. | |
113 * @param {number} x The x-position. | |
114 * @param {number} y The y-position. | |
115 * animate. | |
116 */ | |
117 setBounds: function(size, x, y) { | |
118 this.style.width = this.style.height = size + 'px'; | |
119 this.style.left = x + 'px'; | |
120 this.style.top = y + 'px'; | |
121 }, | |
122 }; | |
123 | |
82 // The fraction of the app tile size that the icon uses. | 124 // The fraction of the app tile size that the icon uses. |
83 var APP_IMG_SIZE_FRACTION = 4 / 5; | 125 var APP_IMG_SIZE_FRACTION = 4 / 5; |
84 | 126 |
85 var appsPageGridValues = { | 127 var appsPageGridValues = { |
86 // The fewest tiles we will show in a row. | 128 // The fewest tiles we will show in a row. |
87 minColCount: 3, | 129 minColCount: 3, |
88 // The most tiles we will show in a row. | 130 // The most tiles we will show in a row. |
89 maxColCount: 6, | 131 maxColCount: 6, |
90 | 132 |
91 // The smallest a tile can be. | 133 // The smallest a tile can be. |
(...skipping 25 matching lines...) Expand all Loading... | |
117 }, | 159 }, |
118 | 160 |
119 /** | 161 /** |
120 * Creates an app DOM element and places it at the last position on the | 162 * Creates an app DOM element and places it at the last position on the |
121 * page. | 163 * page. |
122 * @param {Object} appData The data object that describes the app. | 164 * @param {Object} appData The data object that describes the app. |
123 */ | 165 */ |
124 appendApp: function(appData) { | 166 appendApp: function(appData) { |
125 this.appendTile(new App(appData)); | 167 this.appendTile(new App(appData)); |
126 }, | 168 }, |
169 | |
170 /** @inheritDoc */ | |
171 shouldAcceptDrag: function(tile, dataTransfer) { | |
172 return tile || (dataTransfer && dataTransfer.types.indexOf('url') != -1); | |
173 }, | |
174 | |
175 /** @inheritDoc */ | |
176 addOutsideData: function(dataTransfer, index) { | |
177 var url = dataTransfer.getData('url'); | |
178 assert(url); | |
179 if (!url) | |
180 return; | |
181 | |
182 // If the dataTransfer has html data, use that html's text contents as the | |
183 // title of the new link. | |
184 var html = dataTransfer.getData('text/html'); | |
185 var title; | |
186 if (html) { | |
187 // It's important that we don't attach this node to the document | |
188 // because it might contain scripts. | |
189 var node = this.ownerDocument.createElement('div'); | |
190 node.innerHTML = html; | |
191 title = node.textContent; | |
192 } | |
193 if (!title) | |
194 title = url; | |
195 | |
196 var data = {url: url, title: title}; | |
197 this.addTileAt(new Link(data), index); | |
198 }, | |
127 }; | 199 }; |
128 | 200 |
129 return { | 201 return { |
130 AppsPage: AppsPage, | 202 AppsPage: AppsPage, |
131 }; | 203 }; |
132 }); | 204 }); |
OLD | NEW |