1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784
|
// Copyright 2007 The Closure Library Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/**
* @fileoverview Rich text spell checker implementation.
*
* @author eae@google.com (Emil A Eklund)
* @see ../demos/richtextspellchecker.html
*/
goog.provide('goog.ui.RichTextSpellChecker');
goog.require('goog.Timer');
goog.require('goog.asserts');
goog.require('goog.dom');
goog.require('goog.dom.NodeType');
goog.require('goog.dom.Range');
goog.require('goog.events.EventHandler');
goog.require('goog.events.EventType');
goog.require('goog.events.KeyCodes');
goog.require('goog.events.KeyHandler');
goog.require('goog.math.Coordinate');
goog.require('goog.spell.SpellCheck');
goog.require('goog.string.StringBuffer');
goog.require('goog.style');
goog.require('goog.ui.AbstractSpellChecker');
goog.require('goog.ui.Component');
goog.require('goog.ui.PopupMenu');
/**
* Rich text spell checker implementation.
*
* @param {goog.spell.SpellCheck} handler Instance of the SpellCheckHandler
* support object to use. A single instance can be shared by multiple editor
* components.
* @param {goog.dom.DomHelper=} opt_domHelper Optional DOM helper.
* @constructor
* @extends {goog.ui.AbstractSpellChecker}
*/
goog.ui.RichTextSpellChecker = function(handler, opt_domHelper) {
goog.ui.AbstractSpellChecker.call(this, handler, opt_domHelper);
/**
* String buffer for use in reassembly of the original text.
* @type {goog.string.StringBuffer}
* @private
*/
this.workBuffer_ = new goog.string.StringBuffer();
/**
* Bound async function (to avoid rebinding it on every call).
* @type {Function}
* @private
*/
this.boundContinueAsyncFn_ = goog.bind(this.continueAsync_, this);
/**
* Event handler for listening to events without leaking.
* @private {!goog.events.EventHandler}
*/
this.eventHandler_ = new goog.events.EventHandler(this);
this.registerDisposable(this.eventHandler_);
/**
* The object handling keyboard events.
* @private {!goog.events.KeyHandler}
*/
this.keyHandler_ = new goog.events.KeyHandler();
this.registerDisposable(this.keyHandler_);
};
goog.inherits(goog.ui.RichTextSpellChecker, goog.ui.AbstractSpellChecker);
goog.tagUnsealableClass(goog.ui.RichTextSpellChecker);
/**
* Root node for rich editor.
* @type {Node}
* @private
*/
goog.ui.RichTextSpellChecker.prototype.rootNode_;
/**
* Indicates whether the root node for the rich editor is an iframe.
* @private {boolean}
*/
goog.ui.RichTextSpellChecker.prototype.rootNodeIframe_ = false;
/**
* Current node where spell checker has interrupted to go to the next stack
* frame.
* @type {Node}
* @private
*/
goog.ui.RichTextSpellChecker.prototype.currentNode_;
/**
* Counter of inserted elements. Used in processing loop to attempt to preserve
* existing nodes if they contain no misspellings.
* @type {number}
* @private
*/
goog.ui.RichTextSpellChecker.prototype.elementsInserted_ = 0;
/**
* Number of words to scan to precharge the dictionary.
* @type {number}
* @private
*/
goog.ui.RichTextSpellChecker.prototype.dictionaryPreScanSize_ = 1000;
/**
* Class name for word spans.
* @type {string}
*/
goog.ui.RichTextSpellChecker.prototype.wordClassName =
goog.getCssName('goog-spellcheck-word');
/**
* DomHelper to be used for interacting with the editable document/element.
*
* @type {goog.dom.DomHelper|undefined}
* @private
*/
goog.ui.RichTextSpellChecker.prototype.editorDom_;
/**
* Tag name portion of the marker for the text that does not need to be checked
* for spelling.
*
* @type {Array<string|undefined>}
*/
goog.ui.RichTextSpellChecker.prototype.excludeTags;
/**
* CSS Style text for invalid words. As it's set inside the rich edit iframe
* classes defined in the parent document are not available, thus the style is
* set inline.
* @type {string}
*/
goog.ui.RichTextSpellChecker.prototype.invalidWordCssText =
'background: yellow;';
/**
* Creates the initial DOM representation for the component.
*
* @throws {Error} Not supported. Use decorate.
* @see #decorate
* @override
*/
goog.ui.RichTextSpellChecker.prototype.createDom = function() {
throw new Error('Render not supported for goog.ui.RichTextSpellChecker.');
};
/**
* Decorates the element for the UI component.
*
* @param {Element} element Element to decorate.
* @override
*/
goog.ui.RichTextSpellChecker.prototype.decorateInternal = function(element) {
this.setElementInternal(element);
this.rootNodeIframe_ = element.contentDocument || element.contentWindow;
if (this.rootNodeIframe_) {
var doc = element.contentDocument || element.contentWindow.document;
this.rootNode_ = doc.body;
this.editorDom_ = goog.dom.getDomHelper(doc);
} else {
this.rootNode_ = element;
this.editorDom_ = goog.dom.getDomHelper(element);
}
};
/** @override */
goog.ui.RichTextSpellChecker.prototype.enterDocument = function() {
goog.ui.RichTextSpellChecker.superClass_.enterDocument.call(this);
var rootElement = goog.asserts.assertElement(
this.rootNode_,
'The rootNode_ of a richtextspellchecker must be an Element.');
this.keyHandler_.attach(rootElement);
this.initSuggestionsMenu();
};
/** @override */
goog.ui.RichTextSpellChecker.prototype.initSuggestionsMenu = function() {
goog.ui.RichTextSpellChecker.base(this, 'initSuggestionsMenu');
var menu = goog.asserts.assertInstanceof(
this.getMenu(), goog.ui.PopupMenu,
'The menu of a richtextspellchecker must be a PopupMenu.');
this.eventHandler_.listen(
menu, goog.ui.Component.EventType.HIDE, this.onCorrectionHide_);
};
/**
* Checks spelling for all text and displays correction UI.
* @override
*/
goog.ui.RichTextSpellChecker.prototype.check = function() {
this.blockReadyEvents();
this.preChargeDictionary_(this.rootNode_, this.dictionaryPreScanSize_);
this.unblockReadyEvents();
this.eventHandler_.listen(
this.spellCheck, goog.spell.SpellCheck.EventType.READY,
this.onDictionaryCharged_, true);
this.spellCheck.processPending();
};
/**
* Processes nodes recursively.
*
* @param {Node} node Node to start with.
* @param {number} words Max number of words to process.
* @private
*/
goog.ui.RichTextSpellChecker.prototype.preChargeDictionary_ = function(
node, words) {
while (node) {
var next = this.nextNode_(node);
if (this.isExcluded_(node)) {
node = next;
continue;
}
if (node.nodeType == goog.dom.NodeType.TEXT) {
if (node.nodeValue) {
words -= this.populateDictionary(node.nodeValue, words);
if (words <= 0) {
return;
}
}
} else if (node.nodeType == goog.dom.NodeType.ELEMENT) {
if (node.firstChild) {
next = node.firstChild;
}
}
node = next;
}
};
/**
* Starts actual processing after the dictionary is charged.
* @param {goog.events.Event} e goog.spell.SpellCheck.EventType.READY event.
* @private
*/
goog.ui.RichTextSpellChecker.prototype.onDictionaryCharged_ = function(e) {
e.stopPropagation();
this.eventHandler_.unlisten(
this.spellCheck, goog.spell.SpellCheck.EventType.READY,
this.onDictionaryCharged_, true);
// Now actually do the spell checking.
this.clearWordElements();
this.initializeAsyncMode();
this.elementsInserted_ = 0;
var result = this.processNode_(this.rootNode_);
if (result == goog.ui.AbstractSpellChecker.AsyncResult.PENDING) {
goog.Timer.callOnce(this.boundContinueAsyncFn_);
return;
}
this.finishAsyncProcessing();
this.finishCheck_();
};
/**
* Continues asynchrnonous spell checking.
* @private
*/
goog.ui.RichTextSpellChecker.prototype.continueAsync_ = function() {
var result = this.continueAsyncProcessing();
if (result == goog.ui.AbstractSpellChecker.AsyncResult.PENDING) {
goog.Timer.callOnce(this.boundContinueAsyncFn_);
return;
}
result = this.processNode_(this.currentNode_);
if (result == goog.ui.AbstractSpellChecker.AsyncResult.PENDING) {
goog.Timer.callOnce(this.boundContinueAsyncFn_);
return;
}
this.finishAsyncProcessing();
this.finishCheck_();
};
/**
* Finalizes spelling check.
* @private
*/
goog.ui.RichTextSpellChecker.prototype.finishCheck_ = function() {
delete this.currentNode_;
this.spellCheck.processPending();
if (!this.isVisible()) {
this.eventHandler_
.listen(this.rootNode_, goog.events.EventType.CLICK, this.onWordClick_)
.listen(
this.keyHandler_, goog.events.KeyHandler.EventType.KEY,
this.handleRootNodeKeyEvent);
}
goog.ui.RichTextSpellChecker.superClass_.check.call(this);
};
/**
* Finds next node in our enumeration of the tree.
*
* @param {Node} node The node to which we're computing the next node for.
* @return {Node} The next node or null if none was found.
* @private
*/
goog.ui.RichTextSpellChecker.prototype.nextNode_ = function(node) {
while (node != this.rootNode_) {
if (node.nextSibling) {
return node.nextSibling;
}
node = node.parentNode;
}
return null;
};
/**
* Determines if the node is text node without any children.
*
* @param {Node} node The node to check.
* @return {boolean} Whether the node is a text leaf node.
* @private
*/
goog.ui.RichTextSpellChecker.prototype.isTextLeaf_ = function(node) {
return node != null && node.nodeType == goog.dom.NodeType.TEXT &&
!node.firstChild;
};
/** @override */
goog.ui.RichTextSpellChecker.prototype.setExcludeMarker = function(marker) {
if (marker) {
if (typeof marker == 'string') {
marker = [marker];
}
this.excludeTags = [];
this.excludeMarker = [];
for (var i = 0; i < marker.length; i++) {
var parts = marker[i].split('.');
if (parts.length == 2) {
this.excludeTags.push(parts[0]);
this.excludeMarker.push(parts[1]);
} else {
this.excludeMarker.push(parts[0]);
this.excludeTags.push(undefined);
}
}
}
};
/**
* Determines if the node is excluded from checking.
*
* @param {Node} node The node to check.
* @return {boolean} Whether the node is excluded.
* @private
*/
goog.ui.RichTextSpellChecker.prototype.isExcluded_ = function(node) {
if (this.excludeMarker && node.className) {
for (var i = 0; i < this.excludeMarker.length; i++) {
var excludeTag = this.excludeTags[i];
var excludeClass = this.excludeMarker[i];
var isExcluded =
!!(excludeClass && node.className.indexOf(excludeClass) != -1 &&
(!excludeTag || node.tagName == excludeTag));
if (isExcluded) {
return true;
}
}
}
return false;
};
/**
* Processes nodes recursively.
*
* @param {Node} node Node where to start.
* @return {goog.ui.AbstractSpellChecker.AsyncResult|undefined} Result code.
* @private
*/
goog.ui.RichTextSpellChecker.prototype.processNode_ = function(node) {
delete this.currentNode_;
while (node) {
var next = this.nextNode_(node);
if (this.isExcluded_(node)) {
node = next;
continue;
}
if (node.nodeType == goog.dom.NodeType.TEXT) {
var deleteNode = true;
if (node.nodeValue) {
var currentElements = this.elementsInserted_;
var result = this.processTextAsync(node, node.nodeValue);
if (result == goog.ui.AbstractSpellChecker.AsyncResult.PENDING) {
// This marks node for deletion (empty nodes get deleted couple
// of lines down this function). This is so our algorithm terminates.
// In this case the node may be needlessly recreated, but it
// happens rather infrequently and saves a lot of code.
node.nodeValue = '';
this.currentNode_ = node;
return result;
}
// If we did not add nodes in processing, the current element is still
// valid. Let's preserve it!
if (currentElements == this.elementsInserted_) {
deleteNode = false;
}
}
if (deleteNode) {
goog.dom.removeNode(node);
}
} else if (node.nodeType == goog.dom.NodeType.ELEMENT) {
// If this is a spell checker element...
if (node.className == this.wordClassName) {
// First, reconsolidate the text nodes inside the element - editing
// in IE splits them up.
var runner = node.firstChild;
while (runner) {
if (this.isTextLeaf_(runner)) {
while (this.isTextLeaf_(runner.nextSibling)) {
// Yes, this is not super efficient in IE, but it will almost
// never happen.
runner.nodeValue += runner.nextSibling.nodeValue;
goog.dom.removeNode(runner.nextSibling);
}
}
runner = runner.nextSibling;
}
// Move its contents out and reprocess it on the next iteration.
if (node.firstChild) {
next = node.firstChild;
while (node.firstChild) {
node.parentNode.insertBefore(node.firstChild, node);
}
}
// get rid of the empty shell.
goog.dom.removeNode(node);
} else {
if (node.firstChild) {
next = node.firstChild;
}
}
}
node = next;
}
};
/**
* Processes word.
*
* @param {Node} node Node containing word.
* @param {string} word Word to process.
* @param {goog.spell.SpellCheck.WordStatus} status Status of the word.
* @protected
* @override
*/
goog.ui.RichTextSpellChecker.prototype.processWord = function(
node, word, status) {
node.parentNode.insertBefore(this.createWordElement(word, status), node);
this.elementsInserted_++;
};
/**
* Processes recognized text and separators.
*
* @param {Node} node Node containing separator.
* @param {string} text Text to process.
* @protected
* @override
*/
goog.ui.RichTextSpellChecker.prototype.processRange = function(node, text) {
// The text does not change, it only gets split, so if the lengths are the
// same, the text is the same, so keep the existing node.
if (node.nodeType == goog.dom.NodeType.TEXT &&
node.nodeValue.length == text.length) {
return;
}
node.parentNode.insertBefore(this.editorDom_.createTextNode(text), node);
this.elementsInserted_++;
};
/** @override */
goog.ui.RichTextSpellChecker.prototype.getElementByIndex = function(id) {
return this.editorDom_.getElement(this.makeElementId(id));
};
/**
* Updates or replaces element based on word status.
* @see goog.ui.AbstractSpellChecker.prototype.updateElement_
*
* Overridden from AbstractSpellChecker because we need to be mindful of
* deleting the currentNode_ - this can break our pending processing.
*
* @param {Element} el Word element.
* @param {string} word Word to update status for.
* @param {goog.spell.SpellCheck.WordStatus} status Status of word.
* @protected
* @override
*/
goog.ui.RichTextSpellChecker.prototype.updateElement = function(
el, word, status) {
if (status == goog.spell.SpellCheck.WordStatus.VALID &&
el != this.currentNode_ && el.nextSibling != this.currentNode_) {
this.removeMarkup(el);
} else {
goog.dom.setProperties(el, this.getElementProperties(status));
}
};
/**
* Hides correction UI.
* @override
*/
goog.ui.RichTextSpellChecker.prototype.resume = function() {
goog.ui.RichTextSpellChecker.superClass_.resume.call(this);
this.restoreNode_(this.rootNode_);
this.eventHandler_
.unlisten(this.rootNode_, goog.events.EventType.CLICK, this.onWordClick_)
.unlisten(
this.keyHandler_, goog.events.KeyHandler.EventType.KEY,
this.handleRootNodeKeyEvent);
};
/**
* Processes nodes recursively, removes all spell checker markup, and
* consolidates text nodes.
*
* @param {Node} node node on which to recurse.
* @private
*/
goog.ui.RichTextSpellChecker.prototype.restoreNode_ = function(node) {
while (node) {
if (this.isExcluded_(node)) {
node = node.nextSibling;
continue;
}
// Contents of the child of the element is usually 1 text element, but the
// user can actually add multiple nodes in it during editing. So we move
// all the children out, prepend, and reprocess (pointer is set back to
// the first node that's been moved out, and the loop repeats).
if (node.nodeType == goog.dom.NodeType.ELEMENT &&
node.className == this.wordClassName) {
var firstElement = node.firstChild;
var next;
for (var child = firstElement; child; child = next) {
next = child.nextSibling;
node.parentNode.insertBefore(child, node);
}
next = firstElement || node.nextSibling;
goog.dom.removeNode(node);
node = next;
continue;
}
// If this is a chain of text elements, we're trying to consolidate it.
var textLeaf = this.isTextLeaf_(node);
if (textLeaf) {
var textNodes = 1;
var next = node.nextSibling;
while (this.isTextLeaf_(node.previousSibling)) {
node = node.previousSibling;
++textNodes;
}
while (this.isTextLeaf_(next)) {
next = next.nextSibling;
++textNodes;
}
if (textNodes > 1) {
this.workBuffer_.append(node.nodeValue);
while (this.isTextLeaf_(node.nextSibling)) {
this.workBuffer_.append(node.nextSibling.nodeValue);
goog.dom.removeNode(node.nextSibling);
}
node.nodeValue = this.workBuffer_.toString();
this.workBuffer_.clear();
}
}
// Process child nodes, if any.
if (node.firstChild) {
this.restoreNode_(node.firstChild);
}
node = node.nextSibling;
}
};
/**
* Returns desired element properties for the specified status.
*
* @param {goog.spell.SpellCheck.WordStatus} status Status of the word.
* @return {!Object} Properties to apply to word element.
* @protected
* @override
*/
goog.ui.RichTextSpellChecker.prototype.getElementProperties = function(status) {
return {
'class': this.wordClassName,
'style': (status == goog.spell.SpellCheck.WordStatus.INVALID) ?
this.invalidWordCssText :
''
};
};
/**
* Handler for click events.
*
* @param {goog.events.BrowserEvent} event Event object.
* @private
*/
goog.ui.RichTextSpellChecker.prototype.onWordClick_ = function(event) {
var target = /** @type {Element} */ (event.target);
if (event.target.className == this.wordClassName &&
this.spellCheck.checkWord(goog.dom.getTextContent(target)) ==
goog.spell.SpellCheck.WordStatus.INVALID) {
this.showSuggestionsMenu(target, event);
// Prevent document click handler from closing the menu.
event.stopPropagation();
}
};
/** @override */
goog.ui.RichTextSpellChecker.prototype.disposeInternal = function() {
goog.ui.RichTextSpellChecker.superClass_.disposeInternal.call(this);
this.rootNode_ = null;
this.editorDom_ = null;
};
/**
* Returns whether the editor node is an iframe.
*
* @return {boolean} true the editor node is an iframe, otherwise false.
* @protected
*/
goog.ui.RichTextSpellChecker.prototype.isEditorIframe = function() {
return this.rootNodeIframe_;
};
/**
* Handles keyboard events inside the editor to allow keyboard navigation
* between misspelled words and activation of the suggestion menu.
*
* @param {goog.events.BrowserEvent} e the key event.
* @return {boolean} The handled value.
* @protected
*/
goog.ui.RichTextSpellChecker.prototype.handleRootNodeKeyEvent = function(e) {
var handled = false;
switch (e.keyCode) {
case goog.events.KeyCodes.RIGHT:
if (e.ctrlKey) {
handled = this.navigate(goog.ui.AbstractSpellChecker.Direction.NEXT);
}
break;
case goog.events.KeyCodes.LEFT:
if (e.ctrlKey) {
handled =
this.navigate(goog.ui.AbstractSpellChecker.Direction.PREVIOUS);
}
break;
case goog.events.KeyCodes.DOWN:
if (this.getFocusedElementIndex()) {
var el = this.editorDom_.getElement(
this.makeElementId(this.getFocusedElementIndex()));
if (el) {
var position = goog.style.getClientPosition(el);
if (this.isEditorIframe()) {
var iframePosition =
goog.style.getClientPosition(this.getElementStrict());
position = goog.math.Coordinate.sum(iframePosition, position);
}
var size = goog.style.getSize(el);
position.x += size.width / 2;
position.y += size.height / 2;
this.showSuggestionsMenu(el, position);
handled = true;
}
}
break;
}
if (handled) {
e.preventDefault();
}
return handled;
};
/** @override */
goog.ui.RichTextSpellChecker.prototype.onCorrectionAction = function(event) {
goog.ui.RichTextSpellChecker.base(this, 'onCorrectionAction', event);
// In case of editWord base class has already set the focus (on the input),
// otherwise set the focus back on the word.
if (event.target != this.getMenuEdit()) {
this.reFocus_();
}
};
/**
* Restores focus when the suggestion menu is hidden.
*
* @param {goog.events.BrowserEvent} event Blur event.
* @private
*/
goog.ui.RichTextSpellChecker.prototype.onCorrectionHide_ = function(event) {
this.reFocus_();
};
/**
* Sets the focus back on the previously focused word element.
* @private
*/
goog.ui.RichTextSpellChecker.prototype.reFocus_ = function() {
this.getElementStrict().focus();
var el = this.getElementByIndex(this.getFocusedElementIndex());
if (el) {
this.focusOnElement(el);
}
};
/** @override */
goog.ui.RichTextSpellChecker.prototype.focusOnElement = function(element) {
goog.dom.Range.createCaret(element, 0).select();
};
|