Commit 35fab120 authored by Ted Choc's avatar Ted Choc Committed by Commit Bot

Allow full infobar text to be clickable if it contains a single span.

On Android, the InfoBar text layout is handled by Android, which
causes the click region fo the links to be very small.  For InfoBar
messages with a single clickable span, this enables the full text to
be clickable.

BUG=670340

Change-Id: I1cc2dd0ffd34a583ae2040859b003c33c2e12baf
Reviewed-on: https://chromium-review.googlesource.com/1114002
Commit-Queue: Ted Choc <tedchoc@chromium.org>
Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570136}
parent ecbec4dd
......@@ -3,7 +3,7 @@
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<org.chromium.ui.widget.TextViewWithClickableSpans
<org.chromium.chrome.browser.infobar.InfoBarMessageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/infobar_message"
android:layout_width="match_parent"
......
......@@ -22,7 +22,6 @@ import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.Callback;
import org.chromium.chrome.R;
import org.chromium.ui.text.NoUnderlineClickableSpan;
import org.chromium.ui.widget.TextViewWithClickableSpans;
/**
* Lays out controls along a line, sandwiched between an (optional) icon and close button.
......@@ -164,7 +163,7 @@ public class InfoBarCompactLayout extends LinearLayout implements View.OnClickLi
builder.append(mMessage);
if (mLink != null) builder.append(" ").append(mLink);
TextView prompt = new TextViewWithClickableSpans(mLayout.getContext());
TextView prompt = new InfoBarMessageView(mLayout.getContext());
ApiCompatibilityUtils.setTextAppearance(prompt, R.style.BlackBodyDefault);
prompt.setText(builder);
prompt.setGravity(Gravity.CENTER_VERTICAL);
......
// Copyright 2018 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.
package org.chromium.chrome.browser.infobar;
import android.content.Context;
import android.support.annotation.CallSuper;
import android.text.style.ClickableSpan;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.OnClickListener;
import org.chromium.ui.widget.TextViewWithClickableSpans;
/**
* Handles the additional message view responsibilities needed for InfoBars.
* - Makes the full text view clickable if there is just a single link.
*/
public class InfoBarMessageView extends TextViewWithClickableSpans implements OnClickListener {
public InfoBarMessageView(Context context) {
super(context);
}
public InfoBarMessageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@CallSuper
@Override
public void setText(CharSequence text, BufferType type) {
super.setText(text, type);
ClickableSpan[] spans = getClickableSpans();
setOnClickListener(spans != null && spans.length == 1 ? this : null);
}
@Override
public void onClick(View v) {
ClickableSpan[] spans = getClickableSpans();
if (spans == null || spans.length != 1) {
assert false : "Click listener should not be registered with more than 1 span";
return;
}
spans[0].onClick(this);
}
}
......@@ -623,6 +623,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/infobar/InfoBarContainerLayout.java",
"java/src/org/chromium/chrome/browser/infobar/InfoBarControlLayout.java",
"java/src/org/chromium/chrome/browser/infobar/InfoBarLayout.java",
"java/src/org/chromium/chrome/browser/infobar/InfoBarMessageView.java",
"java/src/org/chromium/chrome/browser/infobar/InfoBarView.java",
"java/src/org/chromium/chrome/browser/infobar/InfoBarWrapper.java",
"java/src/org/chromium/chrome/browser/infobar/InstallableAmbientBadgeInfoBar.java",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment