Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implemented win.menu=null to remove menubar #4743

Merged
merged 1 commit into from
Apr 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/For Users/Advanced/Customize Menubar.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ See both [Menu](../../References/Menu.md) and [Window](../../References/Window.m

On Windows and Linux, the menubars behave exactly the same. Each window can have one menubar and they all reside bellow the titlebar.

!!! tip "Menubar in Fullscreen / Kiosk Mode"
In fullscreen or kiosk mode, menubar is visible on top of the window on Windows and Linux. Setting `win.menu` to `null` can completely remove the menubar. See also [`win.menu`](../../References/Window.md#winmenu).

### Mac OS X

!!! warning "Behavior Changed"
Expand Down
4 changes: 3 additions & 1 deletion docs/References/Window.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ Get or set window's title.

## win.menu

Get or set window's menubar. Set with a Menu with type `menubar`. See [Menu](Menu.md).
Get or set window's menubar. Set with a Menu with type `menubar`. When `win.menu` is set to `null`, the menubar is completely removed for Windows and Linux, and the menubar is cleared out on Mac.

See [Customize Menubar](../For Users/Advanced/Customize Menubar.md) for the usage of menubars. And see [Menu](Menu.md) and [MenuItem](MenuItem.md) for detailed APIs.

## win.isFullscreen

Expand Down
24 changes: 24 additions & 0 deletions src/api/nw_window_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,30 @@ NwCurrentWindowInternalClearMenuFunction::~NwCurrentWindowInternalClearMenuFunct
}

bool NwCurrentWindowInternalClearMenuFunction::RunAsync() {
AppWindow* window = getAppWindow(this);
if (!window) {
error_ = kNoAssociatedAppWindow;
return false;
}

#if defined(OS_MACOSX)
NWChangeAppMenu(NULL);
#endif

#if defined(OS_LINUX) || defined(OS_WIN)
native_app_window::NativeAppWindowViews* native_app_window_views =
static_cast<native_app_window::NativeAppWindowViews*>(
window->GetBaseWindow());

BrowserViewLayout *browser_view_layout = static_cast<BrowserViewLayout*>(native_app_window_views->GetLayoutManager());
views::View* menubar = browser_view_layout->menu_bar();
if (menubar) {
native_app_window_views->RemoveChildView(menubar);
}
browser_view_layout->set_menu_bar(NULL);
native_app_window_views->layout_();
native_app_window_views->SchedulePaint();
#endif
return true;
}

Expand Down
10 changes: 9 additions & 1 deletion src/nw_content_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@
#import "ui/gfx/mac/nswindow_frame_controls.h"

void NWChangeAppMenu(nw::Menu* menu) {
[NSApp setMainMenu:menu->menu_];
NSMenu *main_menu;

if (menu == nil) {
main_menu = [[NSMenu alloc] initWithTitle:@""];
} else {
main_menu = menu->menu_;
}

[NSApp setMainMenu:main_menu];
}

void NWSetNSWindowShowInTaskbar(extensions::NativeAppWindow* win, bool show) {
Expand Down