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

Unified Diff: ui/views/cocoa/bridged_native_widget.mm

Issue 1796773003: Implement NativeWidgetMac::ReorderNativeViews (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits and xcode 7 compilation. 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
« no previous file with comments | « ui/views/cocoa/bridged_native_widget.h ('k') | ui/views/controls/native/native_view_host_mac.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/cocoa/bridged_native_widget.mm
diff --git a/ui/views/cocoa/bridged_native_widget.mm b/ui/views/cocoa/bridged_native_widget.mm
index 6f5dec0f96864ede56c8a7cf940de5ebf964aa92..ecaffa1ad826153c41c333c2000af58ac221c3d4 100644
--- a/ui/views/cocoa/bridged_native_widget.mm
+++ b/ui/views/cocoa/bridged_native_widget.mm
@@ -83,6 +83,18 @@ CGError CGSSetWindowBackgroundBlurRadius(CGSConnection connection,
namespace {
+using RankMap = std::map<NSView*, int>;
+
+// SDK 10.11 contains incompatible changes of sortSubviewsUsingFunction.
+// It takes (__kindof NSView*) as comparator argument.
+// https://llvm.org/bugs/show_bug.cgi?id=25149
+#if !defined(MAC_OS_X_VERSION_10_11) || \
+ MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_11
+using NSViewComparatorValue = id;
+#else
+using NSViewComparatorValue = __kindof NSView*;
+#endif
+
const CGFloat kMavericksMenuOpacity = 251.0 / 255.0;
const CGFloat kYosemiteMenuOpacity = 194.0 / 255.0;
const int kYosemiteMenuBlur = 80;
@@ -263,6 +275,40 @@ scoped_refptr<base::SingleThreadTaskRunner> GetCompositorTaskRunner() {
return task_runner ? task_runner : base::ThreadTaskRunnerHandle::Get();
}
+void RankNSViews(views::View* view,
+ const views::BridgedNativeWidget::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(NSViewComparatorValue lhs,
+ NSViewComparatorValue 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 above associated views.
+ if (left_found != right_found)
+ return left_found ? NSOrderedAscending : NSOrderedDescending;
+
+ if (left_found) {
+ return left_rank->second < right_rank->second ? NSOrderedAscending
+ : NSOrderedDescending;
+ }
+
+ // If both are unassociated, consider that order is not important
+ return NSOrderedSame;
+}
+
} // namespace
namespace views {
@@ -884,6 +930,31 @@ void BridgedNativeWidget::CreateLayer(ui::LayerType layer_type,
UpdateLayerProperties();
}
+void BridgedNativeWidget::SetAssociationForView(const views::View* view,
+ NSView* native_view) {
+ DCHECK_EQ(0u, associated_views_.count(view));
+ associated_views_[view] = native_view;
+ native_widget_mac_->GetWidget()->ReorderNativeViews();
+}
+
+void BridgedNativeWidget::ClearAssociationForView(const views::View* view) {
+ auto it = associated_views_.find(view);
+ DCHECK(it != associated_views_.end());
+ associated_views_.erase(it);
+}
+
+void BridgedNativeWidget::ReorderChildViews() {
+ RankMap rank;
+ Widget* widget = native_widget_mac_->GetWidget();
+ RankNSViews(widget->GetRootView(), associated_views_, &rank);
+ // Unassociated NSViews should be ordered above associated ones. The exception
+ // is the UI compositor's superview, which should always be on the very
+ // bottom, so give it an explicit negative rank.
+ if (compositor_superview_)
+ rank[compositor_superview_] = -1;
+ [bridged_view_ sortSubviewsUsingFunction:&SubviewSorter context:&rank];
+}
+
////////////////////////////////////////////////////////////////////////////////
// BridgedNativeWidget, internal::InputMethodDelegate:
« no previous file with comments | « ui/views/cocoa/bridged_native_widget.h ('k') | ui/views/controls/native/native_view_host_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698