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

Side by Side Diff: ui/views/widget/widget_mac_utils.mm

Issue 1796773003: Implement NativeWidgetMac::ReorderNativeViews (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Using NativeViewHost*->NSView* map. Created 4 years, 9 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
OLDNEW
(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
OLDNEW
« ui/views/widget/native_widget_mac_unittest.mm ('K') | « ui/views/widget/widget_mac_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698