De-duplicate "actor contains actor" code
Add _st_actor_contains() in st-private for use within St, and monkey-patch in a Clutter.Actor.contains() for use by javascript, and then replace all the duplicate implementations with one or the other of those. https://bugzilla.gnome.org/show_bug.cgi?id=621197
This commit is contained in:
@ -65,15 +65,6 @@ Chrome.prototype = {
|
||||
children[i].allocate_preferred_size(flags);
|
||||
},
|
||||
|
||||
_verifyAncestry: function(actor, ancestor) {
|
||||
while (actor) {
|
||||
if (actor == ancestor)
|
||||
return true;
|
||||
actor = actor.get_parent();
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
// addActor:
|
||||
// @actor: an actor to add to the chrome layer
|
||||
// @params: (optional) additional params
|
||||
@ -195,7 +186,7 @@ Chrome.prototype = {
|
||||
},
|
||||
|
||||
_actorReparented: function(actor, oldParent) {
|
||||
if (!this._verifyAncestry(actor, this.actor))
|
||||
if (!this.actor.contains(actor))
|
||||
this._untrackActor(actor);
|
||||
},
|
||||
|
||||
|
@ -275,16 +275,7 @@ SearchEntry.prototype = {
|
||||
|
||||
_onCapturedEvent: function(actor, event) {
|
||||
let source = event.get_source();
|
||||
let panelEvent = false;
|
||||
|
||||
if (source) {
|
||||
let parent = source;
|
||||
do {
|
||||
if (parent == Main.panel.actor)
|
||||
break;
|
||||
} while ((parent = parent.get_parent()) != null);
|
||||
panelEvent = (parent != null);
|
||||
}
|
||||
let panelEvent = source && Main.panel.actor.contains(source);
|
||||
|
||||
switch (event.type()) {
|
||||
case Clutter.EventType.BUTTON_PRESS:
|
||||
|
@ -1,5 +1,6 @@
|
||||
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
||||
|
||||
const Clutter = imports.gi.Clutter;;
|
||||
const Shell = imports.gi.Shell;
|
||||
const St = imports.gi.St;
|
||||
const Gettext_gtk20 = imports.gettext.domain('gtk20');
|
||||
@ -70,6 +71,12 @@ function init() {
|
||||
_patchContainerClass(St.BoxLayout);
|
||||
_patchContainerClass(St.Table);
|
||||
|
||||
Clutter.Actor.prototype.contains = function(child) {
|
||||
while (child != null && child != this)
|
||||
child = child.get_parent();
|
||||
return child != null;
|
||||
};
|
||||
|
||||
_blockMethod('Clutter.Event.get_state', 'Shell.get_event_state',
|
||||
'gjs\'s handling of Clutter.ModifierType is broken. See bug 597292.');
|
||||
_blockMethod('Gdk.Display.get_pointer', 'global.get_pointer',
|
||||
|
@ -494,28 +494,17 @@ PopupMenuManager.prototype = {
|
||||
this.ungrab();
|
||||
},
|
||||
|
||||
_containsActor: function(container, actor) {
|
||||
let parent = actor;
|
||||
while (parent != null) {
|
||||
if (parent == container)
|
||||
return true;
|
||||
parent = parent.get_parent();
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
_eventIsOnActiveMenu: function(event) {
|
||||
let src = event.get_source();
|
||||
return this._activeMenu != null
|
||||
&& (this._containsActor(this._activeMenu.actor, src) ||
|
||||
this._containsActor(this._activeMenu.sourceActor, src));
|
||||
&& (this._activeMenu.actor.contains(src) ||
|
||||
this._activeMenu.sourceActor.contains(src));
|
||||
},
|
||||
|
||||
_eventIsOnAnyMenuSource: function(event) {
|
||||
let src = event.get_source();
|
||||
for (let i = 0; i < this._menus.length; i++) {
|
||||
let actor = this._menus[i].sourceActor;
|
||||
if (this._containsActor(actor, src))
|
||||
if (this._menus[i].sourceActor.contains(src))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -629,11 +629,8 @@ Notification.prototype = {
|
||||
return false;
|
||||
|
||||
let source = event.get_source ();
|
||||
while (source) {
|
||||
if (source == notification)
|
||||
return false;
|
||||
source = source.get_parent();
|
||||
}
|
||||
if (source && notification.contains(source))
|
||||
return false;
|
||||
|
||||
// @source is outside @notification, which has to mean that
|
||||
// we have a pointer grab, and the user clicked outside the
|
||||
|
Reference in New Issue
Block a user