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.
5 #include "chrome/browser/android/compositor/scene_layer/reader_mode_scene_layer.h"
7 #include "base/android/jni_android.h"
8 #include "chrome/browser/android/compositor/layer/reader_mode_layer.h"
9 #include "content/public/browser/android/content_view_core.h"
10 #include "jni/ReaderModeSceneLayer_jni.h"
11 #include "ui/android/resources/resource_manager_impl.h"
16 ReaderModeSceneLayer::ReaderModeSceneLayer(JNIEnv
* env
, jobject jobj
)
17 : SceneLayer(env
, jobj
) {
20 ReaderModeSceneLayer::~ReaderModeSceneLayer() {
23 void ReaderModeSceneLayer::UpdateReaderModeLayer(
26 jint panel_background_resource_id
,
27 jint panel_text_resource_id
,
28 jobject jreader_mode_content_view_core
,
31 jfloat panel_margin_top
,
34 jfloat distilled_height
,
36 jfloat panel_text_opacity
,
37 jint header_background_color
,
38 jobject jresource_manager
) {
39 ui::ResourceManager
* resource_manager
=
40 ui::ResourceManagerImpl::FromJavaObject(jresource_manager
);
41 // Lazily construct the reader mode layer, as the feature is only
42 // conditionally enabled.
43 if (!reader_mode_layer_
.get()) {
44 if (!resource_manager
)
46 reader_mode_layer_
= ReaderModeLayer::Create(resource_manager
);
47 layer_
->AddChild(reader_mode_layer_
->layer());
50 // NOTE(pedrosimonetti): The ContentViewCore might not exist at this time if
51 // the Reader Mode has not been requested yet. In this case,
52 // we'll pass NULL to Reader Mode's Layer Tree.
53 content::ContentViewCore
* content_view_core
=
54 !jreader_mode_content_view_core
? NULL
55 : content::ContentViewCore::GetNativeContentViewCore(
56 env
, jreader_mode_content_view_core
);
58 reader_mode_layer_
->SetProperties(
59 panel_background_resource_id
, panel_text_resource_id
,
61 panel_y
, panel_width
, panel_margin_top
, panel_height
,
62 distilled_y
, distilled_height
,
64 panel_text_opacity
, header_background_color
);
67 static jlong
Init(JNIEnv
* env
, jobject jobj
) {
68 // This will automatically bind to the Java object and pass ownership there.
69 ReaderModeSceneLayer
* tree_provider
=
70 new ReaderModeSceneLayer(env
, jobj
);
71 return reinterpret_cast<intptr_t>(tree_provider
);
74 bool RegisterReaderModeSceneLayer(JNIEnv
* env
) {
75 return RegisterNativesImpl(env
);
78 } // namespace android