NavigatorOverlayController.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * Copyright (C) 2012 Google Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are
  6. * met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above
  12. * copyright notice, this list of conditions and the following disclaimer
  13. * in the documentation and/or other materials provided with the
  14. * distribution.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. AND ITS CONTRIBUTORS
  17. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  18. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  19. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC.
  20. * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  21. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  22. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  26. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. /**
  29. * @constructor
  30. * @param {WebInspector.SidebarView} parentSidebarView
  31. * @param {WebInspector.View} navigatorView
  32. * @param {WebInspector.View} editorView
  33. */
  34. WebInspector.NavigatorOverlayController = function(parentSidebarView, navigatorView, editorView)
  35. {
  36. this._parentSidebarView = parentSidebarView;
  37. this._navigatorView = navigatorView;
  38. this._editorView = editorView;
  39. this._navigatorSidebarResizeWidgetElement = document.createElement("div");
  40. this._navigatorSidebarResizeWidgetElement.addStyleClass("scripts-navigator-resizer-widget");
  41. this._parentSidebarView.installResizer(this._navigatorSidebarResizeWidgetElement);
  42. this._navigatorView.element.appendChild(this._navigatorSidebarResizeWidgetElement);
  43. this._navigatorShowHideButton = new WebInspector.StatusBarButton(WebInspector.UIString("Hide navigator"), "scripts-navigator-show-hide-button", 3);
  44. this._navigatorShowHideButton.state = "pinned";
  45. this._navigatorShowHideButton.addEventListener("click", this._toggleNavigator, this);
  46. this._editorView.element.appendChild(this._navigatorShowHideButton.element);
  47. WebInspector.settings.navigatorHidden = WebInspector.settings.createSetting("navigatorHidden", true);
  48. if (WebInspector.settings.navigatorHidden.get())
  49. this._toggleNavigator();
  50. }
  51. WebInspector.NavigatorOverlayController.prototype = {
  52. wasShown: function()
  53. {
  54. window.setTimeout(this._maybeShowNavigatorOverlay.bind(this), 0);
  55. },
  56. _maybeShowNavigatorOverlay: function()
  57. {
  58. if (WebInspector.settings.navigatorHidden.get() && !WebInspector.settings.navigatorWasOnceHidden.get())
  59. this.showNavigatorOverlay();
  60. },
  61. _toggleNavigator: function()
  62. {
  63. if (this._navigatorShowHideButton.state === "overlay")
  64. this._pinNavigator();
  65. else if (this._navigatorShowHideButton.state === "hidden")
  66. this.showNavigatorOverlay();
  67. else
  68. this._hidePinnedNavigator();
  69. },
  70. _hidePinnedNavigator: function()
  71. {
  72. this._navigatorShowHideButton.state = "hidden";
  73. this._navigatorShowHideButton.title = WebInspector.UIString("Show navigator");
  74. this._parentSidebarView.element.appendChild(this._navigatorShowHideButton.element);
  75. this._editorView.element.addStyleClass("navigator-hidden");
  76. this._navigatorSidebarResizeWidgetElement.addStyleClass("hidden");
  77. this._parentSidebarView.hideSidebarElement();
  78. this._navigatorView.detach();
  79. this._editorView.focus();
  80. WebInspector.settings.navigatorWasOnceHidden.set(true);
  81. WebInspector.settings.navigatorHidden.set(true);
  82. },
  83. _pinNavigator: function()
  84. {
  85. this._navigatorShowHideButton.state = "pinned";
  86. this._navigatorShowHideButton.title = WebInspector.UIString("Hide navigator");
  87. this._editorView.element.removeStyleClass("navigator-hidden");
  88. this._navigatorSidebarResizeWidgetElement.removeStyleClass("hidden");
  89. this._editorView.element.appendChild(this._navigatorShowHideButton.element);
  90. this._innerHideNavigatorOverlay();
  91. this._parentSidebarView.showSidebarElement();
  92. this._navigatorView.show(this._parentSidebarView.sidebarElement);
  93. this._navigatorView.focus();
  94. WebInspector.settings.navigatorHidden.set(false);
  95. },
  96. showNavigatorOverlay: function()
  97. {
  98. if (this._navigatorShowHideButton.state === "overlay")
  99. return;
  100. this._navigatorShowHideButton.state = "overlay";
  101. this._navigatorShowHideButton.title = WebInspector.UIString("Pin navigator");
  102. this._sidebarOverlay = new WebInspector.SidebarOverlay(this._navigatorView, "scriptsPanelNavigatorOverlayWidth", Preferences.minScriptsSidebarWidth);
  103. this._boundKeyDown = this._keyDown.bind(this);
  104. this._sidebarOverlay.element.addEventListener("keydown", this._boundKeyDown, false);
  105. var navigatorOverlayResizeWidgetElement = document.createElement("div");
  106. navigatorOverlayResizeWidgetElement.addStyleClass("scripts-navigator-resizer-widget");
  107. this._sidebarOverlay.resizerWidgetElement = navigatorOverlayResizeWidgetElement;
  108. this._navigatorView.element.appendChild(this._navigatorShowHideButton.element);
  109. this._boundContainingElementFocused = this._containingElementFocused.bind(this);
  110. this._parentSidebarView.element.addEventListener("mousedown", this._boundContainingElementFocused, false);
  111. this._sidebarOverlay.show(this._parentSidebarView.element);
  112. this._navigatorView.focus();
  113. },
  114. _keyDown: function(event)
  115. {
  116. if (event.handled)
  117. return;
  118. if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Esc.code) {
  119. this.hideNavigatorOverlay();
  120. event.consume(true);
  121. }
  122. },
  123. hideNavigatorOverlay: function()
  124. {
  125. if (this._navigatorShowHideButton.state !== "overlay")
  126. return;
  127. this._navigatorShowHideButton.state = "hidden";
  128. this._navigatorShowHideButton.title = WebInspector.UIString("Show navigator");
  129. this._parentSidebarView.element.appendChild(this._navigatorShowHideButton.element);
  130. this._innerHideNavigatorOverlay();
  131. this._editorView.focus();
  132. },
  133. _innerHideNavigatorOverlay: function()
  134. {
  135. this._parentSidebarView.element.removeEventListener("mousedown", this._boundContainingElementFocused, false);
  136. this._sidebarOverlay.element.removeEventListener("keydown", this._boundKeyDown, false);
  137. this._sidebarOverlay.hide();
  138. },
  139. _containingElementFocused: function(event)
  140. {
  141. if (!event.target.isSelfOrDescendant(this._sidebarOverlay.element))
  142. this.hideNavigatorOverlay();
  143. },
  144. isNavigatorPinned: function()
  145. {
  146. return this._navigatorShowHideButton.state === "pinned";
  147. },
  148. isNavigatorHidden: function()
  149. {
  150. return this._navigatorShowHideButton.state === "hidden";
  151. }
  152. }