blob: b1814a57d4ee0f514210db437265be9adbd59b7d [file] [log] [blame]
cjgrant2a755872017-05-13 19:30:211// Copyright 2017 The Chromium 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
Ian Vollick4e26ac322017-07-11 14:58:215#include "chrome/browser/vr/elements/loading_indicator.h"
cjgrant2a755872017-05-13 19:30:216
7#include "base/memory/ptr_util.h"
Ian Vollick4e26ac322017-07-11 14:58:218#include "chrome/browser/vr/elements/loading_indicator_texture.h"
cjgrant2a755872017-05-13 19:30:219
Ian Vollick4e26ac322017-07-11 14:58:2110namespace vr {
cjgrant2a755872017-05-13 19:30:2111
cjgrant2a755872017-05-13 19:30:2112LoadingIndicator::LoadingIndicator(int preferred_width)
13 : TexturedElement(preferred_width),
klausw66af1342017-05-18 18:19:1414 texture_(base::MakeUnique<LoadingIndicatorTexture>()) {
Ian Vollicke1b825582017-07-20 23:07:0315 SetVisible(false);
klausw66af1342017-05-18 18:19:1416}
cjgrant2a755872017-05-13 19:30:2117
18LoadingIndicator::~LoadingIndicator() = default;
19
20UiTexture* LoadingIndicator::GetTexture() const {
21 return texture_.get();
22}
23
Ian Vollickdf624532017-08-30 19:49:1624void LoadingIndicator::SetVisible(bool visible) {
25 if (visible_ == visible)
cjgrant2a755872017-05-13 19:30:2126 return;
Ian Vollickdf624532017-08-30 19:49:1627 visible_ = visible;
28 UpdateOpacity();
cjgrant2a755872017-05-13 19:30:2129}
30
31void LoadingIndicator::SetLoading(bool loading) {
32 if (loading_ == loading)
33 return;
34 loading_ = loading;
35 texture_->SetLoading(loading);
36 texture_->SetLoadProgress(0);
Ian Vollickdf624532017-08-30 19:49:1637 UpdateOpacity();
cjgrant2a755872017-05-13 19:30:2138}
39
40void LoadingIndicator::SetLoadProgress(float progress) {
41 texture_->SetLoadProgress(progress);
42}
43
Ian Vollickdf624532017-08-30 19:49:1644void LoadingIndicator::UpdateOpacity() {
45 SetOpacity((visible_ && loading_) ? opacity_when_visible() : 0);
cjgrant2a755872017-05-13 19:30:2146}
47
Ian Vollick4e26ac322017-07-11 14:58:2148} // namespace vr