Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
8120b8f4
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,发现更多精彩内容 >>
提交
8120b8f4
编写于
4月 29, 2016
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Extract ScrollbarState to its own file
上级
83ee1c98
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
186 addition
and
177 deletion
+186
-177
src/vs/base/browser/ui/scrollbar/abstractScrollbar.ts
src/vs/base/browser/ui/scrollbar/abstractScrollbar.ts
+2
-177
src/vs/base/browser/ui/scrollbar/scrollbarState.ts
src/vs/base/browser/ui/scrollbar/scrollbarState.ts
+184
-0
未找到文件。
src/vs/base/browser/ui/scrollbar/abstractScrollbar.ts
浏览文件 @
8120b8f4
...
...
@@ -14,6 +14,7 @@ import {GlobalMouseMoveMonitor, IStandardMouseMoveEventData, standardMouseMoveMe
import
{
Widget
}
from
'
vs/base/browser/ui/widget
'
;
import
{
TimeoutTimer
,
IntervalTimer
}
from
'
vs/base/common/async
'
;
import
{
FastDomNode
,
createFastDomNode
}
from
'
vs/base/browser/styleMutator
'
;
import
{
ScrollbarState
}
from
'
vs/base/browser/ui/scrollbar/scrollbarState
'
;
/**
* The arrow image size.
...
...
@@ -25,189 +26,13 @@ export const ARROW_IMG_SIZE = 11;
*/
const
MOUSE_DRAG_RESET_DISTANCE
=
140
;
/**
* The minimal size of the slider (such that it can still be clickable) -- it is artificially enlarged.
*/
const
MINIMUM_SLIDER_SIZE
=
20
;
export
interface
IMouseWheelEventFactory
{
():
IMouseWheelEvent
;
}
export
class
ScrollbarState
{
// --- immutable
private
_scrollbarSize
:
number
;
private
_oppositeScrollbarSize
:
number
;
private
_arrowSize
:
number
;
// --- variables
private
_visibleSize
:
number
;
private
_scrollSize
:
number
;
private
_scrollPosition
:
number
;
// --- computed variables
/**
* `visibleSize` - `oppositeScrollbarSize`
*/
private
_computedAvailableSize
:
number
;
/**
* `computedAvailableSize` - 2 * `arrowSize`
*/
private
_computedRepresentableSize
:
number
;
/**
* `computedRepresentableSize` / `scrollSize`
*/
private
_computedRatio
:
number
;
/**
* (`scrollSize` > `visibleSize`)
*/
private
_computedIsNeeded
:
boolean
;
private
_computedSliderSize
:
number
;
private
_computedSliderPosition
:
number
;
constructor
(
arrowSize
:
number
,
scrollbarSize
:
number
,
oppositeScrollbarSize
:
number
)
{
this
.
_scrollbarSize
=
Math
.
round
(
scrollbarSize
);
this
.
_oppositeScrollbarSize
=
Math
.
round
(
oppositeScrollbarSize
);
this
.
_arrowSize
=
Math
.
round
(
arrowSize
);
this
.
_visibleSize
=
0
;
this
.
_scrollSize
=
0
;
this
.
_scrollPosition
=
0
;
this
.
_computedAvailableSize
=
0
;
this
.
_computedRepresentableSize
=
0
;
this
.
_computedRatio
=
0.1
;
this
.
_computedIsNeeded
=
false
;
this
.
_computedSliderSize
=
0
;
this
.
_computedSliderPosition
=
0
;
this
.
_refreshComputedValues
();
}
public
setVisibleSize
(
visibleSize
:
number
):
boolean
{
let
iVisibleSize
=
Math
.
round
(
visibleSize
);
if
(
this
.
_visibleSize
!==
iVisibleSize
)
{
this
.
_visibleSize
=
iVisibleSize
;
this
.
_refreshComputedValues
();
return
true
;
}
return
false
;
}
public
setScrollSize
(
scrollSize
:
number
):
boolean
{
let
iScrollSize
=
Math
.
round
(
scrollSize
);
if
(
this
.
_scrollSize
!==
iScrollSize
)
{
this
.
_scrollSize
=
iScrollSize
;
this
.
_refreshComputedValues
();
return
true
;
}
return
false
;
}
public
setScrollPosition
(
scrollPosition
:
number
):
boolean
{
let
iScrollPosition
=
Math
.
round
(
scrollPosition
);
if
(
this
.
_scrollPosition
!==
iScrollPosition
)
{
this
.
_scrollPosition
=
iScrollPosition
;
this
.
_refreshComputedValues
();
return
true
;
}
return
false
;
}
private
_refreshComputedValues
():
void
{
const
oppositeScrollbarSize
=
this
.
_oppositeScrollbarSize
;
const
arrowSize
=
this
.
_arrowSize
;
const
visibleSize
=
this
.
_visibleSize
;
const
scrollSize
=
this
.
_scrollSize
;
const
scrollPosition
=
this
.
_scrollPosition
;
let
computedAvailableSize
=
Math
.
max
(
0
,
visibleSize
-
oppositeScrollbarSize
);
let
computedRepresentableSize
=
Math
.
max
(
0
,
computedAvailableSize
-
2
*
arrowSize
);
let
computedRatio
=
scrollSize
>
0
?
(
computedRepresentableSize
/
scrollSize
)
:
0
;
let
computedIsNeeded
=
(
scrollSize
>
visibleSize
);
let
computedSliderSize
:
number
;
let
computedSliderPosition
:
number
;
if
(
!
computedIsNeeded
)
{
computedSliderSize
=
computedRepresentableSize
;
computedSliderPosition
=
0
;
}
else
{
computedSliderSize
=
Math
.
floor
(
visibleSize
*
computedRatio
);
computedSliderPosition
=
Math
.
floor
(
scrollPosition
*
computedRatio
);
if
(
computedSliderSize
<
MINIMUM_SLIDER_SIZE
)
{
// We must artificially increase the size of the slider, since the slider would be too small otherwise
// The effort is to keep the slider centered around the original position, but we must take into
// account the cases when the slider is too close to the top or too close to the bottom
let
sliderArtificialOffset
=
(
MINIMUM_SLIDER_SIZE
-
computedSliderSize
)
/
2
;
computedSliderSize
=
MINIMUM_SLIDER_SIZE
;
computedSliderPosition
-=
sliderArtificialOffset
;
if
(
computedSliderPosition
+
computedSliderSize
>
computedRepresentableSize
)
{
// Slider is too close to the bottom, so we glue it to the bottom
computedSliderPosition
=
computedRepresentableSize
-
computedSliderSize
;
}
if
(
computedSliderPosition
<
0
)
{
// Slider is too close to the top, so we glue it to the top
computedSliderPosition
=
0
;
}
}
}
this
.
_computedAvailableSize
=
Math
.
round
(
computedAvailableSize
);
this
.
_computedRepresentableSize
=
Math
.
round
(
computedRepresentableSize
);
this
.
_computedRatio
=
computedRatio
;
this
.
_computedIsNeeded
=
computedIsNeeded
;
this
.
_computedSliderSize
=
Math
.
round
(
computedSliderSize
);
this
.
_computedSliderPosition
=
Math
.
round
(
computedSliderPosition
);
}
public
getArrowSize
():
number
{
return
this
.
_arrowSize
;
}
public
getRectangleLargeSize
():
number
{
return
this
.
_computedAvailableSize
;
}
public
getRectangleSmallSize
():
number
{
return
this
.
_scrollbarSize
;
}
public
isNeeded
():
boolean
{
return
this
.
_computedIsNeeded
;
}
public
getSliderSize
():
number
{
return
this
.
_computedSliderSize
;
}
public
getSliderPosition
():
number
{
return
this
.
_computedSliderPosition
;
}
public
convertSliderPositionToScrollPosition
(
desiredSliderPosition
:
number
):
number
{
return
desiredSliderPosition
/
this
.
_computedRatio
;
}
public
validateScrollPosition
(
desiredScrollPosition
:
number
):
number
{
desiredScrollPosition
=
Math
.
round
(
desiredScrollPosition
);
desiredScrollPosition
=
Math
.
max
(
desiredScrollPosition
,
0
);
desiredScrollPosition
=
Math
.
min
(
desiredScrollPosition
,
this
.
_scrollSize
-
this
.
_visibleSize
);
return
desiredScrollPosition
;
}
}
class
ScrollbarArrow
extends
Widget
{
private
_parent
:
IParent
;
...
...
src/vs/base/browser/ui/scrollbar/scrollbarState.ts
0 → 100644
浏览文件 @
8120b8f4
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
/**
* The minimal size of the slider (such that it can still be clickable) -- it is artificially enlarged.
*/
const
MINIMUM_SLIDER_SIZE
=
20
;
export
class
ScrollbarState
{
// --- immutable
private
_scrollbarSize
:
number
;
private
_oppositeScrollbarSize
:
number
;
private
_arrowSize
:
number
;
// --- variables
private
_visibleSize
:
number
;
private
_scrollSize
:
number
;
private
_scrollPosition
:
number
;
// --- computed variables
/**
* `visibleSize` - `oppositeScrollbarSize`
*/
private
_computedAvailableSize
:
number
;
/**
* `computedAvailableSize` - 2 * `arrowSize`
*/
private
_computedRepresentableSize
:
number
;
/**
* `computedRepresentableSize` / `scrollSize`
*/
private
_computedRatio
:
number
;
/**
* (`scrollSize` > `visibleSize`)
*/
private
_computedIsNeeded
:
boolean
;
private
_computedSliderSize
:
number
;
private
_computedSliderPosition
:
number
;
constructor
(
arrowSize
:
number
,
scrollbarSize
:
number
,
oppositeScrollbarSize
:
number
)
{
this
.
_scrollbarSize
=
Math
.
round
(
scrollbarSize
);
this
.
_oppositeScrollbarSize
=
Math
.
round
(
oppositeScrollbarSize
);
this
.
_arrowSize
=
Math
.
round
(
arrowSize
);
this
.
_visibleSize
=
0
;
this
.
_scrollSize
=
0
;
this
.
_scrollPosition
=
0
;
this
.
_computedAvailableSize
=
0
;
this
.
_computedRepresentableSize
=
0
;
this
.
_computedRatio
=
0.1
;
this
.
_computedIsNeeded
=
false
;
this
.
_computedSliderSize
=
0
;
this
.
_computedSliderPosition
=
0
;
this
.
_refreshComputedValues
();
}
public
setVisibleSize
(
visibleSize
:
number
):
boolean
{
let
iVisibleSize
=
Math
.
round
(
visibleSize
);
if
(
this
.
_visibleSize
!==
iVisibleSize
)
{
this
.
_visibleSize
=
iVisibleSize
;
this
.
_refreshComputedValues
();
return
true
;
}
return
false
;
}
public
setScrollSize
(
scrollSize
:
number
):
boolean
{
let
iScrollSize
=
Math
.
round
(
scrollSize
);
if
(
this
.
_scrollSize
!==
iScrollSize
)
{
this
.
_scrollSize
=
iScrollSize
;
this
.
_refreshComputedValues
();
return
true
;
}
return
false
;
}
public
setScrollPosition
(
scrollPosition
:
number
):
boolean
{
let
iScrollPosition
=
Math
.
round
(
scrollPosition
);
if
(
this
.
_scrollPosition
!==
iScrollPosition
)
{
this
.
_scrollPosition
=
iScrollPosition
;
this
.
_refreshComputedValues
();
return
true
;
}
return
false
;
}
private
_refreshComputedValues
():
void
{
const
oppositeScrollbarSize
=
this
.
_oppositeScrollbarSize
;
const
arrowSize
=
this
.
_arrowSize
;
const
visibleSize
=
this
.
_visibleSize
;
const
scrollSize
=
this
.
_scrollSize
;
const
scrollPosition
=
this
.
_scrollPosition
;
let
computedAvailableSize
=
Math
.
max
(
0
,
visibleSize
-
oppositeScrollbarSize
);
let
computedRepresentableSize
=
Math
.
max
(
0
,
computedAvailableSize
-
2
*
arrowSize
);
let
computedRatio
=
scrollSize
>
0
?
(
computedRepresentableSize
/
scrollSize
)
:
0
;
let
computedIsNeeded
=
(
scrollSize
>
visibleSize
);
let
computedSliderSize
:
number
;
let
computedSliderPosition
:
number
;
if
(
!
computedIsNeeded
)
{
computedSliderSize
=
computedRepresentableSize
;
computedSliderPosition
=
0
;
}
else
{
computedSliderSize
=
Math
.
floor
(
visibleSize
*
computedRatio
);
computedSliderPosition
=
Math
.
floor
(
scrollPosition
*
computedRatio
);
if
(
computedSliderSize
<
MINIMUM_SLIDER_SIZE
)
{
// We must artificially increase the size of the slider, since the slider would be too small otherwise
// The effort is to keep the slider centered around the original position, but we must take into
// account the cases when the slider is too close to the top or too close to the bottom
let
sliderArtificialOffset
=
(
MINIMUM_SLIDER_SIZE
-
computedSliderSize
)
/
2
;
computedSliderSize
=
MINIMUM_SLIDER_SIZE
;
computedSliderPosition
-=
sliderArtificialOffset
;
if
(
computedSliderPosition
+
computedSliderSize
>
computedRepresentableSize
)
{
// Slider is too close to the bottom, so we glue it to the bottom
computedSliderPosition
=
computedRepresentableSize
-
computedSliderSize
;
}
if
(
computedSliderPosition
<
0
)
{
// Slider is too close to the top, so we glue it to the top
computedSliderPosition
=
0
;
}
}
}
this
.
_computedAvailableSize
=
Math
.
round
(
computedAvailableSize
);
this
.
_computedRepresentableSize
=
Math
.
round
(
computedRepresentableSize
);
this
.
_computedRatio
=
computedRatio
;
this
.
_computedIsNeeded
=
computedIsNeeded
;
this
.
_computedSliderSize
=
Math
.
round
(
computedSliderSize
);
this
.
_computedSliderPosition
=
Math
.
round
(
computedSliderPosition
);
}
public
getArrowSize
():
number
{
return
this
.
_arrowSize
;
}
public
getRectangleLargeSize
():
number
{
return
this
.
_computedAvailableSize
;
}
public
getRectangleSmallSize
():
number
{
return
this
.
_scrollbarSize
;
}
public
isNeeded
():
boolean
{
return
this
.
_computedIsNeeded
;
}
public
getSliderSize
():
number
{
return
this
.
_computedSliderSize
;
}
public
getSliderPosition
():
number
{
return
this
.
_computedSliderPosition
;
}
public
convertSliderPositionToScrollPosition
(
desiredSliderPosition
:
number
):
number
{
return
desiredSliderPosition
/
this
.
_computedRatio
;
}
public
validateScrollPosition
(
desiredScrollPosition
:
number
):
number
{
desiredScrollPosition
=
Math
.
round
(
desiredScrollPosition
);
desiredScrollPosition
=
Math
.
max
(
desiredScrollPosition
,
0
);
desiredScrollPosition
=
Math
.
min
(
desiredScrollPosition
,
this
.
_scrollSize
-
this
.
_visibleSize
);
return
desiredScrollPosition
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录