| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/extensions/extension_toolbar_model.h" | 5 #include "chrome/browser/extensions/extension_toolbar_model.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 ++extension) { | 710 ++extension) { |
| 711 if (*id == (*extension)->id()) | 711 if (*id == (*extension)->id()) |
| 712 highlighted_items_.push_back(*extension); | 712 highlighted_items_.push_back(*extension); |
| 713 } | 713 } |
| 714 } | 714 } |
| 715 | 715 |
| 716 // If we have any items in |highlighted_items_|, then we entered highlighting | 716 // If we have any items in |highlighted_items_|, then we entered highlighting |
| 717 // mode. | 717 // mode. |
| 718 if (highlighted_items_.size()) { | 718 if (highlighted_items_.size()) { |
| 719 old_visible_icon_count_ = visible_icon_count_; | 719 old_visible_icon_count_ = visible_icon_count_; |
| 720 is_highlighting_ = true; | |
| 721 if (visible_icon_count() < extension_ids.size()) | 720 if (visible_icon_count() < extension_ids.size()) |
| 722 SetVisibleIconCount(extension_ids.size()); | 721 SetVisibleIconCount(extension_ids.size()); |
| 723 | 722 |
| 723 // It's important that is_highlighting_ is changed right immediately before |
| 724 // the observers are notified since it changes the result of |
| 725 // toolbar_items(). |
| 726 is_highlighting_ = true; |
| 724 FOR_EACH_OBSERVER(Observer, observers_, | 727 FOR_EACH_OBSERVER(Observer, observers_, |
| 725 OnToolbarHighlightModeChanged(true)); | 728 OnToolbarHighlightModeChanged(true)); |
| 726 return true; | 729 return true; |
| 727 } | 730 } |
| 728 | 731 |
| 729 // Otherwise, we didn't enter highlighting mode (and, in fact, exited it if | 732 // Otherwise, we didn't enter highlighting mode (and, in fact, exited it if |
| 730 // we were otherwise in it). | 733 // we were otherwise in it). |
| 731 if (is_highlighting_) | 734 if (is_highlighting_) |
| 732 StopHighlighting(); | 735 StopHighlighting(); |
| 733 return false; | 736 return false; |
| 734 } | 737 } |
| 735 | 738 |
| 736 void ExtensionToolbarModel::StopHighlighting() { | 739 void ExtensionToolbarModel::StopHighlighting() { |
| 737 if (is_highlighting_) { | 740 if (is_highlighting_) { |
| 738 highlighted_items_.clear(); | 741 highlighted_items_.clear(); |
| 739 is_highlighting_ = false; | |
| 740 if (old_visible_icon_count_ != visible_icon_count_) | 742 if (old_visible_icon_count_ != visible_icon_count_) |
| 741 SetVisibleIconCount(old_visible_icon_count_); | 743 SetVisibleIconCount(old_visible_icon_count_); |
| 744 |
| 745 // It's important that is_highlighting_ is changed right immediately before |
| 746 // the observers are notified since it changes the result of |
| 747 // toolbar_items(). |
| 748 is_highlighting_ = false; |
| 742 FOR_EACH_OBSERVER(Observer, observers_, | 749 FOR_EACH_OBSERVER(Observer, observers_, |
| 743 OnToolbarHighlightModeChanged(false)); | 750 OnToolbarHighlightModeChanged(false)); |
| 744 } | 751 } |
| 745 } | 752 } |
| 746 | 753 |
| 747 bool ExtensionToolbarModel::RedesignIsShowingNewIcons() const { | 754 bool ExtensionToolbarModel::RedesignIsShowingNewIcons() const { |
| 748 for (const scoped_refptr<const Extension>& extension : toolbar_items_) { | 755 for (const scoped_refptr<const Extension>& extension : toolbar_items_) { |
| 749 // Without the redesign, we only show extensions with browser actions. | 756 // Without the redesign, we only show extensions with browser actions. |
| 750 // Any extension without a browser action is an indication that we're | 757 // Any extension without a browser action is an indication that we're |
| 751 // showing something new. | 758 // showing something new. |
| 752 if (!extension->manifest()->HasKey(manifest_keys::kBrowserAction)) | 759 if (!extension->manifest()->HasKey(manifest_keys::kBrowserAction)) |
| 753 return true; | 760 return true; |
| 754 } | 761 } |
| 755 return false; | 762 return false; |
| 756 } | 763 } |
| 757 | 764 |
| 758 } // namespace extensions | 765 } // namespace extensions |
| OLD | NEW |