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 android.content.Context; |
| 8 import android.content.res.Resources; |
| 9 import android.graphics.Rect; |
| 10 |
| 11 import com.google.android.apps.chrome.R; |
| 12 |
| 13 import org.chromium.base.JNINamespace; |
| 14 import org.chromium.chrome.browser.compositor.LayerTitleCache; |
| 15 import org.chromium.chrome.browser.compositor.layouts.Layout; |
| 16 import org.chromium.chrome.browser.compositor.layouts.Layout.Orientation; |
| 17 import org.chromium.chrome.browser.compositor.layouts.components.LayoutTab; |
| 18 import org.chromium.chrome.browser.compositor.layouts.content.TabContentManager; |
| 19 import org.chromium.chrome.browser.tab.ChromeTab; |
| 20 import org.chromium.ui.resources.ResourceManager; |
| 21 |
| 22 /** |
| 23 * A SceneLayer to render a tab stack. |
| 24 * TODO(changwan): change layouts to share one instance of this. |
| 25 */ |
| 26 @JNINamespace("chrome::android") |
| 27 public class TabListSceneLayer extends SceneLayer { |
| 28 private long mNativePtr; |
| 29 |
| 30 /** |
| 31 * Sets a content tree inside this scene overlay tree. |
| 32 * |
| 33 * TODO(changwan): use SceneOverlayTree's setContentTree() once we have refa
ctored |
| 34 * ContextualSearchSupportedLayout into LayoutHelper. |
| 35 * |
| 36 * @param contentTree A content tree. |
| 37 */ |
| 38 public void setContentTree(SceneLayer contentTree) { |
| 39 nativeSetContentTree(mNativePtr, contentTree); |
| 40 } |
| 41 |
| 42 /** |
| 43 * Pushes all relevant {@link LayoutTab}s from a {@link Layout} to the CC La
yer tree. This will |
| 44 * let them be rendered on the screen. This should only be called when the
Compositor has |
| 45 * disabled ScheduleComposite calls as this will change the tree and could s
ubsequently cause |
| 46 * unnecessary follow up renders. |
| 47 * @param context The {@link Context} to use to query device informa
tion. |
| 48 * @param layout The {@link Layout} to push to the screen. |
| 49 */ |
| 50 public void pushLayers(Context context, Rect viewport, Rect contentViewport,
Layout layout, |
| 51 LayerTitleCache layerTitleCache, TabContentManager tabContentManager
, |
| 52 ResourceManager resourceManager) { |
| 53 if (mNativePtr == 0) return; |
| 54 |
| 55 Resources res = context.getResources(); |
| 56 final float dpToPx = res.getDisplayMetrics().density; |
| 57 |
| 58 LayoutTab[] tabs = layout.getLayoutTabsToRender(); |
| 59 int tabsCount = tabs != null ? tabs.length : 0; |
| 60 |
| 61 nativeBeginBuildingFrame(mNativePtr); |
| 62 for (int i = 0; i < tabsCount; i++) { |
| 63 LayoutTab t = tabs[i]; |
| 64 assert t.isVisible() : "LayoutTab in that list should be visible"; |
| 65 final float decoration = t.getDecorationAlpha(); |
| 66 |
| 67 int borderResource = t.isIncognito() ? R.drawable.tabswitcher_border
_frame_incognito |
| 68 : R.drawable.tabswitcher_border
_frame; |
| 69 int closeBtnResource = t.isIncognito() ? R.drawable.btn_tab_close_wh
ite_normal |
| 70 : R.drawable.btn_tab_close_no
rmal; |
| 71 int borderColorResource = |
| 72 t.isIncognito() ? R.color.tab_back_incognito : R.color.tab_b
ack; |
| 73 // TODO(dtrainor, clholgat): remove "* dpToPx" once the native part
fully supports dp. |
| 74 nativePutLayer(mNativePtr, t.getId(), R.id.control_container, closeB
tnResource, |
| 75 R.drawable.tabswitcher_border_frame_shadow, |
| 76 R.drawable.tabswitcher_border_frame_decoration, R.drawable.l
ogo_card_back, |
| 77 borderResource, t.canUseLiveTexture(), |
| 78 (t.getFallbackThumbnailId() == ChromeTab.NTP_TAB_ID), t.getB
ackgroundColor(), |
| 79 context.getResources().getColor(R.color.tab_switcher_backgro
und), |
| 80 res.getColor(borderColorResource), t.isIncognito(), |
| 81 layout.getOrientation() == Orientation.PORTRAIT, t.getRender
X() * dpToPx, |
| 82 t.getRenderY() * dpToPx, t.getScaledContentWidth() * dpToPx, |
| 83 t.getScaledContentHeight() * dpToPx, t.getOriginalContentWid
th() * dpToPx, |
| 84 t.getOriginalContentHeight() * dpToPx, contentViewport.heigh
t(), viewport.left, |
| 85 viewport.top, viewport.width(), viewport.height(), t.getClip
pedX() * dpToPx, |
| 86 t.getClippedY() * dpToPx, |
| 87 Math.min(t.getClippedWidth(), t.getScaledContentWidth()) * d
pToPx, |
| 88 Math.min(t.getClippedHeight(), t.getScaledContentHeight()) *
dpToPx, |
| 89 t.getTiltXPivotOffset() * dpToPx, t.getTiltYPivotOffset() *
dpToPx, |
| 90 t.getTiltX(), t.getTiltY(), t.getAlpha(), t.getBorderAlpha()
* decoration, |
| 91 decoration, t.getShadowOpacity() * decoration, |
| 92 t.getBorderCloseButtonAlpha() * decoration, |
| 93 LayoutTab.CLOSE_BUTTON_WIDTH_DP * dpToPx, t.getStaticToViewB
lend(), |
| 94 t.getBorderScale(), t.getSaturation(), t.getBrightness(), t.
showToolbar(), |
| 95 t.anonymizeToolbar(), t.getToolbarAlpha(), t.getToolbarYOffs
et() * dpToPx, |
| 96 t.getSideBorderScale(), true, t.insetBorderVertical(), layer
TitleCache, |
| 97 tabContentManager, resourceManager); |
| 98 } |
| 99 nativeFinishBuildingFrame(mNativePtr); |
| 100 } |
| 101 |
| 102 @Override |
| 103 protected void initializeNative() { |
| 104 if (mNativePtr == 0) { |
| 105 mNativePtr = nativeInit(); |
| 106 } |
| 107 assert mNativePtr != 0; |
| 108 } |
| 109 |
| 110 /** |
| 111 * Destroys this object and the corresponding native component. |
| 112 */ |
| 113 @Override |
| 114 public void destroy() { |
| 115 super.destroy(); |
| 116 mNativePtr = 0; |
| 117 } |
| 118 |
| 119 private native long nativeInit(); |
| 120 private native void nativeSetContentTree(long nativeTabListSceneLayer, Scene
Layer contentTree); |
| 121 private native void nativeBeginBuildingFrame(long nativeTabListSceneLayer); |
| 122 private native void nativeFinishBuildingFrame(long nativeTabListSceneLayer); |
| 123 private native void nativePutLayer(long nativeTabListSceneLayer, int id, int
toolbarResourceId, |
| 124 int closeButtonResourceId, int shadowResourceId, int contourResource
Id, |
| 125 int backLogoResourceId, int borderResourceId, boolean canUseLiveLaye
r, |
| 126 boolean canUseNtpFallback, int tabBackgroundColor, int backgroundCol
or, |
| 127 int backLogoColor, boolean incognito, boolean isPortrait, float x, f
loat y, float width, |
| 128 float height, float contentWidth, float contentHeight, float visible
ContentHeight, |
| 129 float viewportX, float viewportY, float viewportWidth, float viewpor
tHeight, |
| 130 float shadowX, float shadowY, float shadowWidth, float shadowHeight,
float pivotX, |
| 131 float pivotY, float rotationX, float rotationY, float alpha, float b
orderAlpha, |
| 132 float contourAlpha, float shadowAlpha, float closeAlpha, float close
BtnWidth, |
| 133 float staticToViewBlend, float borderScale, float saturation, float
brightness, |
| 134 boolean showToolbar, boolean anonymizeToolbar, float toolbarAlpha, f
loat toolbarYOffset, |
| 135 float sideBorderScale, boolean attachContent, boolean insetVerticalB
order, |
| 136 LayerTitleCache layerTitleCache, TabContentManager tabContentManager
, |
| 137 ResourceManager resourceManager); |
| 138 } |
OLD | NEW |