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

Side by Side Diff: ui/views/view.cc

Issue 2648583003: Handle floating point coordinates from ozone to exosphere (Closed)
Patch Set: Handle floating point coordinates from ozone to exosphere Created 3 years, 11 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
« ui/aura/window.cc ('K') | « ui/views/view.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. 5 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first.
6 6
7 #include "ui/views/view.h" 7 #include "ui/views/view.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cmath> 10 #include <cmath>
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 GetWidget()->GetRootView()->GetViewsInGroup(group, &views); 701 GetWidget()->GetRootView()->GetViewsInGroup(group, &views);
702 return views.empty() ? NULL : views[0]; 702 return views.empty() ? NULL : views[0];
703 } 703 }
704 704
705 // Coordinate conversion ------------------------------------------------------- 705 // Coordinate conversion -------------------------------------------------------
706 706
707 // static 707 // static
708 void View::ConvertPointToTarget(const View* source, 708 void View::ConvertPointToTarget(const View* source,
709 const View* target, 709 const View* target,
710 gfx::Point* point) { 710 gfx::Point* point) {
711 gfx::PointF point_f(*point);
712 ConvertPointToTargetF(source, target, &point_f);
713 *point = gfx::ToFlooredPoint(point_f);
714 }
715
716 // static
717 void View::ConvertPointToTargetF(const View* source,
718 const View* target,
719 gfx::PointF* point) {
711 DCHECK(source); 720 DCHECK(source);
712 DCHECK(target); 721 DCHECK(target);
713 if (source == target) 722 if (source == target)
714 return; 723 return;
715 724
716 const View* root = GetHierarchyRoot(target); 725 const View* root = GetHierarchyRoot(target);
717 CHECK_EQ(GetHierarchyRoot(source), root); 726 CHECK_EQ(GetHierarchyRoot(source), root);
718 727
719 if (source != root) 728 if (source != root)
720 source->ConvertPointForAncestor(root, point); 729 source->ConvertPointForAncestorF(root, point);
721 730
722 if (target != root) 731 if (target != root)
723 target->ConvertPointFromAncestor(root, point); 732 target->ConvertPointFromAncestorF(root, point);
724 } 733 }
725 734
726 // static 735 // static
727 void View::ConvertRectToTarget(const View* source, 736 void View::ConvertRectToTarget(const View* source,
728 const View* target, 737 const View* target,
729 gfx::RectF* rect) { 738 gfx::RectF* rect) {
730 DCHECK(source); 739 DCHECK(source);
731 DCHECK(target); 740 DCHECK(target);
732 if (source == target) 741 if (source == target)
733 return; 742 return;
(...skipping 1405 matching lines...) Expand 10 before | Expand all | Expand 10 after
2139 p = p->parent_; 2148 p = p->parent_;
2140 } 2149 }
2141 2150
2142 return p == ancestor; 2151 return p == ancestor;
2143 } 2152 }
2144 2153
2145 // Coordinate conversion ------------------------------------------------------- 2154 // Coordinate conversion -------------------------------------------------------
2146 2155
2147 bool View::ConvertPointForAncestor(const View* ancestor, 2156 bool View::ConvertPointForAncestor(const View* ancestor,
2148 gfx::Point* point) const { 2157 gfx::Point* point) const {
2158 gfx::PointF point_f(*point);
2159 bool result = ConvertPointForAncestorF(ancestor, &point_f);
2160 *point = gfx::ToFlooredPoint(point_f);
2161 return result;
2162 }
2163
2164 bool View::ConvertPointForAncestorF(const View* ancestor,
2165 gfx::PointF* point) const {
2149 gfx::Transform trans; 2166 gfx::Transform trans;
2150 // TODO(sad): Have some way of caching the transformation results. 2167 // TODO(sad): Have some way of caching the transformation results.
2151 bool result = GetTransformRelativeTo(ancestor, &trans); 2168 bool result = GetTransformRelativeTo(ancestor, &trans);
2152 auto p = gfx::Point3F(gfx::PointF(*point)); 2169 auto p = gfx::Point3F(*point);
2153 trans.TransformPoint(&p); 2170 trans.TransformPoint(&p);
2154 *point = gfx::ToFlooredPoint(p.AsPointF()); 2171 *point = p.AsPointF();
2155 return result; 2172 return result;
2156 } 2173 }
2157 2174
2158 bool View::ConvertPointFromAncestor(const View* ancestor, 2175 bool View::ConvertPointFromAncestor(const View* ancestor,
2159 gfx::Point* point) const { 2176 gfx::Point* point) const {
2160 gfx::Transform trans; 2177 gfx::PointF point_f(*point);
2161 bool result = GetTransformRelativeTo(ancestor, &trans); 2178 bool result = ConvertPointFromAncestorF(ancestor, &point_f);
2162 auto p = gfx::Point3F(gfx::PointF(*point)); 2179 *point = gfx::ToFlooredPoint(point_f);
2163 trans.TransformPointReverse(&p);
2164 *point = gfx::ToFlooredPoint(p.AsPointF());
2165 return result; 2180 return result;
2166 } 2181 }
2167 2182
2183 bool View::ConvertPointFromAncestorF(const View* ancestor,
2184 gfx::PointF* point) const {
2185 gfx::Transform trans;
2186 bool result = GetTransformRelativeTo(ancestor, &trans);
2187 auto p = gfx::Point3F(*point);
2188 trans.TransformPointReverse(&p);
2189 *point = p.AsPointF();
2190 return result;
2191 }
2192
2168 bool View::ConvertRectForAncestor(const View* ancestor, 2193 bool View::ConvertRectForAncestor(const View* ancestor,
2169 gfx::RectF* rect) const { 2194 gfx::RectF* rect) const {
2170 gfx::Transform trans; 2195 gfx::Transform trans;
2171 // TODO(sad): Have some way of caching the transformation results. 2196 // TODO(sad): Have some way of caching the transformation results.
2172 bool result = GetTransformRelativeTo(ancestor, &trans); 2197 bool result = GetTransformRelativeTo(ancestor, &trans);
2173 trans.TransformRect(rect); 2198 trans.TransformRect(rect);
2174 return result; 2199 return result;
2175 } 2200 }
2176 2201
2177 bool View::ConvertRectFromAncestor(const View* ancestor, 2202 bool View::ConvertRectFromAncestor(const View* ancestor,
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
2546 // Message the RootView to do the drag and drop. That way if we're removed 2571 // Message the RootView to do the drag and drop. That way if we're removed
2547 // the RootView can detect it and avoid calling us back. 2572 // the RootView can detect it and avoid calling us back.
2548 gfx::Point widget_location(event.location()); 2573 gfx::Point widget_location(event.location());
2549 ConvertPointToWidget(this, &widget_location); 2574 ConvertPointToWidget(this, &widget_location);
2550 widget->RunShellDrag(this, data, widget_location, drag_operations, source); 2575 widget->RunShellDrag(this, data, widget_location, drag_operations, source);
2551 // WARNING: we may have been deleted. 2576 // WARNING: we may have been deleted.
2552 return true; 2577 return true;
2553 } 2578 }
2554 2579
2555 } // namespace views 2580 } // namespace views
OLDNEW
« ui/aura/window.cc ('K') | « ui/views/view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698