Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Unified Diff: sky/framework/sky-scrollable.sky

Issue 882583002: Add a scrollbar to sky-scrollable (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/framework/sky-scrollable.sky
diff --git a/sky/framework/sky-scrollable.sky b/sky/framework/sky-scrollable.sky
index dd22953e5ce86accf11e99cf5873ec1459688c58..e04a620b94dca48f551e5433b24b0bb3e181c2e0 100644
--- a/sky/framework/sky-scrollable.sky
+++ b/sky/framework/sky-scrollable.sky
@@ -17,19 +17,32 @@
<style>
:host {
overflow: hidden;
+ position: relative;
}
#scrollable {
transform: translateY(0);
}
+ #vbar {
+ position: absolute;
+ right: 0;
+ width: 3px;
+ background-color: lightgray;
+ top: 0;
+ height: 0;
+ }
</style>
+ <div id="vbar" />
<div id="scrollable">
<content />
</div>
</template>
<script>
+const kScrollbarFadeDurationMS = 300;
+
module.exports = class extends SkyElement {
created() {
this.scrollable_ = null;
+ this.vbar_ = null;
this.scrollOffset_ = 0;
this.flingCurve_ = null;
this.flingAnimationId_ = null;
@@ -37,21 +50,35 @@ module.exports = class extends SkyElement {
shadowRootReady() {
this.scrollable_ = this.shadowRoot.getElementById('scrollable');
+ this.vbar_ = this.shadowRoot.getElementById('vbar');
}
- scrollBy(scrollDelta) {
- var scrollHeight = this.scrollable_.clientHeight - this.clientHeight;
- var offset = Math.max(0, Math.min(scrollHeight, this.scrollOffset_ + scrollDelta));
- if (offset == this.scrollOffset_)
- return false;
- this.scrollOffset_ = offset;
- this.applyScrollOffset_();
- return true;
+ get scrollOffset() {
+ return this.scrollOffset_;
}
- applyScrollOffset_() {
+ set scrollOffset(value) {
+ // TODO(abarth): Can we get these values without forcing a synchronous layout?
ojan 2015/01/27 05:32:25 We should add apis that give you stale values and
abarth-chromium 2015/01/27 05:36:39 Yeah, it seems fine to use stale values here. I a
abarth-chromium 2015/01/27 05:36:39 Yeah, it seems fine to use stale values here. I a
+ var outerHeight = this.clientHeight;
+ var innerHeight = this.scrollable_.clientHeight;
+ var scrollRange = innerHeight - outerHeight;
+ var newScrollOffset = Math.max(0, Math.min(scrollRange, value));
+ if (newScrollOffset == this.scrollOffset_)
+ return;
+ this.scrollOffset_ = newScrollOffset;
var transform = 'translateY(' + -this.scrollOffset_.toFixed(2) + 'px)';
this.scrollable_.style.transform = transform;
+
+ var topPercent = newScrollOffset / innerHeight * 100;
+ var heightPercent = outerHeight / innerHeight * 100;
+ this.vbar_.style.top = topPercent + '%';
+ this.vbar_.style.height = heightPercent + '%';
ojan 2015/01/27 05:32:25 This won't work if the scrollable's height is auto
abarth-chromium 2015/01/27 05:36:39 Yeah. This should work as long as you don't chang
+ }
+
+ scrollBy(scrollDelta) {
+ var oldScrollOffset = this.scrollOffset_;
+ this.scrollOffset += scrollDelta;
+ return this.scrollOffset_ != oldScrollOffset;
}
scheduleFlingUpdate_() {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698