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

Side by Side Diff: cc/math_util.cc

Issue 12280014: cc: Don't consider HUD layer for touches (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: moved funcs around Created 7 years, 10 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 | Annotate | Revision Log
« cc/layer_tree_host_impl.cc ('K') | « cc/math_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 "cc/math_util.h" 5 #include "cc/math_util.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 dotProduct = std::max(-1.0, std::min(1.0, dotProduct)); 379 dotProduct = std::max(-1.0, std::min(1.0, dotProduct));
380 return static_cast<float>(Rad2Deg(std::acos(dotProduct))); 380 return static_cast<float>(Rad2Deg(std::acos(dotProduct)));
381 } 381 }
382 382
383 gfx::Vector2dF MathUtil::projectVector(gfx::Vector2dF source, gfx::Vector2dF des tination) 383 gfx::Vector2dF MathUtil::projectVector(gfx::Vector2dF source, gfx::Vector2dF des tination)
384 { 384 {
385 float projectedLength = gfx::DotProduct(source, destination) / destination.L engthSquared(); 385 float projectedLength = gfx::DotProduct(source, destination) / destination.L engthSquared();
386 return gfx::Vector2dF(projectedLength * destination.x(), projectedLength * d estination.y()); 386 return gfx::Vector2dF(projectedLength * destination.x(), projectedLength * d estination.y());
387 } 387 }
388 388
389 bool MathUtil::pointHitsRect(const gfx::PointF& screenSpacePoint,
390 const gfx::Transform& localSpaceToScreenSpaceTransf orm,
391 gfx::RectF localSpaceRect)
392 {
393 // If the transform is not invertible, then assume that this point doesn't h it this rect.
394 gfx::Transform inverseLocalSpaceToScreenSpace(gfx::Transform::kSkipInitializ ation);
395 if (!localSpaceToScreenSpaceTransform.GetInverse(&inverseLocalSpaceToScreenS pace))
396 return false;
397
398 // Transform the hit test point from screen space to the local space of the given rect.
399 bool clipped = false;
400 gfx::PointF hitTestPointInLocalSpace = projectPoint(inverseLocalSpaceToScree nSpace, screenSpacePoint, clipped);
401
402 // If projectPoint could not project to a valid value, then we assume that t his point doesn't hit this rect.
403 if (clipped)
404 return false;
405
406 return localSpaceRect.Contains(hitTestPointInLocalSpace);
407 }
408
389 scoped_ptr<base::Value> MathUtil::asValue(gfx::Size s) { 409 scoped_ptr<base::Value> MathUtil::asValue(gfx::Size s) {
390 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); 410 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue());
391 res->SetDouble("width", s.width()); 411 res->SetDouble("width", s.width());
392 res->SetDouble("height", s.height()); 412 res->SetDouble("height", s.height());
393 return res.PassAs<base::Value>(); 413 return res.PassAs<base::Value>();
394 } 414 }
395 415
396 scoped_ptr<base::Value> MathUtil::asValue(gfx::PointF pt) { 416 scoped_ptr<base::Value> MathUtil::asValue(gfx::PointF pt) {
397 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); 417 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue());
398 res->SetDouble("x", pt.x()); 418 res->SetDouble("x", pt.x());
(...skipping 14 matching lines...) Expand all
413 return scoped_ptr<base::Value>(base::Value::CreateDoubleValue( 433 return scoped_ptr<base::Value>(base::Value::CreateDoubleValue(
414 std::min(value, std::numeric_limits<double>::max()))); 434 std::min(value, std::numeric_limits<double>::max())));
415 } 435 }
416 436
417 scoped_ptr<base::Value> MathUtil::asValueSafely(float value) { 437 scoped_ptr<base::Value> MathUtil::asValueSafely(float value) {
418 return scoped_ptr<base::Value>(base::Value::CreateDoubleValue( 438 return scoped_ptr<base::Value>(base::Value::CreateDoubleValue(
419 std::min(value, std::numeric_limits<float>::max()))); 439 std::min(value, std::numeric_limits<float>::max())));
420 } 440 }
421 441
422 } // namespace cc 442 } // namespace cc
OLDNEW
« cc/layer_tree_host_impl.cc ('K') | « cc/math_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698