forked from chromiumembedded/java-cef
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfocus_handler.cpp
More file actions
79 lines (69 loc) · 2.31 KB
/
Copy pathfocus_handler.cpp
File metadata and controls
79 lines (69 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright (c) 2014 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "focus_handler.h"
#include "include/base/cef_bind.h"
#include "include/wrapper/cef_closure_task.h"
#include "client_handler.h"
#include "jni_util.h"
#include "util.h"
FocusHandler::FocusHandler(JNIEnv* env, jobject handler) {
jhandler_ = env->NewGlobalRef(handler);
}
FocusHandler::~FocusHandler() {
JNIEnv* env = GetJNIEnv();
env->DeleteGlobalRef(jhandler_);
}
void FocusHandler::OnTakeFocus(CefRefPtr<CefBrowser> browser, bool next) {
JNIEnv* env = GetJNIEnv();
if (!env)
return;
JNI_CALL_VOID_METHOD(env, jhandler_, "onTakeFocus",
"(Lorg/cef/browser/CefBrowser;Z)V",
GetJNIBrowser(browser), (jboolean)next);
}
#if defined(OS_WIN)
static void FocusParent(HWND browserHandle) {
HWND parent = GetParent(browserHandle);
SetActiveWindow(parent);
SetFocus(parent);
}
#endif
bool FocusHandler::OnSetFocus(CefRefPtr<CefBrowser> browser,
FocusSource source) {
JNIEnv* env = GetJNIEnv();
if (!env)
return false;
jboolean jreturn = JNI_FALSE;
jobject jsource = NULL;
switch (source) {
JNI_CASE(env, "org/cef/handler/CefFocusHandler$FocusSource",
FOCUS_SOURCE_NAVIGATION, jsource);
default:
JNI_CASE(env, "org/cef/handler/CefFocusHandler$FocusSource",
FOCUS_SOURCE_SYSTEM, jsource);
}
JNI_CALL_METHOD(env, jhandler_, "onSetFocus",
"(Lorg/cef/browser/CefBrowser;Lorg/cef/handler/"
"CefFocusHandler$FocusSource;)Z",
Boolean, jreturn, GetJNIBrowser(browser), jsource);
bool result = (jreturn != JNI_FALSE);
#if defined(OS_WIN)
if (result) {
HWND browserHandle = browser->GetHost()->GetWindowHandle();
if (CefCurrentlyOn(TID_UI))
FocusParent(browserHandle);
else
CefPostTask(TID_UI, base::Bind(&FocusParent, browserHandle));
}
#endif
return result;
}
void FocusHandler::OnGotFocus(CefRefPtr<CefBrowser> browser) {
JNIEnv* env = GetJNIEnv();
if (!env)
return;
JNI_CALL_VOID_METHOD(env, jhandler_, "onGotFocus",
"(Lorg/cef/browser/CefBrowser;)V",
GetJNIBrowser(browser));
}