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

Side by Side Diff: extensions/renderer/resources/guest_view/guest_view_container.js

Issue 987473002: Added the onResize and onContentResize events to GuestViewEvents. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Small fix. Created 5 years, 9 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 // This module implements the shared functionality for different guestview 5 // This module implements the shared functionality for different guestview
6 // containers, such as web_view, app_view, etc. 6 // containers, such as web_view, app_view, etc.
7 7
8 var DocumentNatives = requireNative('document_natives'); 8 var DocumentNatives = requireNative('document_natives');
9 var GuestView = require('guestView').GuestView; 9 var GuestView = require('guestView').GuestView;
10 var GuestViewInternalNatives = requireNative('guest_view_internal'); 10 var GuestViewInternalNatives = requireNative('guest_view_internal');
11 var IdGenerator = requireNative('id_generator'); 11 var IdGenerator = requireNative('id_generator');
12 12
13 function GuestViewContainer(element, viewType) { 13 function GuestViewContainer(element, viewType) {
14 privates(element).internal = this; 14 privates(element).internal = this;
15 this.element = element; 15 this.element = element;
16 this.elementAttached = false; 16 this.elementAttached = false;
17 this.guest = new GuestView(viewType);
18 this.viewInstanceId = IdGenerator.GetNextId(); 17 this.viewInstanceId = IdGenerator.GetNextId();
19 this.viewType = viewType; 18 this.viewType = viewType;
20 19
20 this.setupGuestProperty();
21 this.guest = new GuestView(viewType);
22
21 privates(this).browserPluginElement = this.createBrowserPluginElement(); 23 privates(this).browserPluginElement = this.createBrowserPluginElement();
22 this.setupFocusPropagation(); 24 this.setupFocusPropagation();
23 25
24 var shadowRoot = this.element.createShadowRoot(); 26 var shadowRoot = this.element.createShadowRoot();
25 shadowRoot.appendChild(privates(this).browserPluginElement); 27 shadowRoot.appendChild(privates(this).browserPluginElement);
26 } 28 }
27 29
28 // Forward public API methods from |proto| to their internal implementations. 30 // Forward public API methods from |proto| to their internal implementations.
29 GuestViewContainer.forwardApiMethods = function(proto, apiMethods) { 31 GuestViewContainer.forwardApiMethods = function(proto, apiMethods) {
30 var createProtoHandler = function(m) { 32 var createProtoHandler = function(m) {
(...skipping 15 matching lines...) Expand all
46 window.addEventListener('readystatechange', function listener(event) { 48 window.addEventListener('readystatechange', function listener(event) {
47 if (document.readyState == 'loading') { 49 if (document.readyState == 'loading') {
48 return; 50 return;
49 } 51 }
50 52
51 registerBrowserPluginElement( 53 registerBrowserPluginElement(
52 guestViewContainerType.VIEW_TYPE.toLowerCase()); 54 guestViewContainerType.VIEW_TYPE.toLowerCase());
53 registerGuestViewElement(guestViewContainerType); 55 registerGuestViewElement(guestViewContainerType);
54 window.removeEventListener(event.type, listener, useCapture); 56 window.removeEventListener(event.type, listener, useCapture);
55 }, useCapture); 57 }, useCapture);
58 };
59
60 // Create the 'guest' property to track new GuestViews and always listen for
61 // their resizes.
62 GuestViewContainer.prototype.setupGuestProperty = function() {
63 Object.defineProperty(this, 'guest', {
64 get: function() {
65 return privates(this).guest;
66 }.bind(this),
67 set: function(value) {
68 privates(this).guest = value;
69 if (!value) {
70 return;
71 }
72 privates(this).guest.onresize = function(e) {
73 // Dispatch the 'contentresize' event.
74 var contentResizeEvent = new Event('contentresize', { bubbles: true });
75 contentResizeEvent.oldWidth = e.oldWidth;
76 contentResizeEvent.oldHeight = e.oldHeight;
77 contentResizeEvent.newWidth = e.newWidth;
78 contentResizeEvent.newHeight = e.newHeight;
79 this.dispatchEvent(contentResizeEvent);
80 }.bind(this);
81 }.bind(this),
82 enumerable: true
83 });
56 }; 84 };
57 85
58 GuestViewContainer.prototype.createBrowserPluginElement = function() { 86 GuestViewContainer.prototype.createBrowserPluginElement = function() {
59 // We create BrowserPlugin as a custom element in order to observe changes 87 // We create BrowserPlugin as a custom element in order to observe changes
60 // to attributes synchronously. 88 // to attributes synchronously.
61 var browserPluginElement = 89 var browserPluginElement =
62 new GuestViewContainer[this.viewType + 'BrowserPlugin'](); 90 new GuestViewContainer[this.viewType + 'BrowserPlugin']();
63 privates(browserPluginElement).internal = this; 91 privates(browserPluginElement).internal = this;
64 return browserPluginElement; 92 return browserPluginElement;
65 }; 93 };
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 return; 135 return;
108 } 136 }
109 this.guest.attach(this.internalInstanceId, 137 this.guest.attach(this.internalInstanceId,
110 this.viewInstanceId, 138 this.viewInstanceId,
111 this.buildParams()); 139 this.buildParams());
112 } 140 }
113 }; 141 };
114 142
115 GuestViewContainer.prototype.onElementResize = function(oldWidth, oldHeight, 143 GuestViewContainer.prototype.onElementResize = function(oldWidth, oldHeight,
116 newWidth, newHeight) { 144 newWidth, newHeight) {
145 // Dispatch the 'resize' event.
146 var resizeEvent = new Event('resize', { bubbles: true });
147 resizeEvent.oldWidth = oldWidth;
148 resizeEvent.oldHeight = oldHeight;
149 resizeEvent.newWidth = newWidth;
150 resizeEvent.newHeight = newHeight;
151 this.dispatchEvent(resizeEvent);
152
117 if (!this.guest.getId()) 153 if (!this.guest.getId())
118 return; 154 return;
119 this.guest.setSize( 155 this.guest.setSize({normal: {width: newWidth, height: newHeight}});
120 {normal: {width: newWidth, height: newHeight}});
121 }; 156 };
122 157
123 GuestViewContainer.prototype.buildParams = function() { 158 GuestViewContainer.prototype.buildParams = function() {
124 var params = this.buildContainerParams(); 159 var params = this.buildContainerParams();
125 params['instanceId'] = this.viewInstanceId; 160 params['instanceId'] = this.viewInstanceId;
126 var elementRect = this.element.getBoundingClientRect(); 161 var elementRect = this.element.getBoundingClientRect();
127 params['elementWidth'] = parseInt(elementRect.width); 162 params['elementWidth'] = parseInt(elementRect.width);
128 params['elementHeight'] = parseInt(elementRect.height); 163 params['elementHeight'] = parseInt(elementRect.height);
129 return params; 164 return params;
130 }; 165 };
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 // Delete the callbacks so developers cannot call them and produce unexpected 262 // Delete the callbacks so developers cannot call them and produce unexpected
228 // behavior. 263 // behavior.
229 delete proto.createdCallback; 264 delete proto.createdCallback;
230 delete proto.attachedCallback; 265 delete proto.attachedCallback;
231 delete proto.detachedCallback; 266 delete proto.detachedCallback;
232 delete proto.attributeChangedCallback; 267 delete proto.attributeChangedCallback;
233 } 268 }
234 269
235 // Exports. 270 // Exports.
236 exports.GuestViewContainer = GuestViewContainer; 271 exports.GuestViewContainer = GuestViewContainer;
OLDNEW
« no previous file with comments | « extensions/renderer/resources/guest_view/guest_view.js ('k') | extensions/renderer/resources/guest_view/guest_view_events.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698