Pass element size when attaching
This commit is contained in:
parent
b45ed8d9a2
commit
e4bb456964
4 changed files with 26 additions and 15 deletions
|
@ -62,6 +62,8 @@ struct Converter<atom::api::SetSizeParams> {
|
|||
out->min_size.reset(new gfx::Size(size));
|
||||
if (params.Get("max", &size))
|
||||
out->max_size.reset(new gfx::Size(size));
|
||||
if (params.Get("elementSize", &size))
|
||||
out->normal_size.reset(new gfx::Size(size));
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
@ -476,6 +478,7 @@ void WebContents::WillAttach(content::WebContents* embedder_web_contents,
|
|||
bool is_full_page_plugin) {
|
||||
embedder_web_contents_ = embedder_web_contents;
|
||||
element_instance_id_ = element_instance_id;
|
||||
is_full_page_plugin_ = is_full_page_plugin;
|
||||
}
|
||||
|
||||
void WebContents::Destroy() {
|
||||
|
|
|
@ -41,7 +41,6 @@ createGuest = (embedder, params) ->
|
|||
guest = webContents.create
|
||||
isGuest: true
|
||||
guestInstanceId: id
|
||||
storagePartitionId: params.storagePartitionId
|
||||
guestInstances[id] = {guest, embedder}
|
||||
|
||||
# Destroy guest when the embedder is gone or navigated.
|
||||
|
@ -58,9 +57,12 @@ createGuest = (embedder, params) ->
|
|||
delete @attachParams
|
||||
|
||||
@viewInstanceId = params.instanceId
|
||||
min = width: params.minwidth, height: params.minheight
|
||||
max = width: params.maxwidth, height: params.maxheight
|
||||
@setSize params.autosize, min, max
|
||||
@setSize
|
||||
enableAutoSize: params.autosize
|
||||
min:
|
||||
width: params.minwidth, height: params.minheight
|
||||
max:
|
||||
width: params.maxwidth, height: params.maxheight
|
||||
|
||||
if params.src
|
||||
opts = {}
|
||||
|
@ -123,7 +125,7 @@ destroyGuest = (embedder, id) ->
|
|||
delete reverseEmbedderElementsMap[id]
|
||||
delete embedderElementsMap[key]
|
||||
|
||||
ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_CREATE_GUEST', (event, type, params, requestId) ->
|
||||
ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_CREATE_GUEST', (event, params, requestId) ->
|
||||
event.sender.send "ATOM_SHELL_RESPONSE_#{requestId}", createGuest(event.sender, params)
|
||||
|
||||
ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_ATTACH_GUEST', (event, elementInstanceId, guestInstanceId, params) ->
|
||||
|
|
|
@ -55,9 +55,9 @@ module.exports =
|
|||
ipc.removeAllListeners "ATOM_SHELL_GUEST_VIEW_INTERNAL_IPC_MESSAGE-#{viewInstanceId}"
|
||||
ipc.removeAllListeners "ATOM_SHELL_GUEST_VIEW_INTERNAL_SIZE_CHANGED-#{viewInstanceId}"
|
||||
|
||||
createGuest: (type, params, callback) ->
|
||||
createGuest: (params, callback) ->
|
||||
requestId++
|
||||
ipc.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_CREATE_GUEST', type, params, requestId
|
||||
ipc.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_CREATE_GUEST', params, requestId
|
||||
ipc.once "ATOM_SHELL_RESPONSE_#{requestId}", callback
|
||||
|
||||
attachGuest: (elementInstanceId, guestInstanceId, params) ->
|
||||
|
|
|
@ -88,7 +88,7 @@ class WebViewImpl
|
|||
|
||||
return unless @guestInstanceId
|
||||
|
||||
guestViewInternal.attachGuest @internalInstanceId, @guestInstanceId, @buildAttachParams()
|
||||
guestViewInternal.attachGuest @internalInstanceId, @guestInstanceId, @buildParams()
|
||||
|
||||
onSizeChanged: (webViewEvent) ->
|
||||
newWidth = webViewEvent.newWidth
|
||||
|
@ -121,9 +121,7 @@ class WebViewImpl
|
|||
@dispatchEvent webViewEvent
|
||||
|
||||
createGuest: ->
|
||||
params =
|
||||
storagePartitionId: @attributes[webViewConstants.ATTRIBUTE_PARTITION].getValue()
|
||||
guestViewInternal.createGuest 'webview', params, (guestInstanceId) =>
|
||||
guestViewInternal.createGuest @buildParams(), (guestInstanceId) =>
|
||||
@attachWindow guestInstanceId
|
||||
|
||||
dispatchEvent: (webViewEvent) ->
|
||||
|
@ -156,21 +154,29 @@ class WebViewImpl
|
|||
onAttach: (storagePartitionId) ->
|
||||
@attributes[webViewConstants.ATTRIBUTE_PARTITION].setValue storagePartitionId
|
||||
|
||||
buildAttachParams: ->
|
||||
buildParams: ->
|
||||
params =
|
||||
instanceId: @viewInstanceId
|
||||
userAgentOverride: @userAgentOverride
|
||||
for attributeName, attribute of @attributes
|
||||
params[attributeName] = attribute.getValue()
|
||||
# When the WebView is not participating in layout (display:none)
|
||||
# then getBoundingClientRect() would report a width and height of 0.
|
||||
# However, in the case where the WebView has a fixed size we can
|
||||
# use that value to initially size the guest so as to avoid a relayout of
|
||||
# the on display:block.
|
||||
css = window.getComputedStyle @webviewNode, null
|
||||
elementRect = @webviewNode.getBoundingClientRect()
|
||||
params.elementSize =
|
||||
width: parseInt(elementRect.width) || parseInt(css.getPropertyValue('width'))
|
||||
height: parseInt(elementRect.height) || parseInt(css.getPropertyValue('height'))
|
||||
params
|
||||
|
||||
attachWindow: (guestInstanceId) ->
|
||||
@guestInstanceId = guestInstanceId
|
||||
params = @buildAttachParams()
|
||||
|
||||
return true unless @internalInstanceId
|
||||
|
||||
guestViewInternal.attachGuest @internalInstanceId, @guestInstanceId, params
|
||||
guestViewInternal.attachGuest @internalInstanceId, @guestInstanceId, @buildParams()
|
||||
|
||||
# Registers browser plugin <object> custom element.
|
||||
registerBrowserPluginElement = ->
|
||||
|
|
Loading…
Reference in a new issue