]> khamidou — GitHub mirrors - electron.git/commitdiff
Pass element size when attaching
authorCheng Zhao <zcbenz@gmail.com>
Fri, 29 May 2015 03:44:49 +0000 (11:44 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 29 May 2015 03:47:54 +0000 (11:47 +0800)
atom/browser/api/atom_api_web_contents.cc
atom/browser/lib/guest-view-manager.coffee
atom/renderer/lib/web-view/guest-view-internal.coffee
atom/renderer/lib/web-view/web-view.coffee

index f82a65818a6ab04ddcac30fe44c420dd52397699..639b875fa975545eae54a8cb89973606f4538428 100644 (file)
@@ -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() {
index e59bdb42c009b49f51bee5b1f58158f5e46355ee..ab8aa8a4ad9880fbc930d602be5aff84309ba5c4 100644 (file)
@@ -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) ->
index 2abc47edffe63f187dddbdb15f1d35fb2c6dd76d..cc0a7c928e38fa32f6f84441f482b36f625222f6 100644 (file)
@@ -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) ->
index 6a8e3cf05e58a416ae3b40d63b052e7448534c5c..72961052a055110b13b3ad1a523978d40cffabb5 100644 (file)
@@ -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 = ->