Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7016)

Unified Diff: chrome/browser/ui/views/toolbar/browser_actions_container.cc

Issue 675893002: Revert of Rename BrowserActionView to ToolbarActionView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/toolbar/browser_actions_container.cc
diff --git a/chrome/browser/ui/views/toolbar/browser_actions_container.cc b/chrome/browser/ui/views/toolbar/browser_actions_container.cc
index 4631a36c6a8d1c435f26c90a9da893ddbfd8bca2..d00e9d99cf6e81947975d1b60641b6b95c16e945 100644
--- a/chrome/browser/ui/views/toolbar/browser_actions_container.cc
+++ b/chrome/browser/ui/views/toolbar/browser_actions_container.cc
@@ -22,7 +22,6 @@
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "chrome/common/extensions/command.h"
#include "chrome/grit/generated_resources.h"
-#include "components/crx_file/id_util.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/runtime_data.h"
#include "extensions/common/feature_switch.h"
@@ -164,7 +163,7 @@
if (model_)
model_->RemoveObserver(this);
HideActivePopup();
- DeleteToolbarActionViews();
+ DeleteBrowserActionViews();
}
void BrowserActionsContainer::Init() {
@@ -181,47 +180,47 @@
}
const std::string& BrowserActionsContainer::GetIdAt(size_t index) {
- return toolbar_action_views_[index]->view_controller()->GetId();
-}
-
-ToolbarActionView* BrowserActionsContainer::GetViewForExtension(
+ return browser_action_views_[index]->view_controller()->GetId();
+}
+
+BrowserActionView* BrowserActionsContainer::GetViewForExtension(
const Extension* extension) {
- for (ToolbarActionView* view : toolbar_action_views_) {
+ for (BrowserActionView* view : browser_action_views_) {
if (view->view_controller()->GetId() == extension->id())
return view;
}
- return nullptr;
-}
-
-void BrowserActionsContainer::RefreshToolbarActionViews() {
- for (ToolbarActionView* view : toolbar_action_views_)
+ return NULL;
+}
+
+void BrowserActionsContainer::RefreshBrowserActionViews() {
+ for (BrowserActionView* view : browser_action_views_)
view->UpdateState();
}
-void BrowserActionsContainer::CreateToolbarActionViews() {
- DCHECK(toolbar_action_views_.empty());
+void BrowserActionsContainer::CreateBrowserActionViews() {
+ DCHECK(browser_action_views_.empty());
if (!model_)
return;
ScopedVector<ToolbarActionViewController> actions =
GetToolbarActions(model_, browser_);
for (ToolbarActionViewController* controller : actions) {
- ToolbarActionView* view =
- new ToolbarActionView(make_scoped_ptr(controller), browser_, this);
- toolbar_action_views_.push_back(view);
+ BrowserActionView* view =
+ new BrowserActionView(make_scoped_ptr(controller), browser_, this);
+ browser_action_views_.push_back(view);
AddChildView(view);
}
actions.weak_clear();
}
-void BrowserActionsContainer::DeleteToolbarActionViews() {
+void BrowserActionsContainer::DeleteBrowserActionViews() {
HideActivePopup();
- STLDeleteElements(&toolbar_action_views_);
+ STLDeleteElements(&browser_action_views_);
}
size_t BrowserActionsContainer::VisibleBrowserActions() const {
size_t visible_actions = 0;
- for (const ToolbarActionView* view : toolbar_action_views_) {
+ for (const BrowserActionView* view : browser_action_views_) {
if (view->visible())
++visible_actions;
}
@@ -253,7 +252,7 @@
// can't possibly have had no visible icons on the main bar.
DCHECK_NE(0, icon_count);
if (icon_count == -1)
- icon_count = toolbar_action_views_.size();
+ icon_count = browser_action_views_.size();
model_->SetVisibleIconCount(icon_count - 1);
}
@@ -261,7 +260,7 @@
return in_overflow_mode();
}
-void BrowserActionsContainer::OnToolbarActionViewDragDone() {
+void BrowserActionsContainer::OnBrowserActionViewDragDone() {
ToolbarVisibleCountChanged();
FOR_EACH_OBSERVER(BrowserActionsContainerObserver,
observers_,
@@ -276,7 +275,7 @@
BrowserView::GetBrowserViewForBrowser(browser_)->toolbar()->app_menu();
}
-void BrowserActionsContainer::SetPopupOwner(ToolbarActionView* popup_owner) {
+void BrowserActionsContainer::SetPopupOwner(BrowserActionView* popup_owner) {
// We should never be setting a popup owner when one already exists, and
// never unsetting one when one wasn't set.
DCHECK((!popup_owner_ && popup_owner) ||
@@ -289,21 +288,21 @@
popup_owner_->view_controller()->HidePopup();
}
-ToolbarActionView* BrowserActionsContainer::GetMainViewForAction(
- ToolbarActionView* view) {
+BrowserActionView* BrowserActionsContainer::GetMainViewForAction(
+ BrowserActionView* view) {
if (!in_overflow_mode())
return view; // This is the main view.
// The overflow container and main container each have the same views and
// view indices, so we can return the view of the index that |view| has in
// this container.
- ToolbarActionViews::const_iterator iter =
- std::find(toolbar_action_views_.begin(),
- toolbar_action_views_.end(),
+ BrowserActionViews::const_iterator iter =
+ std::find(browser_action_views_.begin(),
+ browser_action_views_.end(),
view);
- DCHECK(iter != toolbar_action_views_.end());
- size_t index = iter - toolbar_action_views_.begin();
- return main_container_->toolbar_action_views_[index];
+ DCHECK(iter != browser_action_views_.end());
+ size_t index = iter - browser_action_views_.begin();
+ return main_container_->browser_action_views_[index];
}
void BrowserActionsContainer::AddObserver(
@@ -330,7 +329,7 @@
}
// If there are no actions to show, then don't show the container at all.
- if (toolbar_action_views_.empty())
+ if (browser_action_views_.empty())
return gfx::Size();
// We calculate the size of the view by taking the current width and
@@ -357,7 +356,7 @@
}
void BrowserActionsContainer::Layout() {
- if (toolbar_action_views_.empty()) {
+ if (browser_action_views_.empty()) {
SetVisible(false);
return;
}
@@ -392,17 +391,17 @@
// can display with the given width. We add an extra kItemSpacing because the
// last icon doesn't need padding, but we want it to divide easily.
size_t end_index = in_overflow_mode() ?
- toolbar_action_views_.size() :
+ browser_action_views_.size() :
(max_x - 2 * container_padding + kItemSpacing) / IconWidth(true);
// The maximum length for one row of icons.
size_t row_length =
in_overflow_mode() ? icons_per_overflow_menu_row_ : end_index;
- // Now draw the icons for the actions in the available space. Once all the
- // variables are in place, the layout works equally well for the main and
- // overflow container.
- for (size_t i = 0u; i < toolbar_action_views_.size(); ++i) {
- ToolbarActionView* view = toolbar_action_views_[i];
+ // Now draw the icons for the browser actions in the available space. Once
+ // all the variables are in place, the layout works equally well for the main
+ // and overflow container.
+ for (size_t i = 0u; i < browser_action_views_.size(); ++i) {
+ BrowserActionView* view = browser_action_views_[i];
if (i < start_index || i >= end_index) {
view->SetVisible(false);
} else {
@@ -436,8 +435,8 @@
const ui::DropTargetEvent& event) {
size_t row_index = 0;
size_t before_icon_in_row = 0;
- // If there are no visible actions (such as when dragging an icon to an empty
- // overflow/main container), then 0, 0 for row, column is correct.
+ // If there are no visible browser actions (such as when dragging an icon to
+ // an empty overflow/main container), then 0, 0 for row, column is correct.
if (VisibleBrowserActions() != 0) {
// Figure out where to display the indicator. This is a complex calculation:
@@ -542,7 +541,7 @@
// If this was a drag between containers, we will have to adjust the number of
// visible icons.
bool drag_between_containers =
- !toolbar_action_views_[data.index()]->visible();
+ !browser_action_views_[data.index()]->visible();
model_->MoveExtensionIcon(GetIdAt(data.index()), i);
if (drag_between_containers) {
@@ -568,10 +567,10 @@
OSExchangeData* data) {
DCHECK(data);
- ToolbarActionViews::iterator iter = std::find(toolbar_action_views_.begin(),
- toolbar_action_views_.end(),
+ BrowserActionViews::iterator iter = std::find(browser_action_views_.begin(),
+ browser_action_views_.end(),
sender);
- DCHECK(iter != toolbar_action_views_.end());
+ DCHECK(iter != browser_action_views_.end());
ToolbarActionViewController* view_controller = (*iter)->view_controller();
drag_utils::SetDragImageOnDataObject(
view_controller->GetIconWithBadge(),
@@ -579,7 +578,7 @@
data);
// Fill in the remaining info.
BrowserActionDragData drag_data(view_controller->GetId(),
- iter - toolbar_action_views_.begin());
+ iter - browser_action_views_.begin());
drag_data.Write(profile_, data);
}
@@ -659,7 +658,7 @@
void BrowserActionsContainer::OnPaint(gfx::Canvas* canvas) {
// If the views haven't been initialized yet, wait for the next call to
// paint (one will be triggered by entering highlight mode).
- if (model_->is_highlighting() && !toolbar_action_views_.empty() &&
+ if (model_->is_highlighting() && !browser_action_views_.empty() &&
!in_overflow_mode()) {
views::Painter::PaintPainterAt(
canvas, highlight_painter_.get(), GetLocalBounds());
@@ -726,7 +725,7 @@
// We do this here instead of in the constructor because AddBrowserAction
// calls Layout on the Toolbar, which needs this object to be constructed
// before its Layout function is called.
- CreateToolbarActionViews();
+ CreateBrowserActionViews();
}
}
@@ -756,17 +755,18 @@
void BrowserActionsContainer::ToolbarExtensionAdded(const Extension* extension,
int index) {
-#if !defined(NDEBUG)
- for (size_t i = 0; i < toolbar_action_views_.size(); ++i) {
- DCHECK(GetViewForExtension(extension) == nullptr) <<
- "Asked to add an action view for an extension that already exists";
+#if defined(DEBUG)
+ for (size_t i = 0; i < browser_action_views_.size(); ++i) {
+ DCHECK(browser_action_views_[i]->extension() != extension) <<
+ "Asked to add a browser action view for an extension that already "
+ "exists.";
}
#endif
if (chevron_)
chevron_->CloseMenu();
- // Add the new action to the vector and the view hierarchy.
- ToolbarActionView* view = new ToolbarActionView(
+ // Add the new browser action to the vector and the view hierarchy.
+ BrowserActionView* view = new BrowserActionView(
make_scoped_ptr(new ExtensionActionViewController(
extension,
browser_,
@@ -774,7 +774,7 @@
GetExtensionAction(*extension))),
browser_,
this);
- toolbar_action_views_.insert(toolbar_action_views_.begin() + index, view);
+ browser_action_views_.insert(browser_action_views_.begin() + index, view);
AddChildViewAt(view, index);
// If we are still initializing the container, don't bother animating.
@@ -792,7 +792,7 @@
// will need to be displayed.
int model_icon_count = model_->GetVisibleIconCount();
if (model_icon_count == -1 ||
- (static_cast<size_t>(model_icon_count) < toolbar_action_views_.size() &&
+ (static_cast<size_t>(model_icon_count) < browser_action_views_.size() &&
(chevron_ && !chevron_->visible()))) {
suppress_chevron_ = true;
Animate(gfx::Tween::LINEAR, GetIconCount());
@@ -811,11 +811,11 @@
chevron_->CloseMenu();
size_t visible_actions = VisibleBrowserActionsAfterAnimation();
- for (ToolbarActionViews::iterator i(toolbar_action_views_.begin());
- i != toolbar_action_views_.end(); ++i) {
+ for (BrowserActionViews::iterator i(browser_action_views_.begin());
+ i != browser_action_views_.end(); ++i) {
if ((*i)->view_controller()->GetId() == extension->id()) {
delete *i;
- toolbar_action_views_.erase(i);
+ browser_action_views_.erase(i);
// If the extension is being upgraded we don't want the bar to shrink
// because the icon is just going to get re-added to the same location.
@@ -823,7 +823,7 @@
IsBeingUpgraded(extension))
return;
- if (toolbar_action_views_.size() > visible_actions) {
+ if (browser_action_views_.size() > visible_actions) {
// If we have more icons than we can show, then we must not be changing
// the container size (since we either removed an icon from the main
// area and one from the overflow list will have shifted in, or we
@@ -834,7 +834,7 @@
// overflow container by 1. Either way the size changed, so animate.
if (chevron_)
chevron_->SetVisible(false);
- Animate(gfx::Tween::EASE_OUT, toolbar_action_views_.size());
+ Animate(gfx::Tween::EASE_OUT, browser_action_views_.size());
}
return; // We have found the action to remove, bail out.
}
@@ -843,21 +843,21 @@
void BrowserActionsContainer::ToolbarExtensionMoved(const Extension* extension,
int index) {
- DCHECK(index >= 0 && index < static_cast<int>(toolbar_action_views_.size()));
-
- ToolbarActionViews::iterator iter = toolbar_action_views_.begin();
- while (iter != toolbar_action_views_.end() &&
+ DCHECK(index >= 0 && index < static_cast<int>(browser_action_views_.size()));
+
+ BrowserActionViews::iterator iter = browser_action_views_.begin();
+ while (iter != browser_action_views_.end() &&
(*iter)->view_controller()->GetId() != extension->id())
++iter;
- DCHECK(iter != toolbar_action_views_.end());
- if (iter - toolbar_action_views_.begin() == index)
+ DCHECK(iter != browser_action_views_.end());
+ if (iter - browser_action_views_.begin() == index)
return; // Already in place.
- ToolbarActionView* moved_view = *iter;
- toolbar_action_views_.erase(iter);
- toolbar_action_views_.insert(
- toolbar_action_views_.begin() + index, moved_view);
+ BrowserActionView* moved_view = *iter;
+ browser_action_views_.erase(iter);
+ browser_action_views_.insert(
+ browser_action_views_.begin() + index, moved_view);
Layout();
SchedulePaint();
@@ -865,7 +865,7 @@
void BrowserActionsContainer::ToolbarExtensionUpdated(
const Extension* extension) {
- ToolbarActionView* view = GetViewForExtension(extension);
+ BrowserActionView* view = GetViewForExtension(extension);
// There might not be a view in cases where we are highlighting or if we
// haven't fully initialized extensions.
if (view)
@@ -879,7 +879,7 @@
if (popup_owner_ || !browser_->window()->IsActive())
return false;
- ToolbarActionView* view = GetViewForExtension(extension);
+ BrowserActionView* view = GetViewForExtension(extension);
return view && view->view_controller()->ExecuteAction(grant_active_tab);
}
@@ -894,8 +894,8 @@
// we delete and recreate everything here, but given everything else going on
// (the lack of highlight, n more extensions appearing, etc), it's not worth
// the extra complexity to create and insert only the new extensions.
- DeleteToolbarActionViews();
- CreateToolbarActionViews();
+ DeleteBrowserActionViews();
+ CreateBrowserActionViews();
Animate(gfx::Tween::LINEAR, GetIconCount());
}
@@ -918,7 +918,7 @@
}
void BrowserActionsContainer::OnBrowserActionVisibilityChanged() {
- SetVisible(!toolbar_action_views_.empty());
+ SetVisible(!browser_action_views_.empty());
if (parent()) { // Parent can be null in testing.
parent()->Layout();
parent()->SchedulePaint();
@@ -932,15 +932,15 @@
void BrowserActionsContainer::SetChevronVisibility() {
if (chevron_) {
chevron_->SetVisible(
- VisibleBrowserActionsAfterAnimation() < toolbar_action_views_.size());
+ VisibleBrowserActionsAfterAnimation() < browser_action_views_.size());
}
}
int BrowserActionsContainer::IconCountToWidth(int icons) const {
if (icons < 0)
- icons = toolbar_action_views_.size();
+ icons = browser_action_views_.size();
bool display_chevron =
- chevron_ && static_cast<size_t>(icons) < toolbar_action_views_.size();
+ chevron_ && static_cast<size_t>(icons) < browser_action_views_.size();
if (icons == 0 && !display_chevron)
return ToolbarView::kStandardSpacing;
int icons_size =
@@ -960,7 +960,7 @@
size_t BrowserActionsContainer::WidthToIconCount(int pixels) const {
// Check for widths large enough to show the entire icon set.
if (pixels >= IconCountToWidth(-1))
- return toolbar_action_views_.size();
+ return browser_action_views_.size();
// We reserve space for the padding on either side of the toolbar...
int available_space = pixels - (ToolbarView::kStandardSpacing * 2);
@@ -1006,19 +1006,19 @@
size_t absolute_model_visible_size = model_visible_size == -1 ?
model_->toolbar_items().size() : model_visible_size;
-#if !defined(NDEBUG)
+#if defined(DEBUG)
// Good time for some sanity checks: We should never try to display more
// icons than we have, and we should always have a view per item in the model.
// (The only exception is if this is in initialization.)
if (initialized_) {
size_t num_extension_actions = 0u;
- for (ToolbarActionView* view : toolbar_action_views_) {
+ for (const BrowserActionView* view : browser_action_views_) {
num_extension_actions +=
- crx_file::id_util::IdIsValid(view->view_controller()->GetId()) ?
- 1 : 0;
+ view->view_controller()->GetType() ==
+ ToolbarActionViewController::TYPE_EXTENSION_ACTION ? 1 : 0;
}
- DCHECK_LE(absolute_model_visible_size, toolbar_action_views_.size());
- DCHECK_EQ(model_->toolbar_items().size(), toolbar_action_views_.size());
+ DCHECK_LE(absolute_model_visible_size, browser_action_views_.size());
+ DCHECK_EQ(model_->toolbar_items().size(), browser_action_views_.size());
}
#endif

Powered by Google App Engine
This is Rietveld 408576698