Skip to content

Commit b87762f

Browse files
Jahanzeb Sherwanirogerwang
authored andcommitted
Add support for nwWindow.setShadow(bool) on Mac
1 parent aec4ae4 commit b87762f

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

src/api/nw_current_window_internal.idl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ namespace nw.currentWindowInternal {
2323

2424
interface Functions {
2525
static void close(optional boolean force);
26+
static void setShadow(boolean shadow);
2627
static void showDevToolsInternal(optional ShowDevToolsCallback callback);
2728
static void closeDevTools();
2829
static void setBadgeLabel(DOMString badge);

src/api/nw_window_api.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,17 @@ bool NwCurrentWindowInternalGetTitleInternalFunction::RunNWSync(base::ListValue*
621621
return true;
622622
}
623623

624+
bool NwCurrentWindowInternalSetShadowFunction::RunAsync() {
625+
#if defined(OS_MACOSX)
626+
EXTENSION_FUNCTION_VALIDATE(args_);
627+
bool shadow;
628+
EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(0, &shadow));
629+
AppWindow* window = getAppWindow(this);
630+
SetShadowOnWindow(window->GetNativeWindow(), shadow);
631+
#endif
632+
return true;
633+
}
634+
624635
bool NwCurrentWindowInternalSetTitleInternalFunction::RunNWSync(base::ListValue* response, std::string* error) {
625636
EXTENSION_FUNCTION_VALIDATE(args_);
626637
std::string title;

src/api/nw_window_api.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,19 @@ class NwCurrentWindowInternalSetMenuFunction : public NWSyncExtensionFunction {
120120
DISALLOW_COPY_AND_ASSIGN(NwCurrentWindowInternalSetMenuFunction);
121121
};
122122

123+
class NwCurrentWindowInternalSetShadowFunction : public AsyncExtensionFunction {
124+
public:
125+
NwCurrentWindowInternalSetShadowFunction(){}
126+
127+
protected:
128+
~NwCurrentWindowInternalSetShadowFunction() override {}
129+
void SetShadowOnWindow(NSWindow *window, bool shadow);
130+
131+
// ExtensionFunction:
132+
bool RunAsync() override;
133+
DECLARE_EXTENSION_FUNCTION("nw.currentWindowInternal.setShadow", UNKNOWN)
134+
};
135+
123136
class NwCurrentWindowInternalSetBadgeLabelFunction : public AsyncExtensionFunction {
124137
public:
125138
NwCurrentWindowInternalSetBadgeLabelFunction(){}

src/api/nw_window_api_mac.mm

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#import <Appkit/NSDocktile.h>
99
#import <Appkit/NSImageView.h>
1010
#import <Appkit/NSProgressIndicator.h>
11+
#import <Appkit/NSWindow.h>
1112

1213
@interface NWProgressBar : NSProgressIndicator
1314
@end
@@ -44,7 +45,11 @@ - (void)drawRect:(NSRect)dirtyRect {
4445
@end
4546

4647
namespace extensions {
47-
48+
49+
void NwCurrentWindowInternalSetShadowFunction::SetShadowOnWindow(NSWindow *window, bool shadow) {
50+
window.hasShadow = shadow;
51+
}
52+
4853
bool NwCurrentWindowInternalSetBadgeLabelFunction::RunAsync() {
4954
EXTENSION_FUNCTION_VALIDATE(args_);
5055
std::string badge;

src/resources/api_nw_window.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,10 @@ nw_binding.registerCustomHook(function(bindingsAPI) {
379379
return this;
380380
};
381381

382+
NWWindow.prototype.setShadow = function(shadow) {
383+
currentNWWindowInternal.setShadow(shadow);
384+
}
385+
382386
NWWindow.prototype.showDevTools = function(frm, callback) {
383387
var id = '';
384388
if (typeof frm === 'string')

0 commit comments

Comments
 (0)