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

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: Add units to timeout constant. 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 if (enabled_)
32 Update();
33 ResetVisibilityTimer();
34 SetVisibility();
35 }
36
37 void LoadingIndicator::SetLoading(bool loading) {
38 if (loading_ == loading)
39 return;
40 loading_ = loading;
41 texture_->SetLoading(loading);
42 texture_->SetLoadProgress(0);
43 if (enabled_)
44 Update();
45 ResetVisibilityTimer();
46 SetVisibility();
47 }
48
49 void LoadingIndicator::SetLoadProgress(float progress) {
50 texture_->SetLoadProgress(progress);
51 if (enabled_)
52 Update();
53 }
54
55 void LoadingIndicator::ResetVisibilityTimer() {
56 if (enabled_ && !loading_) {
57 visibility_timer_.Start(
58 FROM_HERE, base::TimeDelta::FromMilliseconds(kVisibilityTimeoutMs),
59 this, &LoadingIndicator::SetVisibility);
60 } else {
61 visibility_timer_.Stop();
62 }
63 }
64
65 void LoadingIndicator::SetVisibility() {
66 set_visible(enabled_ && (loading_ || visibility_timer_.IsRunning()));
67 }
68
69 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698