boxPointer: Stop using Shell.GenericContainer

An easy removal too.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/153
This commit is contained in:
Georges Basile Stavracas Neto 2018-08-21 07:38:23 -03:00
parent f460f2748d
commit 3fa19e58ac
No known key found for this signature in database
GPG Key ID: 886C17EE170D1385
4 changed files with 66 additions and 64 deletions

View File

@ -34,25 +34,25 @@ var POPUP_ANIMATION_TIME = 0.15;
*/ */
var BoxPointer = new Lang.Class({ var BoxPointer = new Lang.Class({
Name: 'BoxPointer', Name: 'BoxPointer',
Extends: St.Widget,
Signals: { 'arrow-side-changed': {} },
_init(arrowSide, binProperties) { _init(arrowSide, binProperties) {
this.parent();
this.actor = this;
this.set_offscreen_redirect(Clutter.OffscreenRedirect.ALWAYS);
this._arrowSide = arrowSide; this._arrowSide = arrowSide;
this._userArrowSide = arrowSide; this._userArrowSide = arrowSide;
this._arrowOrigin = 0; this._arrowOrigin = 0;
this._arrowActor = null; 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.bin = new St.Bin(binProperties);
this._container.add_actor(this.bin); this.add_actor(this.bin);
this._border = new St.DrawingArea(); this._border = new St.DrawingArea();
this._border.connect('repaint', this._drawBorder.bind(this)); 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.bin.raise(this._border);
this._xOffset = 0; this._xOffset = 0;
this._yOffset = 0; this._yOffset = 0;
@ -69,13 +69,13 @@ var BoxPointer = new Lang.Class({
_muteInput() { _muteInput() {
if (this._capturedEventId == 0) if (this._capturedEventId == 0)
this._capturedEventId = this.actor.connect('captured-event', this._capturedEventId = this.connect('captured-event',
() => Clutter.EVENT_STOP); () => Clutter.EVENT_STOP);
}, },
_unmuteInput() { _unmuteInput() {
if (this._capturedEventId != 0) { if (this._capturedEventId != 0) {
this.actor.disconnect(this._capturedEventId); this.disconnect(this._capturedEventId);
this._capturedEventId = 0; this._capturedEventId = 0;
} }
}, },
@ -111,7 +111,7 @@ var BoxPointer = new Lang.Class({
}, },
open(animate, onComplete) { open(animate, onComplete) {
let themeNode = this.actor.get_theme_node(); let themeNode = this.get_theme_node();
let rise = themeNode.get_length('-arrow-rise'); let rise = themeNode.get_length('-arrow-rise');
let animationTime = (animate & PopupAnimation.FULL) ? POPUP_ANIMATION_TIME : 0; let animationTime = (animate & PopupAnimation.FULL) ? POPUP_ANIMATION_TIME : 0;
@ -120,7 +120,7 @@ var BoxPointer = new Lang.Class({
else else
this.opacity = 255; this.opacity = 255;
this.actor.show(); this.show();
if (animate & PopupAnimation.SLIDE) { if (animate & PopupAnimation.SLIDE) {
switch (this._arrowSide) { switch (this._arrowSide) {
@ -152,12 +152,12 @@ var BoxPointer = new Lang.Class({
}, },
close(animate, onComplete) { close(animate, onComplete) {
if (!this.actor.visible) if (!this.visible)
return; return;
let xOffset = 0; let xOffset = 0;
let yOffset = 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 rise = themeNode.get_length('-arrow-rise');
let fade = (animate & PopupAnimation.FADE); let fade = (animate & PopupAnimation.FADE);
let animationTime = (animate & PopupAnimation.FULL) ? POPUP_ANIMATION_TIME : 0; let animationTime = (animate & PopupAnimation.FULL) ? POPUP_ANIMATION_TIME : 0;
@ -188,7 +188,7 @@ var BoxPointer = new Lang.Class({
transition: 'linear', transition: 'linear',
time: animationTime, time: animationTime,
onComplete: () => { onComplete: () => {
this.actor.hide(); this.hide();
this.opacity = 0; this.opacity = 0;
this.xOffset = 0; this.xOffset = 0;
this.yOffset = 0; this.yOffset = 0;
@ -198,37 +198,48 @@ var BoxPointer = new Lang.Class({
}); });
}, },
_adjustAllocationForArrow(isWidth, alloc) { _adjustAllocationForArrow(isWidth, minSize, natSize) {
let themeNode = this.actor.get_theme_node(); let themeNode = this.get_theme_node();
let borderWidth = themeNode.get_length('-arrow-border-width'); let borderWidth = themeNode.get_length('-arrow-border-width');
alloc.min_size += borderWidth * 2; minSize += borderWidth * 2;
alloc.natural_size += borderWidth * 2; natSize += borderWidth * 2;
if ((!isWidth && (this._arrowSide == St.Side.TOP || this._arrowSide == St.Side.BOTTOM)) if ((!isWidth && (this._arrowSide == St.Side.TOP || this._arrowSide == St.Side.BOTTOM))
|| (isWidth && (this._arrowSide == St.Side.LEFT || this._arrowSide == St.Side.RIGHT))) { || (isWidth && (this._arrowSide == St.Side.LEFT || this._arrowSide == St.Side.RIGHT))) {
let rise = themeNode.get_length('-arrow-rise'); let rise = themeNode.get_length('-arrow-rise');
alloc.min_size += rise; minSize += rise;
alloc.natural_size += rise; natSize += rise;
} }
return [minSize, natSize];
}, },
_getPreferredWidth(actor, forHeight, alloc) { vfunc_get_preferred_width(forHeight) {
let [minInternalSize, natInternalSize] = this.bin.get_preferred_width(forHeight); let themeNode = this.get_theme_node();
alloc.min_size = minInternalSize; forHeight = themeNode.adjust_for_height(forHeight);
alloc.natural_size = natInternalSize;
this._adjustAllocationForArrow(true, alloc); let width = this.bin.get_preferred_width(forHeight);
width = this._adjustAllocationForArrow(true, ...width);
return themeNode.adjust_preferred_width(...width);
}, },
_getPreferredHeight(actor, forWidth, alloc) { vfunc_get_preferred_height(forWidth) {
let themeNode = this.actor.get_theme_node(); let themeNode = this.get_theme_node();
let borderWidth = themeNode.get_length('-arrow-border-width'); let borderWidth = themeNode.get_length('-arrow-border-width');
let [minSize, naturalSize] = this.bin.get_preferred_height(forWidth - 2 * borderWidth); forWidth = themeNode.adjust_for_width(forWidth);
alloc.min_size = minSize;
alloc.natural_size = naturalSize; let height = this.bin.get_preferred_height(forWidth - 2 * borderWidth);
this._adjustAllocationForArrow(false, alloc); height = this._adjustAllocationForArrow(false, ...height);
return themeNode.adjust_preferred_height(...height);
}, },
_allocate(actor, box, flags) { vfunc_allocate(box, flags) {
let themeNode = this.actor.get_theme_node(); 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 borderWidth = themeNode.get_length('-arrow-border-width');
let rise = themeNode.get_length('-arrow-rise'); let rise = themeNode.get_length('-arrow-rise');
let childBox = new Clutter.ActorBox(); let childBox = new Clutter.ActorBox();
@ -268,12 +279,12 @@ var BoxPointer = new Lang.Class({
}, },
_drawBorder(area) { _drawBorder(area) {
let themeNode = this.actor.get_theme_node(); let themeNode = this.get_theme_node();
if (this._arrowActor) { if (this._arrowActor) {
let [sourceX, sourceY] = this._arrowActor.get_transformed_position(); let [sourceX, sourceY] = this._arrowActor.get_transformed_position();
let [sourceWidth, sourceHeight] = this._arrowActor.get_transformed_size(); 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 || if (this._arrowSide == St.Side.TOP ||
this._arrowSide == St.Side.BOTTOM) { this._arrowSide == St.Side.BOTTOM) {
@ -452,7 +463,7 @@ var BoxPointer = new Lang.Class({
setPosition(sourceActor, alignment) { setPosition(sourceActor, alignment) {
// We need to show it now to force an allocation, // We need to show it now to force an allocation,
// so that we can query the correct size. // so that we can query the correct size.
this.actor.show(); this.show();
this._sourceActor = sourceActor; this._sourceActor = sourceActor;
this._arrowAlignment = alignment; this._arrowAlignment = alignment;
@ -480,13 +491,13 @@ var BoxPointer = new Lang.Class({
let sourceAllocation = Shell.util_get_transformed_allocation(sourceActor); let sourceAllocation = Shell.util_get_transformed_allocation(sourceActor);
let sourceCenterX = sourceAllocation.x1 + sourceContentBox.x1 + (sourceContentBox.x2 - sourceContentBox.x1) * this._sourceAlignment; 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 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 // We also want to keep it onscreen, and separated from the
// edge by the same distance as the main part of the box is // edge by the same distance as the main part of the box is
// separated from its sourceActor // separated from its sourceActor
let monitor = Main.layoutManager.findMonitorForActor(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 borderWidth = themeNode.get_length('-arrow-border-width');
let arrowBase = themeNode.get_length('-arrow-base'); let arrowBase = themeNode.get_length('-arrow-base');
let borderRadius = themeNode.get_length('-arrow-border-radius'); let borderRadius = themeNode.get_length('-arrow-border-radius');
@ -572,7 +583,7 @@ var BoxPointer = new Lang.Class({
this.setArrowOrigin(arrowOrigin); this.setArrowOrigin(arrowOrigin);
let parent = this.actor.get_parent(); let parent = this.get_parent();
let success, x, y; let success, x, y;
while (!success) { while (!success) {
[success, x, y] = parent.transform_stage_point(resX, resY); [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 // allocation loops and warnings. Instead we do the positioning via
// the anchor point, which is independent of allocation, and leave // the anchor point, which is independent of allocation, and leave
// x == y == 0. // x == y == 0.
this.actor.set_anchor_point(-(this._xPosition + this._xOffset), this.set_anchor_point(-(this._xPosition + this._xOffset),
-(this._yPosition + this._yOffset)); -(this._yPosition + this._yOffset));
}, },
_calculateArrowSide(arrowSide) { _calculateArrowSide(arrowSide) {
let sourceAllocation = Shell.util_get_transformed_allocation(this._sourceActor); 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; let monitorActor = this.sourceActor;
if (!monitorActor) if (!monitorActor)
monitorActor = this.actor; monitorActor = this;
let monitor = Main.layoutManager.findMonitorForActor(monitorActor); let monitor = Main.layoutManager.findMonitorForActor(monitorActor);
switch (arrowSide) { switch (arrowSide) {
@ -655,7 +666,7 @@ var BoxPointer = new Lang.Class({
this._arrowSide = arrowSide; this._arrowSide = arrowSide;
this._reposition(); this._reposition();
Meta.later_add(Meta.LaterType.BEFORE_REDRAW, () => { Meta.later_add(Meta.LaterType.BEFORE_REDRAW, () => {
this._container.queue_relayout(); this.queue_relayout();
return false; return false;
}); });
@ -681,14 +692,6 @@ var BoxPointer = new Lang.Class({
return this._yOffset; return this._yOffset;
}, },
set opacity(opacity) {
this.actor.opacity = opacity;
},
get opacity() {
return this.actor.opacity;
},
updateArrowSide(side) { updateArrowSide(side) {
this._arrowSide = side; this._arrowSide = side;
this._border.queue_repaint(); this._border.queue_repaint();
@ -701,7 +704,6 @@ var BoxPointer = new Lang.Class({
}, },
getArrowHeight() { getArrowHeight() {
return this.actor.get_theme_node().get_length('-arrow-rise'); return this.get_theme_node().get_length('-arrow-rise');
} }
}); });
Signals.addSignalMethods(BoxPointer.prototype);

View File

@ -133,9 +133,9 @@ var CandidatePopup = new Lang.Class({
_init() { _init() {
this._boxPointer = new BoxPointer.BoxPointer(St.Side.TOP); this._boxPointer = new BoxPointer.BoxPointer(St.Side.TOP);
this._boxPointer.actor.visible = false; this._boxPointer.visible = false;
this._boxPointer.actor.style_class = 'candidate-popup-boxpointer'; this._boxPointer.style_class = 'candidate-popup-boxpointer';
Main.layoutManager.addChrome(this._boxPointer.actor); Main.layoutManager.addChrome(this._boxPointer);
let box = new St.BoxLayout({ style_class: 'candidate-popup-content', let box = new St.BoxLayout({ style_class: 'candidate-popup-content',
vertical: true }); vertical: true });

View File

@ -269,7 +269,7 @@ var Key = new Lang.Class({
_onDestroy() { _onDestroy() {
if (this._boxPointer) { if (this._boxPointer) {
this._boxPointer.actor.destroy(); this._boxPointer.destroy();
this._boxPointer = null; this._boxPointer = null;
} }
}, },
@ -282,7 +282,7 @@ var Key = new Lang.Class({
{ x_fill: true, { x_fill: true,
y_fill: true, y_fill: true,
x_align: St.Align.START }); x_align: St.Align.START });
this._boxPointer.actor.hide(); this._boxPointer.hide();
Main.layoutManager.addChrome(this._boxPointer.actor); Main.layoutManager.addChrome(this._boxPointer.actor);
this._boxPointer.setPosition(this.keyButton, 0.5); this._boxPointer.setPosition(this.keyButton, 0.5);

View File

@ -782,7 +782,7 @@ var PopupMenu = new Lang.Class({
{ x_fill: true, { x_fill: true,
y_fill: true, y_fill: true,
x_align: St.Align.START }); x_align: St.Align.START });
this.actor = this._boxPointer.actor; this.actor = this._boxPointer;
this.actor._delegate = this; this.actor._delegate = this;
this.actor.style_class = 'popup-menu-boxpointer'; this.actor.style_class = 'popup-menu-boxpointer';