root_view.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright (c) 2018 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ELECTRON_SHELL_BROWSER_UI_VIEWS_ROOT_VIEW_H_
  5. #define ELECTRON_SHELL_BROWSER_UI_VIEWS_ROOT_VIEW_H_
  6. #include <memory>
  7. #include "base/memory/raw_ref.h"
  8. #include "shell/browser/ui/accelerator_util.h"
  9. #include "ui/views/view.h"
  10. #include "ui/views/view_tracker.h"
  11. namespace input {
  12. struct NativeWebKeyboardEvent;
  13. }
  14. namespace electron {
  15. class ElectronMenuModel;
  16. class MenuBar;
  17. class NativeWindow;
  18. class RootView : public views::View {
  19. public:
  20. explicit RootView(NativeWindow* window);
  21. ~RootView() override;
  22. // disable copy
  23. RootView(const RootView&) = delete;
  24. RootView& operator=(const RootView&) = delete;
  25. void SetMenu(ElectronMenuModel* menu_model);
  26. bool HasMenu() const;
  27. int GetMenuBarHeight() const;
  28. void SetAutoHideMenuBar(bool auto_hide);
  29. bool is_menu_bar_auto_hide() const { return menu_bar_autohide_; }
  30. void SetMenuBarVisibility(bool visible);
  31. bool is_menu_bar_visible() const { return menu_bar_visible_; }
  32. void HandleKeyEvent(const input::NativeWebKeyboardEvent& event);
  33. void ResetAltState();
  34. void RestoreFocus();
  35. // Register/Unregister accelerators supported by the menu model.
  36. void RegisterAcceleratorsWithFocusManager(ElectronMenuModel* menu_model);
  37. void UnregisterAcceleratorsWithFocusManager();
  38. views::View* GetMainView() { return &main_view_.get(); }
  39. // views::View:
  40. gfx::Size GetMinimumSize() const override;
  41. gfx::Size GetMaximumSize() const override;
  42. bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
  43. private:
  44. // Parent window, weak ref.
  45. const raw_ref<NativeWindow> window_;
  46. // Menu bar.
  47. std::unique_ptr<MenuBar> menu_bar_;
  48. bool menu_bar_autohide_ = false;
  49. bool menu_bar_visible_ = false;
  50. bool menu_bar_alt_pressed_ = false;
  51. // Main view area.
  52. const raw_ref<views::View> main_view_;
  53. // Map from accelerator to menu item's command id.
  54. accelerator_util::AcceleratorTable accelerator_table_;
  55. views::ViewTracker last_focused_view_tracker_;
  56. };
  57. } // namespace electron
  58. #endif // ELECTRON_SHELL_BROWSER_UI_VIEWS_ROOT_VIEW_H_