| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/cocoa/location_bar/location_bar_view_mac.h" | 5 #import "chrome/browser/cocoa/location_bar/location_bar_view_mac.h" |
| 6 | 6 |
| 7 #include "app/l10n_util_mac.h" | 7 #include "app/l10n_util_mac.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/nsimage_cache_mac.h" | 10 #include "base/nsimage_cache_mac.h" |
| 11 #include "base/stl_util-inl.h" | 11 #include "base/stl_util-inl.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/sys_string_conversions.h" | 13 #include "base/sys_string_conversions.h" |
| 14 #include "chrome/app/chrome_dll_resource.h" | 14 #include "chrome/app/chrome_dll_resource.h" |
| 15 #include "chrome/browser/alternate_nav_url_fetcher.h" | 15 #include "chrome/browser/alternate_nav_url_fetcher.h" |
| 16 #import "chrome/browser/app_controller_mac.h" | 16 #import "chrome/browser/app_controller_mac.h" |
| 17 #import "chrome/browser/autocomplete/autocomplete_edit_view_mac.h" | 17 #import "chrome/browser/autocomplete/autocomplete_edit_view_mac.h" |
| 18 #include "chrome/browser/browser_list.h" | 18 #include "chrome/browser/browser_list.h" |
| 19 #import "chrome/browser/cocoa/content_blocked_bubble_controller.h" | 19 #import "chrome/browser/cocoa/content_blocked_bubble_controller.h" |
| 20 #include "chrome/browser/cocoa/event_utils.h" | 20 #include "chrome/browser/cocoa/event_utils.h" |
| 21 #import "chrome/browser/cocoa/extensions/extension_action_context_menu.h" | 21 #import "chrome/browser/cocoa/extensions/extension_action_context_menu.h" |
| 22 #import "chrome/browser/cocoa/extensions/extension_popup_controller.h" | 22 #import "chrome/browser/cocoa/extensions/extension_popup_controller.h" |
| 23 #import "chrome/browser/cocoa/first_run_bubble_controller.h" | 23 #import "chrome/browser/cocoa/first_run_bubble_controller.h" |
| 24 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field.h" | 24 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field.h" |
| 25 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.h" | 25 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.h" |
| 26 #import "chrome/browser/cocoa/location_bar/ev_bubble_decoration.h" | 26 #import "chrome/browser/cocoa/location_bar/ev_bubble_decoration.h" |
| 27 #import "chrome/browser/cocoa/location_bar/location_icon_decoration.h" | 27 #import "chrome/browser/cocoa/location_bar/location_icon_decoration.h" |
| 28 #import "chrome/browser/cocoa/location_bar/selected_keyword_decoration.h" | 28 #import "chrome/browser/cocoa/location_bar/selected_keyword_decoration.h" |
| 29 #import "chrome/browser/cocoa/location_bar/star_decoration.h" |
| 29 #include "chrome/browser/command_updater.h" | 30 #include "chrome/browser/command_updater.h" |
| 30 #include "chrome/browser/content_setting_image_model.h" | 31 #include "chrome/browser/content_setting_image_model.h" |
| 31 #include "chrome/browser/content_setting_bubble_model.h" | 32 #include "chrome/browser/content_setting_bubble_model.h" |
| 32 #include "chrome/browser/extensions/extension_browser_event_router.h" | 33 #include "chrome/browser/extensions/extension_browser_event_router.h" |
| 33 #include "chrome/browser/extensions/extensions_service.h" | 34 #include "chrome/browser/extensions/extensions_service.h" |
| 34 #include "chrome/browser/extensions/extension_tabs_module.h" | 35 #include "chrome/browser/extensions/extension_tabs_module.h" |
| 35 #include "chrome/browser/location_bar_util.h" | 36 #include "chrome/browser/location_bar_util.h" |
| 36 #include "chrome/browser/profile.h" | 37 #include "chrome/browser/profile.h" |
| 37 #include "chrome/browser/search_engines/template_url.h" | 38 #include "chrome/browser/search_engines/template_url.h" |
| 38 #include "chrome/browser/search_engines/template_url_model.h" | 39 #include "chrome/browser/search_engines/template_url_model.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 62 command_updater, field)), | 63 command_updater, field)), |
| 63 command_updater_(command_updater), | 64 command_updater_(command_updater), |
| 64 field_(field), | 65 field_(field), |
| 65 disposition_(CURRENT_TAB), | 66 disposition_(CURRENT_TAB), |
| 66 location_icon_decoration_(new LocationIconDecoration(this)), | 67 location_icon_decoration_(new LocationIconDecoration(this)), |
| 67 selected_keyword_decoration_( | 68 selected_keyword_decoration_( |
| 68 new SelectedKeywordDecoration([field_ font])), | 69 new SelectedKeywordDecoration([field_ font])), |
| 69 ev_bubble_decoration_( | 70 ev_bubble_decoration_( |
| 70 new EVBubbleDecoration(location_icon_decoration_.get(), | 71 new EVBubbleDecoration(location_icon_decoration_.get(), |
| 71 [field_ font])), | 72 [field_ font])), |
| 72 star_icon_view_(command_updater), | 73 star_decoration_(new StarDecoration(command_updater)), |
| 73 page_action_views_(this, profile, toolbar_model), | 74 page_action_views_(this, profile, toolbar_model), |
| 74 profile_(profile), | 75 profile_(profile), |
| 75 browser_(browser), | 76 browser_(browser), |
| 76 toolbar_model_(toolbar_model), | 77 toolbar_model_(toolbar_model), |
| 77 transition_(PageTransition::TYPED), | 78 transition_(PageTransition::TYPED), |
| 78 first_run_bubble_(this) { | 79 first_run_bubble_(this) { |
| 79 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { | 80 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { |
| 80 ContentSettingImageView* content_setting_view = | 81 ContentSettingImageView* content_setting_view = |
| 81 new ContentSettingImageView(static_cast<ContentSettingsType>(i), this, | 82 new ContentSettingImageView(static_cast<ContentSettingsType>(i), this, |
| 82 profile_); | 83 profile_); |
| 83 content_setting_views_.push_back(content_setting_view); | 84 content_setting_views_.push_back(content_setting_view); |
| 84 content_setting_view->SetVisible(false); | 85 content_setting_view->SetVisible(false); |
| 85 } | 86 } |
| 86 | 87 |
| 87 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell]; | 88 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell]; |
| 88 [cell setStarIconView:&star_icon_view_]; | |
| 89 [cell setPageActionViewList:&page_action_views_]; | 89 [cell setPageActionViewList:&page_action_views_]; |
| 90 [cell setContentSettingViewsList:&content_setting_views_]; | 90 [cell setContentSettingViewsList:&content_setting_views_]; |
| 91 | 91 |
| 92 registrar_.Add(this, | 92 registrar_.Add(this, |
| 93 NotificationType::EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, | 93 NotificationType::EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, |
| 94 NotificationService::AllSources()); | 94 NotificationService::AllSources()); |
| 95 } | 95 } |
| 96 | 96 |
| 97 LocationBarViewMac::~LocationBarViewMac() { | 97 LocationBarViewMac::~LocationBarViewMac() { |
| 98 // Disconnect from cell in case it outlives us. | 98 // Disconnect from cell in case it outlives us. |
| 99 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell]; | 99 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell]; |
| 100 [cell setPageActionViewList:NULL]; | 100 [cell setPageActionViewList:NULL]; |
| 101 [cell setStarIconView:NULL]; | 101 [cell clearDecorations]; |
| 102 } | 102 } |
| 103 | 103 |
| 104 void LocationBarViewMac::ShowFirstRunBubble(FirstRun::BubbleType bubble_type) { | 104 void LocationBarViewMac::ShowFirstRunBubble(FirstRun::BubbleType bubble_type) { |
| 105 // We need the browser window to be shown before we can show the bubble, but | 105 // We need the browser window to be shown before we can show the bubble, but |
| 106 // we get called before that's happened. | 106 // we get called before that's happened. |
| 107 Task* task = first_run_bubble_.NewRunnableMethod( | 107 Task* task = first_run_bubble_.NewRunnableMethod( |
| 108 &LocationBarViewMac::ShowFirstRunBubbleInternal, bubble_type); | 108 &LocationBarViewMac::ShowFirstRunBubbleInternal, bubble_type); |
| 109 MessageLoop::current()->PostTask(FROM_HERE, task); | 109 MessageLoop::current()->PostTask(FROM_HERE, task); |
| 110 } | 110 } |
| 111 | 111 |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 void LocationBarViewMac::TestPageActionPressed(size_t index) { | 349 void LocationBarViewMac::TestPageActionPressed(size_t index) { |
| 350 if (index >= page_action_views_.Count()) { | 350 if (index >= page_action_views_.Count()) { |
| 351 NOTREACHED(); | 351 NOTREACHED(); |
| 352 return; | 352 return; |
| 353 } | 353 } |
| 354 page_action_views_.OnMousePressed(NSZeroRect, index); | 354 page_action_views_.OnMousePressed(NSZeroRect, index); |
| 355 } | 355 } |
| 356 | 356 |
| 357 void LocationBarViewMac::SetEditable(bool editable) { | 357 void LocationBarViewMac::SetEditable(bool editable) { |
| 358 [field_ setEditable:editable ? YES : NO]; | 358 [field_ setEditable:editable ? YES : NO]; |
| 359 star_icon_view_.SetVisible(editable); | 359 star_decoration_->SetVisible(editable); |
| 360 UpdatePageActions(); | 360 UpdatePageActions(); |
| 361 Layout(); | 361 Layout(); |
| 362 } | 362 } |
| 363 | 363 |
| 364 bool LocationBarViewMac::IsEditable() { | 364 bool LocationBarViewMac::IsEditable() { |
| 365 return [field_ isEditable] ? true : false; | 365 return [field_ isEditable] ? true : false; |
| 366 } | 366 } |
| 367 | 367 |
| 368 void LocationBarViewMac::SetStarred(bool starred) { | 368 void LocationBarViewMac::SetStarred(bool starred) { |
| 369 star_icon_view_.SetStarred(starred); | 369 star_decoration_->SetStarred(starred); |
| 370 | 370 |
| 371 // TODO(shess): The field-editor frame and cursor rects should not | 371 // TODO(shess): The field-editor frame and cursor rects should not |
| 372 // change, here. | 372 // change, here. |
| 373 [field_ updateCursorAndToolTipRects]; | 373 [field_ updateCursorAndToolTipRects]; |
| 374 [field_ resetFieldEditorFrameIfNeeded]; | 374 [field_ resetFieldEditorFrameIfNeeded]; |
| 375 [field_ setNeedsDisplay:YES]; | 375 [field_ setNeedsDisplay:YES]; |
| 376 } | 376 } |
| 377 | 377 |
| 378 NSPoint LocationBarViewMac::GetBookmarkBubblePoint() const { | 378 NSPoint LocationBarViewMac::GetBookmarkBubblePoint() const { |
| 379 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell]; | 379 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell]; |
| 380 NSRect frame = [cell starIconFrameForFrame:[field_ bounds]]; | 380 const NSRect frame = [cell frameForDecoration:star_decoration_.get() |
| 381 frame = [field_ convertRect:frame toView:nil]; | 381 inFrame:[field_ bounds]]; |
| 382 | 382 const NSPoint point = star_decoration_->GetBubblePointInFrame(frame); |
| 383 // Star is not exactly centered horizontally, and the tip should | 383 return [field_ convertPoint:point toView:nil]; |
| 384 // point to the visual bottom of the star, not the middle. | |
| 385 return NSMakePoint(NSMidX(frame), NSMinY(frame) + 4.0); | |
| 386 } | 384 } |
| 387 | 385 |
| 388 NSImage* LocationBarViewMac::GetTabButtonImage() { | 386 NSImage* LocationBarViewMac::GetTabButtonImage() { |
| 389 if (!tab_button_image_) { | 387 if (!tab_button_image_) { |
| 390 SkBitmap* skiaBitmap = ResourceBundle::GetSharedInstance(). | 388 SkBitmap* skiaBitmap = ResourceBundle::GetSharedInstance(). |
| 391 GetBitmapNamed(IDR_LOCATION_BAR_KEYWORD_HINT_TAB); | 389 GetBitmapNamed(IDR_LOCATION_BAR_KEYWORD_HINT_TAB); |
| 392 if (skiaBitmap) { | 390 if (skiaBitmap) { |
| 393 tab_button_image_.reset([gfx::SkBitmapToNSImage(*skiaBitmap) retain]); | 391 tab_button_image_.reset([gfx::SkBitmapToNSImage(*skiaBitmap) retain]); |
| 394 } | 392 } |
| 395 } | 393 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 return NSZeroSize; | 468 return NSZeroSize; |
| 471 } | 469 } |
| 472 | 470 |
| 473 NSSize LocationBarViewMac::LocationBarImageView::GetImageSize() const { | 471 NSSize LocationBarViewMac::LocationBarImageView::GetImageSize() const { |
| 474 NSImage* image = GetImage(); | 472 NSImage* image = GetImage(); |
| 475 if (image) | 473 if (image) |
| 476 return [image size]; | 474 return [image size]; |
| 477 return GetDefaultImageSize(); | 475 return GetDefaultImageSize(); |
| 478 } | 476 } |
| 479 | 477 |
| 480 // StarIconView----------------------------------------------------------------- | |
| 481 | |
| 482 LocationBarViewMac::StarIconView::StarIconView(CommandUpdater* command_updater) | |
| 483 : command_updater_(command_updater) { | |
| 484 SetVisible(true); | |
| 485 SetStarred(false); | |
| 486 } | |
| 487 | |
| 488 void LocationBarViewMac::StarIconView::SetStarred(bool starred) { | |
| 489 if (starred) { | |
| 490 SetImage(AutocompleteEditViewMac::ImageForResource(IDR_OMNIBOX_STAR_LIT)); | |
| 491 tooltip_.reset( | |
| 492 [l10n_util::GetNSStringWithFixup(IDS_TOOLTIP_STARRED) retain]); | |
| 493 } else { | |
| 494 SetImage(AutocompleteEditViewMac::ImageForResource(IDR_OMNIBOX_STAR)); | |
| 495 tooltip_.reset( | |
| 496 [l10n_util::GetNSStringWithFixup(IDS_TOOLTIP_STAR) retain]); | |
| 497 } | |
| 498 } | |
| 499 | |
| 500 void LocationBarViewMac::StarIconView::OnMousePressed(NSRect bounds) { | |
| 501 command_updater_->ExecuteCommand(IDC_BOOKMARK_PAGE); | |
| 502 } | |
| 503 | |
| 504 NSString* LocationBarViewMac::StarIconView::GetToolTip() { | |
| 505 return tooltip_.get(); | |
| 506 } | |
| 507 | |
| 508 // PageActionImageView---------------------------------------------------------- | 478 // PageActionImageView---------------------------------------------------------- |
| 509 | 479 |
| 510 LocationBarViewMac::PageActionImageView::PageActionImageView( | 480 LocationBarViewMac::PageActionImageView::PageActionImageView( |
| 511 LocationBarViewMac* owner, | 481 LocationBarViewMac* owner, |
| 512 Profile* profile, | 482 Profile* profile, |
| 513 ExtensionAction* page_action) | 483 ExtensionAction* page_action) |
| 514 : owner_(owner), | 484 : owner_(owner), |
| 515 profile_(profile), | 485 profile_(profile), |
| 516 page_action_(page_action), | 486 page_action_(page_action), |
| 517 tracker_(this), | 487 tracker_(this), |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell]; | 825 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell]; |
| 856 | 826 |
| 857 // Reset the left-hand decorations. | 827 // Reset the left-hand decorations. |
| 858 // TODO(shess): Shortly, this code will live somewhere else, like in | 828 // TODO(shess): Shortly, this code will live somewhere else, like in |
| 859 // the constructor. I am still wrestling with how best to deal with | 829 // the constructor. I am still wrestling with how best to deal with |
| 860 // right-hand decorations, which are not a static set. | 830 // right-hand decorations, which are not a static set. |
| 861 [cell clearDecorations]; | 831 [cell clearDecorations]; |
| 862 [cell addLeftDecoration:location_icon_decoration_.get()]; | 832 [cell addLeftDecoration:location_icon_decoration_.get()]; |
| 863 [cell addLeftDecoration:selected_keyword_decoration_.get()]; | 833 [cell addLeftDecoration:selected_keyword_decoration_.get()]; |
| 864 [cell addLeftDecoration:ev_bubble_decoration_.get()]; | 834 [cell addLeftDecoration:ev_bubble_decoration_.get()]; |
| 835 [cell addRightDecoration:star_decoration_.get()]; |
| 865 | 836 |
| 866 // By default only the location icon is visible. | 837 // By default only the location icon is visible. |
| 867 location_icon_decoration_->SetVisible(true); | 838 location_icon_decoration_->SetVisible(true); |
| 868 selected_keyword_decoration_->SetVisible(false); | 839 selected_keyword_decoration_->SetVisible(false); |
| 869 ev_bubble_decoration_->SetVisible(false); | 840 ev_bubble_decoration_->SetVisible(false); |
| 870 | 841 |
| 871 // Get the keyword to use for keyword-search and hinting. | 842 // Get the keyword to use for keyword-search and hinting. |
| 872 const std::wstring keyword(edit_view_->model()->keyword()); | 843 const std::wstring keyword(edit_view_->model()->keyword()); |
| 873 std::wstring short_name; | 844 std::wstring short_name; |
| 874 bool is_extension_keyword = false; | 845 bool is_extension_keyword = false; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 | 902 |
| 932 // These need to change anytime the layout changes. | 903 // These need to change anytime the layout changes. |
| 933 // TODO(shess): Anytime the field editor might have changed, the | 904 // TODO(shess): Anytime the field editor might have changed, the |
| 934 // cursor rects almost certainly should have changed. The tooltips | 905 // cursor rects almost certainly should have changed. The tooltips |
| 935 // might change even when the rects don't change. | 906 // might change even when the rects don't change. |
| 936 [field_ resetFieldEditorFrameIfNeeded]; | 907 [field_ resetFieldEditorFrameIfNeeded]; |
| 937 [field_ updateCursorAndToolTipRects]; | 908 [field_ updateCursorAndToolTipRects]; |
| 938 | 909 |
| 939 [field_ setNeedsDisplay:YES]; | 910 [field_ setNeedsDisplay:YES]; |
| 940 } | 911 } |
| OLD | NEW |