forked from nwjs/nw.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow.cc
More file actions
152 lines (144 loc) · 5.79 KB
/
window.cc
File metadata and controls
152 lines (144 loc) · 5.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// Copyright (c) 2012 Intel Corp
// Copyright (c) 2012 The Chromium Authors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell co
// pies of the Software, and to permit persons to whom the Software is furnished
// to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in al
// l copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IM
// PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNES
// S FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
// OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WH
// ETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "content/nw/src/api/window/window.h"
#include "base/values.h"
#include "content/nw/src/api/dispatcher_host.h"
#include "content/nw/src/api/menu/menu.h"
#include "content/nw/src/browser/native_window.h"
#include "content/nw/src/nw_shell.h"
namespace api {
Window::Window(int id,
DispatcherHost* dispatcher_host,
const base::DictionaryValue& option)
: Base(id, dispatcher_host, option),
shell_(content::Shell::FromRenderViewHost(dispatcher_host->
render_view_host())) {
// Set ID for Shell
shell_->set_id(id);
}
Window::~Window() {
// Window object got deleted when we launch new render view host and
// delete the old one; at this time the Shell should be decoupled
// with the renderer side
shell_->set_id(-1);
}
void Window::Call(const std::string& method,
const base::ListValue& arguments) {
if (method == "Show") {
shell_->window()->Show();
} else if (method == "Close") {
bool force = false;
arguments.GetBoolean(0, &force);
shell_->set_force_close(force);
shell_->window()->Close();
} else if (method == "Hide") {
shell_->window()->Hide();
} else if (method == "Maximize") {
shell_->window()->Maximize();
} else if (method == "Unmaximize") {
shell_->window()->Unmaximize();
} else if (method == "Minimize") {
shell_->window()->Minimize();
} else if (method == "Restore") {
shell_->window()->Restore();
} else if (method == "EnterFullscreen") {
shell_->window()->SetFullscreen(true);
} else if (method == "LeaveFullscreen") {
shell_->window()->SetFullscreen(false);
} else if (method == "ToggleFullscreen") {
shell_->window()->SetFullscreen(!shell_->window()->IsFullscreen());
} else if (method == "EnterKioskMode") {
shell_->window()->SetKiosk(true);
} else if (method == "LeaveKioskMode") {
shell_->window()->SetKiosk(false);
} else if (method == "ToggleKioskMode") {
shell_->window()->SetKiosk(!shell_->window()->IsKiosk());
} else if (method == "ShowDevTools") {
shell_->ShowDevTools();
} else if (method == "ResizeTo") {
int width, height;
if (arguments.GetInteger(0, &width) &&
arguments.GetInteger(1, &height))
shell_->window()->SetSize(gfx::Size(width, height));
} else if (method == "SetMaximumSize") {
int width, height;
if (arguments.GetInteger(0, &width) &&
arguments.GetInteger(1, &height))
shell_->window()->SetMaximumSize(width, height);
} else if (method == "SetMinimumSize") {
int width, height;
if (arguments.GetInteger(0, &width) &&
arguments.GetInteger(1, &height))
shell_->window()->SetMinimumSize(width, height);
} else if (method == "SetResizable") {
bool resizable;
if (arguments.GetBoolean(0, &resizable))
shell_->window()->SetResizable(resizable);
} else if (method == "SetAlwaysOnTop") {
bool top;
if (arguments.GetBoolean(0, &top))
shell_->window()->SetAlwaysOnTop(top);
} else if (method == "SetShowInTaskbar" ) {
bool show;
if (arguments.GetBoolean(0, &show))
shell_->window()->SetShowInTaskbar(show);
} else if (method == "MoveTo") {
int x, y;
if (arguments.GetInteger(0, &x) &&
arguments.GetInteger(1, &y))
shell_->window()->SetPosition(gfx::Point(x, y));
} else if (method == "RequestAttention") {
bool flash;
if (arguments.GetBoolean(0, &flash))
shell_->window()->FlashFrame(flash);
} else if (method == "SetMenu") {
int id;
if (arguments.GetInteger(0, &id))
shell_->window()->SetMenu(dispatcher_host()->GetApiObject<Menu>(id));
} else if (method == "Reload") {
int type;
if (arguments.GetInteger(0, &type))
shell_->Reload(static_cast<content::Shell::ReloadType>(type));
} else {
NOTREACHED() << "Invalid call to Window method:" << method
<< " arguments:" << arguments;
}
}
void Window::CallSync(const std::string& method,
const base::ListValue& arguments,
base::ListValue* result) {
if (method == "IsFullscreen") {
result->AppendBoolean(shell_->window()->IsFullscreen());
} else if (method == "IsKioskMode") {
result->AppendBoolean(shell_->window()->IsKiosk());
} else if (method == "GetSize") {
gfx::Size size = shell_->window()->GetSize();
result->AppendInteger(size.width());
result->AppendInteger(size.height());
} else if (method == "GetPosition") {
gfx::Point position = shell_->window()->GetPosition();
result->AppendInteger(position.x());
result->AppendInteger(position.y());
} else {
NOTREACHED() << "Invalid call to Window method:" << method
<< " arguments:" << arguments;
}
}
} // namespace api