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
67 lines (58 loc) · 2.08 KB
/
Copy pathfocus_handler.cpp
File metadata and controls
67 lines (58 loc) · 2.08 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
// 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"
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;
jobject jbrowser = GetJNIBrowser(browser);
JNI_CALL_VOID_METHOD(env, jhandler_, "onTakeFocus",
"(Lorg/cef/browser/CefBrowser;Z)V",
jbrowser, (jboolean)next);
env->DeleteLocalRef(jbrowser);
}
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);
}
jobject jbrowser = GetJNIBrowser(browser);
JNI_CALL_METHOD(env, jhandler_, "onSetFocus",
"(Lorg/cef/browser/CefBrowser;Lorg/cef/handler/"
"CefFocusHandler$FocusSource;)Z",
Boolean, jreturn, jbrowser, jsource);
env->DeleteLocalRef(jbrowser);
env->DeleteLocalRef(jsource);
return (jreturn != JNI_FALSE);
}
void FocusHandler::OnGotFocus(CefRefPtr<CefBrowser> browser) {
JNIEnv* env = GetJNIEnv();
if (!env)
return;
jobject jbrowser = GetJNIBrowser(browser);
JNI_CALL_VOID_METHOD(env, jhandler_, "onGotFocus",
"(Lorg/cef/browser/CefBrowser;)V",
jbrowser);
env->DeleteLocalRef(jbrowser);
}