OLD | NEW |
| (Empty) |
1 // Copyright 2016 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 org.chromium.base.annotations.JNINamespace; | |
8 import org.chromium.chrome.R; | |
9 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel; | |
10 import org.chromium.content_public.browser.WebContents; | |
11 import org.chromium.ui.resources.ResourceManager; | |
12 | |
13 /** | |
14 * A SceneLayer to render layers for Reader Mode. | |
15 */ | |
16 @JNINamespace("android") | |
17 public class ReaderModeSceneLayer extends SceneOverlayLayer { | |
18 /** Pointer to native ReaderModeSceneLayer. */ | |
19 private long mNativePtr; | |
20 | |
21 /** If the scene layer has been initialized. */ | |
22 private boolean mIsInitialized; | |
23 | |
24 /** The conversion multiple from dp to px. */ | |
25 private final float mDpToPx; | |
26 | |
27 /** | |
28 * @param dpToPx The conversion multiple from dp to px for the device. | |
29 */ | |
30 public ReaderModeSceneLayer(float dpToPx) { | |
31 mDpToPx = dpToPx; | |
32 } | |
33 | |
34 /** | |
35 * Update the scene layer to draw an OverlayPanel. | |
36 * @param resourceManager Manager to get view and image resources. | |
37 * @param panel The OverlayPanel to render. | |
38 * @param barTextViewId The ID of the view containing the Reader Mode text. | |
39 * @param barTextOpacity The opacity of the text specified by {@code barText
ViewId}. | |
40 */ | |
41 public void update(ResourceManager resourceManager, OverlayPanel panel, int
barTextViewId, | |
42 float barTextOpacity) { | |
43 // Don't try to update the layer if not initialized or showing. | |
44 if (resourceManager == null || !panel.isShowing()) return; | |
45 | |
46 if (!mIsInitialized) { | |
47 nativeCreateReaderModeLayer(mNativePtr, resourceManager); | |
48 // TODO(mdjones): Rename contextual search resources below to be gen
eric to overlay | |
49 // panels. | |
50 nativeSetResourceIds(mNativePtr, | |
51 barTextViewId, | |
52 R.drawable.contextual_search_bar_background, | |
53 R.drawable.contextual_search_bar_shadow, | |
54 R.drawable.infobar_mobile_friendly, | |
55 R.drawable.btn_close); | |
56 mIsInitialized = true; | |
57 } | |
58 | |
59 WebContents panelWebContents = panel.getContentViewCore() != null | |
60 ? panel.getContentViewCore().getWebContents() : null; | |
61 | |
62 nativeUpdate(mNativePtr, | |
63 mDpToPx, | |
64 panel.getBasePageBrightness(), | |
65 panel.getBasePageY() * mDpToPx, | |
66 panelWebContents, | |
67 panel.getOffsetX() * mDpToPx, | |
68 panel.getOffsetY() * mDpToPx, | |
69 panel.getWidth() * mDpToPx, | |
70 panel.getHeight() * mDpToPx, | |
71 panel.getBarMarginSide() * mDpToPx, | |
72 panel.getBarHeight() * mDpToPx, | |
73 barTextOpacity, | |
74 panel.isBarBorderVisible(), | |
75 panel.getBarBorderHeight() * mDpToPx, | |
76 panel.getBarShadowVisible(), | |
77 panel.getBarShadowOpacity()); | |
78 } | |
79 | |
80 @Override | |
81 public void setContentTree(SceneLayer contentTree) { | |
82 nativeSetContentTree(mNativePtr, contentTree); | |
83 } | |
84 | |
85 /** | |
86 * Hide the layer tree; for use if the panel is not being shown. | |
87 */ | |
88 public void hideTree() { | |
89 if (!mIsInitialized) return; | |
90 nativeHideTree(mNativePtr); | |
91 } | |
92 | |
93 @Override | |
94 protected void initializeNative() { | |
95 if (mNativePtr == 0) { | |
96 mNativePtr = nativeInit(); | |
97 } | |
98 assert mNativePtr != 0; | |
99 } | |
100 | |
101 /** | |
102 * Destroys this object and the corresponding native component. | |
103 */ | |
104 @Override | |
105 public void destroy() { | |
106 super.destroy(); | |
107 mIsInitialized = false; | |
108 mNativePtr = 0; | |
109 } | |
110 | |
111 private native long nativeInit(); | |
112 private native void nativeCreateReaderModeLayer( | |
113 long nativeReaderModeSceneLayer, | |
114 ResourceManager resourceManager); | |
115 private native void nativeSetContentTree( | |
116 long nativeReaderModeSceneLayer, | |
117 SceneLayer contentTree); | |
118 private native void nativeHideTree( | |
119 long nativeReaderModeSceneLayer); | |
120 private native void nativeSetResourceIds( | |
121 long nativeReaderModeSceneLayer, | |
122 int barTextResourceId, | |
123 int barBackgroundResourceId, | |
124 int barShadowResourceId, | |
125 int panelIconResourceId, | |
126 int closeIconResourceId); | |
127 private native void nativeUpdate( | |
128 long nativeReaderModeSceneLayer, | |
129 float dpToPx, | |
130 float basePageBrightness, | |
131 float basePageYOffset, | |
132 WebContents webContents, | |
133 float panelX, | |
134 float panelY, | |
135 float panelWidth, | |
136 float panelHeight, | |
137 float barMarginSide, | |
138 float barHeight, | |
139 float textOpacity, | |
140 boolean barBorderVisible, | |
141 float barBorderHeight, | |
142 boolean barShadowVisible, | |
143 float barShadowOpacity); | |
144 } | |
OLD | NEW |