OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/views/infobars/translate_message_infobar.h" |
| 6 |
| 7 #include "chrome/browser/translate/translate_infobar_delegate2.h" |
| 8 #include "chrome/browser/views/infobars/infobar_text_button.h" |
| 9 #include "views/controls/image_view.h" |
| 10 |
| 11 TranslateMessageInfoBar::TranslateMessageInfoBar( |
| 12 TranslateInfoBarDelegate2* delegate) |
| 13 : TranslateInfoBarBase(delegate) { |
| 14 label_ = CreateLabel(delegate->GetMessageInfoBarText()); |
| 15 AddChildView(label_); |
| 16 |
| 17 string16 button_text = delegate->GetMessageInfoBarButtonText(); |
| 18 if (button_text.empty()) { |
| 19 button_ = NULL; |
| 20 } else { |
| 21 button_ = InfoBarTextButton::Create(this, button_text); |
| 22 AddChildView(button_); |
| 23 } |
| 24 } |
| 25 |
| 26 void TranslateMessageInfoBar::Layout() { |
| 27 TranslateInfoBarBase::Layout(); |
| 28 |
| 29 int x = icon_->bounds().right() + InfoBar::kIconLabelSpacing; |
| 30 gfx::Size label_pref_size = label_->GetPreferredSize(); |
| 31 int available_width = GetAvailableWidth() - x; |
| 32 gfx::Size button_pref_size; |
| 33 if (button_) { |
| 34 button_pref_size = button_->GetPreferredSize(); |
| 35 available_width -= |
| 36 (button_pref_size.width() + InfoBar::kButtonInLabelSpacing); |
| 37 } |
| 38 label_->SetBounds(x, InfoBar::OffsetY(this, label_pref_size), |
| 39 std::min(label_pref_size.width(), available_width), |
| 40 label_pref_size.height()); |
| 41 |
| 42 if (button_) { |
| 43 button_->SetBounds(label_->bounds().right() + |
| 44 InfoBar::kButtonInLabelSpacing, |
| 45 InfoBar::OffsetY(this, button_pref_size), |
| 46 button_pref_size.width(), button_pref_size.height()); |
| 47 } |
| 48 } |
| 49 |
| 50 void TranslateMessageInfoBar::ButtonPressed(views::Button* sender, |
| 51 const views::Event& event) { |
| 52 if (sender == button_) { |
| 53 GetDelegate()->MessageInfoBarButtonPressed(); |
| 54 return; |
| 55 } |
| 56 TranslateInfoBarBase::ButtonPressed(sender, event); |
| 57 } |
OLD | NEW |