diff options
author | bulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-05 11:40:08 +0000 |
---|---|---|
committer | bulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-05 11:40:08 +0000 |
commit | 352104ee28f47810b5d2dc5fd6193c60d2cd2e95 (patch) | |
tree | 1d4d26928b9951a3d5f54688c550835740849837 /chrome/browser/cocoa | |
parent | ff039f0833a278d7ca80aeb8987e73b6c258f305 (diff) | |
download | chromium_src-352104ee28f47810b5d2dc5fd6193c60d2cd2e95.zip chromium_src-352104ee28f47810b5d2dc5fd6193c60d2cd2e95.tar.gz chromium_src-352104ee28f47810b5d2dc5fd6193c60d2cd2e95.tar.bz2 |
Renames ContentBlockedImageView to ContentSettingImageView.
Adds ContentSettingImageModel to provide icon and tooltips for platform-specific ContentBlockedImageView.
(in preparation for:
http://codereview.chromium.org/650180/show
)
TEST=chrome/browser/content_setting_image_model_unittest.cc
Review URL: http://codereview.chromium.org/660279
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40732 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa')
-rw-r--r-- | chrome/browser/cocoa/autocomplete_text_field_cell.h | 6 | ||||
-rw-r--r-- | chrome/browser/cocoa/autocomplete_text_field_cell.mm | 16 | ||||
-rw-r--r-- | chrome/browser/cocoa/location_bar_view_mac.h | 30 | ||||
-rw-r--r-- | chrome/browser/cocoa/location_bar_view_mac.mm | 103 |
4 files changed, 75 insertions, 80 deletions
diff --git a/chrome/browser/cocoa/autocomplete_text_field_cell.h b/chrome/browser/cocoa/autocomplete_text_field_cell.h index 3763e2c..1da806f 100644 --- a/chrome/browser/cocoa/autocomplete_text_field_cell.h +++ b/chrome/browser/cocoa/autocomplete_text_field_cell.h @@ -55,7 +55,7 @@ class ExtensionAction; LocationBarViewMac::PageActionViewList* page_action_views_; // List of content blocked icons. This may be NULL during testing. - LocationBarViewMac::ContentBlockedViews* content_blocked_views_; + LocationBarViewMac::ContentSettingViews* content_setting_views_; } // Chooses |partialString| if |width| won't fit |fullString|. Strings @@ -79,8 +79,8 @@ class ExtensionAction; - (void)setSecurityImageView:(LocationBarViewMac::SecurityImageView*)view; - (void)setPageActionViewList:(LocationBarViewMac::PageActionViewList*)list; -- (void)setContentBlockedViewList: - (LocationBarViewMac::ContentBlockedViews*)views; +- (void)setContentSettingViewsList: + (LocationBarViewMac::ContentSettingViews*)views; // Returns an array of the visible AutocompleteTextFieldIcon objects. Returns // only visible icons. diff --git a/chrome/browser/cocoa/autocomplete_text_field_cell.mm b/chrome/browser/cocoa/autocomplete_text_field_cell.mm index 89b5f99..2b5600a 100644 --- a/chrome/browser/cocoa/autocomplete_text_field_cell.mm +++ b/chrome/browser/cocoa/autocomplete_text_field_cell.mm @@ -217,9 +217,9 @@ CGFloat WidthForKeyword(NSAttributedString* keywordString) { security_image_view_ = view; } -- (void)setContentBlockedViewList: - (LocationBarViewMac::ContentBlockedViews*)views { - content_blocked_views_ = views; +- (void)setContentSettingViewsList: + (LocationBarViewMac::ContentSettingViews*)views { + content_setting_views_ = views; } // Overriden to account for the hint strings and hint icons. @@ -430,13 +430,13 @@ CGFloat WidthForKeyword(NSAttributedString* keywordString) { } } - if (content_blocked_views_) { + if (content_setting_views_) { // We use a reverse_iterator here because we're laying out the views from // right to left but in the vector they're ordered left to right. - for (LocationBarViewMac::ContentBlockedViews::const_reverse_iterator - it(content_blocked_views_->rbegin()); - it != const_cast<const LocationBarViewMac::ContentBlockedViews*>( - content_blocked_views_)->rend(); + for (LocationBarViewMac::ContentSettingViews::const_reverse_iterator + it(content_setting_views_->rbegin()); + it != const_cast<const LocationBarViewMac::ContentSettingViews*>( + content_setting_views_)->rend(); ++it) { if ((*it)->IsVisible()) { NSImage* image = (*it)->GetImage(); diff --git a/chrome/browser/cocoa/location_bar_view_mac.h b/chrome/browser/cocoa/location_bar_view_mac.h index 75241f8..9f376e6 100644 --- a/chrome/browser/cocoa/location_bar_view_mac.h +++ b/chrome/browser/cocoa/location_bar_view_mac.h @@ -25,6 +25,7 @@ @class AutocompleteTextField; class BubblePositioner; class CommandUpdater; +class ContentSettingImageModel; @class ExtensionPopupController; class Profile; class ToolbarModel; @@ -55,7 +56,7 @@ class LocationBarViewMac : public AutocompleteEditController, virtual void AcceptInputWithDisposition(WindowOpenDisposition disposition); virtual void FocusLocation(); virtual void FocusSearch(); - virtual void UpdateContentBlockedIcons(); + virtual void UpdateContentSettingsIcons(); virtual void UpdatePageActions(); virtual void InvalidatePageActions(); virtual void SaveStateToContents(TabContents* contents); @@ -306,20 +307,20 @@ class LocationBarViewMac : public AutocompleteEditController, DISALLOW_COPY_AND_ASSIGN(PageActionImageView); }; - // ContentBlockedImageView is used to display the content settings images - // when types of contents are blocked on the current page. - class ContentBlockedImageView : public LocationBarImageView { + // ContentSettingImageView is used to display the content settings images + // on the current page. + class ContentSettingImageView : public LocationBarImageView { public: - ContentBlockedImageView(ContentSettingsType settings_type, + ContentSettingImageView(ContentSettingsType settings_type, LocationBarViewMac* owner, Profile* profile); - virtual ~ContentBlockedImageView(); + virtual ~ContentSettingImageView(); // Shows a content settings bubble. void OnMousePressed(NSRect bounds); - // Returns the settings type this shows up for. - ContentSettingsType settings_type() { return settings_type_; } + // Updates the image and visibility state based on the supplied TabContents. + void UpdateFromTabContents(const TabContents* tab_contents); // Returns the tooltip for this Page Action image or |nil| if there is none. virtual const NSString* GetToolTip(); @@ -327,16 +328,15 @@ class LocationBarViewMac : public AutocompleteEditController, private: void SetToolTip(NSString* tooltip); - // The type of content handled by this view. - ContentSettingsType settings_type_; + scoped_ptr<ContentSettingImageModel> content_setting_image_model_; LocationBarViewMac* owner_; Profile* profile_; scoped_nsobject<NSString> tooltip_; - DISALLOW_COPY_AND_ASSIGN(ContentBlockedImageView); + DISALLOW_COPY_AND_ASSIGN(ContentSettingImageView); }; - typedef ScopedVector<ContentBlockedImageView> ContentBlockedViews; + typedef ScopedVector<ContentSettingImageView> ContentSettingViews; class PageActionViewList { public: @@ -386,9 +386,9 @@ class LocationBarViewMac : public AutocompleteEditController, // Posts |notification| to the default notification center. void PostNotification(const NSString* notification); - // Updates visibility of the content blocked icons based on the current + // Updates visibility of the content settings icons based on the current // tab contents state. - void RefreshContentBlockedViews(); + void RefreshContentSettingsViews(); scoped_ptr<AutocompleteEditViewMac> edit_view_; @@ -411,7 +411,7 @@ class LocationBarViewMac : public AutocompleteEditController, PageActionViewList page_action_views_; // The content blocked views. - ContentBlockedViews content_blocked_views_; + ContentSettingViews content_setting_views_; Profile* profile_; diff --git a/chrome/browser/cocoa/location_bar_view_mac.mm b/chrome/browser/cocoa/location_bar_view_mac.mm index 854fd45..3229f45 100644 --- a/chrome/browser/cocoa/location_bar_view_mac.mm +++ b/chrome/browser/cocoa/location_bar_view_mac.mm @@ -22,6 +22,7 @@ #import "chrome/browser/cocoa/extensions/extension_action_context_menu.h" #import "chrome/browser/cocoa/extensions/extension_popup_controller.h" #include "chrome/browser/command_updater.h" +#include "chrome/browser/content_setting_image_model.h" #include "chrome/browser/extensions/extension_browser_event_router.h" #include "chrome/browser/extensions/extensions_service.h" #include "chrome/browser/extensions/extension_tabs_module.h" @@ -105,17 +106,17 @@ LocationBarViewMac::LocationBarViewMac( toolbar_model_(toolbar_model), transition_(PageTransition::TYPED) { for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { - ContentBlockedImageView* content_blocked_view = - new ContentBlockedImageView(static_cast<ContentSettingsType>(i), this, + ContentSettingImageView* content_setting_view = + new ContentSettingImageView(static_cast<ContentSettingsType>(i), this, profile_); - content_blocked_views_.push_back(content_blocked_view); - content_blocked_view->SetVisible(false); + content_setting_views_.push_back(content_setting_view); + content_setting_view->SetVisible(false); } AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell]; [cell setSecurityImageView:&security_image_view_]; [cell setPageActionViewList:&page_action_views_]; - [cell setContentBlockedViewList:&content_blocked_views_]; + [cell setContentSettingViewsList:&content_setting_views_]; registrar_.Add(this, NotificationType::EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, @@ -166,8 +167,8 @@ void LocationBarViewMac::FocusSearch() { edit_view_->SetForcedQuery(); } -void LocationBarViewMac::UpdateContentBlockedIcons() { - RefreshContentBlockedViews(); +void LocationBarViewMac::UpdateContentSettingsIcons() { + RefreshContentSettingsViews(); [field_ updateCursorAndToolTipRects]; [field_ setNeedsDisplay:YES]; } @@ -204,7 +205,7 @@ void LocationBarViewMac::Update(const TabContents* contents, bool should_restore_state) { SetSecurityIcon(toolbar_model_->GetIcon()); page_action_views_.RefreshViews(); - RefreshContentBlockedViews(); + RefreshContentSettingsViews(); // AutocompleteEditView restores state if the tab is non-NULL. edit_view_->Update(should_restore_state ? contents : NULL); } @@ -515,13 +516,13 @@ void LocationBarViewMac::PostNotification(const NSString* notification) { object:[NSValue valueWithPointer:this]]; } -void LocationBarViewMac::RefreshContentBlockedViews() { +void LocationBarViewMac::RefreshContentSettingsViews() { const TabContents* tab_contents = browser_->GetSelectedTabContents(); - for (ContentBlockedViews::iterator it(content_blocked_views_.begin()); - it != content_blocked_views_.end(); + for (ContentSettingViews::iterator it(content_setting_views_.begin()); + it != content_setting_views_.end(); ++it) { - (*it)->SetVisible((!toolbar_model_->input_in_progress() && tab_contents) ? - tab_contents->IsContentBlocked((*it)->settings_type()) : false); + (*it)->UpdateFromTabContents( + toolbar_model_->input_in_progress() ? NULL : tab_contents); } } @@ -823,43 +824,20 @@ void LocationBarViewMac::PageActionImageView::Observe( } // ContentSettingsImageView----------------------------------------------------- - -LocationBarViewMac::ContentBlockedImageView::ContentBlockedImageView( +LocationBarViewMac::ContentSettingImageView::ContentSettingImageView( ContentSettingsType settings_type, LocationBarViewMac* owner, Profile* profile) - : settings_type_(settings_type), + : content_setting_image_model_( + ContentSettingImageModel::CreateContentSettingImageModel( + settings_type)), owner_(owner), profile_(profile) { - // TODO(thakis): We should use pdfs for these icons on OSX. - // http://crbug.com/35847 - static const int kIconIDs[] = { - IDR_BLOCKED_COOKIES, - IDR_BLOCKED_IMAGES, - IDR_BLOCKED_JAVASCRIPT, - IDR_BLOCKED_PLUGINS, - IDR_BLOCKED_POPUPS, - }; - DCHECK_EQ(arraysize(kIconIDs), - static_cast<size_t>(CONTENT_SETTINGS_NUM_TYPES)); - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - SetImage(rb.GetNSImageNamed(kIconIDs[settings_type])); - - static const int kTooltipIDs[] = { - IDS_BLOCKED_COOKIES_TITLE, - IDS_BLOCKED_IMAGES_TITLE, - IDS_BLOCKED_JAVASCRIPT_TITLE, - IDS_BLOCKED_PLUGINS_TITLE, - IDS_BLOCKED_POPUPS_TOOLTIP, - }; - DCHECK_EQ(arraysize(kTooltipIDs), - static_cast<size_t>(CONTENT_SETTINGS_NUM_TYPES)); - SetToolTip(l10n_util::GetNSStringWithFixup(kTooltipIDs[settings_type])); -} - -LocationBarViewMac::ContentBlockedImageView::~ContentBlockedImageView() {} - -void LocationBarViewMac::ContentBlockedImageView::OnMousePressed(NSRect bounds) +} + +LocationBarViewMac::ContentSettingImageView::~ContentSettingImageView() {} + +void LocationBarViewMac::ContentSettingImageView::OnMousePressed(NSRect bounds) { // Get host. This should be shared shared on linux/win/osx medium-term. TabContents* tabContents = @@ -880,20 +858,37 @@ void LocationBarViewMac::ContentBlockedImageView::OnMousePressed(NSRect bounds) // Open bubble. NSPoint anchor = NSMakePoint(NSMidX(bounds) + 1, NSMinY(bounds)); - [[ContentBlockedBubbleController showForType:settings_type_ - parentWindow:window - anchoredAt:anchor - host:url.host() - displayHost:base::SysWideToNSString(displayHost) - tabContents:tabContents - profile:profile_] showWindow:nil]; + [[ContentBlockedBubbleController + showForType:content_setting_image_model_->get_content_settings_type() + parentWindow:window + anchoredAt:anchor + host:url.host() + displayHost:base::SysWideToNSString(displayHost) + tabContents:tabContents + profile:profile_] showWindow:nil]; } -const NSString* LocationBarViewMac::ContentBlockedImageView::GetToolTip() { +const NSString* LocationBarViewMac::ContentSettingImageView::GetToolTip() { return tooltip_.get(); } -void LocationBarViewMac::ContentBlockedImageView::SetToolTip(NSString* tooltip) +void LocationBarViewMac::ContentSettingImageView::UpdateFromTabContents( + const TabContents* tab_contents) { + content_setting_image_model_->UpdateFromTabContents(tab_contents); + if (content_setting_image_model_->is_visible()) { + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + // TODO(thakis): We should use pdfs for these icons on OSX. + // http://crbug.com/35847 + SetImage(rb.GetNSImageNamed(content_setting_image_model_->get_icon())); + SetToolTip(base::SysUTF8ToNSString( + content_setting_image_model_->get_tooltip())); + SetVisible(true); + } else { + SetVisible(false); + } +} + +void LocationBarViewMac::ContentSettingImageView::SetToolTip(NSString* tooltip) { tooltip_.reset([tooltip retain]); } |