const mate::Dictionary& options)
: NativeWindow(web_contents, options),
window_(new views::Widget),
- menu_bar_(NULL),
web_view_(inspectable_web_contents()->GetView()->GetView()),
+ menu_bar_autohide_(false),
+ menu_bar_show_(false),
keyboard_event_handler_(new views::UnhandledKeyboardEventHandler),
use_content_size_(false),
resizable_(true) {
options.Get(switches::kResizable, &resizable_);
options.Get(switches::kTitle, &title_);
+ options.Get(switches::kAutoHideMenuBar, &menu_bar_autohide_);
int width = 800, height = 600;
options.Get(switches::kWidth, &width);
gfx::Size content_size =
window_->non_client_view()->frame_view()->GetBoundsForClientView().size();
- if (menu_bar_)
+ if (menu_bar_ && menu_bar_show_)
content_size.set_height(content_size.height() - kMenuBarHeight);
return content_size;
}
if (!menu_bar_) {
gfx::Size content_size = GetContentSize();
- menu_bar_ = new MenuBar;
- AddChildViewAt(menu_bar_, 0);
-
- if (use_content_size_)
- SetContentSize(content_size);
+ menu_bar_.reset(new MenuBar);
+ menu_bar_->set_owned_by_client();
+
+ if (!menu_bar_autohide_) {
+ SetMenuBarVisibility(true);
+ if (use_content_size_)
+ SetContentSize(content_size);
+ }
}
menu_bar_->SetMenu(menu_model);
void NativeWindowViews::HandleKeyboardEvent(
content::WebContents*,
const content::NativeWebKeyboardEvent& event) {
+ if (menu_bar_autohide_ &&
+ (event.modifiers & content::NativeWebKeyboardEvent::AltKey) &&
+ (event.windowsKeyCode == 164 || event.windowsKeyCode == 165) &&
+ (event.type == blink::WebInputEvent::RawKeyDown)) {
+ SetMenuBarVisibility(!menu_bar_show_);
+ Layout();
+ }
+
keyboard_event_handler_->HandleKeyboardEvent(event, GetFocusManager());
}
const gfx::Rect& bounds) {
gfx::Rect window_bounds =
window_->non_client_view()->GetWindowBoundsForClientBounds(bounds);
- if (menu_bar_)
+ if (menu_bar_ && menu_bar_show_)
window_bounds.set_height(window_bounds.height() + kMenuBarHeight);
return window_bounds;
}
+void NativeWindowViews::SetMenuBarVisibility(bool visible) {
+ if (!menu_bar_)
+ return;
+
+ menu_bar_show_ = visible;
+ if (visible)
+ AddChildView(menu_bar_.get());
+ else
+ RemoveChildView(menu_bar_.get());
+}
+
// static
NativeWindow* NativeWindow::Create(content::WebContents* web_contents,
const mate::Dictionary& options) {
gfx::Rect web_view_bounds = gfx::Rect(
0, menu_height_, size.width(), size.height() - menu_height_);
- views::View* menu_bar = host->child_at(0);
- views::View* web_view = host->child_at(1);
- menu_bar->SetBoundsRect(menu_Bar_bounds);
+ views::View* web_view = host->child_at(0);
+ views::View* menu_bar = host->child_at(1);
web_view->SetBoundsRect(web_view_bounds);
+ menu_bar->SetBoundsRect(menu_Bar_bounds);
}
gfx::Size MenuLayout::GetPreferredSize(views::View* host) {