Commit e61ed440 authored by Pedro Amaral's avatar Pedro Amaral Committed by Commit Bot

Unify home button across top and bottom toolbars

Bug: 903864
Change-Id: I7110ee2b0e6eab650d9388c828738ad349e20cc2
Reviewed-on: https://chromium-review.googlesource.com/c/1340791
Commit-Queue: Pedro Amaral <amaralp@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611455}
parent 13e562fd
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
android:paddingStart="@dimen/bottom_toolbar_start_padding" android:paddingStart="@dimen/bottom_toolbar_start_padding"
android:paddingEnd="@dimen/bottom_toolbar_end_padding" > android:paddingEnd="@dimen/bottom_toolbar_end_padding" >
<org.chromium.chrome.browser.toolbar.bottom.HomeButton <org.chromium.chrome.browser.toolbar.HomeButton
android:id="@+id/home_button" android:id="@+id/home_button"
style="@style/BottomToolbarButton" style="@style/BottomToolbarButton"
android:contentDescription="@string/accessibility_toolbar_btn_home" /> android:contentDescription="@string/accessibility_toolbar_btn_home" />
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
android:visibility="invisible" android:visibility="invisible"
android:contentDescription="@string/accessibility_toolbar_btn_new_tab" /> android:contentDescription="@string/accessibility_toolbar_btn_new_tab" />
<org.chromium.chrome.browser.toolbar.HomePageButton <org.chromium.chrome.browser.toolbar.HomeButton
android:id="@+id/home_button" android:id="@+id/home_button"
style="@style/ToolbarButton" style="@style/ToolbarButton"
android:src="@drawable/btn_toolbar_home" android:src="@drawable/btn_toolbar_home"
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="horizontal" > android:orientation="horizontal" >
<org.chromium.chrome.browser.toolbar.HomePageButton <org.chromium.chrome.browser.toolbar.HomeButton
android:id="@+id/home_button" android:id="@+id/home_button"
style="@style/ToolbarButton" style="@style/ToolbarButton"
android:src="@drawable/btn_toolbar_home" android:src="@drawable/btn_toolbar_home"
......
...@@ -2,16 +2,22 @@ ...@@ -2,16 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
package org.chromium.chrome.browser.toolbar.bottom; package org.chromium.chrome.browser.toolbar;
import android.content.Context; import android.content.Context;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnCreateContextMenuListener;
import org.chromium.base.ApiCompatibilityUtils; import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.toolbar.ThemeColorProvider; import org.chromium.chrome.browser.partnercustomizations.HomepageManager;
import org.chromium.chrome.browser.toolbar.ThemeColorProvider.ThemeColorObserver; import org.chromium.chrome.browser.toolbar.ThemeColorProvider.ThemeColorObserver;
import org.chromium.chrome.browser.util.FeatureUtilities; import org.chromium.chrome.browser.util.FeatureUtilities;
import org.chromium.ui.widget.ChromeImageButton; import org.chromium.ui.widget.ChromeImageButton;
...@@ -19,7 +25,11 @@ import org.chromium.ui.widget.ChromeImageButton; ...@@ -19,7 +25,11 @@ import org.chromium.ui.widget.ChromeImageButton;
/** /**
* The home button. * The home button.
*/ */
class HomeButton extends ChromeImageButton implements ThemeColorObserver { public class HomeButton extends ChromeImageButton implements ThemeColorObserver,
OnCreateContextMenuListener,
MenuItem.OnMenuItemClickListener {
private static final int ID_REMOVE = 0;
/** A provider that notifies components when the theme color changes.*/ /** A provider that notifies components when the theme color changes.*/
private ThemeColorProvider mThemeColorProvider; private ThemeColorProvider mThemeColorProvider;
...@@ -30,22 +40,38 @@ class HomeButton extends ChromeImageButton implements ThemeColorObserver { ...@@ -30,22 +40,38 @@ class HomeButton extends ChromeImageButton implements ThemeColorObserver {
? R.drawable.ic_home ? R.drawable.ic_home
: R.drawable.btn_toolbar_home; : R.drawable.btn_toolbar_home;
setImageDrawable(ContextCompat.getDrawable(context, homeButtonIcon)); setImageDrawable(ContextCompat.getDrawable(context, homeButtonIcon));
if (!FeatureUtilities.isNewTabPageButtonEnabled()
&& !FeatureUtilities.isBottomToolbarEnabled()) {
setOnCreateContextMenuListener(this);
}
} }
void setThemeColorProvider(ThemeColorProvider themeColorProvider) { public void destroy() {
mThemeColorProvider = themeColorProvider;
mThemeColorProvider.addObserver(this);
}
void destroy() {
if (mThemeColorProvider != null) { if (mThemeColorProvider != null) {
mThemeColorProvider.removeObserver(this); mThemeColorProvider.removeObserver(this);
mThemeColorProvider = null; mThemeColorProvider = null;
} }
} }
public void setThemeColorProvider(ThemeColorProvider themeColorProvider) {
mThemeColorProvider = themeColorProvider;
mThemeColorProvider.addObserver(this);
}
@Override @Override
public void onThemeColorChanged(ColorStateList tint, int primaryColor) { public void onThemeColorChanged(ColorStateList tint, int primaryColor) {
ApiCompatibilityUtils.setImageTintList(this, tint); ApiCompatibilityUtils.setImageTintList(this, tint);
} }
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
menu.add(Menu.NONE, ID_REMOVE, Menu.NONE, R.string.remove).setOnMenuItemClickListener(this);
}
@Override
public boolean onMenuItemClick(MenuItem item) {
assert item.getItemId() == ID_REMOVE;
HomepageManager.getInstance().setPrefHomepageEnabled(false);
return true;
}
} }
// Copyright 2015 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.toolbar;
import android.content.Context;
import android.util.AttributeSet;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnCreateContextMenuListener;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.partnercustomizations.HomepageManager;
import org.chromium.chrome.browser.util.FeatureUtilities;
import org.chromium.ui.widget.ChromeImageButton;
/**
* View that displays the home page button.
*/
public class HomePageButton extends ChromeImageButton
implements OnCreateContextMenuListener, MenuItem.OnMenuItemClickListener {
private static final int ID_REMOVE = 0;
/** Constructor inflating from XML. */
public HomePageButton(Context context, AttributeSet attrs) {
super(context, attrs);
if (!FeatureUtilities.isNewTabPageButtonEnabled()) setOnCreateContextMenuListener(this);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
menu.add(Menu.NONE, ID_REMOVE, Menu.NONE, R.string.remove)
.setOnMenuItemClickListener(this);
}
@Override
public boolean onMenuItemClick(MenuItem item) {
assert item.getItemId() == ID_REMOVE;
HomepageManager.getInstance().setPrefHomepageEnabled(false);
return true;
}
}
...@@ -19,6 +19,7 @@ import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager; ...@@ -19,6 +19,7 @@ import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager;
import org.chromium.chrome.browser.modelutil.PropertyModelChangeProcessor; import org.chromium.chrome.browser.modelutil.PropertyModelChangeProcessor;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.TabModelSelector; import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.toolbar.HomeButton;
import org.chromium.chrome.browser.toolbar.MenuButton; import org.chromium.chrome.browser.toolbar.MenuButton;
import org.chromium.chrome.browser.toolbar.TabCountProvider; import org.chromium.chrome.browser.toolbar.TabCountProvider;
import org.chromium.chrome.browser.toolbar.TabSwitcherButtonCoordinator; import org.chromium.chrome.browser.toolbar.TabSwitcherButtonCoordinator;
......
...@@ -45,7 +45,6 @@ import org.chromium.chrome.browser.toolbar.MenuButton; ...@@ -45,7 +45,6 @@ import org.chromium.chrome.browser.toolbar.MenuButton;
import org.chromium.chrome.browser.toolbar.TabCountProvider; import org.chromium.chrome.browser.toolbar.TabCountProvider;
import org.chromium.chrome.browser.toolbar.ToolbarDataProvider; import org.chromium.chrome.browser.toolbar.ToolbarDataProvider;
import org.chromium.chrome.browser.toolbar.ToolbarTabController; import org.chromium.chrome.browser.toolbar.ToolbarTabController;
import org.chromium.chrome.browser.util.FeatureUtilities;
import org.chromium.chrome.browser.util.ViewUtils; import org.chromium.chrome.browser.util.ViewUtils;
import org.chromium.chrome.browser.widget.PulseDrawable; import org.chromium.chrome.browser.widget.PulseDrawable;
import org.chromium.chrome.browser.widget.ToolbarProgressBar; import org.chromium.chrome.browser.widget.ToolbarProgressBar;
...@@ -958,15 +957,4 @@ public abstract class ToolbarLayout extends FrameLayout { ...@@ -958,15 +957,4 @@ public abstract class ToolbarLayout extends FrameLayout {
* it. * it.
*/ */
void setTabModelSelector(TabModelSelector selector) {} void setTabModelSelector(TabModelSelector selector) {}
/**
* Sets the icon drawable for the ntp button if the ntp button feature is enabled.
* Note: This method is called twice in ToolbarLayout's children - once in
* #onNativeLibraryReady() & once in #onFinishInflate() (see https://crbug.com/862887).
* @param ntpButton The button that needs to be changed.
*/
void changeIconToNTPIcon(ImageButton ntpButton) {
if (FeatureUtilities.isNewTabPageButtonEnabled())
ntpButton.setImageResource(R.drawable.ic_home);
}
} }
...@@ -382,7 +382,6 @@ public class ToolbarPhone ...@@ -382,7 +382,6 @@ public class ToolbarPhone
mToolbarButtonsContainer = (ViewGroup) findViewById(R.id.toolbar_buttons); mToolbarButtonsContainer = (ViewGroup) findViewById(R.id.toolbar_buttons);
mHomeButton = findViewById(R.id.home_button); mHomeButton = findViewById(R.id.home_button);
changeIconToNTPIcon(mHomeButton);
if (FeatureUtilities.isBottomToolbarEnabled()) { if (FeatureUtilities.isBottomToolbarEnabled()) {
disableMenuButton(); disableMenuButton();
if (mHomeButton != null) { if (mHomeButton != null) {
...@@ -510,7 +509,6 @@ public class ToolbarPhone ...@@ -510,7 +509,6 @@ public class ToolbarPhone
if (!FeatureUtilities.isBottomToolbarEnabled()) enableTabSwitchingResources(); if (!FeatureUtilities.isBottomToolbarEnabled()) enableTabSwitchingResources();
if (mHomeButton != null) { if (mHomeButton != null) {
changeIconToNTPIcon(mHomeButton);
mHomeButton.setOnClickListener(this); mHomeButton.setOnClickListener(this);
} }
......
...@@ -105,7 +105,6 @@ public class ToolbarTablet extends ToolbarLayout ...@@ -105,7 +105,6 @@ public class ToolbarTablet extends ToolbarLayout
mLocationBar = (LocationBarTablet) findViewById(R.id.location_bar); mLocationBar = (LocationBarTablet) findViewById(R.id.location_bar);
mHomeButton = findViewById(R.id.home_button); mHomeButton = findViewById(R.id.home_button);
changeIconToNTPIcon(mHomeButton);
mBackButton = findViewById(R.id.back_button); mBackButton = findViewById(R.id.back_button);
mForwardButton = findViewById(R.id.forward_button); mForwardButton = findViewById(R.id.forward_button);
mReloadButton = findViewById(R.id.refresh_button); mReloadButton = findViewById(R.id.refresh_button);
...@@ -163,7 +162,6 @@ public class ToolbarTablet extends ToolbarLayout ...@@ -163,7 +162,6 @@ public class ToolbarTablet extends ToolbarLayout
public void onNativeLibraryReady() { public void onNativeLibraryReady() {
super.onNativeLibraryReady(); super.onNativeLibraryReady();
mLocationBar.onNativeLibraryReady(); mLocationBar.onNativeLibraryReady();
changeIconToNTPIcon(mHomeButton);
mHomeButton.setOnClickListener(this); mHomeButton.setOnClickListener(this);
mHomeButton.setOnKeyListener(new KeyboardNavigationListener() { mHomeButton.setOnKeyListener(new KeyboardNavigationListener() {
@Override @Override
......
...@@ -1577,7 +1577,7 @@ chrome_java_sources = [ ...@@ -1577,7 +1577,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/tabmodel/document/StorageDelegate.java", "java/src/org/chromium/chrome/browser/tabmodel/document/StorageDelegate.java",
"java/src/org/chromium/chrome/browser/tabmodel/document/TabDelegate.java", "java/src/org/chromium/chrome/browser/tabmodel/document/TabDelegate.java",
"java/src/org/chromium/chrome/browser/tasks/TasksUma.java", "java/src/org/chromium/chrome/browser/tasks/TasksUma.java",
"java/src/org/chromium/chrome/browser/toolbar/HomePageButton.java", "java/src/org/chromium/chrome/browser/toolbar/HomeButton.java",
"java/src/org/chromium/chrome/browser/toolbar/IncognitoStateProvider.java", "java/src/org/chromium/chrome/browser/toolbar/IncognitoStateProvider.java",
"java/src/org/chromium/chrome/browser/toolbar/IncognitoToggleTabLayout.java", "java/src/org/chromium/chrome/browser/toolbar/IncognitoToggleTabLayout.java",
"java/src/org/chromium/chrome/browser/toolbar/KeyboardNavigationListener.java", "java/src/org/chromium/chrome/browser/toolbar/KeyboardNavigationListener.java",
...@@ -1600,7 +1600,6 @@ chrome_java_sources = [ ...@@ -1600,7 +1600,6 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/toolbar/bottom/BrowsingModeBottomToolbarMediator.java", "java/src/org/chromium/chrome/browser/toolbar/bottom/BrowsingModeBottomToolbarMediator.java",
"java/src/org/chromium/chrome/browser/toolbar/bottom/BrowsingModeBottomToolbarModel.java", "java/src/org/chromium/chrome/browser/toolbar/bottom/BrowsingModeBottomToolbarModel.java",
"java/src/org/chromium/chrome/browser/toolbar/bottom/BrowsingModeBottomToolbarViewBinder.java", "java/src/org/chromium/chrome/browser/toolbar/bottom/BrowsingModeBottomToolbarViewBinder.java",
"java/src/org/chromium/chrome/browser/toolbar/bottom/HomeButton.java",
"java/src/org/chromium/chrome/browser/toolbar/bottom/ScrollingBottomViewResourceFrameLayout.java", "java/src/org/chromium/chrome/browser/toolbar/bottom/ScrollingBottomViewResourceFrameLayout.java",
"java/src/org/chromium/chrome/browser/toolbar/bottom/SearchAccelerator.java", "java/src/org/chromium/chrome/browser/toolbar/bottom/SearchAccelerator.java",
"java/src/org/chromium/chrome/browser/toolbar/bottom/ShareButton.java", "java/src/org/chromium/chrome/browser/toolbar/bottom/ShareButton.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