Chromium Code Reviews| 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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 // tied to the C++ object, rather than the delegate (which may be reference | 344 // tied to the C++ object, rather than the delegate (which may be reference |
| 345 // counted). This is required since the application hides do not send an | 345 // counted). This is required since the application hides do not send an |
| 346 // orderOut: to individual windows. Unhide, however, does send an order | 346 // orderOut: to individual windows. Unhide, however, does send an order |
| 347 // message. | 347 // message. |
| 348 [[NSNotificationCenter defaultCenter] | 348 [[NSNotificationCenter defaultCenter] |
| 349 addObserver:window_delegate_ | 349 addObserver:window_delegate_ |
| 350 selector:@selector(onWindowOrderChanged:) | 350 selector:@selector(onWindowOrderChanged:) |
| 351 name:NSApplicationDidHideNotification | 351 name:NSApplicationDidHideNotification |
| 352 object:nil]; | 352 object:nil]; |
| 353 | 353 |
| 354 // Get notified whenever Full Keyboard Access mode is changed. | |
| 355 // Todo(karandeepb): See how to store constant string. | |
|
tapted
2016/02/23 03:01:19
You can just declare a
NSString* const kFullKeybo
karandeepb
2016/03/15 02:19:50
Done.
| |
| 356 [[NSDistributedNotificationCenter defaultCenter] | |
| 357 addObserver:window_delegate_ | |
| 358 selector:@selector(onFullKeyboardAccessModeChanged:) | |
| 359 name:@"com.apple.KeyboardUIModeDidChange" | |
| 360 object:nil]; | |
| 361 | |
| 354 // Validate the window's initial state, otherwise the bridge's initial | 362 // Validate the window's initial state, otherwise the bridge's initial |
| 355 // tracking state will be incorrect. | 363 // tracking state will be incorrect. |
| 356 DCHECK(![window_ isVisible]); | 364 DCHECK(![window_ isVisible]); |
| 357 DCHECK_EQ(0u, [window_ styleMask] & NSFullScreenWindowMask); | 365 DCHECK_EQ(0u, [window_ styleMask] & NSFullScreenWindowMask); |
| 358 | 366 |
| 359 if (params.parent) { | 367 if (params.parent) { |
| 360 // Disallow creating child windows of views not currently in an NSWindow. | 368 // Disallow creating child windows of views not currently in an NSWindow. |
| 361 CHECK([params.parent window]); | 369 CHECK([params.parent window]); |
| 362 BridgedNativeWidget* bridged_native_widget_parent = | 370 BridgedNativeWidget* bridged_native_widget_parent = |
| 363 NativeWidgetMac::GetBridgeForNativeWindow([params.parent window]); | 371 NativeWidgetMac::GetBridgeForNativeWindow([params.parent window]); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 419 tooltip_manager_.reset(new TooltipManagerMac(this)); | 427 tooltip_manager_.reset(new TooltipManagerMac(this)); |
| 420 } | 428 } |
| 421 | 429 |
| 422 void BridgedNativeWidget::SetFocusManager(FocusManager* focus_manager) { | 430 void BridgedNativeWidget::SetFocusManager(FocusManager* focus_manager) { |
| 423 if (focus_manager_ == focus_manager) | 431 if (focus_manager_ == focus_manager) |
| 424 return; | 432 return; |
| 425 | 433 |
| 426 if (focus_manager_) | 434 if (focus_manager_) |
| 427 focus_manager_->RemoveFocusChangeListener(this); | 435 focus_manager_->RemoveFocusChangeListener(this); |
| 428 | 436 |
| 429 if (focus_manager) | 437 if (focus_manager) { |
| 430 focus_manager->AddFocusChangeListener(this); | 438 focus_manager->AddFocusChangeListener(this); |
| 439 focus_manager->SetKeyboardAccessibility( | |
| 440 [NSApp isFullKeyboardAccessEnabled]); | |
| 441 } | |
| 431 | 442 |
| 432 focus_manager_ = focus_manager; | 443 focus_manager_ = focus_manager; |
| 433 } | 444 } |
| 434 | 445 |
| 435 void BridgedNativeWidget::SetBounds(const gfx::Rect& new_bounds) { | 446 void BridgedNativeWidget::SetBounds(const gfx::Rect& new_bounds) { |
| 436 Widget* widget = native_widget_mac_->GetWidget(); | 447 Widget* widget = native_widget_mac_->GetWidget(); |
| 437 // -[NSWindow contentMinSize] is only checked by Cocoa for user-initiated | 448 // -[NSWindow contentMinSize] is only checked by Cocoa for user-initiated |
| 438 // resizes. This is not what toolkit-views expects, so clamp. Note there is | 449 // resizes. This is not what toolkit-views expects, so clamp. Note there is |
| 439 // no check for maximum size (consistent with aura::Window::SetBounds()). | 450 // no check for maximum size (consistent with aura::Window::SetBounds()). |
| 440 gfx::Size clamped_content_size = | 451 gfx::Size clamped_content_size = |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 589 [window_delegate_ setCursor:cursor]; | 600 [window_delegate_ setCursor:cursor]; |
| 590 } | 601 } |
| 591 | 602 |
| 592 void BridgedNativeWidget::OnWindowWillClose() { | 603 void BridgedNativeWidget::OnWindowWillClose() { |
| 593 if (parent_) { | 604 if (parent_) { |
| 594 parent_->RemoveChildWindow(this); | 605 parent_->RemoveChildWindow(this); |
| 595 parent_ = nullptr; | 606 parent_ = nullptr; |
| 596 } | 607 } |
| 597 [window_ setDelegate:nil]; | 608 [window_ setDelegate:nil]; |
| 598 [[NSNotificationCenter defaultCenter] removeObserver:window_delegate_]; | 609 [[NSNotificationCenter defaultCenter] removeObserver:window_delegate_]; |
| 610 [[NSDistributedNotificationCenter defaultCenter] | |
| 611 removeObserver:window_delegate_]; | |
| 599 native_widget_mac_->OnWindowWillClose(); | 612 native_widget_mac_->OnWindowWillClose(); |
| 600 } | 613 } |
| 601 | 614 |
| 602 void BridgedNativeWidget::OnFullscreenTransitionStart( | 615 void BridgedNativeWidget::OnFullscreenTransitionStart( |
| 603 bool target_fullscreen_state) { | 616 bool target_fullscreen_state) { |
| 604 // Note: This can fail for fullscreen changes started externally, but a user | 617 // Note: This can fail for fullscreen changes started externally, but a user |
| 605 // shouldn't be able to do that if the window is invisible to begin with. | 618 // shouldn't be able to do that if the window is invisible to begin with. |
| 606 DCHECK(window_visible_); | 619 DCHECK(window_visible_); |
| 607 | 620 |
| 608 DCHECK_NE(target_fullscreen_state, target_fullscreen_state_); | 621 DCHECK_NE(target_fullscreen_state, target_fullscreen_state_); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 751 } | 764 } |
| 752 | 765 |
| 753 void BridgedNativeWidget::OnWindowKeyStatusChangedTo(bool is_key) { | 766 void BridgedNativeWidget::OnWindowKeyStatusChangedTo(bool is_key) { |
| 754 Widget* widget = native_widget_mac()->GetWidget(); | 767 Widget* widget = native_widget_mac()->GetWidget(); |
| 755 widget->OnNativeWidgetActivationChanged(is_key); | 768 widget->OnNativeWidgetActivationChanged(is_key); |
| 756 // The contentView is the BridgedContentView hosting the views::RootView. The | 769 // The contentView is the BridgedContentView hosting the views::RootView. The |
| 757 // focus manager will already know if a native subview has focus. | 770 // focus manager will already know if a native subview has focus. |
| 758 if ([window_ contentView] == [window_ firstResponder]) { | 771 if ([window_ contentView] == [window_ firstResponder]) { |
| 759 if (is_key) { | 772 if (is_key) { |
| 760 widget->OnNativeFocus(); | 773 widget->OnNativeFocus(); |
| 774 // The NSApplication class automatically suspends distributed notification | |
| 775 // delivery when the application is not active. For the full keyboard | |
| 776 // access mode change notification, the default suspension behavior of | |
| 777 // NSNotificationSuspensionBehaviorCoalesce should have worked, but | |
| 778 // it doesn't sometimes. Hence explicitly set the keyboard accessibility | |
| 779 // state on regaining key window status. | |
| 780 widget->GetFocusManager()->SetKeyboardAccessibility( | |
| 781 [NSApp isFullKeyboardAccessEnabled]); | |
| 761 widget->GetFocusManager()->RestoreFocusedView(); | 782 widget->GetFocusManager()->RestoreFocusedView(); |
| 762 } else { | 783 } else { |
| 763 widget->OnNativeBlur(); | 784 widget->OnNativeBlur(); |
| 764 widget->GetFocusManager()->StoreFocusedView(true); | 785 widget->GetFocusManager()->StoreFocusedView(true); |
| 765 } | 786 } |
| 766 } | 787 } |
| 767 } | 788 } |
| 768 | 789 |
| 769 bool BridgedNativeWidget::ShouldRepostPendingLeftMouseDown( | 790 bool BridgedNativeWidget::ShouldRepostPendingLeftMouseDown( |
| 770 NSPoint location_in_window) { | 791 NSPoint location_in_window) { |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1238 [bridged_view_ setMouseDownCanMoveWindow:draggable]; | 1259 [bridged_view_ setMouseDownCanMoveWindow:draggable]; |
| 1239 // AppKit will not update its cache of mouseDownCanMoveWindow unless something | 1260 // AppKit will not update its cache of mouseDownCanMoveWindow unless something |
| 1240 // changes. Previously we tried adding an NSView and removing it, but for some | 1261 // 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. | 1262 // reason it required reposting the mouse-down event, and didn't always work. |
| 1242 // Calling the below seems to be an effective solution. | 1263 // Calling the below seems to be an effective solution. |
| 1243 [window_ setMovableByWindowBackground:NO]; | 1264 [window_ setMovableByWindowBackground:NO]; |
| 1244 [window_ setMovableByWindowBackground:YES]; | 1265 [window_ setMovableByWindowBackground:YES]; |
| 1245 } | 1266 } |
| 1246 | 1267 |
| 1247 } // namespace views | 1268 } // namespace views |
| OLD | NEW |