• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2013 The Flutter 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
5part of engine;
6
7/// A surface that translates its children using CSS transform and translate.
8class PersistedOffset extends PersistedContainerSurface
9    implements ui.OffsetEngineLayer {
10  PersistedOffset(PersistedOffset oldLayer, this.dx, this.dy) : super(oldLayer);
11
12  /// Horizontal displacement.
13  final double dx;
14
15  /// Vertical displacement.
16  final double dy;
17
18  @override
19  void recomputeTransformAndClip() {
20    _transform = parent._transform;
21    if (dx != 0.0 || dy != 0.0) {
22      _transform = _transform.clone();
23      _transform.translate(dx, dy);
24    }
25    _globalClip = parent._globalClip;
26  }
27
28  @override
29  html.Element createElement() {
30    return defaultCreateElement('flt-offset')..style.transformOrigin = '0 0 0';
31  }
32
33  @override
34  void apply() {
35    rootElement.style.transform = 'translate(${dx}px, ${dy}px)';
36  }
37
38  @override
39  void update(PersistedOffset oldSurface) {
40    super.update(oldSurface);
41
42    if (oldSurface.dx != dx || oldSurface.dy != dy) {
43      apply();
44    }
45  }
46}
47