OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008 Apple Inc. All rights reserved. |
3 * Copyright (C) 2011 Google Inc. All rights reserved. | 3 * Copyright (C) 2011 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * | 8 * |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 | 296 |
297 /** | 297 /** |
298 * @param {boolean=} includeTimeout | 298 * @param {boolean=} includeTimeout |
299 */ | 299 */ |
300 clearAutoComplete: function(includeTimeout) | 300 clearAutoComplete: function(includeTimeout) |
301 { | 301 { |
302 if (includeTimeout && this._completeTimeout) { | 302 if (includeTimeout && this._completeTimeout) { |
303 clearTimeout(this._completeTimeout); | 303 clearTimeout(this._completeTimeout); |
304 delete this._completeTimeout; | 304 delete this._completeTimeout; |
305 } | 305 } |
| 306 delete this._waitingForCompletions; |
306 | 307 |
307 if (!this.autoCompleteElement) | 308 if (!this.autoCompleteElement) |
308 return; | 309 return; |
309 | 310 |
310 if (this.autoCompleteElement.parentNode) | 311 if (this.autoCompleteElement.parentNode) |
311 this.autoCompleteElement.parentNode.removeChild(this.autoCompleteEle
ment); | 312 this.autoCompleteElement.parentNode.removeChild(this.autoCompleteEle
ment); |
312 delete this.autoCompleteElement; | 313 delete this.autoCompleteElement; |
313 | 314 |
314 if (!this._userEnteredRange || !this._userEnteredText) | 315 if (!this._userEnteredRange || !this._userEnteredText) |
315 return; | 316 return; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 var wordSuffixRange = selectionRange.startContainer.rangeOfWord(sele
ctionRange.endOffset, this._completionStopCharacters, this._element, "forward"); | 372 var wordSuffixRange = selectionRange.startContainer.rangeOfWord(sele
ctionRange.endOffset, this._completionStopCharacters, this._element, "forward"); |
372 if (wordSuffixRange.toString().length) | 373 if (wordSuffixRange.toString().length) |
373 shouldExit = true; | 374 shouldExit = true; |
374 } | 375 } |
375 if (shouldExit) { | 376 if (shouldExit) { |
376 this.hideSuggestBox(); | 377 this.hideSuggestBox(); |
377 return; | 378 return; |
378 } | 379 } |
379 | 380 |
380 var wordPrefixRange = selectionRange.startContainer.rangeOfWord(selectio
nRange.startOffset, this._completionStopCharacters, this._element, "backward"); | 381 var wordPrefixRange = selectionRange.startContainer.rangeOfWord(selectio
nRange.startOffset, this._completionStopCharacters, this._element, "backward"); |
| 382 this._waitingForCompletions = true; |
381 this._loadCompletions(this, wordPrefixRange, force, this._completionsRea
dy.bind(this, selection, auto, wordPrefixRange, !!reverse)); | 383 this._loadCompletions(this, wordPrefixRange, force, this._completionsRea
dy.bind(this, selection, auto, wordPrefixRange, !!reverse)); |
382 }, | 384 }, |
383 | 385 |
384 _boxForAnchorAtStart: function(selection, textRange) | 386 _boxForAnchorAtStart: function(selection, textRange) |
385 { | 387 { |
386 var rangeCopy = selection.getRangeAt(0).cloneRange(); | 388 var rangeCopy = selection.getRangeAt(0).cloneRange(); |
387 var anchorElement = document.createElement("span"); | 389 var anchorElement = document.createElement("span"); |
388 anchorElement.textContent = "\u200B"; | 390 anchorElement.textContent = "\u200B"; |
389 textRange.insertNode(anchorElement); | 391 textRange.insertNode(anchorElement); |
390 var box = anchorElement.boxInWindow(window); | 392 var box = anchorElement.boxInWindow(window); |
(...skipping 25 matching lines...) Expand all Loading... |
416 | 418 |
417 /** | 419 /** |
418 * @param {Selection} selection | 420 * @param {Selection} selection |
419 * @param {boolean} auto | 421 * @param {boolean} auto |
420 * @param {Range} originalWordPrefixRange | 422 * @param {Range} originalWordPrefixRange |
421 * @param {boolean} reverse | 423 * @param {boolean} reverse |
422 * @param {Array.<string>=} completions | 424 * @param {Array.<string>=} completions |
423 */ | 425 */ |
424 _completionsReady: function(selection, auto, originalWordPrefixRange, revers
e, completions) | 426 _completionsReady: function(selection, auto, originalWordPrefixRange, revers
e, completions) |
425 { | 427 { |
426 if (!completions || !completions.length) { | 428 if (!this._waitingForCompletions || !completions || !completions.length)
{ |
427 this.hideSuggestBox(); | 429 this.hideSuggestBox(); |
428 return; | 430 return; |
429 } | 431 } |
| 432 delete this._waitingForCompletions; |
430 | 433 |
431 var selectionRange = selection.getRangeAt(0); | 434 var selectionRange = selection.getRangeAt(0); |
432 | 435 |
433 var fullWordRange = document.createRange(); | 436 var fullWordRange = document.createRange(); |
434 fullWordRange.setStart(originalWordPrefixRange.startContainer, originalW
ordPrefixRange.startOffset); | 437 fullWordRange.setStart(originalWordPrefixRange.startContainer, originalW
ordPrefixRange.startOffset); |
435 fullWordRange.setEnd(selectionRange.endContainer, selectionRange.endOffs
et); | 438 fullWordRange.setEnd(selectionRange.endContainer, selectionRange.endOffs
et); |
436 | 439 |
437 if (originalWordPrefixRange.toString() + selectionRange.toString() != fu
llWordRange.toString()) | 440 if (originalWordPrefixRange.toString() + selectionRange.toString() != fu
llWordRange.toString()) |
438 return; | 441 return; |
439 | 442 |
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1254 // Report the event as non-handled if there is no selected item, | 1257 // Report the event as non-handled if there is no selected item, |
1255 // to commit the input or handle it otherwise. | 1258 // to commit the input or handle it otherwise. |
1256 return hasSelectedItem; | 1259 return hasSelectedItem; |
1257 }, | 1260 }, |
1258 | 1261 |
1259 tabKeyPressed: function(event) | 1262 tabKeyPressed: function(event) |
1260 { | 1263 { |
1261 return this.enterKeyPressed(event); | 1264 return this.enterKeyPressed(event); |
1262 } | 1265 } |
1263 } | 1266 } |
OLD | NEW |