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));
|
out->min_size.reset(new gfx::Size(size));
|
||||||
if (params.Get("max", &size))
|
if (params.Get("max", &size))
|
||||||
out->max_size.reset(new gfx::Size(size));
|
out->max_size.reset(new gfx::Size(size));
|
||||||
|
if (params.Get("elementSize", &size))
|
||||||
|
out->normal_size.reset(new gfx::Size(size));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -476,6 +478,7 @@ void WebContents::WillAttach(content::WebContents* embedder_web_contents,
|
||||||
bool is_full_page_plugin) {
|
bool is_full_page_plugin) {
|
||||||
embedder_web_contents_ = embedder_web_contents;
|
embedder_web_contents_ = embedder_web_contents;
|
||||||
element_instance_id_ = element_instance_id;
|
element_instance_id_ = element_instance_id;
|
||||||
|
is_full_page_plugin_ = is_full_page_plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::Destroy() {
|
void WebContents::Destroy() {
|
||||||
|
|
|
@ -41,7 +41,6 @@ createGuest = (embedder, params) ->
|
||||||
guest = webContents.create
|
guest = webContents.create
|
||||||
isGuest: true
|
isGuest: true
|
||||||
guestInstanceId: id
|
guestInstanceId: id
|
||||||
storagePartitionId: params.storagePartitionId
|
|
||||||
guestInstances[id] = {guest, embedder}
|
guestInstances[id] = {guest, embedder}
|
||||||
|
|
||||||
# Destroy guest when the embedder is gone or navigated.
|
# Destroy guest when the embedder is gone or navigated.
|
||||||
|
@ -58,9 +57,12 @@ createGuest = (embedder, params) ->
|
||||||
delete @attachParams
|
delete @attachParams
|
||||||
|
|
||||||
@viewInstanceId = params.instanceId
|
@viewInstanceId = params.instanceId
|
||||||
min = width: params.minwidth, height: params.minheight
|
@setSize
|
||||||
max = width: params.maxwidth, height: params.maxheight
|
enableAutoSize: params.autosize
|
||||||
@setSize params.autosize, min, max
|
min:
|
||||||
|
width: params.minwidth, height: params.minheight
|
||||||
|
max:
|
||||||
|
width: params.maxwidth, height: params.maxheight
|
||||||
|
|
||||||
if params.src
|
if params.src
|
||||||
opts = {}
|
opts = {}
|
||||||
|
@ -123,7 +125,7 @@ destroyGuest = (embedder, id) ->
|
||||||
delete reverseEmbedderElementsMap[id]
|
delete reverseEmbedderElementsMap[id]
|
||||||
delete embedderElementsMap[key]
|
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)
|
event.sender.send "ATOM_SHELL_RESPONSE_#{requestId}", createGuest(event.sender, params)
|
||||||
|
|
||||||
ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_ATTACH_GUEST', (event, elementInstanceId, guestInstanceId, 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_IPC_MESSAGE-#{viewInstanceId}"
|
||||||
ipc.removeAllListeners "ATOM_SHELL_GUEST_VIEW_INTERNAL_SIZE_CHANGED-#{viewInstanceId}"
|
ipc.removeAllListeners "ATOM_SHELL_GUEST_VIEW_INTERNAL_SIZE_CHANGED-#{viewInstanceId}"
|
||||||
|
|
||||||
createGuest: (type, params, callback) ->
|
createGuest: (params, callback) ->
|
||||||
requestId++
|
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
|
ipc.once "ATOM_SHELL_RESPONSE_#{requestId}", callback
|
||||||
|
|
||||||
attachGuest: (elementInstanceId, guestInstanceId, params) ->
|
attachGuest: (elementInstanceId, guestInstanceId, params) ->
|
||||||
|
|
|
@ -88,7 +88,7 @@ class WebViewImpl
|
||||||
|
|
||||||
return unless @guestInstanceId
|
return unless @guestInstanceId
|
||||||
|
|
||||||
guestViewInternal.attachGuest @internalInstanceId, @guestInstanceId, @buildAttachParams()
|
guestViewInternal.attachGuest @internalInstanceId, @guestInstanceId, @buildParams()
|
||||||
|
|
||||||
onSizeChanged: (webViewEvent) ->
|
onSizeChanged: (webViewEvent) ->
|
||||||
newWidth = webViewEvent.newWidth
|
newWidth = webViewEvent.newWidth
|
||||||
|
@ -121,9 +121,7 @@ class WebViewImpl
|
||||||
@dispatchEvent webViewEvent
|
@dispatchEvent webViewEvent
|
||||||
|
|
||||||
createGuest: ->
|
createGuest: ->
|
||||||
params =
|
guestViewInternal.createGuest @buildParams(), (guestInstanceId) =>
|
||||||
storagePartitionId: @attributes[webViewConstants.ATTRIBUTE_PARTITION].getValue()
|
|
||||||
guestViewInternal.createGuest 'webview', params, (guestInstanceId) =>
|
|
||||||
@attachWindow guestInstanceId
|
@attachWindow guestInstanceId
|
||||||
|
|
||||||
dispatchEvent: (webViewEvent) ->
|
dispatchEvent: (webViewEvent) ->
|
||||||
|
@ -156,21 +154,29 @@ class WebViewImpl
|
||||||
onAttach: (storagePartitionId) ->
|
onAttach: (storagePartitionId) ->
|
||||||
@attributes[webViewConstants.ATTRIBUTE_PARTITION].setValue storagePartitionId
|
@attributes[webViewConstants.ATTRIBUTE_PARTITION].setValue storagePartitionId
|
||||||
|
|
||||||
buildAttachParams: ->
|
buildParams: ->
|
||||||
params =
|
params =
|
||||||
instanceId: @viewInstanceId
|
instanceId: @viewInstanceId
|
||||||
userAgentOverride: @userAgentOverride
|
userAgentOverride: @userAgentOverride
|
||||||
for attributeName, attribute of @attributes
|
for attributeName, attribute of @attributes
|
||||||
params[attributeName] = attribute.getValue()
|
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
|
params
|
||||||
|
|
||||||
attachWindow: (guestInstanceId) ->
|
attachWindow: (guestInstanceId) ->
|
||||||
@guestInstanceId = guestInstanceId
|
@guestInstanceId = guestInstanceId
|
||||||
params = @buildAttachParams()
|
|
||||||
|
|
||||||
return true unless @internalInstanceId
|
return true unless @internalInstanceId
|
||||||
|
|
||||||
guestViewInternal.attachGuest @internalInstanceId, @guestInstanceId, params
|
guestViewInternal.attachGuest @internalInstanceId, @guestInstanceId, @buildParams()
|
||||||
|
|
||||||
# Registers browser plugin <object> custom element.
|
# Registers browser plugin <object> custom element.
|
||||||
registerBrowserPluginElement = ->
|
registerBrowserPluginElement = ->
|
||||||
|
|
Loading…
Reference in a new issue