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/ui/views/infobars/before_translate_infobar.h" | 5 #include "chrome/browser/ui/views/infobars/before_translate_infobar.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/translate/options_menu_model.h" |
8 #include "chrome/browser/translate/translate_infobar_delegate.h" | 9 #include "chrome/browser/translate/translate_infobar_delegate.h" |
| 10 #include "chrome/browser/ui/views/infobars/translate_language_menu_model.h" |
9 #include "grit/generated_resources.h" | 11 #include "grit/generated_resources.h" |
10 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
11 #include "ui/views/controls/button/label_button.h" | 13 #include "ui/views/controls/button/label_button.h" |
12 #include "ui/views/controls/button/menu_button.h" | 14 #include "ui/views/controls/button/menu_button.h" |
13 #include "ui/views/controls/label.h" | 15 #include "ui/views/controls/label.h" |
14 #include "ui/views/controls/menu/menu_item_view.h" | 16 #include "ui/views/controls/menu/menu_item_view.h" |
15 | 17 |
16 BeforeTranslateInfoBar::BeforeTranslateInfoBar( | 18 BeforeTranslateInfoBar::BeforeTranslateInfoBar( |
17 InfoBarService* owner, | 19 scoped_ptr<TranslateInfoBarDelegate> delegate) |
18 TranslateInfoBarDelegate* delegate) | 20 : TranslateInfoBarBase(delegate.Pass()), |
19 : TranslateInfoBarBase(owner, delegate), | |
20 label_1_(NULL), | 21 label_1_(NULL), |
21 label_2_(NULL), | 22 label_2_(NULL), |
22 language_menu_button_(NULL), | 23 language_menu_button_(NULL), |
23 accept_button_(NULL), | 24 accept_button_(NULL), |
24 deny_button_(NULL), | 25 deny_button_(NULL), |
25 never_translate_button_(NULL), | 26 never_translate_button_(NULL), |
26 always_translate_button_(NULL), | 27 always_translate_button_(NULL), |
27 options_menu_button_(NULL), | 28 options_menu_button_(NULL) { |
28 options_menu_model_(delegate) { | |
29 } | 29 } |
30 | 30 |
31 BeforeTranslateInfoBar::~BeforeTranslateInfoBar() { | 31 BeforeTranslateInfoBar::~BeforeTranslateInfoBar() { |
32 } | 32 } |
33 | 33 |
34 void BeforeTranslateInfoBar::Layout() { | 34 void BeforeTranslateInfoBar::Layout() { |
35 TranslateInfoBarBase::Layout(); | 35 TranslateInfoBarBase::Layout(); |
36 | 36 |
37 int available_width = std::max(0, EndX() - StartX() - ContentMinimumWidth()); | 37 int available_width = std::max(0, EndX() - StartX() - ContentMinimumWidth()); |
38 gfx::Size label_1_size = label_1_->GetPreferredSize(); | 38 gfx::Size label_1_size = label_1_->GetPreferredSize(); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 AddChildView(never_translate_button_); | 126 AddChildView(never_translate_button_); |
127 } else if (delegate->ShouldShowAlwaysTranslateShortcut()) { | 127 } else if (delegate->ShouldShowAlwaysTranslateShortcut()) { |
128 always_translate_button_ = CreateLabelButton(this, | 128 always_translate_button_ = CreateLabelButton(this, |
129 l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_ALWAYS_TRANSLATE, | 129 l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_ALWAYS_TRANSLATE, |
130 language), false); | 130 language), false); |
131 AddChildView(always_translate_button_); | 131 AddChildView(always_translate_button_); |
132 } | 132 } |
133 | 133 |
134 options_menu_button_ = CreateMenuButton( | 134 options_menu_button_ = CreateMenuButton( |
135 l10n_util::GetStringUTF16(IDS_TRANSLATE_INFOBAR_OPTIONS), this); | 135 l10n_util::GetStringUTF16(IDS_TRANSLATE_INFOBAR_OPTIONS), this); |
| 136 options_menu_model_.reset(new OptionsMenuModel(delegate)); |
136 AddChildView(options_menu_button_); | 137 AddChildView(options_menu_button_); |
137 | 138 |
138 // This must happen after adding all other children so InfoBarView can ensure | 139 // This must happen after adding all other children so InfoBarView can ensure |
139 // the close button is the last child. | 140 // the close button is the last child. |
140 TranslateInfoBarBase::ViewHierarchyChanged(details); | 141 TranslateInfoBarBase::ViewHierarchyChanged(details); |
141 | 142 |
142 // This must happen after adding all children because it triggers layout, | 143 // This must happen after adding all children because it triggers layout, |
143 // which assumes that particular children (e.g. the close button) have already | 144 // which assumes that particular children (e.g. the close button) have already |
144 // been added. | 145 // been added. |
145 UpdateLanguageButtonText(language_menu_button_, | 146 UpdateLanguageButtonText(language_menu_button_, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 | 184 |
184 void BeforeTranslateInfoBar::OnMenuButtonClicked(views::View* source, | 185 void BeforeTranslateInfoBar::OnMenuButtonClicked(views::View* source, |
185 const gfx::Point& point) { | 186 const gfx::Point& point) { |
186 if (!owner()) | 187 if (!owner()) |
187 return; // We're closing; don't call anything, it might access the owner. | 188 return; // We're closing; don't call anything, it might access the owner. |
188 if (source == language_menu_button_) { | 189 if (source == language_menu_button_) { |
189 RunMenuAt(language_menu_model_.get(), language_menu_button_, | 190 RunMenuAt(language_menu_model_.get(), language_menu_button_, |
190 views::MenuItemView::TOPLEFT); | 191 views::MenuItemView::TOPLEFT); |
191 } else { | 192 } else { |
192 DCHECK_EQ(options_menu_button_, source); | 193 DCHECK_EQ(options_menu_button_, source); |
193 RunMenuAt(&options_menu_model_, options_menu_button_, | 194 RunMenuAt(options_menu_model_.get(), options_menu_button_, |
194 views::MenuItemView::TOPRIGHT); | 195 views::MenuItemView::TOPRIGHT); |
195 } | 196 } |
196 } | 197 } |
OLD | NEW |