| 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 #include "chrome/browser/android/compositor/scene_layer/toolbar_scene_layer.h" |
| 6 |
| 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_array.h" |
| 9 #include "cc/layers/solid_color_layer.h" |
| 10 #include "chrome/browser/android/compositor/layer/toolbar_layer.h" |
| 11 #include "content/public/browser/android/compositor.h" |
| 12 #include "content/public/browser/android/content_view_core.h" |
| 13 #include "jni/ToolbarSceneLayer_jni.h" |
| 14 #include "ui/android/resources/resource_manager_impl.h" |
| 15 #include "ui/gfx/android/java_bitmap.h" |
| 16 |
| 17 namespace chrome { |
| 18 namespace android { |
| 19 |
| 20 ToolbarSceneLayer::ToolbarSceneLayer(JNIEnv* env, jobject jobj) |
| 21 : SceneLayer(env, jobj), |
| 22 should_show_background_(false), |
| 23 background_color_(SK_ColorWHITE), |
| 24 content_container_(cc::Layer::Create()) { |
| 25 layer()->AddChild(content_container_); |
| 26 layer()->SetIsDrawable(true); |
| 27 } |
| 28 |
| 29 ToolbarSceneLayer::~ToolbarSceneLayer() { |
| 30 } |
| 31 |
| 32 void ToolbarSceneLayer::UpdateToolbarLayer( |
| 33 JNIEnv* env, |
| 34 const JavaParamRef<jobject>& object, |
| 35 const JavaParamRef<jobject>& jresource_manager, |
| 36 jint toolbar_resource_id, |
| 37 jint toolbar_background_color, |
| 38 jint url_bar_resource_id, |
| 39 jfloat url_bar_alpha, |
| 40 jfloat top_offset, |
| 41 bool visible, |
| 42 bool show_shadow) { |
| 43 // If the toolbar layer has not been created yet, create it. |
| 44 if (!toolbar_layer_) { |
| 45 ui::ResourceManager* resource_manager = |
| 46 ui::ResourceManagerImpl::FromJavaObject(jresource_manager); |
| 47 toolbar_layer_ = ToolbarLayer::Create(resource_manager); |
| 48 toolbar_layer_->layer()->SetHideLayerAndSubtree(true); |
| 49 layer_->AddChild(toolbar_layer_->layer()); |
| 50 } |
| 51 |
| 52 toolbar_layer_->layer()->SetHideLayerAndSubtree(!visible); |
| 53 if (visible) { |
| 54 toolbar_layer_->layer()->SetPosition(gfx::PointF(0, top_offset)); |
| 55 // If we're at rest, hide the shadow. The Android view should be drawing. |
| 56 bool clip_shadow = top_offset >= 0.f && !show_shadow; |
| 57 toolbar_layer_->PushResource(toolbar_resource_id, toolbar_background_color, |
| 58 false, SK_ColorWHITE, url_bar_resource_id, |
| 59 url_bar_alpha, false, clip_shadow); |
| 60 } |
| 61 } |
| 62 |
| 63 void ToolbarSceneLayer::UpdateProgressBar(JNIEnv* env, |
| 64 const JavaParamRef<jobject>& object, |
| 65 jint progress_bar_x, |
| 66 jint progress_bar_y, |
| 67 jint progress_bar_width, |
| 68 jint progress_bar_height, |
| 69 jint progress_bar_color, |
| 70 jint progress_bar_background_x, |
| 71 jint progress_bar_background_y, |
| 72 jint progress_bar_background_width, |
| 73 jint progress_bar_background_height, |
| 74 jint progress_bar_background_color) { |
| 75 if (!toolbar_layer_) return; |
| 76 toolbar_layer_->UpdateProgressBar(progress_bar_x, |
| 77 progress_bar_y, |
| 78 progress_bar_width, |
| 79 progress_bar_height, |
| 80 progress_bar_color, |
| 81 progress_bar_background_x, |
| 82 progress_bar_background_y, |
| 83 progress_bar_background_width, |
| 84 progress_bar_background_height, |
| 85 progress_bar_background_color); |
| 86 } |
| 87 |
| 88 void ToolbarSceneLayer::SetContentTree( |
| 89 JNIEnv* env, |
| 90 const JavaParamRef<jobject>& jobj, |
| 91 const JavaParamRef<jobject>& jcontent_tree) { |
| 92 SceneLayer* content_tree = FromJavaObject(env, jcontent_tree); |
| 93 if (!content_tree || !content_tree->layer()) return; |
| 94 |
| 95 if (!content_tree->layer()->parent() |
| 96 || (content_tree->layer()->parent()->id() != content_container_->id())) { |
| 97 // Clear out all the children of the container when the content changes. |
| 98 // This indicates that the layout has switched. |
| 99 content_container_->RemoveAllChildren(); |
| 100 content_container_->AddChild(content_tree->layer()); |
| 101 } |
| 102 |
| 103 // Propagate the background color up from the content layer. |
| 104 should_show_background_ = content_tree->ShouldShowBackground(); |
| 105 background_color_ = content_tree->GetBackgroundColor(); |
| 106 } |
| 107 |
| 108 SkColor ToolbarSceneLayer::GetBackgroundColor() { |
| 109 return background_color_; |
| 110 } |
| 111 |
| 112 bool ToolbarSceneLayer::ShouldShowBackground() { |
| 113 return should_show_background_; |
| 114 } |
| 115 |
| 116 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& jobj) { |
| 117 // This will automatically bind to the Java object and pass ownership there. |
| 118 ToolbarSceneLayer* toolbar_scene_layer = |
| 119 new ToolbarSceneLayer(env, jobj); |
| 120 return reinterpret_cast<intptr_t>(toolbar_scene_layer); |
| 121 } |
| 122 |
| 123 bool RegisterToolbarSceneLayer(JNIEnv* env) { |
| 124 return RegisterNativesImpl(env); |
| 125 } |
| 126 |
| 127 } // namespace android |
| 128 } // namespace chrome |
| OLD | NEW |