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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/screencast/ScreencastView.js

Issue 2672983002: [DevTools] Separate ScreenCaptureModel out of ResourceTreeModel. (Closed)
Patch Set: rebased Created 3 years, 10 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
(...skipping 15 matching lines...) Expand all
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 * @implements {SDK.DOMNodeHighlighter} 31 * @implements {SDK.DOMNodeHighlighter}
32 * @unrestricted 32 * @unrestricted
33 */ 33 */
34 Screencast.ScreencastView = class extends UI.VBox { 34 Screencast.ScreencastView = class extends UI.VBox {
35 /** 35 /**
36 * @param {!SDK.Target} target 36 * @param {!SDK.ScreenCaptureModel} screenCaptureModel
37 * @param {!SDK.ResourceTreeModel} resourceTreeModel
38 */ 37 */
39 constructor(target, resourceTreeModel) { 38 constructor(screenCaptureModel) {
40 super(); 39 super();
41 this._target = target; 40 this._target = screenCaptureModel.target();
42 this._domModel = SDK.DOMModel.fromTarget(target); 41 this._screenCaptureModel = screenCaptureModel;
43 this._resourceTreeModel = resourceTreeModel; 42 this._domModel = SDK.DOMModel.fromTarget(this._target);
43 this._resourceTreeModel = SDK.ResourceTreeModel.fromTarget(this._target);
44 44
45 this.setMinimumSize(150, 150); 45 this.setMinimumSize(150, 150);
46 this.registerRequiredCSS('screencast/screencastView.css'); 46 this.registerRequiredCSS('screencast/screencastView.css');
47 } 47 }
48 48
49 initialize() { 49 initialize() {
50 this.element.classList.add('screencast'); 50 this.element.classList.add('screencast');
51 51
52 this._createNavigationBar(); 52 this._createNavigationBar();
53 53
(...skipping 29 matching lines...) Expand all
83 83
84 this._imageElement = new Image(); 84 this._imageElement = new Image();
85 this._isCasting = false; 85 this._isCasting = false;
86 this._context = this._canvasElement.getContext('2d'); 86 this._context = this._canvasElement.getContext('2d');
87 this._checkerboardPattern = this._createCheckerboardPattern(this._context); 87 this._checkerboardPattern = this._createCheckerboardPattern(this._context);
88 88
89 this._shortcuts = /** !Object.<number, function(Event=):boolean> */ ({}); 89 this._shortcuts = /** !Object.<number, function(Event=):boolean> */ ({});
90 this._shortcuts[UI.KeyboardShortcut.makeKey('l', UI.KeyboardShortcut.Modifie rs.Ctrl)] = 90 this._shortcuts[UI.KeyboardShortcut.makeKey('l', UI.KeyboardShortcut.Modifie rs.Ctrl)] =
91 this._focusNavigationBar.bind(this); 91 this._focusNavigationBar.bind(this);
92 92
93 this._resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Screen castFrame, this._screencastFrame, this);
94 this._resourceTreeModel.addEventListener(
95 SDK.ResourceTreeModel.Events.ScreencastVisibilityChanged, this._screenca stVisibilityChanged, this);
96
97 SDK.targetManager.addEventListener(SDK.TargetManager.Events.SuspendStateChan ged, this._onSuspendStateChange, this); 93 SDK.targetManager.addEventListener(SDK.TargetManager.Events.SuspendStateChan ged, this._onSuspendStateChange, this);
98 this._updateGlasspane(); 94 this._updateGlasspane();
99 } 95 }
100 96
101 /** 97 /**
102 * @override 98 * @override
103 */ 99 */
104 wasShown() { 100 wasShown() {
105 this._startCasting(); 101 this._startCasting();
106 } 102 }
(...skipping 13 matching lines...) Expand all
120 this._isCasting = true; 116 this._isCasting = true;
121 117
122 const maxImageDimension = 2048; 118 const maxImageDimension = 2048;
123 var dimensions = this._viewportDimensions(); 119 var dimensions = this._viewportDimensions();
124 if (dimensions.width < 0 || dimensions.height < 0) { 120 if (dimensions.width < 0 || dimensions.height < 0) {
125 this._isCasting = false; 121 this._isCasting = false;
126 return; 122 return;
127 } 123 }
128 dimensions.width *= window.devicePixelRatio; 124 dimensions.width *= window.devicePixelRatio;
129 dimensions.height *= window.devicePixelRatio; 125 dimensions.height *= window.devicePixelRatio;
130 // Note: startScreencast with and height expect to be integers so must be fl oored. 126 // Note: startScreencast width and height are expected to be integers so mus t be floored.
131 this._target.pageAgent().startScreencast( 127 this._screenCaptureModel.startScreencast(
132 'jpeg', 80, Math.floor(Math.min(maxImageDimension, dimensions.width)), 128 'jpeg', 80, Math.floor(Math.min(maxImageDimension, dimensions.width)),
133 Math.floor(Math.min(maxImageDimension, dimensions.height))); 129 Math.floor(Math.min(maxImageDimension, dimensions.height)), undefined, t his._screencastFrame.bind(this),
134 this._target.emulationAgent().setTouchEmulationEnabled(true); 130 this._screencastVisibilityChanged.bind(this));
135 this._domModel.setHighlighter(this); 131 Emulation.MultitargetTouchModel.instance().setCustomTouchEnabled(true);
132 if (this._domModel)
133 this._domModel.setHighlighter(this);
136 } 134 }
137 135
138 _stopCasting() { 136 _stopCasting() {
139 if (!this._isCasting) 137 if (!this._isCasting)
140 return; 138 return;
141 this._isCasting = false; 139 this._isCasting = false;
142 this._target.pageAgent().stopScreencast(); 140 this._screenCaptureModel.stopScreencast();
143 this._target.emulationAgent().setTouchEmulationEnabled(false); 141 Emulation.MultitargetTouchModel.instance().setCustomTouchEnabled(false);
144 this._domModel.setHighlighter(null); 142 if (this._domModel)
143 this._domModel.setHighlighter(null);
145 } 144 }
146 145
147 /** 146 /**
148 * @param {!Common.Event} event 147 * @param {string} base64Data
148 * @param {!Protocol.Page.ScreencastFrameMetadata} metadata
149 */ 149 */
150 _screencastFrame(event) { 150 _screencastFrame(base64Data, metadata) {
151 var metadata = /** type {Protocol.Page.ScreencastFrameMetadata} */ (event.da ta.metadata);
152 var base64Data = /** type {string} */ (event.data.data);
153 this._imageElement.onload = () => { 151 this._imageElement.onload = () => {
154 this._pageScaleFactor = metadata.pageScaleFactor; 152 this._pageScaleFactor = metadata.pageScaleFactor;
155 this._screenOffsetTop = metadata.offsetTop; 153 this._screenOffsetTop = metadata.offsetTop;
156 this._scrollOffsetX = metadata.scrollOffsetX; 154 this._scrollOffsetX = metadata.scrollOffsetX;
157 this._scrollOffsetY = metadata.scrollOffsetY; 155 this._scrollOffsetY = metadata.scrollOffsetY;
158 156
159 var deviceSizeRatio = metadata.deviceHeight / metadata.deviceWidth; 157 var deviceSizeRatio = metadata.deviceHeight / metadata.deviceWidth;
160 var dimensionsCSS = this._viewportDimensions(); 158 var dimensionsCSS = this._viewportDimensions();
161 159
162 this._imageZoom = Math.min( 160 this._imageZoom = Math.min(
(...skipping 10 matching lines...) Expand all
173 this.highlightDOMNode(this._highlightNode, this._highlightConfig); 171 this.highlightDOMNode(this._highlightNode, this._highlightConfig);
174 }; 172 };
175 this._imageElement.src = 'data:image/jpg;base64,' + base64Data; 173 this._imageElement.src = 'data:image/jpg;base64,' + base64Data;
176 } 174 }
177 175
178 _isGlassPaneActive() { 176 _isGlassPaneActive() {
179 return !this._glassPaneElement.classList.contains('hidden'); 177 return !this._glassPaneElement.classList.contains('hidden');
180 } 178 }
181 179
182 /** 180 /**
183 * @param {!Common.Event} event 181 * @param {boolean} visible
184 */ 182 */
185 _screencastVisibilityChanged(event) { 183 _screencastVisibilityChanged(visible) {
186 this._targetInactive = !event.data.visible; 184 this._targetInactive = !visible;
187 this._updateGlasspane(); 185 this._updateGlasspane();
188 } 186 }
189 187
190 /** 188 /**
191 * @param {!Common.Event} event 189 * @param {!Common.Event} event
192 */ 190 */
193 _onSuspendStateChange(event) { 191 _onSuspendStateChange(event) {
194 if (SDK.targetManager.allTargetsSuspended()) 192 if (SDK.targetManager.allTargetsSuspended())
195 this._stopCasting(); 193 this._stopCasting();
196 else 194 else
(...skipping 15 matching lines...) Expand all
212 210
213 /** 211 /**
214 * @param {!Event} event 212 * @param {!Event} event
215 */ 213 */
216 _handleMouseEvent(event) { 214 _handleMouseEvent(event) {
217 if (this._isGlassPaneActive()) { 215 if (this._isGlassPaneActive()) {
218 event.consume(); 216 event.consume();
219 return; 217 return;
220 } 218 }
221 219
222 if (!this._pageScaleFactor) 220 if (!this._pageScaleFactor || !this._domModel)
223 return; 221 return;
224 222
225 if (!this._inspectModeConfig || event.type === 'mousewheel') { 223 if (!this._inspectModeConfig || event.type === 'mousewheel') {
226 this._simulateTouchForMouseEvent(event); 224 this._simulateTouchForMouseEvent(event);
227 event.preventDefault(); 225 event.preventDefault();
228 if (event.type === 'mousedown') 226 if (event.type === 'mousedown')
229 this._canvasElement.focus(); 227 this._canvasElement.focus();
230 return; 228 return;
231 } 229 }
232 230
233 var position = this._convertIntoScreenSpace(event); 231 var position = this._convertIntoScreenSpace(event);
234 this._domModel.nodeForLocation( 232 this._domModel.nodeForLocation(
235 position.x / this._pageScaleFactor + this._scrollOffsetX, 233 Math.floor(position.x / this._pageScaleFactor + this._scrollOffsetX),
236 position.y / this._pageScaleFactor + this._scrollOffsetY, callback.bind( this)); 234 Math.floor(position.y / this._pageScaleFactor + this._scrollOffsetY), ca llback.bind(this));
237 235
238 /** 236 /**
239 * @param {?SDK.DOMNode} node 237 * @param {?SDK.DOMNode} node
240 * @this {Screencast.ScreencastView} 238 * @this {Screencast.ScreencastView}
241 */ 239 */
242 function callback(node) { 240 function callback(node) {
243 if (!node) 241 if (!node)
244 return; 242 return;
245 if (event.type === 'mousemove') { 243 if (event.type === 'mousemove') {
246 this.highlightDOMNode(node, this._inspectModeConfig); 244 this.highlightDOMNode(node, this._inspectModeConfig);
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 734
737 _navigateToHistoryEntry(offset) { 735 _navigateToHistoryEntry(offset) {
738 var newIndex = this._historyIndex + offset; 736 var newIndex = this._historyIndex + offset;
739 if (newIndex < 0 || newIndex >= this._historyEntries.length) 737 if (newIndex < 0 || newIndex >= this._historyEntries.length)
740 return; 738 return;
741 this._target.pageAgent().navigateToHistoryEntry(this._historyEntries[newInde x].id); 739 this._target.pageAgent().navigateToHistoryEntry(this._historyEntries[newInde x].id);
742 this._requestNavigationHistory(); 740 this._requestNavigationHistory();
743 } 741 }
744 742
745 _navigateReload() { 743 _navigateReload() {
746 this._resourceTreeModel.reloadPage(); 744 if (this._resourceTreeModel)
745 this._resourceTreeModel.reloadPage();
747 } 746 }
748 747
749 _navigationUrlKeyUp(event) { 748 _navigationUrlKeyUp(event) {
750 if (event.key !== 'Enter') 749 if (event.key !== 'Enter')
751 return; 750 return;
752 var url = this._navigationUrl.value; 751 var url = this._navigationUrl.value;
753 if (!url) 752 if (!url)
754 return; 753 return;
755 if (!url.match(Screencast.ScreencastView._SchemeRegex)) 754 if (!url.match(Screencast.ScreencastView._SchemeRegex))
756 url = 'http://' + url; 755 url = 'http://' + url;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 if (this._maxDisplayedProgress >= progress) 864 if (this._maxDisplayedProgress >= progress)
866 return; 865 return;
867 this._maxDisplayedProgress = progress; 866 this._maxDisplayedProgress = progress;
868 this._displayProgress(progress); 867 this._displayProgress(progress);
869 } 868 }
870 869
871 _displayProgress(progress) { 870 _displayProgress(progress) {
872 this._element.style.width = (100 * progress) + '%'; 871 this._element.style.width = (100 * progress) + '%';
873 } 872 }
874 }; 873 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698