Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
|
tapted
2016/03/17 08:18:59
Can this entire file just be moved into the anonym
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/views/widget/widget_mac_utils.h" | |
| 6 | |
| 7 #include "base/mac/foundation_util.h" | |
| 8 #include "ui/views/widget/widget.h" | |
| 9 | |
| 10 namespace views { | |
| 11 namespace { | |
| 12 | |
| 13 using RankMap = std::map<NSView*, int>; | |
| 14 | |
| 15 void RankNSViews(View* view, const AssociatedViews& hosts, RankMap* rank) { | |
| 16 auto it = hosts.find(view); | |
| 17 if (it != hosts.end()) | |
| 18 rank->emplace(it->second, rank->size()); | |
| 19 for (int i = 0; i < view->child_count(); ++i) | |
| 20 RankNSViews(view->child_at(i), hosts, rank); | |
| 21 } | |
| 22 | |
| 23 NSComparisonResult SubviewSorter(id lhs, id rhs, void* rank_as_void) { | |
| 24 DCHECK_NE(lhs, rhs); | |
| 25 | |
| 26 const RankMap* rank = static_cast<const RankMap*>(rank_as_void); | |
| 27 auto left_rank = rank->find(lhs); | |
| 28 auto right_rank = rank->find(rhs); | |
| 29 bool left_found = left_rank != rank->end(); | |
| 30 bool right_found = right_rank != rank->end(); | |
| 31 | |
| 32 // Sort unassociated views below associated views. | |
| 33 if (left_found != right_found) | |
| 34 return left_found ? NSOrderedDescending : NSOrderedAscending; | |
| 35 | |
| 36 if (left_found) | |
| 37 return *left_rank < *right_rank ? NSOrderedAscending : NSOrderedDescending; | |
| 38 | |
| 39 // If both are unassociated, consider that order is not important | |
| 40 return NSOrderedSame; | |
| 41 } | |
| 42 | |
| 43 } // namespace | |
| 44 | |
| 45 void ReorderChildNSViews(Widget* widget, | |
| 46 const AssociatedViews& associated_views) { | |
| 47 RankMap rank; | |
| 48 RankNSViews(widget->GetRootView(), associated_views, &rank); | |
| 49 [widget->GetNativeView() sortSubviewsUsingFunction:&SubviewSorter | |
| 50 context:&rank]; | |
| 51 } | |
| 52 | |
| 53 } // namespace views | |
| OLD | NEW |