| 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/options_menu_model.h" |
| 9 #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" | 10 #include "chrome/browser/ui/views/infobars/translate_language_menu_model.h" |
| 11 #include "grit/generated_resources.h" | 11 #include "grit/generated_resources.h" |
| 12 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
| 13 #include "ui/views/controls/button/label_button.h" | 13 #include "ui/views/controls/button/label_button.h" |
| 14 #include "ui/views/controls/button/menu_button.h" | 14 #include "ui/views/controls/button/menu_button.h" |
| 15 #include "ui/views/controls/label.h" | 15 #include "ui/views/controls/label.h" |
| 16 #include "ui/views/controls/menu/menu_item_view.h" | |
| 17 | 16 |
| 18 BeforeTranslateInfoBar::BeforeTranslateInfoBar( | 17 BeforeTranslateInfoBar::BeforeTranslateInfoBar( |
| 19 scoped_ptr<TranslateInfoBarDelegate> delegate) | 18 scoped_ptr<TranslateInfoBarDelegate> delegate) |
| 20 : TranslateInfoBarBase(delegate.Pass()), | 19 : TranslateInfoBarBase(delegate.Pass()), |
| 21 label_1_(NULL), | 20 label_1_(NULL), |
| 22 label_2_(NULL), | 21 label_2_(NULL), |
| 23 language_menu_button_(NULL), | 22 language_menu_button_(NULL), |
| 24 accept_button_(NULL), | 23 accept_button_(NULL), |
| 25 deny_button_(NULL), | 24 deny_button_(NULL), |
| 26 never_translate_button_(NULL), | 25 never_translate_button_(NULL), |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 } else { | 159 } else { |
| 161 TranslateInfoBarBase::ButtonPressed(sender, event); | 160 TranslateInfoBarBase::ButtonPressed(sender, event); |
| 162 } | 161 } |
| 163 } | 162 } |
| 164 | 163 |
| 165 void BeforeTranslateInfoBar::OnMenuButtonClicked(views::View* source, | 164 void BeforeTranslateInfoBar::OnMenuButtonClicked(views::View* source, |
| 166 const gfx::Point& point) { | 165 const gfx::Point& point) { |
| 167 if (!owner()) | 166 if (!owner()) |
| 168 return; // We're closing; don't call anything, it might access the owner. | 167 return; // We're closing; don't call anything, it might access the owner. |
| 169 if (source == language_menu_button_) { | 168 if (source == language_menu_button_) { |
| 170 RunMenuAt(language_menu_model_.get(), language_menu_button_, | 169 RunMenuAt(language_menu_model_.get(), |
| 171 views::MenuItemView::TOPLEFT); | 170 language_menu_button_, |
| 171 views::MENU_ANCHOR_TOPLEFT); |
| 172 } else { | 172 } else { |
| 173 DCHECK_EQ(options_menu_button_, source); | 173 DCHECK_EQ(options_menu_button_, source); |
| 174 RunMenuAt(options_menu_model_.get(), options_menu_button_, | 174 RunMenuAt(options_menu_model_.get(), |
| 175 views::MenuItemView::TOPRIGHT); | 175 options_menu_button_, |
| 176 views::MENU_ANCHOR_TOPRIGHT); |
| 176 } | 177 } |
| 177 } | 178 } |
| 178 | 179 |
| 179 int BeforeTranslateInfoBar::NonLabelWidth() const { | 180 int BeforeTranslateInfoBar::NonLabelWidth() const { |
| 180 return (label_1_->text().empty() ? 0 : kButtonInLabelSpacing) + | 181 return (label_1_->text().empty() ? 0 : kButtonInLabelSpacing) + |
| 181 language_menu_button_->width() + | 182 language_menu_button_->width() + |
| 182 (label_2_->text().empty() ? 0 : kButtonInLabelSpacing) + | 183 (label_2_->text().empty() ? 0 : kButtonInLabelSpacing) + |
| 183 kEndOfLabelSpacing + accept_button_->width() + kButtonButtonSpacing + | 184 kEndOfLabelSpacing + accept_button_->width() + kButtonButtonSpacing + |
| 184 deny_button_->width() + | 185 deny_button_->width() + |
| 185 (never_translate_button_ ? | 186 (never_translate_button_ ? |
| 186 (kButtonButtonSpacing + never_translate_button_->width()) : 0) + | 187 (kButtonButtonSpacing + never_translate_button_->width()) : 0) + |
| 187 (always_translate_button_ ? | 188 (always_translate_button_ ? |
| 188 (kButtonButtonSpacing + always_translate_button_->width()) : 0) + | 189 (kButtonButtonSpacing + always_translate_button_->width()) : 0) + |
| 189 kEndOfLabelSpacing + options_menu_button_->width(); | 190 kEndOfLabelSpacing + options_menu_button_->width(); |
| 190 } | 191 } |
| OLD | NEW |