PageRenderTime 40ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/atom/browser/api/atom_api_window.h

https://gitlab.com/lishaomin/electron
C Header | 192 lines | 149 code | 34 blank | 9 comment | 2 complexity | c85644bdea5daec4cd1242637ee51f8d MD5 | raw file
  1. // Copyright (c) 2013 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_WINDOW_H_
  5. #define ATOM_BROWSER_API_ATOM_API_WINDOW_H_
  6. #include <string>
  7. #include <vector>
  8. #include "base/memory/scoped_ptr.h"
  9. #include "ui/gfx/image/image.h"
  10. #include "atom/browser/api/trackable_object.h"
  11. #include "atom/browser/native_window.h"
  12. #include "atom/browser/native_window_observer.h"
  13. #include "native_mate/handle.h"
  14. class GURL;
  15. namespace gfx {
  16. class Rect;
  17. }
  18. namespace mate {
  19. class Arguments;
  20. class Dictionary;
  21. }
  22. namespace atom {
  23. class NativeWindow;
  24. namespace api {
  25. class WebContents;
  26. class Window : public mate::TrackableObject<Window>,
  27. public NativeWindowObserver {
  28. public:
  29. static mate::Wrappable* New(v8::Isolate* isolate,
  30. const mate::Dictionary& options);
  31. static void BuildPrototype(v8::Isolate* isolate,
  32. v8::Local<v8::ObjectTemplate> prototype);
  33. // Returns the BrowserWindow object from |native_window|.
  34. static v8::Local<v8::Value> From(v8::Isolate* isolate,
  35. NativeWindow* native_window);
  36. NativeWindow* window() const { return window_.get(); }
  37. protected:
  38. Window(v8::Isolate* isolate, const mate::Dictionary& options);
  39. virtual ~Window();
  40. // NativeWindowObserver:
  41. void OnPageTitleUpdated(bool* prevent_default,
  42. const std::string& title) override;
  43. void WillCloseWindow(bool* prevent_default) override;
  44. void OnWindowClosed() override;
  45. void OnWindowBlur() override;
  46. void OnWindowFocus() override;
  47. void OnWindowMaximize() override;
  48. void OnWindowUnmaximize() override;
  49. void OnWindowMinimize() override;
  50. void OnWindowRestore() override;
  51. void OnWindowResize() override;
  52. void OnWindowMove() override;
  53. void OnWindowMoved() override;
  54. void OnWindowEnterFullScreen() override;
  55. void OnWindowLeaveFullScreen() override;
  56. void OnWindowEnterHtmlFullScreen() override;
  57. void OnWindowLeaveHtmlFullScreen() override;
  58. void OnRendererUnresponsive() override;
  59. void OnRendererResponsive() override;
  60. void OnExecuteWindowsCommand(const std::string& command_name) override;
  61. // mate::Wrappable:
  62. bool IsDestroyed() const override;
  63. private:
  64. // mate::TrackableObject:
  65. void Destroy() override;
  66. // APIs for NativeWindow.
  67. void Close();
  68. bool IsClosed();
  69. void Focus();
  70. bool IsFocused();
  71. void Show();
  72. void ShowInactive();
  73. void Hide();
  74. bool IsVisible();
  75. void Maximize();
  76. void Unmaximize();
  77. bool IsMaximized();
  78. void Minimize();
  79. void Restore();
  80. bool IsMinimized();
  81. void SetFullScreen(bool fullscreen);
  82. bool IsFullscreen();
  83. void SetBounds(const gfx::Rect& bounds);
  84. gfx::Rect GetBounds();
  85. void SetSize(int width, int height);
  86. std::vector<int> GetSize();
  87. void SetContentSize(int width, int height);
  88. std::vector<int> GetContentSize();
  89. void SetMinimumSize(int width, int height);
  90. std::vector<int> GetMinimumSize();
  91. void SetMaximumSize(int width, int height);
  92. std::vector<int> GetMaximumSize();
  93. void SetResizable(bool resizable);
  94. bool IsResizable();
  95. void SetAlwaysOnTop(bool top);
  96. bool IsAlwaysOnTop();
  97. void Center();
  98. void SetPosition(int x, int y);
  99. std::vector<int> GetPosition();
  100. void SetTitle(const std::string& title);
  101. std::string GetTitle();
  102. void FlashFrame(bool flash);
  103. void SetSkipTaskbar(bool skip);
  104. void SetKiosk(bool kiosk);
  105. bool IsKiosk();
  106. void FocusOnWebView();
  107. void BlurWebView();
  108. bool IsWebViewFocused();
  109. bool IsDevToolsFocused();
  110. void SetRepresentedFilename(const std::string& filename);
  111. std::string GetRepresentedFilename();
  112. void SetDocumentEdited(bool edited);
  113. bool IsDocumentEdited();
  114. void CapturePage(mate::Arguments* args);
  115. void SetProgressBar(double progress);
  116. void SetOverlayIcon(const gfx::Image& overlay,
  117. const std::string& description);
  118. bool SetThumbarButtons(mate::Arguments* args);
  119. void SetMenu(v8::Isolate* isolate, v8::Local<v8::Value> menu);
  120. void SetAutoHideMenuBar(bool auto_hide);
  121. bool IsMenuBarAutoHide();
  122. void SetMenuBarVisibility(bool visible);
  123. bool IsMenuBarVisible();
  124. void SetAspectRatio(double aspect_ratio, mate::Arguments* args);
  125. #if defined(OS_MACOSX)
  126. void ShowDefinitionForSelection();
  127. #endif
  128. void SetVisibleOnAllWorkspaces(bool visible);
  129. bool IsVisibleOnAllWorkspaces();
  130. int32_t ID() const;
  131. v8::Local<v8::Value> WebContents(v8::Isolate* isolate);
  132. v8::Global<v8::Value> web_contents_;
  133. v8::Global<v8::Value> menu_;
  134. api::WebContents* api_web_contents_;
  135. scoped_ptr<NativeWindow> window_;
  136. DISALLOW_COPY_AND_ASSIGN(Window);
  137. };
  138. } // namespace api
  139. } // namespace atom
  140. namespace mate {
  141. template<>
  142. struct Converter<atom::NativeWindow*> {
  143. static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
  144. atom::NativeWindow** out) {
  145. // null would be tranfered to NULL.
  146. if (val->IsNull()) {
  147. *out = NULL;
  148. return true;
  149. }
  150. atom::api::Window* window;
  151. if (!Converter<atom::api::Window*>::FromV8(isolate, val, &window))
  152. return false;
  153. *out = window->window();
  154. return true;
  155. }
  156. };
  157. } // namespace mate
  158. #endif // ATOM_BROWSER_API_ATOM_API_WINDOW_H_