OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/views/infobars/translate_message_infobar.h" | |
6 | |
7 #include "components/translate/core/browser/translate_infobar_delegate.h" | |
8 #include "ui/views/controls/button/label_button.h" | |
9 #include "ui/views/controls/label.h" | |
10 | |
11 TranslateMessageInfoBar::TranslateMessageInfoBar( | |
12 scoped_ptr<TranslateInfoBarDelegate> delegate) | |
13 : TranslateInfoBarBase(delegate.Pass()), | |
14 label_(NULL), | |
15 button_(NULL) { | |
16 } | |
17 | |
18 TranslateMessageInfoBar::~TranslateMessageInfoBar() { | |
19 } | |
20 | |
21 void TranslateMessageInfoBar::Layout() { | |
22 TranslateInfoBarBase::Layout(); | |
23 | |
24 int x = StartX(); | |
25 const int width = | |
26 std::min(label_->width(), std::max(0, EndX() - x - NonLabelWidth())); | |
27 label_->SetBounds(x, OffsetY(label_), width, label_->height()); | |
28 if (!label_->text().empty()) | |
29 x = label_->bounds().right() + kEndOfLabelSpacing; | |
30 | |
31 if (button_) | |
32 button_->SetPosition(gfx::Point(x, OffsetY(button_))); | |
33 } | |
34 | |
35 void TranslateMessageInfoBar::ViewHierarchyChanged( | |
36 const ViewHierarchyChangedDetails& details) { | |
37 if (details.is_add && (details.child == this) && (label_ == NULL)) { | |
38 TranslateInfoBarDelegate* delegate = GetDelegate(); | |
39 label_ = CreateLabel(delegate->GetMessageInfoBarText()); | |
40 AddChildView(label_); | |
41 | |
42 base::string16 button_text(delegate->GetMessageInfoBarButtonText()); | |
43 if (!button_text.empty()) { | |
44 button_ = CreateLabelButton(this, button_text); | |
45 AddChildView(button_); | |
46 } | |
47 } | |
48 | |
49 // This must happen after adding all other children so InfoBarView can ensure | |
50 // the close button is the last child. | |
51 TranslateInfoBarBase::ViewHierarchyChanged(details); | |
52 } | |
53 | |
54 void TranslateMessageInfoBar::ButtonPressed(views::Button* sender, | |
55 const ui::Event& event) { | |
56 if (!owner()) | |
57 return; // We're closing; don't call anything, it might access the owner. | |
58 if (sender == button_) | |
59 GetDelegate()->MessageInfoBarButtonPressed(); | |
60 else | |
61 TranslateInfoBarBase::ButtonPressed(sender, event); | |
62 } | |
63 | |
64 int TranslateMessageInfoBar::ContentMinimumWidth() const { | |
65 return label_->GetMinimumSize().width() + NonLabelWidth(); | |
66 } | |
67 | |
68 int TranslateMessageInfoBar::NonLabelWidth() const { | |
69 if (!button_) | |
70 return 0; | |
71 return button_->width() + (label_->text().empty() ? 0 : kEndOfLabelSpacing); | |
72 } | |
OLD | NEW |