Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Unified Diff: chrome/browser/android/compositor/scene_layer/toolbar_scene_layer.cc

Issue 1988023010: Toolbar is a root layer for the UI compositor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add comments Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/android/compositor/scene_layer/toolbar_scene_layer.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/compositor/scene_layer/toolbar_scene_layer.cc
diff --git a/chrome/browser/android/compositor/scene_layer/toolbar_scene_layer.cc b/chrome/browser/android/compositor/scene_layer/toolbar_scene_layer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..85f9b0cef62b6d8e59ad1fe0d11fc984708ce537
--- /dev/null
+++ b/chrome/browser/android/compositor/scene_layer/toolbar_scene_layer.cc
@@ -0,0 +1,128 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/android/compositor/scene_layer/toolbar_scene_layer.h"
+
+#include "base/android/jni_android.h"
+#include "base/android/jni_array.h"
+#include "cc/layers/solid_color_layer.h"
+#include "chrome/browser/android/compositor/layer/toolbar_layer.h"
+#include "content/public/browser/android/compositor.h"
+#include "content/public/browser/android/content_view_core.h"
+#include "jni/ToolbarSceneLayer_jni.h"
+#include "ui/android/resources/resource_manager_impl.h"
+#include "ui/gfx/android/java_bitmap.h"
+
+namespace chrome {
+namespace android {
+
+ToolbarSceneLayer::ToolbarSceneLayer(JNIEnv* env, jobject jobj)
+ : SceneLayer(env, jobj),
+ should_show_background_(false),
+ background_color_(SK_ColorWHITE),
+ content_container_(cc::Layer::Create()) {
+ layer()->AddChild(content_container_);
+ layer()->SetIsDrawable(true);
+}
+
+ToolbarSceneLayer::~ToolbarSceneLayer() {
+}
+
+void ToolbarSceneLayer::UpdateToolbarLayer(
+ JNIEnv* env,
+ const JavaParamRef<jobject>& object,
+ const JavaParamRef<jobject>& jresource_manager,
+ jint toolbar_resource_id,
+ jint toolbar_background_color,
+ jint url_bar_resource_id,
+ jfloat url_bar_alpha,
+ jfloat top_offset,
+ bool visible,
+ bool show_shadow) {
+ // If the toolbar layer has not been created yet, create it.
+ if (!toolbar_layer_) {
+ ui::ResourceManager* resource_manager =
+ ui::ResourceManagerImpl::FromJavaObject(jresource_manager);
+ toolbar_layer_ = ToolbarLayer::Create(resource_manager);
+ toolbar_layer_->layer()->SetHideLayerAndSubtree(true);
+ layer_->AddChild(toolbar_layer_->layer());
+ }
+
+ toolbar_layer_->layer()->SetHideLayerAndSubtree(!visible);
+ if (visible) {
+ toolbar_layer_->layer()->SetPosition(gfx::PointF(0, top_offset));
+ // If we're at rest, hide the shadow. The Android view should be drawing.
+ bool clip_shadow = top_offset >= 0.f && !show_shadow;
+ toolbar_layer_->PushResource(toolbar_resource_id, toolbar_background_color,
+ false, SK_ColorWHITE, url_bar_resource_id,
+ url_bar_alpha, false, clip_shadow);
+ }
+}
+
+void ToolbarSceneLayer::UpdateProgressBar(JNIEnv* env,
+ const JavaParamRef<jobject>& object,
+ jint progress_bar_x,
+ jint progress_bar_y,
+ jint progress_bar_width,
+ jint progress_bar_height,
+ jint progress_bar_color,
+ jint progress_bar_background_x,
+ jint progress_bar_background_y,
+ jint progress_bar_background_width,
+ jint progress_bar_background_height,
+ jint progress_bar_background_color) {
+ if (!toolbar_layer_) return;
+ toolbar_layer_->UpdateProgressBar(progress_bar_x,
+ progress_bar_y,
+ progress_bar_width,
+ progress_bar_height,
+ progress_bar_color,
+ progress_bar_background_x,
+ progress_bar_background_y,
+ progress_bar_background_width,
+ progress_bar_background_height,
+ progress_bar_background_color);
+}
+
+void ToolbarSceneLayer::SetContentTree(
+ JNIEnv* env,
+ const JavaParamRef<jobject>& jobj,
+ const JavaParamRef<jobject>& jcontent_tree) {
+ SceneLayer* content_tree = FromJavaObject(env, jcontent_tree);
+ if (!content_tree || !content_tree->layer()) return;
+
+ if (!content_tree->layer()->parent()
+ || (content_tree->layer()->parent()->id() != content_container_->id())) {
+ // Clear out all the children of the container when the content changes.
+ // This indicates that the layout has switched.
+ content_container_->RemoveAllChildren();
+ content_container_->AddChild(content_tree->layer());
+ }
+
+ // Propagate the background color up from the content layer.
+ should_show_background_ = content_tree->ShouldShowBackground();
+ background_color_ = content_tree->GetBackgroundColor();
+}
+
+SkColor ToolbarSceneLayer::GetBackgroundColor() {
+ return background_color_;
+}
+
+bool ToolbarSceneLayer::ShouldShowBackground() {
+ return should_show_background_;
+}
+
+static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& jobj) {
+ // This will automatically bind to the Java object and pass ownership there.
+ ToolbarSceneLayer* toolbar_scene_layer =
+ new ToolbarSceneLayer(env, jobj);
+ return reinterpret_cast<intptr_t>(toolbar_scene_layer);
+}
+
+bool RegisterToolbarSceneLayer(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+} // namespace android
+} // namespace chrome
« no previous file with comments | « chrome/browser/android/compositor/scene_layer/toolbar_scene_layer.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698