appDisplay: Move ensureIconVisible logic to util, make it more generic

In particular, make it work if we have multiple parents, like in the
search case.

https://bugzilla.gnome.org/show_bug.cgi?id=689681
This commit is contained in:
Jasper St. Pierre 2013-03-11 13:43:38 -04:00
parent 0fdb7430ff
commit 5870709fbc
2 changed files with 40 additions and 24 deletions

View File

@ -5,6 +5,9 @@ const GLib = imports.gi.GLib;
const St = imports.gi.St; const St = imports.gi.St;
const Main = imports.ui.main; const Main = imports.ui.main;
const Tweener = imports.ui.tweener;
const SCROLL_TIME = 0.1;
// http://daringfireball.net/2010/07/improved_regex_for_matching_urls // http://daringfireball.net/2010/07/improved_regex_for_matching_urls
const _balancedParens = '\\((?:[^\\s()<>]+|(?:\\(?:[^\\s()<>]+\\)))*\\)'; const _balancedParens = '\\((?:[^\\s()<>]+|(?:\\(?:[^\\s()<>]+\\)))*\\)';
@ -234,3 +237,39 @@ function makeCloseButton() {
return closeButton; return closeButton;
} }
function ensureActorVisibleInScrollView(scrollView, actor) {
let adjustment = scrollView.vscroll.adjustment;
let [value, lower, upper, stepIncrement, pageIncrement, pageSize] = adjustment.get_values();
let offset = 0;
let vfade = scrollView.get_effect("fade");
if (vfade)
offset = vfade.vfade_offset;
let box = actor.get_allocation_box();
let y1 = box.y1, y2 = box.y2;
let parent = actor.get_parent();
while (parent != scrollView) {
if (!parent)
throw new Error("actor not in scroll view");
let box = parent.get_allocation_box();
y1 += box.y1;
y2 += box.y1;
parent = parent.get_parent();
}
if (y1 < value + offset)
value = Math.max(0, y1 - offset);
else if (y2 > value + pageSize - offset)
value = Math.min(upper, y2 + offset - pageSize);
else
return;
Tweener.addTween(adjustment,
{ value: value,
time: SCROLL_TIME,
transition: 'easeOutQuad' });
}

View File

@ -29,7 +29,6 @@ const Util = imports.misc.util;
const MAX_APPLICATION_WORK_MILLIS = 75; const MAX_APPLICATION_WORK_MILLIS = 75;
const MENU_POPUP_TIMEOUT = 600; const MENU_POPUP_TIMEOUT = 600;
const SCROLL_TIME = 0.1;
const MAX_COLUMNS = 6; const MAX_COLUMNS = 6;
const INACTIVE_GRID_OPACITY = 77; const INACTIVE_GRID_OPACITY = 77;
@ -259,29 +258,7 @@ const AllView = new Lang.Class({
}, },
_ensureIconVisible: function(icon) { _ensureIconVisible: function(icon) {
let adjustment = this.actor.vscroll.adjustment; Util.ensureActorVisibleInScrollView(this.actor, icon);
let [value, lower, upper, stepIncrement, pageIncrement, pageSize] = adjustment.get_values();
let offset = 0;
let vfade = this.actor.get_effect("fade");
if (vfade)
offset = vfade.vfade_offset;
// If this gets called as part of a right-click, the actor
// will be needs_allocation, and so "icon.y" would return 0
let box = icon.get_allocation_box();
if (box.y1 < value + offset)
value = Math.max(0, box.y1 - offset);
else if (box.y2 > value + pageSize - offset)
value = Math.min(upper, box.y2 + offset - pageSize);
else
return;
Tweener.addTween(adjustment,
{ value: value,
time: SCROLL_TIME,
transition: 'easeOutQuad' });
}, },
_updateIconOpacities: function(folderOpen) { _updateIconOpacities: function(folderOpen) {