| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 constructor(canDock) { | 38 constructor(canDock) { |
| 39 super(); | 39 super(); |
| 40 this._canDock = canDock; | 40 this._canDock = canDock; |
| 41 | 41 |
| 42 this._closeButton = new UI.ToolbarButton(Common.UIString('Close'), 'largeico
n-delete'); | 42 this._closeButton = new UI.ToolbarButton(Common.UIString('Close'), 'largeico
n-delete'); |
| 43 this._closeButton.addEventListener( | 43 this._closeButton.addEventListener( |
| 44 UI.ToolbarButton.Events.Click, InspectorFrontendHost.closeWindow.bind(In
spectorFrontendHost)); | 44 UI.ToolbarButton.Events.Click, InspectorFrontendHost.closeWindow.bind(In
spectorFrontendHost)); |
| 45 | 45 |
| 46 if (!canDock) { | 46 if (!canDock) { |
| 47 this._dockSide = Components.DockController.State.Undocked; | 47 this._dockSide = Components.DockController.State.Undocked; |
| 48 this._updateUI(); | 48 this._closeButton.setVisible(false); |
| 49 return; | 49 return; |
| 50 } | 50 } |
| 51 | 51 |
| 52 this._states = [ | 52 this._states = [ |
| 53 Components.DockController.State.DockedToRight, Components.DockController.S
tate.DockedToBottom, | 53 Components.DockController.State.DockedToRight, Components.DockController.S
tate.DockedToBottom, |
| 54 Components.DockController.State.Undocked | 54 Components.DockController.State.DockedToLeft, Components.DockController.St
ate.Undocked |
| 55 ]; | 55 ]; |
| 56 this._currentDockStateSetting = Common.settings.moduleSetting('currentDockSt
ate'); | 56 this._currentDockStateSetting = Common.settings.moduleSetting('currentDockSt
ate'); |
| 57 this._currentDockStateSetting.addChangeListener(this._dockSideChanged, this)
; | 57 this._currentDockStateSetting.addChangeListener(this._dockSideChanged, this)
; |
| 58 this._lastDockStateSetting = Common.settings.createSetting('lastDockState',
'bottom'); | 58 this._lastDockStateSetting = Common.settings.createSetting('lastDockState',
'bottom'); |
| 59 if (this._states.indexOf(this._currentDockStateSetting.get()) === -1) | 59 if (this._states.indexOf(this._currentDockStateSetting.get()) === -1) |
| 60 this._currentDockStateSetting.set('right'); | 60 this._currentDockStateSetting.set('right'); |
| 61 if (this._states.indexOf(this._lastDockStateSetting.get()) === -1) | 61 if (this._states.indexOf(this._lastDockStateSetting.get()) === -1) |
| 62 this._currentDockStateSetting.set('bottom'); | 62 this._currentDockStateSetting.set('bottom'); |
| 63 } | 63 } |
| 64 | 64 |
| 65 initialize() { | 65 initialize() { |
| 66 if (!this._canDock) | 66 if (!this._canDock) |
| 67 return; | 67 return; |
| 68 | 68 |
| 69 this._titles = [ | 69 this._titles = [ |
| 70 Common.UIString('Dock to right'), Common.UIString('Dock to bottom'), | 70 Common.UIString('Dock to right'), Common.UIString('Dock to bottom'), Commo
n.UIString('Dock to left'), |
| 71 Common.UIString('Undock into separate window') | 71 Common.UIString('Undock into separate window') |
| 72 ]; | 72 ]; |
| 73 this._dockSideChanged(); | 73 this._dockSideChanged(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 _dockSideChanged() { | 76 _dockSideChanged() { |
| 77 this.setDockSide(this._currentDockStateSetting.get()); | 77 this.setDockSide(this._currentDockStateSetting.get()); |
| 78 } | 78 } |
| 79 | 79 |
| 80 /** | 80 /** |
| 81 * @return {string} | 81 * @return {string} |
| 82 */ | 82 */ |
| 83 dockSide() { | 83 dockSide() { |
| 84 return this._dockSide; | 84 return this._dockSide; |
| 85 } | 85 } |
| 86 | 86 |
| 87 /** | 87 /** |
| 88 * @return {boolean} | 88 * @return {boolean} |
| 89 */ | 89 */ |
| 90 canDock() { | 90 canDock() { |
| 91 return this._canDock; | 91 return this._canDock; |
| 92 } | 92 } |
| 93 | 93 |
| 94 /** | 94 /** |
| 95 * @return {boolean} | 95 * @return {boolean} |
| 96 */ | 96 */ |
| 97 isVertical() { | 97 isVertical() { |
| 98 return this._dockSide === Components.DockController.State.DockedToRight; | 98 return this._dockSide === Components.DockController.State.DockedToRight || |
| 99 this._dockSide === Components.DockController.State.DockedToLeft; |
| 99 } | 100 } |
| 100 | 101 |
| 101 /** | 102 /** |
| 102 * @param {string} dockSide | 103 * @param {string} dockSide |
| 103 * @suppressGlobalPropertiesCheck | 104 * @suppressGlobalPropertiesCheck |
| 104 */ | 105 */ |
| 105 setDockSide(dockSide) { | 106 setDockSide(dockSide) { |
| 106 if (this._states.indexOf(dockSide) === -1) | 107 if (this._states.indexOf(dockSide) === -1) |
| 107 dockSide = this._states[0]; | 108 dockSide = this._states[0]; |
| 108 | 109 |
| 109 if (this._dockSide === dockSide) | 110 if (this._dockSide === dockSide) |
| 110 return; | 111 return; |
| 111 | 112 |
| 112 if (this._dockSide) | 113 if (this._dockSide) |
| 113 this._lastDockStateSetting.set(this._dockSide); | 114 this._lastDockStateSetting.set(this._dockSide); |
| 114 | 115 |
| 115 this._savedFocus = document.deepActiveElement(); | 116 this._savedFocus = document.deepActiveElement(); |
| 116 var eventData = {from: this._dockSide, to: dockSide}; | 117 var eventData = {from: this._dockSide, to: dockSide}; |
| 117 this.dispatchEventToListeners(Components.DockController.Events.BeforeDockSid
eChanged, eventData); | 118 this.dispatchEventToListeners(Components.DockController.Events.BeforeDockSid
eChanged, eventData); |
| 118 console.timeStamp('DockController.setIsDocked'); | 119 console.timeStamp('DockController.setIsDocked'); |
| 119 this._dockSide = dockSide; | 120 this._dockSide = dockSide; |
| 120 this._currentDockStateSetting.set(dockSide); | 121 this._currentDockStateSetting.set(dockSide); |
| 121 InspectorFrontendHost.setIsDocked( | 122 InspectorFrontendHost.setIsDocked( |
| 122 dockSide !== Components.DockController.State.Undocked, this._setIsDocked
Response.bind(this, eventData)); | 123 dockSide !== Components.DockController.State.Undocked, this._setIsDocked
Response.bind(this, eventData)); |
| 123 this._updateUI(); | 124 this._closeButton.setVisible(this._dockSide !== Components.DockController.St
ate.Undocked); |
| 124 this.dispatchEventToListeners(Components.DockController.Events.DockSideChang
ed, eventData); | 125 this.dispatchEventToListeners(Components.DockController.Events.DockSideChang
ed, eventData); |
| 125 } | 126 } |
| 126 | 127 |
| 127 /** | 128 /** |
| 128 * @param {{from: string, to: string}} eventData | 129 * @param {{from: string, to: string}} eventData |
| 129 */ | 130 */ |
| 130 _setIsDockedResponse(eventData) { | 131 _setIsDockedResponse(eventData) { |
| 131 this.dispatchEventToListeners(Components.DockController.Events.AfterDockSide
Changed, eventData); | 132 this.dispatchEventToListeners(Components.DockController.Events.AfterDockSide
Changed, eventData); |
| 132 if (this._savedFocus) { | 133 if (this._savedFocus) { |
| 133 this._savedFocus.focus(); | 134 this._savedFocus.focus(); |
| 134 this._savedFocus = null; | 135 this._savedFocus = null; |
| 135 } | 136 } |
| 136 } | 137 } |
| 137 | 138 |
| 138 /** | |
| 139 * @suppressGlobalPropertiesCheck | |
| 140 */ | |
| 141 _updateUI() { | |
| 142 var body = document.body; // Only for main window. | |
| 143 switch (this._dockSide) { | |
| 144 case Components.DockController.State.DockedToBottom: | |
| 145 body.classList.remove('undocked'); | |
| 146 body.classList.remove('dock-to-right'); | |
| 147 body.classList.add('dock-to-bottom'); | |
| 148 break; | |
| 149 case Components.DockController.State.DockedToRight: | |
| 150 body.classList.remove('undocked'); | |
| 151 body.classList.add('dock-to-right'); | |
| 152 body.classList.remove('dock-to-bottom'); | |
| 153 break; | |
| 154 case Components.DockController.State.Undocked: | |
| 155 body.classList.add('undocked'); | |
| 156 body.classList.remove('dock-to-right'); | |
| 157 body.classList.remove('dock-to-bottom'); | |
| 158 break; | |
| 159 } | |
| 160 this._closeButton.setVisible(this._dockSide !== Components.DockController.St
ate.Undocked); | |
| 161 } | |
| 162 | |
| 163 _toggleDockSide() { | 139 _toggleDockSide() { |
| 164 if (this._lastDockStateSetting.get() === this._currentDockStateSetting.get()
) { | 140 if (this._lastDockStateSetting.get() === this._currentDockStateSetting.get()
) { |
| 165 var index = this._states.indexOf(this._currentDockStateSetting.get()) || 0
; | 141 var index = this._states.indexOf(this._currentDockStateSetting.get()) || 0
; |
| 166 this._lastDockStateSetting.set(this._states[(index + 1) % this._states.len
gth]); | 142 this._lastDockStateSetting.set(this._states[(index + 1) % this._states.len
gth]); |
| 167 } | 143 } |
| 168 this.setDockSide(this._lastDockStateSetting.get()); | 144 this.setDockSide(this._lastDockStateSetting.get()); |
| 169 } | 145 } |
| 170 }; | 146 }; |
| 171 | 147 |
| 172 Components.DockController.State = { | 148 Components.DockController.State = { |
| 173 DockedToBottom: 'bottom', | 149 DockedToBottom: 'bottom', |
| 174 DockedToRight: 'right', | 150 DockedToRight: 'right', |
| 151 DockedToLeft: 'left', |
| 175 Undocked: 'undocked' | 152 Undocked: 'undocked' |
| 176 }; | 153 }; |
| 177 | 154 |
| 178 // Use BeforeDockSideChanged to do something before all the UI bits are updated, | 155 // Use BeforeDockSideChanged to do something before all the UI bits are updated, |
| 179 // DockSideChanged to update UI, and AfterDockSideChanged to perform actions | 156 // DockSideChanged to update UI, and AfterDockSideChanged to perform actions |
| 180 // after frontend is docked/undocked in the browser. | 157 // after frontend is docked/undocked in the browser. |
| 181 | 158 |
| 182 /** @enum {symbol} */ | 159 /** @enum {symbol} */ |
| 183 Components.DockController.Events = { | 160 Components.DockController.Events = { |
| 184 BeforeDockSideChanged: Symbol('BeforeDockSideChanged'), | 161 BeforeDockSideChanged: Symbol('BeforeDockSideChanged'), |
| (...skipping 29 matching lines...) Expand all Loading... |
| 214 */ | 191 */ |
| 215 item() { | 192 item() { |
| 216 return Components.dockController._closeButton; | 193 return Components.dockController._closeButton; |
| 217 } | 194 } |
| 218 }; | 195 }; |
| 219 | 196 |
| 220 /** | 197 /** |
| 221 * @type {!Components.DockController} | 198 * @type {!Components.DockController} |
| 222 */ | 199 */ |
| 223 Components.dockController; | 200 Components.dockController; |
| OLD | NEW |