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