NavigatorOverlayController.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 = this._navigatorView.element.createChild("div", "resizer-widget");
  40. this._parentSidebarView.installResizer(this._navigatorSidebarResizeWidgetElement);
  41. this._navigatorShowHideButton = new WebInspector.StatusBarButton(WebInspector.UIString("Hide navigator"), "left-sidebar-show-hide-button scripts-navigator-show-hide-button", 3);
  42. this._navigatorShowHideButton.state = "left";
  43. this._navigatorShowHideButton.addEventListener("click", this._toggleNavigator, this);
  44. this._editorView.element.appendChild(this._navigatorShowHideButton.element);
  45. WebInspector.settings.navigatorHidden = WebInspector.settings.createSetting("navigatorHidden", true);
  46. if (WebInspector.settings.navigatorHidden.get())
  47. this._toggleNavigator();
  48. }
  49. WebInspector.NavigatorOverlayController.prototype = {
  50. wasShown: function()
  51. {
  52. window.setTimeout(this._maybeShowNavigatorOverlay.bind(this), 0);
  53. },
  54. _maybeShowNavigatorOverlay: function()
  55. {
  56. if (WebInspector.settings.navigatorHidden.get() && !WebInspector.settings.navigatorWasOnceHidden.get())
  57. this.showNavigatorOverlay();
  58. },
  59. _toggleNavigator: function()
  60. {
  61. if (this._navigatorShowHideButton.state === "overlay")
  62. this._pinNavigator();
  63. else if (this._navigatorShowHideButton.state === "right")
  64. this.showNavigatorOverlay();
  65. else
  66. this._hidePinnedNavigator();
  67. },
  68. _hidePinnedNavigator: function()
  69. {
  70. this._navigatorShowHideButton.state = "right";
  71. this._navigatorShowHideButton.title = WebInspector.UIString("Show navigator");
  72. this._parentSidebarView.element.appendChild(this._navigatorShowHideButton.element);
  73. this._editorView.element.addStyleClass("navigator-hidden");
  74. this._navigatorSidebarResizeWidgetElement.addStyleClass("hidden");
  75. this._parentSidebarView.hideSidebarElement();
  76. this._navigatorView.detach();
  77. this._editorView.focus();
  78. WebInspector.settings.navigatorWasOnceHidden.set(true);
  79. WebInspector.settings.navigatorHidden.set(true);
  80. },
  81. _pinNavigator: function()
  82. {
  83. this._navigatorShowHideButton.state = "left";
  84. this._navigatorShowHideButton.title = WebInspector.UIString("Hide navigator");
  85. this._editorView.element.removeStyleClass("navigator-hidden");
  86. this._navigatorSidebarResizeWidgetElement.removeStyleClass("hidden");
  87. this._editorView.element.appendChild(this._navigatorShowHideButton.element);
  88. this._innerHideNavigatorOverlay();
  89. this._parentSidebarView.showSidebarElement();
  90. this._navigatorView.show(this._parentSidebarView.sidebarElement);
  91. this._navigatorView.focus();
  92. WebInspector.settings.navigatorHidden.set(false);
  93. },
  94. showNavigatorOverlay: function()
  95. {
  96. if (this._navigatorShowHideButton.state === "overlay")
  97. return;
  98. this._navigatorShowHideButton.state = "overlay";
  99. this._navigatorShowHideButton.title = WebInspector.UIString("Pin navigator");
  100. this._sidebarOverlay = new WebInspector.SidebarOverlay(this._navigatorView, "scriptsPanelNavigatorOverlayWidth", Preferences.minScriptsSidebarWidth);
  101. this._boundKeyDown = this._keyDown.bind(this);
  102. this._sidebarOverlay.element.addEventListener("keydown", this._boundKeyDown, false);
  103. var navigatorOverlayResizeWidgetElement = document.createElement("div");
  104. navigatorOverlayResizeWidgetElement.addStyleClass("resizer-widget");
  105. this._sidebarOverlay.resizerWidgetElement = navigatorOverlayResizeWidgetElement;
  106. this._navigatorView.element.appendChild(this._navigatorShowHideButton.element);
  107. this._boundContainingElementFocused = this._containingElementFocused.bind(this);
  108. this._parentSidebarView.element.addEventListener("mousedown", this._boundContainingElementFocused, false);
  109. this._sidebarOverlay.show(this._parentSidebarView.element);
  110. this._navigatorView.focus();
  111. },
  112. _keyDown: function(event)
  113. {
  114. if (event.handled)
  115. return;
  116. if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Esc.code) {
  117. this.hideNavigatorOverlay();
  118. event.consume(true);
  119. }
  120. },
  121. hideNavigatorOverlay: function()
  122. {
  123. if (this._navigatorShowHideButton.state !== "overlay")
  124. return;
  125. this._navigatorShowHideButton.state = "right";
  126. this._navigatorShowHideButton.title = WebInspector.UIString("Show navigator");
  127. this._parentSidebarView.element.appendChild(this._navigatorShowHideButton.element);
  128. this._innerHideNavigatorOverlay();
  129. this._editorView.focus();
  130. },
  131. _innerHideNavigatorOverlay: function()
  132. {
  133. this._parentSidebarView.element.removeEventListener("mousedown", this._boundContainingElementFocused, false);
  134. this._sidebarOverlay.element.removeEventListener("keydown", this._boundKeyDown, false);
  135. this._sidebarOverlay.hide();
  136. },
  137. _containingElementFocused: function(event)
  138. {
  139. if (!event.target.isSelfOrDescendant(this._sidebarOverlay.element))
  140. this.hideNavigatorOverlay();
  141. },
  142. isNavigatorPinned: function()
  143. {
  144. return this._navigatorShowHideButton.state === "left";
  145. },
  146. isNavigatorHidden: function()
  147. {
  148. return this._navigatorShowHideButton.state === "right";
  149. }
  150. }