abstracttabhandler.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright 2008 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview Abstract Editor plugin class to handle tab keys. Has one
  16. * abstract method which should be overriden to handle a tab key press.
  17. *
  18. * @author robbyw@google.com (Robby Walker)
  19. */
  20. goog.provide('goog.editor.plugins.AbstractTabHandler');
  21. goog.require('goog.editor.Plugin');
  22. goog.require('goog.events.KeyCodes');
  23. goog.require('goog.userAgent');
  24. /**
  25. * Plugin to handle tab keys. Specific tab behavior defined by subclasses.
  26. *
  27. * @constructor
  28. * @extends {goog.editor.Plugin}
  29. */
  30. goog.editor.plugins.AbstractTabHandler = function() {
  31. goog.editor.Plugin.call(this);
  32. };
  33. goog.inherits(goog.editor.plugins.AbstractTabHandler, goog.editor.Plugin);
  34. /** @override */
  35. goog.editor.plugins.AbstractTabHandler.prototype.getTrogClassId =
  36. goog.abstractMethod;
  37. /** @override */
  38. goog.editor.plugins.AbstractTabHandler.prototype.handleKeyboardShortcut =
  39. function(e, key, isModifierPressed) {
  40. // If a dialog doesn't have selectable field, Moz grabs the event and
  41. // performs actions in editor window. This solves that problem and allows
  42. // the event to be passed on to proper handlers.
  43. if (goog.userAgent.GECKO && this.getFieldObject().inModalMode()) {
  44. return false;
  45. }
  46. // Don't handle Ctrl+Tab since the user is most likely trying to switch
  47. // browser tabs. See bug 1305086.
  48. // FF3 on Mac sends Ctrl-Tab to trogedit and we end up inserting a tab, but
  49. // then it also switches the tabs. See bug 1511681. Note that we don't use
  50. // isModifierPressed here since isModifierPressed is true only if metaKey
  51. // is true on Mac.
  52. if (e.keyCode == goog.events.KeyCodes.TAB && !e.metaKey && !e.ctrlKey) {
  53. return this.handleTabKey(e);
  54. }
  55. return false;
  56. };
  57. /**
  58. * Handle a tab key press.
  59. * @param {goog.events.Event} e The key event.
  60. * @return {boolean} Whether this event was handled by this plugin.
  61. * @protected
  62. */
  63. goog.editor.plugins.AbstractTabHandler.prototype.handleTabKey =
  64. goog.abstractMethod;