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

Side by Side Diff: Source/core/platform/animation/TimingFunction.h

Issue 57563002: Adding operator== for ChainedTimingFunction (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Remove EQ reflectivity fix. Created 7 years, 1 month 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
« no previous file with comments | « no previous file | Source/core/platform/animation/TimingFunctionTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Antti Koivisto (koivisto@kde.org) 3 * (C) 2000 Antti Koivisto (koivisto@kde.org)
4 * (C) 2000 Dirk Mueller (mueller@kde.org) 4 * (C) 2000 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2003, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 5 * Copyright (C) 2003, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
6 * Copyright (C) 2006 Graham Dennis (graham.dennis@gmail.com) 6 * Copyright (C) 2006 Graham Dennis (graham.dennis@gmail.com)
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 size_t i = 0; 284 size_t i = 0;
285 const Segment* segment = &m_segments[i++]; 285 const Segment* segment = &m_segments[i++];
286 while (fraction >= segment->max() && i < m_segments.size()) { 286 while (fraction >= segment->max() && i < m_segments.size()) {
287 segment = &m_segments[i++]; 287 segment = &m_segments[i++];
288 } 288 }
289 return segment->evaluate(fraction, accuracy); 289 return segment->evaluate(fraction, accuracy);
290 } 290 }
291 291
292 virtual bool operator==(const TimingFunction& other) const 292 virtual bool operator==(const TimingFunction& other) const
293 { 293 {
294 // This class is not exposed to CSS, so this method is not required. 294 if (other.type() != ChainedFunction)
295 ASSERT_NOT_REACHED(); 295 return false;
296 return false; 296
297 if (this == &other)
298 return true;
299
300 const ChainedTimingFunction* ctf = static_cast<const ChainedTimingFuncti on*>(&other);
301 if (ctf->m_segments.size() != m_segments.size())
302 return false;
303
304 for (size_t i = 0; i < m_segments.size(); i++) {
305 if (m_segments[i] != ctf->m_segments[i])
306 return false;
307 }
308 return true;
297 } 309 }
298 310
299 private: 311 private:
300 class Segment { 312 class Segment {
301 public: 313 public:
302 Segment(double min, double max, TimingFunction* timingFunction) 314 Segment(double min, double max, TimingFunction* timingFunction)
303 : m_min(min) 315 : m_min(min)
304 , m_max(max) 316 , m_max(max)
305 , m_timingFunction(timingFunction) 317 , m_timingFunction(timingFunction)
306 { } 318 { }
307 319
308 double max() const { return m_max; } 320 double max() const { return m_max; }
309 double evaluate(double fraction, double accuracy) const 321 double evaluate(double fraction, double accuracy) const
310 { 322 {
311 return scaleFromLocal(m_timingFunction->evaluate(scaleToLocal(fracti on), accuracy)); 323 return scaleFromLocal(m_timingFunction->evaluate(scaleToLocal(fracti on), accuracy));
312 } 324 }
313 325
326 bool operator==(const Segment& other) const
327 {
328 if (this == &other)
329 return true;
330
331 bool minMaxEq = m_min == other.m_min && m_max == other.m_max;
332 if (!minMaxEq)
333 return false;
334
335 if (m_timingFunction == other.m_timingFunction)
336 return true;
337
338 if (!m_timingFunction || !other.m_timingFunction)
339 return false;
340
341 return (*m_timingFunction.get()) == (*other.m_timingFunction.get());
342 }
343 bool operator!=(const Segment& other) const
344 {
345 return !operator==(other);
346 }
314 private: 347 private:
315 double scaleToLocal(double x) const { return (x - m_min) / (m_max - m_mi n); } 348 double scaleToLocal(double x) const { return (x - m_min) / (m_max - m_mi n); }
316 double scaleFromLocal(double x) const { return blend(m_min, m_max, x); } 349 double scaleFromLocal(double x) const { return blend(m_min, m_max, x); }
317 350
318 double m_min; 351 double m_min;
319 double m_max; 352 double m_max;
320 RefPtr<TimingFunction> m_timingFunction; 353 RefPtr<TimingFunction> m_timingFunction;
321 354
322 // Allow printing of our segments. Can be removed once 355 // Allow printing of our segments. Can be removed once
323 // ChainedTimingFunction has a public API for segments. 356 // ChainedTimingFunction has a public API for segments.
324 friend class ChainedTimingFunctionPrintTo; 357 friend class ChainedTimingFunctionPrintTo;
325 }; 358 };
326 359
327 ChainedTimingFunction() 360 ChainedTimingFunction()
328 : TimingFunction(ChainedFunction) 361 : TimingFunction(ChainedFunction)
329 { 362 {
330 ASSERT(RuntimeEnabledFeatures::webAnimationsEnabled()); 363 ASSERT(RuntimeEnabledFeatures::webAnimationsEnabled());
331 } 364 }
332 365
333 Vector<Segment> m_segments; 366 Vector<Segment> m_segments;
334 367
335 // Allow printing of our segments. Can be removed once 368 // Allow printing of our segments. Can be removed once
336 // ChainedTimingFunction has a public API for segments. 369 // ChainedTimingFunction has a public API for segments.
337 friend class ChainedTimingFunctionPrintTo; 370 friend class ChainedTimingFunctionPrintTo;
338 }; 371 };
339 372
340 } // namespace WebCore 373 } // namespace WebCore
341 374
342 #endif // TimingFunction_h 375 #endif // TimingFunction_h
OLDNEW
« no previous file with comments | « no previous file | Source/core/platform/animation/TimingFunctionTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698