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

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

Issue 84363002: Minor c/b/ui/views/infobars changes: (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
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 InfoBarService* owner,
18 TranslateInfoBarDelegate* delegate) 20 TranslateInfoBarDelegate* delegate)
19 : TranslateInfoBarBase(owner, delegate), 21 : TranslateInfoBarBase(owner, delegate),
20 label_1_(NULL), 22 label_1_(NULL),
21 label_2_(NULL), 23 label_2_(NULL),
22 language_menu_button_(NULL), 24 language_menu_button_(NULL),
23 accept_button_(NULL), 25 accept_button_(NULL),
24 deny_button_(NULL), 26 deny_button_(NULL),
25 never_translate_button_(NULL), 27 never_translate_button_(NULL),
26 always_translate_button_(NULL), 28 always_translate_button_(NULL),
27 options_menu_button_(NULL), 29 options_menu_button_(NULL) {
28 options_menu_model_(delegate) {
29 } 30 }
30 31
31 BeforeTranslateInfoBar::~BeforeTranslateInfoBar() { 32 BeforeTranslateInfoBar::~BeforeTranslateInfoBar() {
32 } 33 }
33 34
34 void BeforeTranslateInfoBar::Layout() { 35 void BeforeTranslateInfoBar::Layout() {
35 TranslateInfoBarBase::Layout(); 36 TranslateInfoBarBase::Layout();
36 37
37 int available_width = std::max(0, EndX() - StartX() - ContentMinimumWidth()); 38 int available_width = std::max(0, EndX() - StartX() - ContentMinimumWidth());
38 gfx::Size label_1_size = label_1_->GetPreferredSize(); 39 gfx::Size label_1_size = label_1_->GetPreferredSize();
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 AddChildView(never_translate_button_); 127 AddChildView(never_translate_button_);
127 } else if (delegate->ShouldShowAlwaysTranslateShortcut()) { 128 } else if (delegate->ShouldShowAlwaysTranslateShortcut()) {
128 always_translate_button_ = CreateLabelButton(this, 129 always_translate_button_ = CreateLabelButton(this,
129 l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_ALWAYS_TRANSLATE, 130 l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_ALWAYS_TRANSLATE,
130 language), false); 131 language), false);
131 AddChildView(always_translate_button_); 132 AddChildView(always_translate_button_);
132 } 133 }
133 134
134 options_menu_button_ = CreateMenuButton( 135 options_menu_button_ = CreateMenuButton(
135 l10n_util::GetStringUTF16(IDS_TRANSLATE_INFOBAR_OPTIONS), this); 136 l10n_util::GetStringUTF16(IDS_TRANSLATE_INFOBAR_OPTIONS), this);
137 options_menu_model_.reset(new OptionsMenuModel(delegate));
136 AddChildView(options_menu_button_); 138 AddChildView(options_menu_button_);
137 139
138 // This must happen after adding all other children so InfoBarView can ensure 140 // This must happen after adding all other children so InfoBarView can ensure
139 // the close button is the last child. 141 // the close button is the last child.
140 TranslateInfoBarBase::ViewHierarchyChanged(details); 142 TranslateInfoBarBase::ViewHierarchyChanged(details);
141 143
142 // This must happen after adding all children because it triggers layout, 144 // This must happen after adding all children because it triggers layout,
143 // which assumes that particular children (e.g. the close button) have already 145 // which assumes that particular children (e.g. the close button) have already
144 // been added. 146 // been added.
145 UpdateLanguageButtonText(language_menu_button_, 147 UpdateLanguageButtonText(language_menu_button_,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 185
184 void BeforeTranslateInfoBar::OnMenuButtonClicked(views::View* source, 186 void BeforeTranslateInfoBar::OnMenuButtonClicked(views::View* source,
185 const gfx::Point& point) { 187 const gfx::Point& point) {
186 if (!owner()) 188 if (!owner())
187 return; // We're closing; don't call anything, it might access the owner. 189 return; // We're closing; don't call anything, it might access the owner.
188 if (source == language_menu_button_) { 190 if (source == language_menu_button_) {
189 RunMenuAt(language_menu_model_.get(), language_menu_button_, 191 RunMenuAt(language_menu_model_.get(), language_menu_button_,
190 views::MenuItemView::TOPLEFT); 192 views::MenuItemView::TOPLEFT);
191 } else { 193 } else {
192 DCHECK_EQ(options_menu_button_, source); 194 DCHECK_EQ(options_menu_button_, source);
193 RunMenuAt(&options_menu_model_, options_menu_button_, 195 RunMenuAt(options_menu_model_.get(), options_menu_button_,
194 views::MenuItemView::TOPRIGHT); 196 views::MenuItemView::TOPRIGHT);
195 } 197 }
196 } 198 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698