summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-29 18:07:40 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-29 18:07:40 +0000
commitb8005ef1c304bcb20442c78077bd8af8d6691f2d (patch)
treed06f9738db7b4dd3893d54a98925d057e8240bdc /chrome
parent437cf0eb7842e8db4a5702b4e18a5b865e58042a (diff)
downloadchromium_src-b8005ef1c304bcb20442c78077bd8af8d6691f2d.zip
chromium_src-b8005ef1c304bcb20442c78077bd8af8d6691f2d.tar.gz
chromium_src-b8005ef1c304bcb20442c78077bd8af8d6691f2d.tar.bz2
Clean up some things about LocationBarView:
* PageActionViews can be parent-owned, simplifying things. * Using iterators in some loops could make a few things less verbose. * Misc. other tiny bits like removed extra qualifiers or unneeded blank lines. BUG=none TEST=none Review URL: http://codereview.chromium.org/557053 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37520 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/views/location_bar_view.cc77
-rw-r--r--chrome/browser/views/location_bar_view.h15
2 files changed, 41 insertions, 51 deletions
diff --git a/chrome/browser/views/location_bar_view.cc b/chrome/browser/views/location_bar_view.cc
index 130ff4c..450b8d6 100644
--- a/chrome/browser/views/location_bar_view.cc
+++ b/chrome/browser/views/location_bar_view.cc
@@ -150,7 +150,6 @@ LocationBarView::LocationBarView(Profile* profile,
}
LocationBarView::~LocationBarView() {
- DeletePageActionViews();
}
void LocationBarView::Init() {
@@ -346,11 +345,10 @@ void LocationBarView::SetPreviewEnabledPageAction(ExtensionAction *page_action,
views::View* LocationBarView::GetPageActionView(
ExtensionAction *page_action) {
DCHECK(page_action);
- for (std::vector<PageActionWithBadgeView*>::iterator iter =
- page_action_views_.begin(); iter != page_action_views_.end();
- ++iter) {
- if ((*iter)->image_view()->page_action() == page_action)
- return *iter;
+ for (PageActionViews::const_iterator i(page_action_views_.begin());
+ i != page_action_views_.end(); ++i) {
+ if ((*i)->image_view()->page_action() == page_action)
+ return *i;
}
return NULL;
}
@@ -467,6 +465,10 @@ void LocationBarView::OnChanged() {
DoLayout(false);
}
+void LocationBarView::OnInputInProgress(bool in_progress) {
+ delegate_->OnInputInProgress(in_progress);
+}
+
void LocationBarView::OnKillFocus() {
}
@@ -497,12 +499,10 @@ void LocationBarView::DoLayout(const bool force_layout) {
int entry_width = width() - (kEntryPadding * 2);
- gfx::Size page_action_size;
- for (size_t i = 0; i < page_action_views_.size(); i++) {
- if (page_action_views_[i]->IsVisible()) {
- page_action_size = page_action_views_[i]->GetPreferredSize();
- entry_width -= page_action_size.width() + kInnerPadding;
- }
+ for (PageActionViews::const_iterator i(page_action_views_.begin());
+ i != page_action_views_.end(); ++i) {
+ if ((*i)->IsVisible())
+ entry_width -= (*i)->GetPreferredSize().width() + kInnerPadding;
}
gfx::Size security_image_size;
if (security_image_view_.IsVisible()) {
@@ -556,13 +556,12 @@ void LocationBarView::DoLayout(const bool force_layout) {
offset -= kInnerPadding;
}
- for (size_t i = 0; i < page_action_views_.size(); i++) {
- if (page_action_views_[i]->IsVisible()) {
- page_action_size = page_action_views_[i]->GetPreferredSize();
- offset -= page_action_size.width();
- page_action_views_[i]->SetBounds(offset, location_y,
- page_action_size.width(),
- location_height);
+ for (PageActionViews::const_iterator i(page_action_views_.begin());
+ i != page_action_views_.end(); ++i) {
+ if ((*i)->IsVisible()) {
+ int page_action_width = (*i)->GetPreferredSize().width();
+ offset -= page_action_width;
+ (*i)->SetBounds(offset, location_y, page_action_width, location_height);
offset -= kInnerPadding;
}
}
@@ -698,13 +697,10 @@ void LocationBarView::SetSecurityIcon(ToolbarModel::Icon icon) {
}
void LocationBarView::DeletePageActionViews() {
- if (!page_action_views_.empty()) {
- for (size_t i = 0; i < page_action_views_.size(); ++i)
- RemoveChildView(page_action_views_[i]);
- STLDeleteContainerPointers(page_action_views_.begin(),
- page_action_views_.end());
- page_action_views_.clear();
- }
+ for (PageActionViews::const_iterator i(page_action_views_.begin());
+ i != page_action_views_.end(); ++i)
+ RemoveChildView(*i);
+ STLDeleteElements(&page_action_views_);
}
void LocationBarView::RefreshPageActionViews() {
@@ -714,10 +710,9 @@ void LocationBarView::RefreshPageActionViews() {
return;
std::map<ExtensionAction*, bool> old_visibility;
- for (size_t i = 0; i < page_action_views_.size(); i++) {
- old_visibility[page_action_views_[i]->image_view()->page_action()] =
- page_action_views_[i]->IsVisible();
- }
+ for (PageActionViews::const_iterator i(page_action_views_.begin());
+ i != page_action_views_.end(); ++i)
+ old_visibility[(*i)->image_view()->page_action()] = (*i)->IsVisible();
// Remember the previous visibility of the page actions so that we can
// notify when this changes.
@@ -738,7 +733,6 @@ void LocationBarView::RefreshPageActionViews() {
new PageActionImageView(this, profile_,
page_actions[i], bubble_positioner_));
page_action_views_[i]->SetVisible(false);
- page_action_views_[i]->set_parent_owned(false);
AddChildView(page_action_views_[i]);
}
}
@@ -747,14 +741,14 @@ void LocationBarView::RefreshPageActionViews() {
if (!page_action_views_.empty() && contents) {
GURL url = GURL(WideToUTF8(model_->GetText()));
- for (size_t i = 0; i < page_action_views_.size(); i++) {
- page_action_views_[i]->UpdateVisibility(contents, url);
+ for (PageActionViews::const_iterator i(page_action_views_.begin());
+ i != page_action_views_.end(); ++i) {
+ (*i)->UpdateVisibility(contents, url);
// Check if the visibility of the action changed and notify if it did.
- ExtensionAction* action =
- page_action_views_[i]->image_view()->page_action();
+ ExtensionAction* action = (*i)->image_view()->page_action();
if (old_visibility.find(action) == old_visibility.end() ||
- old_visibility[action] != page_action_views_[i]->IsVisible()) {
+ old_visibility[action] != (*i)->IsVisible()) {
NotificationService::current()->Notify(
NotificationType::EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED,
Source<ExtensionAction>(action),
@@ -1238,10 +1232,10 @@ LocationBarView::SecurityImageView::~SecurityImageView() {
void LocationBarView::SecurityImageView::SetImageShown(Image image) {
switch (image) {
case LOCK:
- ImageView::SetImage(lock_icon_);
+ SetImage(lock_icon_);
break;
case WARNING:
- ImageView::SetImage(warning_icon_);
+ SetImage(warning_icon_);
break;
default:
NOTREACHED();
@@ -1467,7 +1461,7 @@ void LocationBarView::PageActionImageView::UpdateVisibility(
}
if (!icon.isNull())
- ImageView::SetImage(&icon);
+ SetImage(&icon);
}
SetVisible(visible);
}
@@ -1611,13 +1605,14 @@ void LocationBarView::TestPageActionPressed(size_t index) {
for (size_t i = 0; i < page_action_views_.size(); ++i) {
if (page_action_views_[i]->IsVisible()) {
if (current == index) {
- const int button = 1; // Left mouse button.
- page_action_views_[i]->image_view()->ExecuteAction(button);
+ const int kLeftMouseButton = 1;
+ page_action_views_[i]->image_view()->ExecuteAction(kLeftMouseButton);
return;
}
++current;
}
}
}
+
NOTREACHED();
}
diff --git a/chrome/browser/views/location_bar_view.h b/chrome/browser/views/location_bar_view.h
index cc7fb215..ad168f0 100644
--- a/chrome/browser/views/location_bar_view.h
+++ b/chrome/browser/views/location_bar_view.h
@@ -109,7 +109,7 @@ class LocationBarView : public LocationBar,
void SetPreviewEnabledPageAction(ExtensionAction *page_action,
bool preview_enabled);
- // Retrieves the PageAction View which is associated with |page_action|
+ // Retrieves the PageAction View which is associated with |page_action|.
views::View* GetPageActionView(ExtensionAction* page_action);
// Sizing functions
@@ -126,7 +126,6 @@ class LocationBarView : public LocationBar,
// to close its popup.
virtual void VisibleBoundsInRootChanged();
-
#if defined(OS_WIN)
// Event Handlers
virtual bool OnMousePressed(const views::MouseEvent& event);
@@ -140,9 +139,7 @@ class LocationBarView : public LocationBar,
PageTransition::Type transition,
const GURL& alternate_nav_url);
virtual void OnChanged();
- virtual void OnInputInProgress(bool in_progress) {
- delegate_->OnInputInProgress(in_progress);
- }
+ virtual void OnInputInProgress(bool in_progress);
virtual void OnKillFocus();
virtual void OnSetFocus();
virtual SkBitmap GetFavIcon() const;
@@ -273,7 +270,6 @@ class LocationBarView : public LocationBar,
DISALLOW_COPY_AND_ASSIGN(KeywordHintView);
};
-
class ShowInfoBubbleTask;
class ShowFirstRunBubbleTask;
@@ -348,9 +344,6 @@ class LocationBarView : public LocationBar,
// The warning icon shown when HTTPS is broken.
static SkBitmap* warning_icon_;
- // The currently shown info bubble if any.
- InfoBubble* info_bubble_;
-
// A task used to display the info bubble when the mouse hovers on the
// image.
ShowInfoBubbleTask* show_info_bubble_task_;
@@ -462,6 +455,8 @@ class LocationBarView : public LocationBar,
class PageActionWithBadgeView;
friend class PageActionWithBadgeView;
+ typedef std::vector<PageActionWithBadgeView*> PageActionViews;
+
// Both Layout and OnChanged call into this. This updates the contents
// of the 3 views: selected_keyword, keyword_hint and type_search_view. If
// force_layout is true, or one of these views has changed in such a way as
@@ -580,7 +575,7 @@ class LocationBarView : public LocationBar,
SecurityImageView security_image_view_;
// The page action icon views.
- std::vector<PageActionWithBadgeView*> page_action_views_;
+ PageActionViews page_action_views_;
// A label displayed after the lock icon to show some extra information.
views::Label info_label_;