cleanup: Use inheritance for Actor classes instead of composition
Remove the `this.actor = ...` and `this.actor._delegate = this` patterns in most of classes, by inheriting all the actor container classes. Uses interfaces when needed for making sure that multiple classes will implement some required methods or to avoid redefining the same code multiple times. https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/559
This commit is contained in:

committed by
Florian Müllner

parent
f67b409fc1
commit
c4c5c4fd5c
@ -1290,7 +1290,7 @@ var ZoomRegion = class ZoomRegion {
|
||||
|
||||
// Add a background for when the magnified uiGroup is scrolled
|
||||
// out of view (don't want to see desktop showing through).
|
||||
this._background = (new Background.SystemBackground()).actor;
|
||||
this._background = new Background.SystemBackground();
|
||||
mainGroup.add_actor(this._background);
|
||||
|
||||
// Clone the group that contains all of UI on the screen. This is the
|
||||
@ -1587,8 +1587,9 @@ var ZoomRegion = class ZoomRegion {
|
||||
}
|
||||
};
|
||||
|
||||
var Crosshairs = class Crosshairs {
|
||||
constructor() {
|
||||
var Crosshairs = GObject.registerClass(
|
||||
class Crosshairs extends Clutter.Actor {
|
||||
_init() {
|
||||
|
||||
// Set the group containing the crosshairs to three times the desktop
|
||||
// size in case the crosshairs need to appear to be infinite in
|
||||
@ -1596,7 +1597,7 @@ var Crosshairs = class Crosshairs {
|
||||
let groupWidth = global.screen_width * 3;
|
||||
let groupHeight = global.screen_height * 3;
|
||||
|
||||
this._actor = new Clutter.Actor({
|
||||
super._init({
|
||||
clip_to_allocation: false,
|
||||
width: groupWidth,
|
||||
height: groupHeight
|
||||
@ -1605,10 +1606,10 @@ var Crosshairs = class Crosshairs {
|
||||
this._horizRightHair = new Clutter.Actor();
|
||||
this._vertTopHair = new Clutter.Actor();
|
||||
this._vertBottomHair = new Clutter.Actor();
|
||||
this._actor.add_actor(this._horizLeftHair);
|
||||
this._actor.add_actor(this._horizRightHair);
|
||||
this._actor.add_actor(this._vertTopHair);
|
||||
this._actor.add_actor(this._vertBottomHair);
|
||||
this.add_actor(this._horizLeftHair);
|
||||
this.add_actor(this._horizRightHair);
|
||||
this.add_actor(this._vertTopHair);
|
||||
this.add_actor(this._vertBottomHair);
|
||||
this._clipSize = [0, 0];
|
||||
this._clones = [];
|
||||
this.reCenter();
|
||||
@ -1618,7 +1619,7 @@ var Crosshairs = class Crosshairs {
|
||||
}
|
||||
|
||||
_monitorsChanged() {
|
||||
this._actor.set_size(global.screen_width * 3, global.screen_height * 3);
|
||||
this.set_size(global.screen_width * 3, global.screen_height * 3);
|
||||
this.reCenter();
|
||||
}
|
||||
|
||||
@ -1639,12 +1640,15 @@ var Crosshairs = class Crosshairs {
|
||||
if (zoomRegion && magnifiedMouse) {
|
||||
let container = magnifiedMouse.get_parent();
|
||||
if (container) {
|
||||
crosshairsActor = this._actor;
|
||||
if (this._actor.get_parent() != null) {
|
||||
crosshairsActor = new Clutter.Clone({ source: this._actor });
|
||||
crosshairsActor = this;
|
||||
if (this.get_parent() != null) {
|
||||
crosshairsActor = new Clutter.Clone({ source: this });
|
||||
this._clones.push(crosshairsActor);
|
||||
|
||||
// Clones don't share visibility.
|
||||
this.bind_property('visible', crosshairsActor, 'visible',
|
||||
GObject.BindingFlags.SYNC_CREATE);
|
||||
}
|
||||
crosshairsActor.visible = this._actor.visible;
|
||||
|
||||
container.add_actor(crosshairsActor);
|
||||
container.raise_child(magnifiedMouse, crosshairsActor);
|
||||
@ -1663,7 +1667,7 @@ var Crosshairs = class Crosshairs {
|
||||
* child actor if it was just a clone of the crosshairs actor.
|
||||
*/
|
||||
removeFromParent(childActor) {
|
||||
if (childActor == this._actor)
|
||||
if (childActor == this)
|
||||
childActor.get_parent().remove_actor(childActor);
|
||||
else
|
||||
childActor.destroy();
|
||||
@ -1773,28 +1777,6 @@ var Crosshairs = class Crosshairs {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* show:
|
||||
* Show the crosshairs.
|
||||
*/
|
||||
show() {
|
||||
this._actor.show();
|
||||
// Clones don't share visibility.
|
||||
for (let i = 0; i < this._clones.length; i++)
|
||||
this._clones[i].show();
|
||||
}
|
||||
|
||||
/**
|
||||
* hide:
|
||||
* Hide the crosshairs.
|
||||
*/
|
||||
hide() {
|
||||
this._actor.hide();
|
||||
// Clones don't share visibility.
|
||||
for (let i = 0; i < this._clones.length; i++)
|
||||
this._clones[i].hide();
|
||||
}
|
||||
|
||||
/**
|
||||
* reCenter:
|
||||
* Reposition the horizontal and vertical hairs such that they cross at
|
||||
@ -1803,7 +1785,7 @@ var Crosshairs = class Crosshairs {
|
||||
* @clipSize: Optional. If present, an array of the form [width, height].
|
||||
*/
|
||||
reCenter(clipSize) {
|
||||
let [groupWidth, groupHeight] = this._actor.get_size();
|
||||
let [groupWidth, groupHeight] = this.get_size();
|
||||
let leftLength = this._horizLeftHair.get_width();
|
||||
let topLength = this._vertTopHair.get_height();
|
||||
let thickness = this._horizLeftHair.get_height();
|
||||
@ -1825,7 +1807,7 @@ var Crosshairs = class Crosshairs {
|
||||
this._vertTopHair.set_position((groupWidth - thickness) / 2, top);
|
||||
this._vertBottomHair.set_position((groupWidth - thickness) / 2, bottom);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
var MagShaderEffects = class MagShaderEffects {
|
||||
constructor(uiGroupClone) {
|
||||
|
Reference in New Issue
Block a user