~ubuntu-branches/ubuntu/trusty/gnome-shell/trusty-proposed

« back to all changes in this revision

Viewing changes to js/ui/dash.js

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2012-03-14 13:47:20 UTC
  • mfrom: (1.1.36) (18.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20120314134720-202sbjbu4a3z1fru
Tags: 3.3.90-0ubuntu1
* Sync with Debian experimental svn packaging (LP: #941755, #937709).
  Remaining changes:
  - debian/gnome-shell.gsettings-override: Update for Ubuntu defaults
  - debian/control.in: Recommend cups-pk-helper
  - debian/patches/10-make-NetworkManager-optional.patch: Disabled
  - Don't run dh-autoreconf

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
const Meta = imports.gi.Meta;
7
7
const Shell = imports.gi.Shell;
8
8
const St = imports.gi.St;
 
9
const Mainloop = imports.mainloop;
9
10
 
10
11
const AppDisplay = imports.ui.appDisplay;
11
12
const AppFavorites = imports.ui.appFavorites;
16
17
const Workspace = imports.ui.workspace;
17
18
 
18
19
const DASH_ANIMATION_TIME = 0.2;
 
20
const DASH_ITEM_LABEL_SHOW_TIME = 0.15;
 
21
const DASH_ITEM_LABEL_HIDE_TIME = 0.1;
 
22
const DASH_ITEM_HOVER_TIMEOUT = 300;
19
23
 
20
24
// A container like StBin, but taking the child's scale into account
21
25
// when requesting a size
22
 
function DashItemContainer() {
23
 
    this._init();
24
 
}
 
26
const DashItemContainer = new Lang.Class({
 
27
    Name: 'DashItemContainer',
25
28
 
26
 
DashItemContainer.prototype = {
27
29
    _init: function() {
28
30
        this.actor = new Shell.GenericContainer({ style_class: 'dash-item-container' });
29
31
        this.actor.connect('get-preferred-width',
34
36
                           Lang.bind(this, this._allocate));
35
37
        this.actor._delegate = this;
36
38
 
 
39
        this._label = null;
 
40
 
37
41
        this.child = null;
38
42
        this._childScale = 1;
39
43
        this._childOpacity = 255;
86
90
        alloc.natural_size = natWidth * this.child.scale_y;
87
91
    },
88
92
 
 
93
    showLabel: function() {
 
94
        if (this._label == null)
 
95
            return;
 
96
 
 
97
        this._label.opacity = 0;
 
98
        this._label.show();
 
99
 
 
100
        let [stageX, stageY] = this.actor.get_transformed_position();
 
101
 
 
102
        let itemHeight = this.actor.allocation.y2 - this.actor.allocation.y1;
 
103
 
 
104
        let labelHeight = this._label.get_height();
 
105
        let yOffset = Math.floor((itemHeight - labelHeight) / 2)
 
106
 
 
107
        let y = stageY + yOffset;
 
108
 
 
109
        let node = this._label.get_theme_node();
 
110
        let xOffset = node.get_length('-x-offset');
 
111
 
 
112
        let x;
 
113
        if (St.Widget.get_default_direction () == St.TextDirection.RTL)
 
114
            x = stageX - this._label.get_width() - xOffset;
 
115
        else
 
116
            x = stageX + this.actor.get_width() + xOffset;
 
117
 
 
118
        this._label.set_position(x, y);
 
119
        Tweener.addTween(this._label,
 
120
                         { opacity: 255,
 
121
                           time: DASH_ITEM_LABEL_SHOW_TIME,
 
122
                           transition: 'easeOutQuad',
 
123
                         });
 
124
    },
 
125
 
 
126
    setLabelText: function(text) {
 
127
        if (this._label == null)
 
128
            this._label = new St.Label({ style_class: 'dash-label'});
 
129
 
 
130
        this._label.set_text(text);
 
131
        Main.layoutManager.addChrome(this._label);
 
132
        this._label.hide();
 
133
    },
 
134
 
 
135
    hideLabel: function () {
 
136
        this._label.opacity = 255;
 
137
        Tweener.addTween(this._label,
 
138
                         { opacity: 0,
 
139
                           time: DASH_ITEM_LABEL_HIDE_TIME,
 
140
                           transition: 'easeOutQuad',
 
141
                           onComplete: Lang.bind(this, function() {
 
142
                               this._label.hide();
 
143
                           })
 
144
                         });
 
145
    },
 
146
 
89
147
    setChild: function(actor) {
90
148
        if (this.child == actor)
91
149
            return;
92
150
 
93
 
        this.actor.destroy_children();
 
151
        this.actor.destroy_all_children();
94
152
 
95
153
        this.child = actor;
96
154
        this.actor.add_actor(this.child);
157
215
    get childOpacity() {
158
216
        return this._childOpacity;
159
217
    }
160
 
};
161
 
 
162
 
function RemoveFavoriteIcon() {
163
 
    this._init();
164
 
}
165
 
 
166
 
RemoveFavoriteIcon.prototype = {
167
 
    __proto__: DashItemContainer.prototype,
 
218
});
 
219
 
 
220
const RemoveFavoriteIcon = new Lang.Class({
 
221
    Name: 'RemoveFavoriteIcon',
 
222
    Extends: DashItemContainer,
168
223
 
169
224
    _init: function() {
170
 
        DashItemContainer.prototype._init.call(this);
 
225
        this.parent();
171
226
 
172
227
        this._iconBin = new St.Bin({ style_class: 'remove-favorite' });
173
228
        this._iconActor = null;
219
274
 
220
275
        return true;
221
276
    }
222
 
};
223
 
 
224
 
 
225
 
function DragPlaceholderItem() {
226
 
    this._init();
227
 
}
228
 
 
229
 
DragPlaceholderItem.prototype = {
230
 
    __proto__: DashItemContainer.prototype,
 
277
});
 
278
 
 
279
const DragPlaceholderItem = new Lang.Class({
 
280
    Name: 'DragPlaceholderItem',
 
281
    Extends: DashItemContainer,
231
282
 
232
283
    _init: function() {
233
 
        DashItemContainer.prototype._init.call(this);
234
 
        this.setChild(new St.Bin({ style_class: 'dash-placeholder' }));
 
284
        this.parent();
 
285
        this.setChild(new St.Bin({ style_class: 'placeholder' }));
235
286
    }
236
 
};
237
 
 
238
 
 
239
 
function Dash() {
240
 
    this._init();
241
 
}
242
 
 
243
 
Dash.prototype = {
 
287
});
 
288
 
 
289
const Dash = new Lang.Class({
 
290
    Name: 'Dash',
 
291
 
244
292
    _init : function() {
245
293
        this._maxHeight = -1;
246
294
        this.iconSize = 64;
250
298
        this._dragPlaceholderPos = -1;
251
299
        this._animatingPlaceholdersCount = 0;
252
300
        this._favRemoveTarget = null;
 
301
        this._showLabelTimeoutId = 0;
 
302
        this._resetHoverTimeoutId = 0;
 
303
        this._labelShowing = false;
253
304
 
254
305
        this._box = new St.BoxLayout({ name: 'dash',
255
306
                                       vertical: true,
383
434
                                   Lang.bind(this, function() {
384
435
                                       display.actor.opacity = 255;
385
436
                                   }));
386
 
        display.actor.set_tooltip_text(app.get_name());
387
437
 
388
438
        let item = new DashItemContainer();
389
439
        item.setChild(display.actor);
390
440
 
 
441
        item.setLabelText(app.get_name());
 
442
 
391
443
        display.icon.setIconSize(this.iconSize);
392
 
 
 
444
        display.actor.connect('notify::hover',
 
445
                               Lang.bind(this, function() {
 
446
                                   this._onHover(item, display)
 
447
                               }));
393
448
        return item;
394
449
    },
395
450
 
 
451
    _onHover: function (item, display) {
 
452
        if (display.actor.get_hover() && !display.isMenuUp) {
 
453
            if (this._showLabelTimeoutId == 0) {
 
454
                let timeout = this._labelShowing ? 0 : DASH_ITEM_HOVER_TIMEOUT;
 
455
                this._showLabelTimeoutId = Mainloop.timeout_add(timeout,
 
456
                    Lang.bind(this, function() {
 
457
                        this._labelShowing = true;
 
458
                        item.showLabel();
 
459
                        return false;
 
460
                    }));
 
461
                if (this._resetHoverTimeoutId > 0) {
 
462
                    Mainloop.source_remove(this._resetHoverTimeoutId);
 
463
                this._resetHoverTimeoutId = 0;
 
464
                }
 
465
            }
 
466
        } else {
 
467
            if (this._showLabelTimeoutId > 0)
 
468
                Mainloop.source_remove(this._showLabelTimeoutId);
 
469
            this._showLabelTimeoutId = 0;
 
470
            item.hideLabel();
 
471
            if (this._labelShowing) {
 
472
                this._resetHoverTimeoutId = Mainloop.timeout_add(DASH_ITEM_HOVER_TIMEOUT,
 
473
                    Lang.bind(this, function() {
 
474
                        this._labelShowing = false;
 
475
                        return false;
 
476
                    }));
 
477
            }
 
478
        }
 
479
    },
 
480
 
396
481
    _adjustIconSize: function() {
397
482
        // For the icon size, we only consider children which are "proper"
398
483
        // icons (i.e. ignoring drag placeholders) and which are not
416
501
            return;
417
502
 
418
503
 
419
 
        let themeNode = this.actor.get_theme_node();
 
504
        let themeNode = this._box.get_theme_node();
420
505
        let maxAllocation = new Clutter.ActorBox({ x1: 0, y1: 0,
421
506
                                                   x2: 42 /* whatever */,
422
507
                                                   y2: this._maxHeight });
592
677
        }
593
678
 
594
679
        for (let i = 0; i < addedItems.length; i++)
595
 
            this._box.insert_actor(addedItems[i].item.actor,
596
 
                                   addedItems[i].pos);
 
680
            this._box.insert_child_at_index(addedItems[i].item.actor,
 
681
                                            addedItems[i].pos);
597
682
 
598
683
        for (let i = 0; i < removedActors.length; i++) {
599
684
            let item = removedActors[i]._delegate;
702
787
            this._dragPlaceholder = new DragPlaceholderItem();
703
788
            this._dragPlaceholder.child.set_width (this.iconSize);
704
789
            this._dragPlaceholder.child.set_height (this.iconSize / 2);
705
 
            this._box.insert_actor(this._dragPlaceholder.actor,
706
 
                                   this._dragPlaceholderPos);
 
790
            this._box.insert_child_at_index(this._dragPlaceholder.actor,
 
791
                                            this._dragPlaceholderPos);
707
792
            if (fadeIn)
708
793
                this._dragPlaceholder.animateIn();
709
794
        }
762
847
 
763
848
        return true;
764
849
    }
765
 
};
 
850
});
766
851
 
767
852
Signals.addSignalMethods(Dash.prototype);