|
@@ -9,18 +9,12 @@
|
|
|
#include "content/public/common/input/native_web_keyboard_event.h"
|
|
|
#include "shell/browser/native_window.h"
|
|
|
#include "shell/browser/ui/views/menu_bar.h"
|
|
|
+#include "ui/views/layout/box_layout.h"
|
|
|
|
|
|
namespace electron {
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
-// The menu bar height in pixels.
|
|
|
-#if BUILDFLAG(IS_WIN)
|
|
|
-const int kMenuBarHeight = 20;
|
|
|
-#else
|
|
|
-const int kMenuBarHeight = 25;
|
|
|
-#endif
|
|
|
-
|
|
|
bool IsAltKey(const content::NativeWebKeyboardEvent& event) {
|
|
|
return event.windows_key_code == ui::VKEY_MENU;
|
|
|
}
|
|
@@ -41,6 +35,12 @@ RootView::RootView(NativeWindow* window)
|
|
|
: window_(window),
|
|
|
last_focused_view_tracker_(std::make_unique<views::ViewTracker>()) {
|
|
|
set_owned_by_client();
|
|
|
+ views::BoxLayout* layout =
|
|
|
+ SetLayoutManager(std::make_unique<views::BoxLayout>(
|
|
|
+ views::BoxLayout::Orientation::kVertical));
|
|
|
+ main_view_ = AddChildView(std::make_unique<views::View>());
|
|
|
+ main_view_->SetUseDefaultFillLayout(true);
|
|
|
+ layout->SetFlexForView(main_view_, 1);
|
|
|
}
|
|
|
|
|
|
RootView::~RootView() = default;
|
|
@@ -77,7 +77,7 @@ bool RootView::HasMenu() const {
|
|
|
}
|
|
|
|
|
|
int RootView::GetMenuBarHeight() const {
|
|
|
- return kMenuBarHeight;
|
|
|
+ return menu_bar_ ? menu_bar_->GetPreferredSize().height() : 0;
|
|
|
}
|
|
|
|
|
|
void RootView::SetAutoHideMenuBar(bool auto_hide) {
|
|
@@ -90,10 +90,8 @@ void RootView::SetMenuBarVisibility(bool visible) {
|
|
|
|
|
|
menu_bar_visible_ = visible;
|
|
|
if (visible) {
|
|
|
- DCHECK_EQ(children().size(), 1ul);
|
|
|
- AddChildView(menu_bar_.get());
|
|
|
+ AddChildViewAt(menu_bar_.get(), 0);
|
|
|
} else {
|
|
|
- DCHECK_EQ(children().size(), 2ul);
|
|
|
RemoveChildView(menu_bar_.get());
|
|
|
}
|
|
|
|
|
@@ -166,21 +164,6 @@ void RootView::ResetAltState() {
|
|
|
menu_bar_alt_pressed_ = false;
|
|
|
}
|
|
|
|
|
|
-void RootView::Layout(PassKey) {
|
|
|
- if (!window_->content_view()) // Not ready yet.
|
|
|
- return;
|
|
|
-
|
|
|
- const auto menu_bar_bounds =
|
|
|
- menu_bar_visible_ ? gfx::Rect(0, 0, size().width(), kMenuBarHeight)
|
|
|
- : gfx::Rect();
|
|
|
- if (menu_bar_)
|
|
|
- menu_bar_->SetBoundsRect(menu_bar_bounds);
|
|
|
-
|
|
|
- window_->content_view()->SetBoundsRect(
|
|
|
- gfx::Rect(0, menu_bar_visible_ ? menu_bar_bounds.bottom() : 0,
|
|
|
- size().width(), size().height() - menu_bar_bounds.height()));
|
|
|
-}
|
|
|
-
|
|
|
gfx::Size RootView::GetMinimumSize() const {
|
|
|
return window_->GetMinimumSize();
|
|
|
}
|