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

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

Issue 23338005: Mac InfoBar: Use cross platform infobar classes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 #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.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 // TranslateInfoBarDelegate views specific method:
31 InfoBar* TranslateInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { 31 InfoBar* TranslateInfoBarDelegate::CreateInfoBar(InfoBarService* owner) {
32 TranslateInfoBarControllerBase* infobar_controller = NULL; 32 scoped_ptr<InfoBarCocoa> infobar(new InfoBarCocoa(owner, this));
33 base::scoped_nsobject<TranslateInfoBarControllerBase> infobar_controller;
33 switch (infobar_type_) { 34 switch (infobar_type_) {
34 case BEFORE_TRANSLATE: 35 case BEFORE_TRANSLATE:
35 infobar_controller = 36 infobar_controller.reset([[BeforeTranslateInfobarController alloc]
36 [[BeforeTranslateInfobarController alloc] initWithDelegate:this 37 initWithInfoBar:infobar.get()]);
37 owner:owner];
38 break; 38 break;
39 case AFTER_TRANSLATE: 39 case AFTER_TRANSLATE:
40 infobar_controller = 40 infobar_controller.reset([[AfterTranslateInfobarController alloc]
41 [[AfterTranslateInfobarController alloc] initWithDelegate:this 41 initWithInfoBar:infobar.get()]);
42 owner:owner];
43 break; 42 break;
44 case TRANSLATING: 43 case TRANSLATING:
45 case TRANSLATION_ERROR: 44 case TRANSLATION_ERROR:
46 infobar_controller = 45 infobar_controller.reset([[TranslateMessageInfobarController alloc]
47 [[TranslateMessageInfobarController alloc] initWithDelegate:this 46 initWithInfoBar:infobar.get()]);
48 owner:owner];
49 break; 47 break;
50 default: 48 default:
51 NOTREACHED(); 49 NOTREACHED();
52 } 50 }
53 return new InfoBar(infobar_controller, this); 51 infobar->set_controller(infobar_controller);
52 return infobar.release();
54 } 53 }
55 54
56 @implementation TranslateInfoBarControllerBase (FrameChangeObserver) 55 @implementation TranslateInfoBarControllerBase (FrameChangeObserver)
57 56
58 // Triggered when the frame changes. This will figure out what size and 57 // Triggered when the frame changes. This will figure out what size and
59 // visibility the options popup should be. 58 // visibility the options popup should be.
60 - (void)didChangeFrame:(NSNotification*)notification { 59 - (void)didChangeFrame:(NSNotification*)notification {
61 [self adjustOptionsButtonSizeAndVisibilityForView: 60 [self adjustOptionsButtonSizeAndVisibilityForView:
62 [[self visibleControls] lastObject]]; 61 [[self visibleControls] lastObject]];
63 } 62 }
(...skipping 28 matching lines...) Expand all
92 // Completely rebuild "from" and "to" language menus from the data model. 91 // Completely rebuild "from" and "to" language menus from the data model.
93 - (void)populateLanguageMenus; 92 - (void)populateLanguageMenus;
94 93
95 @end 94 @end
96 95
97 #pragma mark TranslateInfoBarController class 96 #pragma mark TranslateInfoBarController class
98 97
99 @implementation TranslateInfoBarControllerBase 98 @implementation TranslateInfoBarControllerBase
100 99
101 - (TranslateInfoBarDelegate*)delegate { 100 - (TranslateInfoBarDelegate*)delegate {
102 return reinterpret_cast<TranslateInfoBarDelegate*>(delegate_); 101 return reinterpret_cast<TranslateInfoBarDelegate*>([super delegate]);
103 } 102 }
104 103
105 - (void)constructViews { 104 - (void)constructViews {
106 // Using a zero or very large frame causes GTMUILocalizerAndLayoutTweaker 105 // Using a zero or very large frame causes GTMUILocalizerAndLayoutTweaker
107 // to not resize the view properly so we take the bounds of the first label 106 // to not resize the view properly so we take the bounds of the first label
108 // which is contained in the nib. 107 // which is contained in the nib.
109 NSRect bogusFrame = [label_ frame]; 108 NSRect bogusFrame = [label_ frame];
110 label1_.reset(CreateLabel(bogusFrame)); 109 label1_.reset(CreateLabel(bogusFrame));
111 label2_.reset(CreateLabel(bogusFrame)); 110 label2_.reset(CreateLabel(bogusFrame));
112 label3_.reset(CreateLabel(bogusFrame)); 111 label3_.reset(CreateLabel(bogusFrame));
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 [[control description] UTF8String] <<[title UTF8String]; 542 [[control description] UTF8String] <<[title UTF8String];
544 return false; 543 return false;
545 } 544 }
546 previousControl = control; 545 previousControl = control;
547 } 546 }
548 547
549 return true; 548 return true;
550 } 549 }
551 550
552 @end // TranslateInfoBarControllerBase (TestingAPI) 551 @end // TranslateInfoBarControllerBase (TestingAPI)
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/infobars/infobar_utilities.mm ('k') | chrome/browser/ui/cocoa/infobars/translate_infobar_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698