Add responsive and unresponsive events for window.
This commit is contained in:
parent
556e84f53a
commit
ae88f303fa
7 changed files with 32 additions and 0 deletions
|
@ -71,6 +71,14 @@ void Window::OnWindowBlur() {
|
||||||
Emit("blur");
|
Emit("blur");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Window::OnRendererUnresponsive() {
|
||||||
|
Emit("unresponsive");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::OnRendererResponsive() {
|
||||||
|
Emit("responsive");
|
||||||
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
v8::Handle<v8::Value> Window::New(const v8::Arguments &args) {
|
v8::Handle<v8::Value> Window::New(const v8::Arguments &args) {
|
||||||
v8::HandleScope scope;
|
v8::HandleScope scope;
|
||||||
|
|
|
@ -38,6 +38,8 @@ class Window : public EventEmitter,
|
||||||
virtual void WillCloseWindow(bool* prevent_default) OVERRIDE;
|
virtual void WillCloseWindow(bool* prevent_default) OVERRIDE;
|
||||||
virtual void OnWindowClosed() OVERRIDE;
|
virtual void OnWindowClosed() OVERRIDE;
|
||||||
virtual void OnWindowBlur() OVERRIDE;
|
virtual void OnWindowBlur() OVERRIDE;
|
||||||
|
virtual void OnRendererUnresponsive() OVERRIDE;
|
||||||
|
virtual void OnRendererResponsive() OVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static v8::Handle<v8::Value> New(const v8::Arguments &args);
|
static v8::Handle<v8::Value> New(const v8::Arguments &args);
|
||||||
|
|
|
@ -7,9 +7,11 @@
|
||||||
This is the default mode of Atom Shell, please follow the instructions in
|
This is the default mode of Atom Shell, please follow the instructions in
|
||||||
wiki to get started.
|
wiki to get started.
|
||||||
<script type="text/javascript" charset="utf-8">
|
<script type="text/javascript" charset="utf-8">
|
||||||
|
|
||||||
var ipc = require('ipc');
|
var ipc = require('ipc');
|
||||||
|
|
||||||
window.addEventListener('contextmenu', function (e) {
|
window.addEventListener('contextmenu', function (e) {
|
||||||
|
while(1) {}
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
ipc.send('menu');
|
ipc.send('menu');
|
||||||
}, false);
|
}, false);
|
||||||
|
|
|
@ -30,6 +30,10 @@ delegate.browserMainParts.preMainMessageLoopRun = function() {
|
||||||
mainWindow = null;
|
mainWindow = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
mainWindow.on('unresponsive', function() {
|
||||||
|
console.log('unresponsive');
|
||||||
|
});
|
||||||
|
|
||||||
var template = [
|
var template = [
|
||||||
{
|
{
|
||||||
label: 'Atom Shell',
|
label: 'Atom Shell',
|
||||||
|
|
|
@ -248,6 +248,14 @@ bool NativeWindow::IsPopupOrPanel(const content::WebContents* source) const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NativeWindow::RendererUnresponsive(content::WebContents* source) {
|
||||||
|
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnRendererUnresponsive());
|
||||||
|
}
|
||||||
|
|
||||||
|
void NativeWindow::RendererResponsive(content::WebContents* source) {
|
||||||
|
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnRendererResponsive());
|
||||||
|
}
|
||||||
|
|
||||||
bool NativeWindow::OnMessageReceived(const IPC::Message& message) {
|
bool NativeWindow::OnMessageReceived(const IPC::Message& message) {
|
||||||
bool handled = true;
|
bool handled = true;
|
||||||
IPC_BEGIN_MESSAGE_MAP(NativeWindow, message)
|
IPC_BEGIN_MESSAGE_MAP(NativeWindow, message)
|
||||||
|
|
|
@ -146,6 +146,8 @@ class NativeWindow : public content::WebContentsDelegate,
|
||||||
virtual void CloseContents(content::WebContents* source) OVERRIDE;
|
virtual void CloseContents(content::WebContents* source) OVERRIDE;
|
||||||
virtual bool IsPopupOrPanel(
|
virtual bool IsPopupOrPanel(
|
||||||
const content::WebContents* source) const OVERRIDE;
|
const content::WebContents* source) const OVERRIDE;
|
||||||
|
virtual void RendererUnresponsive(content::WebContents* source) OVERRIDE;
|
||||||
|
virtual void RendererResponsive(content::WebContents* source) OVERRIDE;
|
||||||
|
|
||||||
// Implementations of content::WebContentsObserver.
|
// Implementations of content::WebContentsObserver.
|
||||||
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
|
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
|
||||||
|
|
|
@ -25,6 +25,12 @@ class NativeWindowObserver {
|
||||||
|
|
||||||
// Called when window loses focus.
|
// Called when window loses focus.
|
||||||
virtual void OnWindowBlur() {}
|
virtual void OnWindowBlur() {}
|
||||||
|
|
||||||
|
// Called when renderer is hung.
|
||||||
|
virtual void OnRendererUnresponsive() {}
|
||||||
|
|
||||||
|
// Called when renderer recovers.
|
||||||
|
virtual void OnRendererResponsive() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
Loading…
Reference in a new issue