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
|
// Copyright 2015 The Chromium 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 "chrome/browser/android/transition_page_helper.h"
#include "cc/layers/layer.h"
#include "chrome/browser/android/tab_android.h"
#include "chrome/browser/ui/android/window_android_helper.h"
#include "content/public/browser/android/content_view_core.h"
#include "content/public/browser/web_contents.h"
#include "jni/TransitionPageHelper_jni.h"
// TODO(simonhatch): Why does 1.f opacity seem to kill per-pixel alpha?
const float TRANSITION_MAX_OPACITY = 0.99999f;
TransitionPageHelper* TransitionPageHelper::FromJavaObject(JNIEnv* env,
jobject jobj) {
return reinterpret_cast<TransitionPageHelper*>(
Java_TransitionPageHelper_getNativePtr(env, jobj));
}
TransitionPageHelper::TransitionPageHelper() {
}
TransitionPageHelper::~TransitionPageHelper() {
}
void TransitionPageHelper::Destroy(JNIEnv* env, jobject jobj) {
delete this;
}
void TransitionPageHelper::SetWebContents(JNIEnv* env,
jobject jobj,
jobject jcontent_view_core) {
content::ContentViewCore* content_view_core =
content::ContentViewCore::GetNativeContentViewCore(env,
jcontent_view_core);
DCHECK(content_view_core);
DCHECK(content_view_core->GetWebContents());
web_contents_.reset(content_view_core->GetWebContents());
}
void TransitionPageHelper::ReleaseWebContents(JNIEnv* env, jobject jobj) {
DCHECK(web_contents_.get());
web_contents_.reset();
}
void TransitionPageHelper::SetOpacity(JNIEnv* env,
jobject jobj,
jobject jcontent_view_core,
jfloat opacity) {
content::ContentViewCore* content_view_core =
content::ContentViewCore::GetNativeContentViewCore(env,
jcontent_view_core);
if (!content_view_core)
return;
content_view_core->GetLayer()->SetOpacity(
std::min(opacity, TRANSITION_MAX_OPACITY));
}
static jlong Init(JNIEnv* env, jobject obj) {
return reinterpret_cast<long>(new TransitionPageHelper());
}
bool TransitionPageHelper::Register(JNIEnv* env) {
return RegisterNativesImpl(env);
}
|