Commit a456ee36 authored by dgozman@chromium.org's avatar dgozman@chromium.org

[filebrowser] Yet another animation in gallery ribbon.

BUG=chromium-os:23434
TEST=See bug.

Review URL: http://codereview.chromium.org/8770044

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112969 0039d316-1c4b-4281-b951-d872f2087c98
parent 95dacd08
...@@ -238,7 +238,7 @@ body { ...@@ -238,7 +238,7 @@ body {
.gallery .filename-spacer > input { .gallery .filename-spacer > input {
background-color: transparent; background-color: transparent;
color: white; color: white;
width: 40em; width: 200px;
border: none; border: none;
outline: none; outline: none;
} }
...@@ -252,31 +252,26 @@ body { ...@@ -252,31 +252,26 @@ body {
/* Thumbnails */ /* Thumbnails */
.gallery .ribbon-spacer { .gallery .ribbon-spacer {
position: relative;
display: -webkit-box; display: -webkit-box;
-webkit-box-flex: 1; -webkit-box-flex: 1;
-webkit-box-orient: horizontal; -webkit-box-orient: horizontal;
-webkit-box-pack: center;
} }
.gallery .toolbar .ribbon { .gallery .toolbar .ribbon {
position: absolute;
top: 0px;
left: 0px;
overflow: hidden; overflow: hidden;
height: 100%; height: 100%;
-webkit-box-flex: 0;
display: -webkit-box; display: -webkit-box;
-webkit-box-orient: horizontal; -webkit-box-orient: horizontal;
-webkit-box-pack: left; -webkit-box-pack: start;
width: 280px;
max-width: 100%; max-width: 100%;
-webkit-transition: max-width 500ms ease-in-out; -webkit-transition: max-width 500ms ease-in-out;
z-index: 0; z-index: 0;
} }
.gallery .toolbar .ribbon[inactive] {
z-index: -1;
}
.gallery[editing] .toolbar .ribbon { .gallery[editing] .toolbar .ribbon {
max-width: 0; max-width: 0;
} }
...@@ -292,18 +287,23 @@ body { ...@@ -292,18 +287,23 @@ body {
height: 47px; height: 47px;
margin: 2px; margin: 2px;
border: 2px solid rgba(255,255,255,0); /* transparent white */ border: 2px solid rgba(255,255,255,0); /* transparent white */
-webkit-transition: margin-left 180ms linear;
}
.gallery .ribbon-image[selected] {
border: 2px solid rgba(255,233,168,1);
}
margin-left: 2px; .gallery .toolbar .ribbon.fade-left {
-webkit-transition: opacity 200ms linear; -webkit-mask-image: -webkit-linear-gradient(left, rgba(0,0,0,0) 0, rgba(0,0,0,1) 40px);
} }
.gallery .ribbon-image[inactive] { .gallery .toolbar .ribbon.fade-right {
opacity: 0; -webkit-mask-image: -webkit-linear-gradient(right, rgba(0,0,0,0) 0, rgba(0,0,0,1) 40px);
pointer-events: none;
} }
.gallery .ribbon-image[selected] { .gallery .toolbar .ribbon.fade-left.fade-right {
border: 2px solid rgba(255,233,168,1); -webkit-mask-image: -webkit-linear-gradient(left, rgba(0,0,0,0) 0, rgba(0,0,0,1) 40px, rgba(0,0,0,1) 230px, rgba(0,0,0,0) 100%);
} }
.gallery .image-wrapper { .gallery .image-wrapper {
...@@ -314,34 +314,6 @@ body { ...@@ -314,34 +314,6 @@ body {
border: 1px solid rgba(0,0,0,0); /* transparent black */ border: 1px solid rgba(0,0,0,0); /* transparent black */
} }
.gallery .toolbar .fade {
background-repeat: no-repeat;
background-position: center center;
position: absolute;
z-index: 10;
width: 55px;
height: 100%;
pointer-events: none;
opacity: 0;
-webkit-transition: opacity 200ms linear;
}
.gallery .toolbar .fade[active] {
opacity: 1;
}
.gallery[editing] .toolbar .fade[active] {
opacity: 0;
}
.gallery .toolbar .fade.left {
background-image: url(../../images/gallery/thumb_fade_left.png);
}
.gallery .toolbar .fade.right {
background-image: url(../../images/gallery/thumb_fade_right.png);
}
/* Editor buttons */ /* Editor buttons */
.gallery .toolbar .edit-bar { .gallery .toolbar .edit-bar {
......
...@@ -501,24 +501,9 @@ function Ribbon(container, client, metadataProvider, arrowLeft, arrowRight) { ...@@ -501,24 +501,9 @@ function Ribbon(container, client, metadataProvider, arrowLeft, arrowRight) {
this.arrowRight_. this.arrowRight_.
addEventListener('click', this.selectNext.bind(this, 1, null)); addEventListener('click', this.selectNext.bind(this, 1, null));
this.fadeLeft_ = this.document_.createElement('div'); this.bar_ = this.document_.createElement('div');
this.fadeLeft_.className = 'fade left'; this.bar_.className = 'ribbon';
this.container_.appendChild(this.fadeLeft_); this.container_.appendChild(this.bar_);
this.bars_ = [];
for (var i = 0; i < 2; i++) {
var bar = this.document_.createElement('div');
bar.className = 'ribbon';
this.container_.appendChild(bar);
this.bars_.push(bar);
}
this.activeBarIndex_ = 0;
ImageUtil.setAttribute(this.bars_[0], 'inactive', false);
ImageUtil.setAttribute(this.bars_[1], 'inactive', true);
this.fadeRight_ = this.document_.createElement('div');
this.fadeRight_.className = 'fade right';
this.container_.appendChild(this.fadeRight_);
} }
Ribbon.PAGING_SINGLE_ITEM_DELAY = 20; Ribbon.PAGING_SINGLE_ITEM_DELAY = 20;
...@@ -529,11 +514,7 @@ Ribbon.prototype.getSelectedItem = function () { ...@@ -529,11 +514,7 @@ Ribbon.prototype.getSelectedItem = function () {
}; };
Ribbon.prototype.clear = function() { Ribbon.prototype.clear = function() {
this.bars_[0].textContent = ''; this.bar_.textContent = '';
this.bars_[1].textContent = '';
this.activeBarIndex_ = 0;
ImageUtil.setAttribute(this.bars_[0], 'inactive', false);
ImageUtil.setAttribute(this.bars_[1], 'inactive', true);
this.items_ = []; this.items_ = [];
this.selectedIndex_ = -1; this.selectedIndex_ = -1;
this.firstVisibleIndex_ = 0; this.firstVisibleIndex_ = 0;
...@@ -639,89 +620,96 @@ Ribbon.prototype.requestPrefetch = function(direction) { ...@@ -639,89 +620,96 @@ Ribbon.prototype.requestPrefetch = function(direction) {
}); });
}; };
Ribbon.prototype.updateControls_ = function() { Ribbon.ITEMS_COUNT = 5;
ImageUtil.setAttribute(this.fadeLeft_, 'active', this.firstVisibleIndex_ > 0);
ImageUtil.setAttribute(this.fadeRight_, 'active',
this.lastVisibleIndex_ + 1 < this.items_.length);
};
Ribbon.prototype.redraw = function() { Ribbon.prototype.redraw = function() {
// The thumbnails are square. // TODO(dgozman): use margin instead of 2 here.
var itemWidth = this.bars_[0].parentNode.clientHeight; var itemWidth = this.bar_.clientHeight - 2;
var width = this.bars_[0].parentNode.clientWidth; var fullItems = Ribbon.ITEMS_COUNT;
var fullItems = Math.floor(width / itemWidth);
var fullWidth = fullItems * itemWidth;
this.bars_[0].style.width = fullWidth + 'px';
this.bars_[1].style.width = fullWidth + 'px';
// Position the shadows over the first and the last visible thumbnails.
this.fadeLeft_.style.left = 0;
this.fadeRight_.style.right = (width - fullWidth) + 'px';
fullItems = Math.min(fullItems, this.items_.length); fullItems = Math.min(fullItems, this.items_.length);
var firstIndex = this.firstVisibleIndex_; var right = Math.floor((fullItems - 1) / 2);
var lastIndex = firstIndex + fullItems - 1;
if (this.selectedIndex_ <= firstIndex && firstIndex > 0) { var fullWidth = fullItems * itemWidth;
firstIndex = Math.max(0, this.selectedIndex_ - (fullItems >> 1)); this.bar_.style.width = fullWidth + 'px';
lastIndex = firstIndex + fullItems - 1;
}
if (this.selectedIndex_ >= lastIndex && lastIndex < this.items_.length - 1) {
lastIndex = Math.min(this.items_.length - 1,
this.selectedIndex_ + (fullItems >> 1));
firstIndex = lastIndex - fullItems + 1;
}
this.updateControls_(); var lastIndex = this.selectedIndex_ + right;
lastIndex = Math.max(lastIndex, fullItems - 1);
lastIndex = Math.min(lastIndex, this.items_.length - 1);
var firstIndex = lastIndex - fullItems + 1;
if (this.firstVisibleIndex_ == firstIndex && if (this.firstVisibleIndex_ == firstIndex &&
this.lastVisibleIndex_ == lastIndex) { this.lastVisibleIndex_ == lastIndex) {
return; return;
} }
var activeBar = this.bars_[this.activeBarIndex_]; if (this.lastVisibleIndex_ == -1) {
var children = activeBar.childNodes; this.firstVisibleIndex_ = firstIndex;
var totalDuration = children.length * Ribbon.PAGING_SINGLE_ITEM_DELAY + this.lastVisibleIndex_ = lastIndex;
Ribbon.PAGING_ANIMATION_DURATION; }
var direction = 1; this.bar_.textContent = '';
var delay = 0; var startIndex = Math.min(firstIndex, this.firstVisibleIndex_);
if (firstIndex < this.firstVisibleIndex_) { var toRemove = [];
direction = -1; for (var index = startIndex + 1;
delay = (children.length - 1) * Ribbon.PAGING_SINGLE_ITEM_DELAY; index <= Math.max(lastIndex, this.lastVisibleIndex_);
++index) {
var box = this.items_[index].getBox(0);
box.style.marginLeft = '0';
this.bar_.appendChild(box);
if (index < firstIndex || index > lastIndex) {
toRemove.push(index);
} }
for (var index = 0; index < children.length; ++index) {
setTimeout(
ImageUtil.setAttribute.bind(null, children[index], 'inactive', true),
delay);
delay += direction * Ribbon.PAGING_SINGLE_ITEM_DELAY;
} }
// Place inactive bar below active after animation is finished. var margin = itemWidth * Math.abs(firstIndex - this.firstVisibleIndex_);
setTimeout( var startBox = this.items_[startIndex].getBox(0);
ImageUtil.setAttribute.bind(null, activeBar, 'inactive', true), if (startIndex == firstIndex) {
totalDuration); startBox.style.marginLeft = -margin + 'px';
if (this.bar_.firstChild)
this.bar_.insertBefore(startBox, this.bar_.firstChild);
else
this.bar_.appendChild(startBox);
setTimeout(function() {
startBox.style.marginLeft = '0';
}, 0);
} else {
toRemove.push(startBox);
startBox.style.marginLeft = '0';
if (this.bar_.firstChild)
this.bar_.insertBefore(startBox, this.bar_.firstChild);
else
this.bar_.appendChild(startBox);
setTimeout(function() {
startBox.style.marginLeft = -margin + 'px';
}, 0);
}
if (firstIndex > 0 && this.selectedIndex_ != firstIndex) {
this.bar_.classList.add('fade-left');
} else {
this.bar_.classList.remove('fade-left');
}
if (lastIndex < this.items_.length - 1 && this.selectedIndex_ != lastIndex) {
this.bar_.classList.add('fade-right');
} else {
this.bar_.classList.remove('fade-right');
}
this.firstVisibleIndex_ = firstIndex; this.firstVisibleIndex_ = firstIndex;
this.lastVisibleIndex_ = lastIndex; this.lastVisibleIndex_ = lastIndex;
this.activeBarIndex_ = 1 - this.activeBarIndex_; var self = this;
activeBar = this.bars_[this.activeBarIndex_]; setTimeout(function() {
activeBar.textContent = ''; for (var i = 0; i < toRemove.length; i++) {
for (var index = firstIndex; index <= lastIndex; ++index) { var index = toRemove[i];
var box = this.items_[index].getBox(this.activeBarIndex_); if (i < this.firstVisibleIndex_ || i > this.lastVisibleIndex_) {
ImageUtil.setAttribute(box, 'inactive', false); var box = this.items_[index].getBox(0);
activeBar.appendChild(box); if (box.parentNode == this.bar_)
this.bar_.removeChild(box);
} }
}
// Place active bar above inactive after animation is finished. }, 200);
setTimeout(
ImageUtil.setAttribute.bind(null, activeBar, 'inactive', false),
totalDuration);
}; };
Ribbon.prototype.getNextSelectedIndex_ = function(direction) { Ribbon.prototype.getNextSelectedIndex_ = function(direction) {
...@@ -765,26 +753,16 @@ Ribbon.Item = function(index, url, document, selectClosure) { ...@@ -765,26 +753,16 @@ Ribbon.Item = function(index, url, document, selectClosure) {
this.index_ = index; this.index_ = index;
this.url_ = url; this.url_ = url;
this.boxes_ = []; this.box_ = document.createElement('div');
this.wrappers_ = []; this.box_.className = 'ribbon-image';
this.imgs_ = []; this.box_.addEventListener('click', selectClosure);
for (var i = 0; i < 2; i++) {
var box = document.createElement('div');
box.className = 'ribbon-image';
box.addEventListener('click', selectClosure);
var wrapper = document.createElement('div');
wrapper.className = 'image-wrapper';
box.appendChild(wrapper);
var img = document.createElement('img'); this.wrapper_ = document.createElement('div');
wrapper.appendChild(img); this.wrapper_.className = 'image-wrapper';
this.box_.appendChild(this.wrapper_);
this.boxes_.push(box); this.img_ = document.createElement('img');
this.wrappers_.push(wrapper); this.wrapper_.appendChild(this.img_);
this.imgs_.push(img);
}
this.original_ = true; this.original_ = true;
this.copyName_ = null; this.copyName_ = null;
...@@ -792,7 +770,7 @@ Ribbon.Item = function(index, url, document, selectClosure) { ...@@ -792,7 +770,7 @@ Ribbon.Item = function(index, url, document, selectClosure) {
Ribbon.Item.prototype.getIndex = function () { return this.index_ }; Ribbon.Item.prototype.getIndex = function () { return this.index_ };
Ribbon.Item.prototype.getBox = function (index) { return this.boxes_[index] }; Ribbon.Item.prototype.getBox = function () { return this.box_ };
Ribbon.Item.prototype.isOriginal = function () { return this.original_ }; Ribbon.Item.prototype.isOriginal = function () { return this.original_ };
...@@ -802,13 +780,11 @@ Ribbon.Item.prototype.setUrl = function (url) { this.url_ = url }; ...@@ -802,13 +780,11 @@ Ribbon.Item.prototype.setUrl = function (url) { this.url_ = url };
Ribbon.Item.prototype.getCopyName = function () { return this.copyName_ }; Ribbon.Item.prototype.getCopyName = function () { return this.copyName_ };
Ribbon.Item.prototype.isSelected = function() { Ribbon.Item.prototype.isSelected = function() {
return this.boxes_[0].hasAttribute('selected'); return this.box_.hasAttribute('selected');
}; };
Ribbon.Item.prototype.select = function(on) { Ribbon.Item.prototype.select = function(on) {
for (var i = 0; i < 2; i++) { ImageUtil.setAttribute(this.box_, 'selected', on);
ImageUtil.setAttribute(this.boxes_[i], 'selected', on);
}
}; };
Ribbon.Item.prototype.updateThumbnail = function(canvas) { Ribbon.Item.prototype.updateThumbnail = function(canvas) {
...@@ -1019,11 +995,9 @@ Ribbon.Item.prototype.setMetadata = function(metadata) { ...@@ -1019,11 +995,9 @@ Ribbon.Item.prototype.setMetadata = function(metadata) {
'scaleY(' + transform.scaleY + ') ' + 'scaleY(' + transform.scaleY + ') ' +
'rotate(' + transform.rotate90 * 90 + 'deg)') : 'rotate(' + transform.rotate90 * 90 + 'deg)') :
''; '';
this.wrapper_.style.webkitTransform = webkitTransform;
for (var i = 0; i < 2; i++) { var img = this.img_;
this.wrappers_[i].style.webkitTransform = webkitTransform;
var img = this.imgs_[i];
if (metadata.width && metadata.height) { if (metadata.width && metadata.height) {
var aspect = metadata.width / metadata.height; var aspect = metadata.width / metadata.height;
...@@ -1046,7 +1020,6 @@ Ribbon.Item.prototype.setMetadata = function(metadata) { ...@@ -1046,7 +1020,6 @@ Ribbon.Item.prototype.setMetadata = function(metadata) {
} }
img.setAttribute('src', url); img.setAttribute('src', url);
}
}; };
function ShareMode(editor, container, toolbar, shareActions, function ShareMode(editor, container, toolbar, shareActions,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment