OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 | 42 |
43 WebInspector.StatusBarItem.prototype = { | 43 WebInspector.StatusBarItem.prototype = { |
44 /** | 44 /** |
45 * @param {boolean} value | 45 * @param {boolean} value |
46 */ | 46 */ |
47 setEnabled: function(value) | 47 setEnabled: function(value) |
48 { | 48 { |
49 if (this._enabled === value) | 49 if (this._enabled === value) |
50 return; | 50 return; |
51 this._enabled = value; | 51 this._enabled = value; |
52 this.applyEnabledState(); | 52 this._applyEnabledState(); |
53 }, | 53 }, |
54 | 54 |
55 /** | 55 _applyEnabledState: function() |
56 * @protected | |
57 */ | |
58 applyEnabledState: function() | |
59 { | 56 { |
60 this.element.disabled = !this._enabled; | 57 this.element.disabled = !this._enabled; |
61 }, | 58 }, |
62 | 59 |
63 get visible() | 60 /** |
| 61 * @return {boolean} x |
| 62 */ |
| 63 visible: function() |
64 { | 64 { |
65 return this._visible; | 65 return this._visible; |
66 }, | 66 }, |
67 | 67 |
68 set visible(x) | 68 /** |
| 69 * @param {boolean} x |
| 70 */ |
| 71 setVisible: function(x) |
69 { | 72 { |
70 if (this._visible === x) | 73 if (this._visible === x) |
71 return; | 74 return; |
72 this.element.classList.toggle("hidden", !x); | 75 this.element.classList.toggle("hidden", !x); |
73 this._visible = x; | 76 this._visible = x; |
74 }, | 77 }, |
75 | 78 |
76 __proto__: WebInspector.Object.prototype | 79 __proto__: WebInspector.Object.prototype |
77 } | 80 } |
78 | 81 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 */ | 241 */ |
239 WebInspector.StatusBarButtonBase = function(title, className, states) | 242 WebInspector.StatusBarButtonBase = function(title, className, states) |
240 { | 243 { |
241 WebInspector.StatusBarItem.call(this, "button"); | 244 WebInspector.StatusBarItem.call(this, "button"); |
242 this.element.className = className + " status-bar-item"; | 245 this.element.className = className + " status-bar-item"; |
243 this.element.addEventListener("click", this._clicked.bind(this), false); | 246 this.element.addEventListener("click", this._clicked.bind(this), false); |
244 this._longClickController = new WebInspector.LongClickController(this.elemen
t); | 247 this._longClickController = new WebInspector.LongClickController(this.elemen
t); |
245 this._longClickController.addEventListener(WebInspector.LongClickController.
Events.LongClick, this._onLongClick.bind(this)); | 248 this._longClickController.addEventListener(WebInspector.LongClickController.
Events.LongClick, this._onLongClick.bind(this)); |
246 this._longClickController.addEventListener(WebInspector.LongClickController.
Events.LongPress, this._onLongPress.bind(this)); | 249 this._longClickController.addEventListener(WebInspector.LongClickController.
Events.LongPress, this._onLongPress.bind(this)); |
247 | 250 |
248 this.states = states; | 251 this._states = states; |
249 if (!states) | 252 if (!states) |
250 this.states = 2; | 253 this._states = 2; |
251 | 254 |
252 if (states == 2) | 255 if (states == 2) |
253 this._state = false; | 256 this._state = "off"; |
254 else | 257 else |
255 this._state = 0; | 258 this._state = "0"; |
256 | 259 |
257 this.title = title; | 260 this.title = title; |
258 this.className = className; | 261 this.className = className; |
259 } | 262 } |
260 | 263 |
261 WebInspector.StatusBarButtonBase.prototype = { | 264 WebInspector.StatusBarButtonBase.prototype = { |
262 /** | 265 /** |
263 * @param {!WebInspector.Event} event | 266 * @param {!WebInspector.Event} event |
264 */ | 267 */ |
265 _onLongClick: function(event) | 268 _onLongClick: function(event) |
(...skipping 11 matching lines...) Expand all Loading... |
277 | 280 |
278 _clicked: function() | 281 _clicked: function() |
279 { | 282 { |
280 this.dispatchEventToListeners("click"); | 283 this.dispatchEventToListeners("click"); |
281 this._longClickController.reset(); | 284 this._longClickController.reset(); |
282 }, | 285 }, |
283 | 286 |
284 /** | 287 /** |
285 * @override | 288 * @override |
286 */ | 289 */ |
287 applyEnabledState: function() | 290 _applyEnabledState: function() |
288 { | 291 { |
289 this.element.disabled = !this._enabled; | 292 this.element.disabled = !this._enabled; |
290 this._longClickController.reset(); | 293 this._longClickController.reset(); |
291 }, | 294 }, |
292 | 295 |
293 /** | 296 /** |
294 * @return {boolean} | 297 * @return {boolean} |
295 */ | 298 */ |
296 enabled: function() | 299 enabled: function() |
297 { | 300 { |
298 return this._enabled; | 301 return this._enabled; |
299 }, | 302 }, |
300 | 303 |
301 get title() | 304 /** |
302 { | 305 * @param {string} x |
303 return this._title; | 306 */ |
304 }, | 307 setTitle: function(x) |
305 | |
306 set title(x) | |
307 { | 308 { |
308 if (this._title === x) | 309 if (this._title === x) |
309 return; | 310 return; |
310 this._title = x; | 311 this._title = x; |
311 this.element.title = x; | 312 this.element.title = x; |
312 }, | 313 }, |
313 | 314 |
314 get state() | 315 /** |
| 316 * @return {string} |
| 317 */ |
| 318 state: function() |
315 { | 319 { |
316 return this._state; | 320 return this._state; |
317 }, | 321 }, |
318 | 322 |
319 set state(x) | 323 /** |
| 324 * @param {string} x |
| 325 */ |
| 326 setState: function(x) |
320 { | 327 { |
321 if (this._state === x) | 328 if (this._state === x) |
322 return; | 329 return; |
323 | 330 |
324 if (this.states === 2) { | 331 this.element.classList.remove("toggled-" + this._state); |
325 this.element.classList.toggle("toggled-on", x); | 332 this.element.classList.add("toggled-" + x); |
326 } else { | |
327 this.element.classList.remove("toggled-" + this._state); | |
328 if (x !== 0) | |
329 this.element.classList.add("toggled-" + x); | |
330 } | |
331 this._state = x; | 333 this._state = x; |
332 }, | 334 }, |
333 | 335 |
334 get toggled() | 336 /** |
| 337 * @return {boolean} |
| 338 */ |
| 339 toggled: function() |
335 { | 340 { |
336 if (this.states !== 2) | 341 if (this._states !== 2) |
337 throw("Only used toggled when there are 2 states, otherwise, use sta
te"); | 342 throw("Only used toggled when there are 2 states, otherwise, use sta
te"); |
338 return this.state; | 343 return this.state() === "on"; |
339 }, | 344 }, |
340 | 345 |
341 set toggled(x) | 346 /** |
| 347 * @param {boolean} x |
| 348 */ |
| 349 setToggled: function(x) |
342 { | 350 { |
343 if (this.states !== 2) | 351 if (this._states !== 2) |
344 throw("Only used toggled when there are 2 states, otherwise, use sta
te"); | 352 throw("Only used toggled when there are 2 states, otherwise, use sta
te"); |
345 this.state = x; | 353 this.setState(x ? "on" : "off"); |
346 }, | 354 }, |
347 | 355 |
348 makeLongClickEnabled: function() | 356 makeLongClickEnabled: function() |
349 { | 357 { |
350 this._longClickController.enable(); | 358 this._longClickController.enable(); |
351 }, | 359 }, |
352 | 360 |
353 unmakeLongClickEnabled: function() | 361 unmakeLongClickEnabled: function() |
354 { | 362 { |
355 this._longClickController.disable(); | 363 this._longClickController.disable(); |
(...skipping 30 matching lines...) Expand all Loading... |
386 this.removeEventListener("longClickDown", this._longClickOptionsData
.longClickDownListener, this); | 394 this.removeEventListener("longClickDown", this._longClickOptionsData
.longClickDownListener, this); |
387 delete this._longClickOptionsData; | 395 delete this._longClickOptionsData; |
388 | 396 |
389 this.unmakeLongClickEnabled(); | 397 this.unmakeLongClickEnabled(); |
390 } | 398 } |
391 }, | 399 }, |
392 | 400 |
393 _showOptions: function() | 401 _showOptions: function() |
394 { | 402 { |
395 var buttons = this._longClickOptionsData.buttonsProvider(); | 403 var buttons = this._longClickOptionsData.buttonsProvider(); |
396 var mainButtonClone = new WebInspector.StatusBarButton(this.title, this.
className, this.states); | 404 var mainButtonClone = new WebInspector.StatusBarButton(this.title, this.
className, this._states); |
397 mainButtonClone.addEventListener("click", this._clicked, this); | 405 mainButtonClone.addEventListener("click", this._clicked, this); |
398 mainButtonClone.state = this.state; | 406 mainButtonClone.setState(this.state()); |
399 buttons.push(mainButtonClone); | 407 buttons.push(mainButtonClone); |
400 | 408 |
401 var document = this.element.ownerDocument; | 409 var document = this.element.ownerDocument; |
402 document.documentElement.addEventListener("mouseup", mouseUp, false); | 410 document.documentElement.addEventListener("mouseup", mouseUp, false); |
403 | 411 |
404 var optionsGlassPane = new WebInspector.GlassPane(document); | 412 var optionsGlassPane = new WebInspector.GlassPane(document); |
405 var optionsBarElement = optionsGlassPane.element.createChild("div", "alt
ernate-status-bar-buttons-bar"); | 413 var optionsBarElement = optionsGlassPane.element.createChild("div", "alt
ernate-status-bar-buttons-bar"); |
406 const buttonHeight = 23; | 414 const buttonHeight = 23; |
407 | 415 |
408 var hostButtonPosition = this.element.totalOffset(); | 416 var hostButtonPosition = this.element.totalOffset(); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 if (title) | 580 if (title) |
573 option.title = title; | 581 option.title = title; |
574 if (typeof value !== "undefined") | 582 if (typeof value !== "undefined") |
575 option.value = value; | 583 option.value = value; |
576 return option; | 584 return option; |
577 }, | 585 }, |
578 | 586 |
579 /** | 587 /** |
580 * @override | 588 * @override |
581 */ | 589 */ |
582 applyEnabledState: function() | 590 _applyEnabledState: function() |
583 { | 591 { |
584 this._selectElement.disabled = !this._enabled; | 592 this._selectElement.disabled = !this._enabled; |
585 }, | 593 }, |
586 | 594 |
587 /** | 595 /** |
588 * @param {!Element} option | 596 * @param {!Element} option |
589 */ | 597 */ |
590 removeOption: function(option) | 598 removeOption: function(option) |
591 { | 599 { |
592 this._selectElement.removeChild(option); | 600 this._selectElement.removeChild(option); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 { | 683 { |
676 WebInspector.StatusBarButton.call(this, "", className, states.length); | 684 WebInspector.StatusBarButton.call(this, "", className, states.length); |
677 | 685 |
678 var onClickBound = this._onClick.bind(this); | 686 var onClickBound = this._onClick.bind(this); |
679 this.addEventListener("click", onClickBound, this); | 687 this.addEventListener("click", onClickBound, this); |
680 | 688 |
681 this._states = states; | 689 this._states = states; |
682 this._buttons = []; | 690 this._buttons = []; |
683 for (var index = 0; index < states.length; index++) { | 691 for (var index = 0; index < states.length; index++) { |
684 var button = new WebInspector.StatusBarButton(titles[index], className,
states.length); | 692 var button = new WebInspector.StatusBarButton(titles[index], className,
states.length); |
685 button.state = this._states[index]; | 693 button.setState(this._states[index]); |
686 button.addEventListener("click", onClickBound, this); | 694 button.addEventListener("click", onClickBound, this); |
687 this._buttons.push(button); | 695 this._buttons.push(button); |
688 } | 696 } |
689 | 697 |
690 this._currentStateSetting = currentStateSetting; | 698 this._currentStateSetting = currentStateSetting; |
691 this._lastStateSetting = lastStateSetting; | 699 this._lastStateSetting = lastStateSetting; |
692 this._stateChangedCallback = stateChangedCallback; | 700 this._stateChangedCallback = stateChangedCallback; |
693 this.setLongClickOptionsEnabled(this._createOptions.bind(this)); | 701 this.setLongClickOptionsEnabled(this._createOptions.bind(this)); |
694 | 702 |
695 this._currentState = null; | 703 this._currentState = null; |
696 this.toggleState(initialState); | 704 this.toggleState(initialState); |
697 } | 705 } |
698 | 706 |
699 WebInspector.StatusBarStatesSettingButton.prototype = { | 707 WebInspector.StatusBarStatesSettingButton.prototype = { |
700 /** | 708 /** |
701 * @param {!WebInspector.Event} e | 709 * @param {!WebInspector.Event} e |
702 */ | 710 */ |
703 _onClick: function(e) | 711 _onClick: function(e) |
704 { | 712 { |
705 this.toggleState(e.target.state); | 713 this.toggleState(e.target.state()); |
706 }, | 714 }, |
707 | 715 |
708 /** | 716 /** |
709 * @param {string} state | 717 * @param {string} state |
710 */ | 718 */ |
711 toggleState: function(state) | 719 toggleState: function(state) |
712 { | 720 { |
713 if (this._currentState === state) | 721 if (this._currentState === state) |
714 return; | 722 return; |
715 | 723 |
716 if (this._currentState) | 724 if (this._currentState) |
717 this._lastStateSetting.set(this._currentState); | 725 this._lastStateSetting.set(this._currentState); |
718 this._currentState = state; | 726 this._currentState = state; |
719 this._currentStateSetting.set(this._currentState); | 727 this._currentStateSetting.set(this._currentState); |
720 | 728 |
721 if (this._stateChangedCallback) | 729 if (this._stateChangedCallback) |
722 this._stateChangedCallback(state); | 730 this._stateChangedCallback(state); |
723 | 731 |
724 var defaultState = this._defaultState(); | 732 var defaultState = this._defaultState(); |
725 this.state = defaultState; | 733 this.setState(defaultState); |
726 this.title = this._buttons[this._states.indexOf(defaultState)].title; | 734 this.title = this._buttons[this._states.indexOf(defaultState)].title; |
727 }, | 735 }, |
728 | 736 |
729 /** | 737 /** |
730 * @return {string} | 738 * @return {string} |
731 */ | 739 */ |
732 _defaultState: function() | 740 _defaultState: function() |
733 { | 741 { |
734 var lastState = this._lastStateSetting.get(); | 742 var lastState = this._lastStateSetting.get(); |
735 if (lastState && this._states.indexOf(lastState) >= 0 && lastState != th
is._currentState) | 743 if (lastState && this._states.indexOf(lastState) >= 0 && lastState != th
is._currentState) |
736 return lastState; | 744 return lastState; |
737 if (this._states.length > 1 && this._currentState === this._states[0]) | 745 if (this._states.length > 1 && this._currentState === this._states[0]) |
738 return this._states[1]; | 746 return this._states[1]; |
739 return this._states[0]; | 747 return this._states[0]; |
740 }, | 748 }, |
741 | 749 |
742 /** | 750 /** |
743 * @return {!Array.<!WebInspector.StatusBarButton>} | 751 * @return {!Array.<!WebInspector.StatusBarButton>} |
744 */ | 752 */ |
745 _createOptions: function() | 753 _createOptions: function() |
746 { | 754 { |
747 var options = []; | 755 var options = []; |
748 for (var index = 0; index < this._states.length; index++) { | 756 for (var index = 0; index < this._states.length; index++) { |
749 if (this._states[index] !== this.state && this._states[index] !== th
is._currentState) | 757 if (this._states[index] !== this.state() && this._states[index] !==
this._currentState) |
750 options.push(this._buttons[index]); | 758 options.push(this._buttons[index]); |
751 } | 759 } |
752 return options; | 760 return options; |
753 }, | 761 }, |
754 | 762 |
755 __proto__: WebInspector.StatusBarButton.prototype | 763 __proto__: WebInspector.StatusBarButton.prototype |
756 } | 764 } |
OLD | NEW |