Implement initial, experimental BrowserView API
[platform/framework/web/crosswalk-tizen.git] / atom / browser / api / atom_api_window.h
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
5 #ifndef ATOM_BROWSER_API_ATOM_API_WINDOW_H_
6 #define ATOM_BROWSER_API_ATOM_API_WINDOW_H_
7
8 #include <map>
9 #include <memory>
10 #include <string>
11 #include <vector>
12
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"
21
22 class GURL;
23
24 namespace gfx {
25 class Rect;
26 }
27
28 namespace mate {
29 class Arguments;
30 class Dictionary;
31 }
32
33 namespace atom {
34
35 class NativeWindow;
36
37 namespace api {
38
39 class WebContents;
40
41 class Window : public mate::TrackableObject<Window>,
42                public NativeWindowObserver {
43  public:
44   static mate::WrappableBase* New(mate::Arguments* args);
45
46   static void BuildPrototype(v8::Isolate* isolate,
47                              v8::Local<v8::FunctionTemplate> prototype);
48
49   // Returns the BrowserWindow object from |native_window|.
50   static v8::Local<v8::Value> From(v8::Isolate* isolate,
51                                    NativeWindow* native_window);
52
53   NativeWindow* window() const { return window_.get(); }
54
55   int32_t ID() const;
56
57  protected:
58   Window(v8::Isolate* isolate, v8::Local<v8::Object> wrapper,
59          const mate::Dictionary& options);
60   ~Window() override;
61
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;
91
92   #if defined(OS_WIN)
93   void OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) override;
94   #endif
95
96  private:
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.
102   void Close();
103   void Focus();
104   void Blur();
105   bool IsFocused();
106   void Show();
107   void ShowInactive();
108   void Hide();
109   bool IsVisible();
110   bool IsEnabled();
111   void Maximize();
112   void Unmaximize();
113   bool IsMaximized();
114   void Minimize();
115   void Restore();
116   bool IsMinimized();
117   void SetFullScreen(bool fullscreen);
118   bool IsFullscreen();
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);
133   bool IsResizable();
134   void SetMovable(bool movable);
135   bool IsMovable();
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);
143   bool IsClosable();
144   void SetAlwaysOnTop(bool top, mate::Arguments* args);
145   bool IsAlwaysOnTop();
146   void Center();
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);
154   bool IsKiosk();
155   void SetBackgroundColor(const std::string& color_name);
156   void SetHasShadow(bool has_shadow);
157   bool HasShadow();
158   void FocusOnWebView();
159   void BlurWebView();
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();
187
188 #if defined(OS_WIN)
189   typedef base::Callback<void(v8::Local<v8::Value>,
190                               v8::Local<v8::Value>)> MessageCallback;
191
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);
199 #endif
200
201 #if defined(TOOLKIT_VIEWS)
202   void SetIcon(mate::Handle<NativeImage> icon);
203 #endif
204
205   void SetVisibleOnAllWorkspaces(bool visible);
206   bool IsVisibleOnAllWorkspaces();
207
208   void SetAutoHideCursor(bool auto_hide);
209
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);
214
215   v8::Local<v8::Value> WebContents(v8::Isolate* isolate);
216
217   // Remove this window from parent window's |child_windows_|.
218   void RemoveFromParentChildWindows();
219
220 #if defined(OS_WIN)
221   typedef std::map<UINT, MessageCallback> MessageCallbackMap;
222   MessageCallbackMap messages_callback_map_;
223 #endif
224
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_;
230
231   api::WebContents* api_web_contents_;
232
233   std::unique_ptr<NativeWindow> window_;
234
235   DISALLOW_COPY_AND_ASSIGN(Window);
236 };
237
238 }  // namespace api
239
240 }  // namespace atom
241
242
243 namespace mate {
244
245 template<>
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.
250     if (val->IsNull()) {
251       *out = NULL;
252       return true;
253     }
254
255     atom::api::Window* window;
256     if (!Converter<atom::api::Window*>::FromV8(isolate, val, &window))
257       return false;
258     *out = window->window();
259     return true;
260   }
261 };
262
263 }  // namespace mate
264
265 #endif  // ATOM_BROWSER_API_ATOM_API_WINDOW_H_