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 19 matching lines...) Expand all Loading... | |
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.ScreenCaptureModel} screenCaptureModel | 36 * @param {!SDK.ScreenCaptureModel} screenCaptureModel |
37 */ | 37 */ |
38 constructor(screenCaptureModel) { | 38 constructor(screenCaptureModel) { |
39 super(); | 39 super(); |
40 this._target = screenCaptureModel.target(); | |
41 this._screenCaptureModel = screenCaptureModel; | 40 this._screenCaptureModel = screenCaptureModel; |
42 this._domModel = this._target.model(SDK.DOMModel); | 41 this._domModel = screenCaptureModel.target().model(SDK.DOMModel); |
43 this._resourceTreeModel = this._target.model(SDK.ResourceTreeModel); | 42 this._resourceTreeModel = screenCaptureModel.target().model(SDK.ResourceTree Model); |
43 this._networkManager = screenCaptureModel.target().model(SDK.NetworkManager) ; | |
44 this._inputModel = screenCaptureModel.target().model(Screencast.InputModel); | |
44 | 45 |
45 this.setMinimumSize(150, 150); | 46 this.setMinimumSize(150, 150); |
46 this.registerRequiredCSS('screencast/screencastView.css'); | 47 this.registerRequiredCSS('screencast/screencastView.css'); |
47 } | 48 } |
48 | 49 |
49 initialize() { | 50 initialize() { |
50 this.element.classList.add('screencast'); | 51 this.element.classList.add('screencast'); |
51 | 52 |
52 this._createNavigationBar(); | 53 this._createNavigationBar(); |
53 | 54 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 _handleMouseEvent(event) { | 215 _handleMouseEvent(event) { |
215 if (this._isGlassPaneActive()) { | 216 if (this._isGlassPaneActive()) { |
216 event.consume(); | 217 event.consume(); |
217 return; | 218 return; |
218 } | 219 } |
219 | 220 |
220 if (!this._pageScaleFactor || !this._domModel) | 221 if (!this._pageScaleFactor || !this._domModel) |
221 return; | 222 return; |
222 | 223 |
223 if (!this._inspectModeConfig || event.type === 'mousewheel') { | 224 if (!this._inspectModeConfig || event.type === 'mousewheel') { |
224 this._simulateTouchForMouseEvent(event); | 225 if (this._inputModel) |
226 this._inputModel.dispatchTouchEventFromMouse(event, this._screenOffsetTo p, this._screenZoom); | |
lushnikov
2017/04/12 01:27:54
emit? to not clash with out event system
dgozman
2017/04/12 18:57:43
Done.
| |
225 event.preventDefault(); | 227 event.preventDefault(); |
226 if (event.type === 'mousedown') | 228 if (event.type === 'mousedown') |
227 this._canvasElement.focus(); | 229 this._canvasElement.focus(); |
228 return; | 230 return; |
229 } | 231 } |
230 | 232 |
231 var position = this._convertIntoScreenSpace(event); | 233 var position = this._convertIntoScreenSpace(event); |
232 this._domModel.nodeForLocation( | 234 this._domModel.nodeForLocation( |
233 Math.floor(position.x / this._pageScaleFactor + this._scrollOffsetX), | 235 Math.floor(position.x / this._pageScaleFactor + this._scrollOffsetX), |
234 Math.floor(position.y / this._pageScaleFactor + this._scrollOffsetY), | 236 Math.floor(position.y / this._pageScaleFactor + this._scrollOffsetY), |
(...skipping 24 matching lines...) Expand all Loading... | |
259 return; | 261 return; |
260 } | 262 } |
261 | 263 |
262 var shortcutKey = UI.KeyboardShortcut.makeKeyFromEvent(/** @type {!KeyboardE vent} */ (event)); | 264 var shortcutKey = UI.KeyboardShortcut.makeKeyFromEvent(/** @type {!KeyboardE vent} */ (event)); |
263 var handler = this._shortcuts[shortcutKey]; | 265 var handler = this._shortcuts[shortcutKey]; |
264 if (handler && handler(event)) { | 266 if (handler && handler(event)) { |
265 event.consume(); | 267 event.consume(); |
266 return; | 268 return; |
267 } | 269 } |
268 | 270 |
269 var type; | 271 if (this._inputModel) |
270 switch (event.type) { | 272 this._inputModel.dispatchKeyEvent(event); |
271 case 'keydown': | |
272 type = 'keyDown'; | |
273 break; | |
274 case 'keyup': | |
275 type = 'keyUp'; | |
276 break; | |
277 case 'keypress': | |
278 type = 'char'; | |
279 break; | |
280 default: | |
281 return; | |
282 } | |
283 | |
284 var text = event.type === 'keypress' ? String.fromCharCode(event.charCode) : undefined; | |
285 this._target.inputAgent().invoke_dispatchKeyEvent({ | |
286 type: type, | |
287 modifiers: this._modifiersForEvent(event), | |
288 timestamp: event.timeStamp / 1000, | |
289 text: text, | |
290 unmodifiedText: text ? text.toLowerCase() : undefined, | |
291 keyIdentifier: event.keyIdentifier, | |
292 code: event.code, | |
293 key: event.key, | |
294 windowsVirtualKeyCode: event.keyCode, | |
295 nativeVirtualKeyCode: event.keyCode, | |
296 autoRepeat: false, | |
297 isKeypad: false, | |
298 isSystemKey: false | |
299 }); | |
300 event.consume(); | 273 event.consume(); |
301 this._canvasElement.focus(); | 274 this._canvasElement.focus(); |
302 } | 275 } |
303 | 276 |
304 /** | 277 /** |
305 * @param {!Event} event | 278 * @param {!Event} event |
306 */ | 279 */ |
307 _handleContextMenuEvent(event) { | 280 _handleContextMenuEvent(event) { |
308 event.consume(true); | 281 event.consume(true); |
309 } | 282 } |
310 | 283 |
311 /** | 284 /** |
312 * @param {!Event} event | 285 * @param {!Event} event |
313 */ | 286 */ |
314 _simulateTouchForMouseEvent(event) { | |
315 const buttons = {0: 'none', 1: 'left', 2: 'middle', 3: 'right'}; | |
316 const types = { | |
317 'mousedown': 'mousePressed', | |
318 'mouseup': 'mouseReleased', | |
319 'mousemove': 'mouseMoved', | |
320 'mousewheel': 'mouseWheel' | |
321 }; | |
322 if (!(event.type in types) || !(event.which in buttons)) | |
323 return; | |
324 if (event.type !== 'mousewheel' && buttons[event.which] === 'none') | |
325 return; | |
326 | |
327 if (event.type === 'mousedown' || typeof this._eventScreenOffsetTop === 'und efined') | |
328 this._eventScreenOffsetTop = this._screenOffsetTop; | |
329 | |
330 var modifiers = | |
331 (event.altKey ? 1 : 0) | (event.ctrlKey ? 2 : 0) | (event.metaKey ? 4 : 0) | (event.shiftKey ? 8 : 0); | |
332 | |
333 var convertedPosition = this._zoomIntoScreenSpace(event); | |
334 convertedPosition.y = Math.round(convertedPosition.y - this._eventScreenOffs etTop); | |
335 var params = { | |
336 type: types[event.type], | |
337 x: convertedPosition.x, | |
338 y: convertedPosition.y, | |
339 modifiers: modifiers, | |
340 timestamp: event.timeStamp / 1000, | |
341 button: buttons[event.which], | |
342 clickCount: 0 | |
343 }; | |
344 if (event.type === 'mousewheel') { | |
345 params.deltaX = event.wheelDeltaX / this._screenZoom; | |
346 params.deltaY = event.wheelDeltaY / this._screenZoom; | |
347 } else { | |
348 this._eventParams = params; | |
349 } | |
350 if (event.type === 'mouseup') | |
351 delete this._eventScreenOffsetTop; | |
352 this._target.inputAgent().invoke_emulateTouchFromMouseEvent(params); | |
353 } | |
354 | |
355 /** | |
356 * @param {!Event} event | |
357 */ | |
358 _handleBlurEvent(event) { | 287 _handleBlurEvent(event) { |
359 if (typeof this._eventScreenOffsetTop !== 'undefined') { | 288 if (this._inputModel) |
360 var params = this._eventParams; | 289 this._inputModel.dispatchTouchOnBlur(); |
361 delete this._eventParams; | |
362 params.type = 'mouseReleased'; | |
363 this._target.inputAgent().invoke_emulateTouchFromMouseEvent(params); | |
364 } | |
365 } | |
366 | |
367 /** | |
368 * @param {!Event} event | |
369 * @return {!{x: number, y: number}} | |
370 */ | |
371 _zoomIntoScreenSpace(event) { | |
372 var position = {}; | |
373 position.x = Math.round(event.offsetX / this._screenZoom); | |
374 position.y = Math.round(event.offsetY / this._screenZoom); | |
375 return position; | |
376 } | 290 } |
377 | 291 |
378 /** | 292 /** |
379 * @param {!Event} event | 293 * @param {!Event} event |
380 * @return {!{x: number, y: number}} | 294 * @return {!{x: number, y: number}} |
381 */ | 295 */ |
382 _convertIntoScreenSpace(event) { | 296 _convertIntoScreenSpace(event) { |
383 var position = this._zoomIntoScreenSpace(event); | 297 var position = {}; |
384 position.y = Math.round(position.y - this._screenOffsetTop); | 298 position.x = Math.round(event.offsetX / this._screenZoom); |
299 position.y = Math.round(event.offsetY / this._screenZoom - this._screenOffse tTop); | |
385 return position; | 300 return position; |
386 } | 301 } |
387 | 302 |
388 /** | 303 /** |
389 * @param {!Event} event | |
390 * @return {number} | |
391 */ | |
392 _modifiersForEvent(event) { | |
393 var modifiers = 0; | |
394 if (event.altKey) | |
395 modifiers = 1; | |
396 if (event.ctrlKey) | |
397 modifiers += 2; | |
398 if (event.metaKey) | |
399 modifiers += 4; | |
400 if (event.shiftKey) | |
401 modifiers += 8; | |
402 return modifiers; | |
403 } | |
404 | |
405 /** | |
406 * @override | 304 * @override |
407 */ | 305 */ |
408 onResize() { | 306 onResize() { |
409 if (this._deferredCasting) { | 307 if (this._deferredCasting) { |
410 clearTimeout(this._deferredCasting); | 308 clearTimeout(this._deferredCasting); |
411 delete this._deferredCasting; | 309 delete this._deferredCasting; |
412 } | 310 } |
413 | 311 |
414 this._stopCasting(); | 312 this._stopCasting(); |
415 this._deferredCasting = setTimeout(this._startCasting.bind(this), 100); | 313 this._deferredCasting = setTimeout(this._startCasting.bind(this), 100); |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
705 pctx.fillRect(0, 0, size, size); | 603 pctx.fillRect(0, 0, size, size); |
706 pctx.fillRect(size, size, size, size); | 604 pctx.fillRect(size, size, size, size); |
707 return context.createPattern(pattern, 'repeat'); | 605 return context.createPattern(pattern, 'repeat'); |
708 } | 606 } |
709 | 607 |
710 _createNavigationBar() { | 608 _createNavigationBar() { |
711 this._navigationBar = this.element.createChild('div', 'screencast-navigation '); | 609 this._navigationBar = this.element.createChild('div', 'screencast-navigation '); |
712 | 610 |
713 this._navigationBack = this._navigationBar.createChild('button', 'back'); | 611 this._navigationBack = this._navigationBar.createChild('button', 'back'); |
714 this._navigationBack.disabled = true; | 612 this._navigationBack.disabled = true; |
715 this._navigationBack.addEventListener('click', this._navigateToHistoryEntry. bind(this, -1), false); | 613 this._navigationBack.addEventListener('click', this._navigateToHistoryEntry. bind(this, -1), false); |
lushnikov
2017/04/12 01:27:54
let's add this listeners only in case of existance
dgozman
2017/04/12 18:57:44
Done.
| |
716 | 614 |
717 this._navigationForward = this._navigationBar.createChild('button', 'forward '); | 615 this._navigationForward = this._navigationBar.createChild('button', 'forward '); |
718 this._navigationForward.disabled = true; | 616 this._navigationForward.disabled = true; |
719 this._navigationForward.addEventListener('click', this._navigateToHistoryEnt ry.bind(this, 1), false); | 617 this._navigationForward.addEventListener('click', this._navigateToHistoryEnt ry.bind(this, 1), false); |
720 | 618 |
721 this._navigationReload = this._navigationBar.createChild('button', 'reload') ; | 619 this._navigationReload = this._navigationBar.createChild('button', 'reload') ; |
722 this._navigationReload.addEventListener('click', this._navigateReload.bind(t his), false); | 620 this._navigationReload.addEventListener('click', this._navigateReload.bind(t his), false); |
723 | 621 |
724 this._navigationUrl = this._navigationBar.createChild('input'); | 622 this._navigationUrl = this._navigationBar.createChild('input'); |
725 this._navigationUrl.type = 'text'; | 623 this._navigationUrl.type = 'text'; |
726 this._navigationUrl.addEventListener('keyup', this._navigationUrlKeyUp.bind( this), true); | 624 this._navigationUrl.addEventListener('keyup', this._navigationUrlKeyUp.bind( this), true); |
727 | 625 |
728 this._navigationProgressBar = | 626 this._navigationProgressBar = new Screencast.ScreencastView.ProgressTracker( |
729 new Screencast.ScreencastView.ProgressTracker(this._navigationBar.create Child('div', 'progress')); | 627 this._resourceTreeModel, this._networkManager, this._navigationBar.creat eChild('div', 'progress')); |
730 | 628 |
731 this._requestNavigationHistory(); | 629 if (this._resourceTreeModel) { |
732 SDK.targetManager.addEventListener( | 630 this._requestNavigationHistory(); |
733 SDK.TargetManager.Events.InspectedURLChanged, this._requestNavigationHis tory, this); | 631 this._resourceTreeModel.addEventListener( |
632 SDK.ResourceTreeModel.Events.MainFrameNavigated, this._requestNavigati onHistory, this); | |
633 this._resourceTreeModel.addEventListener( | |
634 SDK.ResourceTreeModel.Events.CachedResourcesLoaded, this._requestNavig ationHistory, this); | |
635 } | |
734 } | 636 } |
735 | 637 |
638 /** | |
639 * @param {number} offset | |
640 */ | |
736 _navigateToHistoryEntry(offset) { | 641 _navigateToHistoryEntry(offset) { |
642 if (!this._resourceTreeModel) | |
643 return; | |
737 var newIndex = this._historyIndex + offset; | 644 var newIndex = this._historyIndex + offset; |
738 if (newIndex < 0 || newIndex >= this._historyEntries.length) | 645 if (newIndex < 0 || newIndex >= this._historyEntries.length) |
739 return; | 646 return; |
740 this._target.pageAgent().navigateToHistoryEntry(this._historyEntries[newInde x].id); | 647 this._resourceTreeModel.navigateToHistoryEntry(this._historyEntries[newIndex ]); |
741 this._requestNavigationHistory(); | 648 this._requestNavigationHistory(); |
742 } | 649 } |
743 | 650 |
744 _navigateReload() { | 651 _navigateReload() { |
745 if (this._resourceTreeModel) | 652 if (this._resourceTreeModel) |
746 this._resourceTreeModel.reloadPage(); | 653 this._resourceTreeModel.reloadPage(); |
747 } | 654 } |
748 | 655 |
656 /** | |
657 * @param {!Event} event | |
658 */ | |
749 _navigationUrlKeyUp(event) { | 659 _navigationUrlKeyUp(event) { |
750 if (event.key !== 'Enter') | 660 if (event.key !== 'Enter') |
751 return; | 661 return; |
752 var url = this._navigationUrl.value; | 662 var url = this._navigationUrl.value; |
753 if (!url) | 663 if (!url) |
754 return; | 664 return; |
755 if (!url.match(Screencast.ScreencastView._SchemeRegex)) | 665 if (!url.match(Screencast.ScreencastView._SchemeRegex)) |
756 url = 'http://' + url; | 666 url = 'http://' + url; |
757 this._target.pageAgent().navigate(url); | 667 this._resourceTreeModel.navigate(url); |
758 this._canvasElement.focus(); | 668 this._canvasElement.focus(); |
759 } | 669 } |
760 | 670 |
761 _requestNavigationHistory() { | 671 async _requestNavigationHistory() { |
762 this._target.pageAgent().getNavigationHistory(this._onNavigationHistory.bind (this)); | 672 var history = await this._resourceTreeModel.navigationHistory(); |
763 } | 673 if (!history) |
764 | |
765 _onNavigationHistory(error, currentIndex, entries) { | |
766 if (error) | |
767 return; | 674 return; |
768 | 675 |
769 this._historyIndex = currentIndex; | 676 this._historyIndex = history.currentIndex; |
770 this._historyEntries = entries; | 677 this._historyEntries = history.entries; |
771 | 678 |
772 this._navigationBack.disabled = currentIndex === 0; | 679 this._navigationBack.disabled = this._historyIndex === 0; |
773 this._navigationForward.disabled = currentIndex === (entries.length - 1); | 680 this._navigationForward.disabled = this._historyIndex === (this._historyEntr ies.length - 1); |
774 | 681 |
775 var url = entries[currentIndex].url; | 682 var url = this._historyEntries[this._historyIndex].url; |
776 var match = url.match(Screencast.ScreencastView._HttpRegex); | 683 var match = url.match(Screencast.ScreencastView._HttpRegex); |
777 if (match) | 684 if (match) |
778 url = match[1]; | 685 url = match[1]; |
779 InspectorFrontendHost.inspectedURLChanged(url); | 686 InspectorFrontendHost.inspectedURLChanged(url); |
780 this._navigationUrl.value = url; | 687 this._navigationUrl.value = url; |
781 } | 688 } |
782 | 689 |
783 _focusNavigationBar() { | 690 _focusNavigationBar() { |
784 this._navigationUrl.focus(); | 691 this._navigationUrl.focus(); |
785 this._navigationUrl.select(); | 692 this._navigationUrl.select(); |
786 return true; | 693 return true; |
787 } | 694 } |
788 }; | 695 }; |
789 | 696 |
790 Screencast.ScreencastView._bordersSize = 44; | 697 Screencast.ScreencastView._bordersSize = 44; |
791 | 698 |
792 Screencast.ScreencastView._navBarHeight = 29; | 699 Screencast.ScreencastView._navBarHeight = 29; |
793 | 700 |
794 Screencast.ScreencastView._HttpRegex = /^http:\/\/(.+)/; | 701 Screencast.ScreencastView._HttpRegex = /^http:\/\/(.+)/; |
795 | 702 |
796 Screencast.ScreencastView._SchemeRegex = /^(https?|about|chrome):/; | 703 Screencast.ScreencastView._SchemeRegex = /^(https?|about|chrome):/; |
797 | 704 |
798 /** | 705 /** |
799 * @unrestricted | 706 * @unrestricted |
800 */ | 707 */ |
801 Screencast.ScreencastView.ProgressTracker = class { | 708 Screencast.ScreencastView.ProgressTracker = class { |
802 /** | 709 /** |
710 * @param {?SDK.ResourceTreeModel} resourceTreeModel | |
711 * @param {?SDK.NetworkManager} networkManager | |
803 * @param {!Element} element | 712 * @param {!Element} element |
804 */ | 713 */ |
805 constructor(element) { | 714 constructor(resourceTreeModel, networkManager, element) { |
806 this._element = element; | 715 this._element = element; |
807 | 716 if (resourceTreeModel) { |
808 SDK.targetManager.addModelListener( | 717 resourceTreeModel.addEventListener( |
809 SDK.ResourceTreeModel, SDK.ResourceTreeModel.Events.MainFrameNavigated, this._onMainFrameNavigated, this); | 718 SDK.ResourceTreeModel.Events.MainFrameNavigated, this._onMainFrameNavi gated, this); |
810 SDK.targetManager.addModelListener(SDK.ResourceTreeModel, SDK.ResourceTreeMo del.Events.Load, this._onLoad, this); | 719 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Load, this ._onLoad, this); |
811 SDK.targetManager.addModelListener( | 720 } |
812 SDK.NetworkManager, SDK.NetworkManager.Events.RequestStarted, this._onRe questStarted, this); | 721 if (networkManager) { |
813 SDK.targetManager.addModelListener( | 722 networkManager.addEventListener(SDK.NetworkManager.Events.RequestStarted, this._onRequestStarted, this); |
814 SDK.NetworkManager, SDK.NetworkManager.Events.RequestFinished, this._onR equestFinished, this); | 723 networkManager.addEventListener(SDK.NetworkManager.Events.RequestFinished, this._onRequestFinished, this); |
724 } | |
815 } | 725 } |
816 | 726 |
817 _onMainFrameNavigated() { | 727 _onMainFrameNavigated() { |
818 this._requestIds = {}; | 728 this._requestIds = {}; |
819 this._startedRequests = 0; | 729 this._startedRequests = 0; |
820 this._finishedRequests = 0; | 730 this._finishedRequests = 0; |
821 this._maxDisplayedProgress = 0; | 731 this._maxDisplayedProgress = 0; |
822 this._updateProgress(0.1); // Display first 10% on navigation start. | 732 this._updateProgress(0.1); // Display first 10% on navigation start. |
823 } | 733 } |
824 | 734 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
865 if (this._maxDisplayedProgress >= progress) | 775 if (this._maxDisplayedProgress >= progress) |
866 return; | 776 return; |
867 this._maxDisplayedProgress = progress; | 777 this._maxDisplayedProgress = progress; |
868 this._displayProgress(progress); | 778 this._displayProgress(progress); |
869 } | 779 } |
870 | 780 |
871 _displayProgress(progress) { | 781 _displayProgress(progress) { |
872 this._element.style.width = (100 * progress) + '%'; | 782 this._element.style.width = (100 * progress) + '%'; |
873 } | 783 } |
874 }; | 784 }; |
OLD | NEW |