Add ready-to-show event
authorCheng Zhao <zcbenz@gmail.com>
Mon, 13 Jun 2016 12:19:56 +0000 (21:19 +0900)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 13 Jun 2016 12:20:16 +0000 (21:20 +0900)
atom/browser/api/atom_api_window.cc
atom/browser/api/atom_api_window.h
atom/browser/native_window.cc
atom/browser/native_window.h
atom/browser/native_window_observer.h

index 5a93f27..0d72a74 100644 (file)
@@ -156,6 +156,10 @@ void Window::OnWindowHide() {
   Emit("hide");
 }
 
+void Window::OnReadyToShow() {
+  Emit("ready-to-show");
+}
+
 void Window::OnWindowMaximize() {
   Emit("maximize");
 }
index 286b472..9d3f7ef 100644 (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;
index 8a00a88..ab8b4f9 100644 (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) {
index ffcdcc4..796cf21 100644 (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,
index cfbae95..73bf436 100644 (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() {}