// Copyright 2014 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.widget;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.PorterDuff;
import android.util.AttributeSet;
import android.widget.ImageButton;

import org.chromium.chrome.R;

/**
 * Implementation of ImageButton that allows to tint the color of the image button for all
 * image button states using chrome:tint attribute in XML.
 */
public class TintedImageButton extends ImageButton {
    private ColorStateList mTint;

    public TintedImageButton(Context context) {
        super(context);
    }

    public TintedImageButton(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs, 0);
    }

    public TintedImageButton(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(context, attrs, defStyle);
    }

    private void init(Context context, AttributeSet attrs, int defStyle) {
        TypedArray a = context.obtainStyledAttributes(
                attrs, R.styleable.TintedImage, defStyle, 0);
        setTintInternal(a.getColorStateList(R.styleable.TintedImage_tint));
        a.recycle();
    }

    @Override
    protected void drawableStateChanged() {
        super.drawableStateChanged();
        updateTintColor();
    }

    /**
     * Sets the tint color for the given ImageButton for all button states.
     * @param tint The set of colors to use to color the ImageButton.
     */
    public void setTint(ColorStateList tint) {
        if (mTint == tint) return;
        setTintInternal(tint);
        updateTintColor();
    }

    private void setTintInternal(ColorStateList tint) {
        mTint = tint;
    }

    private void updateTintColor() {
        if (mTint == null) return;
        setColorFilter(mTint.getColorForState(getDrawableState(), 0), PorterDuff.Mode.SRC_IN);
    }
}

@@ -699,16 +699,87 @@
 t mTint;
+%0A    private PorterDuff.Mode mColorFilterMode = PorterDuff.Mode.SRC_IN;
 %0A%0A    pu
@@ -1887,32 +1887,351 @@
 Color();%0A    %7D%0A%0A
+    /**%0A     * Sets the Porter-Duff mode to use when tinting the image.%0A     * @param mode The porterduff mode to use to set color filter.%0A     */%0A    public void setColorFilterMode(PorterDuff.Mode mode) %7B%0A        if (mColorFilterMode == mode) return;%0A        mColorFilterMode = mode;%0A        updateTintColor();%0A    %7D%0A%0A
     private void
@@ -2262,32 +2262,32 @@
 ateList tint) %7B%0A
-
         mTint = 
@@ -2441,38 +2441,32 @@
 (), 0), 
-PorterDuff.Mode.SRC_IN
+mColorFilterMode
 );%0A    %7D

Make it possible to set porterduff mode to TintedImageButton