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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/emulation/InspectedPagePlaceholder.js

Issue 2861053003: DevTools: [lighthouse] Implement performance metrics filmstrip (Closed)
Patch Set: test fixed 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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4
4 /** 5 /**
5 * @unrestricted 6 * @unrestricted
6 */ 7 */
7 Emulation.InspectedPagePlaceholder = class extends UI.Widget { 8 Emulation.InspectedPagePlaceholder = class extends UI.Widget {
8 constructor() { 9 constructor() {
9 super(true); 10 super(true);
10 this.registerRequiredCSS('emulation/inspectedPagePlaceholder.css'); 11 this.registerRequiredCSS('emulation/inspectedPagePlaceholder.css');
11 UI.zoomManager.addEventListener(UI.ZoomManager.Events.ZoomChanged, this.onRe size, this); 12 UI.zoomManager.addEventListener(UI.ZoomManager.Events.ZoomChanged, this.onRe size, this);
12 this.restoreMinimumSize(); 13 this.restoreMinimumSize();
13 } 14 }
14 15
15 /** 16 /**
16 * @override 17 * @override
17 */ 18 */
18 onResize() { 19 onResize() {
19 if (this._updateId) 20 if (this._updateId)
20 this.element.window().cancelAnimationFrame(this._updateId); 21 this.element.window().cancelAnimationFrame(this._updateId);
21 this._updateId = this.element.window().requestAnimationFrame(this.update.bin d(this)); 22 this._updateId = this.element.window().requestAnimationFrame(this.update.bin d(this, false));
22 } 23 }
23 24
24 restoreMinimumSize() { 25 restoreMinimumSize() {
25 this.setMinimumSize(150, 150); 26 this.setMinimumSize(150, 150);
26 } 27 }
27 28
28 clearMinimumSize() { 29 clearMinimumSize() {
29 this.setMinimumSize(1, 1); 30 this.setMinimumSize(1, 1);
30 } 31 }
31 32
32 _dipPageRect() { 33 _dipPageRect() {
33 var zoomFactor = UI.zoomManager.zoomFactor(); 34 var zoomFactor = UI.zoomManager.zoomFactor();
34 var rect = this.element.getBoundingClientRect(); 35 var rect = this.element.getBoundingClientRect();
35 var bodyRect = this.element.ownerDocument.body.getBoundingClientRect(); 36 var bodyRect = this.element.ownerDocument.body.getBoundingClientRect();
36 37
37 var left = Math.max(rect.left * zoomFactor, bodyRect.left * zoomFactor); 38 var left = Math.max(rect.left * zoomFactor, bodyRect.left * zoomFactor);
38 var top = Math.max(rect.top * zoomFactor, bodyRect.top * zoomFactor); 39 var top = Math.max(rect.top * zoomFactor, bodyRect.top * zoomFactor);
39 var bottom = Math.min(rect.bottom * zoomFactor, bodyRect.bottom * zoomFactor ); 40 var bottom = Math.min(rect.bottom * zoomFactor, bodyRect.bottom * zoomFactor );
40 var right = Math.min(rect.right * zoomFactor, bodyRect.right * zoomFactor); 41 var right = Math.min(rect.right * zoomFactor, bodyRect.right * zoomFactor);
41 42
42 return {x: left, y: top, width: right - left, height: bottom - top}; 43 return {x: left, y: top, width: right - left, height: bottom - top};
43 } 44 }
44 45
45 update() { 46 /**
47 * @param {boolean=} force
48 */
49 update(force) {
46 delete this._updateId; 50 delete this._updateId;
47 var rect = this._dipPageRect(); 51 var rect = this._dipPageRect();
48 var bounds = { 52 var bounds = {
49 x: Math.round(rect.x), 53 x: Math.round(rect.x),
50 y: Math.round(rect.y), 54 y: Math.round(rect.y),
51 height: Math.max(1, Math.round(rect.height)), 55 height: Math.max(1, Math.round(rect.height)),
52 width: Math.max(1, Math.round(rect.width)) 56 width: Math.max(1, Math.round(rect.width)),
53 }; 57 };
58 if (force) {
59 // Short term fix for Lighthouse interop.
60 --bounds.height;
61 this.dispatchEventToListeners(Emulation.InspectedPagePlaceholder.Events.Up date, bounds);
62 ++bounds.height;
63 }
54 this.dispatchEventToListeners(Emulation.InspectedPagePlaceholder.Events.Upda te, bounds); 64 this.dispatchEventToListeners(Emulation.InspectedPagePlaceholder.Events.Upda te, bounds);
55 } 65 }
56 }; 66 };
57 67
68 /**
69 * @return {!Emulation.InspectedPagePlaceholder}
70 */
71 Emulation.InspectedPagePlaceholder.instance = function() {
72 return singleton(Emulation.InspectedPagePlaceholder);
73 };
74
58 /** @enum {symbol} */ 75 /** @enum {symbol} */
59 Emulation.InspectedPagePlaceholder.Events = { 76 Emulation.InspectedPagePlaceholder.Events = {
60 Update: Symbol('Update') 77 Update: Symbol('Update')
61 }; 78 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698