blob: 3a223d8b643097079d68b543eadc741e797c7977 [file] [log] [blame]
Ben Murdoch61f157c2016-09-16 13:49:30 +01001// Copyright 2015 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5var SelectionBroker = function() {
6 this.brokers = [];
7 this.dispatching = false;
8 this.lastDispatchingHandler = null;
9};
10
11SelectionBroker.prototype.addSelectionHandler = function(handler) {
12 this.brokers.push(handler);
13}
14
15SelectionBroker.prototype.select = function(from, ranges, selected) {
16 if (!this.dispatching) {
17 this.lastDispatchingHandler = from;
18 try {
19 this.dispatching = true;
20 for (var b of this.brokers) {
21 if (b != from) {
22 b.brokeredSelect(ranges, selected);
23 }
24 }
25 }
26 finally {
27 this.dispatching = false;
28 }
29 }
30}
31
32SelectionBroker.prototype.clear = function(from) {
33 this.lastDispatchingHandler = null;
34 if (!this.dispatching) {
35 try {
36 this.dispatching = true;
37 this.brokers.forEach(function(b) {
38 if (b != from) {
39 b.brokeredClear();
40 }
41 });
42 } finally {
43 this.dispatching = false;
44 }
45 }
46}