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

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: Added DISALLOW_COPY_AND_ASSIGN 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/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..cf2cc00edd6eae412b48f7c403fc52866fc0ecbb 100644
--- a/ui/views/cocoa/bridged_native_widget.mm
+++ b/ui/views/cocoa/bridged_native_widget.mm
@@ -83,6 +83,8 @@ CGError CGSSetWindowBackgroundBlurRadius(CGSConnection connection,
namespace {
+using RankMap = std::map<NSView*, int>;
+
const CGFloat kMavericksMenuOpacity = 251.0 / 255.0;
const CGFloat kYosemiteMenuOpacity = 194.0 / 255.0;
const int kYosemiteMenuBlur = 80;
@@ -263,6 +265,38 @@ 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(id lhs, id rhs, void* rank_as_void) {
tapted 2016/03/17 23:51:27 Make sure you do a build with xcode 7 too. I had t
+ 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 +918,30 @@ 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);
+ // Set compositor view below
tapted 2016/03/17 23:04:15 Yep - this makes sense, but the comment should exp
+ if (compositor_superview_)
+ rank[compositor_superview_.get()] = -1;
tapted 2016/03/17 23:04:15 The .get() shouldn't be required -- scoped_nsobjec
+ [widget->GetNativeView() sortSubviewsUsingFunction:&SubviewSorter
tapted 2016/03/17 23:04:15 widget->GetNativeView() --> bridged_view_
+ context:&rank];
+}
+
////////////////////////////////////////////////////////////////////////////////
// BridgedNativeWidget, internal::InputMethodDelegate:

Powered by Google App Engine
This is Rietveld 408576698