cjgrant | 2a75587 | 2017-05-13 19:30:21 | [diff] [blame] | 1 | // 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 Vollick | 4e26ac32 | 2017-07-11 14:58:21 | [diff] [blame] | 5 | #include "chrome/browser/vr/elements/loading_indicator.h" |
cjgrant | 2a75587 | 2017-05-13 19:30:21 | [diff] [blame] | 6 | |
| 7 | #include "base/memory/ptr_util.h" |
Ian Vollick | 4e26ac32 | 2017-07-11 14:58:21 | [diff] [blame] | 8 | #include "chrome/browser/vr/elements/loading_indicator_texture.h" |
cjgrant | 2a75587 | 2017-05-13 19:30:21 | [diff] [blame] | 9 | |
Ian Vollick | 4e26ac32 | 2017-07-11 14:58:21 | [diff] [blame] | 10 | namespace vr { |
cjgrant | 2a75587 | 2017-05-13 19:30:21 | [diff] [blame] | 11 | |
cjgrant | 2a75587 | 2017-05-13 19:30:21 | [diff] [blame] | 12 | LoadingIndicator::LoadingIndicator(int preferred_width) |
| 13 | : TexturedElement(preferred_width), |
klausw | 66af134 | 2017-05-18 18:19:14 | [diff] [blame] | 14 | texture_(base::MakeUnique<LoadingIndicatorTexture>()) { |
Ian Vollick | e1b82558 | 2017-07-20 23:07:03 | [diff] [blame] | 15 | SetVisible(false); |
klausw | 66af134 | 2017-05-18 18:19:14 | [diff] [blame] | 16 | } |
cjgrant | 2a75587 | 2017-05-13 19:30:21 | [diff] [blame] | 17 | |
| 18 | LoadingIndicator::~LoadingIndicator() = default; |
| 19 | |
| 20 | UiTexture* LoadingIndicator::GetTexture() const { |
| 21 | return texture_.get(); |
| 22 | } |
| 23 | |
Ian Vollick | df62453 | 2017-08-30 19:49:16 | [diff] [blame] | 24 | void LoadingIndicator::SetVisible(bool visible) { |
| 25 | if (visible_ == visible) |
cjgrant | 2a75587 | 2017-05-13 19:30:21 | [diff] [blame] | 26 | return; |
Ian Vollick | df62453 | 2017-08-30 19:49:16 | [diff] [blame] | 27 | visible_ = visible; |
| 28 | UpdateOpacity(); |
cjgrant | 2a75587 | 2017-05-13 19:30:21 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | void LoadingIndicator::SetLoading(bool loading) { |
| 32 | if (loading_ == loading) |
| 33 | return; |
| 34 | loading_ = loading; |
| 35 | texture_->SetLoading(loading); |
| 36 | texture_->SetLoadProgress(0); |
Ian Vollick | df62453 | 2017-08-30 19:49:16 | [diff] [blame] | 37 | UpdateOpacity(); |
cjgrant | 2a75587 | 2017-05-13 19:30:21 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | void LoadingIndicator::SetLoadProgress(float progress) { |
| 41 | texture_->SetLoadProgress(progress); |
| 42 | } |
| 43 | |
Ian Vollick | df62453 | 2017-08-30 19:49:16 | [diff] [blame] | 44 | void LoadingIndicator::UpdateOpacity() { |
| 45 | SetOpacity((visible_ && loading_) ? opacity_when_visible() : 0); |
cjgrant | 2a75587 | 2017-05-13 19:30:21 | [diff] [blame] | 46 | } |
| 47 | |
Ian Vollick | 4e26ac32 | 2017-07-11 14:58:21 | [diff] [blame] | 48 | } // namespace vr |