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

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

Issue 15521005: Translate (Mac): add after infobar UI for server side language detection (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: style Created 7 years, 7 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 | 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/cocoa/infobars/after_translate_infobar_controller.h" 5 #include "chrome/browser/ui/cocoa/infobars/after_translate_infobar_controller.h"
6 6
7 #include "base/strings/sys_string_conversions.h" 7 #include "base/strings/sys_string_conversions.h"
8 #import "chrome/browser/ui/cocoa/infobars/infobar_utilities.h" 8 #import "chrome/browser/ui/cocoa/infobars/infobar_utilities.h"
9 9
10 using InfoBarUtilities::MoveControl; 10 using InfoBarUtilities::MoveControl;
11 using InfoBarUtilities::VerifyControlOrderAndSpacing; 11 using InfoBarUtilities::VerifyControlOrderAndSpacing;
12 12
13 @implementation AfterTranslateInfobarController 13 @implementation AfterTranslateInfobarController
14 14
15 - (void)loadLabelText { 15 - (void)loadLabelText {
16 autodeterminedSourceLanguage_ = ([self delegate]->original_language_index() ==
17 TranslateInfoBarDelegate::kNoIndex);
16 std::vector<string16> strings; 18 std::vector<string16> strings;
17 TranslateInfoBarDelegate::GetAfterTranslateStrings( 19 TranslateInfoBarDelegate::GetAfterTranslateStrings(
18 &strings, &swappedLanugageButtons_, false); 20 &strings, &swappedLanugageButtons_, autodeterminedSourceLanguage_);
19 DCHECK(strings.size() == 3U); 21 DCHECK_EQ(autodeterminedSourceLanguage_ ? 2U : 3U, strings.size());
20 NSString* string1 = base::SysUTF16ToNSString(strings[0]); 22 [label1_ setStringValue:base::SysUTF16ToNSString(strings[0])];
21 NSString* string2 = base::SysUTF16ToNSString(strings[1]); 23 [label2_ setStringValue:base::SysUTF16ToNSString(strings[1])];
22 NSString* string3 = base::SysUTF16ToNSString(strings[2]); 24 if (strings.size() == 3U)
23 25 [label3_ setStringValue:base::SysUTF16ToNSString(strings[2])];
24 [label1_ setStringValue:string1];
25 [label2_ setStringValue:string2];
26 [label3_ setStringValue:string3];
27 } 26 }
28 27
29 - (void)layout { 28 - (void)layout {
30 [self removeOkCancelButtons]; 29 [self removeOkCancelButtons];
31 [optionsPopUp_ setHidden:NO]; 30 [optionsPopUp_ setHidden:NO];
32 NSView* firstPopup = fromLanguagePopUp_; 31 NSView* firstPopup = fromLanguagePopUp_;
33 NSView* lastPopup = toLanguagePopUp_; 32 NSView* lastPopup = toLanguagePopUp_;
34 if (swappedLanugageButtons_) { 33 if (swappedLanugageButtons_ || autodeterminedSourceLanguage_) {
35 firstPopup = toLanguagePopUp_; 34 firstPopup = toLanguagePopUp_;
36 lastPopup = fromLanguagePopUp_; 35 lastPopup = fromLanguagePopUp_;
37 } 36 }
38 NSView* lastControl = lastPopup; 37 NSView* lastControl = lastPopup;
39 38
40 MoveControl(label1_, firstPopup, spaceBetweenControls_ / 2, true); 39 MoveControl(label1_, firstPopup, spaceBetweenControls_ / 2, true);
41 MoveControl(firstPopup, label2_, spaceBetweenControls_ / 2, true); 40 if (autodeterminedSourceLanguage_) {
42 MoveControl(label2_, lastPopup, spaceBetweenControls_ / 2, true); 41 MoveControl(firstPopup, label2_, 0, true);
43 MoveControl(lastPopup, label3_, 0, true); 42 lastControl = label2_;
44 lastControl = label3_; 43 } else {
44 MoveControl(firstPopup, label2_, spaceBetweenControls_ / 2, true);
45 MoveControl(label2_, lastPopup, spaceBetweenControls_ / 2, true);
46 MoveControl(lastPopup, label3_, 0, true);
47 lastControl = label3_;
48 }
45 49
46 MoveControl(lastControl, showOriginalButton_, spaceBetweenControls_ * 2, 50 MoveControl(lastControl, showOriginalButton_, spaceBetweenControls_ * 2,
47 true); 51 true);
48 } 52 }
49 53
50 - (NSArray*)visibleControls { 54 - (NSArray*)visibleControls {
55 if (autodeterminedSourceLanguage_) {
56 return [NSArray arrayWithObjects:label1_.get(), toLanguagePopUp_.get(),
57 label2_.get(), showOriginalButton_.get(), nil];
58 }
51 return [NSArray arrayWithObjects:label1_.get(), fromLanguagePopUp_.get(), 59 return [NSArray arrayWithObjects:label1_.get(), fromLanguagePopUp_.get(),
52 label2_.get(), toLanguagePopUp_.get(), label3_.get(), 60 label2_.get(), toLanguagePopUp_.get(), label3_.get(),
53 showOriginalButton_.get(), nil]; 61 showOriginalButton_.get(), nil];
54 } 62 }
55 63
56 - (bool)verifyLayout { 64 - (bool)verifyLayout {
57 if ([optionsPopUp_ isHidden]) 65 if ([optionsPopUp_ isHidden])
58 return false; 66 return false;
59 return [super verifyLayout]; 67 return [super verifyLayout];
60 } 68 }
61 69
62 @end 70 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698