| 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/extensions/extension_installed_bubble_controlle
r.h" | 5 #import "chrome/browser/ui/cocoa/extensions/extension_installed_bubble_controlle
r.h" |
| 6 | 6 |
| 7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/extensions/bundle_installer.h" | 11 #include "chrome/browser/extensions/bundle_installer.h" |
| 12 #include "chrome/browser/extensions/extension_action.h" | 12 #include "chrome/browser/extensions/extension_action.h" |
| 13 #include "chrome/browser/extensions/extension_action_manager.h" | 13 #include "chrome/browser/extensions/extension_action_manager.h" |
| 14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_navigator.h" | 15 #include "chrome/browser/ui/browser_navigator.h" |
| 16 #include "chrome/browser/ui/browser_window.h" | 16 #include "chrome/browser/ui/browser_window.h" |
| 17 #include "chrome/browser/ui/chrome_pages.h" | 17 #include "chrome/browser/ui/chrome_pages.h" |
| 18 #include "chrome/browser/ui/chrome_style.h" | 18 #include "chrome/browser/ui/chrome_style.h" |
| 19 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" | 19 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" |
| 20 #include "chrome/browser/ui/cocoa/browser_window_controller.h" | 20 #include "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 21 #include "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h" | 21 #include "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h" |
| 22 #include "chrome/browser/ui/cocoa/extensions/bundle_util.h" |
| 22 #include "chrome/browser/ui/cocoa/hover_close_button.h" | 23 #include "chrome/browser/ui/cocoa/hover_close_button.h" |
| 23 #include "chrome/browser/ui/cocoa/info_bubble_view.h" | 24 #include "chrome/browser/ui/cocoa/info_bubble_view.h" |
| 24 #include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 25 #include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| 25 #include "chrome/browser/ui/cocoa/new_tab_button.h" | 26 #include "chrome/browser/ui/cocoa/new_tab_button.h" |
| 26 #include "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" | 27 #include "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" |
| 27 #include "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 28 #include "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
| 28 #include "chrome/browser/ui/extensions/extension_install_ui_factory.h" | 29 #include "chrome/browser/ui/extensions/extension_install_ui_factory.h" |
| 29 #include "chrome/browser/ui/extensions/extension_installed_bubble.h" | 30 #include "chrome/browser/ui/extensions/extension_installed_bubble.h" |
| 30 #include "chrome/browser/ui/singleton_tabs.h" | 31 #include "chrome/browser/ui/singleton_tabs.h" |
| 31 #include "chrome/browser/ui/sync/sync_promo_ui.h" | 32 #include "chrome/browser/ui/sync/sync_promo_ui.h" |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 - (int)calculateWindowHeight { | 331 - (int)calculateWindowHeight { |
| 331 // Adjust the window height to reflect the sum height of all messages | 332 // Adjust the window height to reflect the sum height of all messages |
| 332 // and vertical padding. | 333 // and vertical padding. |
| 333 int newWindowHeight = 2 * extension_installed_bubble::kOuterVerticalMargin; | 334 int newWindowHeight = 2 * extension_installed_bubble::kOuterVerticalMargin; |
| 334 | 335 |
| 335 // If type is bundle, list the extensions that were installed and those that | 336 // If type is bundle, list the extensions that were installed and those that |
| 336 // failed. | 337 // failed. |
| 337 if (type_ == extension_installed_bubble::kBundle) { | 338 if (type_ == extension_installed_bubble::kBundle) { |
| 338 NSInteger installedListHeight = | 339 NSInteger installedListHeight = |
| 339 [self addExtensionList:installedHeadingMsg_ | 340 [self addExtensionList:installedHeadingMsg_ |
| 340 itemsMsg:installedItemsMsg_ | 341 itemsView:installedItemsView_ |
| 341 state:BundleInstaller::Item::STATE_INSTALLED]; | 342 state:BundleInstaller::Item::STATE_INSTALLED]; |
| 342 | 343 |
| 343 NSInteger failedListHeight = | 344 NSInteger failedListHeight = |
| 344 [self addExtensionList:failedHeadingMsg_ | 345 [self addExtensionList:failedHeadingMsg_ |
| 345 itemsMsg:failedItemsMsg_ | 346 itemsView:failedItemsView_ |
| 346 state:BundleInstaller::Item::STATE_FAILED]; | 347 state:BundleInstaller::Item::STATE_FAILED]; |
| 347 | 348 |
| 348 newWindowHeight += installedListHeight + failedListHeight; | 349 newWindowHeight += installedListHeight + failedListHeight; |
| 349 | 350 |
| 350 // Put some space between the lists if both are present. | 351 // Put some space between the lists if both are present. |
| 351 if (installedListHeight > 0 && failedListHeight > 0) | 352 if (installedListHeight > 0 && failedListHeight > 0) |
| 352 newWindowHeight += extension_installed_bubble::kInnerVerticalMargin; | 353 newWindowHeight += extension_installed_bubble::kInnerVerticalMargin; |
| 353 | 354 |
| 354 return newWindowHeight; | 355 return newWindowHeight; |
| 355 } | 356 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 chrome_style::GetLinkColor())]; | 456 chrome_style::GetLinkColor())]; |
| 456 [GTMUILocalizerAndLayoutTweaker sizeToFitView:manageShortcutLink_]; | 457 [GTMUILocalizerAndLayoutTweaker sizeToFitView:manageShortcutLink_]; |
| 457 newWindowHeight += extension_installed_bubble::kInnerVerticalMargin; | 458 newWindowHeight += extension_installed_bubble::kInnerVerticalMargin; |
| 458 newWindowHeight += NSHeight([manageShortcutLink_ frame]); | 459 newWindowHeight += NSHeight([manageShortcutLink_ frame]); |
| 459 } | 460 } |
| 460 | 461 |
| 461 return newWindowHeight; | 462 return newWindowHeight; |
| 462 } | 463 } |
| 463 | 464 |
| 464 - (NSInteger)addExtensionList:(NSTextField*)headingMsg | 465 - (NSInteger)addExtensionList:(NSTextField*)headingMsg |
| 465 itemsMsg:(NSTextField*)itemsMsg | 466 itemsView:(NSView*)itemsView |
| 466 state:(BundleInstaller::Item::State)state { | 467 state:(BundleInstaller::Item::State)state { |
| 467 base::string16 heading = bundle_->GetHeadingTextFor(state); | 468 base::string16 heading = bundle_->GetHeadingTextFor(state); |
| 468 bool hidden = heading.empty(); | 469 bool hidden = heading.empty(); |
| 469 [headingMsg setHidden:hidden]; | 470 [headingMsg setHidden:hidden]; |
| 470 [itemsMsg setHidden:hidden]; | 471 [itemsView setHidden:hidden]; |
| 471 if (hidden) | 472 if (hidden) |
| 472 return 0; | 473 return 0; |
| 473 | 474 |
| 474 [headingMsg setStringValue:base::SysUTF16ToNSString(heading)]; | 475 [headingMsg setStringValue:base::SysUTF16ToNSString(heading)]; |
| 475 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:headingMsg]; | 476 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:headingMsg]; |
| 476 | 477 |
| 477 NSMutableString* joinedItems = [NSMutableString string]; | 478 CGFloat height = |
| 478 BundleInstaller::ItemList items = bundle_->GetItemsWithState(state); | 479 PopulateBundleItemsList(bundle_->GetItemsWithState(state), itemsView); |
| 479 for (size_t i = 0; i < items.size(); ++i) { | |
| 480 if (i > 0) | |
| 481 [joinedItems appendString:@"\n"]; | |
| 482 [joinedItems appendString:base::SysUTF16ToNSString( | |
| 483 items[i].GetNameForDisplay())]; | |
| 484 } | |
| 485 | 480 |
| 486 [itemsMsg setStringValue:joinedItems]; | 481 NSRect frame = [itemsView frame]; |
| 487 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:itemsMsg]; | 482 frame.size.height = height; |
| 483 [itemsView setFrame:frame]; |
| 488 | 484 |
| 489 return NSHeight([headingMsg frame]) + | 485 return NSHeight([headingMsg frame]) + |
| 490 extension_installed_bubble::kInnerVerticalMargin + | 486 extension_installed_bubble::kInnerVerticalMargin + |
| 491 NSHeight([itemsMsg frame]); | 487 NSHeight([itemsView frame]); |
| 492 } | 488 } |
| 493 | 489 |
| 494 // Adjust y-position of messages to sit properly in new window height. | 490 // Adjust y-position of messages to sit properly in new window height. |
| 495 - (void)setMessageFrames:(int)newWindowHeight { | 491 - (void)setMessageFrames:(int)newWindowHeight { |
| 496 if (type_ == extension_installed_bubble::kBundle) { | 492 if (type_ == extension_installed_bubble::kBundle) { |
| 497 // Layout the messages from the bottom up. | 493 // Layout the messages from the bottom up. |
| 498 NSTextField* msgs[] = { failedItemsMsg_, failedHeadingMsg_, | 494 NSView* msgs[] = { failedItemsView_, failedHeadingMsg_, |
| 499 installedItemsMsg_, installedHeadingMsg_ }; | 495 installedItemsView_, installedHeadingMsg_ }; |
| 500 NSInteger offsetFromBottom = 0; | 496 NSInteger offsetFromBottom = 0; |
| 501 BOOL isFirstVisible = YES; | 497 BOOL isFirstVisible = YES; |
| 502 for (size_t i = 0; i < arraysize(msgs); ++i) { | 498 for (size_t i = 0; i < arraysize(msgs); ++i) { |
| 503 if ([msgs[i] isHidden]) | 499 if ([msgs[i] isHidden]) |
| 504 continue; | 500 continue; |
| 505 | 501 |
| 506 NSRect frame = [msgs[i] frame]; | 502 NSRect frame = [msgs[i] frame]; |
| 507 NSInteger margin = isFirstVisible ? | 503 NSInteger margin = isFirstVisible ? |
| 508 extension_installed_bubble::kOuterVerticalMargin : | 504 extension_installed_bubble::kOuterVerticalMargin : |
| 509 extension_installed_bubble::kInnerVerticalMargin; | 505 extension_installed_bubble::kInnerVerticalMargin; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 install_ui->OpenAppInstalledUI([self extension]->id()); | 605 install_ui->OpenAppInstalledUI([self extension]->id()); |
| 610 } | 606 } |
| 611 | 607 |
| 612 - (void)awakeFromNib { | 608 - (void)awakeFromNib { |
| 613 if (bundle_) | 609 if (bundle_) |
| 614 return; | 610 return; |
| 615 [self initializeLabel]; | 611 [self initializeLabel]; |
| 616 } | 612 } |
| 617 | 613 |
| 618 @end | 614 @end |
| OLD | NEW |