| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/toolbar_view.h" | 5 #include "chrome/browser/ui/views/toolbar_view.h" |
| 6 | 6 |
| 7 #include "base/i18n/number_formatting.h" | 7 #include "base/i18n/number_formatting.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
| 10 #include "chrome/browser/accessibility/browser_accessibility_state.h" | 10 #include "chrome/browser/accessibility/browser_accessibility_state.h" |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 void ToolbarView::RemoveMenuListener(views::MenuListener* listener) { | 247 void ToolbarView::RemoveMenuListener(views::MenuListener* listener) { |
| 248 for (std::vector<views::MenuListener*>::iterator i(menu_listeners_.begin()); | 248 for (std::vector<views::MenuListener*>::iterator i(menu_listeners_.begin()); |
| 249 i != menu_listeners_.end(); ++i) { | 249 i != menu_listeners_.end(); ++i) { |
| 250 if (*i == listener) { | 250 if (*i == listener) { |
| 251 menu_listeners_.erase(i); | 251 menu_listeners_.erase(i); |
| 252 return; | 252 return; |
| 253 } | 253 } |
| 254 } | 254 } |
| 255 } | 255 } |
| 256 | 256 |
| 257 SkBitmap ToolbarView::GetAppMenuIcon(views::CustomButton::ButtonState state) { |
| 258 ui::ThemeProvider* tp = GetThemeProvider(); |
| 259 |
| 260 int id = 0; |
| 261 switch (state) { |
| 262 case views::CustomButton::BS_NORMAL: id = IDR_TOOLS; break; |
| 263 case views::CustomButton::BS_HOT: id = IDR_TOOLS_H; break; |
| 264 case views::CustomButton::BS_PUSHED: id = IDR_TOOLS_P; break; |
| 265 default: NOTREACHED(); break; |
| 266 } |
| 267 SkBitmap icon = *tp->GetBitmapNamed(id); |
| 268 |
| 269 #if defined(OS_WIN) |
| 270 // Keep track of whether we were showing the badge before, so we don't send |
| 271 // multiple UMA events for example when multiple Chrome windows are open. |
| 272 static bool incompatibility_badge_showing = false; |
| 273 // Save the old value before resetting it. |
| 274 bool was_showing = incompatibility_badge_showing; |
| 275 incompatibility_badge_showing = false; |
| 276 #endif |
| 277 |
| 278 bool add_badge = IsUpgradeRecommended() || ShouldShowIncompatibilityWarning(); |
| 279 if (!add_badge) |
| 280 return icon; |
| 281 |
| 282 // Draw the chrome app menu icon onto the canvas. |
| 283 scoped_ptr<gfx::CanvasSkia> canvas( |
| 284 new gfx::CanvasSkia(icon.width(), icon.height(), false)); |
| 285 canvas->DrawBitmapInt(icon, 0, 0); |
| 286 |
| 287 SkBitmap badge; |
| 288 // Only one badge can be active at any given time. The Upgrade notification |
| 289 // is deemed most important, then the DLL conflict badge. |
| 290 if (IsUpgradeRecommended()) { |
| 291 badge = *tp->GetBitmapNamed( |
| 292 UpgradeDetector::GetInstance()->GetIconResourceID( |
| 293 UpgradeDetector::UPGRADE_ICON_TYPE_BADGE)); |
| 294 } else if (ShouldShowIncompatibilityWarning()) { |
| 295 #if defined(OS_WIN) |
| 296 if (!was_showing) |
| 297 UserMetrics::RecordAction(UserMetricsAction("ConflictBadge")); |
| 298 badge = *tp->GetBitmapNamed(IDR_CONFLICT_BADGE); |
| 299 incompatibility_badge_showing = true; |
| 300 #else |
| 301 NOTREACHED(); |
| 302 #endif |
| 303 } else { |
| 304 NOTREACHED(); |
| 305 } |
| 306 |
| 307 canvas->DrawBitmapInt(badge, icon.width() - badge.width(), kBadgeTopMargin); |
| 308 |
| 309 return canvas->ExtractBitmap(); |
| 310 } |
| 311 |
| 257 //////////////////////////////////////////////////////////////////////////////// | 312 //////////////////////////////////////////////////////////////////////////////// |
| 258 // ToolbarView, AccessiblePaneView overrides: | 313 // ToolbarView, AccessiblePaneView overrides: |
| 259 | 314 |
| 260 bool ToolbarView::SetPaneFocus( | 315 bool ToolbarView::SetPaneFocus( |
| 261 int view_storage_id, views::View* initial_focus) { | 316 int view_storage_id, views::View* initial_focus) { |
| 262 if (!AccessiblePaneView::SetPaneFocus(view_storage_id, initial_focus)) | 317 if (!AccessiblePaneView::SetPaneFocus(view_storage_id, initial_focus)) |
| 263 return false; | 318 return false; |
| 264 | 319 |
| 265 location_bar_->SetShowFocusRect(true); | 320 location_bar_->SetShowFocusRect(true); |
| 266 return true; | 321 return true; |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 app_menu_->SetHoverIcon(GetAppMenuIcon(views::CustomButton::BS_HOT)); | 703 app_menu_->SetHoverIcon(GetAppMenuIcon(views::CustomButton::BS_HOT)); |
| 649 app_menu_->SetPushedIcon(GetAppMenuIcon(views::CustomButton::BS_PUSHED)); | 704 app_menu_->SetPushedIcon(GetAppMenuIcon(views::CustomButton::BS_PUSHED)); |
| 650 } | 705 } |
| 651 | 706 |
| 652 void ToolbarView::UpdateAppMenuBadge() { | 707 void ToolbarView::UpdateAppMenuBadge() { |
| 653 app_menu_->SetIcon(GetAppMenuIcon(views::CustomButton::BS_NORMAL)); | 708 app_menu_->SetIcon(GetAppMenuIcon(views::CustomButton::BS_NORMAL)); |
| 654 app_menu_->SetHoverIcon(GetAppMenuIcon(views::CustomButton::BS_HOT)); | 709 app_menu_->SetHoverIcon(GetAppMenuIcon(views::CustomButton::BS_HOT)); |
| 655 app_menu_->SetPushedIcon(GetAppMenuIcon(views::CustomButton::BS_PUSHED)); | 710 app_menu_->SetPushedIcon(GetAppMenuIcon(views::CustomButton::BS_PUSHED)); |
| 656 SchedulePaint(); | 711 SchedulePaint(); |
| 657 } | 712 } |
| 658 | |
| 659 SkBitmap ToolbarView::GetAppMenuIcon(views::CustomButton::ButtonState state) { | |
| 660 ui::ThemeProvider* tp = GetThemeProvider(); | |
| 661 | |
| 662 int id = 0; | |
| 663 switch (state) { | |
| 664 case views::CustomButton::BS_NORMAL: id = IDR_TOOLS; break; | |
| 665 case views::CustomButton::BS_HOT: id = IDR_TOOLS_H; break; | |
| 666 case views::CustomButton::BS_PUSHED: id = IDR_TOOLS_P; break; | |
| 667 default: NOTREACHED(); break; | |
| 668 } | |
| 669 SkBitmap icon = *tp->GetBitmapNamed(id); | |
| 670 | |
| 671 #if defined(OS_WIN) | |
| 672 // Keep track of whether we were showing the badge before, so we don't send | |
| 673 // multiple UMA events for example when multiple Chrome windows are open. | |
| 674 static bool incompatibility_badge_showing = false; | |
| 675 // Save the old value before resetting it. | |
| 676 bool was_showing = incompatibility_badge_showing; | |
| 677 incompatibility_badge_showing = false; | |
| 678 #endif | |
| 679 | |
| 680 bool add_badge = IsUpgradeRecommended() || ShouldShowIncompatibilityWarning(); | |
| 681 if (!add_badge) | |
| 682 return icon; | |
| 683 | |
| 684 // Draw the chrome app menu icon onto the canvas. | |
| 685 scoped_ptr<gfx::CanvasSkia> canvas( | |
| 686 new gfx::CanvasSkia(icon.width(), icon.height(), false)); | |
| 687 canvas->DrawBitmapInt(icon, 0, 0); | |
| 688 | |
| 689 SkBitmap badge; | |
| 690 // Only one badge can be active at any given time. The Upgrade notification | |
| 691 // is deemed most important, then the DLL conflict badge. | |
| 692 if (IsUpgradeRecommended()) { | |
| 693 badge = *tp->GetBitmapNamed( | |
| 694 UpgradeDetector::GetInstance()->GetIconResourceID( | |
| 695 UpgradeDetector::UPGRADE_ICON_TYPE_BADGE)); | |
| 696 } else if (ShouldShowIncompatibilityWarning()) { | |
| 697 #if defined(OS_WIN) | |
| 698 if (!was_showing) | |
| 699 UserMetrics::RecordAction(UserMetricsAction("ConflictBadge")); | |
| 700 badge = *tp->GetBitmapNamed(IDR_CONFLICT_BADGE); | |
| 701 incompatibility_badge_showing = true; | |
| 702 #else | |
| 703 NOTREACHED(); | |
| 704 #endif | |
| 705 } else { | |
| 706 NOTREACHED(); | |
| 707 } | |
| 708 | |
| 709 canvas->DrawBitmapInt(badge, icon.width() - badge.width(), kBadgeTopMargin); | |
| 710 | |
| 711 return canvas->ExtractBitmap(); | |
| 712 } | |
| OLD | NEW |