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

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: 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
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 FocusedNSView : NSView
tapted 2016/03/04 00:56:19 nit: FocusableTestNSView (name collisions are eas
kirr 2016/03/04 08:31:31 Done.
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 TEST_F(NativeWidgetMacTest, ChangeFocusOnChangeFirstResponder) {
1316 Widget* widget = CreateTopLevelPlatformWidget();
1317 widget->GetRootView()->SetFocusable(true);
1318 widget->Show();
1319
1320 base::scoped_nsobject<NSView> child_view(
1321 [[FocusedNSView alloc] initWithFrame:[widget->GetNativeView() bounds]]);
1322 [widget->GetNativeView() addSubview:child_view];
1323 DCHECK_EQ([child_view acceptsFirstResponder], YES);
tapted 2016/03/04 00:56:19 nit: EXPECT_TRUE
kirr 2016/03/04 08:31:30 Done.
1324 DCHECK_EQ(widget->GetRootView()->IsFocusable(), YES);
tapted 2016/03/04 00:56:19 EXPECT_TRUE (somewhat moot here since this won't
kirr 2016/03/04 08:31:30 Done.
1325
1326 FocusManager* manager = widget->GetFocusManager();
1327 manager->SetFocusedView(widget->GetRootView());
1328 DCHECK_EQ(manager->GetFocusedView(), widget->GetRootView());
tapted 2016/03/04 00:56:19 EXPECT_EQ
kirr 2016/03/04 08:31:31 Done.
1329
1330 [widget->GetNativeWindow() makeFirstResponder: child_view];
tapted 2016/03/04 00:56:19 nit: no space before `child_view`
kirr 2016/03/04 08:31:30 Done.
1331 DCHECK(!manager->GetFocusedView());
tapted 2016/03/04 00:56:19 EXPECT_FALSE
kirr 2016/03/04 08:31:31 Done.
1332
1333 [widget->GetNativeWindow() makeFirstResponder: widget->GetNativeView()];
tapted 2016/03/04 00:56:19 nit: no space before `widget`. -- running `git cl
kirr 2016/03/04 08:31:30 Done. "git cl format" - is super helpful. Thanks a
1334 DCHECK_EQ(manager->GetFocusedView(), widget->GetRootView());
tapted 2016/03/04 00:56:19 EXPECT_EQ
kirr 2016/03/04 08:31:30 Done.
1335
1336 widget->CloseNow();
1337 }
1338
1312 } // namespace test 1339 } // namespace test
1313 } // namespace views 1340 } // namespace views
1314 1341
1315 @implementation TestStopAnimationWaiter 1342 @implementation TestStopAnimationWaiter
1316 - (void)setWindowStateForEnd { 1343 - (void)setWindowStateForEnd {
1317 views::test::ScopedSwizzleWaiter::GetMethodAndMarkCalled()(self, _cmd); 1344 views::test::ScopedSwizzleWaiter::GetMethodAndMarkCalled()(self, _cmd);
1318 } 1345 }
1319 @end 1346 @end
1320 1347
1321 @implementation NativeWidgetMacTestWindow 1348 @implementation NativeWidgetMacTestWindow
(...skipping 11 matching lines...) Expand all
1333 1360
1334 @synthesize drawRectCount = drawRectCount_; 1361 @synthesize drawRectCount = drawRectCount_;
1335 @synthesize lastDirtyRect = lastDirtyRect_; 1362 @synthesize lastDirtyRect = lastDirtyRect_;
1336 1363
1337 - (void)drawRect:(NSRect)dirtyRect { 1364 - (void)drawRect:(NSRect)dirtyRect {
1338 ++drawRectCount_; 1365 ++drawRectCount_;
1339 lastDirtyRect_ = dirtyRect; 1366 lastDirtyRect_ = dirtyRect;
1340 } 1367 }
1341 1368
1342 @end 1369 @end
1370
1371 @implementation FocusedNSView
1372 - (BOOL)acceptsFirstResponder {
1373 return YES;
1374 }
1375 @end
1376
tapted 2016/03/04 00:56:20 nit: remove trailing blank line
kirr 2016/03/04 08:31:30 Done.
OLDNEW
« ui/views/cocoa/bridged_content_view.mm ('K') | « 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