Skip to content

Commit

Permalink
Merge pull request electron#949 from atom/window-transparency
Browse files Browse the repository at this point in the history
Add support for window transparency
  • Loading branch information
zcbenz committed Jan 12, 2015
2 parents 1a80bc7 + 21ba5b8 commit 1926c2c
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 129 deletions.
23 changes: 23 additions & 0 deletions atom/browser/native_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "brightray/browser/inspectable_web_contents_view.h"
#include "chrome/browser/printing/print_view_manager_basic.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/invalidate_type.h"
#include "content/public/browser/navigation_entry.h"
Expand Down Expand Up @@ -60,6 +61,10 @@ using content::NavigationEntry;
using content::RenderWidgetHostView;
using content::RenderWidgetHost;

namespace content {
CONTENT_EXPORT extern bool g_use_transparent_window;
}

namespace atom {

namespace {
Expand Down Expand Up @@ -88,6 +93,7 @@ NativeWindow::NativeWindow(content::WebContents* web_contents,
const mate::Dictionary& options)
: content::WebContentsObserver(web_contents),
has_frame_(true),
transparent_(false),
enable_larger_than_screen_(false),
is_closed_(false),
node_integration_(true),
Expand All @@ -99,9 +105,14 @@ NativeWindow::NativeWindow(content::WebContents* web_contents,
printing::PrintViewManagerBasic::CreateForWebContents(web_contents);

options.Get(switches::kFrame, &has_frame_);
options.Get(switches::kTransparent, &transparent_);
options.Get(switches::kEnableLargerThanScreen, &enable_larger_than_screen_);
options.Get(switches::kNodeIntegration, &node_integration_);

// Tell the content module to initialize renderer widget with transparent
// mode.
content::g_use_transparent_window = transparent_;

// Read icon before window is created.
options.Get(switches::kIcon, &icon_);

Expand Down Expand Up @@ -560,6 +571,18 @@ content::JavaScriptDialogManager* NativeWindow::GetJavaScriptDialogManager() {
return dialog_manager_.get();
}

void NativeWindow::RenderViewCreated(
content::RenderViewHost* render_view_host) {
if (!transparent_)
return;

content::RenderWidgetHostImpl* impl = content::RenderWidgetHostImpl::FromID(
render_view_host->GetProcess()->GetID(),
render_view_host->GetRoutingID());
if (impl)
impl->SetBackgroundOpaque(false);
}

void NativeWindow::BeforeUnloadFired(content::WebContents* tab,
bool proceed,
bool* proceed_to_fire_unload) {
Expand Down
4 changes: 4 additions & 0 deletions atom/browser/native_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
void RendererResponsive(content::WebContents* source) override;

// Implementations of content::WebContentsObserver.
void RenderViewCreated(content::RenderViewHost* render_view_host) override;
void BeforeUnloadFired(const base::TimeTicks& proceed_time) override;
bool OnMessageReceived(const IPC::Message& message) override;

Expand All @@ -287,6 +288,9 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
// Whether window has standard frame.
bool has_frame_;

// Whether window is transparent.
bool transparent_;

// Whether window can be resized larger than screen.
bool enable_larger_than_screen_;

Expand Down
113 changes: 54 additions & 59 deletions atom/browser/native_window_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,52 +26,52 @@ class NativeWindowMac : public NativeWindow {
virtual ~NativeWindowMac();

// NativeWindow implementation.
virtual void Close() OVERRIDE;
virtual void CloseImmediately() OVERRIDE;
virtual void Move(const gfx::Rect& pos) OVERRIDE;
virtual void Focus(bool focus) OVERRIDE;
virtual bool IsFocused() OVERRIDE;
virtual void Show() OVERRIDE;
virtual void ShowInactive() OVERRIDE;
virtual void Hide() OVERRIDE;
virtual bool IsVisible() OVERRIDE;
virtual void Maximize() OVERRIDE;
virtual void Unmaximize() OVERRIDE;
virtual bool IsMaximized() OVERRIDE;
virtual void Minimize() OVERRIDE;
virtual void Restore() OVERRIDE;
virtual bool IsMinimized() OVERRIDE;
virtual void SetFullScreen(bool fullscreen) OVERRIDE;
virtual bool IsFullscreen() OVERRIDE;
virtual void SetSize(const gfx::Size& size) OVERRIDE;
virtual gfx::Size GetSize() OVERRIDE;
virtual void SetContentSize(const gfx::Size& size) OVERRIDE;
virtual gfx::Size GetContentSize() OVERRIDE;
virtual void SetMinimumSize(const gfx::Size& size) OVERRIDE;
virtual gfx::Size GetMinimumSize() OVERRIDE;
virtual void SetMaximumSize(const gfx::Size& size) OVERRIDE;
virtual gfx::Size GetMaximumSize() OVERRIDE;
virtual void SetResizable(bool resizable) OVERRIDE;
virtual bool IsResizable() OVERRIDE;
virtual void SetAlwaysOnTop(bool top) OVERRIDE;
virtual bool IsAlwaysOnTop() OVERRIDE;
virtual void Center() OVERRIDE;
virtual void SetPosition(const gfx::Point& position) OVERRIDE;
virtual gfx::Point GetPosition() OVERRIDE;
virtual void SetTitle(const std::string& title) OVERRIDE;
virtual std::string GetTitle() OVERRIDE;
virtual void FlashFrame(bool flash) OVERRIDE;
virtual void SetSkipTaskbar(bool skip) OVERRIDE;
virtual void SetKiosk(bool kiosk) OVERRIDE;
virtual bool IsKiosk() OVERRIDE;
virtual void SetRepresentedFilename(const std::string& filename) OVERRIDE;
virtual std::string GetRepresentedFilename() OVERRIDE;
virtual void SetDocumentEdited(bool edited) OVERRIDE;
virtual bool IsDocumentEdited() OVERRIDE;
virtual bool HasModalDialog() OVERRIDE;
virtual gfx::NativeWindow GetNativeWindow() OVERRIDE;
virtual void SetProgressBar(double progress) OVERRIDE;
virtual void ShowDefinitionForSelection() OVERRIDE;
void Close() override;
void CloseImmediately() override;
void Move(const gfx::Rect& pos) override;
void Focus(bool focus) override;
bool IsFocused() override;
void Show() override;
void ShowInactive() override;
void Hide() override;
bool IsVisible() override;
void Maximize() override;
void Unmaximize() override;
bool IsMaximized() override;
void Minimize() override;
void Restore() override;
bool IsMinimized() override;
void SetFullScreen(bool fullscreen) override;
bool IsFullscreen() override;
void SetSize(const gfx::Size& size) override;
gfx::Size GetSize() override;
void SetContentSize(const gfx::Size& size) override;
gfx::Size GetContentSize() override;
void SetMinimumSize(const gfx::Size& size) override;
gfx::Size GetMinimumSize() override;
void SetMaximumSize(const gfx::Size& size) override;
gfx::Size GetMaximumSize() override;
void SetResizable(bool resizable) override;
bool IsResizable() override;
void SetAlwaysOnTop(bool top) override;
bool IsAlwaysOnTop() override;
void Center() override;
void SetPosition(const gfx::Point& position) override;
gfx::Point GetPosition() override;
void SetTitle(const std::string& title) override;
std::string GetTitle() override;
void FlashFrame(bool flash) override;
void SetSkipTaskbar(bool skip) override;
void SetKiosk(bool kiosk) override;
bool IsKiosk() override;
void SetRepresentedFilename(const std::string& filename) override;
std::string GetRepresentedFilename() override;
void SetDocumentEdited(bool edited) override;
bool IsDocumentEdited() override;
bool HasModalDialog() override;
gfx::NativeWindow GetNativeWindow() override;
void SetProgressBar(double progress) override;
void ShowDefinitionForSelection() override;

// Returns true if |point| in local Cocoa coordinate system falls within
// the draggable region.
Expand All @@ -83,23 +83,22 @@ class NativeWindowMac : public NativeWindow {
// Clip web view to rounded corner.
void ClipWebView();

SkRegion* draggable_region() const { return draggable_region_.get(); }

protected:
virtual void UpdateDraggableRegions(
const std::vector<DraggableRegion>& regions) OVERRIDE;
void UpdateDraggableRegions(
const std::vector<DraggableRegion>& regions) override;

// Implementations of content::WebContentsDelegate.
virtual void HandleKeyboardEvent(
void HandleKeyboardEvent(
content::WebContents*,
const content::NativeWebKeyboardEvent&) OVERRIDE;
const content::NativeWebKeyboardEvent&) override;

private:
void InstallView();
void UninstallView();
void InstallDraggableRegionViews();
void UpdateDraggableRegionsForCustomDrag(
const std::vector<DraggableRegion>& regions);

// Install the drag view, which will cover the whole window and decides
// whehter we can drag.
void InstallDraggableRegionView();

base::scoped_nsobject<NSWindow> window_;

Expand All @@ -113,10 +112,6 @@ class NativeWindowMac : public NativeWindow {
// The presentation options before entering kiosk mode.
NSApplicationPresentationOptions kiosk_options_;

// For system drag, the whole window is draggable and the non-draggable areas
// have to been explicitly excluded.
std::vector<gfx::Rect> system_drag_exclude_areas_;

// For custom drag, the whole window is non-draggable and the draggable region
// has to been explicitly provided.
scoped_ptr<SkRegion> draggable_region_; // used in custom drag.
Expand Down
Loading

0 comments on commit 1926c2c

Please sign in to comment.