Skip to content

Commit

Permalink
adds test, adds view to AtomNSWindow and minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gerhardberger authored and kevinsawicki committed Nov 11, 2016
1 parent 2cf30c0 commit 5e62d28
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 24 deletions.
11 changes: 3 additions & 8 deletions atom/browser/api/atom_api_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -786,16 +786,11 @@ bool Window::IsVisibleOnAllWorkspaces() {
return window_->IsVisibleOnAllWorkspaces();
}

void Window::SetVibrancy(v8::Local<v8::Value> value, mate::Arguments* args) {
void Window::SetVibrancy(mate::Arguments* args) {
std::string type;

if (value->IsNull()) {
window_->SetVibrancy(std::string());
} else if (mate::ConvertFromV8(isolate(), value, &type)) {
window_->SetVibrancy(type);
} else {
args->ThrowError("Must pass a string or null");
}
args->GetNext(&type);
window_->SetVibrancy(type);
}

int32_t Window::ID() const {
Expand Down
2 changes: 1 addition & 1 deletion atom/browser/api/atom_api_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class Window : public mate::TrackableObject<Window>,
void SetVisibleOnAllWorkspaces(bool visible);
bool IsVisibleOnAllWorkspaces();

void SetVibrancy(v8::Local<v8::Value> value, mate::Arguments* args);
void SetVibrancy(mate::Arguments* args);

int32_t ID() const;
v8::Local<v8::Value> WebContents(v8::Isolate* isolate);
Expand Down
7 changes: 0 additions & 7 deletions atom/browser/native_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,6 @@ void NativeWindow::InitFromOptions(const mate::Dictionary& options) {
options.Get(options::kShow, &show);
if (show)
Show();

#if defined(OS_MACOSX)
std::string type;
if (options.Get(options::kVibrancyType, &type)) {
SetVibrancy(type);
}
#endif
}

void NativeWindow::SetSize(const gfx::Size& size, bool animate) {
Expand Down
3 changes: 0 additions & 3 deletions atom/browser/native_window_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,6 @@ class NativeWindowMac : public NativeWindow,
// The "titleBarStyle" option.
TitleBarStyle title_bar_style_;

// Vibrancy view
NSView* vibrant_view_;

DISALLOW_COPY_AND_ASSIGN(NativeWindowMac);
};

Expand Down
18 changes: 13 additions & 5 deletions atom/browser/native_window_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ @interface AtomNSWindow : EventDispatchingWindow<QLPreviewPanelDataSource, QLPre
@property BOOL disableKeyOrMainWindow;
@property NSPoint windowButtonsOffset;
@property (nonatomic, retain) AtomPreviewItem* quickLookItem;
@property (nonatomic, retain) NSView* vibrantView;

- (void)setShell:(atom::NativeWindowMac*)shell;
- (void)setEnableLargerThanScreen:(bool)enable;
Expand Down Expand Up @@ -743,6 +744,11 @@ static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,

InstallView();

std::string type;
if (options.Get(options::kVibrancyType, &type)) {
SetVibrancy(type);
}

// Set maximizable state last to ensure zoom button does not get reset
// by calls to other APIs.
SetMaximizable(maximizable);
Expand Down Expand Up @@ -1208,20 +1214,22 @@ static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
void NativeWindowMac::SetVibrancy(const std::string& type) {
if (!(base::mac::IsOSMavericks() || base::mac::IsOSYosemiteOrLater())) return;

NSView* vibrant_view = [window_ vibrantView];

if (type.empty()) {
if (vibrant_view_ == nil) return;
if (vibrant_view == nil) return;

[vibrant_view_ removeFromSuperview];
vibrant_view_ = nil;
[vibrant_view removeFromSuperview];
[window_ setVibrantView:nil];

return;
}

NSVisualEffectView* effect_view = (NSVisualEffectView*)vibrant_view_;
NSVisualEffectView* effect_view = (NSVisualEffectView*)vibrant_view;
if (effect_view == nil) {
effect_view = [[NSVisualEffectView alloc] initWithFrame:
[[window_ contentView] bounds]];
vibrant_view_ = (NSView*)effect_view;
[window_ setVibrantView:(NSView*)effect_view];

[effect_view setAutoresizingMask:
NSViewWidthSizable | NSViewHeightSizable];
Expand Down
12 changes: 12 additions & 0 deletions spec/api-browser-window-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,18 @@ describe('browser-window module', function () {
})
})

describe('BrowserWindow.setVibrancy(type)', function () {
it('allows setting, changing, and removing the vibrancy', function () {
assert.doesNotThrow(function () {
w.setVibrancy('light')
w.setVibrancy('dark')
w.setVibrancy(null)
w.setVibrancy('ultra-dark')
w.setVibrancy('')
})
})
})

describe('BrowserWindow.fromId(id)', function () {
it('returns the window with id', function () {
assert.equal(w.id, BrowserWindow.fromId(w.id).id)
Expand Down

0 comments on commit 5e62d28

Please sign in to comment.