root_view.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 "shell/browser/ui/accelerator_util.h"
  8. #include "ui/gfx/geometry/insets.h"
  9. #include "ui/views/view.h"
  10. #include "ui/views/view_tracker.h"
  11. namespace content {
  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 IsMenuBarAutoHide() const;
  30. void SetMenuBarVisibility(bool visible);
  31. bool IsMenuBarVisible() const;
  32. void HandleKeyEvent(const content::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:
  39. void Layout() override;
  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. 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. // Map from accelerator to menu item's command id.
  52. accelerator_util::AcceleratorTable accelerator_table_;
  53. std::unique_ptr<views::ViewTracker> last_focused_view_tracker_;
  54. };
  55. } // namespace electron
  56. #endif // ELECTRON_SHELL_BROWSER_UI_VIEWS_ROOT_VIEW_H_