Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/main/RenderingOptions.js

Issue 2843763004: [DevTools] Introduce EmulationModel which will encapsulate emulation (Closed)
Patch Set: +throttling Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 * copyright notice, this list of conditions and the following disclaimer 11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the 12 * in the documentation and/or other materials provided with the
13 * distribution. 13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its 14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from 15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission. 16 * this software without specific prior written permission.
17 * 17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30
30 /** 31 /**
31 * @implements {SDK.TargetManager.Observer} 32 * @implements {SDK.SDKModelObserver<!SDK.EmulationModel>}
32 * @unrestricted
33 */ 33 */
34 Main.RenderingOptionsView = class extends UI.VBox { 34 Main.RenderingOptionsView = class extends UI.VBox {
35 constructor() { 35 constructor() {
36 super(true); 36 super(true);
37 this.registerRequiredCSS('main/renderingOptions.css'); 37 this.registerRequiredCSS('main/renderingOptions.css');
38 38
39 this._appendCheckbox( 39 this._appendCheckbox(
40 Common.UIString('Paint Flashing'), 40 Common.UIString('Paint Flashing'),
41 Common.UIString('Highlights areas of the page (green) that need to be re painted'), 41 Common.UIString('Highlights areas of the page (green) that need to be re painted'),
42 Common.moduleSetting('showPaintRects')); 42 Common.moduleSetting('showPaintRects'));
(...skipping 17 matching lines...) Expand all
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 62
63 var mediaRow = this.contentElement.createChild('div', 'media-row'); 63 var mediaRow = this.contentElement.createChild('div', 'media-row');
64 this._mediaSelect = mediaRow.createChild('select', 'chrome-select'); 64 this._mediaSelect = mediaRow.createChild('select', 'chrome-select');
65 this._mediaSelect.appendChild(new Option(Common.UIString('print'), 'print')) ; 65 this._mediaSelect.appendChild(new Option(Common.UIString('print'), 'print')) ;
66 this._mediaSelect.appendChild(new Option(Common.UIString('screen'), 'screen' )); 66 this._mediaSelect.appendChild(new Option(Common.UIString('screen'), 'screen' ));
67 this._mediaSelect.addEventListener('change', this._mediaToggled.bind(this), false); 67 this._mediaSelect.addEventListener('change', this._mediaToggled.bind(this), false);
68 this._mediaSelect.disabled = true; 68 this._mediaSelect.disabled = true;
69 69
70 SDK.targetManager.observeTargets(this); 70 SDK.targetManager.observeModels(SDK.EmulationModel, this);
71 } 71 }
72 72
73 /** 73 /**
74 * @return {!Main.RenderingOptionsView}
75 */
76 static instance() {
77 if (!Main.RenderingOptionsView._instanceObject)
78 Main.RenderingOptionsView._instanceObject = new Main.RenderingOptionsView( );
79 return Main.RenderingOptionsView._instanceObject;
80 }
81
82 /**
83 * @param {string} label 74 * @param {string} label
84 * @param {string} subtitle 75 * @param {string} subtitle
85 * @param {!Common.Setting} setting 76 * @param {!Common.Setting} setting
86 */ 77 */
87 _appendCheckbox(label, subtitle, setting) { 78 _appendCheckbox(label, subtitle, setting) {
88 var checkboxLabel = UI.CheckboxLabel.create(label, false, subtitle); 79 var checkboxLabel = UI.CheckboxLabel.create(label, false, subtitle);
89 UI.SettingsUI.bindCheckbox(checkboxLabel.checkboxElement, setting); 80 UI.SettingsUI.bindCheckbox(checkboxLabel.checkboxElement, setting);
90 this.contentElement.appendChild(checkboxLabel); 81 this.contentElement.appendChild(checkboxLabel);
91 } 82 }
92 83
93 /** 84 /**
94 * @override 85 * @override
95 * @param {!SDK.Target} target 86 * @param {!SDK.EmulationModel} emulationModel
96 */ 87 */
97 targetAdded(target) { 88 modelAdded(emulationModel) {
98 if (this._mediaCheckbox.checked && target.hasBrowserCapability()) 89 if (this._mediaCheckbox.checked)
99 this._applyPrintMediaOverride(target); 90 emulationModel.emulateCSSMedia(this._mediaSelect.value);
100 } 91 }
101 92
102 _mediaToggled() { 93 _mediaToggled() {
103 this._mediaSelect.disabled = !this._mediaCheckbox.checked; 94 this._mediaSelect.disabled = !this._mediaCheckbox.checked;
104 var targets = SDK.targetManager.targets(SDK.Target.Capability.Browser); 95 var media = this._mediaCheckbox.checked ? this._mediaSelect.value : null;
105 for (var target of targets) 96 for (var emulationModel of SDK.targetManager.models(SDK.EmulationModel))
106 this._applyPrintMediaOverride(target); 97 emulationModel.emulateCSSMedia(media);
107 }
108
109 /**
110 * @param {!SDK.Target} target
111 */
112 _applyPrintMediaOverride(target) {
113 target.emulationAgent().setEmulatedMedia(this._mediaCheckbox.checked ? this. _mediaSelect.value : '');
114 var cssModel = target.model(SDK.CSSModel);
115 if (cssModel)
116 cssModel.mediaQueryResultChanged();
117 } 98 }
118 99
119 /** 100 /**
120 * @override 101 * @override
121 * @param {!SDK.Target} target 102 * @param {!SDK.EmulationModel} emulationModel
122 */ 103 */
123 targetRemoved(target) { 104 modelRemoved(emulationModel) {
124 } 105 }
125 }; 106 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698