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

Side by Side Diff: chrome/browser/ui/views/infobars/after_translate_infobar.cc

Issue 7981045: Make infobars ignore button clicks when closing. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/infobars/after_translate_infobar.h" 5 #include "chrome/browser/ui/views/infobars/after_translate_infobar.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/translate/translate_infobar_delegate.h" 8 #include "chrome/browser/translate/translate_infobar_delegate.h"
9 #include "grit/generated_resources.h" 9 #include "grit/generated_resources.h"
10 #include "ui/base/l10n/l10n_util.h" 10 #include "ui/base/l10n/l10n_util.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 119
120 // These must happen after adding all children because they trigger layout, 120 // These must happen after adding all children because they trigger layout,
121 // which assumes that particular children (e.g. the close button) have already 121 // which assumes that particular children (e.g. the close button) have already
122 // been added. 122 // been added.
123 OriginalLanguageChanged(); 123 OriginalLanguageChanged();
124 TargetLanguageChanged(); 124 TargetLanguageChanged();
125 } 125 }
126 126
127 void AfterTranslateInfoBar::ButtonPressed(views::Button* sender, 127 void AfterTranslateInfoBar::ButtonPressed(views::Button* sender,
128 const views::Event& event) { 128 const views::Event& event) {
129 if (!owned())
130 return; // We're closing; don't call anything, it might access the owner.
129 if (sender == revert_button_) 131 if (sender == revert_button_)
130 GetDelegate()->RevertTranslation(); 132 GetDelegate()->RevertTranslation();
131 else 133 else
132 TranslateInfoBarBase::ButtonPressed(sender, event); 134 TranslateInfoBarBase::ButtonPressed(sender, event);
133 } 135 }
134 136
135 int AfterTranslateInfoBar::ContentMinimumWidth() const { 137 int AfterTranslateInfoBar::ContentMinimumWidth() const {
136 return 138 return
137 (kButtonInLabelSpacing + 139 (kButtonInLabelSpacing +
138 original_language_menu_button_->GetPreferredSize().width() + 140 original_language_menu_button_->GetPreferredSize().width() +
(...skipping 17 matching lines...) Expand all
156 void AfterTranslateInfoBar::TargetLanguageChanged() { 158 void AfterTranslateInfoBar::TargetLanguageChanged() {
157 // Tests can call this function when the infobar has never been added to a 159 // Tests can call this function when the infobar has never been added to a
158 // view hierarchy and thus there is no button. 160 // view hierarchy and thus there is no button.
159 if (target_language_menu_button_) { 161 if (target_language_menu_button_) {
160 UpdateLanguageButtonText(target_language_menu_button_, 162 UpdateLanguageButtonText(target_language_menu_button_,
161 LanguagesMenuModel::TARGET); 163 LanguagesMenuModel::TARGET);
162 } 164 }
163 } 165 }
164 166
165 void AfterTranslateInfoBar::RunMenu(View* source, const gfx::Point& pt) { 167 void AfterTranslateInfoBar::RunMenu(View* source, const gfx::Point& pt) {
168 if (!owned())
169 return; // We're closing; don't call anything, it might access the owner.
166 ui::MenuModel* menu_model = NULL; 170 ui::MenuModel* menu_model = NULL;
167 views::MenuButton* button = NULL; 171 views::MenuButton* button = NULL;
168 views::MenuItemView::AnchorPosition anchor = views::MenuItemView::TOPLEFT; 172 views::MenuItemView::AnchorPosition anchor = views::MenuItemView::TOPLEFT;
169 if (source == original_language_menu_button_) { 173 if (source == original_language_menu_button_) {
170 menu_model = &original_language_menu_model_; 174 menu_model = &original_language_menu_model_;
171 button = original_language_menu_button_; 175 button = original_language_menu_button_;
172 } else if (source == target_language_menu_button_) { 176 } else if (source == target_language_menu_button_) {
173 menu_model = &target_language_menu_model_; 177 menu_model = &target_language_menu_model_;
174 button = target_language_menu_button_; 178 button = target_language_menu_button_;
175 } else { 179 } else {
176 DCHECK_EQ(options_menu_button_, source); 180 DCHECK_EQ(options_menu_button_, source);
177 menu_model = &options_menu_model_; 181 menu_model = &options_menu_model_;
178 button = options_menu_button_; 182 button = options_menu_button_;
179 anchor = views::MenuItemView::TOPRIGHT; 183 anchor = views::MenuItemView::TOPRIGHT;
180 } 184 }
181 RunMenuAt(menu_model, button, anchor); 185 RunMenuAt(menu_model, button, anchor);
182 // TODO(pkasting): this may be deleted after rewrite.
183 } 186 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698