Create a cross-platform helper class for badging the wrench menu.

Adds WrenchMenuBadgeController which is responsible for notifying toolbar 
UI implementations (i.e. views and cocoa) about how they should be badged. 

Logic is moved from Cocoa and Views toolbar implementations and from 
wrench_icon_painter.cc to this new class. 

This refactor allows to easily expand the functionality of this class to add 
new sources of badging without needing to make the same changes to 
several platform-specific implementations. 

No functional changes. 

BUG=394855

Review URL: https://codereview.chromium.org/395193003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284084 0039d316-1c4b-4281-b951-d872f2087c98
parent 4ee8711f
......@@ -41,19 +41,14 @@
#import "chrome/browser/ui/cocoa/toolbar/wrench_toolbar_button_cell.h"
#import "chrome/browser/ui/cocoa/view_id_util.h"
#import "chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.h"
#include "chrome/browser/ui/global_error/global_error_service.h"
#include "chrome/browser/ui/global_error/global_error_service_factory.h"
#include "chrome/browser/ui/omnibox/omnibox_view.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/toolbar/wrench_menu_model.h"
#include "chrome/browser/upgrade_detector.h"
#include "chrome/browser/ui/toolbar/wrench_menu_badge_controller.h"
#include "chrome/common/pref_names.h"
#include "components/metrics/proto/omnibox_event.pb.h"
#include "components/search_engines/template_url_service.h"
#include "components/url_fixer/url_fixer.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/web_contents.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
......@@ -99,7 +94,8 @@ const CGFloat kWrenchMenuLeftPadding = 3.0;
- (void)browserActionsContainerDragFinished:(NSNotification*)notification;
- (void)browserActionsVisibilityChanged:(NSNotification*)notification;
- (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate;
- (void)updateWrenchButtonSeverity;
- (void)updateWrenchButtonSeverity:(WrenchIconPainter::Severity)severity
animate:(BOOL)animate;
@end
namespace ToolbarControllerInternal {
......@@ -107,29 +103,23 @@ namespace ToolbarControllerInternal {
// A class registered for C++ notifications. This is used to detect changes in
// preferences and upgrade available notifications. Bridges the notification
// back to the ToolbarController.
class NotificationBridge
: public content::NotificationObserver {
class NotificationBridge : public WrenchMenuBadgeController::Delegate {
public:
explicit NotificationBridge(ToolbarController* controller)
: controller_(controller) {
registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
content::NotificationService::AllSources());
registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED,
content::Source<Profile>([controller browser]->profile()));
: controller_(controller),
badge_controller_([controller browser]->profile(), this) {
}
virtual ~NotificationBridge() {
}
// Overridden from content::NotificationObserver:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE {
switch (type) {
case chrome::NOTIFICATION_UPGRADE_RECOMMENDED:
case chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED:
[controller_ updateWrenchButtonSeverity];
break;
default:
NOTREACHED();
}
void UpdateBadgeSeverity() {
badge_controller_.UpdateDelegate();
}
virtual void UpdateBadgeSeverity(WrenchMenuBadgeController::BadgeType type,
WrenchIconPainter::Severity severity,
bool animate) OVERRIDE {
[controller_ updateWrenchButtonSeverity:severity animate:animate];
}
void OnPreferenceChanged(const std::string& pref_name) {
......@@ -139,7 +129,9 @@ class NotificationBridge
private:
ToolbarController* controller_; // weak, owns us
content::NotificationRegistrar registrar_;
WrenchMenuBadgeController badge_controller_;
DISALLOW_COPY_AND_ASSIGN(NotificationBridge);
};
} // namespace ToolbarControllerInternal
......@@ -252,7 +244,9 @@ class NotificationBridge
[[wrenchButton_ cell] setImageID:IDR_TOOLS_P
forButtonState:image_button_cell::kPressedState];
[self updateWrenchButtonSeverity];
notificationBridge_.reset(
new ToolbarControllerInternal::NotificationBridge(self));
notificationBridge_->UpdateBadgeSeverity();
[wrenchButton_ setOpenMenuOnClick:YES];
......@@ -269,10 +263,9 @@ class NotificationBridge
locationBarView_.reset(new LocationBarViewMac(locationBar_, commands_,
profile_, browser_));
[locationBar_ setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]];
// Register pref observers for the optional home and page/options buttons
// and then add them to the toolbar based on those prefs.
notificationBridge_.reset(
new ToolbarControllerInternal::NotificationBridge(self));
PrefService* prefs = profile_->GetPrefs();
showHomeButton_.Init(
prefs::kShowHomeButton, prefs,
......@@ -575,26 +568,11 @@ class NotificationBridge
return wrenchMenuController_;
}
- (void)updateWrenchButtonSeverity {
- (void)updateWrenchButtonSeverity:(WrenchIconPainter::Severity)severity
animate:(BOOL)animate {
WrenchToolbarButtonCell* cell =
base::mac::ObjCCastStrict<WrenchToolbarButtonCell>([wrenchButton_ cell]);
if (UpgradeDetector::GetInstance()->notify_upgrade()) {
UpgradeDetector::UpgradeNotificationAnnoyanceLevel level =
UpgradeDetector::GetInstance()->upgrade_notification_stage();
[cell setSeverity:WrenchIconPainter::SeverityFromUpgradeLevel(level)
shouldAnimate:WrenchIconPainter::ShouldAnimateUpgradeLevel(level)];
return;
}
GlobalError* error = GlobalErrorServiceFactory::GetForProfile(
browser_->profile())->GetHighestSeverityGlobalErrorWithWrenchMenuItem();
if (error) {
[cell setSeverity:WrenchIconPainter::GlobalErrorSeverity()
shouldAnimate:YES];
return;
}
[cell setSeverity:WrenchIconPainter::SEVERITY_NONE shouldAnimate:YES];
[cell setSeverity:severity shouldAnimate:animate];
}
- (void)prefChanged:(const std::string&)prefName {
......
......@@ -4,6 +4,8 @@
#include "chrome/browser/ui/toolbar/wrench_icon_painter.h"
#include <algorithm>
#include "grit/theme_resources.h"
#include "ui/base/theme_provider.h"
#include "ui/gfx/animation/multi_animation.h"
......@@ -30,47 +32,6 @@ double GetStaggeredValue(double value, int index) {
} // namespace
// static
WrenchIconPainter::Severity WrenchIconPainter::SeverityFromUpgradeLevel(
UpgradeDetector::UpgradeNotificationAnnoyanceLevel level) {
switch (level) {
case UpgradeDetector::UPGRADE_ANNOYANCE_NONE:
return SEVERITY_NONE;
case UpgradeDetector::UPGRADE_ANNOYANCE_LOW:
return SEVERITY_LOW;
case UpgradeDetector::UPGRADE_ANNOYANCE_ELEVATED:
return SEVERITY_MEDIUM;
case UpgradeDetector::UPGRADE_ANNOYANCE_HIGH:
return SEVERITY_HIGH;
case UpgradeDetector::UPGRADE_ANNOYANCE_SEVERE:
return SEVERITY_HIGH;
case UpgradeDetector::UPGRADE_ANNOYANCE_CRITICAL:
return SEVERITY_HIGH;
}
NOTREACHED();
return SEVERITY_NONE;
}
// static
bool WrenchIconPainter::ShouldAnimateUpgradeLevel(
UpgradeDetector::UpgradeNotificationAnnoyanceLevel level) {
bool should_animate = true;
if (level == UpgradeDetector::UPGRADE_ANNOYANCE_LOW) {
// Only animate low severity upgrades once.
static bool should_animate_low_severity = true;
should_animate = should_animate_low_severity;
should_animate_low_severity = false;
}
return should_animate;
}
// static
WrenchIconPainter::Severity WrenchIconPainter::GlobalErrorSeverity() {
// If you change this make sure to also change the menu icon and the bubble
// icon.
return SEVERITY_MEDIUM;
}
WrenchIconPainter::WrenchIconPainter(Delegate* delegate)
: delegate_(delegate),
severity_(SEVERITY_NONE) {
......
......@@ -8,8 +8,6 @@
#include "base/compiler_specific.h"
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/ui/global_error/global_error.h"
#include "chrome/browser/upgrade_detector.h"
#include "ui/gfx/animation/animation_delegate.h"
#include "ui/gfx/image/image_skia.h"
......@@ -46,17 +44,6 @@ class WrenchIconPainter : gfx::AnimationDelegate {
virtual ~Delegate() {}
};
// Map an upgrade level to a severity level.
static Severity SeverityFromUpgradeLevel(
UpgradeDetector::UpgradeNotificationAnnoyanceLevel level);
// Checks if the wrench icon should be animated for the given upgrade level.
static bool ShouldAnimateUpgradeLevel(
UpgradeDetector::UpgradeNotificationAnnoyanceLevel level);
// Get the severity level for global errors.
static Severity GlobalErrorSeverity();
explicit WrenchIconPainter(Delegate* delegate);
virtual ~WrenchIconPainter();
......
// 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.
#include "chrome/browser/ui/toolbar/wrench_menu_badge_controller.h"
#include "base/logging.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/ui/global_error/global_error_service.h"
#include "chrome/browser/ui/global_error/global_error_service_factory.h"
#include "chrome/browser/upgrade_detector.h"
#if defined(OS_WIN)
#include "base/win/windows_version.h"
#include "chrome/browser/enumerate_modules_model_win.h"
#endif
namespace {
// Maps an upgrade level to a severity level.
WrenchIconPainter::Severity SeverityFromUpgradeLevel(
UpgradeDetector::UpgradeNotificationAnnoyanceLevel level) {
switch (level) {
case UpgradeDetector::UPGRADE_ANNOYANCE_NONE:
return WrenchIconPainter::SEVERITY_NONE;
case UpgradeDetector::UPGRADE_ANNOYANCE_LOW:
return WrenchIconPainter::SEVERITY_LOW;
case UpgradeDetector::UPGRADE_ANNOYANCE_ELEVATED:
return WrenchIconPainter::SEVERITY_MEDIUM;
case UpgradeDetector::UPGRADE_ANNOYANCE_HIGH:
return WrenchIconPainter::SEVERITY_HIGH;
case UpgradeDetector::UPGRADE_ANNOYANCE_SEVERE:
return WrenchIconPainter::SEVERITY_HIGH;
case UpgradeDetector::UPGRADE_ANNOYANCE_CRITICAL:
return WrenchIconPainter::SEVERITY_HIGH;
}
NOTREACHED();
return WrenchIconPainter::SEVERITY_NONE;
}
// Checks if the wrench icon should be animated for the given upgrade level.
bool ShouldAnimateUpgradeLevel(
UpgradeDetector::UpgradeNotificationAnnoyanceLevel level) {
bool should_animate = true;
if (level == UpgradeDetector::UPGRADE_ANNOYANCE_LOW) {
// Only animate low severity upgrades once.
static bool should_animate_low_severity = true;
should_animate = should_animate_low_severity;
should_animate_low_severity = false;
}
return should_animate;
}
// Returns true if we should show the upgrade recommended badge.
bool ShouldShowUpgradeRecommended() {
#if defined(OS_CHROMEOS)
// In chromeos, the update recommendation is shown in the system tray. So it
// should not be displayed in the wrench menu.
return false;
#else
return UpgradeDetector::GetInstance()->notify_upgrade();
#endif
}
// Returns true if we should show the warning for incompatible software.
bool ShouldShowIncompatibilityWarning() {
#if defined(OS_WIN)
EnumerateModulesModel* loaded_modules = EnumerateModulesModel::GetInstance();
loaded_modules->MaybePostScanningTask();
return loaded_modules->ShouldShowConflictWarning();
#else
return false;
#endif
}
} // namespace
WrenchMenuBadgeController::WrenchMenuBadgeController(Profile* profile,
Delegate* delegate)
: profile_(profile), delegate_(delegate) {
DCHECK(profile_);
DCHECK(delegate_);
registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
content::NotificationService::AllSources());
registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED,
content::Source<Profile>(profile_));
#if defined(OS_WIN)
if (base::win::GetVersion() == base::win::VERSION_XP) {
registrar_.Add(this, chrome::NOTIFICATION_MODULE_LIST_ENUMERATED,
content::NotificationService::AllSources());
}
registrar_.Add(this, chrome::NOTIFICATION_MODULE_INCOMPATIBILITY_BADGE_CHANGE,
content::NotificationService::AllSources());
#endif
}
WrenchMenuBadgeController::~WrenchMenuBadgeController() {
}
void WrenchMenuBadgeController::UpdateDelegate() {
if (ShouldShowUpgradeRecommended()) {
UpgradeDetector::UpgradeNotificationAnnoyanceLevel level =
UpgradeDetector::GetInstance()->upgrade_notification_stage();
delegate_->UpdateBadgeSeverity(BADGE_TYPE_UPGRADE_NOTIFICATION,
SeverityFromUpgradeLevel(level),
ShouldAnimateUpgradeLevel(level));
return;
}
if (ShouldShowIncompatibilityWarning()) {
delegate_->UpdateBadgeSeverity(BADGE_TYPE_INCOMPATIBILITY_WARNING,
WrenchIconPainter::SEVERITY_MEDIUM, true);
return;
}
if (GlobalErrorServiceFactory::GetForProfile(profile_)->
GetHighestSeverityGlobalErrorWithWrenchMenuItem()) {
// If you change the severity here, make sure to also change the menu icon
// and the bubble icon.
delegate_->UpdateBadgeSeverity(BADGE_TYPE_GLOBAL_ERROR,
WrenchIconPainter::SEVERITY_MEDIUM, true);
return;
}
delegate_->UpdateBadgeSeverity(BADGE_TYPE_NONE,
WrenchIconPainter::SEVERITY_NONE, true);
}
void WrenchMenuBadgeController::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
UpdateDelegate();
}
// 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.
#ifndef CHROME_BROWSER_UI_TOOLBAR_WRENCH_MENU_BADGE_CONTROLLER_H_
#define CHROME_BROWSER_UI_TOOLBAR_WRENCH_MENU_BADGE_CONTROLLER_H_
#include "base/macros.h"
#include "chrome/browser/ui/toolbar/wrench_icon_painter.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_service.h"
class Profile;
// WrenchMenuBadgeController encapsulates the logic for badging the wrench menu
// icon as a result of various events - such as available updates, errors, etc.
class WrenchMenuBadgeController : public content::NotificationObserver {
public:
enum BadgeType {
BADGE_TYPE_NONE,
BADGE_TYPE_UPGRADE_NOTIFICATION,
BADGE_TYPE_GLOBAL_ERROR,
BADGE_TYPE_INCOMPATIBILITY_WARNING,
};
// Delegate interface for receiving badge update notifications.
class Delegate {
public:
// Notifies the UI to update the badge to have the specified |severity|, as
// well as specifying whether it should |animate|. The |type| parameter
// specifies the type of change (i.e. the source of the notification).
virtual void UpdateBadgeSeverity(BadgeType type,
WrenchIconPainter::Severity severity,
bool animate) = 0;
protected:
virtual ~Delegate() {}
};
// Creates an instance of this class for the given |profile| that will notify
// |delegate| of updates.
WrenchMenuBadgeController(Profile* profile, Delegate* delegate);
virtual ~WrenchMenuBadgeController();
// Forces an update of the UI based on the current state of the world. This
// will check whether there are any current pending updates, global errors,
// etc. and based on that information trigger an appropriate call to the
// delegate.
void UpdateDelegate();
private:
// content::NotificationObserver:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
Profile* profile_;
Delegate* delegate_;
content::NotificationRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(WrenchMenuBadgeController);
};
#endif // CHROME_BROWSER_UI_TOOLBAR_WRENCH_MENU_BADGE_CONTROLLER_H_
......@@ -4,6 +4,8 @@
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include <algorithm>
#include "base/command_line.h"
#include "base/debug/trace_event.h"
#include "base/i18n/number_formatting.h"
......@@ -44,7 +46,6 @@
#include "chrome/browser/ui/views/toolbar/toolbar_button.h"
#include "chrome/browser/ui/views/toolbar/wrench_menu.h"
#include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h"
#include "chrome/browser/upgrade_detector.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "content/public/browser/browser_accessibility_state.h"
......@@ -73,8 +74,6 @@
#include "ui/views/window/non_client_view.h"
#if defined(OS_WIN)
#include "base/win/windows_version.h"
#include "chrome/browser/enumerate_modules_model_win.h"
#include "chrome/browser/ui/views/conflicting_module_view_win.h"
#include "chrome/browser/ui/views/critical_notification_bubble_view.h"
#endif
......@@ -136,6 +135,7 @@ ToolbarView::ToolbarView(Browser* browser)
browser_actions_(NULL),
app_menu_(NULL),
browser_(browser),
badge_controller_(browser->profile(), this),
extension_message_bubble_factory_(
new extensions::ExtensionMessageBubbleFactory(browser->profile(),
this)) {
......@@ -166,16 +166,7 @@ ToolbarView::ToolbarView(Browser* browser)
#if defined(OS_WIN)
registrar_.Add(this, chrome::NOTIFICATION_CRITICAL_UPGRADE_INSTALLED,
content::NotificationService::AllSources());
if (base::win::GetVersion() == base::win::VERSION_XP) {
registrar_.Add(this, chrome::NOTIFICATION_MODULE_LIST_ENUMERATED,
content::NotificationService::AllSources());
}
#endif
registrar_.Add(this,
chrome::NOTIFICATION_MODULE_INCOMPATIBILITY_BADGE_CHANGE,
content::NotificationService::AllSources());
registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED,
content::Source<Profile>(browser_->profile()));
}
ToolbarView::~ToolbarView() {
......@@ -264,7 +255,7 @@ void ToolbarView::Init() {
// Add any necessary badges to the menu item based on the system state.
// Do this after |app_menu_| has been added as a bubble may be shown that
// needs the widget (widget found by way of app_menu_->GetWidget()).
UpdateAppMenuState();
badge_controller_.UpdateDelegate();
location_bar_->Init();
......@@ -490,12 +481,6 @@ void ToolbarView::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
case chrome::NOTIFICATION_UPGRADE_RECOMMENDED:
case chrome::NOTIFICATION_MODULE_INCOMPATIBILITY_BADGE_CHANGE:
case chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED:
case chrome::NOTIFICATION_MODULE_LIST_ENUMERATED:
UpdateAppMenuState();
break;
case chrome::NOTIFICATION_OUTDATED_INSTALL:
ShowOutdatedInstallNotification(true);
break;
......@@ -714,24 +699,38 @@ bool ToolbarView::DoesIntersectRect(const views::View* target,
return ViewTargeterDelegate::DoesIntersectRect(this, rect);
}
bool ToolbarView::ShouldShowUpgradeRecommended() {
#if defined(OS_CHROMEOS)
// In chromeos, the update recommendation is shown in the system tray. So it
// should not be displayed in the wrench menu.
return false;
#else
return (UpgradeDetector::GetInstance()->notify_upgrade());
#endif
}
void ToolbarView::UpdateBadgeSeverity(WrenchMenuBadgeController::BadgeType type,
WrenchIconPainter::Severity severity,
bool animate) {
// Showing the bubble requires |app_menu_| to be in a widget. See comment
// in ConflictingModuleView for details.
DCHECK(app_menu_->GetWidget());
base::string16 accname_app = l10n_util::GetStringUTF16(IDS_ACCNAME_APP);
if (type == WrenchMenuBadgeController::BADGE_TYPE_UPGRADE_NOTIFICATION) {
accname_app = l10n_util::GetStringFUTF16(
IDS_ACCNAME_APP_UPGRADE_RECOMMENDED, accname_app);
}
app_menu_->SetAccessibleName(accname_app);
app_menu_->SetSeverity(severity, animate);
bool ToolbarView::ShouldShowIncompatibilityWarning() {
// Keep track of whether we were showing the badge before, so we don't send
// multiple UMA events for example when multiple Chrome windows are open.
static bool incompatibility_badge_showing = false;
// Save the old value before resetting it.
bool was_showing = incompatibility_badge_showing;
incompatibility_badge_showing = false;
if (type == WrenchMenuBadgeController::BADGE_TYPE_INCOMPATIBILITY_WARNING) {
if (!was_showing) {
content::RecordAction(UserMetricsAction("ConflictBadge"));
#if defined(OS_WIN)
EnumerateModulesModel* loaded_modules = EnumerateModulesModel::GetInstance();
loaded_modules->MaybePostScanningTask();
return loaded_modules->ShouldShowConflictWarning();
#else
return false;
ConflictingModuleView::MaybeShow(browser_, app_menu_);
#endif
}
incompatibility_badge_showing = true;
return;
}
}
int ToolbarView::PopupTopSpacing() const {
......@@ -791,62 +790,6 @@ void ToolbarView::ShowOutdatedInstallNotification(bool auto_update_enabled) {
}
}
void ToolbarView::UpdateAppMenuState() {
base::string16 accname_app = l10n_util::GetStringUTF16(IDS_ACCNAME_APP);
if (ShouldShowUpgradeRecommended()) {
accname_app = l10n_util::GetStringFUTF16(
IDS_ACCNAME_APP_UPGRADE_RECOMMENDED, accname_app);
}
app_menu_->SetAccessibleName(accname_app);
UpdateWrenchButtonSeverity();
SchedulePaint();
}
void ToolbarView::UpdateWrenchButtonSeverity() {
// Showing the bubble requires |app_menu_| to be in a widget. See comment
// in ConflictingModuleView for details.
DCHECK(app_menu_->GetWidget());
// Keep track of whether we were showing the badge before, so we don't send
// multiple UMA events for example when multiple Chrome windows are open.
static bool incompatibility_badge_showing = false;
// Save the old value before resetting it.
bool was_showing = incompatibility_badge_showing;
incompatibility_badge_showing = false;
if (ShouldShowUpgradeRecommended()) {
UpgradeDetector::UpgradeNotificationAnnoyanceLevel level =
UpgradeDetector::GetInstance()->upgrade_notification_stage();
app_menu_->SetSeverity(WrenchIconPainter::SeverityFromUpgradeLevel(level),
WrenchIconPainter::ShouldAnimateUpgradeLevel(level));
return;
}
if (ShouldShowIncompatibilityWarning()) {
if (!was_showing) {
content::RecordAction(UserMetricsAction("ConflictBadge"));
#if defined(OS_WIN)
ConflictingModuleView::MaybeShow(browser_, app_menu_);
#endif
}
app_menu_->SetSeverity(WrenchIconPainter::SEVERITY_MEDIUM, true);
incompatibility_badge_showing = true;
return;
}
GlobalErrorService* service =
GlobalErrorServiceFactory::GetForProfile(browser_->profile());
GlobalError* error =
service->GetHighestSeverityGlobalErrorWithWrenchMenuItem();
if (error) {
app_menu_->SetSeverity(WrenchIconPainter::GlobalErrorSeverity(), true);
return;
}
app_menu_->SetSeverity(WrenchIconPainter::SEVERITY_NONE, true);
}
void ToolbarView::OnShowHomeButtonChanged() {
Layout();
SchedulePaint();
......
......@@ -13,6 +13,7 @@
#include "base/prefs/pref_member.h"
#include "chrome/browser/command_observer.h"
#include "chrome/browser/ui/toolbar/back_forward_menu_model.h"
#include "chrome/browser/ui/toolbar/wrench_menu_badge_controller.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/views/accessible_pane_view.h"
......@@ -49,7 +50,8 @@ class ToolbarView : public views::AccessiblePaneView,
public CommandObserver,
public views::ButtonListener,
public views::WidgetObserver,
public views::ViewTargeterDelegate {
public views::ViewTargeterDelegate,
public WrenchMenuBadgeController::Delegate {
public:
// The view class name.
static const char kViewClassName[];
......@@ -192,14 +194,10 @@ class ToolbarView : public views::AccessiblePaneView,
virtual bool DoesIntersectRect(const views::View* target,
const gfx::Rect& rect) const OVERRIDE;
// Returns true if we should show the upgrade recommended dot.
bool ShouldShowUpgradeRecommended();
// Returns true if we should show the background page badge.
bool ShouldShowBackgroundPageBadge();
// Returns true if we should show the warning for incompatible software.
bool ShouldShowIncompatibilityWarning();
// WrenchMenuBadgeController::Delegate:
virtual void UpdateBadgeSeverity(WrenchMenuBadgeController::BadgeType type,
WrenchIconPainter::Severity severity,
bool animate) OVERRIDE;
// Returns the number of pixels above the location bar in non-normal display.
int PopupTopSpacing() const;
......@@ -221,12 +219,6 @@ class ToolbarView : public views::AccessiblePaneView,
// |auto_update_enabled| is set to true when auto-upate is on.
void ShowOutdatedInstallNotification(bool auto_update_enabled);
// Updates the badge and the accessible name of the app menu (Wrench).
void UpdateAppMenuState();
// Updates the severity level on the wrench menu button.
void UpdateWrenchButtonSeverity();
void OnShowHomeButtonChanged();
int content_shadow_height() const;
......@@ -241,6 +233,8 @@ class ToolbarView : public views::AccessiblePaneView,
WrenchToolbarButton* app_menu_;
Browser* browser_;
WrenchMenuBadgeController badge_controller_;
// Controls whether or not a home button should be shown on the toolbar.
BooleanPrefMember show_home_button_;
......
......@@ -20,6 +20,7 @@ WrenchToolbarButton::~WrenchToolbarButton() {
void WrenchToolbarButton::SetSeverity(WrenchIconPainter::Severity severity,
bool animate) {
wrench_icon_painter_->SetSeverity(severity, animate);
SchedulePaint();
}
gfx::Size WrenchToolbarButton::GetPreferredSize() const {
......
......@@ -1561,6 +1561,8 @@
'browser/ui/toolbar/encoding_menu_controller.h',
'browser/ui/toolbar/recent_tabs_sub_menu_model.cc',
'browser/ui/toolbar/recent_tabs_sub_menu_model.h',
'browser/ui/toolbar/wrench_menu_badge_controller.cc',
'browser/ui/toolbar/wrench_menu_badge_controller.h',
'browser/ui/toolbar/wrench_icon_painter.cc',
'browser/ui/toolbar/wrench_icon_painter.h',
'browser/ui/toolbar/wrench_menu_model.cc',
......
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