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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/cocoa/infobars/after_translate_infobar_controller.h"
7 #include "base/strings/sys_string_conversions.h"
8 #import "chrome/browser/ui/cocoa/infobars/infobar_utilities.h"
10 using InfoBarUtilities::MoveControl;
11 using InfoBarUtilities::VerifyControlOrderAndSpacing;
13 @implementation AfterTranslateInfobarController
15 - (void)loadLabelText {
16 autodeterminedSourceLanguage_ = ([self delegate]->original_language_index() ==
17 TranslateInfoBarDelegate::kNoIndex);
18 std::vector<base::string16> strings;
19 TranslateInfoBarDelegate::GetAfterTranslateStrings(
20 &strings, &swappedLanugageButtons_, autodeterminedSourceLanguage_);
21 DCHECK_EQ(autodeterminedSourceLanguage_ ? 2U : 3U, strings.size());
22 [label1_ setStringValue:base::SysUTF16ToNSString(strings[0])];
23 [label2_ setStringValue:base::SysUTF16ToNSString(strings[1])];
24 if (strings.size() == 3U)
25 [label3_ setStringValue:base::SysUTF16ToNSString(strings[2])];
29 [self removeOkCancelButtons];
30 [optionsPopUp_ setHidden:NO];
31 NSView* firstPopup = fromLanguagePopUp_;
32 NSView* lastPopup = toLanguagePopUp_;
33 if (swappedLanugageButtons_ || autodeterminedSourceLanguage_) {
34 firstPopup = toLanguagePopUp_;
35 lastPopup = fromLanguagePopUp_;
37 NSView* lastControl = lastPopup;
39 MoveControl(label1_, firstPopup, spaceBetweenControls_ / 2, true);
40 if (autodeterminedSourceLanguage_) {
41 MoveControl(firstPopup, label2_, 0, true);
42 lastControl = label2_;
44 MoveControl(firstPopup, label2_, spaceBetweenControls_ / 2, true);
45 MoveControl(label2_, lastPopup, spaceBetweenControls_ / 2, true);
46 MoveControl(lastPopup, label3_, 0, true);
47 lastControl = label3_;
50 MoveControl(lastControl, showOriginalButton_, spaceBetweenControls_ * 2,
54 - (NSArray*)visibleControls {
55 if (autodeterminedSourceLanguage_) {
56 return [NSArray arrayWithObjects:label1_.get(), toLanguagePopUp_.get(),
57 label2_.get(), showOriginalButton_.get(), nil];
59 return [NSArray arrayWithObjects:label1_.get(), fromLanguagePopUp_.get(),
60 label2_.get(), toLanguagePopUp_.get(), label3_.get(),
61 showOriginalButton_.get(), nil];
64 - (bool)verifyLayout {
65 if ([optionsPopUp_ isHidden])
67 return [super verifyLayout];