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

Side by Side Diff: ui/views/cocoa/bridged_native_widget.mm

Issue 2399783002: Revert of MacViews: Fix crash due to failed DCHECK in BridgedNativeWidget. (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 305
306 if (left_found) { 306 if (left_found) {
307 return left_rank->second < right_rank->second ? NSOrderedAscending 307 return left_rank->second < right_rank->second ? NSOrderedAscending
308 : NSOrderedDescending; 308 : NSOrderedDescending;
309 } 309 }
310 310
311 // If both are unassociated, consider that order is not important 311 // If both are unassociated, consider that order is not important
312 return NSOrderedSame; 312 return NSOrderedSame;
313 } 313 }
314 314
315 #if DCHECK_IS_ON()
316 // Counts windows managed by a BridgedNativeWidget instance in the
317 // |child_windows| array ignoring the windows added by AppKit.
318 NSUInteger CountBridgedWindows(NSArray* child_windows) {
319 NSUInteger count = 0;
320 for (NSWindow* child in child_windows)
321 if ([[child delegate] isKindOfClass:[ViewsNSWindowDelegate class]])
322 ++count;
323
324 return count;
325 }
326 #endif
327
328 } // namespace 315 } // namespace
329 316
330 namespace views { 317 namespace views {
331 318
332 // static 319 // static
333 gfx::Size BridgedNativeWidget::GetWindowSizeForClientSize( 320 gfx::Size BridgedNativeWidget::GetWindowSizeForClientSize(
334 NSWindow* window, 321 NSWindow* window,
335 const gfx::Size& content_size) { 322 const gfx::Size& content_size) {
336 NSRect content_rect = 323 NSRect content_rect =
337 NSMakeRect(0, 0, content_size.width(), content_size.height()); 324 NSMakeRect(0, 0, content_size.width(), content_size.height());
(...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 for (BridgedNativeWidget* child : child_windows_) { 1183 for (BridgedNativeWidget* child : child_windows_) {
1197 if (child->window_visible_) 1184 if (child->window_visible_)
1198 [child->ns_window() orderOut:nil]; 1185 [child->ns_window() orderOut:nil];
1199 1186
1200 DCHECK(!child->window_visible_); 1187 DCHECK(!child->window_visible_);
1201 CHECK_EQ(child_count, child_windows_.size()); 1188 CHECK_EQ(child_count, child_windows_.size());
1202 } 1189 }
1203 // The orderOut calls above should result in a call to OnVisibilityChanged() 1190 // The orderOut calls above should result in a call to OnVisibilityChanged()
1204 // in each child. There, children will remove themselves from the NSWindow 1191 // in each child. There, children will remove themselves from the NSWindow
1205 // childWindow list as well as propagate NotifyVisibilityChangeDown() calls 1192 // childWindow list as well as propagate NotifyVisibilityChangeDown() calls
1206 // to any children of their own. However this is only true for windows 1193 // to any children of their own.
1207 // managed by the BridgedNativeWidget i.e. windows which have 1194 DCHECK_EQ(0u, [[window_ childWindows] count]);
1208 // ViewsNSWindowDelegate as the delegate.
1209 DCHECK_EQ(0u, CountBridgedWindows([window_ childWindows]));
1210 return; 1195 return;
1211 } 1196 }
1212 1197
1213 NSUInteger visible_bridged_children = 0; // For a DCHECK below. 1198 NSUInteger visible_children = 0; // For a DCHECK below.
1214 NSInteger parent_window_number = [window_ windowNumber]; 1199 NSInteger parent_window_number = [window_ windowNumber];
1215 for (BridgedNativeWidget* child: child_windows_) { 1200 for (BridgedNativeWidget* child: child_windows_) {
1216 // Note: order the child windows on top, regardless of whether or not they 1201 // Note: order the child windows on top, regardless of whether or not they
1217 // are currently visible. They probably aren't, since the parent was hidden 1202 // are currently visible. They probably aren't, since the parent was hidden
1218 // prior to this, but they could have been made visible in other ways. 1203 // prior to this, but they could have been made visible in other ways.
1219 if (child->wants_to_be_visible_) { 1204 if (child->wants_to_be_visible_) {
1220 ++visible_bridged_children; 1205 ++visible_children;
1221 // Here -[NSWindow orderWindow:relativeTo:] is used to put the window on 1206 // Here -[NSWindow orderWindow:relativeTo:] is used to put the window on
1222 // screen. However, that by itself is insufficient to guarantee a correct 1207 // screen. However, that by itself is insufficient to guarantee a correct
1223 // z-order relationship. If this function is being called from a z-order 1208 // z-order relationship. If this function is being called from a z-order
1224 // change in the parent, orderWindow turns out to be unreliable (i.e. the 1209 // change in the parent, orderWindow turns out to be unreliable (i.e. the
1225 // ordering doesn't always take effect). What this actually relies on is 1210 // ordering doesn't always take effect). What this actually relies on is
1226 // the resulting call to OnVisibilityChanged() in the child, which will 1211 // the resulting call to OnVisibilityChanged() in the child, which will
1227 // then insert itself into -[NSWindow childWindows] to let Cocoa do its 1212 // then insert itself into -[NSWindow childWindows] to let Cocoa do its
1228 // internal layering magic. 1213 // internal layering magic.
1229 [child->ns_window() orderWindow:NSWindowAbove 1214 [child->ns_window() orderWindow:NSWindowAbove
1230 relativeTo:parent_window_number]; 1215 relativeTo:parent_window_number];
1231 DCHECK(child->window_visible_); 1216 DCHECK(child->window_visible_);
1232 } 1217 }
1233 CHECK_EQ(child_count, child_windows_.size()); 1218 CHECK_EQ(child_count, child_windows_.size());
1234 } 1219 }
1235 DCHECK_EQ(visible_bridged_children, 1220 DCHECK_EQ(visible_children, [[window_ childWindows] count]);
1236 CountBridgedWindows([window_ childWindows]));
1237 } 1221 }
1238 1222
1239 gfx::Size BridgedNativeWidget::GetClientAreaSize() const { 1223 gfx::Size BridgedNativeWidget::GetClientAreaSize() const {
1240 NSRect content_rect = [window_ contentRectForFrameRect:[window_ frame]]; 1224 NSRect content_rect = [window_ contentRectForFrameRect:[window_ frame]];
1241 return gfx::Size(NSWidth(content_rect), NSHeight(content_rect)); 1225 return gfx::Size(NSWidth(content_rect), NSHeight(content_rect));
1242 } 1226 }
1243 1227
1244 void BridgedNativeWidget::CreateCompositor() { 1228 void BridgedNativeWidget::CreateCompositor() {
1245 DCHECK(!compositor_); 1229 DCHECK(!compositor_);
1246 DCHECK(!compositor_widget_); 1230 DCHECK(!compositor_widget_);
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 [bridged_view_ setMouseDownCanMoveWindow:draggable]; 1390 [bridged_view_ setMouseDownCanMoveWindow:draggable];
1407 // AppKit will not update its cache of mouseDownCanMoveWindow unless something 1391 // AppKit will not update its cache of mouseDownCanMoveWindow unless something
1408 // changes. Previously we tried adding an NSView and removing it, but for some 1392 // changes. Previously we tried adding an NSView and removing it, but for some
1409 // reason it required reposting the mouse-down event, and didn't always work. 1393 // reason it required reposting the mouse-down event, and didn't always work.
1410 // Calling the below seems to be an effective solution. 1394 // Calling the below seems to be an effective solution.
1411 [window_ setMovableByWindowBackground:NO]; 1395 [window_ setMovableByWindowBackground:NO];
1412 [window_ setMovableByWindowBackground:YES]; 1396 [window_ setMovableByWindowBackground:YES];
1413 } 1397 }
1414 1398
1415 } // namespace views 1399 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698