summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/modules/media_controls/touchless/elements/media_controls_touchless_time_display_element.cc
blob: 261f52bb2d81b7a458f5c092f48733808f32634c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/modules/media_controls/touchless/elements/media_controls_touchless_time_display_element.h"

#include "third_party/blink/renderer/core/html/media/html_media_element.h"
#include "third_party/blink/renderer/modules/media_controls/media_controls_shared_helper.h"
#include "third_party/blink/renderer/modules/media_controls/touchless/media_controls_touchless_impl.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"

namespace blink {

MediaControlsTouchlessTimeDisplayElement::
    MediaControlsTouchlessTimeDisplayElement(
        MediaControlsTouchlessImpl& media_controls)
    : MediaControlsTouchlessElement(media_controls),
      current_time_(0.0),
      duration_(0.0) {
  SetShadowPseudoId(
      AtomicString("-internal-media-controls-touchless-time-display"));
  UpdateTimeDisplay();
}

void MediaControlsTouchlessTimeDisplayElement::OnTimeUpdate() {
  current_time_ = MediaElement().currentTime();
  UpdateTimeDisplay();
}

void MediaControlsTouchlessTimeDisplayElement::OnDurationChange() {
  duration_ = MediaElement().duration();
  UpdateTimeDisplay();
}

void MediaControlsTouchlessTimeDisplayElement::Trace(blink::Visitor* visitor) {
  MediaControlsTouchlessElement::Trace(visitor);
}

void MediaControlsTouchlessTimeDisplayElement::UpdateTimeDisplay() {
  StringBuilder builder;
  builder.Append(MediaControlsSharedHelpers::FormatTime(current_time_));
  builder.Append(" / ");
  builder.Append(MediaControlsSharedHelpers::FormatTime(duration_));
  setInnerText(builder.ToAtomicString(), ASSERT_NO_EXCEPTION);
}

}  // namespace blink