Bug 1222198 - Update pdf.js to version 1.2.68. r=bdahl, r=Mossop

--HG--
extra : rebase_source : 27058d7e12388176763eda7cb3a769f6bf9017b1
This commit is contained in:
Ryan VanderMeulen 2015-11-05 17:22:25 -05:00
parent c4b8c9e1e5
commit dcca1994a7
7 changed files with 306 additions and 93 deletions

View File

@ -1,3 +1,3 @@
This is the pdf.js project output, https://github.com/mozilla/pdf.js
Current extension version is: 1.1.551
Current extension version is: 1.2.68

View File

@ -368,6 +368,12 @@ ChromeActions.prototype = {
}
return true;
},
supportedMouseWheelZoomModifierKeys: function() {
return {
ctrlKey: getIntPref('mousewheel.with_control.action', 3) === 3,
metaKey: getIntPref('mousewheel.with_meta.action', 1) === 3,
};
},
reportTelemetry: function (data) {
var probeInfo = JSON.parse(data);
switch (probeInfo.type) {
@ -772,7 +778,7 @@ RequestListener.prototype.receive = function(event) {
var response;
if (sync) {
response = actions[action].call(this.actions, data);
event.detail.response = response;
event.detail.response = makeContentReadable(response, doc.defaultView);
} else {
if (!event.detail.responseExpected) {
doc.documentElement.removeChild(message);

View File

@ -22,8 +22,8 @@ if (typeof PDFJS === 'undefined') {
(typeof window !== 'undefined' ? window : this).PDFJS = {};
}
PDFJS.version = '1.1.551';
PDFJS.build = '2a5616c';
PDFJS.version = '1.2.68';
PDFJS.build = '8079bdd';
(function pdfjsWrapper() {
// Use strict in our context only - users might not want it
@ -1326,6 +1326,8 @@ function loadJpegStream(id, imageUrl, objs) {
}
var DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536
/**
* The maximum allowed image size in total pixels e.g. width * height. Images
* above this value will not be drawn. Use -1 for no limit.
@ -1520,6 +1522,9 @@ PDFJS.isEvalSupported = (PDFJS.isEvalSupported === undefined ?
* @property {number} length - The PDF file length. It's used for progress
* reports and range requests operations.
* @property {PDFDataRangeTransport} range
* @property {number} rangeChunkSize - Optional parameter to specify
* maximum number of bytes fetched per range request. The default value is
* 2^16 = 65536.
*/
/**
@ -1629,6 +1634,8 @@ PDFJS.getDocument = function getDocument(src,
params[key] = source[key];
}
params.rangeChunkSize = source.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
workerInitializedCapability = createPromiseCapability();
transport = new WorkerTransport(workerInitializedCapability, source.range);
workerInitializedCapability.promise.then(function transportInitialized() {
@ -2526,6 +2533,9 @@ var WorkerTransport = (function WorkerTransportClosure() {
}, this);
messageHandler.on('StartRenderPage', function transportRender(data) {
if (this.destroyed) {
return; // Ignore any pending requests if the worker was terminated.
}
var page = this.pageCache[data.pageIndex];
page.stats.timeEnd('Page Request');
@ -2533,12 +2543,19 @@ var WorkerTransport = (function WorkerTransportClosure() {
}, this);
messageHandler.on('RenderPageChunk', function transportRender(data) {
if (this.destroyed) {
return; // Ignore any pending requests if the worker was terminated.
}
var page = this.pageCache[data.pageIndex];
page._renderPageChunk(data.operatorList, data.intent);
}, this);
messageHandler.on('commonobj', function transportObj(data) {
if (this.destroyed) {
return; // Ignore any pending requests if the worker was terminated.
}
var id = data[0];
var type = data[1];
if (this.commonObjs.hasData(id)) {
@ -2575,6 +2592,10 @@ var WorkerTransport = (function WorkerTransportClosure() {
}, this);
messageHandler.on('obj', function transportObj(data) {
if (this.destroyed) {
return; // Ignore any pending requests if the worker was terminated.
}
var id = data[0];
var pageIndex = data[1];
var type = data[2];
@ -2606,6 +2627,10 @@ var WorkerTransport = (function WorkerTransportClosure() {
}, this);
messageHandler.on('DocProgress', function transportDocProgress(data) {
if (this.destroyed) {
return; // Ignore any pending requests if the worker was terminated.
}
var loadingTask = this.loadingTask;
if (loadingTask.onProgress) {
loadingTask.onProgress({
@ -2616,6 +2641,10 @@ var WorkerTransport = (function WorkerTransportClosure() {
}, this);
messageHandler.on('PageError', function transportError(data) {
if (this.destroyed) {
return; // Ignore any pending requests if the worker was terminated.
}
var page = this.pageCache[data.pageNum - 1];
var intentState = page.intentStates[data.intent];
if (intentState.displayReadyCapability) {
@ -2626,6 +2655,10 @@ var WorkerTransport = (function WorkerTransportClosure() {
}, this);
messageHandler.on('JpegDecode', function(data) {
if (this.destroyed) {
return Promise.reject('Worker was terminated');
}
var imageUrl = data[0];
var components = data[1];
if (components !== 3 && components !== 1) {
@ -2665,7 +2698,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
};
img.src = imageUrl;
});
});
}, this);
},
fetchDocument: function WorkerTransport_fetchDocument(loadingTask, source) {
@ -4521,16 +4554,13 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var x = 0, i;
for (i = 0; i < glyphsLength; ++i) {
var glyph = glyphs[i];
if (glyph === null) {
// word break
x += fontDirection * wordSpacing;
continue;
} else if (isNum(glyph)) {
if (isNum(glyph)) {
x += spacingDir * glyph * fontSize / 1000;
continue;
}
var restoreNeeded = false;
var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
var character = glyph.fontChar;
var accent = glyph.accent;
var scaledX, scaledY, scaledAccentX, scaledAccentY;
@ -4574,7 +4604,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
}
}
var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
var charWidth = width * widthAdvanceScale + spacing * fontDirection;
x += charWidth;
if (restoreNeeded) {
@ -4619,18 +4649,14 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
for (i = 0; i < glyphsLength; ++i) {
glyph = glyphs[i];
if (glyph === null) {
// word break
this.ctx.translate(wordSpacing, 0);
current.x += wordSpacing * textHScale;
continue;
} else if (isNum(glyph)) {
if (isNum(glyph)) {
spacingLength = spacingDir * glyph * fontSize / 1000;
this.ctx.translate(spacingLength, 0);
current.x += spacingLength * textHScale;
continue;
}
var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
var operatorList = font.charProcOperatorList[glyph.operatorListId];
if (!operatorList) {
warn('Type3 character \"' + glyph.operatorListId +
@ -4645,7 +4671,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
this.restore();
var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
width = transformed[0] * fontSize + charSpacing;
width = transformed[0] * fontSize + spacing;
ctx.translate(width, 0);
current.x += width * textHScale;

View File

@ -22,8 +22,8 @@ if (typeof PDFJS === 'undefined') {
(typeof window !== 'undefined' ? window : this).PDFJS = {};
}
PDFJS.version = '1.1.551';
PDFJS.build = '2a5616c';
PDFJS.version = '1.2.68';
PDFJS.build = '8079bdd';
(function pdfjsWrapper() {
// Use strict in our context only - users might not want it
@ -1856,9 +1856,6 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
})();
// The maximum number of bytes fetched per range request
var RANGE_CHUNK_SIZE = 65536;
// TODO(mack): Make use of PDFJS.Util.inherit() when it becomes available
var BasePdfManager = (function BasePdfManagerClosure() {
function BasePdfManager() {
@ -1990,7 +1987,8 @@ var NetworkPdfManager = (function NetworkPdfManagerClosure() {
disableAutoFetch: args.disableAutoFetch,
initialData: args.initialData
};
this.streamManager = new ChunkedStreamManager(args.length, RANGE_CHUNK_SIZE,
this.streamManager = new ChunkedStreamManager(args.length,
args.rangeChunkSize,
args.url, params);
this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
@ -10587,9 +10585,6 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
for (var i = 0, ii = glyphs.length; i < ii; i++) {
var glyph = glyphs[i];
if (glyph === null) {
continue;
}
buildPath(glyph.fontChar);
// If the glyph has an accent we need to build a path for its
@ -11249,10 +11244,6 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var defaultVMetrics = font.defaultVMetrics;
for (var i = 0; i < glyphs.length; i++) {
var glyph = glyphs[i];
if (!glyph) { // Previous glyph was a space.
width += textState.wordSpacing * textState.textHScale;
continue;
}
var vMetricX = null;
var vMetricY = null;
var glyphWidth = null;
@ -11288,11 +11279,14 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
// var x = pt[0];
// var y = pt[1];
var charSpacing = 0;
if (textChunk.str.length > 0) {
// Apply char spacing only when there are chars.
// As a result there is only spacing between glyphs.
charSpacing = textState.charSpacing;
var charSpacing = textState.charSpacing;
if (glyph.isSpace) {
var wordSpacing = textState.wordSpacing;
charSpacing += wordSpacing;
if (wordSpacing > 0) {
addFakeSpaces(wordSpacing * 1000 / textState.fontSize,
textChunk.str);
}
}
var tx = 0;
@ -11326,6 +11320,22 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
return textChunk;
}
function addFakeSpaces(width, strBuf) {
var spaceWidth = textState.font.spaceWidth;
if (spaceWidth <= 0) {
return;
}
var fakeSpaces = width / spaceWidth;
if (fakeSpaces > MULTI_SPACE_FACTOR) {
fakeSpaces = Math.round(fakeSpaces);
while (fakeSpaces--) {
strBuf.push(' ');
}
} else if (fakeSpaces > SPACE_FACTOR) {
strBuf.push(' ');
}
}
var timeSlotManager = new TimeSlotManager();
return new Promise(function next(resolve, reject) {
@ -11404,29 +11414,26 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
// In the default coordinate system, a positive adjustment
// has the effect of moving the next glyph painted either to
// the left or down by the given amount.
var val = items[j] * textState.fontSize / 1000;
var advance = items[j];
var val = advance * textState.fontSize / 1000;
if (textState.font.vertical) {
offset = val * textState.textMatrix[3];
textState.translateTextMatrix(0, offset);
offset = val *
(textState.textHScale * textState.textMatrix[2] +
textState.textMatrix[3]);
textState.translateTextMatrix(0, val);
// Value needs to be added to height to paint down.
textChunk.height += offset;
} else {
offset = val * textState.textHScale *
textState.textMatrix[0];
textState.translateTextMatrix(offset, 0);
offset = val * (
textState.textHScale * textState.textMatrix[0] +
textState.textMatrix[1]);
textState.translateTextMatrix(-val, 0);
// Value needs to be subtracted from width to paint left.
textChunk.width -= offset;
advance = -advance;
}
if (items[j] < 0 && textState.font.spaceWidth > 0) {
var fakeSpaces = -items[j] / textState.font.spaceWidth;
if (fakeSpaces > MULTI_SPACE_FACTOR) {
fakeSpaces = Math.round(fakeSpaces);
while (fakeSpaces--) {
textChunk.str.push(' ');
}
} else if (fakeSpaces > SPACE_FACTOR) {
textChunk.str.push(' ');
}
if (advance > 0) {
addFakeSpaces(advance, textChunk.str);
}
}
}
@ -12157,6 +12164,7 @@ var OperatorList = (function OperatorListClosure() {
this.fnArray = [];
this.argsArray = [];
this.dependencies = {};
this._totalLength = 0;
this.pageIndex = pageIndex;
this.intent = intent;
}
@ -12166,6 +12174,14 @@ var OperatorList = (function OperatorListClosure() {
return this.argsArray.length;
},
/**
* @returns {number} The total length of the entire operator list,
* since `this.length === 0` after flushing.
*/
get totalLength() {
return (this._totalLength + this.length);
},
addOp: function(fn, args) {
this.fnArray.push(fn);
this.argsArray.push(args);
@ -12214,12 +12230,15 @@ var OperatorList = (function OperatorListClosure() {
new QueueOptimizer().optimize(this);
}
var transfers = getTransfers(this);
var length = this.length;
this._totalLength += length;
this.messageHandler.send('RenderPageChunk', {
operatorList: {
fnArray: this.fnArray,
argsArray: this.argsArray,
lastChunk: lastChunk,
length: this.length
length: length
},
pageIndex: this.pageIndex,
intent: this.intent
@ -16095,23 +16114,26 @@ function getFontType(type, subtype) {
}
var Glyph = (function GlyphClosure() {
function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId) {
function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId,
isSpace) {
this.fontChar = fontChar;
this.unicode = unicode;
this.accent = accent;
this.width = width;
this.vmetric = vmetric;
this.operatorListId = operatorListId;
this.isSpace = isSpace;
}
Glyph.prototype.matchesForCache =
function(fontChar, unicode, accent, width, vmetric, operatorListId) {
Glyph.prototype.matchesForCache = function(fontChar, unicode, accent, width,
vmetric, operatorListId, isSpace) {
return this.fontChar === fontChar &&
this.unicode === unicode &&
this.accent === accent &&
this.width === width &&
this.vmetric === vmetric &&
this.operatorListId === operatorListId;
this.operatorListId === operatorListId &&
this.isSpace === isSpace;
};
return Glyph;
@ -18626,7 +18648,7 @@ var Font = (function FontClosure() {
return width;
},
charToGlyph: function Font_charToGlyph(charcode) {
charToGlyph: function Font_charToGlyph(charcode, isSpace) {
var fontCharCode, width, operatorListId;
var widthCode = charcode;
@ -18669,9 +18691,9 @@ var Font = (function FontClosure() {
var glyph = this.glyphCache[charcode];
if (!glyph ||
!glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
operatorListId)) {
operatorListId, isSpace)) {
glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
operatorListId);
operatorListId, isSpace);
this.glyphCache[charcode] = glyph;
}
return glyph;
@ -18707,22 +18729,16 @@ var Font = (function FontClosure() {
charcode = c.charcode;
var length = c.length;
i += length;
glyph = this.charToGlyph(charcode);
// Space is char with code 0x20 and length 1 in multiple-byte codes.
var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
glyph = this.charToGlyph(charcode, isSpace);
glyphs.push(glyph);
// placing null after each word break charcode (ASCII SPACE)
// Ignore occurences of 0x20 in multiple-byte codes.
if (length === 1 && chars.charCodeAt(i - 1) === 0x20) {
glyphs.push(null);
}
}
} else {
for (i = 0, ii = chars.length; i < ii; ++i) {
charcode = chars.charCodeAt(i);
glyph = this.charToGlyph(charcode);
glyph = this.charToGlyph(charcode, charcode === 0x20);
glyphs.push(glyph);
if (charcode === 0x20) {
glyphs.push(null);
}
}
}
@ -33808,7 +33824,7 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
return;
}
source.length = length;
if (length <= 2 * RANGE_CHUNK_SIZE) {
if (length <= 2 * source.rangeChunkSize) {
// The file size is smaller than the size of two chunks, so it does
// not make any sense to abort the request and retry with a range
// request.
@ -34115,7 +34131,7 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
finishWorkerTask(task);
info('page=' + pageNum + ' - getOperatorList: time=' +
(Date.now() - start) + 'ms, len=' + operatorList.fnArray.length);
(Date.now() - start) + 'ms, len=' + operatorList.totalLength);
}, function(e) {
finishWorkerTask(task);
if (task.terminated) {

View File

@ -59,6 +59,22 @@
.textLayer ::selection { background: rgb(0,0,255); }
.textLayer ::-moz-selection { background: rgb(0,0,255); }
.textLayer .endOfContent {
display: block;
position: absolute;
left: 0px;
top: 100%;
right: 0px;
bottom: 0px;
z-index: -1;
cursor: default;
-moz-user-select: none;
}
.textLayer .endOfContent.active {
top: 0px;
}
.annotationLayer .annotLink > a:hover {
opacity: 0.2;
@ -420,9 +436,8 @@ html[dir='rtl'] #toolbarContainer, .findbar, .secondaryToolbar {
}
@keyframes progressIndeterminate {
0% { left: 0%; }
50% { left: 100%; }
100% { left: 100%; }
0% { left: -142px; }
100% { left: 0; }
}
#loadingBar .progress.indeterminate {
@ -430,18 +445,19 @@ html[dir='rtl'] #toolbarContainer, .findbar, .secondaryToolbar {
transition: none;
}
#loadingBar .indeterminate .glimmer {
#loadingBar .progress.indeterminate .glimmer {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 50px;
width: calc(100% + 150px);
background-image: linear-gradient(to right, #999 0%, #fff 50%, #999 100%);
background-size: 100% 100%;
background-repeat: no-repeat;
background: repeating-linear-gradient(135deg,
#bbb 0, #999 5px,
#999 45px, #ddd 55px,
#ddd 95px, #bbb 100px);
animation: progressIndeterminate 2s linear infinite;
animation: progressIndeterminate 950ms linear infinite;
}
.findbar, .secondaryToolbar {
@ -551,6 +567,13 @@ html[dir='ltr'] .doorHangerRight:before {
margin-right: -9px;
}
#findResultsCount {
background-color: hsl(0, 0%, 85%);
color: hsl(0, 0%, 32%);
text-align: center;
padding: 3px 4px;
}
#findMsg {
font-style: italic;
color: #A6B7D0;

View File

@ -88,6 +88,7 @@ See https://github.com/adobe-type-tools/cmap-resources
<label for="findHighlightAll" class="toolbarLabel" data-l10n-id="find_highlight">Highlight all</label>
<input type="checkbox" id="findMatchCase" class="toolbarField" tabindex="95">
<label for="findMatchCase" class="toolbarLabel" data-l10n-id="find_match_case_label">Match case</label>
<span id="findResultsCount" class="toolbarLabel hidden"></span>
<span id="findMsg" class="toolbarLabel"></span>
</div> <!-- findbar -->

View File

@ -31,7 +31,6 @@ var DEFAULT_URL = 'compressed.tracemonkey-pldi-09.pdf';
var DEFAULT_SCALE_DELTA = 1.1;
var MIN_SCALE = 0.25;
var MAX_SCALE = 10.0;
var VIEW_HISTORY_MEMORY = 20;
var SCALE_SELECT_CONTAINER_PADDING = 8;
var SCALE_SELECT_PADDING = 22;
var PAGE_NUMBER_LOADING_INDICATOR = 'visiblePageIsLoading';
@ -266,6 +265,55 @@ function binarySearchFirstItem(items, condition) {
return minIndex; /* === maxIndex */
}
/**
* Approximates float number as a fraction using Farey sequence (max order
* of 8).
* @param {number} x - Positive float number.
* @returns {Array} Estimated fraction: the first array item is a numerator,
* the second one is a denominator.
*/
function approximateFraction(x) {
// Fast paths for int numbers or their inversions.
if (Math.floor(x) === x) {
return [x, 1];
}
var xinv = 1 / x;
var limit = 8;
if (xinv > limit) {
return [1, limit];
} else if (Math.floor(xinv) === xinv) {
return [1, xinv];
}
var x_ = x > 1 ? xinv : x;
// a/b and c/d are neighbours in Farey sequence.
var a = 0, b = 1, c = 1, d = 1;
// Limiting search to order 8.
while (true) {
// Generating next term in sequence (order of q).
var p = a + c, q = b + d;
if (q > limit) {
break;
}
if (x_ <= p / q) {
c = p; d = q;
} else {
a = p; b = q;
}
}
// Select closest of the neighbours to x.
if (x_ - a / b < c / d - x_) {
return x_ === x ? [a, b] : [b, a];
} else {
return x_ === x ? [c, d] : [d, c];
}
}
function roundToDivide(x, div) {
var r = x % div;
return r === 0 ? x : Math.round(x - r + div);
}
/**
* Generic helper to find out what elements are visible within a scroll pane.
*/
@ -733,6 +781,8 @@ Preferences._readFromStorage = function (prefObj) {
var DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20;
/**
* View History - This is a utility for saving various view parameters for
* recently opened files.
@ -743,8 +793,9 @@ Preferences._readFromStorage = function (prefObj) {
* - GENERIC or CHROME - uses localStorage, if it is available.
*/
var ViewHistory = (function ViewHistoryClosure() {
function ViewHistory(fingerprint) {
function ViewHistory(fingerprint, cacheSize) {
this.fingerprint = fingerprint;
this.cacheSize = cacheSize || DEFAULT_VIEW_HISTORY_CACHE_SIZE;
this.isInitializedPromiseResolved = false;
this.initializedPromise =
this._readFromStorage().then(function (databaseStr) {
@ -754,7 +805,7 @@ var ViewHistory = (function ViewHistoryClosure() {
if (!('files' in database)) {
database.files = [];
}
if (database.files.length >= VIEW_HISTORY_MEMORY) {
if (database.files.length >= this.cacheSize) {
database.files.shift();
}
var index;
@ -836,6 +887,7 @@ var PDFFindBar = (function PDFFindBarClosure() {
this.highlightAll = options.highlightAllCheckbox || null;
this.caseSensitive = options.caseSensitiveCheckbox || null;
this.findMsg = options.findMsg || null;
this.findResultsCount = options.findResultsCount || null;
this.findStatusIcon = options.findStatusIcon || null;
this.findPreviousButton = options.findPreviousButton || null;
this.findNextButton = options.findNextButton || null;
@ -898,7 +950,8 @@ var PDFFindBar = (function PDFFindBarClosure() {
return window.dispatchEvent(event);
},
updateUIState: function PDFFindBar_updateUIState(state, previous) {
updateUIState:
function PDFFindBar_updateUIState(state, previous, matchCount) {
var notFound = false;
var findMsg = '';
var status = '';
@ -935,6 +988,26 @@ var PDFFindBar = (function PDFFindBarClosure() {
this.findField.setAttribute('data-status', status);
this.findMsg.textContent = findMsg;
this.updateResultsCount(matchCount);
},
updateResultsCount: function(matchCount) {
if (!this.findResultsCount) {
return; // no UI control is provided
}
// If there are no matches, hide the counter
if (!matchCount) {
this.findResultsCount.classList.add('hidden');
return;
}
// Create the match counter
this.findResultsCount.textContent = matchCount.toLocaleString();
// Show the counter
this.findResultsCount.classList.remove('hidden');
},
open: function PDFFindBar_open() {
@ -991,6 +1064,7 @@ var PDFFindController = (function PDFFindControllerClosure() {
this.active = false; // If active, find results will be highlighted.
this.pageContents = []; // Stores the text for each page.
this.pageMatches = [];
this.matchCount = 0;
this.selected = { // Currently selected match.
pageIdx: -1,
matchIdx: -1
@ -1068,7 +1142,8 @@ var PDFFindController = (function PDFFindControllerClosure() {
var queryLen = query.length;
if (queryLen === 0) {
return; // Do nothing: the matches should be wiped out already.
// Do nothing: the matches should be wiped out already.
return;
}
if (!caseSensitive) {
@ -1091,6 +1166,12 @@ var PDFFindController = (function PDFFindControllerClosure() {
this.resumePageIdx = null;
this.nextPageMatch();
}
// Update the matches count
if (matches.length > 0) {
this.matchCount += matches.length;
this.updateUIResultsCount();
}
},
extractText: function PDFFindController_extractText() {
@ -1182,6 +1263,7 @@ var PDFFindController = (function PDFFindControllerClosure() {
this.hadMatch = false;
this.resumePageIdx = null;
this.pageMatches = [];
this.matchCount = 0;
var self = this;
for (var i = 0; i < numPages; i++) {
@ -1338,6 +1420,15 @@ var PDFFindController = (function PDFFindControllerClosure() {
}
},
updateUIResultsCount:
function PDFFindController_updateUIResultsCount() {
if (this.findBar === null) {
throw new Error('PDFFindController is not initialized with a ' +
'PDFFindBar instance.');
}
this.findBar.updateResultsCount(this.matchCount);
},
updateUIState: function PDFFindController_updateUIState(state, previous) {
if (this.integratedFind) {
FirefoxCom.request('updateFindControlState',
@ -1348,7 +1439,7 @@ var PDFFindController = (function PDFFindControllerClosure() {
throw new Error('PDFFindController is not initialized with a ' +
'PDFFindBar instance.');
}
this.findBar.updateUIState(state, previous);
this.findBar.updateUIState(state, previous, this.matchCount);
}
};
return PDFFindController;
@ -3705,7 +3796,7 @@ var PDFPageView = (function PDFPageViewClosure() {
var outputScale = getOutputScale(ctx);
if (PDFJS.useOnlyCssZoom) {
var actualSizeViewport = viewport.clone({ scale: CSS_UNITS });
var actualSizeViewport = viewport.clone({scale: CSS_UNITS});
// Use a scale that will make the canvas be the original intended size
// of the page.
outputScale.sx *= actualSizeViewport.width / viewport.width;
@ -3726,10 +3817,12 @@ var PDFPageView = (function PDFPageViewClosure() {
}
}
canvas.width = (Math.floor(viewport.width) * outputScale.sx) | 0;
canvas.height = (Math.floor(viewport.height) * outputScale.sy) | 0;
canvas.style.width = Math.floor(viewport.width) + 'px';
canvas.style.height = Math.floor(viewport.height) + 'px';
var sfx = approximateFraction(outputScale.sx);
var sfy = approximateFraction(outputScale.sy);
canvas.width = roundToDivide(viewport.width * outputScale.sx, sfx[0]);
canvas.height = roundToDivide(viewport.height * outputScale.sy, sfy[0]);
canvas.style.width = roundToDivide(viewport.width, sfx[1]) + 'px';
canvas.style.height = roundToDivide(viewport.height, sfy[1]) + 'px';
// Add the viewport so it's known what it was originally drawn with.
canvas._viewport = viewport;
@ -3969,12 +4062,17 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
this.viewport = options.viewport;
this.textDivs = [];
this.findController = options.findController || null;
this._bindMouse();
}
TextLayerBuilder.prototype = {
_finishRendering: function TextLayerBuilder_finishRendering() {
this.renderingDone = true;
var endOfContent = document.createElement('div');
endOfContent.className = 'endOfContent';
this.textLayerDiv.appendChild(endOfContent);
var event = document.createEvent('CustomEvent');
event.initCustomEvent('textlayerrendered', true, true, {
pageNumber: this.pageNumber
@ -4310,7 +4408,30 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
this.matches = this.convertMatches(this.findController === null ?
[] : (this.findController.pageMatches[this.pageIdx] || []));
this.renderMatches(this.matches);
}
},
/**
* Fixes text selection: adds additional div where mouse was clicked.
* This reduces flickering of the content if mouse slowly dragged down/up.
* @private
*/
_bindMouse: function TextLayerBuilder_bindMouse() {
var div = this.textLayerDiv;
div.addEventListener('mousedown', function (e) {
var end = div.querySelector('.endOfContent');
if (!end) {
return;
}
end.classList.add('active');
});
div.addEventListener('mouseup', function (e) {
var end = div.querySelector('.endOfContent');
if (!end) {
return;
}
end.classList.remove('active');
});
},
};
return TextLayerBuilder;
})();
@ -4930,6 +5051,10 @@ var PDFViewer = (function pdfViewer() {
*/
scrollPageIntoView: function PDFViewer_scrollPageIntoView(pageNumber,
dest) {
if (!this.pdfDocument) {
return;
}
var pageView = this._pages[pageNumber - 1];
if (this.isInPresentationMode) {
@ -6111,6 +6236,7 @@ var PDFViewerApplication = {
highlightAllCheckbox: document.getElementById('findHighlightAll'),
caseSensitiveCheckbox: document.getElementById('findMatchCase'),
findMsg: document.getElementById('findMsg'),
findResultsCount: document.getElementById('findResultsCount'),
findStatusIcon: document.getElementById('findStatusIcon'),
findPreviousButton: document.getElementById('findPrevious'),
findNextButton: document.getElementById('findNext'),
@ -6338,6 +6464,16 @@ var PDFViewerApplication = {
return PDFJS.shadow(this, 'loadingBar', bar);
},
get supportedMouseWheelZoomModifierKeys() {
var support = {
ctrlKey: true,
metaKey: true,
};
support = FirefoxCom.requestSync('supportedMouseWheelZoomModifierKeys');
return PDFJS.shadow(this, 'supportedMouseWheelZoomModifierKeys', support);
},
initPassiveLoading: function pdfViewInitPassiveLoading() {
function FirefoxComDataRangeTransport(length, initialData) {
PDFJS.PDFDataRangeTransport.call(this, length, initialData);
@ -7624,6 +7760,11 @@ function handleMouseWheel(evt) {
PDFViewerApplication.scrollPresentationMode(ticks *
MOUSE_WHEEL_DELTA_FACTOR);
} else if (evt.ctrlKey || evt.metaKey) {
var support = PDFViewerApplication.supportedMouseWheelZoomModifierKeys;
if ((evt.ctrlKey && !support.ctrlKey) ||
(evt.metaKey && !support.metaKey)) {
return;
}
// Only zoom the pages, not the entire viewer.
evt.preventDefault();