Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: chrome/browser/views/infobars/before_translate_infobar.cc

Issue 2602003: Refactored the translate infobars. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Synced Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/before_translate_infobar.h"
6
7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h"
9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/translate/options_menu_model.h"
11 #include "chrome/browser/translate/translate_infobar_delegate2.h"
12 #include "chrome/browser/views/infobars/infobar_text_button.h"
13 #include "grit/generated_resources.h"
14 #include "views/controls/button/menu_button.h"
15 #include "views/controls/image_view.h"
16 #include "views/controls/menu/menu_2.h"
17
18 BeforeTranslateInfoBar::BeforeTranslateInfoBar(
19 TranslateInfoBarDelegate2* delegate)
20 : TranslateInfoBarBase(delegate),
21 languages_menu_model_(delegate, LanguagesMenuModel2::ORIGINAL),
22 options_menu_model_(delegate) {
23 size_t offset = 0;
24 string16 text =
25 l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_BEFORE_MESSAGE,
26 string16(), &offset);
27
28 label_1_ = CreateLabel(text.substr(0, offset));
29 AddChildView(label_1_);
30
31 label_2_ = CreateLabel(text.substr(offset));
32 AddChildView(label_2_);
33
34 accept_button_ =
35 InfoBarTextButton::CreateWithMessageID(this,
36 IDS_TRANSLATE_INFOBAR_ACCEPT);
37 AddChildView(accept_button_);
38
39 deny_button_ =
40 InfoBarTextButton::CreateWithMessageID(this,
41 IDS_TRANSLATE_INFOBAR_DENY);
42 AddChildView(deny_button_);
43
44 language_menu_button_ = CreateMenuButton(string16(), true, this);
45 AddChildView(language_menu_button_);
46
47 options_menu_button_ =
48 CreateMenuButton(l10n_util::GetStringUTF16(IDS_TRANSLATE_INFOBAR_OPTIONS),
49 false, this);
50 AddChildView(options_menu_button_);
51
52 UpdateOriginalButtonText();
53 }
54
55 BeforeTranslateInfoBar::~BeforeTranslateInfoBar() {
56 }
57
58 // Overridden from views::View:
59 void BeforeTranslateInfoBar::Layout() {
60 // Layout the icon and close button.
61 TranslateInfoBarBase::Layout();
62
63 // Layout the options menu button on right of bar.
64 int available_width = InfoBar::GetAvailableWidth();
65 gfx::Size pref_size = options_menu_button_->GetPreferredSize();
66 options_menu_button_->SetBounds(available_width - pref_size.width(),
67 OffsetY(this, pref_size), pref_size.width(), pref_size.height());
68
69 pref_size = label_1_->GetPreferredSize();
70 label_1_->SetBounds(icon_->bounds().right() + InfoBar::kIconLabelSpacing,
71 InfoBar::OffsetY(this, pref_size), pref_size.width(), pref_size.height());
72
73 pref_size = language_menu_button_->GetPreferredSize();
74 language_menu_button_->SetBounds(label_1_->bounds().right() +
75 InfoBar::kButtonInLabelSpacing, OffsetY(this, pref_size),
76 pref_size.width(), pref_size.height());
77
78 pref_size = label_2_->GetPreferredSize();
79 label_2_->SetBounds(language_menu_button_->bounds().right() +
80 InfoBar::kButtonInLabelSpacing , InfoBar::OffsetY(this, pref_size),
81 pref_size.width(), pref_size.height());
82
83 pref_size = accept_button_->GetPreferredSize();
84 accept_button_->SetBounds(
85 label_2_->bounds().right() + InfoBar::kEndOfLabelSpacing,
86 OffsetY(this, pref_size), pref_size.width(), pref_size.height());
87
88 pref_size = deny_button_->GetPreferredSize();
89 deny_button_->SetBounds(
90 accept_button_->bounds().right() + InfoBar::kButtonButtonSpacing,
91 OffsetY(this, pref_size), pref_size.width(), pref_size.height());
92 }
93
94 void BeforeTranslateInfoBar::ButtonPressed(views::Button* sender,
95 const views::Event& event) {
96 if (sender == accept_button_) {
97 GetDelegate()->Translate();
98 } else if (sender == deny_button_) {
99 Close();
100 } else {
101 TranslateInfoBarBase::ButtonPressed(sender, event);
102 }
103 }
104
105 void BeforeTranslateInfoBar::OriginalLanguageChanged() {
106 UpdateOriginalButtonText();
107 }
108
109 void BeforeTranslateInfoBar::TargetLanguageChanged() {
110 NOTREACHED();
111 }
112
113 void BeforeTranslateInfoBar::RunMenu(views::View* source,
114 const gfx::Point& pt) {
115 if (source == language_menu_button_) {
116 if (!languages_menu_.get())
117 languages_menu_.reset(new views::Menu2(&languages_menu_model_));
118 languages_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT);
119 } else if (source == options_menu_button_) {
120 if (!options_menu_.get())
121 options_menu_.reset(new views::Menu2(&options_menu_model_));
122 options_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT);
123 } else {
124 NOTREACHED();
125 }
126 }
127
128 void BeforeTranslateInfoBar::UpdateOriginalButtonText() {
129 string16 language = GetDelegate()->GetLanguageDisplayableNameAt(
130 GetDelegate()->original_language_index());
131 language_menu_button_->SetText(UTF16ToWideHack(language));
132 // The following line is necessary for the preferred size to be recomputed.
133 language_menu_button_->ClearMaxTextSize();
134 // The button may have to grow to show the new text.
135 Layout();
136 SchedulePaint();
137 }
OLDNEW
« no previous file with comments | « chrome/browser/views/infobars/before_translate_infobar.h ('k') | chrome/browser/views/infobars/infobar_button_border.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698