summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/modules/media_controls/touchless/elements/media_controls_touchless_time_display_element.cc
blob: 5c6db6bfa0160984041b95c314c746231a0a0e61 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// 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/text/platform_locale.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::OnSeeking() {
  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);

  StringBuilder aria_label;
  aria_label.Append(GetLocale().QueryString(
      WebLocalizedString::kAXMediaCurrentTimeDisplay,
      MediaControlsSharedHelpers::FormatTime(current_time_)));
  aria_label.Append(" ");
  aria_label.Append(GetLocale().QueryString(
      WebLocalizedString::kAXMediaTimeRemainingDisplay,
      MediaControlsSharedHelpers::FormatTime(duration_)));
  setAttribute(html_names::kAriaLabelAttr, aria_label.ToAtomicString());
}

}  // namespace blink