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

cc / input / android / offset_tag_android.cc [blame]

// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cc/input/android/offset_tag_android.h"

#include "base/android/scoped_java_ref.h"
#include "base/android/token_android.h"
#include "base/logging.h"
#include "base/token.h"
#include "cc/cc_jni_headers/BrowserControlsOffsetTagsInfo_jni.h"
#include "cc/cc_jni_headers/OffsetTag_jni.h"
#include "cc/input/browser_controls_offset_tags_info.h"
#include "components/viz/common/quads/offset_tag.h"

namespace cc::android {

viz::OffsetTag FromJavaOffsetTag(
    JNIEnv* env,
    const base::android::JavaRef<jobject>& joffset_tag) {
  if (!joffset_tag) {
    return viz::OffsetTag();
  }
  const base::android::JavaRef<jobject>& jtoken =
      Java_OffsetTag_getToken(env, joffset_tag);
  base::Token token = base::android::TokenAndroid::FromJavaToken(env, jtoken);
  return viz::OffsetTag(token);
}

cc::BrowserControlsOffsetTagsInfo FromJavaBrowserControlsOffsetTagsInfo(
    JNIEnv* env,
    const base::android::JavaRef<jobject>& jbrowser_controls_offset_tags_info) {
  cc::BrowserControlsOffsetTagsInfo tags_info;
  if (!jbrowser_controls_offset_tags_info) {
    return tags_info;
  }

  const base::android::JavaRef<jobject>& jbottom_controls_offset_tag =
      Java_BrowserControlsOffsetTagsInfo_getBottomControlsOffsetTag(
          env, jbrowser_controls_offset_tags_info);
  viz::OffsetTag bottom_controls_offset_tag =
      FromJavaOffsetTag(env, jbottom_controls_offset_tag);
  tags_info.bottom_controls_offset_tag = bottom_controls_offset_tag;

  const base::android::JavaRef<jobject>& jcontent_offset_tag =
      Java_BrowserControlsOffsetTagsInfo_getContentOffsetTag(
          env, jbrowser_controls_offset_tags_info);
  viz::OffsetTag content_offset_tag =
      FromJavaOffsetTag(env, jcontent_offset_tag);
  tags_info.content_offset_tag = content_offset_tag;

  const base::android::JavaRef<jobject>& jtop_controls_offset_tag =
      Java_BrowserControlsOffsetTagsInfo_getTopControlsOffsetTag(
          env, jbrowser_controls_offset_tags_info);
  viz::OffsetTag top_controls_offset_tag =
      FromJavaOffsetTag(env, jtop_controls_offset_tag);
  tags_info.top_controls_offset_tag = top_controls_offset_tag;

  tags_info.bottom_controls_height =
      Java_BrowserControlsOffsetTagsInfo_getBottomControlsHeight(
          env, jbrowser_controls_offset_tags_info);

  tags_info.bottom_controls_additional_height =
      Java_BrowserControlsOffsetTagsInfo_getBottomControlsAdditionalHeight(
          env, jbrowser_controls_offset_tags_info);

  tags_info.top_controls_height =
      Java_BrowserControlsOffsetTagsInfo_getTopControlsHeight(
          env, jbrowser_controls_offset_tags_info);

  tags_info.top_controls_hairline_height =
      Java_BrowserControlsOffsetTagsInfo_getTopControlsHairlineHeight(
          env, jbrowser_controls_offset_tags_info);

  return tags_info;
}

}  // namespace cc::android