Chromium Code Reviews| Index: chrome/browser/ui/cocoa/translate/translate_bubble_controller.mm |
| diff --git a/chrome/browser/ui/cocoa/translate/translate_bubble_controller.mm b/chrome/browser/ui/cocoa/translate/translate_bubble_controller.mm |
| index 577da21c46945240cd981e26285ec200d6bea601..d2107c88e91d51f0254212a0519c45a9cb125399 100644 |
| --- a/chrome/browser/ui/cocoa/translate/translate_bubble_controller.mm |
| +++ b/chrome/browser/ui/cocoa/translate/translate_bubble_controller.mm |
| @@ -4,15 +4,76 @@ |
| #import "chrome/browser/ui/cocoa/translate/translate_bubble_controller.h" |
| +#include "base/mac/foundation_util.h" |
| #include "base/mac/scoped_nsobject.h" |
| +#include "base/strings/sys_string_conversions.h" |
| #include "chrome/browser/translate/translate_ui_delegate.h" |
| #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
| #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
| #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
| +#include "chrome/browser/ui/translate/language_combobox_model.h" |
| #include "chrome/browser/ui/translate/translate_bubble_model_impl.h" |
| -#import "ui/base/cocoa/flipped_view.h" |
| +#include "content/public/browser/browser_context.h" |
| +#include "grit/generated_resources.h" |
| +#include "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
|
groby-ooo-7-16
2014/03/25 18:49:05
You don't need that any more.
hajimehoshi
2014/03/26 11:06:05
Done.
|
| +#import "ui/base/cocoa/controls/hyperlink_button_cell.h" |
| #import "ui/base/cocoa/window_size_constants.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| +#include "ui/base/models/combobox_model.h" |
| + |
| +class TranslateDenialComboboxModel : public ui::ComboboxModel { |
| + public: |
| + explicit TranslateDenialComboboxModel( |
| + const base::string16& original_language_name) { |
| + // Dummy menu item, which is shown on the top of a NSPopUpButton. The top |
| + // text of the denial pop up menu should be IDS_TRANSLATE_BUBBLE_DENY, while |
| + // it is impossible to use it here because NSPopUpButtons' addItemWithTitle |
| + // removes a duplicated menu item. Instead, the title will be set later by |
| + // NSMenuItem's setTitle. |
|
groby-ooo-7-16
2014/03/25 18:49:05
Having an entry twice in a popup menu is counter t
hajimehoshi
2014/03/26 11:06:05
The context is that we wanted the 'fancy' button (
groby-ooo-7-16
2014/03/27 00:39:39
Ah, I understand. Thank you for the explanation, a
|
| + items_.push_back(base::string16()); |
| + |
| + // Menu items in the drop down menu. |
| + items_.push_back(l10n_util::GetStringUTF16(IDS_TRANSLATE_BUBBLE_DENY)); |
| + items_.push_back(l10n_util::GetStringFUTF16( |
| + IDS_TRANSLATE_BUBBLE_NEVER_TRANSLATE_LANG, |
| + original_language_name)); |
| + items_.push_back(l10n_util::GetStringUTF16( |
| + IDS_TRANSLATE_BUBBLE_NEVER_TRANSLATE_SITE)); |
| + } |
| + virtual ~TranslateDenialComboboxModel() {} |
| + |
| + private: |
| + // ComboboxModel: |
| + virtual int GetItemCount() const OVERRIDE { |
| + return items_.size(); |
| + } |
| + virtual base::string16 GetItemAt(int index) OVERRIDE { |
| + return items_[index]; |
| + } |
| + virtual bool IsItemSeparatorAt(int index) OVERRIDE { |
| + return false; |
| + } |
| + virtual int GetDefaultIndex() const OVERRIDE { |
| + return 0; |
| + } |
| + |
| + std::vector<base::string16> items_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TranslateDenialComboboxModel); |
| +}; |
| + |
| +const CGFloat kWindowWidth = 320; |
| + |
| +// Padding between the window frame and content. |
| +const CGFloat kFramePadding = 16; |
| + |
| +const CGFloat kRelatedControlHorizontalSpacing = -2; |
| + |
| +const CGFloat kRelatedControlVerticalSpacing = 4; |
| +const CGFloat kUnrelatedControlVerticalSpacing = 20; |
| + |
| +const CGFloat kContentWidth = kWindowWidth - 2 * kFramePadding; |
| @implementation TranslateBubbleController |
| @@ -39,6 +100,12 @@ |
| translateExecuted_ = YES; |
| } |
| + beforeTranslateView_.reset([self createViewBeforeTranslate]); |
| + translatingView_.reset([self createViewTranslating]); |
| + afterTranslateView_.reset([self createViewAfterTranslate]); |
| + errorView_.reset([self createViewError]); |
| + advancedView_.reset([self createViewAdvanced]); |
| + |
| [self performLayout]; |
| } |
| return self; |
| @@ -46,6 +113,23 @@ |
| @synthesize webContents = webContents_; |
| +- (NSView*)currentView { |
| + switch (model_->GetViewState()) { |
| + case TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE: |
| + return beforeTranslateView_; |
| + case TranslateBubbleModel::VIEW_STATE_TRANSLATING: |
| + return translatingView_; |
| + case TranslateBubbleModel::VIEW_STATE_AFTER_TRANSLATE: |
| + return afterTranslateView_; |
| + case TranslateBubbleModel::VIEW_STATE_ERROR: |
| + return errorView_; |
| + case TranslateBubbleModel::VIEW_STATE_ADVANCED: |
| + return advancedView_; |
| + } |
| + NOTREACHED(); |
| + return nil; |
| +} |
| + |
| - (const TranslateBubbleModel*)model { |
| return model_.get(); |
| } |
| @@ -71,8 +155,482 @@ |
| } |
| - (void)performLayout { |
| - // TODO(hajimehoshi): Now this shows just an empty bubble. Implement this. |
| - [[self window] display]; |
| + NSWindow* window = [self window]; |
| + [[window contentView] setSubviews:@[ [self currentView] ]]; |
| + |
| + CGFloat height = NSHeight([[self currentView] frame]) + |
| + 2 * kFramePadding + info_bubble::kBubbleArrowHeight; |
| + |
| + NSRect windowFrame = [window contentRectForFrameRect:[[self window] frame]]; |
| + NSRect newWindowFrame = [window frameRectForContentRect:NSMakeRect( |
| + NSMinX(windowFrame), NSMaxY(windowFrame) - height, kWindowWidth, height)]; |
| + [window setFrame:newWindowFrame |
| + display:YES |
| + animate:[[self window] isVisible]]; |
| +} |
| + |
| +- (NSView*)createViewBeforeTranslate { |
|
groby-ooo-7-16
2014/03/25 18:49:05
Please declare private methods in a private interf
hajimehoshi
2014/03/26 11:06:05
Done. As you mentioned before, should I split this
|
| + NSRect contentFrame = NSMakeRect( |
| + kFramePadding, |
| + kFramePadding, |
| + kContentWidth, |
| + 0); |
| + NSView* view = [[NSView alloc] initWithFrame:contentFrame]; |
| + |
| + NSString* message = |
| + l10n_util::GetNSStringWithFixup(IDS_TRANSLATE_BUBBLE_BEFORE_TRANSLATE); |
| + NSTextField* textLabel = [self addText:message |
| + toView:view]; |
| + message = l10n_util::GetNSStringWithFixup(IDS_TRANSLATE_BUBBLE_ADVANCED); |
| + NSButton* advancedLinkButton = |
| + [self addLinkButtonWithText:message |
| + action:@selector(handleAdvancedLinkButtonPressed) |
| + toView:view]; |
| + |
| + NSString* title = |
| + l10n_util::GetNSStringWithFixup(IDS_TRANSLATE_BUBBLE_ACCEPT); |
| + NSButton* translateButton = |
| + [self addButton:title |
| + action:@selector(handleTranslateButtonPressed) |
| + toView:view]; |
| + |
| + base::string16 originalLanguageName = |
| + model_->GetLanguageNameAt(model_->GetOriginalLanguageIndex()); |
| + translateDenialComboboxModel_.reset( |
| + new TranslateDenialComboboxModel(originalLanguageName)); |
|
groby-ooo-7-16
2014/03/25 18:49:05
Note for later CL's: When you factor out the Trans
hajimehoshi
2014/03/26 11:06:05
Thanks.
|
| + NSPopUpButton* denyPopUpButton = |
| + [self addPopUpButton:translateDenialComboboxModel_.get() |
| + action:nil |
| + toView:view]; |
| + [denyPopUpButton setPullsDown:YES]; |
| + [[denyPopUpButton itemAtIndex:1] setTarget:self]; |
| + [[denyPopUpButton itemAtIndex:1] |
| + setAction:@selector(handleDenialPopUpButtonNopeSelected)]; |
| + [[denyPopUpButton itemAtIndex:2] setTarget:self]; |
| + [[denyPopUpButton itemAtIndex:2] |
| + setAction:@selector(handleDenialPopUpButtonNeverTranslateLanguageSelected)]; |
| + [[denyPopUpButton itemAtIndex:3] setTarget:self]; |
| + [[denyPopUpButton itemAtIndex:3] |
| + setAction:@selector(handleDenialPopUpButtonNeverTranslateSiteSelected)]; |
| + |
| + title = base::SysUTF16ToNSString( |
| + l10n_util::GetStringUTF16(IDS_TRANSLATE_BUBBLE_DENY)); |
| + [[denyPopUpButton itemAtIndex:0] setTitle:title]; |
| + |
| + // Adjust width for the first item. |
| + std::vector<NSString*> titles; |
| + NSArray* items = [denyPopUpButton itemArray]; |
| + int index = 0; |
| + for (NSMenuItem* item in items) { |
| + if (index != 0) { |
|
groby-ooo-7-16
2014/03/25 18:49:05
No need for this check (or for tracking index). It
hajimehoshi
2014/03/26 11:06:05
Thanks, but I used your suggestion of copying NSCe
|
| + titles.push_back([item title]); |
| + [item setTitle:@""]; |
| + } |
| + index++; |
| + } |
| + [denyPopUpButton sizeToFit]; |
| + for (int i = 1; i < [denyPopUpButton numberOfItems]; i++) { |
| + NSMenuItem* item = [denyPopUpButton itemAtIndex:i]; |
| + [item setTitle:titles[i-1]]; |
| + } |
| + |
| + // Layout |
| + CGFloat yPos = 0; |
| + |
| + [translateButton setFrameOrigin:NSMakePoint( |
| + kContentWidth - NSWidth([translateButton frame]), yPos)]; |
| + |
| + NSRect denyPopUpButtonFrame = [denyPopUpButton frame]; |
| + CGFloat diffY = [[denyPopUpButton cell] |
| + titleRectForBounds:[denyPopUpButton bounds]].origin.y; |
| + [denyPopUpButton setFrameOrigin:NSMakePoint( |
| + NSMinX([translateButton frame]) - denyPopUpButtonFrame.size.width |
| + - kRelatedControlHorizontalSpacing, |
| + yPos + diffY)]; |
| + |
| + yPos += NSHeight([translateButton frame]) + |
| + kUnrelatedControlVerticalSpacing; |
| + |
| + [textLabel setFrameOrigin:NSMakePoint(0, yPos)]; |
| + [advancedLinkButton setFrameOrigin:NSMakePoint( |
| + NSWidth([textLabel frame]), yPos)]; |
| + |
| + [view setFrameSize:NSMakeSize(kContentWidth, NSMaxY([textLabel frame]))]; |
| + |
| + return view; |
| +} |
| + |
| +- (NSView*)createViewTranslating { |
|
groby-ooo-7-16
2014/03/25 18:49:05
See above re: name
hajimehoshi
2014/03/26 11:06:05
Done.
|
| + NSRect contentFrame = NSMakeRect( |
| + kFramePadding, |
| + kFramePadding, |
| + kContentWidth, |
| + 0); |
| + NSView* view = [[NSView alloc] initWithFrame:contentFrame]; |
| + |
| + NSString* message = |
| + l10n_util::GetNSStringWithFixup(IDS_TRANSLATE_BUBBLE_TRANSLATING); |
| + NSTextField* textLabel = [self addText:message |
| + toView:view]; |
| + NSString* title = |
| + l10n_util::GetNSStringWithFixup(IDS_TRANSLATE_BUBBLE_REVERT); |
| + NSButton* showOriginalButton = |
| + [self addButton:title |
| + action:@selector(handleShowOriginalButtonPressed) |
| + toView:view]; |
| + [showOriginalButton setEnabled:NO]; |
| + |
| + // Layout |
| + CGFloat yPos = 0; |
| + |
| + [showOriginalButton setFrameOrigin:NSMakePoint( |
| + kContentWidth - NSWidth([showOriginalButton frame]), yPos)]; |
| + |
| + yPos += NSHeight([showOriginalButton frame]) + |
| + kUnrelatedControlVerticalSpacing; |
| + |
| + [textLabel setFrameOrigin:NSMakePoint(0, yPos)]; |
| + |
| + [view setFrameSize:NSMakeSize(kContentWidth, NSMaxY([textLabel frame]))]; |
| + |
| + return view; |
| +} |
| + |
| +- (NSView*)createViewAfterTranslate { |
| + NSRect contentFrame = NSMakeRect( |
| + kFramePadding, |
| + kFramePadding, |
| + kContentWidth, |
| + 0); |
| + NSView* view = [[NSView alloc] initWithFrame:contentFrame]; |
| + |
| + NSString* message = |
| + l10n_util::GetNSStringWithFixup(IDS_TRANSLATE_BUBBLE_TRANSLATED); |
| + NSTextField* textLabel = [self addText:message |
| + toView:view]; |
| + message = l10n_util::GetNSStringWithFixup(IDS_TRANSLATE_BUBBLE_ADVANCED); |
| + NSButton* advancedLinkButton = |
| + [self addLinkButtonWithText:message |
| + action:@selector(handleAdvancedLinkButtonPressed) |
| + toView:view]; |
| + NSString* title = |
| + l10n_util::GetNSStringWithFixup(IDS_TRANSLATE_BUBBLE_REVERT); |
| + NSButton* showOriginalButton = |
| + [self addButton:title |
| + action:@selector(handleShowOriginalButtonPressed) |
| + toView:view]; |
| + |
| + // Layout |
| + CGFloat yPos = 0; |
| + |
| + [showOriginalButton setFrameOrigin:NSMakePoint( |
| + kContentWidth - NSWidth([showOriginalButton frame]), yPos)]; |
| + |
| + yPos += NSHeight([showOriginalButton frame]) + |
| + kUnrelatedControlVerticalSpacing; |
| + |
| + [textLabel setFrameOrigin:NSMakePoint(0, yPos)]; |
| + [advancedLinkButton setFrameOrigin:NSMakePoint( |
| + NSMaxX([textLabel frame]), yPos)]; |
| + |
| + [view setFrameSize:NSMakeSize(kContentWidth, NSMaxY([textLabel frame]))]; |
| + |
| + return view; |
| +} |
| + |
| +- (NSView*)createViewError { |
| + NSRect contentFrame = NSMakeRect( |
| + kFramePadding, |
| + kFramePadding, |
| + kContentWidth, |
| + 0); |
| + NSView* view = [[NSView alloc] initWithFrame:contentFrame]; |
| + |
| + // TODO(hajimehoshi): Implement this. |
| + |
| + return view; |
| +} |
| + |
| +- (NSView*)createViewAdvanced { |
| + NSRect contentFrame = NSMakeRect( |
| + kFramePadding, |
| + kFramePadding, |
| + kContentWidth, |
| + 0); |
| + NSView* view = [[NSView alloc] initWithFrame:contentFrame]; |
| + |
| + NSString* title = l10n_util::GetNSStringWithFixup( |
| + IDS_TRANSLATE_BUBBLE_PAGE_LANGUAGE); |
| + NSTextField* sourceLanguageLabel = [self addText:title |
| + toView:view]; |
| + title = l10n_util::GetNSStringWithFixup( |
| + IDS_TRANSLATE_BUBBLE_TRANSLATION_LANGUAGE); |
| + NSTextField* targetLanguageLabel = [self addText:title |
| + toView:view]; |
| + |
| + // combobox |
| + int sourceDefaultIndex = model_->GetOriginalLanguageIndex(); |
| + int targetDefaultIndex = model_->GetTargetLanguageIndex(); |
| + sourceLanguageComboboxModel_.reset( |
| + new LanguageComboboxModel(sourceDefaultIndex, model_.get())); |
| + targetLanguageComboboxModel_.reset( |
| + new LanguageComboboxModel(targetDefaultIndex, model_.get())); |
| + SEL action = @selector(handleSourceLanguagePopUpButtonSelectedItemChanged:); |
| + NSPopUpButton* sourcePopUpButton = |
| + [self addPopUpButton:sourceLanguageComboboxModel_.get() |
| + action:action |
| + toView:view]; |
| + action = @selector(handleTargetLanguagePopUpButtonSelectedItemChanged:); |
| + NSPopUpButton* targetPopUpButton = |
| + [self addPopUpButton:targetLanguageComboboxModel_.get() |
| + action:action |
| + toView:view]; |
| + |
| + // 'Always translate' checkbox |
| + BOOL isIncognitoWindow = webContents_ ? |
| + webContents_->GetBrowserContext()->IsOffTheRecord() : NO; |
| + if (!isIncognitoWindow) { |
| + NSString* title = |
| + l10n_util::GetNSStringWithFixup(IDS_TRANSLATE_BUBBLE_ALWAYS); |
| + alwaysTranslateCheckbox_ = [self addCheckbox:title |
| + toView:view]; |
| + } |
| + |
| + // Buttons |
| + advancedDoneButton_ = |
| + [self addButton:l10n_util::GetNSStringWithFixup(IDS_DONE) |
| + action:@selector(handleDoneButtonPressed) |
| + toView:view]; |
| + advancedCancelButton_ = |
| + [self addButton:l10n_util::GetNSStringWithFixup(IDS_CANCEL) |
| + action:@selector(handleCancelButtonPressed) |
| + toView:view]; |
| + |
| + // Layout |
| + CGFloat textLabelWidth = NSWidth([sourceLanguageLabel frame]); |
| + if (textLabelWidth < NSWidth([targetLanguageLabel frame])) |
| + textLabelWidth = NSWidth([targetLanguageLabel frame]); |
| + |
| + CGFloat yPos = 0; |
| + |
| + [advancedDoneButton_ setFrameOrigin:NSMakePoint(0, yPos)]; |
| + [advancedCancelButton_ setFrameOrigin:NSMakePoint(0, yPos)]; |
| + |
| + yPos += NSHeight([advancedDoneButton_ frame]) + |
| + kUnrelatedControlVerticalSpacing; |
| + |
| + if (alwaysTranslateCheckbox_) { |
| + [alwaysTranslateCheckbox_ setFrameOrigin:NSMakePoint(textLabelWidth, yPos)]; |
| + |
| + yPos += NSHeight([alwaysTranslateCheckbox_ frame]) + |
| + kRelatedControlVerticalSpacing; |
| + } |
| + |
| + CGFloat diffY = [[sourcePopUpButton cell] |
| + titleRectForBounds:[sourcePopUpButton bounds]].origin.y; |
| + |
| + [targetLanguageLabel setFrameOrigin:NSMakePoint( |
| + textLabelWidth - NSWidth([targetLanguageLabel frame]), yPos + diffY)]; |
| + |
| + NSRect frame = [targetPopUpButton frame]; |
| + frame.origin = NSMakePoint(textLabelWidth, yPos); |
| + frame.size.width = (kWindowWidth - 2 * kFramePadding) - textLabelWidth; |
| + [targetPopUpButton setFrame:frame]; |
| + |
| + yPos += NSHeight([targetPopUpButton frame]) + |
| + kRelatedControlVerticalSpacing; |
| + |
| + [sourceLanguageLabel setFrameOrigin:NSMakePoint( |
| + textLabelWidth - NSWidth([sourceLanguageLabel frame]), yPos + diffY)]; |
| + |
| + frame = [sourcePopUpButton frame]; |
| + frame.origin = NSMakePoint(textLabelWidth, yPos); |
| + frame.size.width = NSWidth([targetPopUpButton frame]); |
|
groby-ooo-7-16
2014/03/25 18:49:05
Are you sure you don't want target & source width
hajimehoshi
2014/03/26 11:06:05
The sets of source and target languages are same,
|
| + [sourcePopUpButton setFrame:frame]; |
| + |
| + [view setFrameSize:NSMakeSize(kContentWidth, |
| + NSMaxY([sourcePopUpButton frame]))]; |
| + |
| + [self updateAdvancedView]; |
| + |
| + return view; |
| +} |
| + |
| +- (void)updateAdvancedView { |
| + NSInteger state = model_->ShouldAlwaysTranslate() ? NSOnState : NSOffState; |
| + [alwaysTranslateCheckbox_ setState:state]; |
| + |
| + NSString* title; |
| + if (model_->IsPageTranslatedInCurrentLanguages()) |
| + title = l10n_util::GetNSStringWithFixup(IDS_DONE); |
| + else |
| + title = l10n_util::GetNSStringWithFixup(IDS_TRANSLATE_BUBBLE_ACCEPT); |
| + [advancedDoneButton_ setTitle:title]; |
| + [advancedDoneButton_ sizeToFit]; |
| + |
| + NSRect frame = [advancedDoneButton_ frame]; |
| + frame.origin.x = (kWindowWidth - 2 * kFramePadding) - NSWidth(frame); |
| + [advancedDoneButton_ setFrameOrigin:frame.origin]; |
| + |
| + frame = [advancedCancelButton_ frame]; |
| + frame.origin.x = NSMinX([advancedDoneButton_ frame]) - NSWidth(frame) |
| + - kRelatedControlHorizontalSpacing; |
| + [advancedCancelButton_ setFrameOrigin:frame.origin]; |
| +} |
| + |
| +- (NSTextField*)addText:(NSString*)text |
| + toView:(NSView*)view { |
| + base::scoped_nsobject<NSTextField> textField( |
| + [[NSTextField alloc] initWithFrame:NSZeroRect]); |
| + [textField setEditable:NO]; |
| + [textField setSelectable:YES]; |
| + [textField setDrawsBackground:NO]; |
| + [textField setBezeled:NO]; |
| + [textField setStringValue:text]; |
| + NSFont* font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; |
| + [textField setFont:font]; |
| + [textField setAutoresizingMask:NSViewWidthSizable]; |
| + [view addSubview:textField.get()]; |
| + |
| + [textField sizeToFit]; |
| + return textField.get(); |
| +} |
| + |
| +- (NSButton*)addLinkButtonWithText:(NSString*)text |
| + action:(SEL)action |
| + toView:(NSView*)view { |
| + base::scoped_nsobject<NSButton> button( |
| + [[HyperlinkButtonCell buttonWithString:text] retain]); |
| + |
| + [button setButtonType:NSMomentaryPushInButton]; |
| + [button setBezelStyle:NSRegularSquareBezelStyle]; |
| + [button setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; |
| + [button sizeToFit]; |
| + [button setTarget:self]; |
| + [button setAction:action]; |
| + |
| + [view addSubview:button.get()]; |
| + |
| + return button.get(); |
| +} |
| + |
| +- (NSButton*)addButton:(NSString*)title |
| + action:(SEL)action |
| + toView:(NSView*)view { |
| + base::scoped_nsobject<NSButton> button( |
| + [[NSButton alloc] initWithFrame:NSZeroRect]); |
| + [button setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; |
| + [button setTitle:title]; |
| + [button setBezelStyle:NSRoundedBezelStyle]; |
| + [[button cell] setControlSize:NSSmallControlSize]; |
| + [button sizeToFit]; |
| + [button setTarget:self]; |
| + [button setAction:action]; |
| + |
| + [view addSubview:button.get()]; |
| + |
| + return button.get(); |
| +} |
| + |
| +- (NSButton*)addCheckbox:(NSString*)title |
| + toView:(NSView*)view { |
| + base::scoped_nsobject<NSButton> button( |
| + [[NSButton alloc] initWithFrame:NSZeroRect]); |
| + [button setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; |
| + [button setTitle:title]; |
| + [[button cell] setControlSize:NSSmallControlSize]; |
| + [button setButtonType:NSSwitchButton]; |
| + [button sizeToFit]; |
| + |
| + [view addSubview:button.get()]; |
| + |
| + return button.get(); |
| +} |
| + |
| +- (NSPopUpButton*)addPopUpButton:(ui::ComboboxModel*)model |
| + action:(SEL)action |
| + toView:(NSView*)view { |
| + base::scoped_nsobject<NSPopUpButton> button( |
| + [[NSPopUpButton alloc] initWithFrame:NSZeroRect pullsDown:NO]); |
| + [button setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; |
| + [button setBordered:YES]; |
| + [[button cell] setControlSize:NSSmallControlSize]; |
| + [button setTarget:self]; |
| + [button setAction:action]; |
| + |
| + for (int i = 0; i < model->GetItemCount(); ++i) |
|
groby-ooo-7-16
2014/03/25 18:49:05
This works, but doesn't account for separators. Ar
hajimehoshi
2014/03/26 11:06:05
Correct. I'll fix this. Sorry but I have to leave
hajimehoshi
2014/03/27 10:37:28
Done.
|
| + [button addItemWithTitle:base::SysUTF16ToNSString(model->GetItemAt(i))]; |
| + [button selectItemAtIndex:model->GetDefaultIndex()]; |
| + |
| + [button sizeToFit]; |
| + |
| + [view addSubview:button.get()]; |
| + |
| + return button.get(); |
| +} |
| + |
| +- (void)handleTranslateButtonPressed { |
|
groby-ooo-7-16
2014/03/25 18:49:05
I'd think most of the handleXYZ callbacks could li
hajimehoshi
2014/03/26 11:06:05
Not planned, but it seems not easy. Let me think a
|
| + translateExecuted_ = YES; |
| + model_->Translate(); |
| +} |
| + |
| +- (void)handleNopeButtonPressed { |
| + [self close]; |
| +} |
| + |
| +- (void)handleDoneButtonPressed { |
| + if (alwaysTranslateCheckbox_) { |
| + model_->SetAlwaysTranslate( |
| + [alwaysTranslateCheckbox_ state] == NSOnState); |
| + } |
| + if (model_->IsPageTranslatedInCurrentLanguages()) { |
| + model_->GoBackFromAdvanced(); |
| + [self performLayout]; |
| + } else { |
| + translateExecuted_ = true; |
| + model_->Translate(); |
| + [self switchView:TranslateBubbleModel::VIEW_STATE_TRANSLATING]; |
| + } |
| +} |
| + |
| +- (void)handleCancelButtonPressed { |
| + model_->GoBackFromAdvanced(); |
| + [self performLayout]; |
| +} |
| + |
| +- (void)handleShowOriginalButtonPressed { |
| + model_->RevertTranslation(); |
| + [self close]; |
| +} |
| + |
| +- (void)handleAdvancedLinkButtonPressed { |
| + [self switchView:TranslateBubbleModel::VIEW_STATE_ADVANCED]; |
| +} |
| + |
| +- (void)handleDenialPopUpButtonNopeSelected { |
| + [self close]; |
| +} |
| + |
| +- (void)handleDenialPopUpButtonNeverTranslateLanguageSelected { |
| + model_->SetNeverTranslateLanguage(true); |
| + [self close]; |
| +} |
| + |
| +- (void)handleDenialPopUpButtonNeverTranslateSiteSelected { |
| + model_->SetNeverTranslateSite(true); |
| + [self close]; |
| +} |
| + |
| +- (void)handleSourceLanguagePopUpButtonSelectedItemChanged:(id)sender { |
| + NSPopUpButton* button = base::mac::ObjCCastStrict<NSPopUpButton>(sender); |
| + model_->UpdateOriginalLanguageIndex([button indexOfSelectedItem]); |
| + [self updateAdvancedView]; |
| +} |
| + |
| +- (void)handleTargetLanguagePopUpButtonSelectedItemChanged:(id)sender { |
| + NSPopUpButton* button = base::mac::ObjCCastStrict<NSPopUpButton>(sender); |
| + model_->UpdateTargetLanguageIndex([button indexOfSelectedItem]); |
| + [self updateAdvancedView]; |
| } |
| @end |