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

Side by Side Diff: ui/views/widget/native_widget_mac_unittest.mm

Issue 1759913004: MacViews: Handling changing of first responder inside NativeWidgetMac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added comment for test. Created 4 years, 9 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 | « ui/views/cocoa/bridged_content_view.mm ('k') | 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/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"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 NSUInteger drawRectCount_; 64 NSUInteger drawRectCount_;
65 65
66 // The dirtyRect parameter passed to last invocation of drawRect:. 66 // The dirtyRect parameter passed to last invocation of drawRect:.
67 NSRect lastDirtyRect_; 67 NSRect lastDirtyRect_;
68 } 68 }
69 69
70 @property(assign, nonatomic) NSUInteger drawRectCount; 70 @property(assign, nonatomic) NSUInteger drawRectCount;
71 @property(assign, nonatomic) NSRect lastDirtyRect; 71 @property(assign, nonatomic) NSRect lastDirtyRect;
72 @end 72 @end
73 73
74 @interface FocusableTestNSView : NSView
75 @end
76
74 namespace views { 77 namespace views {
75 namespace test { 78 namespace test {
76 79
77 // BridgedNativeWidget friend to access private members. 80 // BridgedNativeWidget friend to access private members.
78 class BridgedNativeWidgetTestApi { 81 class BridgedNativeWidgetTestApi {
79 public: 82 public:
80 explicit BridgedNativeWidgetTestApi(NSWindow* window) { 83 explicit BridgedNativeWidgetTestApi(NSWindow* window) {
81 bridge_ = NativeWidgetMac::GetBridgeForNativeWindow(window); 84 bridge_ = NativeWidgetMac::GetBridgeForNativeWindow(window);
82 } 85 }
83 86
(...skipping 1218 matching lines...) Expand 10 before | Expand all | Expand 10 after
1302 // These are expected dummy_view bounds in AppKit coordinate system. The y 1305 // These are expected dummy_view bounds in AppKit coordinate system. The y
1303 // coordinate of rect origin is calculated as: 1306 // coordinate of rect origin is calculated as:
1304 // 100(client area height) - 30 (dummy_view's y coordinate) - 15 (dummy view's 1307 // 100(client area height) - 30 (dummy_view's y coordinate) - 15 (dummy view's
1305 // height). 1308 // height).
1306 gfx::Rect expected_appkit_bounds(25, 55, 10, 15); 1309 gfx::Rect expected_appkit_bounds(25, 55, 10, 15);
1307 EXPECT_NSEQ(expected_appkit_bounds.ToCGRect(), 1310 EXPECT_NSEQ(expected_appkit_bounds.ToCGRect(),
1308 [mock_bridged_view lastDirtyRect]); 1311 [mock_bridged_view lastDirtyRect]);
1309 widget->CloseNow(); 1312 widget->CloseNow();
1310 } 1313 }
1311 1314
1315 // Ensure traversing NSView focus correctly updates the views::FocusManager.
1316 TEST_F(NativeWidgetMacTest, ChangeFocusOnChangeFirstResponder) {
1317 Widget* widget = CreateTopLevelPlatformWidget();
1318 widget->GetRootView()->SetFocusable(true);
1319 widget->Show();
1320
1321 base::scoped_nsobject<NSView> child_view([[FocusableTestNSView alloc]
1322 initWithFrame:[widget->GetNativeView() bounds]]);
1323 [widget->GetNativeView() addSubview:child_view];
1324 EXPECT_TRUE([child_view acceptsFirstResponder]);
1325 EXPECT_TRUE(widget->GetRootView()->IsFocusable());
1326
1327 FocusManager* manager = widget->GetFocusManager();
1328 manager->SetFocusedView(widget->GetRootView());
1329 EXPECT_EQ(manager->GetFocusedView(), widget->GetRootView());
1330
1331 [widget->GetNativeWindow() makeFirstResponder:child_view];
1332 EXPECT_FALSE(manager->GetFocusedView());
1333
1334 [widget->GetNativeWindow() makeFirstResponder:widget->GetNativeView()];
1335 EXPECT_EQ(manager->GetFocusedView(), widget->GetRootView());
1336
1337 widget->CloseNow();
1338 }
1339
1312 } // namespace test 1340 } // namespace test
1313 } // namespace views 1341 } // namespace views
1314 1342
1315 @implementation TestStopAnimationWaiter 1343 @implementation TestStopAnimationWaiter
1316 - (void)setWindowStateForEnd { 1344 - (void)setWindowStateForEnd {
1317 views::test::ScopedSwizzleWaiter::GetMethodAndMarkCalled()(self, _cmd); 1345 views::test::ScopedSwizzleWaiter::GetMethodAndMarkCalled()(self, _cmd);
1318 } 1346 }
1319 @end 1347 @end
1320 1348
1321 @implementation NativeWidgetMacTestWindow 1349 @implementation NativeWidgetMacTestWindow
(...skipping 11 matching lines...) Expand all
1333 1361
1334 @synthesize drawRectCount = drawRectCount_; 1362 @synthesize drawRectCount = drawRectCount_;
1335 @synthesize lastDirtyRect = lastDirtyRect_; 1363 @synthesize lastDirtyRect = lastDirtyRect_;
1336 1364
1337 - (void)drawRect:(NSRect)dirtyRect { 1365 - (void)drawRect:(NSRect)dirtyRect {
1338 ++drawRectCount_; 1366 ++drawRectCount_;
1339 lastDirtyRect_ = dirtyRect; 1367 lastDirtyRect_ = dirtyRect;
1340 } 1368 }
1341 1369
1342 @end 1370 @end
1371
1372 @implementation FocusableTestNSView
1373 - (BOOL)acceptsFirstResponder {
1374 return YES;
1375 }
1376 @end
OLDNEW
« no previous file with comments | « ui/views/cocoa/bridged_content_view.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698