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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 Common.UIString('FPS Meter'), | 47 Common.UIString('FPS Meter'), |
| 48 Common.UIString('Plots frames per second, frame rate distribution, and G PU memory'), | 48 Common.UIString('Plots frames per second, frame rate distribution, and G PU memory'), |
| 49 Common.moduleSetting('showFPSCounter')); | 49 Common.moduleSetting('showFPSCounter')); |
| 50 this._appendCheckbox( | 50 this._appendCheckbox( |
| 51 Common.UIString('Scrolling Performance Issues'), | 51 Common.UIString('Scrolling Performance Issues'), |
| 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 this._mediaSetting = Common.moduleSetting('emulateCSSMedia'); |
| 58 var checkboxLabel = UI.CheckboxLabel.create(Common.UIString('Emulate CSS Med ia'), false, cssMediaSubtitle); | 58 this._mediaSetting.addChangeListener(this._mediaChanged.bind(this)); |
| 59 this._mediaCheckbox = checkboxLabel.checkboxElement; | 59 var emulateMediaExtension = self.runtime.extensions('setting').find( |
| 60 this._mediaCheckbox.addEventListener('click', this._mediaToggled.bind(this), false); | 60 extension => extension.descriptor()['settingName'] === 'emulateCSSMedia' && !!extension.descriptor().options); |
| 61 this.contentElement.appendChild(checkboxLabel); | 61 if (emulateMediaExtension) { |
| 62 | 62 var mediaOptions = emulateMediaExtension.descriptor().options; |
|
pfeldman
2017/05/10 20:55:19
I'm seeing the same code in SettingsScreen.js - ca
luoe
2017/05/11 21:40:02
We can do a settingExtensionToControl that holds c
| |
| 63 var mediaRow = this.contentElement.createChild('div', 'media-row'); | 63 var mediaSelect = UI.SettingsUI.createSettingSelect( |
| 64 this._mediaSelect = mediaRow.createChild('select', 'chrome-select'); | 64 Common.UIString('Emulate CSS Media'), mediaOptions, this._mediaSetting , |
| 65 this._mediaSelect.appendChild(new Option(Common.UIString('print'), 'print')) ; | 65 Common.UIString('Forces media type for testing print and screen styles ')); |
| 66 this._mediaSelect.appendChild(new Option(Common.UIString('screen'), 'screen' )); | 66 this.contentElement.createChild('div', 'media-row').appendChild(mediaSelec t); |
| 67 this._mediaSelect.addEventListener('change', this._mediaToggled.bind(this), false); | 67 } |
| 68 this._mediaSelect.disabled = true; | |
| 69 | 68 |
| 70 SDK.targetManager.observeModels(SDK.EmulationModel, this); | 69 SDK.targetManager.observeModels(SDK.EmulationModel, this); |
| 71 } | 70 } |
| 72 | 71 |
| 73 /** | 72 /** |
| 74 * @param {string} label | 73 * @param {string} label |
| 75 * @param {string} subtitle | 74 * @param {string} subtitle |
| 76 * @param {!Common.Setting} setting | 75 * @param {!Common.Setting} setting |
| 77 */ | 76 */ |
| 78 _appendCheckbox(label, subtitle, setting) { | 77 _appendCheckbox(label, subtitle, setting) { |
| 79 var checkboxLabel = UI.CheckboxLabel.create(label, false, subtitle); | 78 var checkboxLabel = UI.CheckboxLabel.create(label, false, subtitle); |
| 80 UI.SettingsUI.bindCheckbox(checkboxLabel.checkboxElement, setting); | 79 UI.SettingsUI.bindCheckbox(checkboxLabel.checkboxElement, setting); |
| 81 this.contentElement.appendChild(checkboxLabel); | 80 this.contentElement.appendChild(checkboxLabel); |
| 82 } | 81 } |
| 83 | 82 |
| 84 /** | 83 /** |
| 85 * @override | 84 * @override |
| 86 * @param {!SDK.EmulationModel} emulationModel | 85 * @param {!SDK.EmulationModel} emulationModel |
| 87 */ | 86 */ |
| 88 modelAdded(emulationModel) { | 87 modelAdded(emulationModel) { |
| 89 if (this._mediaCheckbox.checked) | 88 var mediaValue = this._mediaSetting.get() === 'none' ? null : this._mediaSet ting.get(); |
| 90 emulationModel.emulateCSSMedia(this._mediaSelect.value); | 89 emulationModel.emulateCSSMedia(mediaValue); |
| 91 } | 90 } |
| 92 | 91 |
| 93 _mediaToggled() { | 92 _mediaChanged() { |
| 94 this._mediaSelect.disabled = !this._mediaCheckbox.checked; | 93 var mediaValue = this._mediaSetting.get() === 'none' ? null : this._mediaSet ting.get(); |
| 95 var media = this._mediaCheckbox.checked ? this._mediaSelect.value : null; | |
| 96 for (var emulationModel of SDK.targetManager.models(SDK.EmulationModel)) | 94 for (var emulationModel of SDK.targetManager.models(SDK.EmulationModel)) |
| 97 emulationModel.emulateCSSMedia(media); | 95 emulationModel.emulateCSSMedia(mediaValue); |
| 98 } | 96 } |
| 99 | 97 |
| 100 /** | 98 /** |
| 101 * @override | 99 * @override |
| 102 * @param {!SDK.EmulationModel} emulationModel | 100 * @param {!SDK.EmulationModel} emulationModel |
| 103 */ | 101 */ |
| 104 modelRemoved(emulationModel) { | 102 modelRemoved(emulationModel) { |
| 105 } | 103 } |
| 106 }; | 104 }; |
| OLD | NEW |