Skip to content

Commit 576259c

Browse files
committed
Win: implement 'focus' property of Window to set initial focus
Fix nwjs#424
1 parent 4953a61 commit 576259c

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/browser/native_window_win.cc

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,10 @@ NativeWindowWin::NativeWindowWin(const base::WeakPtr<content::Shell>& shell,
246246
menu_(NULL),
247247
resizable_(true),
248248
minimum_size_(0, 0),
249-
maximum_size_() {
249+
maximum_size_(),
250+
initial_focus_(true) {
251+
manifest->GetBoolean("focus", &initial_focus_);
252+
250253
window_ = new views::Widget;
251254
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
252255
params.delegate = this;
@@ -287,9 +290,13 @@ void NativeWindowWin::Focus(bool focus) {
287290
}
288291

289292
void NativeWindowWin::Show() {
293+
VLOG(1) << "NativeWindowWin::Show(); initial_focus = " << initial_focus_;
290294
if (is_maximized_)
291295
window_->native_widget_private()->ShowWithWindowState(ui::SHOW_STATE_MAXIMIZED);
292-
else
296+
else if (!initial_focus_) {
297+
window_->set_focus_on_creation(false);
298+
window_->native_widget_private()->ShowWithWindowState(ui::SHOW_STATE_INACTIVE);
299+
} else
293300
window_->native_widget_private()->Show();
294301
}
295302

@@ -604,6 +611,10 @@ void NativeWindowWin::OnFocus() {
604611
web_view_->RequestFocus();
605612
}
606613

614+
void NativeWindowWin::SetInitialFocus(bool initial_focus) {
615+
initial_focus_ = initial_focus;
616+
}
617+
607618
bool NativeWindowWin::ExecuteWindowsCommand(int command_id) {
608619
// Windows uses the 4 lower order bits of |command_id| for type-specific
609620
// information so we must exclude this when comparing.

src/browser/native_window_win.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ class NativeWindowWin : public NativeWindow,
7979
bool enabled) OVERRIDE;
8080
virtual void SetToolbarUrlEntry(const std::string& url) OVERRIDE;
8181
virtual void SetToolbarIsLoading(bool loading) OVERRIDE;
82+
virtual void SetInitialFocus(bool initial_focus) OVERRIDE;
83+
virtual bool InitialFocus() OVERRIDE { return initial_focus_; }
8284

8385
// WidgetDelegate implementation.
8486
virtual views::View* GetContentsView() OVERRIDE;
@@ -146,6 +148,8 @@ class NativeWindowWin : public NativeWindow,
146148
gfx::Size minimum_size_;
147149
gfx::Size maximum_size_;
148150

151+
bool initial_focus_;
152+
149153
DISALLOW_COPY_AND_ASSIGN(NativeWindowWin);
150154
};
151155

0 commit comments

Comments
 (0)