[gnome-shell/gbsneto/remove-generic-container: 14/21] boxPointer: Stop using Shell.GenericContainer



commit 6702a6343e979d40522a45117314683ad7a819f1
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Tue Aug 21 07:38:23 2018 -0300

    boxPointer: Stop using Shell.GenericContainer
    
    An easy removal too.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/153

 js/ui/boxpointer.js         | 118 ++++++++++++++++++++++----------------------
 js/ui/ibusCandidatePopup.js |   6 +--
 js/ui/keyboard.js           |   4 +-
 js/ui/popupMenu.js          |   2 +-
 4 files changed, 66 insertions(+), 64 deletions(-)
---
diff --git a/js/ui/boxpointer.js b/js/ui/boxpointer.js
index f9394e3a7..8d916887c 100644
--- a/js/ui/boxpointer.js
+++ b/js/ui/boxpointer.js
@@ -34,25 +34,25 @@ var POPUP_ANIMATION_TIME = 0.15;
  */
 var BoxPointer = new Lang.Class({
     Name: 'BoxPointer',
+    Extends: St.Widget,
+    Signals: { 'arrow-side-changed': {} },
 
     _init(arrowSide, binProperties) {
+        this.parent();
+
+        this.actor = this;
+
+        this.set_offscreen_redirect(Clutter.OffscreenRedirect.ALWAYS);
+
         this._arrowSide = arrowSide;
         this._userArrowSide = arrowSide;
         this._arrowOrigin = 0;
         this._arrowActor = null;
-        this.actor = new St.Bin({ x_fill: true,
-                                  y_fill: true });
-        this._container = new Shell.GenericContainer();
-        this.actor.set_child(this._container);
-        this.actor.set_offscreen_redirect(Clutter.OffscreenRedirect.ALWAYS);
-        this._container.connect('get-preferred-width', this._getPreferredWidth.bind(this));
-        this._container.connect('get-preferred-height', this._getPreferredHeight.bind(this));
-        this._container.connect('allocate', this._allocate.bind(this));
         this.bin = new St.Bin(binProperties);
-        this._container.add_actor(this.bin);
+        this.add_actor(this.bin);
         this._border = new St.DrawingArea();
         this._border.connect('repaint', this._drawBorder.bind(this));
-        this._container.add_actor(this._border);
+        this.add_actor(this._border);
         this.bin.raise(this._border);
         this._xOffset = 0;
         this._yOffset = 0;
@@ -69,13 +69,13 @@ var BoxPointer = new Lang.Class({
 
     _muteInput() {
         if (this._capturedEventId == 0)
-            this._capturedEventId = this.actor.connect('captured-event',
-                                                       () => Clutter.EVENT_STOP);
+            this._capturedEventId = this.connect('captured-event',
+                                                 () => Clutter.EVENT_STOP);
     },
 
     _unmuteInput() {
         if (this._capturedEventId != 0) {
-            this.actor.disconnect(this._capturedEventId);
+            this.disconnect(this._capturedEventId);
             this._capturedEventId = 0;
         }
     },
@@ -111,7 +111,7 @@ var BoxPointer = new Lang.Class({
     },
 
     open(animate, onComplete) {
-        let themeNode = this.actor.get_theme_node();
+        let themeNode = this.get_theme_node();
         let rise = themeNode.get_length('-arrow-rise');
         let animationTime = (animate & PopupAnimation.FULL) ? POPUP_ANIMATION_TIME : 0;
 
@@ -120,7 +120,7 @@ var BoxPointer = new Lang.Class({
         else
             this.opacity = 255;
 
-        this.actor.show();
+        this.show();
 
         if (animate & PopupAnimation.SLIDE) {
             switch (this._arrowSide) {
@@ -152,12 +152,12 @@ var BoxPointer = new Lang.Class({
     },
 
     close(animate, onComplete) {
-        if (!this.actor.visible)
+        if (!this.visible)
             return;
 
         let xOffset = 0;
         let yOffset = 0;
-        let themeNode = this.actor.get_theme_node();
+        let themeNode = this.get_theme_node();
         let rise = themeNode.get_length('-arrow-rise');
         let fade = (animate & PopupAnimation.FADE);
         let animationTime = (animate & PopupAnimation.FULL) ? POPUP_ANIMATION_TIME : 0;
@@ -188,7 +188,7 @@ var BoxPointer = new Lang.Class({
                                  transition: 'linear',
                                  time: animationTime,
                                  onComplete: () => {
-                                     this.actor.hide();
+                                     this.hide();
                                      this.opacity = 0;
                                      this.xOffset = 0;
                                      this.yOffset = 0;
@@ -198,37 +198,48 @@ var BoxPointer = new Lang.Class({
                                });
     },
 
-    _adjustAllocationForArrow(isWidth, alloc) {
-        let themeNode = this.actor.get_theme_node();
+    _adjustAllocationForArrow(isWidth, minSize, natSize) {
+        let themeNode = this.get_theme_node();
         let borderWidth = themeNode.get_length('-arrow-border-width');
-        alloc.min_size += borderWidth * 2;
-        alloc.natural_size += borderWidth * 2;
+        minSize += borderWidth * 2;
+        natSize += borderWidth * 2;
         if ((!isWidth && (this._arrowSide == St.Side.TOP || this._arrowSide == St.Side.BOTTOM))
             || (isWidth && (this._arrowSide == St.Side.LEFT || this._arrowSide == St.Side.RIGHT))) {
             let rise = themeNode.get_length('-arrow-rise');
-            alloc.min_size += rise;
-            alloc.natural_size += rise;
+            minSize += rise;
+            natSize += rise;
         }
+
+        return [minSize, natSize];
     },
 
-    _getPreferredWidth(actor, forHeight, alloc) {
-        let [minInternalSize, natInternalSize] = this.bin.get_preferred_width(forHeight);
-        alloc.min_size = minInternalSize;
-        alloc.natural_size = natInternalSize;
-        this._adjustAllocationForArrow(true, alloc);
+    vfunc_get_preferred_width(forHeight) {
+        let themeNode = this.get_theme_node();
+        forHeight = themeNode.adjust_for_height(forHeight);
+
+        let width = this.bin.get_preferred_width(forHeight);
+        width = this._adjustAllocationForArrow(true, ...width);
+
+        return themeNode.adjust_preferred_width(...width);
     },
 
-    _getPreferredHeight(actor, forWidth, alloc) {
-        let themeNode = this.actor.get_theme_node();
+    vfunc_get_preferred_height(forWidth) {
+        let themeNode = this.get_theme_node();
         let borderWidth = themeNode.get_length('-arrow-border-width');
-        let [minSize, naturalSize] = this.bin.get_preferred_height(forWidth - 2 * borderWidth);
-        alloc.min_size = minSize;
-        alloc.natural_size = naturalSize;
-        this._adjustAllocationForArrow(false, alloc);
+        forWidth = themeNode.adjust_for_width(forWidth);
+
+        let height = this.bin.get_preferred_height(forWidth - 2 * borderWidth);
+        height = this._adjustAllocationForArrow(false, ...height);
+
+        return themeNode.adjust_preferred_height(...height);
     },
 
-    _allocate(actor, box, flags) {
-        let themeNode = this.actor.get_theme_node();
+    vfunc_allocate(box, flags) {
+        this.set_allocation(box, flags);
+
+        let themeNode = this.get_theme_node();
+        box = themeNode.get_content_box(box);
+
         let borderWidth = themeNode.get_length('-arrow-border-width');
         let rise = themeNode.get_length('-arrow-rise');
         let childBox = new Clutter.ActorBox();
@@ -268,12 +279,12 @@ var BoxPointer = new Lang.Class({
     },
 
     _drawBorder(area) {
-        let themeNode = this.actor.get_theme_node();
+        let themeNode = this.get_theme_node();
 
         if (this._arrowActor) {
             let [sourceX, sourceY] = this._arrowActor.get_transformed_position();
             let [sourceWidth, sourceHeight] = this._arrowActor.get_transformed_size();
-            let [absX, absY] = this.actor.get_transformed_position();
+            let [absX, absY] = this.get_transformed_position();
 
             if (this._arrowSide == St.Side.TOP ||
                 this._arrowSide == St.Side.BOTTOM) {
@@ -452,7 +463,7 @@ var BoxPointer = new Lang.Class({
     setPosition(sourceActor, alignment) {
         // We need to show it now to force an allocation,
         // so that we can query the correct size.
-        this.actor.show();
+        this.show();
 
         this._sourceActor = sourceActor;
         this._arrowAlignment = alignment;
@@ -480,13 +491,13 @@ var BoxPointer = new Lang.Class({
         let sourceAllocation = Shell.util_get_transformed_allocation(sourceActor);
         let sourceCenterX = sourceAllocation.x1 + sourceContentBox.x1 + (sourceContentBox.x2 - 
sourceContentBox.x1) * this._sourceAlignment;
         let sourceCenterY = sourceAllocation.y1 + sourceContentBox.y1 + (sourceContentBox.y2 - 
sourceContentBox.y1) * this._sourceAlignment;
-        let [minWidth, minHeight, natWidth, natHeight] = this.actor.get_preferred_size();
+        let [minWidth, minHeight, natWidth, natHeight] = this.get_preferred_size();
 
         // We also want to keep it onscreen, and separated from the
         // edge by the same distance as the main part of the box is
         // separated from its sourceActor
         let monitor = Main.layoutManager.findMonitorForActor(sourceActor);
-        let themeNode = this.actor.get_theme_node();
+        let themeNode = this.get_theme_node();
         let borderWidth = themeNode.get_length('-arrow-border-width');
         let arrowBase = themeNode.get_length('-arrow-base');
         let borderRadius = themeNode.get_length('-arrow-border-radius');
@@ -572,7 +583,7 @@ var BoxPointer = new Lang.Class({
 
         this.setArrowOrigin(arrowOrigin);
 
-        let parent = this.actor.get_parent();
+        let parent = this.get_parent();
         let success, x, y;
         while (!success) {
             [success, x, y] = parent.transform_stage_point(resX, resY);
@@ -611,16 +622,16 @@ var BoxPointer = new Lang.Class({
         // allocation loops and warnings. Instead we do the positioning via
         // the anchor point, which is independent of allocation, and leave
         // x == y == 0.
-        this.actor.set_anchor_point(-(this._xPosition + this._xOffset),
-                                    -(this._yPosition + this._yOffset));
+        this.set_anchor_point(-(this._xPosition + this._xOffset),
+                              -(this._yPosition + this._yOffset));
     },
 
     _calculateArrowSide(arrowSide) {
         let sourceAllocation = Shell.util_get_transformed_allocation(this._sourceActor);
-        let [minWidth, minHeight, boxWidth, boxHeight] = this._container.get_preferred_size();
+        let [minWidth, minHeight, boxWidth, boxHeight] = this.get_preferred_size();
         let monitorActor = this.sourceActor;
         if (!monitorActor)
-            monitorActor = this.actor;
+            monitorActor = this;
         let monitor = Main.layoutManager.findMonitorForActor(monitorActor);
 
         switch (arrowSide) {
@@ -655,7 +666,7 @@ var BoxPointer = new Lang.Class({
             this._arrowSide = arrowSide;
             this._reposition();
             Meta.later_add(Meta.LaterType.BEFORE_REDRAW, () => {
-                this._container.queue_relayout();
+                this.queue_relayout();
                 return false;
             });
 
@@ -681,14 +692,6 @@ var BoxPointer = new Lang.Class({
         return this._yOffset;
     },
 
-    set opacity(opacity) {
-        this.actor.opacity = opacity;
-    },
-
-    get opacity() {
-        return this.actor.opacity;
-    },
-
     updateArrowSide(side) {
         this._arrowSide = side;
         this._border.queue_repaint();
@@ -701,7 +704,6 @@ var BoxPointer = new Lang.Class({
     },
 
     getArrowHeight() {
-        return this.actor.get_theme_node().get_length('-arrow-rise');
+        return this.get_theme_node().get_length('-arrow-rise');
     }
 });
-Signals.addSignalMethods(BoxPointer.prototype);
diff --git a/js/ui/ibusCandidatePopup.js b/js/ui/ibusCandidatePopup.js
index af2c777d3..085aaaa25 100644
--- a/js/ui/ibusCandidatePopup.js
+++ b/js/ui/ibusCandidatePopup.js
@@ -133,9 +133,9 @@ var CandidatePopup = new Lang.Class({
 
     _init() {
         this._boxPointer = new BoxPointer.BoxPointer(St.Side.TOP);
-        this._boxPointer.actor.visible = false;
-        this._boxPointer.actor.style_class = 'candidate-popup-boxpointer';
-        Main.layoutManager.addChrome(this._boxPointer.actor);
+        this._boxPointer.visible = false;
+        this._boxPointer.style_class = 'candidate-popup-boxpointer';
+        Main.layoutManager.addChrome(this._boxPointer);
 
         let box = new St.BoxLayout({ style_class: 'candidate-popup-content',
                                      vertical: true });
diff --git a/js/ui/keyboard.js b/js/ui/keyboard.js
index 6104ab779..106c30210 100644
--- a/js/ui/keyboard.js
+++ b/js/ui/keyboard.js
@@ -269,7 +269,7 @@ var Key = new Lang.Class({
 
     _onDestroy() {
         if (this._boxPointer) {
-            this._boxPointer.actor.destroy();
+            this._boxPointer.destroy();
             this._boxPointer = null;
         }
     },
@@ -282,7 +282,7 @@ var Key = new Lang.Class({
                                                      { x_fill: true,
                                                        y_fill: true,
                                                        x_align: St.Align.START });
-        this._boxPointer.actor.hide();
+        this._boxPointer.hide();
         Main.layoutManager.addChrome(this._boxPointer.actor);
         this._boxPointer.setPosition(this.keyButton, 0.5);
 
diff --git a/js/ui/popupMenu.js b/js/ui/popupMenu.js
index 41455a202..0895321cb 100644
--- a/js/ui/popupMenu.js
+++ b/js/ui/popupMenu.js
@@ -782,7 +782,7 @@ var PopupMenu = new Lang.Class({
                                                      { x_fill: true,
                                                        y_fill: true,
                                                        x_align: St.Align.START });
-        this.actor = this._boxPointer.actor;
+        this.actor = this._boxPointer;
         this.actor._delegate = this;
         this.actor.style_class = 'popup-menu-boxpointer';
 


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