OLD | NEW |
---|---|
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 Loading... | |
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() | |
tapted
2016/10/06 07:38:46
dang it - typically this is required to avoid a "t
karandeepb
2016/10/07 01:03:57
Yeah, so the arguments to the DCHECK macros are st
| |
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 | |
315 } // namespace | 328 } // namespace |
316 | 329 |
317 namespace views { | 330 namespace views { |
318 | 331 |
319 // static | 332 // static |
320 gfx::Size BridgedNativeWidget::GetWindowSizeForClientSize( | 333 gfx::Size BridgedNativeWidget::GetWindowSizeForClientSize( |
321 NSWindow* window, | 334 NSWindow* window, |
322 const gfx::Size& content_size) { | 335 const gfx::Size& content_size) { |
323 NSRect content_rect = | 336 NSRect content_rect = |
324 NSMakeRect(0, 0, content_size.width(), content_size.height()); | 337 NSMakeRect(0, 0, content_size.width(), content_size.height()); |
(...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1183 for (BridgedNativeWidget* child : child_windows_) { | 1196 for (BridgedNativeWidget* child : child_windows_) { |
1184 if (child->window_visible_) | 1197 if (child->window_visible_) |
1185 [child->ns_window() orderOut:nil]; | 1198 [child->ns_window() orderOut:nil]; |
1186 | 1199 |
1187 DCHECK(!child->window_visible_); | 1200 DCHECK(!child->window_visible_); |
1188 CHECK_EQ(child_count, child_windows_.size()); | 1201 CHECK_EQ(child_count, child_windows_.size()); |
1189 } | 1202 } |
1190 // The orderOut calls above should result in a call to OnVisibilityChanged() | 1203 // The orderOut calls above should result in a call to OnVisibilityChanged() |
1191 // in each child. There, children will remove themselves from the NSWindow | 1204 // in each child. There, children will remove themselves from the NSWindow |
1192 // childWindow list as well as propagate NotifyVisibilityChangeDown() calls | 1205 // childWindow list as well as propagate NotifyVisibilityChangeDown() calls |
1193 // to any children of their own. | 1206 // to any children of their own. However this is only true for windows |
1194 DCHECK_EQ(0u, [[window_ childWindows] count]); | 1207 // managed by the BridgedNativeWidget i.e. windows which have |
1208 // ViewsNSWindowDelegate as the delegate. | |
1209 DCHECK_EQ(0u, CountBridgedWindows([window_ childWindows])); | |
1195 return; | 1210 return; |
1196 } | 1211 } |
1197 | 1212 |
1198 NSUInteger visible_children = 0; // For a DCHECK below. | 1213 NSUInteger visible_bridged_children = 0; // For a DCHECK below. |
1199 NSInteger parent_window_number = [window_ windowNumber]; | 1214 NSInteger parent_window_number = [window_ windowNumber]; |
1200 for (BridgedNativeWidget* child: child_windows_) { | 1215 for (BridgedNativeWidget* child: child_windows_) { |
1201 // Note: order the child windows on top, regardless of whether or not they | 1216 // Note: order the child windows on top, regardless of whether or not they |
1202 // are currently visible. They probably aren't, since the parent was hidden | 1217 // are currently visible. They probably aren't, since the parent was hidden |
1203 // prior to this, but they could have been made visible in other ways. | 1218 // prior to this, but they could have been made visible in other ways. |
1204 if (child->wants_to_be_visible_) { | 1219 if (child->wants_to_be_visible_) { |
1205 ++visible_children; | 1220 ++visible_bridged_children; |
1206 // Here -[NSWindow orderWindow:relativeTo:] is used to put the window on | 1221 // Here -[NSWindow orderWindow:relativeTo:] is used to put the window on |
1207 // screen. However, that by itself is insufficient to guarantee a correct | 1222 // screen. However, that by itself is insufficient to guarantee a correct |
1208 // z-order relationship. If this function is being called from a z-order | 1223 // z-order relationship. If this function is being called from a z-order |
1209 // change in the parent, orderWindow turns out to be unreliable (i.e. the | 1224 // change in the parent, orderWindow turns out to be unreliable (i.e. the |
1210 // ordering doesn't always take effect). What this actually relies on is | 1225 // ordering doesn't always take effect). What this actually relies on is |
1211 // the resulting call to OnVisibilityChanged() in the child, which will | 1226 // the resulting call to OnVisibilityChanged() in the child, which will |
1212 // then insert itself into -[NSWindow childWindows] to let Cocoa do its | 1227 // then insert itself into -[NSWindow childWindows] to let Cocoa do its |
1213 // internal layering magic. | 1228 // internal layering magic. |
1214 [child->ns_window() orderWindow:NSWindowAbove | 1229 [child->ns_window() orderWindow:NSWindowAbove |
1215 relativeTo:parent_window_number]; | 1230 relativeTo:parent_window_number]; |
1216 DCHECK(child->window_visible_); | 1231 DCHECK(child->window_visible_); |
1217 } | 1232 } |
1218 CHECK_EQ(child_count, child_windows_.size()); | 1233 CHECK_EQ(child_count, child_windows_.size()); |
1219 } | 1234 } |
1220 DCHECK_EQ(visible_children, [[window_ childWindows] count]); | 1235 DCHECK_EQ(visible_bridged_children, |
1236 CountBridgedWindows([window_ childWindows])); | |
1221 } | 1237 } |
1222 | 1238 |
1223 gfx::Size BridgedNativeWidget::GetClientAreaSize() const { | 1239 gfx::Size BridgedNativeWidget::GetClientAreaSize() const { |
1224 NSRect content_rect = [window_ contentRectForFrameRect:[window_ frame]]; | 1240 NSRect content_rect = [window_ contentRectForFrameRect:[window_ frame]]; |
1225 return gfx::Size(NSWidth(content_rect), NSHeight(content_rect)); | 1241 return gfx::Size(NSWidth(content_rect), NSHeight(content_rect)); |
1226 } | 1242 } |
1227 | 1243 |
1228 void BridgedNativeWidget::CreateCompositor() { | 1244 void BridgedNativeWidget::CreateCompositor() { |
1229 DCHECK(!compositor_); | 1245 DCHECK(!compositor_); |
1230 DCHECK(!compositor_widget_); | 1246 DCHECK(!compositor_widget_); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1390 [bridged_view_ setMouseDownCanMoveWindow:draggable]; | 1406 [bridged_view_ setMouseDownCanMoveWindow:draggable]; |
1391 // AppKit will not update its cache of mouseDownCanMoveWindow unless something | 1407 // AppKit will not update its cache of mouseDownCanMoveWindow unless something |
1392 // changes. Previously we tried adding an NSView and removing it, but for some | 1408 // changes. Previously we tried adding an NSView and removing it, but for some |
1393 // reason it required reposting the mouse-down event, and didn't always work. | 1409 // reason it required reposting the mouse-down event, and didn't always work. |
1394 // Calling the below seems to be an effective solution. | 1410 // Calling the below seems to be an effective solution. |
1395 [window_ setMovableByWindowBackground:NO]; | 1411 [window_ setMovableByWindowBackground:NO]; |
1396 [window_ setMovableByWindowBackground:YES]; | 1412 [window_ setMovableByWindowBackground:YES]; |
1397 } | 1413 } |
1398 | 1414 |
1399 } // namespace views | 1415 } // namespace views |
OLD | NEW |