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 package org.chromium.chrome.browser.compositor.scene_layer; |
| 6 |
| 7 import com.google.android.apps.chrome.R; |
| 8 |
| 9 import org.chromium.base.JNINamespace; |
| 10 import org.chromium.chrome.browser.dom_distiller.ReaderModePanel; |
| 11 import org.chromium.content.browser.ContentViewCore; |
| 12 import org.chromium.ui.resources.ResourceManager; |
| 13 |
| 14 /** |
| 15 * A SceneLayer to render layers for ReaderModeLayout. |
| 16 */ |
| 17 @JNINamespace("chrome::android") |
| 18 public class ReaderModeSceneLayer extends SceneLayer { |
| 19 |
| 20 // NOTE: If you use SceneLayer's native pointer here, the JNI generator will
try to |
| 21 // downcast using reinterpret_cast<>. We keep a separate pointer to avoid it
. |
| 22 private long mNativePtr; |
| 23 |
| 24 private final float mDpToPx; |
| 25 |
| 26 public ReaderModeSceneLayer(float dpToPx) { |
| 27 mDpToPx = dpToPx; |
| 28 } |
| 29 |
| 30 /** |
| 31 * Update reader mode's layer tree using the parameters. |
| 32 * |
| 33 * @param panel |
| 34 * @param resourceManager |
| 35 */ |
| 36 public void update(ReaderModePanel panel, ResourceManager resourceManager) { |
| 37 if (panel == null) return; |
| 38 if (!panel.isShowing()) return; |
| 39 |
| 40 nativeUpdateReaderModeLayer(mNativePtr, |
| 41 R.drawable.reader_mode_bar_background, R.id.reader_mode_view, |
| 42 panel.didFirstNonEmptyDistilledPaint() ? panel.getDistilledConte
ntViewCore() : null, |
| 43 panel.getPanelY() * mDpToPx, |
| 44 panel.getWidth() * mDpToPx, |
| 45 panel.getMarginTop() * mDpToPx, |
| 46 panel.getPanelHeight() * mDpToPx, |
| 47 panel.getDistilledContentY() * mDpToPx, |
| 48 panel.getDistilledHeight() * mDpToPx, |
| 49 panel.getX() * mDpToPx, |
| 50 panel.getTextOpacity(), |
| 51 panel.getReaderModeHeaderBackgroundColor(), |
| 52 resourceManager); |
| 53 } |
| 54 |
| 55 @Override |
| 56 protected void initializeNative() { |
| 57 if (mNativePtr == 0) { |
| 58 mNativePtr = nativeInit(); |
| 59 } |
| 60 assert mNativePtr != 0; |
| 61 } |
| 62 |
| 63 /** |
| 64 * Destroys this object and the corresponding native component. |
| 65 */ |
| 66 @Override |
| 67 public void destroy() { |
| 68 super.destroy(); |
| 69 mNativePtr = 0; |
| 70 } |
| 71 |
| 72 private native long nativeInit(); |
| 73 private native void nativeUpdateReaderModeLayer(long nativeReaderModeSceneLa
yer, |
| 74 int panelBackgroundResourceId, int panelTextResourceId, |
| 75 ContentViewCore readerModeContentViewCore, |
| 76 float panelY, float panelWidth, float panelMarginTop, float panelHei
ght, |
| 77 float distilledY, float distilledHeight, |
| 78 float x, |
| 79 float panelTextOpacity, int headerBackgroundColor, |
| 80 ResourceManager resourceManager); |
| 81 } |
OLD | NEW |