]> khamidou — GitHub mirrors - electron.git/commitdiff
Implement allowtransparency attribute
authorCheng Zhao <zcbenz@gmail.com>
Fri, 24 Oct 2014 08:48:21 +0000 (16:48 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 24 Oct 2014 08:48:21 +0000 (16:48 +0800)
atom/browser/api/atom_api_web_contents.cc
atom/browser/api/atom_api_web_contents.h
atom/browser/api/lib/web-contents.coffee
atom/browser/lib/guest-view-manager.coffee
atom/renderer/lib/guest-view-internal.coffee
atom/renderer/lib/webview.coffee

index b2a0eef6cde09bd099f8e3746b0c53c6c9a6ed2c..571ae0f7f2aa51b4057e55d3d11e2f0c9e690d49 100644 (file)
@@ -34,11 +34,13 @@ v8::Persistent<v8::ObjectTemplate> template_;
 WebContents::WebContents(content::WebContents* web_contents)
     : content::WebContentsObserver(web_contents),
       guest_instance_id_(-1),
+      guest_opaque_(true),
       auto_size_enabled_(false) {
 }
 
 WebContents::WebContents(const mate::Dictionary& options)
     : guest_instance_id_(-1),
+      guest_opaque_(true),
       auto_size_enabled_(false) {
   options.Get("guestInstanceId", &guest_instance_id_);
 
@@ -103,6 +105,13 @@ void WebContents::RenderViewReady() {
   if (!is_guest())
     return;
 
+  // We don't want to accidentally set the opacity of an interstitial page.
+  // WebContents::GetRenderWidgetHostView will return the RWHV of an
+  // interstitial page if one is showing at this time. We only want opacity
+  // to apply to web pages.
+  web_contents()->GetRenderViewHost()->GetView()->
+      SetBackgroundOpaque(guest_opaque_);
+
   content::RenderViewHost* rvh = web_contents()->GetRenderViewHost();
   if (auto_size_enabled_) {
     rvh->EnableAutoResize(min_auto_size_, max_auto_size_);
@@ -291,6 +300,17 @@ void WebContents::SetAutoSize(bool enabled,
   }
 }
 
+void WebContents::SetAllowTransparency(bool allow) {
+  if (guest_opaque_ != allow)
+    return;
+
+  guest_opaque_ = !allow;
+  if (!web_contents()->GetRenderViewHost()->GetView())
+    return;
+
+  web_contents()->GetRenderViewHost()->GetView()->SetBackgroundOpaque(!allow);
+}
+
 mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
     v8::Isolate* isolate) {
   if (template_.IsEmpty())
@@ -318,6 +338,7 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
         .SetMethod("_executeJavaScript", &WebContents::ExecuteJavaScript)
         .SetMethod("_send", &WebContents::SendIPCMessage)
         .SetMethod("setAutoSize", &WebContents::SetAutoSize)
+        .SetMethod("setAllowTransparency", &WebContents::SetAllowTransparency)
         .Build());
 
   return mate::ObjectTemplateBuilder(
index ee2fcc784d85af5fd5a6969c4f31b3ad4a6e1acc..0dcd47114dc88c3056abebe0f946c65463867167 100644 (file)
@@ -61,6 +61,9 @@ class WebContents : public mate::EventEmitter,
                    const gfx::Size& min_size,
                    const gfx::Size& max_size);
 
+  // Sets the transparency of the guest.
+  void SetAllowTransparency(bool allow);
+
   // Returns whether this is a guest view.
   bool is_guest() const { return guest_instance_id_ != -1; }
 
@@ -129,6 +132,9 @@ class WebContents : public mate::EventEmitter,
 
   DestructionCallback destruction_callback_;
 
+  // Stores whether the contents of the guest can be transparent.
+  bool guest_opaque_;
+
   // The extra parameters associated with this guest view passed
   // in from JavaScript. This will typically be the view instance ID,
   // the API to use, and view-specific parameters. These parameters
index 24f7375cb9942b590dcfbab82d4725bc07f55538..318769eab535c74f7ae45a4ab88e6c342d157a49 100644 (file)
@@ -22,14 +22,6 @@ module.exports.wrap = (webContents) ->
     else
       webContents.once 'did-finish-load', @_executeJavaScript.bind(this, code)
 
-  # Init guest web view.
-  webContents.on 'internal-did-attach', (event, params) ->
-    min = width: params.minwidth, height: params.minheight
-    max = width: params.maxwidth, height: params.maxheight
-    @setAutoSize params.autosize, min, max
-    if params.src
-      @loadUrl params.src
-
   # The processId and routingId and identify a webContents.
   webContents.getId = -> "#{@getProcessId()}-#{@getRoutingId()}"
   webContents.equal = (other) -> @getId() is other.getId()
index e66103ba1890d291f18968c6be364af340757b1b..10de5a5d6d5e0f031cc18c7f9ade0aa1dbd6b703 100644 (file)
@@ -22,7 +22,18 @@ createGuest = (embedder, params) ->
   webViewManager.addGuest id, embedder, guest
 
   # Destroy guest when the embedder is gone.
-  embedder.once 'render-view-deleted', -> destroyGuest id
+  embedder.once 'render-view-deleted', ->
+    destroyGuest id
+
+  # Init guest web view after attached.
+  guest.once 'internal-did-attach', (event, params) ->
+    min = width: params.minwidth, height: params.minheight
+    max = width: params.maxwidth, height: params.maxheight
+    @setAutoSize params.autosize, min, max
+    if params.src
+      @loadUrl params.src
+    if params.allowtransparency?
+      @setAllowTransparency params.allowtransparency
 
   id
 
@@ -35,8 +46,11 @@ destroyGuest = (id) ->
 ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_CREATE_GUEST', (event, type, params, requestId) ->
   event.sender.send "ATOM_SHELL_RESPONSE_#{requestId}", createGuest(event.sender, params)
 
-ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_DESTROY_GUEST', (event, guestInstanceId) ->
-  destroyGuest guestInstanceId
+ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_DESTROY_GUEST', (event, id) ->
+  destroyGuest id
 
-ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_SET_AUTO_SIZE', (event, guestInstanceId, params) ->
+ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_SET_AUTO_SIZE', (event, id, params) ->
   guestInstances[id]?.setAutoSize params.enableAutoSize, params.min, params.max
+
+ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_SET_ALLOW_TRANSPARENCY', (event, id, allowtransparency) ->
+  guestInstances[id]?.setAllowTransparency allowtransparency
index e2fd9b356b90813804d8eeefb344b8a4e5e255da..7fc2de3f2dde0c0e80704daa8c0a42edb2d1d915 100644 (file)
@@ -13,3 +13,6 @@ module.exports =
 
   setAutoSize: (guestInstanceId, params) ->
     ipc.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_SET_AUTO_SIZE', guestInstanceId, params
+
+  setAllowTransparency: (guestInstanceId, allowtransparency) ->
+    ipc.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_SET_ALLOW_TRANSPARENCY', guestInstanceId, allowtransparency
index 1e1ee08210fab99bc2824f820a423e6f8556edca..7a767234352586cf5fd9c584e45491155dd48ee9 100644 (file)
@@ -242,8 +242,7 @@ class WebView
 
       return unless @guestInstanceId
 
-      # FIXME
-      # WebViewInternal.setAllowTransparency @guestInstanceId, @allowtransparency
+      guestViewInternal.setAllowTransparency @guestInstanceId, @allowtransparency
     else if name is 'name'
       # We treat null attribute (attribute removed) and the empty string as
       # one case.