Add ready-to-show event

This commit is contained in:
Cheng Zhao 2016-06-13 21:19:56 +09:00
parent 2dc453b4be
commit 4d65af3c60
5 changed files with 29 additions and 0 deletions

View file

@ -156,6 +156,10 @@ void Window::OnWindowHide() {
Emit("hide");
}
void Window::OnReadyToShow() {
Emit("ready-to-show");
}
void Window::OnWindowMaximize() {
Emit("maximize");
}

View file

@ -61,6 +61,7 @@ class Window : public mate::TrackableObject<Window>,
void OnWindowFocus() override;
void OnWindowShow() override;
void OnWindowHide() override;
void OnReadyToShow() override;
void OnWindowMaximize() override;
void OnWindowUnmaximize() override;
void OnWindowMinimize() override;

View file

@ -560,6 +560,19 @@ void NativeWindow::BeforeUnloadDialogCancelled() {
window_unresposive_closure_.Cancel();
}
void NativeWindow::DidFirstVisuallyNonEmptyPaint() {
// When there is a non-empty first paint, resize the RenderWidget to force
// Chromium to draw.
const auto view = web_contents()->GetRenderWidgetHostView();
view->Show();
view->SetSize(GetContentSize());
// Emit the ReadyToShow event in next tick in case of pending drawing work.
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(&NativeWindow::NotifyReadyToShow, GetWeakPtr()));
}
bool NativeWindow::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(NativeWindow, message)
@ -601,6 +614,10 @@ void NativeWindow::NotifyWindowUnresponsive() {
OnRendererUnresponsive());
}
void NativeWindow::NotifyReadyToShow() {
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnReadyToShow());
}
void NativeWindow::OnCapturePageDone(const CapturePageCallback& callback,
const SkBitmap& bitmap,
content::ReadbackResponse response) {

View file

@ -275,6 +275,7 @@ class NativeWindow : public base::SupportsUserData,
// content::WebContentsObserver:
void RenderViewCreated(content::RenderViewHost* render_view_host) override;
void BeforeUnloadDialogCancelled() override;
void DidFirstVisuallyNonEmptyPaint() override;
bool OnMessageReceived(const IPC::Message& message) override;
private:
@ -284,6 +285,9 @@ class NativeWindow : public base::SupportsUserData,
// Dispatch unresponsive event to observers.
void NotifyWindowUnresponsive();
// Dispatch ReadyToShow event to observers.
void NotifyReadyToShow();
// Called when CapturePage has done.
void OnCapturePageDone(const CapturePageCallback& callback,
const SkBitmap& bitmap,

View file

@ -48,6 +48,9 @@ class NativeWindowObserver {
// Called when window is hidden.
virtual void OnWindowHide() {}
// Called when window is ready to show.
virtual void OnReadyToShow() {}
// Called when window state changed.
virtual void OnWindowMaximize() {}
virtual void OnWindowUnmaximize() {}