Move ready-to-show to api::BrowserWindow
This commit is contained in:
parent
0d9a157914
commit
c256a43139
5 changed files with 31 additions and 34 deletions
|
@ -77,7 +77,8 @@ v8::Local<v8::Value> ToBuffer(v8::Isolate* isolate, void* val, int size) {
|
||||||
|
|
||||||
BrowserWindow::BrowserWindow(v8::Isolate* isolate,
|
BrowserWindow::BrowserWindow(v8::Isolate* isolate,
|
||||||
v8::Local<v8::Object> wrapper,
|
v8::Local<v8::Object> wrapper,
|
||||||
const mate::Dictionary& options) {
|
const mate::Dictionary& options)
|
||||||
|
: weak_factory_(this) {
|
||||||
mate::Handle<class WebContents> web_contents;
|
mate::Handle<class WebContents> web_contents;
|
||||||
|
|
||||||
// Use options.webPreferences in WebContents.
|
// Use options.webPreferences in WebContents.
|
||||||
|
@ -176,6 +177,24 @@ BrowserWindow::~BrowserWindow() {
|
||||||
base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, window_.release());
|
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) {
|
void BrowserWindow::WillCloseWindow(bool* prevent_default) {
|
||||||
*prevent_default = Emit("close");
|
*prevent_default = Emit("close");
|
||||||
}
|
}
|
||||||
|
@ -232,10 +251,6 @@ void BrowserWindow::OnWindowHide() {
|
||||||
Emit("hide");
|
Emit("hide");
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowserWindow::OnReadyToShow() {
|
|
||||||
Emit("ready-to-show");
|
|
||||||
}
|
|
||||||
|
|
||||||
void BrowserWindow::OnWindowMaximize() {
|
void BrowserWindow::OnWindowMaximize() {
|
||||||
Emit("maximize");
|
Emit("maximize");
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include "atom/browser/native_window_observer.h"
|
#include "atom/browser/native_window_observer.h"
|
||||||
#include "atom/common/api/atom_api_native_image.h"
|
#include "atom/common/api/atom_api_native_image.h"
|
||||||
#include "atom/common/key_weak_map.h"
|
#include "atom/common/key_weak_map.h"
|
||||||
|
#include "base/memory/weak_ptr.h"
|
||||||
#include "content/public/browser/web_contents_observer.h"
|
#include "content/public/browser/web_contents_observer.h"
|
||||||
#include "native_mate/handle.h"
|
#include "native_mate/handle.h"
|
||||||
#include "native_mate/persistent_dictionary.h"
|
#include "native_mate/persistent_dictionary.h"
|
||||||
|
@ -60,6 +61,9 @@ class BrowserWindow : public mate::TrackableObject<BrowserWindow>,
|
||||||
const mate::Dictionary& options);
|
const mate::Dictionary& options);
|
||||||
~BrowserWindow() override;
|
~BrowserWindow() override;
|
||||||
|
|
||||||
|
// content::WebContentsObserver:
|
||||||
|
void DidFirstVisuallyNonEmptyPaint() override;
|
||||||
|
|
||||||
// NativeWindowObserver:
|
// NativeWindowObserver:
|
||||||
void WillCloseWindow(bool* prevent_default) override;
|
void WillCloseWindow(bool* prevent_default) override;
|
||||||
void WillDestroyNativeObject() override;
|
void WillDestroyNativeObject() override;
|
||||||
|
@ -69,7 +73,6 @@ class BrowserWindow : public mate::TrackableObject<BrowserWindow>,
|
||||||
void OnWindowFocus() override;
|
void OnWindowFocus() override;
|
||||||
void OnWindowShow() override;
|
void OnWindowShow() override;
|
||||||
void OnWindowHide() override;
|
void OnWindowHide() override;
|
||||||
void OnReadyToShow() override;
|
|
||||||
void OnWindowMaximize() override;
|
void OnWindowMaximize() override;
|
||||||
void OnWindowUnmaximize() override;
|
void OnWindowUnmaximize() override;
|
||||||
void OnWindowMinimize() 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;
|
void OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) override;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
base::WeakPtr<BrowserWindow> GetWeakPtr() {
|
||||||
|
return weak_factory_.GetWeakPtr();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Init(v8::Isolate* isolate,
|
void Init(v8::Isolate* isolate,
|
||||||
v8::Local<v8::Object> wrapper,
|
v8::Local<v8::Object> wrapper,
|
||||||
const mate::Dictionary& options,
|
const mate::Dictionary& options,
|
||||||
mate::Handle<class WebContents> web_contents);
|
mate::Handle<class WebContents> web_contents);
|
||||||
|
|
||||||
// APIs for NativeWindow.
|
// APIs for NativeWindow.
|
||||||
void Close();
|
void Close();
|
||||||
void Focus();
|
void Focus();
|
||||||
|
@ -250,6 +258,8 @@ class BrowserWindow : public mate::TrackableObject<BrowserWindow>,
|
||||||
|
|
||||||
std::unique_ptr<NativeWindow> window_;
|
std::unique_ptr<NativeWindow> window_;
|
||||||
|
|
||||||
|
base::WeakPtrFactory<BrowserWindow> weak_factory_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(BrowserWindow);
|
DISALLOW_COPY_AND_ASSIGN(BrowserWindow);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -672,22 +672,6 @@ void NativeWindow::BeforeUnloadDialogCancelled() {
|
||||||
window_unresposive_closure_.Cancel();
|
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,
|
bool NativeWindow::OnMessageReceived(const IPC::Message& message,
|
||||||
content::RenderFrameHost* rfh) {
|
content::RenderFrameHost* rfh) {
|
||||||
bool handled = true;
|
bool handled = true;
|
||||||
|
@ -731,9 +715,4 @@ void NativeWindow::NotifyWindowUnresponsive() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindow::NotifyReadyToShow() {
|
|
||||||
for (NativeWindowObserver& observer : observers_)
|
|
||||||
observer.OnReadyToShow();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -320,7 +320,6 @@ class NativeWindow : public base::SupportsUserData,
|
||||||
// content::WebContentsObserver:
|
// content::WebContentsObserver:
|
||||||
void RenderViewCreated(content::RenderViewHost* render_view_host) override;
|
void RenderViewCreated(content::RenderViewHost* render_view_host) override;
|
||||||
void BeforeUnloadDialogCancelled() override;
|
void BeforeUnloadDialogCancelled() override;
|
||||||
void DidFirstVisuallyNonEmptyPaint() override;
|
|
||||||
bool OnMessageReceived(const IPC::Message& message,
|
bool OnMessageReceived(const IPC::Message& message,
|
||||||
content::RenderFrameHost* rfh) override;
|
content::RenderFrameHost* rfh) override;
|
||||||
|
|
||||||
|
@ -331,9 +330,6 @@ class NativeWindow : public base::SupportsUserData,
|
||||||
// Dispatch unresponsive event to observers.
|
// Dispatch unresponsive event to observers.
|
||||||
void NotifyWindowUnresponsive();
|
void NotifyWindowUnresponsive();
|
||||||
|
|
||||||
// Dispatch ReadyToShow event to observers.
|
|
||||||
void NotifyReadyToShow();
|
|
||||||
|
|
||||||
// Whether window has standard frame.
|
// Whether window has standard frame.
|
||||||
bool has_frame_;
|
bool has_frame_;
|
||||||
|
|
||||||
|
|
|
@ -55,9 +55,6 @@ class NativeWindowObserver {
|
||||||
// Called when window is hidden.
|
// Called when window is hidden.
|
||||||
virtual void OnWindowHide() {}
|
virtual void OnWindowHide() {}
|
||||||
|
|
||||||
// Called when window is ready to show.
|
|
||||||
virtual void OnReadyToShow() {}
|
|
||||||
|
|
||||||
// Called when window state changed.
|
// Called when window state changed.
|
||||||
virtual void OnWindowMaximize() {}
|
virtual void OnWindowMaximize() {}
|
||||||
virtual void OnWindowUnmaximize() {}
|
virtual void OnWindowUnmaximize() {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue