Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / infobars / after_translate_infobar_controller.mm
blob6c18f58cd0fe0c7ade1709f94a3ae86147294b7c
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_ =
17       ([self delegate]->original_language_index() ==
18        translate::TranslateInfoBarDelegate::kNoIndex);
19   std::vector<base::string16> strings;
20   translate::TranslateInfoBarDelegate::GetAfterTranslateStrings(
21       &strings, &swappedLanugageButtons_, autodeterminedSourceLanguage_);
22   DCHECK_EQ(autodeterminedSourceLanguage_ ? 2U : 3U, strings.size());
23   [label1_ setStringValue:base::SysUTF16ToNSString(strings[0])];
24   [label2_ setStringValue:base::SysUTF16ToNSString(strings[1])];
25   if (strings.size() == 3U)
26     [label3_ setStringValue:base::SysUTF16ToNSString(strings[2])];
29 - (void)layout {
30   [self removeOkCancelButtons];
31   [optionsPopUp_ setHidden:NO];
32   NSView* firstPopup = fromLanguagePopUp_;
33   NSView* lastPopup = toLanguagePopUp_;
34   if (swappedLanugageButtons_ || autodeterminedSourceLanguage_) {
35     firstPopup = toLanguagePopUp_;
36     lastPopup = fromLanguagePopUp_;
37   }
38   NSView* lastControl = lastPopup;
40   MoveControl(label1_, firstPopup, spaceBetweenControls_ / 2, true);
41   if (autodeterminedSourceLanguage_) {
42     MoveControl(firstPopup, label2_, 0, true);
43     lastControl = label2_;
44   } else {
45     MoveControl(firstPopup, label2_, spaceBetweenControls_ / 2, true);
46     MoveControl(label2_, lastPopup, spaceBetweenControls_ / 2, true);
47     MoveControl(lastPopup, label3_, 0, true);
48     lastControl = label3_;
49   }
51   MoveControl(lastControl, showOriginalButton_, spaceBetweenControls_ * 2,
52       true);
55 - (NSArray*)visibleControls {
56   if (autodeterminedSourceLanguage_) {
57     return [NSArray arrayWithObjects:label1_.get(), toLanguagePopUp_.get(),
58         label2_.get(), showOriginalButton_.get(), nil];
59   }
60   return [NSArray arrayWithObjects:label1_.get(), fromLanguagePopUp_.get(),
61       label2_.get(), toLanguagePopUp_.get(), label3_.get(),
62       showOriginalButton_.get(), nil];
65 - (bool)verifyLayout {
66   if ([optionsPopUp_ isHidden])
67     return false;
68   return [super verifyLayout];
71 @end