Add 'closed' and 'destroyed' event for Window.
This commit is contained in:
parent
afe07521c5
commit
21df63fc9b
3 changed files with 12 additions and 3 deletions
|
@ -32,6 +32,11 @@ EventEmitter::EventEmitter(v8::Handle<v8::Object> wrapper) {
|
||||||
EventEmitter::~EventEmitter() {
|
EventEmitter::~EventEmitter() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool EventEmitter::Emit(const std::string& name) {
|
||||||
|
base::ListValue args;
|
||||||
|
return Emit(name, &args);
|
||||||
|
}
|
||||||
|
|
||||||
bool EventEmitter::Emit(const std::string& name, base::ListValue* args) {
|
bool EventEmitter::Emit(const std::string& name, base::ListValue* args) {
|
||||||
v8::HandleScope scope;
|
v8::HandleScope scope;
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ class EventEmitter : public node::ObjectWrap {
|
||||||
virtual ~EventEmitter();
|
virtual ~EventEmitter();
|
||||||
|
|
||||||
// Emit an event and returns whether the handler has called preventDefault().
|
// Emit an event and returns whether the handler has called preventDefault().
|
||||||
|
bool Emit(const std::string& name);
|
||||||
bool Emit(const std::string& name, base::ListValue* args);
|
bool Emit(const std::string& name, base::ListValue* args);
|
||||||
|
|
||||||
// Small accessor to return handle_, this follows Google C++ Style.
|
// Small accessor to return handle_, this follows Google C++ Style.
|
||||||
|
|
|
@ -34,7 +34,7 @@ v8::Handle<v8::String> UTF16ToV8String(const string16& s) {
|
||||||
return v8::String::New(reinterpret_cast<const uint16_t*>(s.data()), s.size());
|
return v8::String::New(reinterpret_cast<const uint16_t*>(s.data()), s.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
Window::Window(v8::Handle<v8::Object> wrapper, base::DictionaryValue* options)
|
Window::Window(v8::Handle<v8::Object> wrapper, base::DictionaryValue* options)
|
||||||
: EventEmitter(wrapper),
|
: EventEmitter(wrapper),
|
||||||
|
@ -44,6 +44,8 @@ Window::Window(v8::Handle<v8::Object> wrapper, base::DictionaryValue* options)
|
||||||
}
|
}
|
||||||
|
|
||||||
Window::~Window() {
|
Window::~Window() {
|
||||||
|
Emit("destroyed");
|
||||||
|
|
||||||
window_->RemoveObserver(this);
|
window_->RemoveObserver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,11 +57,12 @@ void Window::OnPageTitleUpdated(bool* prevent_default,
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::WillCloseWindow(bool* prevent_default) {
|
void Window::WillCloseWindow(bool* prevent_default) {
|
||||||
base::ListValue args;
|
*prevent_default = Emit("close");
|
||||||
*prevent_default = Emit("close", &args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::OnWindowClosed() {
|
void Window::OnWindowClosed() {
|
||||||
|
Emit("closed");
|
||||||
|
|
||||||
// Free memory immediately when window is closed.
|
// Free memory immediately when window is closed.
|
||||||
delete this;
|
delete this;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue