atom_api_layout_manager.cc 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. #include "atom/browser/api/atom_api_layout_manager.h"
  5. #include "atom/common/api/constructor.h"
  6. #include "native_mate/dictionary.h"
  7. #include "atom/common/node_includes.h"
  8. namespace atom {
  9. namespace api {
  10. LayoutManager::LayoutManager(views::LayoutManager* layout_manager)
  11. : layout_manager_(layout_manager) {
  12. DCHECK(layout_manager_);
  13. }
  14. LayoutManager::~LayoutManager() {
  15. if (managed_by_us_)
  16. delete layout_manager_;
  17. }
  18. std::unique_ptr<views::LayoutManager> LayoutManager::TakeOver() {
  19. if (!managed_by_us_) // already taken over.
  20. return nullptr;
  21. managed_by_us_ = false;
  22. return std::unique_ptr<views::LayoutManager>(layout_manager_);
  23. }
  24. // static
  25. mate::WrappableBase* LayoutManager::New(mate::Arguments* args) {
  26. args->ThrowError("LayoutManager can not be created directly");
  27. return nullptr;
  28. }
  29. // static
  30. void LayoutManager::BuildPrototype(v8::Isolate* isolate,
  31. v8::Local<v8::FunctionTemplate> prototype) {}
  32. } // namespace api
  33. } // namespace atom
  34. namespace {
  35. using atom::api::LayoutManager;
  36. void Initialize(v8::Local<v8::Object> exports,
  37. v8::Local<v8::Value> unused,
  38. v8::Local<v8::Context> context,
  39. void* priv) {
  40. v8::Isolate* isolate = context->GetIsolate();
  41. mate::Dictionary dict(isolate, exports);
  42. dict.Set("LayoutManager", mate::CreateConstructor<LayoutManager>(
  43. isolate, base::Bind(&LayoutManager::New)));
  44. }
  45. } // namespace
  46. NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_layout_manager, Initialize)