Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
706139c6
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
706139c6
编写于
6月 18, 2019
作者:
M
Matt Bierner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Cleaning up webviewElement
上级
bc075762
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
32 addition
and
27 deletion
+32
-27
src/vs/workbench/contrib/webview/browser/webviewElement.ts
src/vs/workbench/contrib/webview/browser/webviewElement.ts
+32
-27
未找到文件。
src/vs/workbench/contrib/webview/browser/webviewElement.ts
浏览文件 @
706139c6
...
...
@@ -6,11 +6,9 @@
import
{
Emitter
}
from
'
vs/base/common/event
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
Webview
,
WebviewContentOptions
,
WebviewOptions
}
from
'
vs/workbench/contrib/webview/common/webview
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
IThemeService
,
ITheme
}
from
'
vs/platform/theme/common/themeService
'
;
import
{
IEnvironmentService
}
from
'
vs/platform/environment/common/environment
'
;
import
{
IFileService
}
from
'
vs/platform/files/common/files
'
;
import
{
ITelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
{
Disposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
areWebviewInputOptionsEqual
}
from
'
vs/workbench/contrib/webview/browser/webviewEditorService
'
;
import
{
addDisposableListener
,
addClass
}
from
'
vs/base/browser/dom
'
;
...
...
@@ -25,9 +23,9 @@ interface WebviewContent {
}
export
class
IFrameWebview
extends
Disposable
implements
Webview
{
private
element
:
HTMLIFrameElement
;
private
element
?
:
HTMLIFrameElement
;
private
_ready
:
Promise
<
void
>
;
private
readonly
_ready
:
Promise
<
void
>
;
private
content
:
WebviewContent
;
private
_focused
=
false
;
...
...
@@ -37,11 +35,9 @@ export class IFrameWebview extends Disposable implements Webview {
constructor
(
private
_options
:
WebviewOptions
,
contentOptions
:
WebviewContentOptions
,
@
IInstantiationService
instantiationService
:
IInstantiationService
,
@
IThemeService
themeService
:
IThemeService
,
@
IEnvironmentService
environmentService
:
IEnvironmentService
,
@
IFileService
private
readonly
fileService
:
IFileService
,
@
ITelemetryService
telemetryService
:
ITelemetryService
,
@
IConfigurationService
private
readonly
_configurationService
:
IConfigurationService
,
)
{
super
();
...
...
@@ -58,8 +54,7 @@ export class IFrameWebview extends Disposable implements Webview {
this
.
id
=
`webview-
${
Date
.
now
()}
`
;
this
.
element
=
document
.
createElement
(
'
iframe
'
);
this
.
element
.
sandbox
.
add
(
'
allow-scripts
'
);
this
.
element
.
sandbox
.
add
(
'
allow-same-origin
'
);
this
.
element
.
sandbox
.
add
(
'
allow-scripts
'
,
'
allow-same-origin
'
);
this
.
element
.
setAttribute
(
'
src
'
,
`
${
environmentService
.
webviewEndpoint
}
?id=
${
this
.
id
}
`
);
this
.
element
.
style
.
border
=
'
none
'
;
this
.
element
.
style
.
width
=
'
100%
'
;
...
...
@@ -78,20 +73,13 @@ export class IFrameWebview extends Disposable implements Webview {
return
;
case
'
did-click-link
'
:
le
t
[
uri
]
=
e
.
data
.
data
;
cons
t
[
uri
]
=
e
.
data
.
data
;
this
.
_onDidClickLink
.
fire
(
URI
.
parse
(
uri
));
return
;
case
'
did-set-content
'
:
// this._webview.style.flex = '';
// this._webview.style.width = '100%';
// this._webview.style.height = '100%';
// this.layout();
return
;
case
'
did-scroll
'
:
// if (e
vent.args && typeof event
.args[0] === 'number') {
// this._onDidScroll.fire({ scrollYPercentage: e
vent
.args[0] });
// if (e
.args && typeof e
.args[0] === 'number') {
// this._onDidScroll.fire({ scrollYPercentage: e.args[0] });
// }
return
;
...
...
@@ -126,7 +114,9 @@ export class IFrameWebview extends Disposable implements Webview {
this
.
_ready
=
new
Promise
(
resolve
=>
{
const
subscription
=
this
.
_register
(
addDisposableListener
(
window
,
'
message
'
,
(
e
)
=>
{
if
(
e
.
data
&&
e
.
data
.
target
===
this
.
id
&&
e
.
data
.
channel
===
'
webview-ready
'
)
{
addClass
(
this
.
element
,
'
ready
'
);
if
(
this
.
element
)
{
addClass
(
this
.
element
,
'
ready
'
);
}
subscription
.
dispose
();
resolve
();
}
...
...
@@ -138,7 +128,9 @@ export class IFrameWebview extends Disposable implements Webview {
}
public
mountTo
(
parent
:
HTMLElement
)
{
parent
.
appendChild
(
this
.
element
);
if
(
this
.
element
)
{
parent
.
appendChild
(
this
.
element
);
}
}
public
set
options
(
options
:
WebviewContentOptions
)
{
...
...
@@ -195,7 +187,6 @@ export class IFrameWebview extends Disposable implements Webview {
}
initialScrollProgress
:
number
;
state
:
string
|
undefined
;
private
readonly
_onDidFocus
=
this
.
_register
(
new
Emitter
<
void
>
());
public
readonly
onDidFocus
=
this
.
_onDidFocus
.
event
;
...
...
@@ -221,7 +212,9 @@ export class IFrameWebview extends Disposable implements Webview {
}
focus
():
void
{
this
.
element
.
focus
();
if
(
this
.
element
)
{
this
.
element
.
focus
();
}
}
dispose
():
void
{
...
...
@@ -263,16 +256,28 @@ export class IFrameWebview extends Disposable implements Webview {
throw
new
Error
(
'
Method not implemented.
'
);
}
public
set
state
(
state
:
string
|
undefined
)
{
this
.
content
=
{
html
:
this
.
content
.
html
,
options
:
this
.
content
.
options
,
state
,
};
}
private
_send
(
channel
:
string
,
data
:
any
):
void
{
this
.
_ready
.
then
(()
=>
this
.
element
.
contentWindow
!
.
postMessage
({
channel
:
channel
,
args
:
data
},
'
*
'
))
.
then
(()
=>
{
if
(
!
this
.
element
)
{
return
;
}
this
.
element
.
contentWindow
!
.
postMessage
({
channel
:
channel
,
args
:
data
},
'
*
'
);
})
.
catch
(
err
=>
console
.
error
(
err
));
}
private
style
(
theme
:
ITheme
):
void
{
const
{
styles
,
activeTheme
}
=
getWebviewThemeData
(
theme
,
this
.
_configurationService
);
this
.
_send
(
'
styles
'
,
{
styles
,
activeTheme
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录