[gnome-shell] appDisplay: Move ensureIconVisible logic to util, make it more generic
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] appDisplay: Move ensureIconVisible logic to util, make it more generic
- Date: Tue, 12 Mar 2013 23:30:00 +0000 (UTC)
commit 5870709fbcc987c2606059c5eca31446eb4cb6d7
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Mon Mar 11 13:43:38 2013 -0400
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
js/misc/util.js | 39 +++++++++++++++++++++++++++++++++++++++
js/ui/appDisplay.js | 25 +------------------------
2 files changed, 40 insertions(+), 24 deletions(-)
---
diff --git a/js/misc/util.js b/js/misc/util.js
index d0ea7ca..15edc37 100644
--- a/js/misc/util.js
+++ b/js/misc/util.js
@@ -5,6 +5,9 @@ const GLib = imports.gi.GLib;
const St = imports.gi.St;
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
const _balancedParens = '\\((?:[^\\s()<>]+|(?:\\(?:[^\\s()<>]+\\)))*\\)';
@@ -234,3 +237,39 @@ function makeCloseButton() {
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' });
+}
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index 1120071..79463b2 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -29,7 +29,6 @@ const Util = imports.misc.util;
const MAX_APPLICATION_WORK_MILLIS = 75;
const MENU_POPUP_TIMEOUT = 600;
-const SCROLL_TIME = 0.1;
const MAX_COLUMNS = 6;
const INACTIVE_GRID_OPACITY = 77;
@@ -259,29 +258,7 @@ const AllView = new Lang.Class({
},
_ensureIconVisible: function(icon) {
- let adjustment = this.actor.vscroll.adjustment;
- 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' });
+ Util.ensureActorVisibleInScrollView(this.actor, icon);
},
_updateIconOpacities: function(folderOpen) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]