Skip to content

Commit 31afd7d

Browse files
committed
Transparency support in Mac OS X
1 parent b5047e3 commit 31afd7d

File tree

3 files changed

+71
-18
lines changed

3 files changed

+71
-18
lines changed

src/browser/native_window_mac.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,15 @@ class NativeWindowCocoa : public NativeWindow {
6060
virtual void SetPosition(const std::string& position) OVERRIDE;
6161
virtual void SetPosition(const gfx::Point& position) OVERRIDE;
6262
virtual gfx::Point GetPosition() OVERRIDE;
63+
virtual gfx::Point GetMousePosition() OVERRIDE;
64+
virtual void BeginOffclientMouseMove() OVERRIDE;
65+
virtual void EndOffclientMouseMove() OVERRIDE;
6366
virtual void SetTitle(const std::string& title) OVERRIDE;
6467
virtual void FlashFrame(bool flash) OVERRIDE;
6568
virtual void SetKiosk(bool kiosk) OVERRIDE;
6669
virtual bool IsKiosk() OVERRIDE;
70+
virtual void SetTransparent() OVERRIDE;
71+
virtual bool IsTransparent() OVERRIDE;
6772
virtual void SetMenu(api::Menu* menu) OVERRIDE;
6873
virtual void SetToolbarButtonEnabled(TOOLBAR_BUTTON button,
6974
bool enabled) OVERRIDE;
@@ -107,6 +112,7 @@ class NativeWindowCocoa : public NativeWindow {
107112

108113
bool is_fullscreen_;
109114
bool is_kiosk_;
115+
bool is_transparent_;
110116
NSRect restored_bounds_;
111117

112118
NSInteger attention_request_id_; // identifier from requestUserAttention

src/browser/native_window_mac.mm

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,13 @@ - (CGFloat)roundedCornerRadius;
194194
@interface ShellNSWindow : UnderlayOpenGLHostingWindow {
195195
@private
196196
content::Shell* shell_;
197+
bool is_transparent_;
197198
}
198199
- (void)setShell:(content::Shell*)shell;
199200
- (void)showDevTools:(id)sender;
200201
- (void)closeAllWindows:(id)sender;
202+
- (void)setTransparent;
203+
- (BOOL)getTransparent;
201204
@end
202205

203206
@implementation ShellNSWindow
@@ -214,6 +217,14 @@ - (void)closeAllWindows:(id)sender {
214217
api::App::CloseAllWindows();
215218
}
216219

220+
- (void)setTransparent {
221+
is_transparent_ = true;
222+
}
223+
224+
- (BOOL)getTransparent {
225+
return is_transparent_;
226+
}
227+
217228
@end
218229

219230
@interface ShellFramelessNSWindow : ShellNSWindow
@@ -231,15 +242,18 @@ - (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view {
231242
[[NSColor clearColor] set];
232243
NSRectFill(rect);
233244

234-
// Set up our clip.
235-
CGFloat cornerRadius = 4.0;
236-
if ([view respondsToSelector:@selector(roundedCornerRadius)])
237-
cornerRadius = [view roundedCornerRadius];
238-
[[NSBezierPath bezierPathWithRoundedRect:[view bounds]
239-
xRadius:cornerRadius
240-
yRadius:cornerRadius] addClip];
241-
[[NSColor whiteColor] set];
242-
NSRectFill(rect);
245+
if(![self getTransparent])
246+
{
247+
// Set up our clip.
248+
CGFloat cornerRadius = 4.0;
249+
if ([view respondsToSelector:@selector(roundedCornerRadius)])
250+
cornerRadius = [view roundedCornerRadius];
251+
[[NSBezierPath bezierPathWithRoundedRect:[view bounds]
252+
xRadius:cornerRadius
253+
yRadius:cornerRadius] addClip];
254+
[[NSColor whiteColor] set];
255+
NSRectFill(rect);
256+
}
243257
}
244258

245259
+ (NSRect)frameRectForContentRect:(NSRect)contentRect
@@ -270,6 +284,7 @@ - (NSRect)contentRectForFrameRect:(NSRect)frameRect {
270284
: NativeWindow(shell, manifest),
271285
is_fullscreen_(false),
272286
is_kiosk_(false),
287+
is_transparent_(false),
273288
attention_request_id_(0),
274289
use_system_drag_(true) {
275290
int width, height;
@@ -428,6 +443,24 @@ - (NSRect)contentRectForFrameRect:(NSRect)frameRect {
428443
return is_fullscreen_;
429444
}
430445

446+
void NativeWindowCocoa::SetTransparent() {
447+
is_transparent_ = true;
448+
restored_bounds_ = [window() frame];
449+
[window() setStyleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)];
450+
[window() setFrame:[window()
451+
frameRectForContentRect:[window() frame]]
452+
display:YES];
453+
[window() setHasShadow:NO];
454+
ShellNSWindow* swin = (ShellNSWindow*)window();
455+
[swin setTransparent];
456+
[window() setOpaque:NO];
457+
[window() setBackgroundColor:[NSColor clearColor]];
458+
}
459+
460+
bool NativeWindowCocoa::IsTransparent() {
461+
return is_transparent_;
462+
}
463+
431464
void NativeWindowCocoa::SetNonLionFullscreen(bool fullscreen) {
432465
if (fullscreen == is_fullscreen_)
433466
return;
@@ -820,6 +853,21 @@ - (NSRect)contentRectForFrameRect:(NSRect)frameRect {
820853
}
821854
}
822855

856+
gfx::Point NativeWindowCocoa::GetMousePosition() {
857+
CGEventRef event = CGEventCreate(NULL);
858+
CGPoint cursor = CGEventGetLocation(event);
859+
CFRelease(event);
860+
return gfx::Point(cursor.x,cursor.y);
861+
}
862+
863+
void NativeWindowCocoa::BeginOffclientMouseMove() {
864+
// Not implemented
865+
}
866+
867+
void NativeWindowCocoa::EndOffclientMouseMove() {
868+
// Not implemented
869+
}
870+
823871
NativeWindow* CreateNativeWindowCocoa(content::Shell* shell,
824872
base::DictionaryValue* manifest) {
825873
return new NativeWindowCocoa(shell, manifest);

src/nw_shell.cc

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -315,16 +315,15 @@ bool Shell::OnMessageReceived(const IPC::Message& message) {
315315
}
316316

317317
void Shell::RenderViewCreated(RenderViewHost* render_view_host) {
318-
std::string transparent;
319318
if(window_->IsTransparent())
320-
{
321-
SkBitmap background;
322-
background.setConfig(SkBitmap::kARGB_8888_Config, 1, 1);
323-
background.allocPixels();
324-
background.eraseARGB(0x00, 0x00, 0x00, 0x00);
325-
326-
content::RenderWidgetHostView* view = render_view_host->GetView();
327-
DCHECK(view);
319+
{
320+
SkBitmap background;
321+
background.setConfig(SkBitmap::kARGB_8888_Config, 1, 1);
322+
background.allocPixels();
323+
background.eraseARGB(0x00, 0x00, 0x00, 0x00);
324+
325+
content::RenderWidgetHostView* view = render_view_host->GetView();
326+
DCHECK(view);
328327
view->SetBackground(background);
329328
}
330329
}

0 commit comments

Comments
 (0)