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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ui/views/cocoa/bridged_native_widget.h" 5 #import "ui/views/cocoa/bridged_native_widget.h"
6 6
7 #import <objc/runtime.h> 7 #import <objc/runtime.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 [window_ invalidateShadow]; 76 [window_ invalidateShadow];
77 } 77 }
78 - (void)setCurrentProgress:(NSAnimationProgress)progress { 78 - (void)setCurrentProgress:(NSAnimationProgress)progress {
79 [super setCurrentProgress:progress]; 79 [super setCurrentProgress:progress];
80 [window_ invalidateShadow]; 80 [window_ invalidateShadow];
81 } 81 }
82 @end 82 @end
83 83
84 namespace { 84 namespace {
85 85
86 using RankMap = std::map<NSView*, int>;
87
88 // SDK 10.11 contains incompatible changes of sortSubviewsUsingFunction.
89 // It takes (__kindof NSView*) as comparator argument.
90 // https://llvm.org/bugs/show_bug.cgi?id=25149
91 #if !defined(MAC_OS_X_VERSION_10_11) || \
92 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_11
93 using NSViewComparatorValue = id;
94 #else
95 using NSViewComparatorValue = __kindof NSView*;
96 #endif
97
86 const CGFloat kMavericksMenuOpacity = 251.0 / 255.0; 98 const CGFloat kMavericksMenuOpacity = 251.0 / 255.0;
87 const CGFloat kYosemiteMenuOpacity = 194.0 / 255.0; 99 const CGFloat kYosemiteMenuOpacity = 194.0 / 255.0;
88 const int kYosemiteMenuBlur = 80; 100 const int kYosemiteMenuBlur = 80;
89 101
90 // Margin at edge and corners of the window that trigger resizing. These match 102 // Margin at edge and corners of the window that trigger resizing. These match
91 // actual Cocoa resize margins. 103 // actual Cocoa resize margins.
92 const int kResizeAreaEdgeSize = 3; 104 const int kResizeAreaEdgeSize = 3;
93 const int kResizeAreaCornerSize = 12; 105 const int kResizeAreaCornerSize = 12;
94 106
95 int kWindowPropertiesKey; 107 int kWindowPropertiesKey;
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 // resize operations to coordinate with frames provided by the GPU process. 268 // resize operations to coordinate with frames provided by the GPU process.
257 scoped_refptr<base::SingleThreadTaskRunner> GetCompositorTaskRunner() { 269 scoped_refptr<base::SingleThreadTaskRunner> GetCompositorTaskRunner() {
258 // If the WindowResizeHelper's pumpable task runner is set, it means the GPU 270 // If the WindowResizeHelper's pumpable task runner is set, it means the GPU
259 // process is directing messages there, and the compositor can synchronize 271 // process is directing messages there, and the compositor can synchronize
260 // with it. Otherwise, just use the UI thread. 272 // with it. Otherwise, just use the UI thread.
261 scoped_refptr<base::SingleThreadTaskRunner> task_runner = 273 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
262 ui::WindowResizeHelperMac::Get()->task_runner(); 274 ui::WindowResizeHelperMac::Get()->task_runner();
263 return task_runner ? task_runner : base::ThreadTaskRunnerHandle::Get(); 275 return task_runner ? task_runner : base::ThreadTaskRunnerHandle::Get();
264 } 276 }
265 277
278 void RankNSViews(views::View* view,
279 const views::BridgedNativeWidget::AssociatedViews& hosts,
280 RankMap* rank) {
281 auto it = hosts.find(view);
282 if (it != hosts.end())
283 rank->emplace(it->second, rank->size());
284 for (int i = 0; i < view->child_count(); ++i)
285 RankNSViews(view->child_at(i), hosts, rank);
286 }
287
288 NSComparisonResult SubviewSorter(NSViewComparatorValue lhs,
289 NSViewComparatorValue rhs,
290 void* rank_as_void) {
291 DCHECK_NE(lhs, rhs);
292
293 const RankMap* rank = static_cast<const RankMap*>(rank_as_void);
294 auto left_rank = rank->find(lhs);
295 auto right_rank = rank->find(rhs);
296 bool left_found = left_rank != rank->end();
297 bool right_found = right_rank != rank->end();
298
299 // Sort unassociated views above associated views.
300 if (left_found != right_found)
301 return left_found ? NSOrderedAscending : NSOrderedDescending;
302
303 if (left_found) {
304 return left_rank->second < right_rank->second ? NSOrderedAscending
305 : NSOrderedDescending;
306 }
307
308 // If both are unassociated, consider that order is not important
309 return NSOrderedSame;
310 }
311
266 } // namespace 312 } // namespace
267 313
268 namespace views { 314 namespace views {
269 315
270 // static 316 // static
271 gfx::Size BridgedNativeWidget::GetWindowSizeForClientSize( 317 gfx::Size BridgedNativeWidget::GetWindowSizeForClientSize(
272 NSWindow* window, 318 NSWindow* window,
273 const gfx::Size& content_size) { 319 const gfx::Size& content_size) {
274 NSRect content_rect = 320 NSRect content_rect =
275 NSMakeRect(0, 0, content_size.width(), content_size.height()); 321 NSMakeRect(0, 0, content_size.width(), content_size.height());
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 // to generate a window shadow from the composited CALayer. To get around 923 // to generate a window shadow from the composited CALayer. To get around
878 // this, let the window background remain opaque and clip the window 924 // this, let the window background remain opaque and clip the window
879 // boundary in drawRect method of BridgedContentView. See crbug.com/543671. 925 // boundary in drawRect method of BridgedContentView. See crbug.com/543671.
880 if (base::mac::IsOSYosemiteOrLater()) 926 if (base::mac::IsOSYosemiteOrLater())
881 [window_ setBackgroundColor:[NSColor clearColor]]; 927 [window_ setBackgroundColor:[NSColor clearColor]];
882 } 928 }
883 929
884 UpdateLayerProperties(); 930 UpdateLayerProperties();
885 } 931 }
886 932
933 void BridgedNativeWidget::SetAssociationForView(const views::View* view,
934 NSView* native_view) {
935 DCHECK_EQ(0u, associated_views_.count(view));
936 associated_views_[view] = native_view;
937 native_widget_mac_->GetWidget()->ReorderNativeViews();
938 }
939
940 void BridgedNativeWidget::ClearAssociationForView(const views::View* view) {
941 auto it = associated_views_.find(view);
942 DCHECK(it != associated_views_.end());
943 associated_views_.erase(it);
944 }
945
946 void BridgedNativeWidget::ReorderChildViews() {
947 RankMap rank;
948 Widget* widget = native_widget_mac_->GetWidget();
949 RankNSViews(widget->GetRootView(), associated_views_, &rank);
950 // Unassociated NSViews should be ordered above associated ones. The exception
951 // is the UI compositor's superview, which should always be on the very
952 // bottom, so give it an explicit negative rank.
953 if (compositor_superview_)
954 rank[compositor_superview_] = -1;
955 [bridged_view_ sortSubviewsUsingFunction:&SubviewSorter context:&rank];
956 }
957
887 //////////////////////////////////////////////////////////////////////////////// 958 ////////////////////////////////////////////////////////////////////////////////
888 // BridgedNativeWidget, internal::InputMethodDelegate: 959 // BridgedNativeWidget, internal::InputMethodDelegate:
889 960
890 ui::EventDispatchDetails BridgedNativeWidget::DispatchKeyEventPostIME( 961 ui::EventDispatchDetails BridgedNativeWidget::DispatchKeyEventPostIME(
891 ui::KeyEvent* key) { 962 ui::KeyEvent* key) {
892 DCHECK(focus_manager_); 963 DCHECK(focus_manager_);
893 native_widget_mac_->GetWidget()->OnKeyEvent(key); 964 native_widget_mac_->GetWidget()->OnKeyEvent(key);
894 if (!key->handled()) { 965 if (!key->handled()) {
895 if (!focus_manager_->OnKeyEvent(*key)) 966 if (!focus_manager_->OnKeyEvent(*key))
896 key->StopPropagation(); 967 key->StopPropagation();
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
1238 [bridged_view_ setMouseDownCanMoveWindow:draggable]; 1309 [bridged_view_ setMouseDownCanMoveWindow:draggable];
1239 // AppKit will not update its cache of mouseDownCanMoveWindow unless something 1310 // AppKit will not update its cache of mouseDownCanMoveWindow unless something
1240 // changes. Previously we tried adding an NSView and removing it, but for some 1311 // changes. Previously we tried adding an NSView and removing it, but for some
1241 // reason it required reposting the mouse-down event, and didn't always work. 1312 // reason it required reposting the mouse-down event, and didn't always work.
1242 // Calling the below seems to be an effective solution. 1313 // Calling the below seems to be an effective solution.
1243 [window_ setMovableByWindowBackground:NO]; 1314 [window_ setMovableByWindowBackground:NO];
1244 [window_ setMovableByWindowBackground:YES]; 1315 [window_ setMovableByWindowBackground:YES];
1245 } 1316 }
1246 1317
1247 } // namespace views 1318 } // namespace views
OLDNEW
« 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