Chromium Code Reviews| OLD | NEW |
|---|---|
| 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'); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 this.element.addEventListener('focus', this.weakWrapper(function(e) { | 104 this.element.addEventListener('focus', this.weakWrapper(function(e) { |
| 105 // Focus the BrowserPlugin when the GuestViewContainer takes focus. | 105 // Focus the BrowserPlugin when the GuestViewContainer takes focus. |
| 106 privates(this).internalElement.focus(); | 106 privates(this).internalElement.focus(); |
| 107 })); | 107 })); |
| 108 this.element.addEventListener('blur', this.weakWrapper(function(e) { | 108 this.element.addEventListener('blur', this.weakWrapper(function(e) { |
| 109 // Blur the BrowserPlugin when the GuestViewContainer loses focus. | 109 // Blur the BrowserPlugin when the GuestViewContainer loses focus. |
| 110 privates(this).internalElement.blur(); | 110 privates(this).internalElement.blur(); |
| 111 })); | 111 })); |
| 112 }; | 112 }; |
| 113 | 113 |
| 114 GuestViewContainer.prototype.focus = function() { | |
| 115 // Focus the internal element when focus() is called on the GuestView element. | |
| 116 privates(this).internalElement.focus(); | |
| 117 } | |
| 118 | |
| 114 GuestViewContainer.prototype.attachWindow$ = function() { | 119 GuestViewContainer.prototype.attachWindow$ = function() { |
| 115 if (!this.internalInstanceId) { | 120 if (!this.internalInstanceId) { |
| 116 return true; | 121 return true; |
| 117 } | 122 } |
| 118 | 123 |
| 119 this.guest.attach(this.internalInstanceId, | 124 this.guest.attach(this.internalInstanceId, |
| 120 this.viewInstanceId, | 125 this.viewInstanceId, |
| 121 this.buildParams()); | 126 this.buildParams()); |
| 122 return true; | 127 return true; |
| 123 }; | 128 }; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 {extends: 'object', prototype: proto}); | 232 {extends: 'object', prototype: proto}); |
| 228 | 233 |
| 229 delete proto.createdCallback; | 234 delete proto.createdCallback; |
| 230 delete proto.attachedCallback; | 235 delete proto.attachedCallback; |
| 231 delete proto.detachedCallback; | 236 delete proto.detachedCallback; |
| 232 delete proto.attributeChangedCallback; | 237 delete proto.attributeChangedCallback; |
| 233 }; | 238 }; |
| 234 | 239 |
| 235 // Registers the guestview container as a custom element. | 240 // Registers the guestview container as a custom element. |
| 236 // |guestViewContainerType| is the type of guestview container | 241 // |guestViewContainerType| is the type of guestview container |
| 237 // (e.g.WebViewImpl). | 242 // (e.g. WebViewImpl). |
| 238 function registerGuestViewElement(guestViewContainerType) { | 243 function registerGuestViewElement(guestViewContainerType) { |
| 239 var proto = $Object.create(HTMLElement.prototype); | 244 var proto = $Object.create(HTMLElement.prototype); |
| 240 | 245 |
| 241 proto.createdCallback = function() { | 246 proto.createdCallback = function() { |
| 242 new guestViewContainerType(this); | 247 new guestViewContainerType(this); |
| 243 }; | 248 }; |
| 244 | 249 |
| 245 proto.attachedCallback = function() { | 250 proto.attachedCallback = function() { |
| 246 var internal = privates(this).internal; | 251 var internal = privates(this).internal; |
| 247 if (!internal) { | 252 if (!internal) { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 265 var internal = privates(this).internal; | 270 var internal = privates(this).internal; |
| 266 if (!internal) { | 271 if (!internal) { |
| 267 return; | 272 return; |
| 268 } | 273 } |
| 269 internal.elementAttached = false; | 274 internal.elementAttached = false; |
| 270 internal.internalInstanceId = 0; | 275 internal.internalInstanceId = 0; |
| 271 internal.guest.destroy(); | 276 internal.guest.destroy(); |
| 272 internal.onElementDetached(); | 277 internal.onElementDetached(); |
| 273 }; | 278 }; |
| 274 | 279 |
| 280 // Override |focus| to let |internal| handle it. | |
| 281 proto.focus = function() { | |
|
Fady Samuel
2015/07/08 14:38:11
What about blur? Also does this pass existing focu
paulmeyer
2015/07/08 20:19:50
I do not believe that doing the same thing for blu
| |
| 282 var internal = privates(this).internal; | |
| 283 if (!internal) { | |
| 284 return; | |
| 285 } | |
| 286 internal.focus(); | |
| 287 }; | |
| 288 | |
| 275 // Let the specific view type add extra functionality to its custom element | 289 // Let the specific view type add extra functionality to its custom element |
| 276 // through |proto|. | 290 // through |proto|. |
| 277 if (guestViewContainerType.setupElement) { | 291 if (guestViewContainerType.setupElement) { |
| 278 guestViewContainerType.setupElement(proto); | 292 guestViewContainerType.setupElement(proto); |
| 279 } | 293 } |
| 280 | 294 |
| 281 window[guestViewContainerType.VIEW_TYPE] = | 295 window[guestViewContainerType.VIEW_TYPE] = |
| 282 DocumentNatives.RegisterElement( | 296 DocumentNatives.RegisterElement( |
| 283 guestViewContainerType.VIEW_TYPE.toLowerCase(), | 297 guestViewContainerType.VIEW_TYPE.toLowerCase(), |
| 284 {prototype: proto}); | 298 {prototype: proto}); |
| 285 | 299 |
| 286 // Delete the callbacks so developers cannot call them and produce unexpected | 300 // Delete the callbacks so developers cannot call them and produce unexpected |
| 287 // behavior. | 301 // behavior. |
| 288 delete proto.createdCallback; | 302 delete proto.createdCallback; |
| 289 delete proto.attachedCallback; | 303 delete proto.attachedCallback; |
| 290 delete proto.detachedCallback; | 304 delete proto.detachedCallback; |
| 291 delete proto.attributeChangedCallback; | 305 delete proto.attributeChangedCallback; |
| 292 } | 306 } |
| 293 | 307 |
| 294 // Exports. | 308 // Exports. |
| 295 exports.GuestViewContainer = GuestViewContainer; | 309 exports.GuestViewContainer = GuestViewContainer; |
| OLD | NEW |