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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/widget/widget_mac_utils.mm
diff --git a/ui/views/widget/widget_mac_utils.mm b/ui/views/widget/widget_mac_utils.mm
new file mode 100644
index 0000000000000000000000000000000000000000..1664bbe08337f11acf711e389816dfc41c48e493
--- /dev/null
+++ b/ui/views/widget/widget_mac_utils.mm
@@ -0,0 +1,53 @@
+// 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
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/views/widget/widget_mac_utils.h"
+
+#include "base/mac/foundation_util.h"
+#include "ui/views/widget/widget.h"
+
+namespace views {
+namespace {
+
+using RankMap = std::map<NSView*, int>;
+
+void RankNSViews(View* view, const AssociatedViews& hosts, RankMap* rank) {
+ auto it = hosts.find(view);
+ if (it != hosts.end())
+ rank->emplace(it->second, rank->size());
+ for (int i = 0; i < view->child_count(); ++i)
+ RankNSViews(view->child_at(i), hosts, rank);
+}
+
+NSComparisonResult SubviewSorter(id lhs, id rhs, void* rank_as_void) {
+ DCHECK_NE(lhs, rhs);
+
+ const RankMap* rank = static_cast<const RankMap*>(rank_as_void);
+ auto left_rank = rank->find(lhs);
+ auto right_rank = rank->find(rhs);
+ bool left_found = left_rank != rank->end();
+ bool right_found = right_rank != rank->end();
+
+ // Sort unassociated views below associated views.
+ if (left_found != right_found)
+ return left_found ? NSOrderedDescending : NSOrderedAscending;
+
+ if (left_found)
+ return *left_rank < *right_rank ? NSOrderedAscending : NSOrderedDescending;
+
+ // If both are unassociated, consider that order is not important
+ return NSOrderedSame;
+}
+
+} // namespace
+
+void ReorderChildNSViews(Widget* widget,
+ const AssociatedViews& associated_views) {
+ RankMap rank;
+ RankNSViews(widget->GetRootView(), associated_views, &rank);
+ [widget->GetNativeView() sortSubviewsUsingFunction:&SubviewSorter
+ context:&rank];
+}
+
+} // namespace views
« 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