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

Side by Side Diff: chrome/browser/resources/print_preview/preview_generator.js

Issue 2617663002: WIP: run clang-format-js on lots of things (Closed)
Patch Set: merge Created 3 years, 11 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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('print_preview', function() { 5 cr.define('print_preview', function() {
6 'use strict'; 6 'use strict';
7 7
8 /** 8 /**
9 * Interface to the Chromium print preview generator. 9 * Interface to the Chromium print preview generator.
10 * @param {!print_preview.DestinationStore} destinationStore Used to get the 10 * @param {!print_preview.DestinationStore} destinationStore Used to get the
11 * currently selected destination. 11 * currently selected destination.
12 * @param {!print_preview.PrintTicketStore} printTicketStore Used to read the 12 * @param {!print_preview.PrintTicketStore} printTicketStore Used to read the
13 * state of the ticket and write document information. 13 * state of the ticket and write document information.
14 * @param {!print_preview.NativeLayer} nativeLayer Used to communicate to 14 * @param {!print_preview.NativeLayer} nativeLayer Used to communicate to
15 * Chromium's preview rendering system. 15 * Chromium's preview rendering system.
16 * @param {!print_preview.DocumentInfo} documentInfo Document data model. 16 * @param {!print_preview.DocumentInfo} documentInfo Document data model.
17 * @constructor 17 * @constructor
18 * @extends {cr.EventTarget} 18 * @extends {cr.EventTarget}
19 */ 19 */
20 function PreviewGenerator( 20 function PreviewGenerator(
21 destinationStore, printTicketStore, nativeLayer, documentInfo) { 21 destinationStore, printTicketStore, nativeLayer, documentInfo) {
22 cr.EventTarget.call(this); 22 cr.EventTarget.call(this);
23 23
24 /** 24 /**
25 * Used to get the currently selected destination. 25 * Used to get the currently selected destination.
26 * @type {!print_preview.DestinationStore} 26 * @type {!print_preview.DestinationStore}
27 * @private 27 * @private
28 */ 28 */
29 this.destinationStore_ = destinationStore; 29 this.destinationStore_ = destinationStore;
30 30
31 /** 31 /**
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 this.pageRanges_ = this.printTicketStore_.pageRange.getPageRanges(); 197 this.pageRanges_ = this.printTicketStore_.pageRange.getPageRanges();
198 this.marginsType_ = this.printTicketStore_.marginsType.getValue(); 198 this.marginsType_ = this.printTicketStore_.marginsType.getValue();
199 this.isCssBackgroundEnabled_ = 199 this.isCssBackgroundEnabled_ =
200 this.printTicketStore_.cssBackground.getValue(); 200 this.printTicketStore_.cssBackground.getValue();
201 this.isSelectionOnlyEnabled_ = 201 this.isSelectionOnlyEnabled_ =
202 this.printTicketStore_.selectionOnly.getValue(); 202 this.printTicketStore_.selectionOnly.getValue();
203 this.selectedDestination_ = this.destinationStore_.selectedDestination; 203 this.selectedDestination_ = this.destinationStore_.selectedDestination;
204 204
205 this.inFlightRequestId_++; 205 this.inFlightRequestId_++;
206 this.nativeLayer_.startGetPreview( 206 this.nativeLayer_.startGetPreview(
207 this.destinationStore_.selectedDestination, 207 this.destinationStore_.selectedDestination, this.printTicketStore_,
208 this.printTicketStore_, 208 this.documentInfo_, this.inFlightRequestId_);
209 this.documentInfo_,
210 this.inFlightRequestId_);
211 return true; 209 return true;
212 }, 210 },
213 211
214 /** Removes all event listeners that the preview generator has attached. */ 212 /** Removes all event listeners that the preview generator has attached. */
215 removeEventListeners: function() { 213 removeEventListeners: function() {
216 this.tracker_.removeAll(); 214 this.tracker_.removeAll();
217 }, 215 },
218 216
219 /** 217 /**
220 * Adds event listeners to the relevant native layer events. 218 * Adds event listeners to the relevant native layer events.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 }, 261 },
264 262
265 /** 263 /**
266 * Dispatches a PREVIEW_START event. Signals that the preview should be 264 * Dispatches a PREVIEW_START event. Signals that the preview should be
267 * reloaded. 265 * reloaded.
268 * @param {number} previewUid Unique identifier of the preview. 266 * @param {number} previewUid Unique identifier of the preview.
269 * @param {number} index Index of the first page of the preview. 267 * @param {number} index Index of the first page of the preview.
270 * @private 268 * @private
271 */ 269 */
272 dispatchPreviewStartEvent_: function(previewUid, index) { 270 dispatchPreviewStartEvent_: function(previewUid, index) {
273 var previewStartEvent = new Event( 271 var previewStartEvent =
274 PreviewGenerator.EventType.PREVIEW_START); 272 new Event(PreviewGenerator.EventType.PREVIEW_START);
275 if (!this.documentInfo_.isModifiable) { 273 if (!this.documentInfo_.isModifiable) {
276 index = -1; 274 index = -1;
277 } 275 }
278 previewStartEvent.previewUrl = 'chrome://print/' + 276 previewStartEvent.previewUrl = 'chrome://print/' + previewUid.toString() +
279 previewUid.toString() + '/' + index + '/print.pdf'; 277 '/' + index + '/print.pdf';
280 this.dispatchEvent(previewStartEvent); 278 this.dispatchEvent(previewStartEvent);
281 }, 279 },
282 280
283 /** 281 /**
284 * @return {boolean} Whether the print ticket has changed sufficiently to 282 * @return {boolean} Whether the print ticket has changed sufficiently to
285 * determine whether a new preview request should be issued. 283 * determine whether a new preview request should be issued.
286 * @private 284 * @private
287 */ 285 */
288 hasPreviewChanged_: function() { 286 hasPreviewChanged_: function() {
289 var ticketStore = this.printTicketStore_; 287 var ticketStore = this.printTicketStore_;
290 return this.inFlightRequestId_ == -1 || 288 return this.inFlightRequestId_ == -1 ||
291 !ticketStore.mediaSize.isValueEqual(this.mediaSize_) || 289 !ticketStore.mediaSize.isValueEqual(this.mediaSize_) ||
292 !ticketStore.landscape.isValueEqual(this.isLandscapeEnabled_) || 290 !ticketStore.landscape.isValueEqual(this.isLandscapeEnabled_) ||
293 !ticketStore.headerFooter.isValueEqual(this.isHeaderFooterEnabled_) || 291 !ticketStore.headerFooter.isValueEqual(this.isHeaderFooterEnabled_) ||
294 !ticketStore.color.isValueEqual(this.colorValue_) || 292 !ticketStore.color.isValueEqual(this.colorValue_) ||
295 !ticketStore.rasterize.isValueEqual(this.rasterizeValue_) || 293 !ticketStore.rasterize.isValueEqual(this.rasterizeValue_) ||
296 !ticketStore.scaling.isValueEqual(this.scalingValue_) || 294 !ticketStore.scaling.isValueEqual(this.scalingValue_) ||
297 !ticketStore.fitToPage.isValueEqual(this.isFitToPageEnabled_) || 295 !ticketStore.fitToPage.isValueEqual(this.isFitToPageEnabled_) ||
298 this.pageRanges_ == null || 296 this.pageRanges_ == null ||
299 !areRangesEqual(ticketStore.pageRange.getPageRanges(), 297 !areRangesEqual(
300 this.pageRanges_) || 298 ticketStore.pageRange.getPageRanges(), this.pageRanges_) ||
301 (!ticketStore.marginsType.isValueEqual(this.marginsType_) && 299 (!ticketStore.marginsType.isValueEqual(this.marginsType_) &&
302 !ticketStore.marginsType.isValueEqual( 300 !ticketStore.marginsType.isValueEqual(
303 print_preview.ticket_items.MarginsType.Value.CUSTOM)) || 301 print_preview.ticket_items.MarginsType.Value.CUSTOM)) ||
304 (ticketStore.marginsType.isValueEqual( 302 (ticketStore.marginsType.isValueEqual(
305 print_preview.ticket_items.MarginsType.Value.CUSTOM) && 303 print_preview.ticket_items.MarginsType.Value.CUSTOM) &&
306 !ticketStore.customMargins.isValueEqual( 304 !ticketStore.customMargins.isValueEqual(
307 this.documentInfo_.margins)) || 305 this.documentInfo_.margins)) ||
308 !ticketStore.cssBackground.isValueEqual( 306 !ticketStore.cssBackground.isValueEqual(
309 this.isCssBackgroundEnabled_) || 307 this.isCssBackgroundEnabled_) ||
310 !ticketStore.selectionOnly.isValueEqual( 308 !ticketStore.selectionOnly.isValueEqual(
311 this.isSelectionOnlyEnabled_) || 309 this.isSelectionOnlyEnabled_) ||
312 (this.selectedDestination_ != 310 (this.selectedDestination_ !=
313 this.destinationStore_.selectedDestination); 311 this.destinationStore_.selectedDestination);
314 }, 312 },
315 313
316 /** 314 /**
317 * Called when the page layout of the document is ready. Always occurs 315 * Called when the page layout of the document is ready. Always occurs
318 * as a result of a preview request. 316 * as a result of a preview request.
319 * @param {Event} event Contains layout info about the document. 317 * @param {Event} event Contains layout info about the document.
320 * @private 318 * @private
321 */ 319 */
322 onPageLayoutReady_: function(event) { 320 onPageLayoutReady_: function(event) {
323 // NOTE: A request ID is not specified, so assuming its for the current 321 // NOTE: A request ID is not specified, so assuming its for the current
324 // in-flight request. 322 // in-flight request.
325 323
326 var origin = new print_preview.Coordinate2d( 324 var origin = new print_preview.Coordinate2d(
327 event.pageLayout.printableAreaX, 325 event.pageLayout.printableAreaX, event.pageLayout.printableAreaY);
328 event.pageLayout.printableAreaY);
329 var size = new print_preview.Size( 326 var size = new print_preview.Size(
330 event.pageLayout.printableAreaWidth, 327 event.pageLayout.printableAreaWidth,
331 event.pageLayout.printableAreaHeight); 328 event.pageLayout.printableAreaHeight);
332 329
333 var margins = new print_preview.Margins( 330 var margins = new print_preview.Margins(
334 Math.round(event.pageLayout.marginTop), 331 Math.round(event.pageLayout.marginTop),
335 Math.round(event.pageLayout.marginRight), 332 Math.round(event.pageLayout.marginRight),
336 Math.round(event.pageLayout.marginBottom), 333 Math.round(event.pageLayout.marginBottom),
337 Math.round(event.pageLayout.marginLeft)); 334 Math.round(event.pageLayout.marginLeft));
338 335
339 var o = print_preview.ticket_items.CustomMargins.Orientation; 336 var o = print_preview.ticket_items.CustomMargins.Orientation;
340 var pageSize = new print_preview.Size( 337 var pageSize = new print_preview.Size(
341 event.pageLayout.contentWidth + 338 event.pageLayout.contentWidth + margins.get(o.LEFT) +
342 margins.get(o.LEFT) + margins.get(o.RIGHT), 339 margins.get(o.RIGHT),
343 event.pageLayout.contentHeight + 340 event.pageLayout.contentHeight + margins.get(o.TOP) +
344 margins.get(o.TOP) + margins.get(o.BOTTOM)); 341 margins.get(o.BOTTOM));
345 342
346 this.documentInfo_.updatePageInfo( 343 this.documentInfo_.updatePageInfo(
347 new print_preview.PrintableArea(origin, size), 344 new print_preview.PrintableArea(origin, size), pageSize,
348 pageSize, 345 event.hasCustomPageSizeStyle, margins);
349 event.hasCustomPageSizeStyle,
350 margins);
351 }, 346 },
352 347
353 /** 348 /**
354 * Called when the document page count is received from the native layer. 349 * Called when the document page count is received from the native layer.
355 * Always occurs as a result of a preview request. 350 * Always occurs as a result of a preview request.
356 * @param {Event} event Contains the document's page count. 351 * @param {Event} event Contains the document's page count.
357 * @private 352 * @private
358 */ 353 */
359 onPageCountReady_: function(event) { 354 onPageCountReady_: function(event) {
360 if (this.inFlightRequestId_ != event.previewResponseId) { 355 if (this.inFlightRequestId_ != event.previewResponseId) {
361 return; // Ignore old response. 356 return; // Ignore old response.
362 } 357 }
363 this.documentInfo_.updatePageCount(event.pageCount); 358 this.documentInfo_.updatePageCount(event.pageCount);
364 this.pageRanges_ = this.printTicketStore_.pageRange.getPageRanges(); 359 this.pageRanges_ = this.printTicketStore_.pageRange.getPageRanges();
365 }, 360 },
366 361
367 /** 362 /**
368 * Called when a page's preview has been generated. Dispatches a 363 * Called when a page's preview has been generated. Dispatches a
369 * PAGE_READY event. 364 * PAGE_READY event.
370 * @param {Event} event Contains the page index and preview UID. 365 * @param {Event} event Contains the page index and preview UID.
371 * @private 366 * @private
372 */ 367 */
373 onPagePreviewReady_: function(event) { 368 onPagePreviewReady_: function(event) {
374 if (this.inFlightRequestId_ != event.previewResponseId) { 369 if (this.inFlightRequestId_ != event.previewResponseId) {
375 return; // Ignore old response. 370 return; // Ignore old response.
376 } 371 }
377 var pageNumber = event.pageIndex + 1; 372 var pageNumber = event.pageIndex + 1;
378 var pageNumberSet = this.printTicketStore_.pageRange.getPageNumberSet(); 373 var pageNumberSet = this.printTicketStore_.pageRange.getPageNumberSet();
379 if (pageNumberSet.hasPageNumber(pageNumber)) { 374 if (pageNumberSet.hasPageNumber(pageNumber)) {
380 var previewIndex = pageNumberSet.getPageNumberIndex(pageNumber); 375 var previewIndex = pageNumberSet.getPageNumberIndex(pageNumber);
381 if (previewIndex == 0) { 376 if (previewIndex == 0) {
382 this.dispatchPreviewStartEvent_(event.previewUid, event.pageIndex); 377 this.dispatchPreviewStartEvent_(event.previewUid, event.pageIndex);
383 } 378 }
384 this.dispatchPageReadyEvent_( 379 this.dispatchPageReadyEvent_(
385 previewIndex, pageNumber, event.previewUid); 380 previewIndex, pageNumber, event.previewUid);
386 } 381 }
387 }, 382 },
388 383
389 /** 384 /**
390 * Called when the preview generation is complete. Dispatches a 385 * Called when the preview generation is complete. Dispatches a
391 * DOCUMENT_READY event. 386 * DOCUMENT_READY event.
392 * @param {Event} event Contains the preview UID and response ID. 387 * @param {Event} event Contains the preview UID and response ID.
393 * @private 388 * @private
394 */ 389 */
395 onPreviewGenerationDone_: function(event) { 390 onPreviewGenerationDone_: function(event) {
396 if (this.inFlightRequestId_ != event.previewResponseId) { 391 if (this.inFlightRequestId_ != event.previewResponseId) {
397 return; // Ignore old response. 392 return; // Ignore old response.
398 } 393 }
399 // Dispatch a PREVIEW_START event since non-modifiable documents don't 394 // Dispatch a PREVIEW_START event since non-modifiable documents don't
400 // trigger PAGE_READY events. 395 // trigger PAGE_READY events.
401 if (!this.documentInfo_.isModifiable) { 396 if (!this.documentInfo_.isModifiable) {
402 this.dispatchPreviewStartEvent_(event.previewUid, 0); 397 this.dispatchPreviewStartEvent_(event.previewUid, 0);
403 } 398 }
404 cr.dispatchSimpleEvent(this, PreviewGenerator.EventType.DOCUMENT_READY); 399 cr.dispatchSimpleEvent(this, PreviewGenerator.EventType.DOCUMENT_READY);
405 }, 400 },
406 401
407 /** 402 /**
408 * Called when the preview generation fails. 403 * Called when the preview generation fails.
409 * @private 404 * @private
410 */ 405 */
411 onPreviewGenerationFail_: function() { 406 onPreviewGenerationFail_: function() {
412 // NOTE: No request ID is returned from Chromium so its assumed its the 407 // NOTE: No request ID is returned from Chromium so its assumed its the
413 // current one. 408 // current one.
414 cr.dispatchSimpleEvent(this, PreviewGenerator.EventType.FAIL); 409 cr.dispatchSimpleEvent(this, PreviewGenerator.EventType.FAIL);
415 } 410 }
416 }; 411 };
417 412
418 // Export 413 // Export
419 return { 414 return {PreviewGenerator: PreviewGenerator};
420 PreviewGenerator: PreviewGenerator
421 };
422 }); 415 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698