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

« back to all changes in this revision

Viewing changes to js/ui/magnifier.js

Tags: upstream-3.3.90
ImportĀ upstreamĀ versionĀ 3.3.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
2
2
 
3
3
const Clutter = imports.gi.Clutter;
 
4
const GDesktopEnums = imports.gi.GDesktopEnums;
4
5
const Gio = imports.gi.Gio;
5
6
const Shell = imports.gi.Shell;
6
7
const St = imports.gi.St;
12
13
const MagnifierDBus = imports.ui.magnifierDBus;
13
14
const Params = imports.misc.params;
14
15
 
15
 
// Keep enums in sync with GSettings schemas
16
 
const MouseTrackingMode = {
17
 
    NONE: 0,
18
 
    CENTERED: 1,
19
 
    PROPORTIONAL: 2,
20
 
    PUSH: 3
21
 
};
22
 
 
23
 
const ScreenPosition = {
24
 
    NONE: 0,
25
 
    FULL_SCREEN: 1,
26
 
    TOP_HALF: 2,
27
 
    BOTTOM_HALF: 3,
28
 
    LEFT_HALF: 4,
29
 
    RIGHT_HALF: 5
30
 
};
31
16
 
32
17
const MOUSE_POLL_FREQUENCY = 50;
33
18
const CROSSHAIRS_CLIP_SIZE = [100, 100];
51
36
 
52
37
let magDBusService = null;
53
38
 
54
 
function Magnifier() {
55
 
    this._init();
56
 
}
 
39
const Magnifier = new Lang.Class({
 
40
    Name: 'Magnifier',
57
41
 
58
 
Magnifier.prototype = {
59
42
    _init: function() {
60
43
        // Magnifier is a manager of ZoomRegions.
61
44
        this._zoomRegions = [];
62
45
 
63
46
        // Create small clutter tree for the magnified mouse.
64
 
        let xfixesCursor = Shell.XFixesCursor.get_default();
 
47
        let xfixesCursor = Shell.XFixesCursor.get_for_stage(global.stage);
65
48
        this._mouseSprite = new Clutter.Texture();
66
49
        xfixesCursor.update_texture_image(this._mouseSprite);
67
50
        this._cursorRoot = new Clutter.Group();
520
503
        if (this._zoomRegions.length) {
521
504
            let position = this._settings.get_enum(SCREEN_POSITION_KEY);
522
505
            this._zoomRegions[0].setScreenPosition(position);
523
 
            if (position != ScreenPosition.FULL_SCREEN)
 
506
            if (position != GDesktopEnums.MagnifierScreenPosition.FULL_SCREEN)
524
507
                this._updateLensMode();
525
508
        }
526
509
    },
558
541
            );
559
542
        }
560
543
    }
561
 
};
 
544
});
562
545
Signals.addSignalMethods(Magnifier.prototype);
563
546
 
564
 
function ZoomRegion(magnifier, mouseSourceActor) {
565
 
    this._init(magnifier, mouseSourceActor);
566
 
}
 
547
const ZoomRegion = new Lang.Class({
 
548
    Name: 'ZoomRegion',
567
549
 
568
 
ZoomRegion.prototype = {
569
550
    _init: function(magnifier, mouseSourceActor) {
570
551
        this._magnifier = magnifier;
571
552
 
572
 
        this._mouseTrackingMode = MouseTrackingMode.NONE;
 
553
        this._mouseTrackingMode = GDesktopEnums.MagnifierMouseTrackingMode.NONE;
573
554
        this._clampScrollingAtEdges = false;
574
555
        this._lensMode = false;
575
 
        this._screenPosition = ScreenPosition.FULL_SCREEN;
 
556
        this._screenPosition = GDesktopEnums.MagnifierScreenPosition.FULL_SCREEN;
576
557
 
577
558
        this._magView = null;
 
559
        this._background = null;
578
560
        this._uiGroupClone = null;
579
561
        this._mouseSourceActor = mouseSourceActor;
580
562
        this._mouseActor  = null;
584
566
        this._viewPortX = 0;
585
567
        this._viewPortY = 0;
586
568
        this._viewPortWidth = global.screen_width;
587
 
        this._viewPortWidth = global.screen_height;
 
569
        this._viewPortHeight = global.screen_height;
588
570
        this._xCenter = this._viewPortWidth / 2;
589
571
        this._yCenter = this._viewPortHeight / 2;
590
572
        this._xMagFactor = 1;
591
573
        this._yMagFactor = 1;
592
574
        this._followingCursor = false;
 
575
 
 
576
        Main.layoutManager.connect('monitors-changed',
 
577
                                   Lang.bind(this, this._monitorsChanged));
593
578
    },
594
579
 
595
580
    /**
647
632
     * @mode:     One of the enum MouseTrackingMode values.
648
633
     */
649
634
    setMouseTrackingMode: function(mode) {
650
 
        if (mode >= MouseTrackingMode.NONE && mode <= MouseTrackingMode.PUSH)
 
635
        if (mode >= GDesktopEnums.MagnifierMouseTrackingMode.NONE &&
 
636
            mode <= GDesktopEnums.MagnifierMouseTrackingMode.PUSH)
651
637
            this._mouseTrackingMode = mode;
652
638
    },
653
639
 
668
654
     */
669
655
    setViewPort: function(viewPort) {
670
656
        this._setViewPort(viewPort);
671
 
        this._screenPosition = ScreenPosition.NONE;
 
657
        this._screenPosition = GDesktopEnums.MagnifierScreenPosition.NONE;
672
658
    },
673
659
 
674
660
    /**
750
736
        viewPort.width = global.screen_width;
751
737
        viewPort.height = global.screen_height/2;
752
738
        this._setViewPort(viewPort);
753
 
        this._screenPosition = ScreenPosition.TOP_HALF;
 
739
        this._screenPosition = GDesktopEnums.MagnifierScreenPosition.TOP_HALF;
754
740
    },
755
741
 
756
742
    /**
764
750
        viewPort.width = global.screen_width;
765
751
        viewPort.height = global.screen_height/2;
766
752
        this._setViewPort(viewPort);
767
 
        this._screenPosition = ScreenPosition.BOTTOM_HALF;
 
753
        this._screenPosition = GDesktopEnums.MagnifierScreenPosition.BOTTOM_HALF;
768
754
    },
769
755
 
770
756
    /**
778
764
        viewPort.width = global.screen_width/2;
779
765
        viewPort.height = global.screen_height;
780
766
        this._setViewPort(viewPort);
781
 
        this._screenPosition = ScreenPosition.LEFT_HALF;
 
767
        this._screenPosition = GDesktopEnums.MagnifierScreenPosition.LEFT_HALF;
782
768
    },
783
769
 
784
770
    /**
792
778
        viewPort.width = global.screen_width/2;
793
779
        viewPort.height = global.screen_height;
794
780
        this._setViewPort(viewPort);
795
 
        this._screenPosition = ScreenPosition.RIGHT_HALF;
 
781
        this._screenPosition = GDesktopEnums.MagnifierScreenPosition.RIGHT_HALF;
796
782
    },
797
783
 
798
784
    /**
808
794
        viewPort.height = global.screen_height;
809
795
        this.setViewPort(viewPort);
810
796
 
811
 
        this._screenPosition = ScreenPosition.FULL_SCREEN;
 
797
        this._screenPosition = GDesktopEnums.MagnifierScreenPosition.FULL_SCREEN;
812
798
    },
813
799
 
814
800
    /**
821
807
     */
822
808
    setScreenPosition: function(inPosition) {
823
809
        switch (inPosition) {
824
 
            case ScreenPosition.FULL_SCREEN:
 
810
            case GDesktopEnums.MagnifierScreenPosition.FULL_SCREEN:
825
811
                this.setFullScreenMode();
826
812
                break;
827
 
            case ScreenPosition.TOP_HALF:
 
813
            case GDesktopEnums.MagnifierScreenPosition.TOP_HALF:
828
814
                this.setTopHalf();
829
815
                break;
830
 
            case ScreenPosition.BOTTOM_HALF:
 
816
            case GDesktopEnums.MagnifierScreenPosition.BOTTOM_HALF:
831
817
                this.setBottomHalf();
832
818
                break;
833
 
            case ScreenPosition.LEFT_HALF:
 
819
            case GDesktopEnums.MagnifierScreenPosition.LEFT_HALF:
834
820
                this.setLeftHalf();
835
821
                break;
836
 
            case ScreenPosition.RIGHT_HALF:
 
822
            case GDesktopEnums.MagnifierScreenPosition.RIGHT_HALF:
837
823
                this.setRightHalf();
838
824
                break;
839
825
        }
856
842
     */
857
843
    scrollToMousePos: function() {
858
844
        this._followingCursor = true;
859
 
        if (this._mouseTrackingMode != MouseTrackingMode.NONE)
 
845
        if (this._mouseTrackingMode != GDesktopEnums.MagnifierMouseTrackingMode.NONE)
860
846
            this._changeROI({ redoCursorTracking: true });
861
847
        else
862
848
            this._updateMousePosition();
909
895
 
910
896
        // Add a background for when the magnified uiGroup is scrolled
911
897
        // out of view (don't want to see desktop showing through).
912
 
        let background = new Clutter.Rectangle({ color: Main.DEFAULT_BACKGROUND_COLOR });
913
 
        mainGroup.add_actor(background);
 
898
        this._background = new Clutter.Rectangle({ color: Main.DEFAULT_BACKGROUND_COLOR });
 
899
        mainGroup.add_actor(this._background);
914
900
 
915
901
        // Clone the group that contains all of UI on the screen.  This is the
916
902
        // chrome, the windows, etc.
917
903
        this._uiGroupClone = new Clutter.Clone({ source: Main.uiGroup });
918
904
        mainGroup.add_actor(this._uiGroupClone);
919
905
        Main.uiGroup.set_size(global.screen_width, global.screen_height);
920
 
        background.set_size(global.screen_width, global.screen_height);
 
906
        this._background.set_size(global.screen_width, global.screen_height);
921
907
 
922
908
        // Add either the given mouseSourceActor to the ZoomRegion, or a clone of
923
909
        // it.
941
927
 
942
928
        this._magView.destroy();
943
929
        this._magView = null;
 
930
        this._background = null;
944
931
        this._uiGroupClone = null;
945
932
        this._mouseActor = null;
946
933
        this._crossHairsActor = null;
991
978
        this._yMagFactor = params.yMagFactor;
992
979
 
993
980
        if (params.redoCursorTracking &&
994
 
            this._mouseTrackingMode != MouseTrackingMode.NONE) {
 
981
            this._mouseTrackingMode != GDesktopEnums.MagnifierMouseTrackingMode.NONE) {
995
982
            // This depends on this.xMagFactor/yMagFactor already being updated
996
983
            [params.xCenter, params.yCenter] = this._centerFromMousePosition();
997
984
        }
1041
1028
    _isFullScreen: function() {
1042
1029
        // Does the magnified view occupy the whole screen? Note that this
1043
1030
        // doesn't necessarily imply
1044
 
        // this._screenPosition = ScreenPosition.FULL_SCREEN;
 
1031
        // this._screenPosition = GDesktopEnums.MagnifierScreenPosition.FULL_SCREEN;
1045
1032
 
1046
1033
        if (this._viewPortX != 0 || this._viewPortY != 0)
1047
1034
            return false;
1058
1045
        let xMouse = this._magnifier.xMouse;
1059
1046
        let yMouse = this._magnifier.yMouse;
1060
1047
 
1061
 
        if (this._mouseTrackingMode == MouseTrackingMode.PROPORTIONAL) {
 
1048
        if (this._mouseTrackingMode == GDesktopEnums.MagnifierMouseTrackingMode.PROPORTIONAL) {
1062
1049
            return this._centerFromMouseProportional(xMouse, yMouse);
1063
1050
        }
1064
 
        else if (this._mouseTrackingMode == MouseTrackingMode.PUSH) {
 
1051
        else if (this._mouseTrackingMode == GDesktopEnums.MagnifierMouseTrackingMode.PUSH) {
1065
1052
            return this._centerFromMousePush(xMouse, yMouse);
1066
1053
        }
1067
 
        else if (this._mouseTrackingMode == MouseTrackingMode.CENTERED) {
 
1054
        else if (this._mouseTrackingMode == GDesktopEnums.MagnifierMouseTrackingMode.CENTERED) {
1068
1055
            return this._centerFromMouseCentered(xMouse, yMouse);
1069
1056
        }
1070
1057
 
1163
1150
            this._crossHairsActor.set_position(xMagMouse - groupWidth / 2,
1164
1151
                                               yMagMouse - groupHeight / 2);
1165
1152
        }
 
1153
    },
 
1154
 
 
1155
    _monitorsChanged: function() {
 
1156
        if (!this.isActive())
 
1157
            return;
 
1158
 
 
1159
        Main.uiGroup.set_size(global.screen_width, global.screen_height);
 
1160
        this._background.set_size(global.screen_width, global.screen_height);
 
1161
 
 
1162
        if (this._screenPosition == GDesktopEnums.MagnifierScreenPosition.NONE)
 
1163
            this._setViewPort({ x: this._viewPortX,
 
1164
                                y: this._viewPortY,
 
1165
                                width: this._viewPortWidth,
 
1166
                                height: this._viewPortHeight });
 
1167
        else
 
1168
            this.setScreenPosition(this._screenPosition);
1166
1169
    }
1167
 
};
1168
 
 
1169
 
function Crosshairs() {
1170
 
    this._init();
1171
 
}
1172
 
 
1173
 
Crosshairs.prototype = {
 
1170
});
 
1171
 
 
1172
const Crosshairs = new Lang.Class({
 
1173
    Name: 'Crosshairs',
 
1174
 
1174
1175
    _init: function() {
1175
1176
 
1176
1177
        // Set the group containing the crosshairs to three times the desktop
1195
1196
        this._clipSize = [0, 0];
1196
1197
        this._clones = [];
1197
1198
        this.reCenter();
 
1199
 
 
1200
        Main.layoutManager.connect('monitors-changed',
 
1201
                                   Lang.bind(this, this._monitorsChanged));
 
1202
    },
 
1203
 
 
1204
    _monitorsChanged: function() {
 
1205
        this._actor.set_size(global.screen_width * 3, global.screen_height * 3);
 
1206
        this.reCenter();
1198
1207
    },
1199
1208
 
1200
1209
   /**
1426
1435
        this._vertTopHair.set_position((groupWidth - thickness) / 2, top);
1427
1436
        this._vertBottomHair.set_position((groupWidth - thickness) / 2, bottom);
1428
1437
    }
1429
 
};
 
1438
});