diff options
-rw-r--r-- | chrome/browser/cocoa/autocomplete_text_field_cell.mm | 17 | ||||
-rw-r--r-- | chrome/browser/cocoa/location_bar_view_mac.h | 9 | ||||
-rw-r--r-- | chrome/browser/cocoa/location_bar_view_mac.mm | 11 |
3 files changed, 19 insertions, 18 deletions
diff --git a/chrome/browser/cocoa/autocomplete_text_field_cell.mm b/chrome/browser/cocoa/autocomplete_text_field_cell.mm index 2b5600a..4b719a1 100644 --- a/chrome/browser/cocoa/autocomplete_text_field_cell.mm +++ b/chrome/browser/cocoa/autocomplete_text_field_cell.mm @@ -304,13 +304,11 @@ CGFloat WidthForKeyword(NSAttributedString* keywordString) { LocationBarViewMac::PageActionImageView* view = page_action_views_->ViewAt(index); - // If we are calculating space for a preview page action, the icon is still - // loading. We use this function only to get the correct x value for the - // extension installed bubble arrow. - if (!view->preview_enabled() && - (!view->GetImage() || !view->IsVisible())) { + // When this method is called, all the icon images are still loading, so + // just check to see whether the view is visible when deciding whether + // its NSRect should be made available. + if (!view->preview_enabled() && !view->IsVisible()) return NSZeroRect; - } for (AutocompleteTextFieldIcon* icon in [self layedOutIcons:cellFrame]) { if (view == [icon view]) @@ -418,8 +416,11 @@ CGFloat WidthForKeyword(NSAttributedString* keywordString) { for (size_t i = 0; i < pageActionCount; ++i) { LocationBarViewMac::PageActionImageView* view = page_action_views_->ViewAt(i); - if (view->preview_enabled() || (view->GetImage() && view->IsVisible())) { - NSSize iconSize = view->GetImageSize(); + if (view->preview_enabled() || view->IsVisible()) { + // If this function is called right after a page action icon has been + // created, the images for all views will still be loading; in this case, + // each visible view will give us its default size. + NSSize iconSize = view->GetPreferredImageSize(); NSRect pageActionFrame = [self rightJustifyImage:iconSize inRect:iconFrame diff --git a/chrome/browser/cocoa/location_bar_view_mac.h b/chrome/browser/cocoa/location_bar_view_mac.h index 9f376e6..393acf3 100644 --- a/chrome/browser/cocoa/location_bar_view_mac.h +++ b/chrome/browser/cocoa/location_bar_view_mac.h @@ -230,9 +230,12 @@ class LocationBarViewMac : public AutocompleteEditController, bool preview_enabled() { return preview_enabled_; } - // Return the size of the image, or a default size if no image available - // and preview is enabled. - virtual NSSize GetImageSize(); + // Returns the size of the image, or a default size if no image available. + // When a new page action is created, all the icons are destroyed and + // recreated; at this point we need to calculate sizes to lay out the + // icons even though no images are available yet. For this case, we return + // the default image size for a page icon. + virtual NSSize GetPreferredImageSize(); // Either notify listeners or show a popup depending on the Page Action. virtual void OnMousePressed(NSRect bounds); diff --git a/chrome/browser/cocoa/location_bar_view_mac.mm b/chrome/browser/cocoa/location_bar_view_mac.mm index bbd30c1..032443f 100644 --- a/chrome/browser/cocoa/location_bar_view_mac.mm +++ b/chrome/browser/cocoa/location_bar_view_mac.mm @@ -646,17 +646,14 @@ LocationBarViewMac::PageActionImageView::~PageActionImageView() { tracker_->StopTrackingImageLoad(); } -NSSize LocationBarViewMac::PageActionImageView::GetImageSize() { +NSSize LocationBarViewMac::PageActionImageView::GetPreferredImageSize() { NSImage* image = GetImage(); - if (preview_enabled_ && !image) { + if (image) { + return [image size]; + } else { return NSMakeSize(Extension::kPageActionIconMaxSize, Extension::kPageActionIconMaxSize); - } else if (image) { - return [image size]; } - // Default value for image size is undefined when preview is not enabled. - NOTREACHED(); - return NSMakeSize(0, 0); } // Overridden from LocationBarImageView. Either notify listeners or show a |