| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/android/transition_page_helper.h" | |
| 6 | |
| 7 #include "cc/layers/layer.h" | |
| 8 #include "chrome/browser/android/tab_android.h" | |
| 9 #include "chrome/browser/ui/android/window_android_helper.h" | |
| 10 #include "content/public/browser/android/content_view_core.h" | |
| 11 #include "content/public/browser/web_contents.h" | |
| 12 #include "jni/TransitionPageHelper_jni.h" | |
| 13 | |
| 14 // TODO(simonhatch): Why does 1.f opacity seem to kill per-pixel alpha? | |
| 15 const float TRANSITION_MAX_OPACITY = 0.99999f; | |
| 16 | |
| 17 TransitionPageHelper* TransitionPageHelper::FromJavaObject(JNIEnv* env, | |
| 18 jobject jobj) { | |
| 19 return reinterpret_cast<TransitionPageHelper*>( | |
| 20 Java_TransitionPageHelper_getNativePtr(env, jobj)); | |
| 21 } | |
| 22 | |
| 23 TransitionPageHelper::TransitionPageHelper() { | |
| 24 } | |
| 25 | |
| 26 TransitionPageHelper::~TransitionPageHelper() { | |
| 27 } | |
| 28 | |
| 29 void TransitionPageHelper::Destroy(JNIEnv* env, jobject jobj) { | |
| 30 delete this; | |
| 31 } | |
| 32 | |
| 33 void TransitionPageHelper::SetWebContents(JNIEnv* env, | |
| 34 jobject jobj, | |
| 35 jobject jcontent_view_core) { | |
| 36 content::ContentViewCore* content_view_core = | |
| 37 content::ContentViewCore::GetNativeContentViewCore(env, | |
| 38 jcontent_view_core); | |
| 39 DCHECK(content_view_core); | |
| 40 DCHECK(content_view_core->GetWebContents()); | |
| 41 | |
| 42 web_contents_.reset(content_view_core->GetWebContents()); | |
| 43 } | |
| 44 | |
| 45 void TransitionPageHelper::ReleaseWebContents(JNIEnv* env, jobject jobj) { | |
| 46 DCHECK(web_contents_.get()); | |
| 47 web_contents_.reset(); | |
| 48 } | |
| 49 | |
| 50 void TransitionPageHelper::SetOpacity(JNIEnv* env, | |
| 51 jobject jobj, | |
| 52 jobject jcontent_view_core, | |
| 53 jfloat opacity) { | |
| 54 content::ContentViewCore* content_view_core = | |
| 55 content::ContentViewCore::GetNativeContentViewCore(env, | |
| 56 jcontent_view_core); | |
| 57 if (!content_view_core) | |
| 58 return; | |
| 59 | |
| 60 content_view_core->GetLayer()->SetOpacity( | |
| 61 std::min(opacity, TRANSITION_MAX_OPACITY)); | |
| 62 } | |
| 63 | |
| 64 static jlong Init(JNIEnv* env, jobject obj) { | |
| 65 return reinterpret_cast<long>(new TransitionPageHelper()); | |
| 66 } | |
| 67 | |
| 68 bool TransitionPageHelper::Register(JNIEnv* env) { | |
| 69 return RegisterNativesImpl(env); | |
| 70 } | |
| OLD | NEW |