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.
5 #ifndef ATOM_BROWSER_API_ATOM_API_WINDOW_H_
6 #define ATOM_BROWSER_API_ATOM_API_WINDOW_H_
13 #include "atom/browser/api/trackable_object.h"
14 #include "atom/browser/native_window.h"
15 #include "atom/browser/native_window_observer.h"
16 #include "atom/common/api/atom_api_native_image.h"
17 #include "atom/common/key_weak_map.h"
18 #include "native_mate/handle.h"
19 #include "native_mate/persistent_dictionary.h"
20 #include "ui/gfx/image/image.h"
41 class Window : public mate::TrackableObject<Window>,
42 public NativeWindowObserver {
44 static mate::WrappableBase* New(mate::Arguments* args);
46 static void BuildPrototype(v8::Isolate* isolate,
47 v8::Local<v8::FunctionTemplate> prototype);
49 // Returns the BrowserWindow object from |native_window|.
50 static v8::Local<v8::Value> From(v8::Isolate* isolate,
51 NativeWindow* native_window);
53 NativeWindow* window() const { return window_.get(); }
58 Window(v8::Isolate* isolate, v8::Local<v8::Object> wrapper,
59 const mate::Dictionary& options);
62 // NativeWindowObserver:
63 void WillCloseWindow(bool* prevent_default) override;
64 void WillDestroyNativeObject() override;
65 void OnWindowClosed() override;
66 void OnWindowBlur() override;
67 void OnWindowFocus() override;
68 void OnWindowShow() override;
69 void OnWindowHide() override;
70 void OnReadyToShow() override;
71 void OnWindowMaximize() override;
72 void OnWindowUnmaximize() override;
73 void OnWindowMinimize() override;
74 void OnWindowRestore() override;
75 void OnWindowResize() override;
76 void OnWindowMove() override;
77 void OnWindowMoved() override;
78 void OnWindowScrollTouchBegin() override;
79 void OnWindowScrollTouchEnd() override;
80 void OnWindowScrollTouchEdge() override;
81 void OnWindowSwipe(const std::string& direction) override;
82 void OnWindowEnterFullScreen() override;
83 void OnWindowLeaveFullScreen() override;
84 void OnWindowEnterHtmlFullScreen() override;
85 void OnWindowLeaveHtmlFullScreen() override;
86 void OnRendererUnresponsive() override;
87 void OnRendererResponsive() override;
88 void OnExecuteWindowsCommand(const std::string& command_name) override;
89 void OnTouchBarItemResult(const std::string& item_id,
90 const base::DictionaryValue& details) override;
93 void OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) override;
97 void Init(v8::Isolate* isolate,
98 v8::Local<v8::Object> wrapper,
99 const mate::Dictionary& options,
100 mate::Handle<class WebContents> web_contents);
101 // APIs for NativeWindow.
117 void SetFullScreen(bool fullscreen);
119 void SetBounds(const gfx::Rect& bounds, mate::Arguments* args);
120 gfx::Rect GetBounds();
121 void SetSize(int width, int height, mate::Arguments* args);
122 std::vector<int> GetSize();
123 void SetContentSize(int width, int height, mate::Arguments* args);
124 std::vector<int> GetContentSize();
125 void SetContentBounds(const gfx::Rect& bounds, mate::Arguments* args);
126 gfx::Rect GetContentBounds();
127 void SetMinimumSize(int width, int height);
128 std::vector<int> GetMinimumSize();
129 void SetMaximumSize(int width, int height);
130 std::vector<int> GetMaximumSize();
131 void SetSheetOffset(double offsetY, mate::Arguments* args);
132 void SetResizable(bool resizable);
134 void SetMovable(bool movable);
136 void SetMinimizable(bool minimizable);
137 bool IsMinimizable();
138 void SetMaximizable(bool maximizable);
139 bool IsMaximizable();
140 void SetFullScreenable(bool fullscreenable);
141 bool IsFullScreenable();
142 void SetClosable(bool closable);
144 void SetAlwaysOnTop(bool top, mate::Arguments* args);
145 bool IsAlwaysOnTop();
147 void SetPosition(int x, int y, mate::Arguments* args);
148 std::vector<int> GetPosition();
149 void SetTitle(const std::string& title);
150 std::string GetTitle();
151 void FlashFrame(bool flash);
152 void SetSkipTaskbar(bool skip);
153 void SetKiosk(bool kiosk);
155 void SetBackgroundColor(const std::string& color_name);
156 void SetHasShadow(bool has_shadow);
158 void FocusOnWebView();
160 bool IsWebViewFocused();
161 void SetRepresentedFilename(const std::string& filename);
162 std::string GetRepresentedFilename();
163 void SetDocumentEdited(bool edited);
164 bool IsDocumentEdited();
165 void SetIgnoreMouseEvents(bool ignore);
166 void SetContentProtection(bool enable);
167 void SetFocusable(bool focusable);
168 void SetProgressBar(double progress, mate::Arguments* args);
169 void SetOverlayIcon(const gfx::Image& overlay,
170 const std::string& description);
171 bool SetThumbarButtons(mate::Arguments* args);
172 void SetMenu(v8::Isolate* isolate, v8::Local<v8::Value> menu);
173 void SetAutoHideMenuBar(bool auto_hide);
174 bool IsMenuBarAutoHide();
175 void SetMenuBarVisibility(bool visible);
176 bool IsMenuBarVisible();
177 void SetAspectRatio(double aspect_ratio, mate::Arguments* args);
178 void PreviewFile(const std::string& path, mate::Arguments* args);
179 void CloseFilePreview();
180 void SetParentWindow(v8::Local<v8::Value> value, mate::Arguments* args);
181 v8::Local<v8::Value> GetParentWindow() const;
182 std::vector<v8::Local<v8::Object>> GetChildWindows() const;
183 v8::Local<v8::Value> GetBrowserView() const;
184 void SetBrowserView(v8::Local<v8::Value> value);
185 bool IsModal() const;
186 v8::Local<v8::Value> GetNativeWindowHandle();
189 typedef base::Callback<void(v8::Local<v8::Value>,
190 v8::Local<v8::Value>)> MessageCallback;
192 bool HookWindowMessage(UINT message, const MessageCallback& callback);
193 bool IsWindowMessageHooked(UINT message);
194 void UnhookWindowMessage(UINT message);
195 void UnhookAllWindowMessages();
196 bool SetThumbnailClip(const gfx::Rect& region);
197 bool SetThumbnailToolTip(const std::string& tooltip);
198 void SetAppDetails(const mate::Dictionary& options);
201 #if defined(TOOLKIT_VIEWS)
202 void SetIcon(mate::Handle<NativeImage> icon);
205 void SetVisibleOnAllWorkspaces(bool visible);
206 bool IsVisibleOnAllWorkspaces();
208 void SetAutoHideCursor(bool auto_hide);
210 void SetVibrancy(mate::Arguments* args);
211 void SetTouchBar(const std::vector<mate::PersistentDictionary>& items);
212 void RefreshTouchBarItem(const std::string& item_id);
213 void SetEscapeTouchBarItem(const mate::PersistentDictionary& item);
215 v8::Local<v8::Value> WebContents(v8::Isolate* isolate);
217 // Remove this window from parent window's |child_windows_|.
218 void RemoveFromParentChildWindows();
221 typedef std::map<UINT, MessageCallback> MessageCallbackMap;
222 MessageCallbackMap messages_callback_map_;
225 v8::Global<v8::Value> browser_view_;
226 v8::Global<v8::Value> web_contents_;
227 v8::Global<v8::Value> menu_;
228 v8::Global<v8::Value> parent_window_;
229 KeyWeakMap<int> child_windows_;
231 api::WebContents* api_web_contents_;
233 std::unique_ptr<NativeWindow> window_;
235 DISALLOW_COPY_AND_ASSIGN(Window);
246 struct Converter<atom::NativeWindow*> {
247 static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
248 atom::NativeWindow** out) {
249 // null would be tranfered to NULL.
255 atom::api::Window* window;
256 if (!Converter<atom::api::Window*>::FromV8(isolate, val, &window))
258 *out = window->window();
265 #endif // ATOM_BROWSER_API_ATOM_API_WINDOW_H_