Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(657)

Side by Side Diff: chrome/browser/android/vr_shell/ui_elements/loading_indicator.cc

Issue 2877133002: VR: Add a loading indicator to the scene. (Closed)
Patch Set: Rebase onto render text change. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
5 #include "chrome/browser/android/vr_shell/ui_elements/loading_indicator.h"
6
7 #include "base/memory/ptr_util.h"
8 #include "chrome/browser/android/vr_shell/textures/loading_indicator_texture.h"
9
10 namespace vr_shell {
11
12 namespace {
13
14 static constexpr int kVisibilityTimeoutMs = 200;
15 }
16
17 LoadingIndicator::LoadingIndicator(int preferred_width)
18 : TexturedElement(preferred_width),
19 texture_(base::MakeUnique<LoadingIndicatorTexture>()) {}
20
21 LoadingIndicator::~LoadingIndicator() = default;
22
23 UiTexture* LoadingIndicator::GetTexture() const {
24 return texture_.get();
25 }
26
27 void LoadingIndicator::SetEnabled(bool enabled) {
28 if (enabled_ == enabled)
29 return;
30 enabled_ = enabled;
31 ResetVisibilityTimer();
32 SetVisibility();
33 }
34
35 void LoadingIndicator::SetLoading(bool loading) {
36 if (loading_ == loading)
37 return;
38 loading_ = loading;
39 texture_->SetLoading(loading);
40 texture_->SetLoadProgress(0);
41 ResetVisibilityTimer();
42 SetVisibility();
43 }
44
45 void LoadingIndicator::SetLoadProgress(float progress) {
46 texture_->SetLoadProgress(progress);
47 }
48
49 void LoadingIndicator::ResetVisibilityTimer() {
50 if (enabled_ && !loading_) {
51 visibility_timer_.Start(
52 FROM_HERE, base::TimeDelta::FromMilliseconds(kVisibilityTimeoutMs),
53 this, &LoadingIndicator::SetVisibility);
54 } else {
55 visibility_timer_.Stop();
56 }
57 }
58
59 void LoadingIndicator::SetVisibility() {
60 set_visible(enabled_ && (loading_ || visibility_timer_.IsRunning()));
61 }
62
63 void LoadingIndicator::OnBeginFrame(const base::TimeTicks& ticks) {
64 if (enabled_ && texture_->dirty())
65 UpdateTexture();
66 }
67
68 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698