OLD | NEW |
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/translate_infobar_delegate.h" | 10 #include "chrome/browser/translate/translate_infobar_delegate.h" |
11 #import "chrome/browser/ui/cocoa/hover_close_button.h" | 11 #import "chrome/browser/ui/cocoa/hover_close_button.h" |
12 #include "chrome/browser/ui/cocoa/infobars/after_translate_infobar_controller.h" | 12 #include "chrome/browser/ui/cocoa/infobars/after_translate_infobar_controller.h" |
13 #import "chrome/browser/ui/cocoa/infobars/before_translate_infobar_controller.h" | 13 #import "chrome/browser/ui/cocoa/infobars/before_translate_infobar_controller.h" |
14 #include "chrome/browser/ui/cocoa/infobars/infobar_cocoa.h" | 14 #include "chrome/browser/ui/cocoa/infobars/infobar_cocoa.h" |
15 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" | 15 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" |
16 #import "chrome/browser/ui/cocoa/infobars/infobar_controller.h" | 16 #import "chrome/browser/ui/cocoa/infobars/infobar_controller.h" |
17 #import "chrome/browser/ui/cocoa/infobars/infobar_gradient_view.h" | 17 #import "chrome/browser/ui/cocoa/infobars/infobar_gradient_view.h" |
18 #import "chrome/browser/ui/cocoa/infobars/infobar_utilities.h" | 18 #import "chrome/browser/ui/cocoa/infobars/infobar_utilities.h" |
19 #include "chrome/browser/ui/cocoa/infobars/translate_message_infobar_controller.
h" | 19 #include "chrome/browser/ui/cocoa/infobars/translate_message_infobar_controller.
h" |
20 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
21 #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" | 21 #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
22 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
23 | 23 |
24 using InfoBarUtilities::MoveControl; | 24 using InfoBarUtilities::MoveControl; |
25 using InfoBarUtilities::VerticallyCenterView; | 25 using InfoBarUtilities::VerticallyCenterView; |
26 using InfoBarUtilities::VerifyControlOrderAndSpacing; | 26 using InfoBarUtilities::VerifyControlOrderAndSpacing; |
27 using InfoBarUtilities::CreateLabel; | 27 using InfoBarUtilities::CreateLabel; |
28 using InfoBarUtilities::AddMenuItem; | 28 using InfoBarUtilities::AddMenuItem; |
29 | 29 |
30 // TranslateInfoBarDelegate views specific method: | 30 // static |
31 InfoBar* TranslateInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { | 31 scoped_ptr<InfoBar> TranslateInfoBarDelegate::CreateInfoBar( |
32 scoped_ptr<InfoBarCocoa> infobar(new InfoBarCocoa(owner, this)); | 32 scoped_ptr<TranslateInfoBarDelegate> delegate) { |
| 33 scoped_ptr<InfoBarCocoa> infobar( |
| 34 new InfoBarCocoa(delegate.PassAs<InfoBarDelegate>())); |
33 base::scoped_nsobject<TranslateInfoBarControllerBase> infobar_controller; | 35 base::scoped_nsobject<TranslateInfoBarControllerBase> infobar_controller; |
34 switch (infobar_type_) { | 36 switch (infobar->delegate()->AsTranslateInfoBarDelegate()->infobar_type()) { |
35 case BEFORE_TRANSLATE: | 37 case BEFORE_TRANSLATE: |
36 infobar_controller.reset([[BeforeTranslateInfobarController alloc] | 38 infobar_controller.reset([[BeforeTranslateInfobarController alloc] |
37 initWithInfoBar:infobar.get()]); | 39 initWithInfoBar:infobar.get()]); |
38 break; | 40 break; |
39 case AFTER_TRANSLATE: | 41 case AFTER_TRANSLATE: |
40 infobar_controller.reset([[AfterTranslateInfobarController alloc] | 42 infobar_controller.reset([[AfterTranslateInfobarController alloc] |
41 initWithInfoBar:infobar.get()]); | 43 initWithInfoBar:infobar.get()]); |
42 break; | 44 break; |
43 case TRANSLATING: | 45 case TRANSLATING: |
44 case TRANSLATION_ERROR: | 46 case TRANSLATION_ERROR: |
45 infobar_controller.reset([[TranslateMessageInfobarController alloc] | 47 infobar_controller.reset([[TranslateMessageInfobarController alloc] |
46 initWithInfoBar:infobar.get()]); | 48 initWithInfoBar:infobar.get()]); |
47 break; | 49 break; |
48 default: | 50 default: |
49 NOTREACHED(); | 51 NOTREACHED(); |
50 } | 52 } |
51 infobar->set_controller(infobar_controller); | 53 infobar->set_controller(infobar_controller); |
52 return infobar.release(); | 54 return infobar.PassAs<InfoBar>(); |
53 } | 55 } |
54 | 56 |
55 @implementation TranslateInfoBarControllerBase (FrameChangeObserver) | 57 @implementation TranslateInfoBarControllerBase (FrameChangeObserver) |
56 | 58 |
57 // Triggered when the frame changes. This will figure out what size and | 59 // Triggered when the frame changes. This will figure out what size and |
58 // visibility the options popup should be. | 60 // visibility the options popup should be. |
59 - (void)didChangeFrame:(NSNotification*)notification { | 61 - (void)didChangeFrame:(NSNotification*)notification { |
60 [self adjustOptionsButtonSizeAndVisibilityForView: | 62 [self adjustOptionsButtonSizeAndVisibilityForView: |
61 [[self visibleControls] lastObject]]; | 63 [[self visibleControls] lastObject]]; |
62 } | 64 } |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 [[control description] UTF8String] <<[title UTF8String]; | 544 [[control description] UTF8String] <<[title UTF8String]; |
543 return false; | 545 return false; |
544 } | 546 } |
545 previousControl = control; | 547 previousControl = control; |
546 } | 548 } |
547 | 549 |
548 return true; | 550 return true; |
549 } | 551 } |
550 | 552 |
551 @end // TranslateInfoBarControllerBase (TestingAPI) | 553 @end // TranslateInfoBarControllerBase (TestingAPI) |
OLD | NEW |