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

Side by Side Diff: views/view.cc

Issue 8620008: Get rid of Widget::ConvertPointFromAncestor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 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 | Annotate | Revision Log
« no previous file with comments | « 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "views/view.h" 5 #include "views/view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 canvas_ = canvas; 68 canvas_ = canvas;
69 canvas_->Save(); 69 canvas_->Save();
70 } 70 }
71 71
72 private: 72 private:
73 gfx::Canvas* canvas_; 73 gfx::Canvas* canvas_;
74 74
75 DISALLOW_COPY_AND_ASSIGN(ScopedCanvas); 75 DISALLOW_COPY_AND_ASSIGN(ScopedCanvas);
76 }; 76 };
77 77
78 // Returns the top view in |view|'s hierarchy.
79 const views::View* GetHierarchyRoot(const views::View* view) {
80 const views::View* root = view;
81 while (root && root->parent())
82 root = root->parent();
83 return root;
84 }
85
78 } // namespace 86 } // namespace
79 87
80 namespace views { 88 namespace views {
81 89
82 // static 90 // static
83 ViewsDelegate* ViewsDelegate::views_delegate = NULL; 91 ViewsDelegate* ViewsDelegate::views_delegate = NULL;
84 92
85 // static 93 // static
86 const char View::kViewClassName[] = "views/View"; 94 const char View::kViewClassName[] = "views/View";
87 95
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 582
575 View* View::GetSelectedViewForGroup(int group) { 583 View* View::GetSelectedViewForGroup(int group) {
576 Views views; 584 Views views;
577 GetWidget()->GetRootView()->GetViewsInGroup(group, &views); 585 GetWidget()->GetRootView()->GetViewsInGroup(group, &views);
578 return views.empty() ? NULL : views[0]; 586 return views.empty() ? NULL : views[0];
579 } 587 }
580 588
581 // Coordinate conversion ------------------------------------------------------- 589 // Coordinate conversion -------------------------------------------------------
582 590
583 // static 591 // static
584 void View::ConvertPointToView(const View* src, 592 void View::ConvertPointToView(const View* source,
585 const View* dst, 593 const View* target,
586 gfx::Point* point) { 594 gfx::Point* point) {
587 ConvertPointToView(src, dst, point, true); 595 if (source == target)
596 return;
597
598 // |source| can be NULL.
599 const View* root = GetHierarchyRoot(target);
600 if (source) {
601 CHECK_EQ(GetHierarchyRoot(source), root);
602
603 if (source != root)
604 source->ConvertPointForAncestor(root, point);
605 }
606
607 if (target != root)
608 target->ConvertPointFromAncestor(root, point);
609
610 // API defines NULL |source| as returning the point in screen coordinates.
611 if (!source) {
612 *point = point->Subtract(
613 root->GetWidget()->GetClientAreaScreenBounds().origin());
614 }
588 } 615 }
589 616
590 // static 617 // static
591 void View::ConvertPointToWidget(const View* src, gfx::Point* p) { 618 void View::ConvertPointToWidget(const View* src, gfx::Point* p) {
592 DCHECK(src); 619 DCHECK(src);
593 DCHECK(p); 620 DCHECK(p);
594 621
595 src->ConvertPointForAncestor(NULL, p); 622 src->ConvertPointForAncestor(NULL, p);
596 } 623 }
597 624
(...skipping 1100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1698 static_cast<float>(p->y())); 1725 static_cast<float>(p->y()));
1699 1726
1700 p = p->parent_; 1727 p = p->parent_;
1701 } 1728 }
1702 1729
1703 return p == ancestor; 1730 return p == ancestor;
1704 } 1731 }
1705 1732
1706 // Coordinate conversion ------------------------------------------------------- 1733 // Coordinate conversion -------------------------------------------------------
1707 1734
1708 // static
1709 void View::ConvertPointToView(const View* src,
1710 const View* dst,
1711 gfx::Point* point,
1712 bool try_other_direction) {
1713 // src can be NULL
1714 DCHECK(dst);
1715 DCHECK(point);
1716
1717 const Widget* src_widget = src ? src->GetWidget() : NULL ;
1718 const Widget* dst_widget = dst->GetWidget();
1719 // If dest and src aren't in the same widget, try to convert the
1720 // point to the destination widget's coordinates first.
1721 // TODO(oshima|sadrul): Cleanup and consolidate conversion methods.
1722 if (Widget::IsPureViews() && src_widget && src_widget != dst_widget) {
1723 // convert to src_widget first.
1724 gfx::Point p = *point;
1725 src->ConvertPointForAncestor(src_widget->GetRootView(), &p);
1726 if (dst_widget->ConvertPointFromAncestor(src_widget, &p)) {
1727 // Convertion to destination widget's coordinates was successful.
1728 // Use destination's root as a source to convert the point further.
1729 src = dst_widget->GetRootView();
1730 *point = p;
1731 }
1732 }
1733
1734 if (src == NULL || src->Contains(dst)) {
1735 dst->ConvertPointFromAncestor(src, point);
1736 if (!src) {
1737 if (dst_widget) {
1738 gfx::Rect b = dst_widget->GetClientAreaScreenBounds();
1739 point->SetPoint(point->x() - b.x(), point->y() - b.y());
1740 }
1741 }
1742 } else if (src && try_other_direction) {
1743 if (!src->ConvertPointForAncestor(dst, point)) {
1744 // |src| is not an ancestor of |dst|, and |dst| is not an ancestor of
1745 // |src| either. At this stage, |point| is in the widget's coordinate
1746 // system. So convert from the widget's to |dst|'s coordinate system now.
1747 ConvertPointFromWidget(dst, point);
1748 }
1749 }
1750 }
1751
1752 bool View::ConvertPointForAncestor(const View* ancestor, 1735 bool View::ConvertPointForAncestor(const View* ancestor,
1753 gfx::Point* point) const { 1736 gfx::Point* point) const {
1754 ui::Transform trans; 1737 ui::Transform trans;
1755 // TODO(sad): Have some way of caching the transformation results. 1738 // TODO(sad): Have some way of caching the transformation results.
1756 bool result = GetTransformRelativeTo(ancestor, &trans); 1739 bool result = GetTransformRelativeTo(ancestor, &trans);
1757 gfx::Point3f p(*point); 1740 gfx::Point3f p(*point);
1758 trans.TransformPoint(p); 1741 trans.TransformPoint(p);
1759 *point = p.AsPoint(); 1742 *point = p.AsPoint();
1760 return result; 1743 return result;
1761 } 1744 }
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
2069 2052
2070 OSExchangeData data; 2053 OSExchangeData data;
2071 WriteDragData(press_pt, &data); 2054 WriteDragData(press_pt, &data);
2072 2055
2073 // Message the RootView to do the drag and drop. That way if we're removed 2056 // Message the RootView to do the drag and drop. That way if we're removed
2074 // the RootView can detect it and avoid calling us back. 2057 // the RootView can detect it and avoid calling us back.
2075 GetWidget()->RunShellDrag(this, data, drag_operations); 2058 GetWidget()->RunShellDrag(this, data, drag_operations);
2076 } 2059 }
2077 2060
2078 } // namespace views 2061 } // namespace views
OLDNEW
« no previous file with comments | « views/view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698