Skip to content

Commit e7ff868

Browse files
committed
[Transparency] add javascript function and manifest, OSX Implementation, stubs for Linux/Windows
1 parent 324ebf1 commit e7ff868

11 files changed

+60
-2
lines changed

src/api/window/window.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ void Window::Call(const std::string& method,
268268
std::string label;
269269
if (arguments.GetString(0, &label))
270270
shell_->window()->SetBadgeLabel(label);
271+
} else if (method == "SetTransparent") {
272+
bool transparent;
273+
if (arguments.GetBoolean(0, &transparent))
274+
shell_->window()->SetTransparent(transparent);
271275
} else if (method == "SetProgressBar") {
272276
double progress;
273277
if (arguments.GetDouble(0, &progress))
@@ -315,6 +319,9 @@ void Window::CallSync(const std::string& method,
315319
gfx::Point position = shell_->window()->GetPosition();
316320
result->AppendInteger(position.x());
317321
result->AppendInteger(position.y());
322+
} else if (method == "IsTransparent") {
323+
bool transparent = shell_->window()->IsTransparent();
324+
result->AppendBoolean(transparent);
318325
} else if (method == "IsDevToolsOpen") {
319326
result->AppendBoolean(shell_->devToolsOpen());
320327
} else if (method == "ShowDevTools") {

src/api/window_bindings.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ Window.prototype.__defineGetter__('isFullscreen', function() {
249249
var result = CallObjectMethodSync(this, 'IsFullscreen', []);
250250
return Boolean(result[0]);
251251
});
252+
253+
Window.prototype.__defineGetter__('isTransparent', function() {
254+
var result = CallObjectMethodSync(this, 'IsTransparent', []);
255+
return Boolean(result[0]);
256+
});
252257

253258
Window.prototype.__defineSetter__('isKioskMode', function(flag) {
254259
if (flag)
@@ -425,6 +430,10 @@ Window.prototype.setProgressBar = function(progress) {
425430
throw new String('progress must be a number');
426431
CallObjectMethod(this, 'SetProgressBar', [ progress ]);
427432
}
433+
434+
Window.prototype.setTransparent = function(transparent) {
435+
CallObjectMethod(this, 'SetTransparent', [ transparent ]);
436+
}
428437

429438
Window.prototype.setPosition = function(position) {
430439
if (position != 'center' && position != 'mouse')

src/browser/native_window.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@ NativeWindow* NativeWindow::Create(const base::WeakPtr<content::Shell>& shell,
6969
NativeWindow::NativeWindow(const base::WeakPtr<content::Shell>& shell,
7070
base::DictionaryValue* manifest)
7171
: shell_(shell),
72+
transparent_(false),
7273
has_frame_(true),
7374
capture_page_helper_(NULL) {
7475
manifest->GetBoolean(switches::kmFrame, &has_frame_);
76+
manifest->GetBoolean(switches::kmTransparent, &transparent_);
7577

7678
LoadAppIconFromPackage(manifest);
7779
}

src/browser/native_window.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class NativeWindow {
8888
virtual void Restore() = 0;
8989
virtual void SetFullscreen(bool fullscreen) = 0;
9090
virtual bool IsFullscreen() = 0;
91+
virtual void SetTransparent(bool transparent) = 0;
9192
virtual void SetSize(const gfx::Size& size) = 0;
9293
virtual gfx::Size GetSize() = 0;
9394
virtual void SetMinimumSize(int width, int height) = 0;
@@ -140,6 +141,7 @@ class NativeWindow {
140141
bool has_frame() const { return has_frame_; }
141142
const gfx::Image& app_icon() const { return app_icon_; }
142143
void CapturePage(const std::string& image_format);
144+
bool IsTransparent() { return transparent_; }
143145

144146
protected:
145147
void OnNativeWindowDestory() {
@@ -151,6 +153,8 @@ class NativeWindow {
151153

152154
// Weak reference to parent.
153155
base::WeakPtr<content::Shell> shell_;
156+
157+
bool transparent_;
154158

155159
bool has_frame_;
156160

src/browser/native_window_aura.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class NativeWindowAura : public NativeWindow,
7878
virtual void Restore() OVERRIDE;
7979
virtual void SetFullscreen(bool fullscreen) OVERRIDE;
8080
virtual bool IsFullscreen() OVERRIDE;
81+
virtual void SetTransparent(bool transparent) OVERRIDE;
8182
virtual void SetSize(const gfx::Size& size) OVERRIDE;
8283
virtual gfx::Size GetSize() OVERRIDE;
8384
virtual void SetMinimumSize(int width, int height) OVERRIDE;

src/browser/native_window_gtk.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class NativeWindowGtk : public NativeWindow {
4848
virtual void Restore() OVERRIDE;
4949
virtual void SetFullscreen(bool fullscreen) OVERRIDE;
5050
virtual bool IsFullscreen() OVERRIDE;
51+
virtual void SetTransparent(bool transparent) OVERRIDE;
5152
virtual void SetSize(const gfx::Size& size) OVERRIDE;
5253
virtual gfx::Size GetSize() OVERRIDE;
5354
virtual void SetMinimumSize(int width, int height) OVERRIDE;

src/browser/native_window_mac.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class NativeWindowCocoa : public NativeWindow {
5252
virtual void Restore() OVERRIDE;
5353
virtual void SetFullscreen(bool fullscreen) OVERRIDE;
5454
virtual bool IsFullscreen() OVERRIDE;
55+
virtual void SetTransparent(bool transparent) OVERRIDE;
5556
virtual void SetSize(const gfx::Size& size) OVERRIDE;
5657
virtual gfx::Size GetSize() OVERRIDE;
5758
virtual void SetMinimumSize(int width, int height) OVERRIDE;
@@ -111,6 +112,9 @@ class NativeWindowCocoa : public NativeWindow {
111112

112113
// Delegate to the toolbar.
113114
base::scoped_nsobject<ShellToolbarDelegate> toolbar_delegate_;
115+
116+
// Data for transparency
117+
NSColor *opaque_color_;
114118

115119
bool is_fullscreen_;
116120
bool is_kiosk_;

src/browser/native_window_mac.mm

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include "content/nw/src/nw_package.h"
3636
#include "content/nw/src/nw_shell.h"
3737
#include "content/public/browser/native_web_keyboard_event.h"
38-
#include "content/public/browser/render_widget_host_view.h"
38+
#include "content/browser/renderer_host/render_widget_host_view_mac.h"
3939
#include "content/public/browser/web_contents.h"
4040
#include "extensions/common/draggable_region.h"
4141
#include "third_party/skia/include/core/SkRegion.h"
@@ -282,7 +282,11 @@ - (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view {
282282
[[NSBezierPath bezierPathWithRoundedRect:[view bounds]
283283
xRadius:cornerRadius
284284
yRadius:cornerRadius] addClip];
285-
[[NSColor whiteColor] set];
285+
if ([self isOpaque])
286+
[[NSColor whiteColor] set];
287+
else
288+
[[NSColor clearColor] set];
289+
286290
NSRectFill(rect);
287291
}
288292

@@ -385,10 +389,13 @@ - (void)drawRect:(NSRect)dirtyRect {
385389
defer:NO];
386390
}
387391
window_ = shell_window;
392+
opaque_color_ = [window() backgroundColor];
388393
[shell_window setShell:shell];
389394
[[window() contentView] setWantsLayer:YES];
390395
[window() setDelegate:[[NativeWindowDelegate alloc] initWithShell:shell]];
391396

397+
SetTransparent(transparent_);
398+
392399
// Disable fullscreen button when 'fullscreen' is specified to false.
393400
bool fullscreen;
394401
if (!(manifest->GetBoolean(switches::kmFullscreen, &fullscreen) &&
@@ -539,6 +546,26 @@ - (void)drawRect:(NSRect)dirtyRect {
539546
return is_fullscreen_;
540547
}
541548

549+
void NativeWindowCocoa::SetTransparent(bool transparent) {
550+
551+
if (!transparent_ && transparent) {
552+
opaque_color_ = [window() backgroundColor];
553+
}
554+
555+
[window() setHasShadow:transparent ? NO : YES];
556+
[window() setOpaque:transparent ? NO : YES];
557+
[window() setBackgroundColor:transparent ? [NSColor clearColor] : opaque_color_];
558+
559+
content::RenderWidgetHostViewMac* rwhv = static_cast<content::RenderWidgetHostViewMac*>(shell_->web_contents()->GetRenderWidgetHostView());
560+
561+
if (rwhv) {
562+
rwhv->SetBackgroundOpaque(!transparent);
563+
[rwhv->background_layer_ setBackgroundColor:CGColorGetConstantColor(transparent ? kCGColorClear : kCGColorWhite)];
564+
}
565+
566+
transparent_ = transparent;
567+
568+
}
542569
void NativeWindowCocoa::SetNonLionFullscreen(bool fullscreen) {
543570
if (fullscreen == is_fullscreen_)
544571
return;

src/common/shell_switches.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const char kmResizable[] = "resizable";
7272
const char kmAsDesktop[] = "as_desktop";
7373
const char kmFullscreen[] = "fullscreen";
7474
const char kmInitialFocus[] = "focus";
75+
const char kmTransparent[] = "transparent";
7576

7677
// Make windows icon hide show or hide in taskbar.
7778
const char kmShowInTaskbar[] = "show_in_taskbar";

src/common/shell_switches.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ extern const char kmShowInTaskbar[];
5454
extern const char kmKiosk[];
5555
extern const char kmAlwaysOnTop[];
5656
extern const char kmInitialFocus[];
57+
extern const char kmTransparent[];
5758

5859
extern const char kmWebgl[];
5960
extern const char kmJava[];

0 commit comments

Comments
 (0)