Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
267f791f
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
267f791f
编写于
3月 05, 2018
作者:
M
Matt Bierner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move webview editor and input to own part
上级
3e7bc808
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
455 addition
and
419 deletion
+455
-419
build/lib/i18n.resources.json
build/lib/i18n.resources.json
+4
-0
src/vs/workbench/api/electron-browser/mainThreadWebview.ts
src/vs/workbench/api/electron-browser/mainThreadWebview.ts
+5
-412
src/vs/workbench/parts/update/electron-browser/releaseNotesEditor.ts
...bench/parts/update/electron-browser/releaseNotesEditor.ts
+0
-6
src/vs/workbench/parts/update/electron-browser/update.ts
src/vs/workbench/parts/update/electron-browser/update.ts
+1
-1
src/vs/workbench/parts/webview/electron-browser/webview.contribution.ts
...ch/parts/webview/electron-browser/webview.contribution.ts
+17
-0
src/vs/workbench/parts/webview/electron-browser/webviewEditor.ts
...workbench/parts/webview/electron-browser/webviewEditor.ts
+214
-0
src/vs/workbench/parts/webview/electron-browser/webviewInput.ts
.../workbench/parts/webview/electron-browser/webviewInput.ts
+212
-0
src/vs/workbench/workbench.main.ts
src/vs/workbench/workbench.main.ts
+2
-0
未找到文件。
build/lib/i18n.resources.json
浏览文件 @
267f791f
...
...
@@ -134,6 +134,10 @@
"name"
:
"vs/workbench/parts/watermark"
,
"project"
:
"vscode-workbench"
},
{
"name"
:
"vs/workbench/parts/webview"
,
"project"
:
"vscode-workbench"
},
{
"name"
:
"vs/workbench/parts/welcome"
,
"project"
:
"vscode-workbench"
...
...
src/vs/workbench/api/electron-browser/mainThreadWebview.ts
浏览文件 @
267f791f
...
...
@@ -5,420 +5,19 @@
'
use strict
'
;
import
*
as
map
from
'
vs/base/common/map
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
MainThreadWebviewsShape
,
MainContext
,
IExtHostContext
,
ExtHostContext
,
ExtHostWebviewsShape
,
WebviewHandle
}
from
'
vs/workbench/api/node/extHost.protocol
'
;
import
{
IDisposable
,
dispose
,
Disposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
dispose
,
Disposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
extHostNamedCustomer
}
from
'
./extHostCustomers
'
;
import
{
EditorInput
,
EditorModel
,
EditorOptions
}
from
'
vs/workbench/common/editor
'
;
import
{
IEditorModel
,
Position
}
from
'
vs/platform/editor/common/editor
'
;
import
{
Position
}
from
'
vs/platform/editor/common/editor
'
;
import
{
IWorkbenchEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
import
{
WebviewEditor
as
BaseWebviewEditor
,
KEYBINDING_CONTEXT_WEBVIEWEDITOR_FOCUS
,
KEYBINDING_CONTEXT_WEBVIEWEDITOR_FIND_WIDGET_INPUT_FOCUSED
,
KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE
}
from
'
vs/workbench/parts/html/browser/webviewEditor
'
;
import
{
Builder
,
Dimension
}
from
'
vs/base/browser/builder
'
;
import
{
Webview
}
from
'
vs/workbench/parts/html/browser/webview
'
;
import
{
IContextKeyService
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
ITelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
{
IThemeService
}
from
'
vs/platform/theme/common/themeService
'
;
import
{
IPartService
,
Parts
}
from
'
vs/workbench/services/part/common/partService
'
;
import
{
IStorageService
}
from
'
vs/platform/storage/common/storage
'
;
import
{
IContextViewService
}
from
'
vs/platform/contextview/browser/contextView
'
;
import
{
IEditorRegistry
,
EditorDescriptor
,
Extensions
as
EditorExtensions
}
from
'
vs/workbench/browser/editor
'
;
import
{
Registry
}
from
'
vs/platform/registry/common/platform
'
;
import
{
SyncDescriptor
}
from
'
vs/platform/instantiation/common/descriptors
'
;
import
{
localize
}
from
'
vs/nls
'
;
import
{
IEnvironmentService
}
from
'
vs/platform/environment/common/environment
'
;
import
{
IPartService
}
from
'
vs/workbench/services/part/common/partService
'
;
import
{
IOpenerService
}
from
'
vs/platform/opener/common/opener
'
;
import
*
as
vscode
from
'
vscode
'
;
import
{
IEditorGroupService
}
from
'
vs/workbench/services/group/common/groupService
'
;
import
{
IWorkspaceContextService
}
from
'
vs/platform/workspace/common/workspace
'
;
import
URI
from
'
vs/base/common/uri
'
;
import
DOM
=
require
(
'
vs/base/browser/dom
'
);
import
Event
,
{
Emitter
}
from
'
vs/base/common/event
'
;
interface
WebviewEvents
{
onMessage
(
message
:
any
):
void
;
onDidChangePosition
(
newPosition
:
Position
):
void
;
onDispose
():
void
;
onDidClickLink
(
link
:
URI
,
options
:
vscode
.
WebviewOptions
):
void
;
}
class
WebviewInput
extends
EditorInput
{
private
static
handlePool
=
0
;
private
readonly
_resource
:
URI
;
private
_name
:
string
;
private
_options
:
vscode
.
WebviewOptions
;
private
_html
:
string
;
private
_currentWebviewHtml
:
string
=
''
;
private
_events
:
WebviewEvents
|
undefined
;
private
_container
:
HTMLElement
;
private
_webview
:
Webview
|
undefined
;
private
_webviewOwner
:
any
;
private
_webviewDisposables
:
IDisposable
[]
=
[];
private
_position
:
Position
;
public
static
create
(
resource
:
URI
,
name
:
string
,
position
:
Position
,
options
:
vscode
.
WebviewOptions
,
html
:
string
,
events
:
WebviewEvents
,
partService
:
IPartService
):
WebviewInput
{
const
id
=
WebviewInput
.
handlePool
++
;
const
webviewContainer
=
document
.
createElement
(
'
div
'
);
webviewContainer
.
id
=
`webview-
${
id
}
`
;
partService
.
getContainer
(
Parts
.
EDITOR_PART
).
appendChild
(
webviewContainer
);
return
new
WebviewInput
(
resource
,
name
,
position
,
options
,
html
,
events
,
webviewContainer
,
undefined
);
}
constructor
(
resource
:
URI
,
name
:
string
,
position
:
Position
,
options
:
vscode
.
WebviewOptions
,
html
:
string
,
events
:
WebviewEvents
,
container
:
HTMLElement
,
webview
:
Webview
|
undefined
)
{
super
();
this
.
_resource
=
resource
;
this
.
_name
=
name
;
this
.
_position
=
position
;
this
.
_options
=
options
;
this
.
_html
=
html
;
this
.
_events
=
events
;
this
.
_container
=
container
;
this
.
_webview
=
webview
;
}
public
getTypeId
():
string
{
return
'
webview
'
;
}
public
dispose
()
{
this
.
disposeWebview
();
if
(
this
.
_container
)
{
this
.
_container
.
remove
();
this
.
_container
=
undefined
;
}
if
(
this
.
_events
)
{
this
.
_events
.
onDispose
();
this
.
_events
=
undefined
;
}
super
.
dispose
();
}
public
getResource
():
URI
{
return
this
.
_resource
;
}
public
getName
():
string
{
return
this
.
_name
;
}
public
setName
(
value
:
string
):
void
{
this
.
_name
=
value
;
this
.
_onDidChangeLabel
.
fire
();
}
public
get
position
():
Position
{
return
this
.
_position
;
}
public
get
html
():
string
{
return
this
.
_html
;
}
public
setHtml
(
value
:
string
):
void
{
if
(
value
===
this
.
_currentWebviewHtml
)
{
return
;
}
this
.
_html
=
value
;
if
(
this
.
_webview
)
{
this
.
_webview
.
contents
=
value
;
this
.
_currentWebviewHtml
=
value
;
}
}
public
get
options
():
vscode
.
WebviewOptions
{
return
this
.
_options
;
}
public
set
options
(
value
:
vscode
.
WebviewOptions
)
{
this
.
_options
=
value
;
}
public
resolve
(
refresh
?:
boolean
):
TPromise
<
IEditorModel
,
any
>
{
return
TPromise
.
as
(
new
EditorModel
());
}
public
supportsSplitEditor
()
{
return
false
;
}
public
get
container
():
HTMLElement
{
return
this
.
_container
;
}
public
get
webview
():
Webview
|
undefined
{
return
this
.
_webview
;
}
public
set
webview
(
value
:
Webview
)
{
this
.
_webviewDisposables
=
dispose
(
this
.
_webviewDisposables
);
this
.
_webview
=
value
;
this
.
_webview
.
onDidClickLink
(
link
=>
{
if
(
this
.
_events
)
{
this
.
_events
.
onDidClickLink
(
link
,
this
.
_options
);
}
},
null
,
this
.
_webviewDisposables
);
this
.
_webview
.
onMessage
(
message
=>
{
if
(
this
.
_events
)
{
this
.
_events
.
onMessage
(
message
);
}
},
null
,
this
.
_webviewDisposables
);
}
public
claimWebview
(
owner
:
any
)
{
this
.
_webviewOwner
=
owner
;
}
public
releaseWebview
(
owner
:
any
)
{
if
(
this
.
_webviewOwner
===
owner
)
{
this
.
_webviewOwner
=
undefined
;
if
(
this
.
_options
.
retainContextWhenHidden
)
{
this
.
container
.
style
.
visibility
=
'
hidden
'
;
}
else
{
this
.
disposeWebview
();
}
}
}
public
disposeWebview
()
{
// The input owns the webview and its parent
if
(
this
.
_webview
)
{
this
.
_webview
.
dispose
();
this
.
_webview
=
undefined
;
}
this
.
_webviewDisposables
=
dispose
(
this
.
_webviewDisposables
);
this
.
_webviewOwner
=
undefined
;
this
.
container
.
style
.
visibility
=
'
hidden
'
;
this
.
_currentWebviewHtml
=
''
;
}
public
onDidChangePosition
(
position
:
Position
)
{
if
(
this
.
_events
)
{
this
.
_events
.
onDidChangePosition
(
position
);
}
this
.
_position
=
position
;
}
}
class
WebviewEditor
extends
BaseWebviewEditor
{
public
static
readonly
ID
=
'
WebviewEditor
'
;
private
editorFrame
:
HTMLElement
;
private
webviewContent
:
HTMLElement
;
private
_onDidFocusWebview
:
Emitter
<
void
>
;
private
_webviewFocusTracker
?:
DOM
.
IFocusTracker
;
private
_webviewFocusListenerDisposable
?:
IDisposable
;
constructor
(
@
ITelemetryService
telemetryService
:
ITelemetryService
,
@
IStorageService
storageService
:
IStorageService
,
@
IThemeService
themeService
:
IThemeService
,
@
IContextKeyService
private
_contextKeyService
:
IContextKeyService
,
@
IPartService
private
readonly
_partService
:
IPartService
,
@
IContextViewService
private
readonly
_contextViewService
:
IContextViewService
,
@
IEnvironmentService
private
readonly
_environmentService
:
IEnvironmentService
,
@
IWorkspaceContextService
private
readonly
_contextService
:
IWorkspaceContextService
)
{
super
(
WebviewEditor
.
ID
,
telemetryService
,
themeService
,
storageService
,
_contextKeyService
);
this
.
_onDidFocusWebview
=
new
Emitter
<
void
>
();
}
protected
createEditor
(
parent
:
Builder
):
void
{
this
.
editorFrame
=
parent
.
getHTMLElement
();
this
.
content
=
document
.
createElement
(
'
div
'
);
parent
.
append
(
this
.
content
);
}
private
doUpdateContainer
()
{
const
webviewContainer
=
this
.
input
&&
(
this
.
input
as
WebviewInput
).
container
;
if
(
webviewContainer
)
{
const
frameRect
=
this
.
editorFrame
.
getBoundingClientRect
();
const
containerRect
=
webviewContainer
.
parentElement
.
getBoundingClientRect
();
webviewContainer
.
style
.
position
=
'
absolute
'
;
webviewContainer
.
style
.
top
=
`
${
frameRect
.
top
-
containerRect
.
top
}
px`
;
webviewContainer
.
style
.
left
=
`
${
frameRect
.
left
-
containerRect
.
left
}
px`
;
webviewContainer
.
style
.
width
=
`
${
frameRect
.
width
}
px`
;
webviewContainer
.
style
.
height
=
`
${
frameRect
.
height
}
px`
;
}
}
public
layout
(
dimension
:
Dimension
):
void
{
if
(
this
.
_webview
)
{
this
.
doUpdateContainer
();
}
super
.
layout
(
dimension
);
}
public
dispose
():
void
{
// Let the editor input dispose of the webview.
this
.
_webview
=
undefined
;
this
.
webviewContent
=
undefined
;
this
.
_onDidFocusWebview
.
dispose
();
if
(
this
.
_webviewFocusTracker
)
{
this
.
_webviewFocusTracker
.
dispose
();
}
if
(
this
.
_webviewFocusListenerDisposable
)
{
this
.
_webviewFocusListenerDisposable
.
dispose
();
}
super
.
dispose
();
}
public
sendMessage
(
data
:
any
):
void
{
if
(
this
.
_webview
)
{
this
.
_webview
.
sendMessage
(
data
);
}
}
public
get
onDidFocus
():
Event
<
any
>
{
return
this
.
_onDidFocusWebview
.
event
;
}
protected
setEditorVisible
(
visible
:
boolean
,
position
?:
Position
):
void
{
if
(
this
.
input
&&
this
.
input
instanceof
WebviewInput
)
{
if
(
visible
)
{
this
.
input
.
claimWebview
(
this
);
}
else
{
this
.
input
.
releaseWebview
(
this
);
}
this
.
updateWebview
(
this
.
input
as
WebviewInput
);
}
if
(
this
.
webviewContent
)
{
if
(
visible
)
{
this
.
webviewContent
.
style
.
visibility
=
'
visible
'
;
this
.
doUpdateContainer
();
}
else
{
this
.
webviewContent
.
style
.
visibility
=
'
hidden
'
;
}
}
super
.
setEditorVisible
(
visible
,
position
);
}
public
clearInput
()
{
if
(
this
.
input
&&
this
.
input
instanceof
WebviewInput
)
{
this
.
input
.
releaseWebview
(
this
);
}
this
.
_webview
=
undefined
;
this
.
webviewContent
=
undefined
;
super
.
clearInput
();
}
async
setInput
(
input
:
WebviewInput
,
options
:
EditorOptions
):
TPromise
<
void
>
{
if
(
this
.
input
&&
this
.
input
.
matches
(
input
))
{
return
undefined
;
}
if
(
this
.
input
&&
this
.
input
.
getResource
().
fsPath
!==
input
.
getResource
().
fsPath
)
{
(
this
.
input
as
WebviewInput
).
releaseWebview
(
this
);
this
.
_webview
=
undefined
;
this
.
webviewContent
=
undefined
;
}
await
super
.
setInput
(
input
,
options
);
input
.
onDidChangePosition
(
this
.
position
);
this
.
updateWebview
(
input
);
}
private
updateWebview
(
input
:
WebviewInput
)
{
const
webview
=
this
.
getWebview
(
input
);
input
.
claimWebview
(
this
);
webview
.
options
=
{
allowScripts
:
input
.
options
.
enableScripts
,
enableWrappedPostMessage
:
true
,
useSameOriginForRoot
:
false
,
localResourceRoots
:
(
input
&&
input
.
options
.
localResourceRoots
)
||
this
.
_contextService
.
getWorkspace
().
folders
.
map
(
x
=>
x
.
uri
)
};
input
.
setHtml
(
input
.
html
);
this
.
webviewContent
.
style
.
visibility
=
'
visible
'
;
this
.
doUpdateContainer
();
}
private
getWebview
(
input
:
WebviewInput
):
Webview
{
if
(
this
.
_webview
)
{
return
this
.
_webview
;
}
this
.
webviewContent
=
input
.
container
;
const
existing
=
input
.
webview
;
if
(
existing
)
{
this
.
_webview
=
existing
;
return
existing
;
}
this
.
_webviewFocusTracker
=
DOM
.
trackFocus
(
this
.
webviewContent
);
this
.
_webviewFocusListenerDisposable
=
this
.
_webviewFocusTracker
.
onDidFocus
(()
=>
{
this
.
_onDidFocusWebview
.
fire
();
});
this
.
_contextKeyService
=
this
.
_contextKeyService
.
createScoped
(
this
.
webviewContent
);
this
.
contextKey
=
KEYBINDING_CONTEXT_WEBVIEWEDITOR_FOCUS
.
bindTo
(
this
.
_contextKeyService
);
this
.
findInputFocusContextKey
=
KEYBINDING_CONTEXT_WEBVIEWEDITOR_FIND_WIDGET_INPUT_FOCUSED
.
bindTo
(
this
.
_contextKeyService
);
this
.
findWidgetVisible
=
KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE
.
bindTo
(
this
.
_contextKeyService
);
this
.
_webview
=
new
Webview
(
this
.
webviewContent
,
this
.
_partService
.
getContainer
(
Parts
.
EDITOR_PART
),
this
.
themeService
,
this
.
_environmentService
,
this
.
_contextViewService
,
this
.
contextKey
,
this
.
findInputFocusContextKey
,
{
enableWrappedPostMessage
:
true
,
useSameOriginForRoot
:
false
});
input
.
webview
=
this
.
_webview
;
this
.
content
.
setAttribute
(
'
aria-flowto
'
,
this
.
webviewContent
.
id
);
this
.
doUpdateContainer
();
return
this
.
_webview
;
}
}
import
{
WebviewInput
}
from
'
vs/workbench/parts/webview/electron-browser/webviewInput
'
;
import
{
WebviewEditor
}
from
'
vs/workbench/parts/webview/electron-browser/webviewEditor
'
;
@
extHostNamedCustomer
(
MainContext
.
MainThreadWebviews
)
...
...
@@ -550,9 +149,3 @@ export class MainThreadWebviews implements MainThreadWebviewsShape {
}
}
}
(
<
IEditorRegistry
>
Registry
.
as
(
EditorExtensions
.
Editors
)).
registerEditor
(
new
EditorDescriptor
(
WebviewEditor
,
WebviewEditor
.
ID
,
localize
(
'
webview.editor.label
'
,
"
webview editor
"
)),
[
new
SyncDescriptor
(
WebviewInput
)]);
src/vs/workbench/parts/update/electron-browser/releaseNotesEditor.ts
浏览文件 @
267f791f
...
...
@@ -122,12 +122,6 @@ export class ReleaseNotesEditor extends WebviewEditor {
super
.
dispose
();
}
protected
getViewState
()
{
return
{
scrollYPercentage
:
this
.
scrollYPercentage
};
}
public
clearInput
():
void
{
if
(
this
.
input
instanceof
ReleaseNotesInput
)
{
this
.
saveViewState
(
this
.
input
.
version
,
{
...
...
src/vs/workbench/parts/update/electron-browser/update.ts
浏览文件 @
267f791f
...
...
@@ -45,7 +45,7 @@ const NotNowAction = new Action(
const
releaseNotesCache
:
{
[
version
:
string
]:
TPromise
<
string
>
;
}
=
Object
.
create
(
null
);
export
function
loadReleaseNotes
(
accessor
:
ServicesAccessor
,
version
:
string
):
TPromise
<
string
>
{
function
loadReleaseNotes
(
accessor
:
ServicesAccessor
,
version
:
string
):
TPromise
<
string
>
{
const
requestService
=
accessor
.
get
(
IRequestService
);
const
keybindingService
=
accessor
.
get
(
IKeybindingService
);
const
match
=
/^
(\d
+
\.\d
+
)\.
/
.
exec
(
version
);
...
...
src/vs/workbench/parts/webview/electron-browser/webview.contribution.ts
0 → 100644
浏览文件 @
267f791f
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
IEditorRegistry
,
EditorDescriptor
,
Extensions
as
EditorExtensions
}
from
'
vs/workbench/browser/editor
'
;
import
{
WebviewEditor
}
from
'
./webviewEditor
'
;
import
{
SyncDescriptor
}
from
'
vs/platform/instantiation/common/descriptors
'
;
import
{
Registry
}
from
'
vs/platform/registry/common/platform
'
;
import
{
WebviewInput
}
from
'
./webviewInput
'
;
import
{
localize
}
from
'
vs/nls
'
;
(
<
IEditorRegistry
>
Registry
.
as
(
EditorExtensions
.
Editors
)).
registerEditor
(
new
EditorDescriptor
(
WebviewEditor
,
WebviewEditor
.
ID
,
localize
(
'
webview.editor.label
'
,
"
webview editor
"
)),
[
new
SyncDescriptor
(
WebviewInput
)]);
\ No newline at end of file
src/vs/workbench/parts/webview/electron-browser/webviewEditor.ts
0 → 100644
浏览文件 @
267f791f
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
IDisposable
,
}
from
'
vs/base/common/lifecycle
'
;
import
{
EditorOptions
}
from
'
vs/workbench/common/editor
'
;
import
{
Position
}
from
'
vs/platform/editor/common/editor
'
;
import
{
WebviewEditor
as
BaseWebviewEditor
,
KEYBINDING_CONTEXT_WEBVIEWEDITOR_FOCUS
,
KEYBINDING_CONTEXT_WEBVIEWEDITOR_FIND_WIDGET_INPUT_FOCUSED
,
KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE
}
from
'
vs/workbench/parts/html/browser/webviewEditor
'
;
import
{
Builder
,
Dimension
}
from
'
vs/base/browser/builder
'
;
import
{
Webview
}
from
'
vs/workbench/parts/html/browser/webview
'
;
import
{
IContextKeyService
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
ITelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
{
IThemeService
}
from
'
vs/platform/theme/common/themeService
'
;
import
{
IPartService
,
Parts
}
from
'
vs/workbench/services/part/common/partService
'
;
import
{
IStorageService
}
from
'
vs/platform/storage/common/storage
'
;
import
{
IContextViewService
}
from
'
vs/platform/contextview/browser/contextView
'
;
import
{
IEnvironmentService
}
from
'
vs/platform/environment/common/environment
'
;
import
{
IWorkspaceContextService
}
from
'
vs/platform/workspace/common/workspace
'
;
import
DOM
=
require
(
'
vs/base/browser/dom
'
);
import
Event
,
{
Emitter
}
from
'
vs/base/common/event
'
;
import
{
WebviewInput
}
from
'
vs/workbench/parts/webview/electron-browser/webviewInput
'
;
export
class
WebviewEditor
extends
BaseWebviewEditor
{
public
static
readonly
ID
=
'
WebviewEditor
'
;
private
editorFrame
:
HTMLElement
;
private
webviewContent
:
HTMLElement
;
private
_onDidFocusWebview
:
Emitter
<
void
>
;
private
_webviewFocusTracker
?:
DOM
.
IFocusTracker
;
private
_webviewFocusListenerDisposable
?:
IDisposable
;
constructor
(
@
ITelemetryService
telemetryService
:
ITelemetryService
,
@
IStorageService
storageService
:
IStorageService
,
@
IThemeService
themeService
:
IThemeService
,
@
IContextKeyService
private
_contextKeyService
:
IContextKeyService
,
@
IPartService
private
readonly
_partService
:
IPartService
,
@
IContextViewService
private
readonly
_contextViewService
:
IContextViewService
,
@
IEnvironmentService
private
readonly
_environmentService
:
IEnvironmentService
,
@
IWorkspaceContextService
private
readonly
_contextService
:
IWorkspaceContextService
)
{
super
(
WebviewEditor
.
ID
,
telemetryService
,
themeService
,
storageService
,
_contextKeyService
);
this
.
_onDidFocusWebview
=
new
Emitter
<
void
>
();
}
protected
createEditor
(
parent
:
Builder
):
void
{
this
.
editorFrame
=
parent
.
getHTMLElement
();
this
.
content
=
document
.
createElement
(
'
div
'
);
parent
.
append
(
this
.
content
);
}
private
doUpdateContainer
()
{
const
webviewContainer
=
this
.
input
&&
(
this
.
input
as
WebviewInput
).
container
;
if
(
webviewContainer
)
{
const
frameRect
=
this
.
editorFrame
.
getBoundingClientRect
();
const
containerRect
=
webviewContainer
.
parentElement
.
getBoundingClientRect
();
webviewContainer
.
style
.
position
=
'
absolute
'
;
webviewContainer
.
style
.
top
=
`
${
frameRect
.
top
-
containerRect
.
top
}
px`
;
webviewContainer
.
style
.
left
=
`
${
frameRect
.
left
-
containerRect
.
left
}
px`
;
webviewContainer
.
style
.
width
=
`
${
frameRect
.
width
}
px`
;
webviewContainer
.
style
.
height
=
`
${
frameRect
.
height
}
px`
;
}
}
public
layout
(
dimension
:
Dimension
):
void
{
if
(
this
.
_webview
)
{
this
.
doUpdateContainer
();
}
super
.
layout
(
dimension
);
}
public
dispose
():
void
{
// Let the editor input dispose of the webview.
this
.
_webview
=
undefined
;
this
.
webviewContent
=
undefined
;
this
.
_onDidFocusWebview
.
dispose
();
if
(
this
.
_webviewFocusTracker
)
{
this
.
_webviewFocusTracker
.
dispose
();
}
if
(
this
.
_webviewFocusListenerDisposable
)
{
this
.
_webviewFocusListenerDisposable
.
dispose
();
}
super
.
dispose
();
}
public
sendMessage
(
data
:
any
):
void
{
if
(
this
.
_webview
)
{
this
.
_webview
.
sendMessage
(
data
);
}
}
public
get
onDidFocus
():
Event
<
any
>
{
return
this
.
_onDidFocusWebview
.
event
;
}
protected
setEditorVisible
(
visible
:
boolean
,
position
?:
Position
):
void
{
if
(
this
.
input
&&
this
.
input
instanceof
WebviewInput
)
{
if
(
visible
)
{
this
.
input
.
claimWebview
(
this
);
}
else
{
this
.
input
.
releaseWebview
(
this
);
}
this
.
updateWebview
(
this
.
input
as
WebviewInput
);
}
if
(
this
.
webviewContent
)
{
if
(
visible
)
{
this
.
webviewContent
.
style
.
visibility
=
'
visible
'
;
this
.
doUpdateContainer
();
}
else
{
this
.
webviewContent
.
style
.
visibility
=
'
hidden
'
;
}
}
super
.
setEditorVisible
(
visible
,
position
);
}
public
clearInput
()
{
if
(
this
.
input
&&
this
.
input
instanceof
WebviewInput
)
{
this
.
input
.
releaseWebview
(
this
);
}
this
.
_webview
=
undefined
;
this
.
webviewContent
=
undefined
;
super
.
clearInput
();
}
async
setInput
(
input
:
WebviewInput
,
options
:
EditorOptions
):
TPromise
<
void
>
{
if
(
this
.
input
&&
this
.
input
.
matches
(
input
))
{
return
undefined
;
}
if
(
this
.
input
&&
this
.
input
.
getResource
().
fsPath
!==
input
.
getResource
().
fsPath
)
{
(
this
.
input
as
WebviewInput
).
releaseWebview
(
this
);
this
.
_webview
=
undefined
;
this
.
webviewContent
=
undefined
;
}
await
super
.
setInput
(
input
,
options
);
input
.
onDidChangePosition
(
this
.
position
);
this
.
updateWebview
(
input
);
}
private
updateWebview
(
input
:
WebviewInput
)
{
const
webview
=
this
.
getWebview
(
input
);
input
.
claimWebview
(
this
);
webview
.
options
=
{
allowScripts
:
input
.
options
.
enableScripts
,
enableWrappedPostMessage
:
true
,
useSameOriginForRoot
:
false
,
localResourceRoots
:
(
input
&&
input
.
options
.
localResourceRoots
)
||
this
.
_contextService
.
getWorkspace
().
folders
.
map
(
x
=>
x
.
uri
)
};
input
.
setHtml
(
input
.
html
);
this
.
webviewContent
.
style
.
visibility
=
'
visible
'
;
this
.
doUpdateContainer
();
}
private
getWebview
(
input
:
WebviewInput
):
Webview
{
if
(
this
.
_webview
)
{
return
this
.
_webview
;
}
this
.
webviewContent
=
input
.
container
;
const
existing
=
input
.
webview
;
if
(
existing
)
{
this
.
_webview
=
existing
;
return
existing
;
}
this
.
_webviewFocusTracker
=
DOM
.
trackFocus
(
this
.
webviewContent
);
this
.
_webviewFocusListenerDisposable
=
this
.
_webviewFocusTracker
.
onDidFocus
(()
=>
{
this
.
_onDidFocusWebview
.
fire
();
});
this
.
_contextKeyService
=
this
.
_contextKeyService
.
createScoped
(
this
.
webviewContent
);
this
.
contextKey
=
KEYBINDING_CONTEXT_WEBVIEWEDITOR_FOCUS
.
bindTo
(
this
.
_contextKeyService
);
this
.
findInputFocusContextKey
=
KEYBINDING_CONTEXT_WEBVIEWEDITOR_FIND_WIDGET_INPUT_FOCUSED
.
bindTo
(
this
.
_contextKeyService
);
this
.
findWidgetVisible
=
KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE
.
bindTo
(
this
.
_contextKeyService
);
this
.
_webview
=
new
Webview
(
this
.
webviewContent
,
this
.
_partService
.
getContainer
(
Parts
.
EDITOR_PART
),
this
.
themeService
,
this
.
_environmentService
,
this
.
_contextViewService
,
this
.
contextKey
,
this
.
findInputFocusContextKey
,
{
enableWrappedPostMessage
:
true
,
useSameOriginForRoot
:
false
});
input
.
webview
=
this
.
_webview
;
this
.
content
.
setAttribute
(
'
aria-flowto
'
,
this
.
webviewContent
.
id
);
this
.
doUpdateContainer
();
return
this
.
_webview
;
}
}
src/vs/workbench/parts/webview/electron-browser/webviewInput.ts
0 → 100644
浏览文件 @
267f791f
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
EditorInput
,
EditorModel
}
from
'
vs/workbench/common/editor
'
;
import
{
IEditorModel
,
Position
}
from
'
vs/platform/editor/common/editor
'
;
import
{
Webview
}
from
'
vs/workbench/parts/html/browser/webview
'
;
import
{
IPartService
,
Parts
}
from
'
vs/workbench/services/part/common/partService
'
;
import
*
as
vscode
from
'
vscode
'
;
import
URI
from
'
vs/base/common/uri
'
;
export
interface
WebviewEvents
{
onMessage
(
message
:
any
):
void
;
onDidChangePosition
(
newPosition
:
Position
):
void
;
onDispose
():
void
;
onDidClickLink
(
link
:
URI
,
options
:
vscode
.
WebviewOptions
):
void
;
}
export
class
WebviewInput
extends
EditorInput
{
private
static
handlePool
=
0
;
private
readonly
_resource
:
URI
;
private
_name
:
string
;
private
_options
:
vscode
.
WebviewOptions
;
private
_html
:
string
;
private
_currentWebviewHtml
:
string
=
''
;
private
_events
:
WebviewEvents
|
undefined
;
private
_container
:
HTMLElement
;
private
_webview
:
Webview
|
undefined
;
private
_webviewOwner
:
any
;
private
_webviewDisposables
:
IDisposable
[]
=
[];
private
_position
:
Position
;
public
static
create
(
resource
:
URI
,
name
:
string
,
position
:
Position
,
options
:
vscode
.
WebviewOptions
,
html
:
string
,
events
:
WebviewEvents
,
partService
:
IPartService
):
WebviewInput
{
const
id
=
WebviewInput
.
handlePool
++
;
const
webviewContainer
=
document
.
createElement
(
'
div
'
);
webviewContainer
.
id
=
`webview-
${
id
}
`
;
partService
.
getContainer
(
Parts
.
EDITOR_PART
).
appendChild
(
webviewContainer
);
return
new
WebviewInput
(
resource
,
name
,
position
,
options
,
html
,
events
,
webviewContainer
,
undefined
);
}
constructor
(
resource
:
URI
,
name
:
string
,
position
:
Position
,
options
:
vscode
.
WebviewOptions
,
html
:
string
,
events
:
WebviewEvents
,
container
:
HTMLElement
,
webview
:
Webview
|
undefined
)
{
super
();
this
.
_resource
=
resource
;
this
.
_name
=
name
;
this
.
_position
=
position
;
this
.
_options
=
options
;
this
.
_html
=
html
;
this
.
_events
=
events
;
this
.
_container
=
container
;
this
.
_webview
=
webview
;
}
public
getTypeId
():
string
{
return
'
webview
'
;
}
public
dispose
()
{
this
.
disposeWebview
();
if
(
this
.
_container
)
{
this
.
_container
.
remove
();
this
.
_container
=
undefined
;
}
if
(
this
.
_events
)
{
this
.
_events
.
onDispose
();
this
.
_events
=
undefined
;
}
super
.
dispose
();
}
public
getResource
():
URI
{
return
this
.
_resource
;
}
public
getName
():
string
{
return
this
.
_name
;
}
public
setName
(
value
:
string
):
void
{
this
.
_name
=
value
;
this
.
_onDidChangeLabel
.
fire
();
}
public
get
position
():
Position
{
return
this
.
_position
;
}
public
get
html
():
string
{
return
this
.
_html
;
}
public
setHtml
(
value
:
string
):
void
{
if
(
value
===
this
.
_currentWebviewHtml
)
{
return
;
}
this
.
_html
=
value
;
if
(
this
.
_webview
)
{
this
.
_webview
.
contents
=
value
;
this
.
_currentWebviewHtml
=
value
;
}
}
public
get
options
():
vscode
.
WebviewOptions
{
return
this
.
_options
;
}
public
set
options
(
value
:
vscode
.
WebviewOptions
)
{
this
.
_options
=
value
;
}
public
resolve
(
refresh
?:
boolean
):
TPromise
<
IEditorModel
,
any
>
{
return
TPromise
.
as
(
new
EditorModel
());
}
public
supportsSplitEditor
()
{
return
false
;
}
public
get
container
():
HTMLElement
{
return
this
.
_container
;
}
public
get
webview
():
Webview
|
undefined
{
return
this
.
_webview
;
}
public
set
webview
(
value
:
Webview
)
{
this
.
_webviewDisposables
=
dispose
(
this
.
_webviewDisposables
);
this
.
_webview
=
value
;
this
.
_webview
.
onDidClickLink
(
link
=>
{
if
(
this
.
_events
)
{
this
.
_events
.
onDidClickLink
(
link
,
this
.
_options
);
}
},
null
,
this
.
_webviewDisposables
);
this
.
_webview
.
onMessage
(
message
=>
{
if
(
this
.
_events
)
{
this
.
_events
.
onMessage
(
message
);
}
},
null
,
this
.
_webviewDisposables
);
}
public
claimWebview
(
owner
:
any
)
{
this
.
_webviewOwner
=
owner
;
}
public
releaseWebview
(
owner
:
any
)
{
if
(
this
.
_webviewOwner
===
owner
)
{
this
.
_webviewOwner
=
undefined
;
if
(
this
.
_options
.
retainContextWhenHidden
)
{
this
.
container
.
style
.
visibility
=
'
hidden
'
;
}
else
{
this
.
disposeWebview
();
}
}
}
public
disposeWebview
()
{
// The input owns the webview and its parent
if
(
this
.
_webview
)
{
this
.
_webview
.
dispose
();
this
.
_webview
=
undefined
;
}
this
.
_webviewDisposables
=
dispose
(
this
.
_webviewDisposables
);
this
.
_webviewOwner
=
undefined
;
this
.
container
.
style
.
visibility
=
'
hidden
'
;
this
.
_currentWebviewHtml
=
''
;
}
public
onDidChangePosition
(
position
:
Position
)
{
if
(
this
.
_events
)
{
this
.
_events
.
onDidChangePosition
(
position
);
}
this
.
_position
=
position
;
}
}
src/vs/workbench/workbench.main.ts
浏览文件 @
267f791f
...
...
@@ -68,6 +68,8 @@ import 'vs/workbench/parts/markers/browser/markersPanel'; // can be packaged sep
import
'
vs/workbench/parts/html/browser/html.contribution
'
;
import
'
vs/workbench/parts/webview/electron-browser/webview.contribution
'
;
import
'
vs/workbench/parts/welcome/walkThrough/electron-browser/walkThrough.contribution
'
;
import
'
vs/workbench/parts/extensions/electron-browser/extensions.contribution
'
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录