зеркало из https://github.com/electron/electron.git
fix: native `View` wrapper crash missing when adding child view (#43638)
fix: native View wrapper crash missing when adding child view
This commit is contained in:
Родитель
dea6a4e5fb
Коммит
74b54278bf
|
@ -15,13 +15,9 @@ DelayedNativeViewHost::~DelayedNativeViewHost() = default;
|
||||||
|
|
||||||
void DelayedNativeViewHost::ViewHierarchyChanged(
|
void DelayedNativeViewHost::ViewHierarchyChanged(
|
||||||
const views::ViewHierarchyChangedDetails& details) {
|
const views::ViewHierarchyChangedDetails& details) {
|
||||||
// NativeViewHost doesn't expect to have children, so filter the
|
NativeViewHost::ViewHierarchyChanged(details);
|
||||||
// ViewHierarchyChanged events before passing them on.
|
if (details.is_add && GetWidget() && !native_view())
|
||||||
if (details.child == this) {
|
Attach(native_view_);
|
||||||
NativeViewHost::ViewHierarchyChanged(details);
|
|
||||||
if (details.is_add && GetWidget() && !native_view())
|
|
||||||
Attach(native_view_);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DelayedNativeViewHost::OnMousePressed(const ui::MouseEvent& ui_event) {
|
bool DelayedNativeViewHost::OnMousePressed(const ui::MouseEvent& ui_event) {
|
||||||
|
|
|
@ -36,6 +36,18 @@ describe('View', () => {
|
||||||
expect(w.contentView.children).to.have.lengthOf(1);
|
expect(w.contentView.children).to.have.lengthOf(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can be added as a child of another View', async () => {
|
||||||
|
const w = new BaseWindow();
|
||||||
|
const v1 = new View();
|
||||||
|
const v2 = new View();
|
||||||
|
|
||||||
|
v1.addChildView(v2);
|
||||||
|
w.contentView.addChildView(v1);
|
||||||
|
|
||||||
|
expect(w.contentView.children).to.deep.equal([v1]);
|
||||||
|
expect(v1.children).to.deep.equal([v2]);
|
||||||
|
});
|
||||||
|
|
||||||
it('correctly reorders children', () => {
|
it('correctly reorders children', () => {
|
||||||
w = new BaseWindow({ show: false });
|
w = new BaseWindow({ show: false });
|
||||||
const cv = new View();
|
const cv = new View();
|
||||||
|
|
|
@ -135,6 +135,20 @@ describe('WebContentsView', () => {
|
||||||
expect(w.isFullScreen()).to.be.true('isFullScreen');
|
expect(w.isFullScreen()).to.be.true('isFullScreen');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can be added as a child of another View', async () => {
|
||||||
|
const w = new BaseWindow();
|
||||||
|
const v = new View();
|
||||||
|
const wcv = new WebContentsView();
|
||||||
|
|
||||||
|
await wcv.webContents.loadURL('data:text/html,<div id="div">This is a simple div.</div>');
|
||||||
|
|
||||||
|
v.addChildView(wcv);
|
||||||
|
w.contentView.addChildView(v);
|
||||||
|
|
||||||
|
expect(w.contentView.children).to.deep.equal([v]);
|
||||||
|
expect(v.children).to.deep.equal([wcv]);
|
||||||
|
});
|
||||||
|
|
||||||
describe('visibilityState', () => {
|
describe('visibilityState', () => {
|
||||||
async function haveVisibilityState (view: WebContentsView, state: string) {
|
async function haveVisibilityState (view: WebContentsView, state: string) {
|
||||||
const docVisState = await view.webContents.executeJavaScript('document.visibilityState');
|
const docVisState = await view.webContents.executeJavaScript('document.visibilityState');
|
||||||
|
|
Загрузка…
Ссылка в новой задаче