| 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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 [infoBarView_ setPostsFrameChangedNotifications:YES]; | 354 [infoBarView_ setPostsFrameChangedNotifications:YES]; |
| 353 [[NSNotificationCenter defaultCenter] | 355 [[NSNotificationCenter defaultCenter] |
| 354 addObserver:self | 356 addObserver:self |
| 355 selector:@selector(didChangeFrame:) | 357 selector:@selector(didChangeFrame:) |
| 356 name:NSViewFrameDidChangeNotification | 358 name:NSViewFrameDidChangeNotification |
| 357 object:infoBarView_]; | 359 object:infoBarView_]; |
| 358 // Show and place GUI elements. | 360 // Show and place GUI elements. |
| 359 [self updateState]; | 361 [self updateState]; |
| 360 } | 362 } |
| 361 | 363 |
| 364 - (void)infobarWillHide { |
| 365 [[fromLanguagePopUp_ menu] cancelTracking]; |
| 366 [[toLanguagePopUp_ menu] cancelTracking]; |
| 367 [[optionsPopUp_ menu] cancelTracking]; |
| 368 [super infobarWillHide]; |
| 369 } |
| 370 |
| 362 - (void)infobarWillClose { | 371 - (void)infobarWillClose { |
| 363 [self disablePopUpMenu:[fromLanguagePopUp_ menu]]; | 372 [self disablePopUpMenu:[fromLanguagePopUp_ menu]]; |
| 364 [self disablePopUpMenu:[toLanguagePopUp_ menu]]; | 373 [self disablePopUpMenu:[toLanguagePopUp_ menu]]; |
| 365 [self disablePopUpMenu:[optionsPopUp_ menu]]; | 374 [self disablePopUpMenu:[optionsPopUp_ menu]]; |
| 366 // [super infobarWillClose] clears the owner field which is relied on by the | |
| 367 // notification handler, so remove the handler first. | |
| 368 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 375 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 369 [super infobarWillClose]; | 376 [super infobarWillClose]; |
| 370 } | 377 } |
| 371 | 378 |
| 372 - (void)adjustOptionsButtonSizeAndVisibilityForView:(NSView*)lastView { | 379 - (void)adjustOptionsButtonSizeAndVisibilityForView:(NSView*)lastView { |
| 373 [optionsPopUp_ setHidden:NO]; | 380 [optionsPopUp_ setHidden:NO]; |
| 374 [self rebuildOptionsMenu:NO]; | 381 [self rebuildOptionsMenu:NO]; |
| 375 [[optionsPopUp_ cell] setArrowPosition:NSPopUpArrowAtBottom]; | 382 [[optionsPopUp_ cell] setArrowPosition:NSPopUpArrowAtBottom]; |
| 376 [optionsPopUp_ sizeToFit]; | 383 [optionsPopUp_ sizeToFit]; |
| 377 | 384 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 // Danger Will Robinson! : This call can release the infobar (e.g. invoking | 458 // Danger Will Robinson! : This call can release the infobar (e.g. invoking |
| 452 // "About Translate" can open a new tab). | 459 // "About Translate" can open a new tab). |
| 453 // Do not access member variables after this line! | 460 // Do not access member variables after this line! |
| 454 optionsMenuModel_->ExecuteCommand(cmd, 0); | 461 optionsMenuModel_->ExecuteCommand(cmd, 0); |
| 455 } else { | 462 } else { |
| 456 NOTREACHED(); | 463 NOTREACHED(); |
| 457 } | 464 } |
| 458 } | 465 } |
| 459 | 466 |
| 460 - (void)dealloc { | 467 - (void)dealloc { |
| 461 // Perhaps this was removed as an observer in -infobarWillClose, but there's | |
| 462 // no guarantee that that was the case. | |
| 463 [[NSNotificationCenter defaultCenter] removeObserver:self]; | |
| 464 [showOriginalButton_ setTarget:nil]; | 468 [showOriginalButton_ setTarget:nil]; |
| 465 [translateMessageButton_ setTarget:nil]; | 469 [translateMessageButton_ setTarget:nil]; |
| 466 [super dealloc]; | 470 [super dealloc]; |
| 467 } | 471 } |
| 468 | 472 |
| 469 #pragma mark NSMenuDelegate | 473 #pragma mark NSMenuDelegate |
| 470 | 474 |
| 471 // Invoked by virtue of us being set as the delegate for the options menu. | 475 // Invoked by virtue of us being set as the delegate for the options menu. |
| 472 - (void)menuNeedsUpdate:(NSMenu *)menu { | 476 - (void)menuNeedsUpdate:(NSMenu *)menu { |
| 473 [self adjustOptionsButtonSizeAndVisibilityForView: | 477 [self adjustOptionsButtonSizeAndVisibilityForView: |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 [[control description] UTF8String] <<[title UTF8String]; | 546 [[control description] UTF8String] <<[title UTF8String]; |
| 543 return false; | 547 return false; |
| 544 } | 548 } |
| 545 previousControl = control; | 549 previousControl = control; |
| 546 } | 550 } |
| 547 | 551 |
| 548 return true; | 552 return true; |
| 549 } | 553 } |
| 550 | 554 |
| 551 @end // TranslateInfoBarControllerBase (TestingAPI) | 555 @end // TranslateInfoBarControllerBase (TestingAPI) |
| OLD | NEW |