Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /** | 1 /** |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 760 | 760 |
| 761 // Block swipe gesture. | 761 // Block swipe gesture. |
| 762 e.consume(true); | 762 e.consume(true); |
| 763 }, | 763 }, |
| 764 | 764 |
| 765 /** | 765 /** |
| 766 * @param {!Event} e | 766 * @param {!Event} e |
| 767 */ | 767 */ |
| 768 _onKeyDown: function(e) | 768 _onKeyDown: function(e) |
| 769 { | 769 { |
| 770 if (e.altKey || e.ctrlKey || e.metaKey) | 770 this._handleZoomPanKeys(e); |
| 771 this._handleSelectionNavigation(e); | |
| 772 }, | |
| 773 | |
| 774 /** | |
| 775 * @param {!Event} e | |
| 776 */ | |
| 777 _handleSelectionNavigation: function(e) | |
| 778 { | |
| 779 if (!WebInspector.KeyboardShortcut.hasNoModifiers(e)) | |
| 780 return; | |
| 781 if (this._selectedEntryIndex === -1) | |
| 782 return; | |
| 783 var timelineData = this._timelineData(); | |
| 784 if (!timelineData) | |
| 785 return; | |
| 786 | |
| 787 /** | |
| 788 * @param {number} time | |
| 789 * @param {number} entryIndex | |
| 790 * @return {number} | |
| 791 */ | |
| 792 function timeComparator(time, entryIndex) | |
| 793 { | |
| 794 return time - timelineData.entryStartTimes[entryIndex]; | |
| 795 } | |
| 796 | |
| 797 /** | |
| 798 * @param {number} entry1 | |
| 799 * @param {number} entry2 | |
| 800 * @return {boolean} | |
| 801 */ | |
| 802 function entriesIntersect(entry1, entry2) | |
| 803 { | |
| 804 var start1 = timelineData.entryStartTimes[entry1]; | |
| 805 var start2 = timelineData.entryStartTimes[entry2]; | |
| 806 var end1 = start1 + timelineData.entryTotalTimes[entry1]; | |
| 807 var end2 = start2 + timelineData.entryTotalTimes[entry2]; | |
| 808 return start1 < end2 && start2 < end1; | |
| 809 } | |
| 810 | |
| 811 var keys = WebInspector.KeyboardShortcut.Keys; | |
| 812 if (e.keyCode === keys.Left.code || e.keyCode === keys.Right.code) { | |
| 813 var level = timelineData.entryLevels[this._selectedEntryIndex]; | |
| 814 var levelIndexes = this._timelineLevels[level]; | |
| 815 var indexOnLevel = levelIndexes.lowerBound(this._selectedEntryIndex) ; | |
| 816 indexOnLevel += e.keyCode === keys.Left.code ? -1 : 1; | |
| 817 e.consume(true); | |
| 818 if (indexOnLevel < 0 || indexOnLevel >= levelIndexes.length) | |
| 819 return; | |
| 820 this.dispatchEventToListeners(WebInspector.FlameChart.Events.EntrySe lected, levelIndexes[indexOnLevel]); | |
|
caseq
2015/05/22 01:14:03
nit: return here...
alph
2015/05/22 01:20:51
Done.
| |
| 821 } else if (e.keyCode === keys.Up.code || e.keyCode === keys.Down.code) { | |
|
caseq
2015/05/22 01:14:03
... and then remove else here. (I think this is mo
| |
| 822 var level = timelineData.entryLevels[this._selectedEntryIndex]; | |
| 823 var delta = e.keyCode === keys.Up.code ? 1 : -1; | |
| 824 e.consume(true); | |
| 825 if (this._isTopDown) | |
| 826 delta = -delta; | |
| 827 level += delta; | |
| 828 if (level < 0 || level >= this._timelineLevels.length) | |
| 829 return; | |
| 830 var entryTime = timelineData.entryStartTimes[this._selectedEntryInde x] + timelineData.entryTotalTimes[this._selectedEntryIndex] / 2; | |
| 831 var levelIndexes = this._timelineLevels[level]; | |
| 832 var indexOnLevel = levelIndexes.upperBound(entryTime, timeComparator ) - 1; | |
| 833 if (!entriesIntersect(this._selectedEntryIndex, levelIndexes[indexOn Level])) { | |
| 834 ++indexOnLevel; | |
| 835 if (indexOnLevel >= levelIndexes.length || !entriesIntersect(thi s._selectedEntryIndex, levelIndexes[indexOnLevel])) | |
| 836 return; | |
| 837 } | |
| 838 this.dispatchEventToListeners(WebInspector.FlameChart.Events.EntrySe lected, levelIndexes[indexOnLevel]); | |
| 839 } | |
| 840 }, | |
| 841 | |
| 842 /** | |
| 843 * @param {!Event} e | |
| 844 */ | |
| 845 _handleZoomPanKeys: function(e) | |
| 846 { | |
| 847 if (!WebInspector.KeyboardShortcut.hasNoModifiers(e)) | |
| 771 return; | 848 return; |
| 772 var zoomMultiplier = e.shiftKey ? 0.8 : 0.3; | 849 var zoomMultiplier = e.shiftKey ? 0.8 : 0.3; |
| 773 var panMultiplier = e.shiftKey ? 320 : 80; | 850 var panMultiplier = e.shiftKey ? 320 : 80; |
| 774 if (e.keyCode === "A".charCodeAt(0)) { | 851 if (e.keyCode === "A".charCodeAt(0)) { |
| 775 this._handlePanGesture(-panMultiplier * this._pixelToTime); | 852 this._handlePanGesture(-panMultiplier * this._pixelToTime); |
| 776 e.consume(true); | 853 e.consume(true); |
| 777 } else if (e.keyCode === "D".charCodeAt(0)) { | 854 } else if (e.keyCode === "D".charCodeAt(0)) { |
| 778 this._handlePanGesture(panMultiplier * this._pixelToTime); | 855 this._handlePanGesture(panMultiplier * this._pixelToTime); |
| 779 e.consume(true); | 856 e.consume(true); |
| 780 } else if (e.keyCode === "W".charCodeAt(0)) { | 857 } else if (e.keyCode === "W".charCodeAt(0)) { |
| (...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1452 this.update(); | 1529 this.update(); |
| 1453 }, | 1530 }, |
| 1454 | 1531 |
| 1455 _enabled: function() | 1532 _enabled: function() |
| 1456 { | 1533 { |
| 1457 return this._rawTimelineDataLength !== 0; | 1534 return this._rawTimelineDataLength !== 0; |
| 1458 }, | 1535 }, |
| 1459 | 1536 |
| 1460 __proto__: WebInspector.HBox.prototype | 1537 __proto__: WebInspector.HBox.prototype |
| 1461 } | 1538 } |
| OLD | NEW |