2 # Copyright Simon Lydell 2015.
4 # This file is part of VimFx.
6 # VimFx is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # VimFx is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with VimFx. If not, see <http://www.gnu.org/licenses/>.
20 # This file contains an abstraction for keeping track of scrollable elements,
21 # automatically keeping the largest scrollable element up-to-date. It stops
22 # tracking elements that are removed from the DOM, or whose containg frame is
25 utils = require('./utils')
27 class ScrollableElements
28 constructor: (@window) ->
32 has: (element) -> @elements.has(element)
35 @elements.add(element)
36 utils.onRemoved(@window, element, @delete.bind(this, element))
38 if not @largest or utils.area(element) > utils.area(@largest)
42 @elements.delete(element)
43 @updateLargest() if @largest == element
46 @elements.forEach((element) => @elements.delete(element) if fn(element))
52 # Find a new largest scrollable element (if there are any left).
54 @elements.forEach((element) =>
55 area = utils.area(element)
61 module.exports = ScrollableElements