[gnome-shell/gbsneto/pagination: 15/22] appDisplay: Move child focus handling to IconGrid



commit 96bf33a7cab5163cc27acdcf388a9a710a57dccc
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Tue May 19 15:34:11 2020 -0300

    appDisplay: Move child focus handling to IconGrid
    
    The icon grid is always paginated, so the app grid code doesn't need
    to behave differently in the FolderView and AppDisplay.
    
    Move the keyboard handling to IconGrid itself, and remove the now dead
    code from AppDisplay.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1271

 js/ui/appDisplay.js | 16 ----------------
 js/ui/iconGrid.js   | 25 +++++++++++--------------
 2 files changed, 11 insertions(+), 30 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index 0097c3d9f5..3191bcbece 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -128,9 +128,6 @@ var BaseAppView = GObject.registerClass({
         super._init(params);
 
         this._grid = new IconGrid.IconGrid();
-        this._grid.connect('child-focused', (grid, actor) => {
-            this._childFocused(actor);
-        });
         // Standard hack for ClutterBinLayout
         this._grid.x_expand = true;
 
@@ -148,10 +145,6 @@ var BaseAppView = GObject.registerClass({
         });
     }
 
-    _childFocused(_actor) {
-        // Nothing by default
-    }
-
     _redisplay() {
         let oldApps = this._orderedItems.slice();
         let oldAppIds = oldApps.map(icon => icon.id);
@@ -736,11 +729,6 @@ class AppDisplay extends BaseAppView {
         });
     }
 
-    _childFocused(icon) {
-        let itemPage = this._grid.getItemPage(icon);
-        this.goToPage(itemPage);
-    }
-
     _updateIconOpacities(folderOpen) {
         for (let icon of this._items.values()) {
             let opacity;
@@ -1068,10 +1056,6 @@ class FolderView extends BaseAppView {
         this._redisplay();
     }
 
-    _childFocused(actor) {
-        Util.ensureActorVisibleInScrollView(this._scrollView, actor);
-    }
-
     // Overridden from BaseAppView
     animate(animationDirection) {
         this._grid.animatePulse(animationDirection);
diff --git a/js/ui/iconGrid.js b/js/ui/iconGrid.js
index dc10c03eb2..dad693a04c 100644
--- a/js/ui/iconGrid.js
+++ b/js/ui/iconGrid.js
@@ -1014,7 +1014,6 @@ var IconGrid = GObject.registerClass({
     Signals: {
         'pages-changed': {},
         'animation-done': {},
-        'child-focused': { param_types: [Clutter.Actor.$gtype] },
     },
 }, class IconGrid extends St.Viewport {
     _init(layoutParams = {}) {
@@ -1068,7 +1067,9 @@ var IconGrid = GObject.registerClass({
     }
 
     _childAdded(grid, child) {
-        child._iconGridKeyFocusInId = child.connect('key-focus-in', actor => this.emit('child-focused', 
actor));
+        child._iconGridKeyFocusInId = child.connect('key-focus-in', () => {
+            this._ensureItemIsVisible(child);
+        });
 
         child._paintVisible = child.opacity > 0;
         child._opacityChangedId = child.connect('notify::opacity', () => {
@@ -1079,6 +1080,14 @@ var IconGrid = GObject.registerClass({
         });
     }
 
+    _ensureItemIsVisible(item) {
+        if (!this.contains(item))
+            throw new Error(`${item} is not a child of IconGrid`);
+
+        const itemPage = this.layout_manager.getItemPage(item);
+        this.goToPage(itemPage);
+    }
+
     _setGridMode(modeIndex) {
         if (this._currentMode === modeIndex)
             return;
@@ -1223,18 +1232,6 @@ var IconGrid = GObject.registerClass({
         });
     }
 
-    /**
-     * getItemPage:
-     * @param {BaseIcon} item: the item
-     *
-     * Retrieves the page @item is in, or -1 if @item is not part of the grid.
-     *
-     * @returns {int} the page where @item is in
-     */
-    getItemPage(item) {
-        return this.layout_manager.getItemPage(item);
-    }
-
     get currentPage() {
         return this._currentPage;
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]