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

Side by Side Diff: chrome/browser/ui/cocoa/infobars/translate_infobar_base.mm

Issue 378253002: Fix translate namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 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
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 #import "chrome/browser/ui/cocoa/infobars/translate_infobar_base.h" 5 #import "chrome/browser/ui/cocoa/infobars/translate_infobar_base.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/sys_string_conversions.h" 8 #include "base/strings/sys_string_conversions.h"
9 #include "chrome/app/chrome_command_ids.h" 9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/translate/chrome_translate_client.h" 10 #include "chrome/browser/translate/chrome_translate_client.h"
(...skipping 11 matching lines...) Expand all
22 #include "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutT weaker.h" 22 #include "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutT weaker.h"
23 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
24 24
25 using InfoBarUtilities::MoveControl; 25 using InfoBarUtilities::MoveControl;
26 using InfoBarUtilities::VerticallyCenterView; 26 using InfoBarUtilities::VerticallyCenterView;
27 using InfoBarUtilities::VerifyControlOrderAndSpacing; 27 using InfoBarUtilities::VerifyControlOrderAndSpacing;
28 using InfoBarUtilities::CreateLabel; 28 using InfoBarUtilities::CreateLabel;
29 using InfoBarUtilities::AddMenuItem; 29 using InfoBarUtilities::AddMenuItem;
30 30
31 scoped_ptr<infobars::InfoBar> ChromeTranslateClient::CreateInfoBar( 31 scoped_ptr<infobars::InfoBar> ChromeTranslateClient::CreateInfoBar(
32 scoped_ptr<TranslateInfoBarDelegate> delegate) const { 32 scoped_ptr<translate::TranslateInfoBarDelegate> delegate) const {
33 scoped_ptr<InfoBarCocoa> infobar( 33 scoped_ptr<InfoBarCocoa> infobar(
34 new InfoBarCocoa(delegate.PassAs<infobars::InfoBarDelegate>())); 34 new InfoBarCocoa(delegate.PassAs<infobars::InfoBarDelegate>()));
35 base::scoped_nsobject<TranslateInfoBarControllerBase> infobar_controller; 35 base::scoped_nsobject<TranslateInfoBarControllerBase> infobar_controller;
36 switch (infobar->delegate()->AsTranslateInfoBarDelegate()->translate_step()) { 36 switch (infobar->delegate()->AsTranslateInfoBarDelegate()->translate_step()) {
37 case translate::TRANSLATE_STEP_BEFORE_TRANSLATE: 37 case translate::TRANSLATE_STEP_BEFORE_TRANSLATE:
38 infobar_controller.reset([[BeforeTranslateInfobarController alloc] 38 infobar_controller.reset([[BeforeTranslateInfobarController alloc]
39 initWithInfoBar:infobar.get()]); 39 initWithInfoBar:infobar.get()]);
40 break; 40 break;
41 case translate::TRANSLATE_STEP_AFTER_TRANSLATE: 41 case translate::TRANSLATE_STEP_AFTER_TRANSLATE:
42 infobar_controller.reset([[AfterTranslateInfobarController alloc] 42 infobar_controller.reset([[AfterTranslateInfobarController alloc]
(...skipping 26 matching lines...) Expand all
69 @interface TranslateInfoBarControllerBase (Private) 69 @interface TranslateInfoBarControllerBase (Private)
70 70
71 // Removes all controls so that layout can add in only the controls 71 // Removes all controls so that layout can add in only the controls
72 // required. 72 // required.
73 - (void)clearAllControls; 73 - (void)clearAllControls;
74 74
75 // Create all the various controls we need for the toolbar. 75 // Create all the various controls we need for the toolbar.
76 - (void)constructViews; 76 - (void)constructViews;
77 77
78 // Reloads text for all labels for the current state. 78 // Reloads text for all labels for the current state.
79 - (void)loadLabelText:(TranslateErrors::Type)error; 79 - (void)loadLabelText:(translate::TranslateErrors::Type)error;
80 80
81 // Main function to update the toolbar graphic state and data model after 81 // Main function to update the toolbar graphic state and data model after
82 // the state has changed. 82 // the state has changed.
83 // Controls are moved around as needed and visibility changed to match the 83 // Controls are moved around as needed and visibility changed to match the
84 // current state. 84 // current state.
85 - (void)updateState; 85 - (void)updateState;
86 86
87 // Called when the source or target language selection changes in a menu. 87 // Called when the source or target language selection changes in a menu.
88 // |newLanguageIdx| is the index of the newly selected item in the appropriate 88 // |newLanguageIdx| is the index of the newly selected item in the appropriate
89 // menu. 89 // menu.
90 - (void)sourceLanguageModified:(NSInteger)newLanguageIdx; 90 - (void)sourceLanguageModified:(NSInteger)newLanguageIdx;
91 - (void)targetLanguageModified:(NSInteger)newLanguageIdx; 91 - (void)targetLanguageModified:(NSInteger)newLanguageIdx;
92 92
93 // Completely rebuild "from" and "to" language menus from the data model. 93 // Completely rebuild "from" and "to" language menus from the data model.
94 - (void)populateLanguageMenus; 94 - (void)populateLanguageMenus;
95 95
96 @end 96 @end
97 97
98 #pragma mark TranslateInfoBarController class 98 #pragma mark TranslateInfoBarController class
99 99
100 @implementation TranslateInfoBarControllerBase 100 @implementation TranslateInfoBarControllerBase
101 101
102 - (TranslateInfoBarDelegate*)delegate { 102 - (translate::TranslateInfoBarDelegate*)delegate {
103 return reinterpret_cast<TranslateInfoBarDelegate*>([super delegate]); 103 return reinterpret_cast<translate::TranslateInfoBarDelegate*>(
104 [super delegate]);
104 } 105 }
105 106
106 - (void)constructViews { 107 - (void)constructViews {
107 // Using a zero or very large frame causes GTMUILocalizerAndLayoutTweaker 108 // Using a zero or very large frame causes GTMUILocalizerAndLayoutTweaker
108 // to not resize the view properly so we take the bounds of the first label 109 // to not resize the view properly so we take the bounds of the first label
109 // which is contained in the nib. 110 // which is contained in the nib.
110 NSRect bogusFrame = [label_ frame]; 111 NSRect bogusFrame = [label_ frame];
111 label1_.reset(CreateLabel(bogusFrame)); 112 label1_.reset(CreateLabel(bogusFrame));
112 label2_.reset(CreateLabel(bogusFrame)); 113 label2_.reset(CreateLabel(bogusFrame));
113 label3_.reset(CreateLabel(bogusFrame)); 114 label3_.reset(CreateLabel(bogusFrame));
114 115
115 optionsPopUp_.reset([[NSPopUpButton alloc] initWithFrame:bogusFrame 116 optionsPopUp_.reset([[NSPopUpButton alloc] initWithFrame:bogusFrame
116 pullsDown:YES]); 117 pullsDown:YES]);
117 fromLanguagePopUp_.reset([[NSPopUpButton alloc] initWithFrame:bogusFrame 118 fromLanguagePopUp_.reset([[NSPopUpButton alloc] initWithFrame:bogusFrame
118 pullsDown:NO]); 119 pullsDown:NO]);
119 toLanguagePopUp_.reset([[NSPopUpButton alloc] initWithFrame:bogusFrame 120 toLanguagePopUp_.reset([[NSPopUpButton alloc] initWithFrame:bogusFrame
120 pullsDown:NO]); 121 pullsDown:NO]);
121 showOriginalButton_.reset([[NSButton alloc] init]); 122 showOriginalButton_.reset([[NSButton alloc] init]);
122 translateMessageButton_.reset([[NSButton alloc] init]); 123 translateMessageButton_.reset([[NSButton alloc] init]);
123 } 124 }
124 125
125 - (void)sourceLanguageModified:(NSInteger)newLanguageIdx { 126 - (void)sourceLanguageModified:(NSInteger)newLanguageIdx {
126 size_t newLanguageIdxSizeT = static_cast<size_t>(newLanguageIdx); 127 size_t newLanguageIdxSizeT = static_cast<size_t>(newLanguageIdx);
127 DCHECK_NE(TranslateInfoBarDelegate::kNoIndex, newLanguageIdxSizeT); 128 DCHECK_NE(translate::TranslateInfoBarDelegate::kNoIndex, newLanguageIdxSizeT);
128 if (newLanguageIdxSizeT == [self delegate]->original_language_index()) 129 if (newLanguageIdxSizeT == [self delegate]->original_language_index())
129 return; 130 return;
130 [self delegate]->UpdateOriginalLanguageIndex(newLanguageIdxSizeT); 131 [self delegate]->UpdateOriginalLanguageIndex(newLanguageIdxSizeT);
131 if ([self delegate]->translate_step() == 132 if ([self delegate]->translate_step() ==
132 translate::TRANSLATE_STEP_AFTER_TRANSLATE) 133 translate::TRANSLATE_STEP_AFTER_TRANSLATE)
133 [self delegate]->Translate(); 134 [self delegate]->Translate();
134 int commandId = IDC_TRANSLATE_ORIGINAL_LANGUAGE_BASE + newLanguageIdx; 135 int commandId = IDC_TRANSLATE_ORIGINAL_LANGUAGE_BASE + newLanguageIdx;
135 int newMenuIdx = [fromLanguagePopUp_ indexOfItemWithTag:commandId]; 136 int newMenuIdx = [fromLanguagePopUp_ indexOfItemWithTag:commandId];
136 [fromLanguagePopUp_ selectItemAtIndex:newMenuIdx]; 137 [fromLanguagePopUp_ selectItemAtIndex:newMenuIdx];
137 } 138 }
138 139
139 - (void)targetLanguageModified:(NSInteger)newLanguageIdx { 140 - (void)targetLanguageModified:(NSInteger)newLanguageIdx {
140 size_t newLanguageIdxSizeT = static_cast<size_t>(newLanguageIdx); 141 size_t newLanguageIdxSizeT = static_cast<size_t>(newLanguageIdx);
141 DCHECK_NE(TranslateInfoBarDelegate::kNoIndex, newLanguageIdxSizeT); 142 DCHECK_NE(translate::TranslateInfoBarDelegate::kNoIndex, newLanguageIdxSizeT);
142 if (newLanguageIdxSizeT == [self delegate]->target_language_index()) 143 if (newLanguageIdxSizeT == [self delegate]->target_language_index())
143 return; 144 return;
144 [self delegate]->UpdateTargetLanguageIndex(newLanguageIdxSizeT); 145 [self delegate]->UpdateTargetLanguageIndex(newLanguageIdxSizeT);
145 if ([self delegate]->translate_step() == 146 if ([self delegate]->translate_step() ==
146 translate::TRANSLATE_STEP_AFTER_TRANSLATE) 147 translate::TRANSLATE_STEP_AFTER_TRANSLATE)
147 [self delegate]->Translate(); 148 [self delegate]->Translate();
148 int commandId = IDC_TRANSLATE_TARGET_LANGUAGE_BASE + newLanguageIdx; 149 int commandId = IDC_TRANSLATE_TARGET_LANGUAGE_BASE + newLanguageIdx;
149 int newMenuIdx = [toLanguagePopUp_ indexOfItemWithTag:commandId]; 150 int newMenuIdx = [toLanguagePopUp_ indexOfItemWithTag:commandId];
150 [toLanguagePopUp_ selectItemAtIndex:newMenuIdx]; 151 [toLanguagePopUp_ selectItemAtIndex:newMenuIdx];
151 } 152 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 - (NSArray*)visibleControls { 215 - (NSArray*)visibleControls {
215 return [NSArray array]; 216 return [NSArray array];
216 } 217 }
217 218
218 - (void)rebuildOptionsMenu:(BOOL)hideTitle { 219 - (void)rebuildOptionsMenu:(BOOL)hideTitle {
219 if (![self shouldShowOptionsPopUp]) 220 if (![self shouldShowOptionsPopUp])
220 return; 221 return;
221 222
222 // The options model doesn't know how to handle state transitions, so rebuild 223 // The options model doesn't know how to handle state transitions, so rebuild
223 // it each time through here. 224 // it each time through here.
224 optionsMenuModel_.reset(new OptionsMenuModel([self delegate])); 225 optionsMenuModel_.reset(new translate::OptionsMenuModel([self delegate]));
225 226
226 [optionsPopUp_ removeAllItems]; 227 [optionsPopUp_ removeAllItems];
227 // Set title. 228 // Set title.
228 NSString* optionsLabel = hideTitle ? @"" : 229 NSString* optionsLabel = hideTitle ? @"" :
229 l10n_util::GetNSString(IDS_TRANSLATE_INFOBAR_OPTIONS); 230 l10n_util::GetNSString(IDS_TRANSLATE_INFOBAR_OPTIONS);
230 [optionsPopUp_ addItemWithTitle:optionsLabel]; 231 [optionsPopUp_ addItemWithTitle:optionsLabel];
231 232
232 // Populate options menu. 233 // Populate options menu.
233 NSMenu* optionsMenu = [optionsPopUp_ menu]; 234 NSMenu* optionsMenu = [optionsPopUp_ menu];
234 [optionsMenu setAutoenablesItems:NO]; 235 [optionsMenu setAutoenablesItems:NO];
(...skipping 29 matching lines...) Expand all
264 i == [self delegate]->original_language_index()); 265 i == [self delegate]->original_language_index());
265 AddMenuItem(targetLanguageMenu, 266 AddMenuItem(targetLanguageMenu,
266 self, 267 self,
267 @selector(languageMenuChanged:), 268 @selector(languageMenuChanged:),
268 title, 269 title,
269 IDC_TRANSLATE_TARGET_LANGUAGE_BASE + i, 270 IDC_TRANSLATE_TARGET_LANGUAGE_BASE + i,
270 i != [self delegate]->original_language_index(), 271 i != [self delegate]->original_language_index(),
271 i == [self delegate]->target_language_index()); 272 i == [self delegate]->target_language_index());
272 } 273 }
273 if ([self delegate]->original_language_index() != 274 if ([self delegate]->original_language_index() !=
274 TranslateInfoBarDelegate::kNoIndex) { 275 translate::TranslateInfoBarDelegate::kNoIndex) {
275 [fromLanguagePopUp_ 276 [fromLanguagePopUp_
276 selectItemAtIndex:([self delegate]->original_language_index())]; 277 selectItemAtIndex:([self delegate]->original_language_index())];
277 } 278 }
278 [toLanguagePopUp_ 279 [toLanguagePopUp_
279 selectItemAtIndex:([self delegate]->target_language_index())]; 280 selectItemAtIndex:([self delegate]->target_language_index())];
280 } 281 }
281 282
282 - (void)addAdditionalControls { 283 - (void)addAdditionalControls {
283 using l10n_util::GetNSString; 284 using l10n_util::GetNSString;
284 using l10n_util::GetNSStringWithFixup; 285 using l10n_util::GetNSStringWithFixup;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 if (!VerifyControlOrderAndSpacing(lastView, optionsPopUp_)) { 394 if (!VerifyControlOrderAndSpacing(lastView, optionsPopUp_)) {
394 [optionsPopUp_ setHidden:YES]; 395 [optionsPopUp_ setHidden:YES];
395 } 396 }
396 } 397 }
397 } 398 }
398 399
399 // Called when "Translate" button is clicked. 400 // Called when "Translate" button is clicked.
400 - (void)ok:(id)sender { 401 - (void)ok:(id)sender {
401 if (![self isOwned]) 402 if (![self isOwned])
402 return; 403 return;
403 TranslateInfoBarDelegate* delegate = [self delegate]; 404 translate::TranslateInfoBarDelegate* delegate = [self delegate];
404 translate::TranslateStep state = delegate->translate_step(); 405 translate::TranslateStep state = delegate->translate_step();
405 DCHECK(state == translate::TRANSLATE_STEP_BEFORE_TRANSLATE || 406 DCHECK(state == translate::TRANSLATE_STEP_BEFORE_TRANSLATE ||
406 state == translate::TRANSLATE_STEP_TRANSLATE_ERROR); 407 state == translate::TRANSLATE_STEP_TRANSLATE_ERROR);
407 delegate->Translate(); 408 delegate->Translate();
408 } 409 }
409 410
410 // Called when someone clicks on the "Nope" button. 411 // Called when someone clicks on the "Nope" button.
411 - (void)cancel:(id)sender { 412 - (void)cancel:(id)sender {
412 if (![self isOwned]) 413 if (![self isOwned])
413 return; 414 return;
414 TranslateInfoBarDelegate* delegate = [self delegate]; 415 translate::TranslateInfoBarDelegate* delegate = [self delegate];
415 DCHECK_EQ(translate::TRANSLATE_STEP_BEFORE_TRANSLATE, 416 DCHECK_EQ(translate::TRANSLATE_STEP_BEFORE_TRANSLATE,
416 delegate->translate_step()); 417 delegate->translate_step());
417 delegate->TranslationDeclined(); 418 delegate->TranslationDeclined();
418 [super removeSelf]; 419 [super removeSelf];
419 } 420 }
420 421
421 - (void)messageButtonPressed:(id)sender { 422 - (void)messageButtonPressed:(id)sender {
422 if (![self isOwned]) 423 if (![self isOwned])
423 return; 424 return;
424 [self delegate]->MessageInfoBarButtonPressed(); 425 [self delegate]->MessageInfoBarButtonPressed();
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 [[control description] UTF8String] <<[title UTF8String]; 547 [[control description] UTF8String] <<[title UTF8String];
547 return false; 548 return false;
548 } 549 }
549 previousControl = control; 550 previousControl = control;
550 } 551 }
551 552
552 return true; 553 return true;
553 } 554 }
554 555
555 @end // TranslateInfoBarControllerBase (TestingAPI) 556 @end // TranslateInfoBarControllerBase (TestingAPI)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698