Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/child/commands.js

Issue 29363476: Issue 2879 - Move element selection into the content process (Closed) Base URL: https://hg.adblockplus.org/elemhidehelper
Patch Set: Created Nov. 17, 2016, 1:17 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * This Source Code is subject to the terms of the Mozilla Public License
3 * version 2.0 (the "License"). You can obtain a copy of the License at
4 * http://mozilla.org/MPL/2.0/.
5 */
6
7 "use strict";
8
9 let messageManager = require("messageManager");
10 let {getNodeInfo} = require("./nodeInfo");
11 let {
12 state, selectElement, setAnchorElement, stopSelection
13 } = require("./selection");
14 let {getParentElement} = require("./utils");
15
16 messageManager.addMessageListener("ElemHideHelper:Command", onCommand);
17
18 onShutdown.add(() =>
19 {
20 messageManager.removeMessageListener("ElemHideHelper:Command", onCommand);
21 });
22
23 function onCommand(message)
24 {
25 let command = message.data;
26 if (typeof exports[command] == "function")
27 exports[command]();
28 }
29
30 function quit()
31 {
32 stopSelection();
33 }
34 exports.quit = quit;
35
36 function select()
37 {
38 if (!state.selectedElement)
39 return;
40
41 messageManager.sendAsyncMessage(
42 "ElemHideHelper:SelectionSucceeded",
43 getNodeInfo(state.selectedElement)
44 );
45 stopSelection();
saroyanm 2016/11/23 17:44:38 Why not call stopSelection in SelectionSucceeded m
Wladimir Palant 2016/11/24 14:02:01 stopSelection() is a general cleanup method. It do
46 }
47 exports.select = select;
48
49 function wider()
50 {
51 if (!state.selectedElement)
52 return;
53
54 let newElement = getParentElement(state.selectedElement);
55 if (!newElement)
56 return;
57
58 state.isUserSelected = true;
59 selectElement(newElement);
60 }
61 exports.wider = wider;
62
63 function narrower()
64 {
65 if (!state.selectedElement)
66 return;
67
68 // Search selected element in the parent chain, starting with the ancho
69 // element. We need to select the element just before the selected one.
70 let e = state.anchorElement;
71 let newElement = null;
72 while (e && e != state.selectedElement)
73 {
74 newElement = e;
75 e = getParentElement(e);
76 }
77
78 if (!e || !newElement)
79 return;
80
81 state.isUserSelected = true;
82 selectElement(newElement);
83 }
84 exports.narrower = narrower;
85
86 function lock()
87 {
88 if (!state.selectedElement)
89 return;
90
91 if (state.lockedAnchor)
92 {
93 setAnchorElement(state.lockedAnchor);
94 state.lockedAnchor = null;
95 }
96 else
97 state.lockedAnchor = state.anchorElement;
98 }
99 exports.lock = lock;
100
101 let blinkState = null;
Wladimir Palant 2016/11/17 13:54:48 I moved the properties related to the blink functi
saroyanm 2016/11/23 17:44:38 Acknowledged.
102
103 function stopBlinking()
104 {
105 blinkState.timer.cancel();
106 if (!Cu.isDeadWrapper(blinkState.element))
107 blinkState.element.style.visibility = blinkState.origVisibility;
108 blinkState = null;
109 }
110
111 function doBlink()
Wladimir Palant 2016/11/17 13:54:48 This was a closure in the original code, having it
saroyanm 2016/11/23 17:44:38 Acknowledged.
112 {
113 if (Cu.isDeadWrapper(blinkState.element))
114 {
115 stopBlinking();
116 return;
117 }
118
119 blinkState.counter++;
120 blinkState.element.style.setProperty(
121 "visibility",
122 (blinkState.counter % 2 == 0 ? "visible" : "hidden"),
123 "important"
124 );
Wladimir Palant 2016/11/17 13:54:48 Original code was simply assigning element.style.v
saroyanm 2016/11/23 17:44:38 Acknowledged.
125 if (blinkState.counter == 6)
126 stopBlinking();
127 }
128
129 function blinkElement()
130 {
131 if (!state.selectedElement)
132 return;
133
134 if (blinkState)
135 stopBlinking();
136
137 blinkState = {
138 counter: 0,
139 element: state.selectedElement,
140 origVisibility: state.selectedElement.style.visibility,
141 timer: Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer)
142 };
143
144 blinkState.timer.initWithCallback(doBlink, 250,
145 Ci.nsITimer.TYPE_REPEATING_SLACK);
146 }
147 exports.blinkElement = blinkElement;
OLDNEW

Powered by Google App Engine
This is Rietveld