File: toolbar_swipe_scene_layer.cc

package info (click to toggle)
chromium 135.0.7049.95-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,959,392 kB
  • sloc: cpp: 34,198,526; ansic: 7,100,035; javascript: 3,985,800; python: 1,395,489; asm: 896,754; xml: 722,891; pascal: 180,504; sh: 94,909; perl: 88,388; objc: 79,739; sql: 53,020; cs: 41,358; fortran: 24,137; makefile: 22,501; php: 13,699; tcl: 10,142; yacc: 8,822; ruby: 7,350; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; awk: 197; sed: 36
file content (86 lines) | stat: -rw-r--r-- 2,883 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright 2021 The Chromium Authors
// 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_swipe_scene_layer.h"

#include "chrome/browser/android/compositor/layer/content_layer.h"
#include "chrome/browser/android/compositor/tab_content_manager.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/size.h"

// Must come after all headers that specialize FromJniType() / ToJniType().
#include "chrome/android/chrome_jni_headers/ToolbarSwipeSceneLayer_jni.h"

using base::android::JavaParamRef;
using base::android::JavaRef;

namespace android {

ToolbarSwipeSceneLayer::ToolbarSwipeSceneLayer(JNIEnv* env,
                                               const JavaRef<jobject>& jobj)
    : SceneLayer(env, jobj),
      left_content_layer_(nullptr),
      right_content_layer_(nullptr),
      tab_content_manager_(nullptr) {}

ToolbarSwipeSceneLayer::~ToolbarSwipeSceneLayer() = default;

void ToolbarSwipeSceneLayer::UpdateLayer(
    JNIEnv* env,
    const base::android::JavaParamRef<jobject>& jobj,
    jint id,
    jboolean left_tab,
    jboolean can_use_live_layer,
    jint default_background_color,
    jfloat x,
    jfloat y) {
  background_color_ = default_background_color;
  ContentLayer* content_layer =
      left_tab ? left_content_layer_.get() : right_content_layer_.get();
  if (!content_layer)
    return;

  // Update layer visibility based on whether there is a valid tab ID.
  content_layer->layer()->SetHideLayerAndSubtree(id < 0);

  if (id < 0)
    return;

  content_layer->SetProperties(id, can_use_live_layer,
                               can_use_live_layer ? 0.0f : 1.0f, false, 1.0f,
                               1.0f, false, gfx::Rect());
  content_layer->layer()->SetPosition(gfx::PointF(x, y));
}

void ToolbarSwipeSceneLayer::SetTabContentManager(
    JNIEnv* env,
    const base::android::JavaParamRef<jobject>& jobj,
    const base::android::JavaParamRef<jobject>& jtab_content_manager) {
  tab_content_manager_ =
      TabContentManager::FromJavaObject(jtab_content_manager);

  left_content_layer_ = ContentLayer::Create(tab_content_manager_);
  layer()->AddChild(left_content_layer_->layer());

  right_content_layer_ = ContentLayer::Create(tab_content_manager_);
  layer()->AddChild(right_content_layer_->layer());
}

bool ToolbarSwipeSceneLayer::ShouldShowBackground() {
  return true;
}

SkColor ToolbarSwipeSceneLayer::GetBackgroundColor() {
  return background_color_;
}

static jlong JNI_ToolbarSwipeSceneLayer_Init(
    JNIEnv* env,
    const JavaParamRef<jobject>& jobj) {
  // This will automatically bind to the Java object and pass ownership there.
  ToolbarSwipeSceneLayer* scene_layer = new ToolbarSwipeSceneLayer(env, jobj);
  return reinterpret_cast<intptr_t>(scene_layer);
}

}  // namespace android