| 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/widget/native_widget_mac.h" | 5 #import "ui/views/widget/native_widget_mac.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #import "base/mac/foundation_util.h" | 9 #import "base/mac/foundation_util.h" |
| 10 #import "base/mac/scoped_nsobject.h" | 10 #import "base/mac/scoped_nsobject.h" |
| 11 #import "base/mac/scoped_objc_class_swizzler.h" | 11 #import "base/mac/scoped_objc_class_swizzler.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/test/test_timeouts.h" | 16 #include "base/test/test_timeouts.h" |
| 17 #import "testing/gtest_mac.h" | 17 #import "testing/gtest_mac.h" |
| 18 #include "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
| 19 #include "third_party/skia/include/core/SkCanvas.h" | 19 #include "third_party/skia/include/core/SkCanvas.h" |
| 20 #import "ui/base/cocoa/constrained_window/constrained_window_animation.h" | 20 #import "ui/base/cocoa/constrained_window/constrained_window_animation.h" |
| 21 #import "ui/base/cocoa/window_size_constants.h" | 21 #import "ui/base/cocoa/window_size_constants.h" |
| 22 #import "ui/events/test/cocoa_test_event_utils.h" | 22 #import "ui/events/test/cocoa_test_event_utils.h" |
| 23 #include "ui/events/test/event_generator.h" | 23 #include "ui/events/test/event_generator.h" |
| 24 #import "ui/gfx/mac/coordinate_conversion.h" | 24 #import "ui/gfx/mac/coordinate_conversion.h" |
| 25 #include "ui/views/bubble/bubble_delegate.h" | 25 #include "ui/views/bubble/bubble_dialog_delegate.h" |
| 26 #import "ui/views/cocoa/bridged_native_widget.h" | 26 #import "ui/views/cocoa/bridged_native_widget.h" |
| 27 #import "ui/views/cocoa/native_widget_mac_nswindow.h" | 27 #import "ui/views/cocoa/native_widget_mac_nswindow.h" |
| 28 #include "ui/views/controls/button/label_button.h" | 28 #include "ui/views/controls/button/label_button.h" |
| 29 #include "ui/views/controls/label.h" | 29 #include "ui/views/controls/label.h" |
| 30 #include "ui/views/controls/native/native_view_host.h" | 30 #include "ui/views/controls/native/native_view_host.h" |
| 31 #include "ui/views/native_cursor.h" | 31 #include "ui/views/native_cursor.h" |
| 32 #include "ui/views/test/native_widget_factory.h" | 32 #include "ui/views/test/native_widget_factory.h" |
| 33 #include "ui/views/test/test_widget_observer.h" | 33 #include "ui/views/test/test_widget_observer.h" |
| 34 #include "ui/views/test/widget_test.h" | 34 #include "ui/views/test/widget_test.h" |
| 35 #include "ui/views/widget/native_widget_mac.h" | 35 #include "ui/views/widget/native_widget_mac.h" |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 gfx::NativeView view() const { return view_.get(); } | 229 gfx::NativeView view() const { return view_.get(); } |
| 230 NativeViewHost* host() const { return host_.get(); } | 230 NativeViewHost* host() const { return host_.get(); } |
| 231 | 231 |
| 232 private: | 232 private: |
| 233 base::scoped_nsobject<NSView> view_; | 233 base::scoped_nsobject<NSView> view_; |
| 234 std::unique_ptr<NativeViewHost> host_; | 234 std::unique_ptr<NativeViewHost> host_; |
| 235 | 235 |
| 236 DISALLOW_COPY_AND_ASSIGN(NativeHostHolder); | 236 DISALLOW_COPY_AND_ASSIGN(NativeHostHolder); |
| 237 }; | 237 }; |
| 238 | 238 |
| 239 // This class gives public access to the protected ctor of |
| 240 // BubbleDialogDelegateView. |
| 241 class SimpleBubbleView : public BubbleDialogDelegateView { |
| 242 public: |
| 243 SimpleBubbleView() {} |
| 244 ~SimpleBubbleView() override {} |
| 245 |
| 246 private: |
| 247 DISALLOW_COPY_AND_ASSIGN(SimpleBubbleView); |
| 248 }; |
| 249 |
| 239 // Test visibility states triggered externally. | 250 // Test visibility states triggered externally. |
| 240 TEST_F(NativeWidgetMacTest, HideAndShowExternally) { | 251 TEST_F(NativeWidgetMacTest, HideAndShowExternally) { |
| 241 Widget* widget = CreateTopLevelPlatformWidget(); | 252 Widget* widget = CreateTopLevelPlatformWidget(); |
| 242 NSWindow* ns_window = widget->GetNativeWindow(); | 253 NSWindow* ns_window = widget->GetNativeWindow(); |
| 243 WidgetChangeObserver observer(widget); | 254 WidgetChangeObserver observer(widget); |
| 244 | 255 |
| 245 // Should initially be hidden. | 256 // Should initially be hidden. |
| 246 EXPECT_FALSE(widget->IsVisible()); | 257 EXPECT_FALSE(widget->IsVisible()); |
| 247 EXPECT_FALSE([ns_window isVisible]); | 258 EXPECT_FALSE([ns_window isVisible]); |
| 248 EXPECT_EQ(0, observer.gained_visible_count()); | 259 EXPECT_EQ(0, observer.gained_visible_count()); |
| (...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1068 | 1079 |
| 1069 // Create a dialog widget (also TYPE_WINDOW), but with a DialogDelegate. | 1080 // Create a dialog widget (also TYPE_WINDOW), but with a DialogDelegate. |
| 1070 Widget* dialog_widget = views::DialogDelegate::CreateDialogWidget( | 1081 Widget* dialog_widget = views::DialogDelegate::CreateDialogWidget( |
| 1071 new ModalDialogDelegate(ui::MODAL_TYPE_CHILD), nullptr, | 1082 new ModalDialogDelegate(ui::MODAL_TYPE_CHILD), nullptr, |
| 1072 regular_widget->GetNativeView()); | 1083 regular_widget->GetNativeView()); |
| 1073 EXPECT_TRUE([dialog_widget->GetNativeWindow() canBecomeKeyWindow]); | 1084 EXPECT_TRUE([dialog_widget->GetNativeWindow() canBecomeKeyWindow]); |
| 1074 // Dialogs shouldn't take main status away from their parent. | 1085 // Dialogs shouldn't take main status away from their parent. |
| 1075 EXPECT_FALSE([dialog_widget->GetNativeWindow() canBecomeMainWindow]); | 1086 EXPECT_FALSE([dialog_widget->GetNativeWindow() canBecomeMainWindow]); |
| 1076 | 1087 |
| 1077 // Create a bubble widget with a parent: also shouldn't get main. | 1088 // Create a bubble widget with a parent: also shouldn't get main. |
| 1078 BubbleDelegateView* bubble_view = new BubbleDelegateView(); | 1089 BubbleDialogDelegateView* bubble_view = new SimpleBubbleView(); |
| 1079 bubble_view->set_parent_window(regular_widget->GetNativeView()); | 1090 bubble_view->set_parent_window(regular_widget->GetNativeView()); |
| 1080 Widget* bubble_widget = BubbleDelegateView::CreateBubble(bubble_view); | 1091 Widget* bubble_widget = BubbleDialogDelegateView::CreateBubble(bubble_view); |
| 1081 EXPECT_TRUE([bubble_widget->GetNativeWindow() canBecomeKeyWindow]); | 1092 EXPECT_TRUE([bubble_widget->GetNativeWindow() canBecomeKeyWindow]); |
| 1082 EXPECT_FALSE([bubble_widget->GetNativeWindow() canBecomeMainWindow]); | 1093 EXPECT_FALSE([bubble_widget->GetNativeWindow() canBecomeMainWindow]); |
| 1083 | 1094 |
| 1084 // But a bubble without a parent should still be able to become main. | 1095 // But a bubble without a parent should still be able to become main. |
| 1085 Widget* toplevel_bubble_widget = | 1096 Widget* toplevel_bubble_widget = |
| 1086 BubbleDelegateView::CreateBubble(new BubbleDelegateView()); | 1097 BubbleDialogDelegateView::CreateBubble(new SimpleBubbleView()); |
| 1087 EXPECT_TRUE([toplevel_bubble_widget->GetNativeWindow() canBecomeKeyWindow]); | 1098 EXPECT_TRUE([toplevel_bubble_widget->GetNativeWindow() canBecomeKeyWindow]); |
| 1088 EXPECT_TRUE([toplevel_bubble_widget->GetNativeWindow() canBecomeMainWindow]); | 1099 EXPECT_TRUE([toplevel_bubble_widget->GetNativeWindow() canBecomeMainWindow]); |
| 1089 | 1100 |
| 1090 toplevel_bubble_widget->CloseNow(); | 1101 toplevel_bubble_widget->CloseNow(); |
| 1091 regular_widget->CloseNow(); | 1102 regular_widget->CloseNow(); |
| 1092 } | 1103 } |
| 1093 | 1104 |
| 1094 NSData* WindowContentsAsTIFF(NSWindow* window) { | 1105 NSData* WindowContentsAsTIFF(NSWindow* window) { |
| 1095 NSView* frame_view = [[window contentView] superview]; | 1106 NSView* frame_view = [[window contentView] superview]; |
| 1096 EXPECT_TRUE(frame_view); | 1107 EXPECT_TRUE(frame_view); |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1499 lastDirtyRect_ = dirtyRect; | 1510 lastDirtyRect_ = dirtyRect; |
| 1500 } | 1511 } |
| 1501 | 1512 |
| 1502 @end | 1513 @end |
| 1503 | 1514 |
| 1504 @implementation FocusableTestNSView | 1515 @implementation FocusableTestNSView |
| 1505 - (BOOL)acceptsFirstResponder { | 1516 - (BOOL)acceptsFirstResponder { |
| 1506 return YES; | 1517 return YES; |
| 1507 } | 1518 } |
| 1508 @end | 1519 @end |
| OLD | NEW |