Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 1 | // 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 | |
| 5 | var SelectionBroker = function() { |
| 6 | this.brokers = []; |
| 7 | this.dispatching = false; |
| 8 | this.lastDispatchingHandler = null; |
| 9 | }; |
| 10 | |
| 11 | SelectionBroker.prototype.addSelectionHandler = function(handler) { |
| 12 | this.brokers.push(handler); |
| 13 | } |
| 14 | |
| 15 | SelectionBroker.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 | |
| 32 | SelectionBroker.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 | } |