electron_api_view.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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_API_ELECTRON_API_VIEW_H_
  5. #define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_VIEW_H_
  6. #include <vector>
  7. #include "electron/buildflags/buildflags.h"
  8. #include "gin/handle.h"
  9. #include "shell/common/gin_helper/wrappable.h"
  10. #include "ui/views/view.h"
  11. namespace electron {
  12. namespace api {
  13. class View : public gin_helper::Wrappable<View> {
  14. public:
  15. static gin_helper::WrappableBase* New(gin::Arguments* args);
  16. static void BuildPrototype(v8::Isolate* isolate,
  17. v8::Local<v8::FunctionTemplate> prototype);
  18. #if BUILDFLAG(ENABLE_VIEWS_API)
  19. void AddChildView(gin::Handle<View> child);
  20. void AddChildViewAt(gin::Handle<View> child, size_t index);
  21. #endif
  22. views::View* view() const { return view_; }
  23. // disable copy
  24. View(const View&) = delete;
  25. View& operator=(const View&) = delete;
  26. protected:
  27. explicit View(views::View* view);
  28. View();
  29. ~View() override;
  30. // Should delete the |view_| in destructor.
  31. void set_delete_view(bool should) { delete_view_ = should; }
  32. private:
  33. std::vector<v8::Global<v8::Object>> child_views_;
  34. bool delete_view_ = true;
  35. views::View* view_ = nullptr;
  36. };
  37. } // namespace api
  38. } // namespace electron
  39. #endif // ELECTRON_SHELL_BROWSER_API_ELECTRON_API_VIEW_H_