Commit 1e358c58 authored by Josh Pratt's avatar Josh Pratt Committed by Commit Bot

Refactor LocationBarView to move Refresh logic for some BubbleIconViews into...

Refactor LocationBarView to move Refresh logic for some BubbleIconViews into the respective subclasses.

This is initial work for adding BubbleIconViews to Chrome OS Desktop PWAs.
It partially decouples BubbleIconViews from the LocationBarView so that
they can also be used in HostedAppButtonContainer.

Bug: 788051
Change-Id: I986951b64fb02f2d2728abbe6a3964ff97e04909
Reviewed-on: https://chromium-review.googlesource.com/923607
Commit-Queue: Trent Apted <tapted@chromium.org>
Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Reviewed-by: default avatarcalamity <calamity@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542045}
parent 53ef4fcc
...@@ -8,27 +8,28 @@ ...@@ -8,27 +8,28 @@
#include "chrome/app/vector_icons/vector_icons.h" #include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h" #include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_command_controller.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/view_ids.h" #include "chrome/browser/ui/view_ids.h"
#include "chrome/browser/ui/views/autofill/save_card_bubble_views.h" #include "chrome/browser/ui/views/autofill/save_card_bubble_views.h"
#include "chrome/browser/ui/views/location_bar/bubble_icon_view.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
namespace autofill { namespace autofill {
SaveCardIconView::SaveCardIconView(CommandUpdater* command_updater, SaveCardIconView::SaveCardIconView(CommandUpdater* command_updater,
Browser* browser) Browser* browser,
: BubbleIconView(command_updater, IDC_SAVE_CREDIT_CARD_FOR_PAGE), BubbleIconView::Delegate* delegate)
: BubbleIconView(command_updater, IDC_SAVE_CREDIT_CARD_FOR_PAGE, delegate),
browser_(browser) { browser_(browser) {
DCHECK(delegate);
set_id(VIEW_ID_SAVE_CREDIT_CARD_BUTTON); set_id(VIEW_ID_SAVE_CREDIT_CARD_BUTTON);
SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_SAVE_CREDIT_CARD)); SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_SAVE_CREDIT_CARD));
} }
SaveCardIconView::~SaveCardIconView() {} SaveCardIconView::~SaveCardIconView() {}
void SaveCardIconView::OnExecuting(
BubbleIconView::ExecuteSource execute_source) {}
views::BubbleDialogDelegateView* SaveCardIconView::GetBubble() const { views::BubbleDialogDelegateView* SaveCardIconView::GetBubble() const {
SaveCardBubbleControllerImpl* controller = GetController(); SaveCardBubbleControllerImpl* controller = GetController();
if (!controller) if (!controller)
...@@ -38,6 +39,24 @@ views::BubbleDialogDelegateView* SaveCardIconView::GetBubble() const { ...@@ -38,6 +39,24 @@ views::BubbleDialogDelegateView* SaveCardIconView::GetBubble() const {
controller->save_card_bubble_view()); controller->save_card_bubble_view());
} }
bool SaveCardIconView::Refresh() {
if (!GetWebContents())
return false;
const bool was_visible = visible();
// |controller| may be nullptr due to lazy initialization.
SaveCardBubbleControllerImpl* controller = GetController();
bool enabled = controller && controller->IsIconVisible();
enabled &= SetCommandEnabled(enabled);
SetVisible(enabled);
return was_visible != visible();
}
void SaveCardIconView::OnExecuting(
BubbleIconView::ExecuteSource execute_source) {}
const gfx::VectorIcon& SaveCardIconView::GetVectorIcon() const { const gfx::VectorIcon& SaveCardIconView::GetVectorIcon() const {
return kCreditCardIcon; return kCreditCardIcon;
} }
...@@ -45,8 +64,8 @@ const gfx::VectorIcon& SaveCardIconView::GetVectorIcon() const { ...@@ -45,8 +64,8 @@ const gfx::VectorIcon& SaveCardIconView::GetVectorIcon() const {
SaveCardBubbleControllerImpl* SaveCardIconView::GetController() const { SaveCardBubbleControllerImpl* SaveCardIconView::GetController() const {
if (!browser_) if (!browser_)
return nullptr; return nullptr;
content::WebContents* web_contents = content::WebContents* web_contents = GetWebContents();
browser_->tab_strip_model()->GetActiveWebContents();
if (!web_contents) if (!web_contents)
return nullptr; return nullptr;
return autofill::SaveCardBubbleControllerImpl::FromWebContents(web_contents); return autofill::SaveCardBubbleControllerImpl::FromWebContents(web_contents);
......
...@@ -20,13 +20,18 @@ class SaveCardBubbleControllerImpl; ...@@ -20,13 +20,18 @@ class SaveCardBubbleControllerImpl;
// it. // it.
class SaveCardIconView : public BubbleIconView { class SaveCardIconView : public BubbleIconView {
public: public:
SaveCardIconView(CommandUpdater* command_updater, Browser* browser); SaveCardIconView(CommandUpdater* command_updater,
Browser* browser,
BubbleIconView::Delegate* delegate);
~SaveCardIconView() override; ~SaveCardIconView() override;
// BubbleIconView:
views::BubbleDialogDelegateView* GetBubble() const override;
bool Refresh() override;
protected: protected:
// BubbleIconView: // BubbleIconView:
void OnExecuting(BubbleIconView::ExecuteSource execute_source) override; void OnExecuting(BubbleIconView::ExecuteSource execute_source) override;
views::BubbleDialogDelegateView* GetBubble() const override;
const gfx::VectorIcon& GetVectorIcon() const override; const gfx::VectorIcon& GetVectorIcon() const override;
private: private:
......
...@@ -28,10 +28,13 @@ void BubbleIconView::Init() { ...@@ -28,10 +28,13 @@ void BubbleIconView::Init() {
SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY);
} }
BubbleIconView::BubbleIconView(CommandUpdater* command_updater, int command_id) BubbleIconView::BubbleIconView(CommandUpdater* command_updater,
int command_id,
BubbleIconView::Delegate* delegate)
: widget_observer_(this), : widget_observer_(this),
image_(new views::ImageView()), image_(new views::ImageView()),
command_updater_(command_updater), command_updater_(command_updater),
delegate_(delegate),
command_id_(command_id), command_id_(command_id),
active_(false), active_(false),
suppress_mouse_released_action_(false) {} suppress_mouse_released_action_(false) {}
...@@ -44,6 +47,12 @@ bool BubbleIconView::IsBubbleShowing() const { ...@@ -44,6 +47,12 @@ bool BubbleIconView::IsBubbleShowing() const {
return GetBubble() != nullptr; return GetBubble() != nullptr;
} }
bool BubbleIconView::SetCommandEnabled(bool enabled) const {
DCHECK(command_updater_);
command_updater_->UpdateCommandEnabled(command_id_, enabled);
return command_updater_->IsCommandEnabled(command_id_);
}
void BubbleIconView::SetImage(const gfx::ImageSkia* image_skia) { void BubbleIconView::SetImage(const gfx::ImageSkia* image_skia) {
image_->SetImage(image_skia); image_->SetImage(image_skia);
} }
...@@ -69,6 +78,10 @@ void BubbleIconView::OnBubbleWidgetCreated(views::Widget* bubble_widget) { ...@@ -69,6 +78,10 @@ void BubbleIconView::OnBubbleWidgetCreated(views::Widget* bubble_widget) {
SetHighlighted(true); SetHighlighted(true);
} }
bool BubbleIconView::Refresh() {
return false;
}
void BubbleIconView::GetAccessibleNodeData(ui::AXNodeData* node_data) { void BubbleIconView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
image_->GetAccessibleNodeData(node_data); image_->GetAccessibleNodeData(node_data);
node_data->role = ax::mojom::Role::kButton; node_data->role = ax::mojom::Role::kButton;
...@@ -240,6 +253,10 @@ void BubbleIconView::SetActiveInternal(bool active) { ...@@ -240,6 +253,10 @@ void BubbleIconView::SetActiveInternal(bool active) {
UpdateIcon(); UpdateIcon();
} }
content::WebContents* BubbleIconView::GetWebContents() const {
return delegate_->GetWebContentsForBubbleIconView();
}
BubbleIconView::WidgetObserver::WidgetObserver(BubbleIconView* parent) BubbleIconView::WidgetObserver::WidgetObserver(BubbleIconView* parent)
: parent_(parent), scoped_observer_(this) {} : parent_(parent), scoped_observer_(this) {}
......
...@@ -16,6 +16,10 @@ ...@@ -16,6 +16,10 @@
class CommandUpdater; class CommandUpdater;
namespace content {
class WebContents;
}
namespace gfx { namespace gfx {
struct VectorIcon; struct VectorIcon;
} }
...@@ -28,6 +32,11 @@ class BubbleDialogDelegateView; ...@@ -28,6 +32,11 @@ class BubbleDialogDelegateView;
// TODO(spqchan): Convert this to subclass Button. // TODO(spqchan): Convert this to subclass Button.
class BubbleIconView : public views::InkDropHostView { class BubbleIconView : public views::InkDropHostView {
public: public:
class Delegate {
public:
virtual content::WebContents* GetWebContentsForBubbleIconView() = 0;
};
void Init(); void Init();
// Invoked when a bubble for this icon is created. The BubbleIconView changes // Invoked when a bubble for this icon is created. The BubbleIconView changes
...@@ -37,6 +46,10 @@ class BubbleIconView : public views::InkDropHostView { ...@@ -37,6 +46,10 @@ class BubbleIconView : public views::InkDropHostView {
// Returns the bubble instance for the icon. // Returns the bubble instance for the icon.
virtual views::BubbleDialogDelegateView* GetBubble() const = 0; virtual views::BubbleDialogDelegateView* GetBubble() const = 0;
// Updates the icon state and associated bubble when the WebContents changes.
// Returns true if there was a change.
virtual bool Refresh();
protected: protected:
enum ExecuteSource { enum ExecuteSource {
EXECUTE_SOURCE_MOUSE, EXECUTE_SOURCE_MOUSE,
...@@ -44,12 +57,18 @@ class BubbleIconView : public views::InkDropHostView { ...@@ -44,12 +57,18 @@ class BubbleIconView : public views::InkDropHostView {
EXECUTE_SOURCE_GESTURE, EXECUTE_SOURCE_GESTURE,
}; };
BubbleIconView(CommandUpdater* command_updater, int command_id); BubbleIconView(CommandUpdater* command_updater,
int command_id,
Delegate* delegate = nullptr);
~BubbleIconView() override; ~BubbleIconView() override;
// Returns true if a related bubble is showing. // Returns true if a related bubble is showing.
bool IsBubbleShowing() const; bool IsBubbleShowing() const;
// Enables or disables the associated command.
// Returns true if the command is enabled.
bool SetCommandEnabled(bool enabled) const;
// Sets the image that should be displayed in |image_|. // Sets the image that should be displayed in |image_|.
void SetImage(const gfx::ImageSkia* image_skia); void SetImage(const gfx::ImageSkia* image_skia);
...@@ -108,6 +127,9 @@ class BubbleIconView : public views::InkDropHostView { ...@@ -108,6 +127,9 @@ class BubbleIconView : public views::InkDropHostView {
// "call to action" color. // "call to action" color.
void SetActiveInternal(bool active); void SetActiveInternal(bool active);
// Returns the associated web contents from the delegate.
content::WebContents* GetWebContents() const;
bool active() const { return active_; } bool active() const { return active_; }
private: private:
...@@ -141,6 +163,9 @@ class BubbleIconView : public views::InkDropHostView { ...@@ -141,6 +163,9 @@ class BubbleIconView : public views::InkDropHostView {
// The CommandUpdater for the Browser object that owns the location bar. // The CommandUpdater for the Browser object that owns the location bar.
CommandUpdater* command_updater_; CommandUpdater* command_updater_;
// Delegate for access to associated state.
Delegate* delegate_;
// The command ID executed when the user clicks this icon. // The command ID executed when the user clicks this icon.
const int command_id_; const int command_id_;
......
...@@ -258,15 +258,20 @@ void LocationBarView::Init() { ...@@ -258,15 +258,20 @@ void LocationBarView::Init() {
AddChildView(image_view); AddChildView(image_view);
} }
bubble_icons_.push_back(zoom_view_ = new ZoomView(delegate_)); zoom_view_ = new ZoomView(delegate_);
bubble_icons_.push_back(manage_passwords_icon_view_ = bubble_icons_.push_back(zoom_view_);
new ManagePasswordsIconViews(command_updater())); manage_passwords_icon_view_ =
if (browser_) new ManagePasswordsIconViews(command_updater(), this);
bubble_icons_.push_back( bubble_icons_.push_back(manage_passwords_icon_view_);
save_credit_card_icon_view_ =
new autofill::SaveCardIconView(command_updater(), browser_)); if (browser_) {
bubble_icons_.push_back(translate_icon_view_ = save_credit_card_icon_view_ =
new TranslateIconView(command_updater())); new autofill::SaveCardIconView(command_updater(), browser_, this);
bubble_icons_.push_back(save_credit_card_icon_view_);
}
translate_icon_view_ = new TranslateIconView(command_updater(), this);
bubble_icons_.push_back(translate_icon_view_);
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
if (browser_) if (browser_)
bubble_icons_.push_back(intent_picker_view_ = bubble_icons_.push_back(intent_picker_view_ =
...@@ -641,14 +646,19 @@ void LocationBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) { ...@@ -641,14 +646,19 @@ void LocationBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) {
void LocationBarView::Update(const WebContents* contents) { void LocationBarView::Update(const WebContents* contents) {
RefreshContentSettingViews(); RefreshContentSettingViews();
// TODO(calamity): Refactor Update to use BubbleIconView::Refresh.
RefreshZoomView(); RefreshZoomView();
RefreshTranslateIcon();
RefreshSaveCreditCardIconView(); RefreshBubbleIconViews();
RefreshManagePasswordsIconView();
// TODO(calamity): Refactor Update to use BubbleIconView::Refresh.
RefreshFindBarIcon(); RefreshFindBarIcon();
if (star_view_) if (star_view_) {
// TODO(calamity): Refactor Update to use BubbleIconView::Refresh.
UpdateBookmarkStarVisibility(); UpdateBookmarkStarVisibility();
}
if (contents) if (contents)
omnibox_view_->OnTabChanged(contents); omnibox_view_->OnTabChanged(contents);
...@@ -709,6 +719,12 @@ LocationBarView::GetContentSettingBubbleModelDelegate() { ...@@ -709,6 +719,12 @@ LocationBarView::GetContentSettingBubbleModelDelegate() {
return delegate_->GetContentSettingBubbleModelDelegate(); return delegate_->GetContentSettingBubbleModelDelegate();
} }
////////////////////////////////////////////////////////////////////////////////
// LocationBarView, public BubbleIconView::Delegate implementation:
WebContents* LocationBarView::GetWebContentsForBubbleIconView() {
return GetWebContents();
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// LocationBarView, private: // LocationBarView, private:
...@@ -770,6 +786,21 @@ bool LocationBarView::RefreshContentSettingViews() { ...@@ -770,6 +786,21 @@ bool LocationBarView::RefreshContentSettingViews() {
return visibility_changed; return visibility_changed;
} }
bool LocationBarView::RefreshBubbleIconViews() {
if (extensions::HostedAppBrowserController::IsForExperimentalHostedAppBrowser(
browser_)) {
// For hosted apps, the location bar is normally hidden and icons appear in
// the window frame instead.
GetWidget()->non_client_view()->ResetWindowControls();
}
bool visibility_changed = false;
for (auto* v : bubble_icons_) {
visibility_changed |= v->Refresh();
}
return visibility_changed;
}
bool LocationBarView::RefreshZoomView() { bool LocationBarView::RefreshZoomView() {
DCHECK(zoom_view_); DCHECK(zoom_view_);
WebContents* web_contents = GetWebContents(); WebContents* web_contents = GetWebContents();
...@@ -807,26 +838,6 @@ bool LocationBarView::IsVirtualKeyboardVisible() { ...@@ -807,26 +838,6 @@ bool LocationBarView::IsVirtualKeyboardVisible() {
#endif #endif
} }
bool LocationBarView::RefreshSaveCreditCardIconView() {
WebContents* web_contents = GetWebContents();
if (!save_credit_card_icon_view_ || !web_contents)
return false;
const bool was_visible = save_credit_card_icon_view_->visible();
// |controller| may be nullptr due to lazy initialization.
autofill::SaveCardBubbleControllerImpl* controller =
autofill::SaveCardBubbleControllerImpl::FromWebContents(web_contents);
bool enabled = controller && controller->IsIconVisible();
if (!command_updater()->UpdateCommandEnabled(
IDC_SAVE_CREDIT_CARD_FOR_PAGE, enabled)) {
enabled = enabled && command_updater()->IsCommandEnabled(
IDC_SAVE_CREDIT_CARD_FOR_PAGE);
}
save_credit_card_icon_view_->SetVisible(enabled);
return was_visible != save_credit_card_icon_view_->visible();
}
bool LocationBarView::RefreshFindBarIcon() { bool LocationBarView::RefreshFindBarIcon() {
// |browser_| may be nullptr since some unit tests pass it in for the // |browser_| may be nullptr since some unit tests pass it in for the
// Browser*. |browser_->window()| may return nullptr because Update() is // Browser*. |browser_->window()| may return nullptr because Update() is
...@@ -841,33 +852,6 @@ bool LocationBarView::RefreshFindBarIcon() { ...@@ -841,33 +852,6 @@ bool LocationBarView::RefreshFindBarIcon() {
return was_visible != find_bar_icon_->visible(); return was_visible != find_bar_icon_->visible();
} }
void LocationBarView::RefreshTranslateIcon() {
WebContents* web_contents = GetWebContents();
if (!web_contents)
return;
translate::LanguageState& language_state =
ChromeTranslateClient::FromWebContents(web_contents)->GetLanguageState();
bool enabled = language_state.translate_enabled();
if (!command_updater()->UpdateCommandEnabled(IDC_TRANSLATE_PAGE, enabled)) {
enabled = enabled && command_updater()->IsCommandEnabled(
IDC_TRANSLATE_PAGE);
}
translate_icon_view_->SetVisible(enabled);
if (!enabled)
TranslateBubbleView::CloseCurrentBubble();
}
bool LocationBarView::RefreshManagePasswordsIconView() {
DCHECK(manage_passwords_icon_view_);
WebContents* web_contents = GetWebContents();
if (!web_contents)
return false;
const bool was_visible = manage_passwords_icon_view_->visible();
ManagePasswordsUIController::FromWebContents(
web_contents)->UpdateIconAndBubbleState(manage_passwords_icon_view_);
return was_visible != manage_passwords_icon_view_->visible();
}
void LocationBarView::RefreshClearAllButtonIcon() { void LocationBarView::RefreshClearAllButtonIcon() {
if (!clear_all_button_) if (!clear_all_button_)
return; return;
...@@ -959,14 +943,14 @@ void LocationBarView::UpdateContentSettingsIcons() { ...@@ -959,14 +943,14 @@ void LocationBarView::UpdateContentSettingsIcons() {
} }
void LocationBarView::UpdateManagePasswordsIconAndBubble() { void LocationBarView::UpdateManagePasswordsIconAndBubble() {
if (RefreshManagePasswordsIconView()) { if (manage_passwords_icon_view_->Refresh()) {
Layout(); Layout();
SchedulePaint(); SchedulePaint();
} }
} }
void LocationBarView::UpdateSaveCreditCardIcon() { void LocationBarView::UpdateSaveCreditCardIcon() {
if (RefreshSaveCreditCardIconView()) { if (save_credit_card_icon_view_->Refresh()) {
Layout(); Layout();
SchedulePaint(); SchedulePaint();
} }
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "chrome/browser/ui/views/dropdown_bar_host.h" #include "chrome/browser/ui/views/dropdown_bar_host.h"
#include "chrome/browser/ui/views/dropdown_bar_host_delegate.h" #include "chrome/browser/ui/views/dropdown_bar_host_delegate.h"
#include "chrome/browser/ui/views/extensions/extension_popup.h" #include "chrome/browser/ui/views/extensions/extension_popup.h"
#include "chrome/browser/ui/views/location_bar/bubble_icon_view.h"
#include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h"
#include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h"
#include "components/prefs/pref_member.h" #include "components/prefs/pref_member.h"
...@@ -31,7 +32,6 @@ ...@@ -31,7 +32,6 @@
#include "ui/views/controls/button/button.h" #include "ui/views/controls/button/button.h"
#include "ui/views/drag_controller.h" #include "ui/views/drag_controller.h"
class BubbleIconView;
class CommandUpdater; class CommandUpdater;
class ContentSettingBubbleModelDelegate; class ContentSettingBubbleModelDelegate;
class FindBarIcon; class FindBarIcon;
...@@ -73,7 +73,8 @@ class LocationBarView : public LocationBar, ...@@ -73,7 +73,8 @@ class LocationBarView : public LocationBar,
public DropdownBarHostDelegate, public DropdownBarHostDelegate,
public zoom::ZoomEventManagerObserver, public zoom::ZoomEventManagerObserver,
public views::ButtonListener, public views::ButtonListener,
public ContentSettingImageView::Delegate { public ContentSettingImageView::Delegate,
public BubbleIconView::Delegate {
public: public:
class Delegate { class Delegate {
public: public:
...@@ -236,6 +237,9 @@ class LocationBarView : public LocationBar, ...@@ -236,6 +237,9 @@ class LocationBarView : public LocationBar,
ContentSettingBubbleModelDelegate* GetContentSettingBubbleModelDelegate() ContentSettingBubbleModelDelegate* GetContentSettingBubbleModelDelegate()
override; override;
// BubbleIconView::Delegate:
content::WebContents* GetWebContentsForBubbleIconView() override;
// ZoomEventManagerObserver: // ZoomEventManagerObserver:
// Updates the view for the zoom icon when default zoom levels change. // Updates the view for the zoom icon when default zoom levels change.
void OnDefaultZoomLevelChanged() override; void OnDefaultZoomLevelChanged() override;
...@@ -271,22 +275,19 @@ class LocationBarView : public LocationBar, ...@@ -271,22 +275,19 @@ class LocationBarView : public LocationBar,
// of at least one of the views in |content_setting_views_| changed. // of at least one of the views in |content_setting_views_| changed.
bool RefreshContentSettingViews(); bool RefreshContentSettingViews();
// Updates the visibility state of the BubbleIconView (page action) icons
// to reflect what actions are available on the current page.
// Returns true if the visibility of at least one of the views in
// |bubble_icons_| changed.
bool RefreshBubbleIconViews();
// Updates the view for the zoom icon based on the current tab's zoom. Returns // Updates the view for the zoom icon based on the current tab's zoom. Returns
// true if the visibility of the view changed. // true if the visibility of the view changed.
bool RefreshZoomView(); bool RefreshZoomView();
// Updates |save_credit_card_icon_view_|. Returns true if visibility changed.
bool RefreshSaveCreditCardIconView();
// Updates |find_bar_icon_|. Returns true if visibility changed. // Updates |find_bar_icon_|. Returns true if visibility changed.
bool RefreshFindBarIcon(); bool RefreshFindBarIcon();
// Updates the Translate icon based on the current tab's Translate status.
void RefreshTranslateIcon();
// Updates |manage_passwords_icon_view_|. Returns true if visibility changed.
bool RefreshManagePasswordsIconView();
// Updates the color of the icon for the "clear all" button. // Updates the color of the icon for the "clear all" button.
void RefreshClearAllButtonIcon(); void RefreshClearAllButtonIcon();
......
...@@ -6,17 +6,20 @@ ...@@ -6,17 +6,20 @@
#include "chrome/app/chrome_command_ids.h" #include "chrome/app/chrome_command_ids.h"
#include "chrome/app/vector_icons/vector_icons.h" #include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/command_updater.h"
#include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h"
#include "chrome/browser/ui/views/passwords/password_bubble_view_base.h" #include "chrome/browser/ui/views/passwords/password_bubble_view_base.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "components/password_manager/core/common/password_manager_ui.h" #include "components/password_manager/core/common/password_manager_ui.h"
#include "content/public/browser/web_contents.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
ManagePasswordsIconViews::ManagePasswordsIconViews(CommandUpdater* updater) ManagePasswordsIconViews::ManagePasswordsIconViews(
: BubbleIconView(updater, IDC_MANAGE_PASSWORDS_FOR_PAGE), CommandUpdater* updater,
BubbleIconView::Delegate* delegate)
: BubbleIconView(updater, IDC_MANAGE_PASSWORDS_FOR_PAGE, delegate),
state_(password_manager::ui::INACTIVE_STATE) { state_(password_manager::ui::INACTIVE_STATE) {
DCHECK(delegate);
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY);
#else #else
...@@ -56,6 +59,20 @@ void ManagePasswordsIconViews::UpdateUiForState() { ...@@ -56,6 +59,20 @@ void ManagePasswordsIconViews::UpdateUiForState() {
parent()->Layout(); parent()->Layout();
} }
views::BubbleDialogDelegateView* ManagePasswordsIconViews::GetBubble() const {
return PasswordBubbleViewBase::manage_password_bubble();
}
bool ManagePasswordsIconViews::Refresh() {
if (!GetWebContents())
return false;
const bool was_visible = visible();
ManagePasswordsUIController::FromWebContents(GetWebContents())
->UpdateIconAndBubbleState(this);
return was_visible != visible();
}
void ManagePasswordsIconViews::OnExecuting( void ManagePasswordsIconViews::OnExecuting(
BubbleIconView::ExecuteSource source) {} BubbleIconView::ExecuteSource source) {}
...@@ -79,10 +96,6 @@ bool ManagePasswordsIconViews::OnKeyPressed(const ui::KeyEvent& event) { ...@@ -79,10 +96,6 @@ bool ManagePasswordsIconViews::OnKeyPressed(const ui::KeyEvent& event) {
return BubbleIconView::OnKeyPressed(event); return BubbleIconView::OnKeyPressed(event);
} }
views::BubbleDialogDelegateView* ManagePasswordsIconViews::GetBubble() const {
return PasswordBubbleViewBase::manage_password_bubble();
}
const gfx::VectorIcon& ManagePasswordsIconViews::GetVectorIcon() const { const gfx::VectorIcon& ManagePasswordsIconViews::GetVectorIcon() const {
return kKeyIcon; return kKeyIcon;
} }
......
...@@ -18,17 +18,19 @@ class CommandUpdater; ...@@ -18,17 +18,19 @@ class CommandUpdater;
class ManagePasswordsIconViews : public ManagePasswordsIconView, class ManagePasswordsIconViews : public ManagePasswordsIconView,
public BubbleIconView { public BubbleIconView {
public: public:
explicit ManagePasswordsIconViews(CommandUpdater* updater); ManagePasswordsIconViews(CommandUpdater* updater,
BubbleIconView::Delegate* delegate);
~ManagePasswordsIconViews() override; ~ManagePasswordsIconViews() override;
// ManagePasswordsIconView: // ManagePasswordsIconView:
void SetState(password_manager::ui::State state) override; void SetState(password_manager::ui::State state) override;
// BubbleIconView: // BubbleIconView:
views::BubbleDialogDelegateView* GetBubble() const override;
bool Refresh() override;
void OnExecuting(BubbleIconView::ExecuteSource source) override; void OnExecuting(BubbleIconView::ExecuteSource source) override;
bool OnMousePressed(const ui::MouseEvent& event) override; bool OnMousePressed(const ui::MouseEvent& event) override;
bool OnKeyPressed(const ui::KeyEvent& event) override; bool OnKeyPressed(const ui::KeyEvent& event) override;
views::BubbleDialogDelegateView* GetBubble() const override;
const gfx::VectorIcon& GetVectorIcon() const override; const gfx::VectorIcon& GetVectorIcon() const override;
// views::View: // views::View:
......
...@@ -8,33 +8,56 @@ ...@@ -8,33 +8,56 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h" #include "chrome/app/chrome_command_ids.h"
#include "chrome/app/vector_icons/vector_icons.h" #include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/ui/browser_command_controller.h"
#include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/translate/translate_bubble_view_state_transition.h" #include "chrome/browser/ui/translate/translate_bubble_view_state_transition.h"
#include "chrome/browser/ui/view_ids.h" #include "chrome/browser/ui/view_ids.h"
#include "chrome/browser/ui/views/translate/translate_bubble_view.h" #include "chrome/browser/ui/views/translate/translate_bubble_view.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "components/translate/core/browser/language_state.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
TranslateIconView::TranslateIconView(CommandUpdater* command_updater) TranslateIconView::TranslateIconView(CommandUpdater* command_updater,
: BubbleIconView(command_updater, IDC_TRANSLATE_PAGE) { BubbleIconView::Delegate* delegate)
: BubbleIconView(command_updater, IDC_TRANSLATE_PAGE, delegate) {
DCHECK(delegate);
set_id(VIEW_ID_TRANSLATE_BUTTON); set_id(VIEW_ID_TRANSLATE_BUTTON);
SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_TRANSLATE)); SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_TRANSLATE));
} }
TranslateIconView::~TranslateIconView() {} TranslateIconView::~TranslateIconView() {}
views::BubbleDialogDelegateView* TranslateIconView::GetBubble() const {
return TranslateBubbleView::GetCurrentBubble();
}
bool TranslateIconView::Refresh() {
if (!GetWebContents())
return false;
const bool was_visible = visible();
const translate::LanguageState& language_state =
ChromeTranslateClient::FromWebContents(GetWebContents())
->GetLanguageState();
bool enabled = language_state.translate_enabled();
// Enable Translate page command or disable icon.
enabled &= SetCommandEnabled(enabled);
SetVisible(enabled);
if (!enabled)
TranslateBubbleView::CloseCurrentBubble();
return was_visible != visible();
}
void TranslateIconView::OnExecuting( void TranslateIconView::OnExecuting(
BubbleIconView::ExecuteSource execute_source) {} BubbleIconView::ExecuteSource execute_source) {}
void TranslateIconView::OnPressed(bool activated) { void TranslateIconView::OnPressed(bool activated) {
translate::ReportUiAction((activated translate::ReportUiAction(activated
? translate::PAGE_ACTION_ICON_ACTIVATED ? translate::PAGE_ACTION_ICON_ACTIVATED
: translate::PAGE_ACTION_ICON_DEACTIVATED)); : translate::PAGE_ACTION_ICON_DEACTIVATED);
}
views::BubbleDialogDelegateView* TranslateIconView::GetBubble() const {
return TranslateBubbleView::GetCurrentBubble();
} }
const gfx::VectorIcon& TranslateIconView::GetVectorIcon() const { const gfx::VectorIcon& TranslateIconView::GetVectorIcon() const {
......
...@@ -14,14 +14,18 @@ class CommandUpdater; ...@@ -14,14 +14,18 @@ class CommandUpdater;
// the page translated. // the page translated.
class TranslateIconView : public BubbleIconView { class TranslateIconView : public BubbleIconView {
public: public:
explicit TranslateIconView(CommandUpdater* command_updater); TranslateIconView(CommandUpdater* command_updater,
BubbleIconView::Delegate* delegate);
~TranslateIconView() override; ~TranslateIconView() override;
// BubbleIconView:
views::BubbleDialogDelegateView* GetBubble() const override;
bool Refresh() override;
protected: protected:
// BubbleIconView: // BubbleIconView:
void OnExecuting(BubbleIconView::ExecuteSource execute_source) override; void OnExecuting(BubbleIconView::ExecuteSource execute_source) override;
void OnPressed(bool activated) override; void OnPressed(bool activated) override;
views::BubbleDialogDelegateView* GetBubble() const override;
const gfx::VectorIcon& GetVectorIcon() const override; const gfx::VectorIcon& GetVectorIcon() const override;
private: private:
......
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