Move ready-to-show to api::BrowserWindow

This commit is contained in:
Cheng Zhao 2018-02-22 14:59:39 +09:00
Родитель 0d9a157914
Коммит c256a43139
5 изменённых файлов: 31 добавлений и 34 удалений

Просмотреть файл

@ -77,7 +77,8 @@ v8::Local<v8::Value> ToBuffer(v8::Isolate* isolate, void* val, int size) {
BrowserWindow::BrowserWindow(v8::Isolate* isolate,
v8::Local<v8::Object> wrapper,
const mate::Dictionary& options) {
const mate::Dictionary& options)
: weak_factory_(this) {
mate::Handle<class WebContents> web_contents;
// Use options.webPreferences in WebContents.
@ -176,6 +177,24 @@ BrowserWindow::~BrowserWindow() {
base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, window_.release());
}
void BrowserWindow::DidFirstVisuallyNonEmptyPaint() {
if (window_->IsVisible())
return;
// 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(window_->GetContentSize());
// Emit the ReadyToShow event in next tick in case of pending drawing work.
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::Bind([](base::WeakPtr<BrowserWindow> self) {
self->Emit("ready-to-show");
}, GetWeakPtr()));
}
void BrowserWindow::WillCloseWindow(bool* prevent_default) {
*prevent_default = Emit("close");
}
@ -232,10 +251,6 @@ void BrowserWindow::OnWindowHide() {
Emit("hide");
}
void BrowserWindow::OnReadyToShow() {
Emit("ready-to-show");
}
void BrowserWindow::OnWindowMaximize() {
Emit("maximize");
}

Просмотреть файл

@ -15,6 +15,7 @@
#include "atom/browser/native_window_observer.h"
#include "atom/common/api/atom_api_native_image.h"
#include "atom/common/key_weak_map.h"
#include "base/memory/weak_ptr.h"
#include "content/public/browser/web_contents_observer.h"
#include "native_mate/handle.h"
#include "native_mate/persistent_dictionary.h"
@ -60,6 +61,9 @@ class BrowserWindow : public mate::TrackableObject<BrowserWindow>,
const mate::Dictionary& options);
~BrowserWindow() override;
// content::WebContentsObserver:
void DidFirstVisuallyNonEmptyPaint() override;
// NativeWindowObserver:
void WillCloseWindow(bool* prevent_default) override;
void WillDestroyNativeObject() override;
@ -69,7 +73,6 @@ class BrowserWindow : public mate::TrackableObject<BrowserWindow>,
void OnWindowFocus() override;
void OnWindowShow() override;
void OnWindowHide() override;
void OnReadyToShow() override;
void OnWindowMaximize() override;
void OnWindowUnmaximize() override;
void OnWindowMinimize() override;
@ -98,11 +101,16 @@ class BrowserWindow : public mate::TrackableObject<BrowserWindow>,
void OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) override;
#endif
base::WeakPtr<BrowserWindow> GetWeakPtr() {
return weak_factory_.GetWeakPtr();
}
private:
void Init(v8::Isolate* isolate,
v8::Local<v8::Object> wrapper,
const mate::Dictionary& options,
mate::Handle<class WebContents> web_contents);
// APIs for NativeWindow.
void Close();
void Focus();
@ -250,6 +258,8 @@ class BrowserWindow : public mate::TrackableObject<BrowserWindow>,
std::unique_ptr<NativeWindow> window_;
base::WeakPtrFactory<BrowserWindow> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(BrowserWindow);
};

Просмотреть файл

@ -672,22 +672,6 @@ void NativeWindow::BeforeUnloadDialogCancelled() {
window_unresposive_closure_.Cancel();
}
void NativeWindow::DidFirstVisuallyNonEmptyPaint() {
if (IsVisible())
return;
// 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::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::Bind(&NativeWindow::NotifyReadyToShow, GetWeakPtr()));
}
bool NativeWindow::OnMessageReceived(const IPC::Message& message,
content::RenderFrameHost* rfh) {
bool handled = true;
@ -731,9 +715,4 @@ void NativeWindow::NotifyWindowUnresponsive() {
}
}
void NativeWindow::NotifyReadyToShow() {
for (NativeWindowObserver& observer : observers_)
observer.OnReadyToShow();
}
} // namespace atom

Просмотреть файл

@ -320,7 +320,6 @@ 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,
content::RenderFrameHost* rfh) override;
@ -331,9 +330,6 @@ class NativeWindow : public base::SupportsUserData,
// Dispatch unresponsive event to observers.
void NotifyWindowUnresponsive();
// Dispatch ReadyToShow event to observers.
void NotifyReadyToShow();
// Whether window has standard frame.
bool has_frame_;

Просмотреть файл

@ -55,9 +55,6 @@ 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() {}