@@ -287,10 +287,16 @@ - (NSRect)contentRectForFrameRect:(NSRect)frameRect {
287
287
is_fullscreen_ (false ),
288
288
is_kiosk_(false ),
289
289
attention_request_id_(0 ),
290
- use_system_drag_(true ) {
290
+ use_system_drag_(true ),
291
+ initial_focus_(false ), // the initial value is different from other
292
+ // platforms since osx will focus the first
293
+ // window and we want to distinguish the first
294
+ // window opening and Window.open case. See also #497
295
+ first_show_(true ) {
291
296
int width, height;
292
297
manifest->GetInteger (switches::kmWidth, &width);
293
298
manifest->GetInteger (switches::kmHeight, &height);
299
+ manifest->GetBoolean (switches::kmInitialFocus, &initial_focus_);
294
300
295
301
NSRect main_screen_rect = [[[NSScreen screens ] objectAtIndex: 0 ] frame ];
296
302
NSRect cocoa_bounds = NSMakeRect (
@@ -412,15 +418,22 @@ - (NSRect)contentRectForFrameRect:(NSRect)frameRect {
412
418
content::RenderWidgetHostView* rwhv =
413
419
shell_->web_contents ()->GetRenderWidgetHostView ();
414
420
415
- // orderFrontRegardless causes us to become the first responder. The usual
416
- // Chrome assumption is that becoming the first responder = you have focus
417
- // so we use this trick to refuse to become first responder during orderFrontRegardless
418
-
419
- if (rwhv)
420
- rwhv->SetTakesFocusOnlyOnMouseDown (true );
421
- [window () orderFrontRegardless ];
422
- if (rwhv)
423
- rwhv->SetTakesFocusOnlyOnMouseDown (false );
421
+ if (first_show_ && initial_focus_) {
422
+ [window () makeKeyAndOrderFront: nil ];
423
+ // FIXME: the new window through Window.open failed
424
+ // the focus-on-load test
425
+ } else {
426
+ // orderFrontRegardless causes us to become the first responder. The usual
427
+ // Chrome assumption is that becoming the first responder = you have focus
428
+ // so we use this trick to refuse to become first responder during orderFrontRegardless
429
+
430
+ if (rwhv)
431
+ rwhv->SetTakesFocusOnlyOnMouseDown (true );
432
+ [window () orderFrontRegardless ];
433
+ if (rwhv)
434
+ rwhv->SetTakesFocusOnlyOnMouseDown (false );
435
+ }
436
+ first_show_ = false ;
424
437
}
425
438
426
439
void NativeWindowCocoa::Hide () {
@@ -618,6 +631,14 @@ - (NSRect)contentRectForFrameRect:(NSRect)frameRect {
618
631
standard_menus.BuildWindowMenu ();
619
632
}
620
633
634
+ void NativeWindowCocoa::SetInitialFocus (bool accept_focus) {
635
+ initial_focus_ = accept_focus;
636
+ }
637
+
638
+ bool NativeWindowCocoa::InitialFocus () {
639
+ return initial_focus_;
640
+ }
641
+
621
642
void NativeWindowCocoa::HandleMouseEvent (NSEvent * event) {
622
643
if ([event type ] == NSLeftMouseDown ) {
623
644
last_mouse_location_ =
0 commit comments