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
@ -1,18 +1,18 @@
|
||||
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
||||
/* exported Animation, AnimatedIcon, Spinner */
|
||||
|
||||
const { Clutter, GLib, Gio, St } = imports.gi;
|
||||
const { Clutter, GLib, GObject, Gio, St } = imports.gi;
|
||||
|
||||
var ANIMATED_ICON_UPDATE_TIMEOUT = 16;
|
||||
var SPINNER_ANIMATION_TIME = 300;
|
||||
var SPINNER_ANIMATION_DELAY = 1000;
|
||||
|
||||
var Animation = class {
|
||||
constructor(file, width, height, speed) {
|
||||
this.actor = new St.Bin();
|
||||
this.actor.set_size(width, height);
|
||||
this.actor.connect('destroy', this._onDestroy.bind(this));
|
||||
this.actor.connect('resource-scale-changed',
|
||||
var Animation = GObject.registerClass(
|
||||
class Animation extends St.Bin {
|
||||
_init(file, width, height, speed) {
|
||||
super._init({ width: width, height: height });
|
||||
this.connect('destroy', this._onDestroy.bind(this));
|
||||
this.connect('resource-scale-changed',
|
||||
this._loadFile.bind(this, file, width, height));
|
||||
|
||||
let themeContext = St.ThemeContext.get_for_stage(global.stage);
|
||||
@ -51,14 +51,14 @@ var Animation = class {
|
||||
}
|
||||
|
||||
_loadFile(file, width, height) {
|
||||
let [validResourceScale, resourceScale] = this.actor.get_resource_scale();
|
||||
let [validResourceScale, resourceScale] = this.get_resource_scale();
|
||||
let wasPlaying = this._isPlaying;
|
||||
|
||||
if (this._isPlaying)
|
||||
this.stop();
|
||||
|
||||
this._isLoaded = false;
|
||||
this.actor.destroy_all_children();
|
||||
this.destroy_all_children();
|
||||
|
||||
if (!validResourceScale) {
|
||||
if (wasPlaying)
|
||||
@ -71,7 +71,7 @@ var Animation = class {
|
||||
this._animations = textureCache.load_sliced_image(file, width, height,
|
||||
scaleFactor, resourceScale,
|
||||
this._animationsLoaded.bind(this));
|
||||
this.actor.set_child(this._animations);
|
||||
this.set_child(this._animations);
|
||||
|
||||
if (wasPlaying)
|
||||
this.play();
|
||||
@ -98,7 +98,7 @@ var Animation = class {
|
||||
if (!this._isLoaded)
|
||||
return;
|
||||
|
||||
let [width, height] = this.actor.get_size();
|
||||
let [width, height] = this.get_size();
|
||||
|
||||
for (let i = 0; i < this._animations.get_n_children(); ++i)
|
||||
this._animations.get_child_at_index(i).set_size(width, height);
|
||||
@ -121,20 +121,22 @@ var Animation = class {
|
||||
themeContext.disconnect(this._scaleChangedId);
|
||||
this._scaleChangedId = 0;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
var AnimatedIcon = class extends Animation {
|
||||
constructor(file, size) {
|
||||
super(file, size, size, ANIMATED_ICON_UPDATE_TIMEOUT);
|
||||
var AnimatedIcon = GObject.registerClass(
|
||||
class AnimatedIcon extends Animation {
|
||||
_init(file, size) {
|
||||
super._init(file, size, size, ANIMATED_ICON_UPDATE_TIMEOUT);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
var Spinner = class extends AnimatedIcon {
|
||||
constructor(size, animate = false) {
|
||||
var Spinner = GObject.registerClass(
|
||||
class Spinner extends AnimatedIcon {
|
||||
_init(size, animate = false) {
|
||||
let file = Gio.File.new_for_uri('resource:///org/gnome/shell/theme/process-working.svg');
|
||||
super(file, size);
|
||||
super._init(file, size);
|
||||
|
||||
this.actor.opacity = 0;
|
||||
this.opacity = 0;
|
||||
this._animate = animate;
|
||||
}
|
||||
|
||||
@ -144,35 +146,35 @@ var Spinner = class extends AnimatedIcon {
|
||||
}
|
||||
|
||||
play() {
|
||||
this.actor.remove_all_transitions();
|
||||
this.remove_all_transitions();
|
||||
|
||||
if (this._animate) {
|
||||
super.play();
|
||||
this.actor.ease({
|
||||
this.ease({
|
||||
opacity: 255,
|
||||
delay: SPINNER_ANIMATION_DELAY,
|
||||
duration: SPINNER_ANIMATION_TIME,
|
||||
mode: Clutter.AnimationMode.LINEAR
|
||||
});
|
||||
} else {
|
||||
this.actor.opacity = 255;
|
||||
this.opacity = 255;
|
||||
super.play();
|
||||
}
|
||||
}
|
||||
|
||||
stop() {
|
||||
this.actor.remove_all_transitions();
|
||||
this.remove_all_transitions();
|
||||
|
||||
if (this._animate) {
|
||||
this.actor.ease({
|
||||
this.ease({
|
||||
opacity: 0,
|
||||
duration: SPINNER_ANIMATION_TIME,
|
||||
mode: Clutter.AnimationMode.LINEAR,
|
||||
onComplete: () => super.stop()
|
||||
});
|
||||
} else {
|
||||
this.actor.opacity = 0;
|
||||
this.opacity = 0;
|
||||
super.stop();
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
Reference in New Issue
Block a user