2018-05-01 04:28:22 +00:00
|
|
|
// Copyright (c) 2018 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_UI_VIEWS_ROOT_VIEW_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_UI_VIEWS_ROOT_VIEW_H_
|
2018-05-01 04:28:22 +00:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
2024-05-15 18:45:47 +00:00
|
|
|
#include "base/memory/raw_ref.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/ui/accelerator_util.h"
|
2018-05-01 04:28:22 +00:00
|
|
|
#include "ui/views/view.h"
|
2018-10-29 18:08:47 +00:00
|
|
|
#include "ui/views/view_tracker.h"
|
2018-05-01 04:28:22 +00:00
|
|
|
|
2024-06-07 21:18:35 +00:00
|
|
|
namespace input {
|
2018-05-01 04:28:22 +00:00
|
|
|
struct NativeWebKeyboardEvent;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace electron {
|
|
|
|
|
|
|
|
class ElectronMenuModel;
|
|
|
|
class MenuBar;
|
|
|
|
class NativeWindow;
|
|
|
|
|
|
|
|
class RootView : public views::View {
|
|
|
|
public:
|
|
|
|
explicit RootView(NativeWindow* window);
|
|
|
|
~RootView() override;
|
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
|
|
|
RootView(const RootView&) = delete;
|
|
|
|
RootView& operator=(const RootView&) = delete;
|
|
|
|
|
2018-05-01 04:28:22 +00:00
|
|
|
void SetMenu(ElectronMenuModel* menu_model);
|
|
|
|
bool HasMenu() const;
|
|
|
|
int GetMenuBarHeight() const;
|
|
|
|
void SetAutoHideMenuBar(bool auto_hide);
|
2024-01-30 02:43:28 +00:00
|
|
|
bool is_menu_bar_auto_hide() const { return menu_bar_autohide_; }
|
2018-05-01 04:28:22 +00:00
|
|
|
void SetMenuBarVisibility(bool visible);
|
2024-01-30 02:43:28 +00:00
|
|
|
bool is_menu_bar_visible() const { return menu_bar_visible_; }
|
2024-06-07 21:18:35 +00:00
|
|
|
void HandleKeyEvent(const input::NativeWebKeyboardEvent& event);
|
2018-05-01 04:28:22 +00:00
|
|
|
void ResetAltState();
|
2018-10-29 18:08:47 +00:00
|
|
|
void RestoreFocus();
|
2018-11-09 21:54:16 +00:00
|
|
|
// Register/Unregister accelerators supported by the menu model.
|
|
|
|
void RegisterAcceleratorsWithFocusManager(ElectronMenuModel* menu_model);
|
|
|
|
void UnregisterAcceleratorsWithFocusManager();
|
2018-05-01 04:28:22 +00:00
|
|
|
|
2024-05-15 18:45:47 +00:00
|
|
|
views::View* GetMainView() { return &main_view_.get(); }
|
2024-04-08 17:30:23 +00:00
|
|
|
|
2018-05-01 04:28:22 +00:00
|
|
|
// views::View:
|
|
|
|
gfx::Size GetMinimumSize() const override;
|
|
|
|
gfx::Size GetMaximumSize() const override;
|
|
|
|
bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Parent window, weak ref.
|
2024-05-15 18:45:47 +00:00
|
|
|
const raw_ref<NativeWindow> window_;
|
2018-05-01 04:28:22 +00:00
|
|
|
|
|
|
|
// Menu bar.
|
|
|
|
std::unique_ptr<MenuBar> menu_bar_;
|
|
|
|
bool menu_bar_autohide_ = false;
|
|
|
|
bool menu_bar_visible_ = false;
|
|
|
|
bool menu_bar_alt_pressed_ = false;
|
|
|
|
|
2024-04-08 17:30:23 +00:00
|
|
|
// Main view area.
|
2024-05-15 18:45:47 +00:00
|
|
|
const raw_ref<views::View> main_view_;
|
2024-04-08 17:30:23 +00:00
|
|
|
|
2018-05-01 04:28:22 +00:00
|
|
|
// Map from accelerator to menu item's command id.
|
|
|
|
accelerator_util::AcceleratorTable accelerator_table_;
|
|
|
|
|
2024-05-15 18:45:47 +00:00
|
|
|
views::ViewTracker last_focused_view_tracker_;
|
2018-05-01 04:28:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace electron
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_UI_VIEWS_ROOT_VIEW_H_
|