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

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

Issue 2801073002: [vr] Use base's time classes (Closed)
Patch Set: updated tests Created 3 years, 8 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/android/vr_shell/ui_elements.h" 5 #include "chrome/browser/android/vr_shell/ui_elements.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/time/time.h"
10 #include "chrome/browser/android/vr_shell/animation.h" 11 #include "chrome/browser/android/vr_shell/animation.h"
11 #include "chrome/browser/android/vr_shell/easing.h" 12 #include "chrome/browser/android/vr_shell/easing.h"
12 13
13 namespace vr_shell { 14 namespace vr_shell {
14 15
15 namespace { 16 namespace {
16 17
17 bool GetRayPlaneDistance(const gvr::Vec3f& ray_origin, 18 bool GetRayPlaneDistance(const gvr::Vec3f& ray_origin,
18 const gvr::Vec3f& ray_vector, 19 const gvr::Vec3f& ray_vector,
19 const gvr::Vec3f& plane_origin, 20 const gvr::Vec3f& plane_origin,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 const gvr::Vec3f& ray_vector, 94 const gvr::Vec3f& ray_vector,
94 float* distance) const { 95 float* distance) const {
95 return GetRayPlaneDistance(ray_origin, ray_vector, GetCenter(), GetNormal(), 96 return GetRayPlaneDistance(ray_origin, ray_vector, GetCenter(), GetNormal(),
96 distance); 97 distance);
97 } 98 }
98 99
99 ContentRectangle::ContentRectangle() = default; 100 ContentRectangle::ContentRectangle() = default;
100 101
101 ContentRectangle::~ContentRectangle() = default; 102 ContentRectangle::~ContentRectangle() = default;
102 103
103 void ContentRectangle::Animate(int64_t time) { 104 void ContentRectangle::Animate(const base::TimeTicks& time) {
104 for (auto& it : animations) { 105 for (auto& it : animations) {
105 Animation& animation = *it; 106 Animation& animation = *it;
106 if (time < animation.start) 107 if (time < animation.start)
107 continue; 108 continue;
108 109
109 // If |from| is not specified, start at the current values. 110 // If |from| is not specified, start at the current values.
110 if (animation.from.size() == 0) { 111 if (animation.from.size() == 0) {
111 switch (animation.property) { 112 switch (animation.property) {
112 case Animation::COPYRECT: 113 case Animation::COPYRECT:
113 animation.from.push_back(copy_rect.x); 114 animation.from.push_back(copy_rect.x);
(...skipping 29 matching lines...) Expand all
143 CHECK_EQ(animation.from.size(), animation.to.size()); 144 CHECK_EQ(animation.from.size(), animation.to.size());
144 145
145 std::vector<float> values(animation.from.size()); 146 std::vector<float> values(animation.from.size());
146 for (std::size_t i = 0; i < animation.from.size(); ++i) { 147 for (std::size_t i = 0; i < animation.from.size(); ++i) {
147 if (animation.to[i] == animation.from[i] || 148 if (animation.to[i] == animation.from[i] ||
148 time >= (animation.start + animation.duration)) { 149 time >= (animation.start + animation.duration)) {
149 values[i] = animation.to[i]; 150 values[i] = animation.to[i];
150 continue; 151 continue;
151 } 152 }
152 double value = animation.easing->CalculateValue( 153 double value = animation.easing->CalculateValue(
153 static_cast<double>(time - animation.start) / animation.duration); 154 (time - animation.start).InMillisecondsF() /
155 animation.duration.InMillisecondsF());
154 values[i] = 156 values[i] =
155 animation.from[i] + (value * (animation.to[i] - animation.from[i])); 157 animation.from[i] + (value * (animation.to[i] - animation.from[i]));
156 } 158 }
157 switch (animation.property) { 159 switch (animation.property) {
158 case Animation::COPYRECT: 160 case Animation::COPYRECT:
159 CHECK_EQ(animation.from.size(), 4u); 161 CHECK_EQ(animation.from.size(), 4u);
160 copy_rect.x = values[0]; 162 copy_rect.x = values[0];
161 copy_rect.y = values[1]; 163 copy_rect.y = values[1];
162 copy_rect.width = values[2]; 164 copy_rect.width = values[2];
163 copy_rect.height = values[3]; 165 copy_rect.height = values[3];
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 206
205 bool ContentRectangle::IsVisible() const { 207 bool ContentRectangle::IsVisible() const {
206 return visible && computed_opacity > 0.0f; 208 return visible && computed_opacity > 0.0f;
207 } 209 }
208 210
209 bool ContentRectangle::IsHitTestable() const { 211 bool ContentRectangle::IsHitTestable() const {
210 return IsVisible() && hit_testable; 212 return IsVisible() && hit_testable;
211 } 213 }
212 214
213 } // namespace vr_shell 215 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/ui_elements.h ('k') | chrome/browser/android/vr_shell/ui_elements_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698