atom_api_view.h 1.7 KB

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