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

Side by Side Diff: services/view_manager/scheduled_animation_group.cc

Issue 1375313006: For c++, Generate enum classes instead of enum from mojom. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 2 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "services/view_manager/scheduled_animation_group.h" 5 #include "services/view_manager/scheduled_animation_group.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "mojo/converters/geometry/geometry_type_converters.h" 9 #include "mojo/converters/geometry/geometry_type_converters.h"
10 #include "services/view_manager/server_view.h" 10 #include "services/view_manager/server_view.h"
11 11
12 using mojo::ANIMATION_PROPERTY_NONE;
13 using mojo::ANIMATION_PROPERTY_OPACITY;
14 using mojo::ANIMATION_PROPERTY_TRANSFORM;
15 using mojo::AnimationProperty; 12 using mojo::AnimationProperty;
16 13
17 namespace view_manager { 14 namespace view_manager {
18 namespace { 15 namespace {
19 16
20 using Sequences = std::vector<ScheduledAnimationSequence>; 17 using Sequences = std::vector<ScheduledAnimationSequence>;
21 18
22 // Gets the value of |property| from |view| into |value|. 19 // Gets the value of |property| from |view| into |value|.
23 void GetValueFromView(const ServerView* view, 20 void GetValueFromView(const ServerView* view,
24 AnimationProperty property, 21 AnimationProperty property,
25 ScheduledAnimationValue* value) { 22 ScheduledAnimationValue* value) {
26 switch (property) { 23 switch (property) {
27 case ANIMATION_PROPERTY_NONE: 24 case AnimationProperty::NONE:
28 NOTREACHED(); 25 NOTREACHED();
29 break; 26 break;
30 case ANIMATION_PROPERTY_OPACITY: 27 case AnimationProperty::OPACITY:
31 value->float_value = view->opacity(); 28 value->float_value = view->opacity();
32 break; 29 break;
33 case ANIMATION_PROPERTY_TRANSFORM: 30 case AnimationProperty::TRANSFORM:
34 value->transform = view->transform(); 31 value->transform = view->transform();
35 break; 32 break;
36 } 33 }
37 } 34 }
38 35
39 // Sets the value of |property| from |value| into |view|. 36 // Sets the value of |property| from |value| into |view|.
40 void SetViewPropertyFromValue(ServerView* view, 37 void SetViewPropertyFromValue(ServerView* view,
41 AnimationProperty property, 38 AnimationProperty property,
42 const ScheduledAnimationValue& value) { 39 const ScheduledAnimationValue& value) {
43 switch (property) { 40 switch (property) {
44 case ANIMATION_PROPERTY_NONE: 41 case AnimationProperty::NONE:
45 break; 42 break;
46 case ANIMATION_PROPERTY_OPACITY: 43 case AnimationProperty::OPACITY:
47 view->SetOpacity(value.float_value); 44 view->SetOpacity(value.float_value);
48 break; 45 break;
49 case ANIMATION_PROPERTY_TRANSFORM: 46 case AnimationProperty::TRANSFORM:
50 view->SetTransform(value.transform); 47 view->SetTransform(value.transform);
51 break; 48 break;
52 } 49 }
53 } 50 }
54 51
55 // Sets the value of |property| into |view| between two points. 52 // Sets the value of |property| into |view| between two points.
56 void SetViewPropertyFromValueBetween(ServerView* view, 53 void SetViewPropertyFromValueBetween(ServerView* view,
57 AnimationProperty property, 54 AnimationProperty property,
58 double value, 55 double value,
59 gfx::Tween::Type tween_type, 56 gfx::Tween::Type tween_type,
60 const ScheduledAnimationValue& start, 57 const ScheduledAnimationValue& start,
61 const ScheduledAnimationValue& target) { 58 const ScheduledAnimationValue& target) {
62 const double tween_value = gfx::Tween::CalculateValue(tween_type, value); 59 const double tween_value = gfx::Tween::CalculateValue(tween_type, value);
63 switch (property) { 60 switch (property) {
64 case ANIMATION_PROPERTY_NONE: 61 case AnimationProperty::NONE:
65 break; 62 break;
66 case ANIMATION_PROPERTY_OPACITY: 63 case AnimationProperty::OPACITY:
67 view->SetOpacity(gfx::Tween::FloatValueBetween( 64 view->SetOpacity(gfx::Tween::FloatValueBetween(
68 tween_value, start.float_value, target.float_value)); 65 tween_value, start.float_value, target.float_value));
69 break; 66 break;
70 case ANIMATION_PROPERTY_TRANSFORM: 67 case AnimationProperty::TRANSFORM:
71 view->SetTransform(gfx::Tween::TransformValueBetween( 68 view->SetTransform(gfx::Tween::TransformValueBetween(
72 tween_value, start.transform, target.transform)); 69 tween_value, start.transform, target.transform));
73 break; 70 break;
74 } 71 }
75 } 72 }
76 73
77 gfx::Tween::Type AnimationTypeToTweenType(mojo::AnimationTweenType type) { 74 gfx::Tween::Type AnimationTypeToTweenType(mojo::AnimationTweenType type) {
78 switch (type) { 75 switch (type) {
79 case mojo::ANIMATION_TWEEN_TYPE_LINEAR: 76 case mojo::AnimationTweenType::LINEAR:
80 return gfx::Tween::LINEAR; 77 return gfx::Tween::LINEAR;
81 case mojo::ANIMATION_TWEEN_TYPE_EASE_IN: 78 case mojo::AnimationTweenType::EASE_IN:
82 return gfx::Tween::EASE_IN; 79 return gfx::Tween::EASE_IN;
83 case mojo::ANIMATION_TWEEN_TYPE_EASE_OUT: 80 case mojo::AnimationTweenType::EASE_OUT:
84 return gfx::Tween::EASE_OUT; 81 return gfx::Tween::EASE_OUT;
85 case mojo::ANIMATION_TWEEN_TYPE_EASE_IN_OUT: 82 case mojo::AnimationTweenType::EASE_IN_OUT:
86 return gfx::Tween::EASE_IN_OUT; 83 return gfx::Tween::EASE_IN_OUT;
87 } 84 }
88 return gfx::Tween::LINEAR; 85 return gfx::Tween::LINEAR;
89 } 86 }
90 87
91 void ConvertToScheduledValue(const mojo::AnimationValue& transport_value, 88 void ConvertToScheduledValue(const mojo::AnimationValue& transport_value,
92 ScheduledAnimationValue* value) { 89 ScheduledAnimationValue* value) {
93 value->float_value = transport_value.float_value; 90 value->float_value = transport_value.float_value;
94 value->transform = transport_value.transform.To<gfx::Transform>(); 91 value->transform = transport_value.transform.To<gfx::Transform>();
95 } 92 }
96 93
97 void ConvertToScheduledElement(const mojo::AnimationElement& transport_element, 94 void ConvertToScheduledElement(const mojo::AnimationElement& transport_element,
98 ScheduledAnimationElement* element) { 95 ScheduledAnimationElement* element) {
99 element->property = transport_element.property; 96 element->property = transport_element.property;
100 element->duration = 97 element->duration =
101 base::TimeDelta::FromMicroseconds(transport_element.duration); 98 base::TimeDelta::FromMicroseconds(transport_element.duration);
102 element->tween_type = AnimationTypeToTweenType(transport_element.tween_type); 99 element->tween_type = AnimationTypeToTweenType(transport_element.tween_type);
103 if (transport_element.property != ANIMATION_PROPERTY_NONE) { 100 if (transport_element.property != AnimationProperty::NONE) {
104 if (transport_element.start_value.get()) { 101 if (transport_element.start_value.get()) {
105 element->is_start_valid = true; 102 element->is_start_valid = true;
106 ConvertToScheduledValue(*transport_element.start_value, 103 ConvertToScheduledValue(*transport_element.start_value,
107 &(element->start_value)); 104 &(element->start_value));
108 } else { 105 } else {
109 element->is_start_valid = false; 106 element->is_start_valid = false;
110 } 107 }
111 ConvertToScheduledValue(*transport_element.target_value, 108 ConvertToScheduledValue(*transport_element.target_value,
112 &(element->target_value)); 109 &(element->target_value));
113 } 110 }
114 } 111 }
115 112
116 bool IsAnimationValueValid(AnimationProperty property, 113 bool IsAnimationValueValid(AnimationProperty property,
117 const mojo::AnimationValue& value) { 114 const mojo::AnimationValue& value) {
118 switch (property) { 115 switch (property) {
119 case ANIMATION_PROPERTY_NONE: 116 case AnimationProperty::NONE:
120 NOTREACHED(); 117 NOTREACHED();
121 return false; 118 return false;
122 case ANIMATION_PROPERTY_OPACITY: 119 case AnimationProperty::OPACITY:
123 return value.float_value >= 0.f && value.float_value <= 1.f; 120 return value.float_value >= 0.f && value.float_value <= 1.f;
124 case ANIMATION_PROPERTY_TRANSFORM: 121 case AnimationProperty::TRANSFORM:
125 return value.transform.get() && value.transform->matrix.size() == 16u; 122 return value.transform.get() && value.transform->matrix.size() == 16u;
126 } 123 }
127 return false; 124 return false;
128 } 125 }
129 126
130 bool IsAnimationElementValid(const mojo::AnimationElement& element) { 127 bool IsAnimationElementValid(const mojo::AnimationElement& element) {
131 if (element.property == ANIMATION_PROPERTY_NONE) 128 if (element.property == AnimationProperty::NONE)
132 return true; // None is a pause and doesn't need any values. 129 return true; // None is a pause and doesn't need any values.
133 if (element.start_value.get() && 130 if (element.start_value.get() &&
134 !IsAnimationValueValid(element.property, *element.start_value)) 131 !IsAnimationValueValid(element.property, *element.start_value))
135 return false; 132 return false;
136 // For all other properties we require a target. 133 // For all other properties we require a target.
137 return element.target_value.get() && 134 return element.target_value.get() &&
138 IsAnimationValueValid(element.property, *element.target_value); 135 IsAnimationValueValid(element.property, *element.target_value);
139 } 136 }
140 137
141 bool IsAnimationSequenceValid(const mojo::AnimationSequence& sequence) { 138 bool IsAnimationSequenceValid(const mojo::AnimationSequence& sequence) {
(...skipping 14 matching lines...) Expand all
156 if (!IsAnimationSequenceValid(*transport_group.sequences[i])) 153 if (!IsAnimationSequenceValid(*transport_group.sequences[i]))
157 return false; 154 return false;
158 } 155 }
159 return true; 156 return true;
160 } 157 }
161 158
162 // If the start value for |element| isn't valid, the value for the property 159 // If the start value for |element| isn't valid, the value for the property
163 // is obtained from |view| and placed into |element|. 160 // is obtained from |view| and placed into |element|.
164 void GetStartValueFromViewIfNecessary(const ServerView* view, 161 void GetStartValueFromViewIfNecessary(const ServerView* view,
165 ScheduledAnimationElement* element) { 162 ScheduledAnimationElement* element) {
166 if (element->property != ANIMATION_PROPERTY_NONE && 163 if (element->property != AnimationProperty::NONE &&
167 !element->is_start_valid) { 164 !element->is_start_valid) {
168 GetValueFromView(view, element->property, &(element->start_value)); 165 GetValueFromView(view, element->property, &(element->start_value));
169 } 166 }
170 } 167 }
171 168
172 void GetScheduledAnimationProperties(const Sequences& sequences, 169 void GetScheduledAnimationProperties(const Sequences& sequences,
173 std::set<AnimationProperty>* properties) { 170 std::set<AnimationProperty>* properties) {
174 for (const ScheduledAnimationSequence& sequence : sequences) { 171 for (const ScheduledAnimationSequence& sequence : sequences) {
175 for (const ScheduledAnimationElement& element : sequence.elements) 172 for (const ScheduledAnimationElement& element : sequence.elements)
176 properties->insert(element.property); 173 properties->insert(element.property);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 } 255 }
259 256
260 } // namespace 257 } // namespace
261 258
262 ScheduledAnimationValue::ScheduledAnimationValue() { 259 ScheduledAnimationValue::ScheduledAnimationValue() {
263 } 260 }
264 ScheduledAnimationValue::~ScheduledAnimationValue() { 261 ScheduledAnimationValue::~ScheduledAnimationValue() {
265 } 262 }
266 263
267 ScheduledAnimationElement::ScheduledAnimationElement() 264 ScheduledAnimationElement::ScheduledAnimationElement()
268 : property(ANIMATION_PROPERTY_OPACITY), 265 : property(AnimationProperty::OPACITY),
269 tween_type(gfx::Tween::EASE_IN), 266 tween_type(gfx::Tween::EASE_IN),
270 is_start_valid(false) { 267 is_start_valid(false) {
271 } 268 }
272 ScheduledAnimationElement::~ScheduledAnimationElement() { 269 ScheduledAnimationElement::~ScheduledAnimationElement() {
273 } 270 }
274 271
275 ScheduledAnimationSequence::ScheduledAnimationSequence() 272 ScheduledAnimationSequence::ScheduledAnimationSequence()
276 : run_until_stopped(false), cycle_count(0), current_index(0u) { 273 : run_until_stopped(false), cycle_count(0), current_index(0u) {
277 } 274 }
278 ScheduledAnimationSequence::~ScheduledAnimationSequence() { 275 ScheduledAnimationSequence::~ScheduledAnimationSequence() {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 void ScheduledAnimationGroup::SetValuesToTargetValuesForPropertiesNotIn( 307 void ScheduledAnimationGroup::SetValuesToTargetValuesForPropertiesNotIn(
311 const ScheduledAnimationGroup& other) { 308 const ScheduledAnimationGroup& other) {
312 std::set<AnimationProperty> our_properties; 309 std::set<AnimationProperty> our_properties;
313 GetScheduledAnimationProperties(sequences_, &our_properties); 310 GetScheduledAnimationProperties(sequences_, &our_properties);
314 311
315 std::set<AnimationProperty> other_properties; 312 std::set<AnimationProperty> other_properties;
316 GetScheduledAnimationProperties(other.sequences_, &other_properties); 313 GetScheduledAnimationProperties(other.sequences_, &other_properties);
317 314
318 for (AnimationProperty property : our_properties) { 315 for (AnimationProperty property : our_properties) {
319 if (other_properties.count(property) == 0 && 316 if (other_properties.count(property) == 0 &&
320 property != ANIMATION_PROPERTY_NONE) { 317 property != AnimationProperty::NONE) {
321 SetPropertyToTargetProperty(view_, property, sequences_); 318 SetPropertyToTargetProperty(view_, property, sequences_);
322 } 319 }
323 } 320 }
324 } 321 }
325 322
326 bool ScheduledAnimationGroup::Tick(base::TimeTicks time) { 323 bool ScheduledAnimationGroup::Tick(base::TimeTicks time) {
327 for (Sequences::iterator i = sequences_.begin(); i != sequences_.end();) { 324 for (Sequences::iterator i = sequences_.begin(); i != sequences_.end();) {
328 if (!AdvanceSequence(view_, &(*i), time)) { 325 if (!AdvanceSequence(view_, &(*i), time)) {
329 i = sequences_.erase(i); 326 i = sequences_.erase(i);
330 continue; 327 continue;
(...skipping 11 matching lines...) Expand all
342 return sequences_.empty(); 339 return sequences_.empty();
343 } 340 }
344 341
345 ScheduledAnimationGroup::ScheduledAnimationGroup(ServerView* view, 342 ScheduledAnimationGroup::ScheduledAnimationGroup(ServerView* view,
346 uint32_t id, 343 uint32_t id,
347 base::TimeTicks time_scheduled) 344 base::TimeTicks time_scheduled)
348 : view_(view), id_(id), time_scheduled_(time_scheduled) { 345 : view_(view), id_(id), time_scheduled_(time_scheduled) {
349 } 346 }
350 347
351 } // namespace view_manager 348 } // namespace view_manager
OLDNEW
« no previous file with comments | « services/view_manager/gesture_manager_unittest.cc ('k') | services/view_manager/scheduled_animation_group_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698