OLD | NEW |
1 // Copyright (c) 2011 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/ui/views/infobars/before_translate_infobar.h" | 5 #include "chrome/browser/ui/views/infobars/before_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" |
11 #include "ui/views/controls/button/menu_button.h" | 11 #include "ui/views/controls/button/menu_button.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 OffsetY(always_button_size), always_button_size.width(), | 78 OffsetY(always_button_size), always_button_size.width(), |
79 always_button_size.height()); | 79 always_button_size.height()); |
80 } | 80 } |
81 | 81 |
82 gfx::Size options_size = options_menu_button_->GetPreferredSize(); | 82 gfx::Size options_size = options_menu_button_->GetPreferredSize(); |
83 options_menu_button_->SetBounds(EndX() - options_size.width(), | 83 options_menu_button_->SetBounds(EndX() - options_size.width(), |
84 OffsetY(options_size), options_size.width(), options_size.height()); | 84 OffsetY(options_size), options_size.width(), options_size.height()); |
85 } | 85 } |
86 | 86 |
87 void BeforeTranslateInfoBar::ViewHierarchyChanged(bool is_add, | 87 void BeforeTranslateInfoBar::ViewHierarchyChanged(bool is_add, |
88 View* parent, | 88 views::View* parent, |
89 View* child) { | 89 views::View* child) { |
90 if (!is_add || (child != this) || (label_1_ != NULL)) { | 90 if (!is_add || (child != this) || (label_1_ != NULL)) { |
91 TranslateInfoBarBase::ViewHierarchyChanged(is_add, parent, child); | 91 TranslateInfoBarBase::ViewHierarchyChanged(is_add, parent, child); |
92 return; | 92 return; |
93 } | 93 } |
94 | 94 |
95 size_t offset = 0; | 95 size_t offset = 0; |
96 string16 text(l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_BEFORE_MESSAGE, | 96 string16 text(l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_BEFORE_MESSAGE, |
97 string16(), &offset)); | 97 string16(), &offset)); |
98 | 98 |
99 label_1_ = CreateLabel(text.substr(0, offset)); | 99 label_1_ = CreateLabel(text.substr(0, offset)); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 | 180 |
181 void BeforeTranslateInfoBar::OriginalLanguageChanged() { | 181 void BeforeTranslateInfoBar::OriginalLanguageChanged() { |
182 // Tests can call this function when the infobar has never been added to a | 182 // Tests can call this function when the infobar has never been added to a |
183 // view hierarchy and thus there is no button. | 183 // view hierarchy and thus there is no button. |
184 if (language_menu_button_) { | 184 if (language_menu_button_) { |
185 UpdateLanguageButtonText(language_menu_button_, | 185 UpdateLanguageButtonText(language_menu_button_, |
186 LanguagesMenuModel::ORIGINAL); | 186 LanguagesMenuModel::ORIGINAL); |
187 } | 187 } |
188 } | 188 } |
189 | 189 |
190 void BeforeTranslateInfoBar::RunMenu(View* source, const gfx::Point& pt) { | 190 void BeforeTranslateInfoBar::OnMenuButtonClicked(views::View* source, |
| 191 const gfx::Point& point) { |
191 if (!owned()) | 192 if (!owned()) |
192 return; // We're closing; don't call anything, it might access the owner. | 193 return; // We're closing; don't call anything, it might access the owner. |
193 ui::MenuModel* menu_model = NULL; | 194 ui::MenuModel* menu_model = NULL; |
194 views::MenuButton* button = NULL; | 195 views::MenuButton* button = NULL; |
195 views::MenuItemView::AnchorPosition anchor = views::MenuItemView::TOPLEFT; | 196 views::MenuItemView::AnchorPosition anchor = views::MenuItemView::TOPLEFT; |
196 if (source == language_menu_button_) { | 197 if (source == language_menu_button_) { |
197 menu_model = &languages_menu_model_; | 198 menu_model = &languages_menu_model_; |
198 button = language_menu_button_; | 199 button = language_menu_button_; |
199 } else { | 200 } else { |
200 DCHECK_EQ(options_menu_button_, source); | 201 DCHECK_EQ(options_menu_button_, source); |
201 menu_model = &options_menu_model_; | 202 menu_model = &options_menu_model_; |
202 button = options_menu_button_; | 203 button = options_menu_button_; |
203 anchor = views::MenuItemView::TOPRIGHT; | 204 anchor = views::MenuItemView::TOPRIGHT; |
204 } | 205 } |
205 RunMenuAt(menu_model, button, anchor); | 206 RunMenuAt(menu_model, button, anchor); |
206 } | 207 } |
OLD | NEW |