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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 Common.UIString( | 52 Common.UIString( |
53 'Highlights elements (teal) that can slow down scrolling, including touch & wheel event handlers and other main-thread scrolling situations.'), | 53 'Highlights elements (teal) that can slow down scrolling, including touch & wheel event handlers and other main-thread scrolling situations.'), |
54 Common.moduleSetting('showScrollBottleneckRects')); | 54 Common.moduleSetting('showScrollBottleneckRects')); |
55 this.contentElement.createChild('div').classList.add('panel-section-separato r'); | 55 this.contentElement.createChild('div').classList.add('panel-section-separato r'); |
56 | 56 |
57 var cssMediaSubtitle = Common.UIString('Forces media type for testing print and screen styles'); | 57 var cssMediaSubtitle = Common.UIString('Forces media type for testing print and screen styles'); |
58 var checkboxLabel = UI.CheckboxLabel.create(Common.UIString('Emulate CSS Med ia'), false, cssMediaSubtitle); | 58 var checkboxLabel = UI.CheckboxLabel.create(Common.UIString('Emulate CSS Med ia'), false, cssMediaSubtitle); |
59 this._mediaCheckbox = checkboxLabel.checkboxElement; | 59 this._mediaCheckbox = checkboxLabel.checkboxElement; |
60 this._mediaCheckbox.addEventListener('click', this._mediaToggled.bind(this), false); | 60 this._mediaCheckbox.addEventListener('click', this._mediaToggled.bind(this), false); |
61 this.contentElement.appendChild(checkboxLabel); | 61 this.contentElement.appendChild(checkboxLabel); |
62 this._emulateCSSMediaSetting = Common.moduleSetting('emulateCSSMedia'); | |
63 this._emulateCSSMediaSetting.addChangeListener(this._emulateCSSMediaSettingC hanged, this); | |
62 | 64 |
63 var mediaRow = this.contentElement.createChild('div', 'media-row'); | 65 var mediaRow = this.contentElement.createChild('div', 'media-row'); |
64 this._mediaSelect = mediaRow.createChild('select', 'chrome-select'); | 66 this._mediaSelect = mediaRow.createChild('select', 'chrome-select'); |
65 this._mediaSelect.appendChild(new Option(Common.UIString('print'), 'print')) ; | 67 this._mediaSelect.appendChild(new Option(Common.UIString('print'), 'print')) ; |
66 this._mediaSelect.appendChild(new Option(Common.UIString('screen'), 'screen' )); | 68 this._mediaSelect.appendChild(new Option(Common.UIString('screen'), 'screen' )); |
67 this._mediaSelect.addEventListener('change', this._mediaToggled.bind(this), false); | 69 this._mediaSelect.addEventListener('change', this._mediaToggled.bind(this), false); |
68 this._mediaSelect.disabled = true; | 70 this._mediaSelect.disabled = true; |
69 | 71 |
70 SDK.targetManager.observeTargets(this); | 72 SDK.targetManager.observeTargets(this); |
71 } | 73 } |
(...skipping 16 matching lines...) Expand all Loading... | |
88 var checkboxLabel = UI.CheckboxLabel.create(label, false, subtitle); | 90 var checkboxLabel = UI.CheckboxLabel.create(label, false, subtitle); |
89 UI.SettingsUI.bindCheckbox(checkboxLabel.checkboxElement, setting); | 91 UI.SettingsUI.bindCheckbox(checkboxLabel.checkboxElement, setting); |
90 this.contentElement.appendChild(checkboxLabel); | 92 this.contentElement.appendChild(checkboxLabel); |
91 } | 93 } |
92 | 94 |
93 /** | 95 /** |
94 * @override | 96 * @override |
95 * @param {!SDK.Target} target | 97 * @param {!SDK.Target} target |
96 */ | 98 */ |
97 targetAdded(target) { | 99 targetAdded(target) { |
98 if (this._mediaCheckbox.checked && target.hasBrowserCapability()) | 100 if (this._emulateCSSMediaSetting.get() !== 'none' && target.hasBrowserCapabi lity()) |
pfeldman
2017/04/27 21:46:18
Can we replace checkbox + combobox with the settin
luoe
2017/05/09 02:58:27
Done.
| |
99 this._applyPrintMediaOverride(target); | 101 this._applyPrintMediaOverride(target); |
100 } | 102 } |
101 | 103 |
102 _mediaToggled() { | 104 _mediaToggled() { |
103 this._mediaSelect.disabled = !this._mediaCheckbox.checked; | 105 this._emulateCSSMediaSetting.set(this._mediaCheckbox.checked ? this._mediaSe lect.value : 'none'); |
106 } | |
107 | |
108 _emulateCSSMediaSettingChanged() { | |
109 var mediaValue = this._emulateCSSMediaSetting.get(); | |
110 var noEmulation = mediaValue === 'none'; | |
111 if (!noEmulation) | |
112 this._mediaSelect.value = mediaValue; | |
113 this._mediaSelect.disabled = noEmulation; | |
114 this._mediaCheckbox.checked = !noEmulation; | |
104 var targets = SDK.targetManager.targets(SDK.Target.Capability.Browser); | 115 var targets = SDK.targetManager.targets(SDK.Target.Capability.Browser); |
105 for (var target of targets) | 116 for (var target of targets) |
106 this._applyPrintMediaOverride(target); | 117 this._applyPrintMediaOverride(target); |
107 } | 118 } |
108 | 119 |
109 /** | 120 /** |
110 * @param {!SDK.Target} target | 121 * @param {!SDK.Target} target |
111 */ | 122 */ |
112 _applyPrintMediaOverride(target) { | 123 _applyPrintMediaOverride(target) { |
113 target.emulationAgent().setEmulatedMedia(this._mediaCheckbox.checked ? this. _mediaSelect.value : ''); | 124 var mediaValue = this._emulateCSSMediaSetting.get() === 'none' ? '' : this._ emulateCSSMediaSetting.get(); |
125 target.emulationAgent().setEmulatedMedia(mediaValue); | |
114 var cssModel = target.model(SDK.CSSModel); | 126 var cssModel = target.model(SDK.CSSModel); |
115 if (cssModel) | 127 if (cssModel) |
116 cssModel.mediaQueryResultChanged(); | 128 cssModel.mediaQueryResultChanged(); |
117 } | 129 } |
118 | 130 |
119 /** | 131 /** |
120 * @override | 132 * @override |
121 * @param {!SDK.Target} target | 133 * @param {!SDK.Target} target |
122 */ | 134 */ |
123 targetRemoved(target) { | 135 targetRemoved(target) { |
124 } | 136 } |
125 }; | 137 }; |
OLD | NEW |