зеркало из https://github.com/electron/electron.git
Add 'closed' and 'destroyed' event for Window.
This commit is contained in:
Родитель
afe07521c5
Коммит
21df63fc9b
|
@ -32,6 +32,11 @@ EventEmitter::EventEmitter(v8::Handle<v8::Object> wrapper) {
|
|||
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) {
|
||||
v8::HandleScope scope;
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ class EventEmitter : public node::ObjectWrap {
|
|||
virtual ~EventEmitter();
|
||||
|
||||
// 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);
|
||||
|
||||
// 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());
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Window::Window(v8::Handle<v8::Object> wrapper, base::DictionaryValue* options)
|
||||
: EventEmitter(wrapper),
|
||||
|
@ -44,6 +44,8 @@ Window::Window(v8::Handle<v8::Object> wrapper, base::DictionaryValue* options)
|
|||
}
|
||||
|
||||
Window::~Window() {
|
||||
Emit("destroyed");
|
||||
|
||||
window_->RemoveObserver(this);
|
||||
}
|
||||
|
||||
|
@ -55,11 +57,12 @@ void Window::OnPageTitleUpdated(bool* prevent_default,
|
|||
}
|
||||
|
||||
void Window::WillCloseWindow(bool* prevent_default) {
|
||||
base::ListValue args;
|
||||
*prevent_default = Emit("close", &args);
|
||||
*prevent_default = Emit("close");
|
||||
}
|
||||
|
||||
void Window::OnWindowClosed() {
|
||||
Emit("closed");
|
||||
|
||||
// Free memory immediately when window is closed.
|
||||
delete this;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче