atom_api_view.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 ATOM_BROWSER_API_ATOM_API_VIEW_H_
  5. #define ATOM_BROWSER_API_ATOM_API_VIEW_H_
  6. #include <memory>
  7. #include <vector>
  8. #include "atom/browser/api/views/atom_api_layout_manager.h"
  9. #include "electron/buildflags/buildflags.h"
  10. #include "native_mate/handle.h"
  11. #include "ui/views/view.h"
  12. namespace atom {
  13. namespace api {
  14. class View : public mate::TrackableObject<View> {
  15. public:
  16. static mate::WrappableBase* New(mate::Arguments* args);
  17. static void BuildPrototype(v8::Isolate* isolate,
  18. v8::Local<v8::FunctionTemplate> prototype);
  19. #if BUILDFLAG(ENABLE_VIEW_API)
  20. void SetLayoutManager(mate::Handle<LayoutManager> layout_manager);
  21. void AddChildView(mate::Handle<View> view);
  22. void AddChildViewAt(mate::Handle<View> view, size_t index);
  23. #endif
  24. views::View* view() const { return view_; }
  25. protected:
  26. explicit View(views::View* view);
  27. View();
  28. ~View() override;
  29. // Should delete the |view_| in destructor.
  30. void set_delete_view(bool should) { delete_view_ = should; }
  31. private:
  32. v8::Global<v8::Object> layout_manager_;
  33. std::vector<v8::Global<v8::Object>> child_views_;
  34. bool delete_view_ = true;
  35. views::View* view_ = nullptr;
  36. DISALLOW_COPY_AND_ASSIGN(View);
  37. };
  38. } // namespace api
  39. } // namespace atom
  40. namespace mate {
  41. template <>
  42. struct Converter<views::View*> {
  43. static bool FromV8(v8::Isolate* isolate,
  44. v8::Local<v8::Value> val,
  45. views::View** out) {
  46. atom::api::View* view;
  47. if (!Converter<atom::api::View*>::FromV8(isolate, val, &view))
  48. return false;
  49. *out = view->view();
  50. return true;
  51. }
  52. };
  53. } // namespace mate
  54. #endif // ATOM_BROWSER_API_ATOM_API_VIEW_H_