Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(609)

Side by Side Diff: chrome/browser/cocoa/location_bar_view_mac.mm

Issue 1540009: [Mac] Move star button into page-actions area of omnibox. (Closed)
Patch Set: Why did the trybot fail? I can't see anything. Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/cocoa/location_bar_view_mac.h ('k') | chrome/browser/cocoa/toolbar_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_view_mac.h" 5 #import "chrome/browser/cocoa/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"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 ToolbarModel* toolbar_model, 98 ToolbarModel* toolbar_model,
99 Profile* profile, 99 Profile* profile,
100 Browser* browser) 100 Browser* browser)
101 : edit_view_(new AutocompleteEditViewMac(this, bubble_positioner, 101 : edit_view_(new AutocompleteEditViewMac(this, bubble_positioner,
102 toolbar_model, profile, command_updater, field)), 102 toolbar_model, profile, command_updater, field)),
103 command_updater_(command_updater), 103 command_updater_(command_updater),
104 field_(field), 104 field_(field),
105 disposition_(CURRENT_TAB), 105 disposition_(CURRENT_TAB),
106 location_icon_view_(this), 106 location_icon_view_(this),
107 security_label_view_(), 107 security_label_view_(),
108 star_icon_view_(command_updater),
108 page_action_views_(this, profile, toolbar_model), 109 page_action_views_(this, profile, toolbar_model),
109 profile_(profile), 110 profile_(profile),
110 browser_(browser), 111 browser_(browser),
111 toolbar_model_(toolbar_model), 112 toolbar_model_(toolbar_model),
112 transition_(PageTransition::TYPED) { 113 transition_(PageTransition::TYPED) {
113 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { 114 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) {
114 ContentSettingImageView* content_setting_view = 115 ContentSettingImageView* content_setting_view =
115 new ContentSettingImageView(static_cast<ContentSettingsType>(i), this, 116 new ContentSettingImageView(static_cast<ContentSettingsType>(i), this,
116 profile_); 117 profile_);
117 content_setting_views_.push_back(content_setting_view); 118 content_setting_views_.push_back(content_setting_view);
118 content_setting_view->SetVisible(false); 119 content_setting_view->SetVisible(false);
119 } 120 }
120 121
121 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell]; 122 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell];
122 [cell setLocationIconView:&location_icon_view_]; 123 [cell setLocationIconView:&location_icon_view_];
123 [cell setSecurityLabelView:&security_label_view_]; 124 [cell setSecurityLabelView:&security_label_view_];
125 [cell setStarIconView:&star_icon_view_];
124 [cell setPageActionViewList:&page_action_views_]; 126 [cell setPageActionViewList:&page_action_views_];
125 [cell setContentSettingViewsList:&content_setting_views_]; 127 [cell setContentSettingViewsList:&content_setting_views_];
126 128
127 registrar_.Add(this, 129 registrar_.Add(this,
128 NotificationType::EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, 130 NotificationType::EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED,
129 NotificationService::AllSources()); 131 NotificationService::AllSources());
130 } 132 }
131 133
132 LocationBarViewMac::~LocationBarViewMac() { 134 LocationBarViewMac::~LocationBarViewMac() {
133 // Disconnect from cell in case it outlives us. 135 // Disconnect from cell in case it outlives us.
134 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell]; 136 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell];
135 [cell setPageActionViewList:NULL]; 137 [cell setPageActionViewList:NULL];
136 [cell setLocationIconView:NULL]; 138 [cell setLocationIconView:NULL];
137 [cell setSecurityLabelView:NULL]; 139 [cell setSecurityLabelView:NULL];
140 [cell setStarIconView:NULL];
138 } 141 }
139 142
140 std::wstring LocationBarViewMac::GetInputString() const { 143 std::wstring LocationBarViewMac::GetInputString() const {
141 return location_input_; 144 return location_input_;
142 } 145 }
143 146
144 WindowOpenDisposition LocationBarViewMac::GetWindowOpenDisposition() const { 147 WindowOpenDisposition LocationBarViewMac::GetWindowOpenDisposition() const {
145 return disposition_; 148 return disposition_;
146 } 149 }
147 150
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 } 445 }
443 446
444 void LocationBarViewMac::TestPageActionPressed(size_t index) { 447 void LocationBarViewMac::TestPageActionPressed(size_t index) {
445 if (index >= page_action_views_.Count()) { 448 if (index >= page_action_views_.Count()) {
446 NOTREACHED(); 449 NOTREACHED();
447 return; 450 return;
448 } 451 }
449 page_action_views_.OnMousePressed(NSZeroRect, index); 452 page_action_views_.OnMousePressed(NSZeroRect, index);
450 } 453 }
451 454
455 void LocationBarViewMac::SetStarred(bool starred) {
456 star_icon_view_.SetStarred(starred);
457 [field_ updateCursorAndToolTipRects];
458 [field_ resetFieldEditorFrameIfNeeded];
459 }
460
452 NSImage* LocationBarViewMac::GetTabButtonImage() { 461 NSImage* LocationBarViewMac::GetTabButtonImage() {
453 if (!tab_button_image_) { 462 if (!tab_button_image_) {
454 SkBitmap* skiaBitmap = ResourceBundle::GetSharedInstance(). 463 SkBitmap* skiaBitmap = ResourceBundle::GetSharedInstance().
455 GetBitmapNamed(IDR_LOCATION_BAR_KEYWORD_HINT_TAB); 464 GetBitmapNamed(IDR_LOCATION_BAR_KEYWORD_HINT_TAB);
456 if (skiaBitmap) { 465 if (skiaBitmap) {
457 tab_button_image_.reset([gfx::SkBitmapToNSImage(*skiaBitmap) retain]); 466 tab_button_image_.reset([gfx::SkBitmapToNSImage(*skiaBitmap) retain]);
458 } 467 }
459 } 468 }
460 return tab_button_image_; 469 return tab_button_image_;
461 } 470 }
462 471
463 void LocationBarViewMac::SetIcon(int resource_id) { 472 void LocationBarViewMac::SetIcon(int resource_id) {
464 DCHECK(resource_id != 0); 473 DCHECK(resource_id != 0);
465 474
466 // The icon is always visible except when there is a keyword hint. 475 // The icon is always visible except when there is a keyword hint.
467 if (!edit_view_->model()->keyword().empty() && 476 if (!edit_view_->model()->keyword().empty() &&
468 !edit_view_->model()->is_keyword_hint()) { 477 !edit_view_->model()->is_keyword_hint()) {
469 location_icon_view_.SetVisible(false); 478 location_icon_view_.SetVisible(false);
470 } else { 479 } else {
471 location_icon_view_.SetImage( 480 location_icon_view_.SetIcon(resource_id);
472 ResourceBundle::GetSharedInstance().GetNSImageNamed(resource_id));
473 location_icon_view_.SetVisible(true); 481 location_icon_view_.SetVisible(true);
474 SetSecurityLabel(); 482 SetSecurityLabel();
475 } 483 }
476 [field_ resetFieldEditorFrameIfNeeded]; 484 [field_ resetFieldEditorFrameIfNeeded];
477 } 485 }
478 486
479 void LocationBarViewMac::SetSecurityLabel() { 487 void LocationBarViewMac::SetSecurityLabel() {
480 std::wstring security_info_text(toolbar_model_->GetSecurityInfoText()); 488 std::wstring security_info_text(toolbar_model_->GetSecurityInfoText());
481 if (security_info_text.empty()) { 489 if (security_info_text.empty()) {
482 security_label_view_.SetLabel(nil, nil, nil); 490 security_label_view_.SetLabel(nil, nil, nil);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 toolbar_model_->input_in_progress() ? NULL : tab_contents); 542 toolbar_model_->input_in_progress() ? NULL : tab_contents);
535 } 543 }
536 } 544 }
537 545
538 // LocationBarImageView--------------------------------------------------------- 546 // LocationBarImageView---------------------------------------------------------
539 547
540 void LocationBarViewMac::LocationBarImageView::SetImage(NSImage* image) { 548 void LocationBarViewMac::LocationBarImageView::SetImage(NSImage* image) {
541 image_.reset([image retain]); 549 image_.reset([image retain]);
542 } 550 }
543 551
544 void LocationBarViewMac::LocationBarImageView::SetImage(SkBitmap* image) { 552 void LocationBarViewMac::LocationBarImageView::SetIcon(int resource_id) {
545 SetImage(gfx::SkBitmapToNSImage(*image)); 553 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
554 SetImage(rb.GetNSImageNamed(resource_id));
546 } 555 }
547 556
548 void LocationBarViewMac::LocationBarImageView::SetLabel(NSString* text, 557 void LocationBarViewMac::LocationBarImageView::SetLabel(NSString* text,
549 NSFont* baseFont, 558 NSFont* baseFont,
550 NSColor* color) { 559 NSColor* color) {
551 // Create an attributed string for the label, if a label was given. 560 // Create an attributed string for the label, if a label was given.
552 label_.reset(); 561 label_.reset();
553 if (text) { 562 if (text) {
554 DCHECK(color); 563 DCHECK(color);
555 DCHECK(baseFont); 564 DCHECK(baseFont);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 void LocationBarViewMac::LocationIconView::OnMousePressed(NSRect bounds) { 602 void LocationBarViewMac::LocationIconView::OnMousePressed(NSRect bounds) {
594 TabContents* tab = owner_->GetTabContents(); 603 TabContents* tab = owner_->GetTabContents();
595 NavigationEntry* nav_entry = tab->controller().GetActiveEntry(); 604 NavigationEntry* nav_entry = tab->controller().GetActiveEntry();
596 if (!nav_entry) { 605 if (!nav_entry) {
597 NOTREACHED(); 606 NOTREACHED();
598 return; 607 return;
599 } 608 }
600 tab->ShowPageInfo(nav_entry->url(), nav_entry->ssl(), true); 609 tab->ShowPageInfo(nav_entry->url(), nav_entry->ssl(), true);
601 } 610 }
602 611
612 // StarIconView-----------------------------------------------------------------
613
614 LocationBarViewMac::StarIconView::StarIconView(CommandUpdater* command_updater)
615 : command_updater_(command_updater) {
616 SetVisible(true);
617 SetStarred(false);
618 }
619
620 void LocationBarViewMac::StarIconView::SetStarred(bool starred) {
621 if (starred) {
622 SetIcon(IDR_STARRED_NOBORDER_CENTER);
623 tooltip_.reset(
624 [l10n_util::GetNSStringWithFixup(IDS_TOOLTIP_STARRED) retain]);
625 } else {
626 SetIcon(IDR_STAR_NOBORDER_CENTER);
627 tooltip_.reset(
628 [l10n_util::GetNSStringWithFixup(IDS_TOOLTIP_STAR) retain]);
629 }
630 }
631
632 void LocationBarViewMac::StarIconView::OnMousePressed(NSRect bounds) {
633 command_updater_->ExecuteCommand(IDC_BOOKMARK_PAGE);
634 }
635
636 const NSString* LocationBarViewMac::StarIconView::GetToolTip() {
637 return tooltip_.get();
638 }
639
603 // PageActionImageView---------------------------------------------------------- 640 // PageActionImageView----------------------------------------------------------
604 641
605 LocationBarViewMac::PageActionImageView::PageActionImageView( 642 LocationBarViewMac::PageActionImageView::PageActionImageView(
606 LocationBarViewMac* owner, 643 LocationBarViewMac* owner,
607 Profile* profile, 644 Profile* profile,
608 ExtensionAction* page_action) 645 ExtensionAction* page_action)
609 : owner_(owner), 646 : owner_(owner),
610 profile_(profile), 647 profile_(profile),
611 page_action_(page_action), 648 page_action_(page_action),
612 tracker_(this), 649 tracker_(this),
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 } 883 }
847 884
848 const NSString* LocationBarViewMac::ContentSettingImageView::GetToolTip() { 885 const NSString* LocationBarViewMac::ContentSettingImageView::GetToolTip() {
849 return tooltip_.get(); 886 return tooltip_.get();
850 } 887 }
851 888
852 void LocationBarViewMac::ContentSettingImageView::UpdateFromTabContents( 889 void LocationBarViewMac::ContentSettingImageView::UpdateFromTabContents(
853 const TabContents* tab_contents) { 890 const TabContents* tab_contents) {
854 content_setting_image_model_->UpdateFromTabContents(tab_contents); 891 content_setting_image_model_->UpdateFromTabContents(tab_contents);
855 if (content_setting_image_model_->is_visible()) { 892 if (content_setting_image_model_->is_visible()) {
856 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
857 // TODO(thakis): We should use pdfs for these icons on OSX. 893 // TODO(thakis): We should use pdfs for these icons on OSX.
858 // http://crbug.com/35847 894 // http://crbug.com/35847
859 SetImage(rb.GetNSImageNamed(content_setting_image_model_->get_icon())); 895 SetIcon(content_setting_image_model_->get_icon());
860 SetToolTip(base::SysUTF8ToNSString( 896 SetToolTip(base::SysUTF8ToNSString(
861 content_setting_image_model_->get_tooltip())); 897 content_setting_image_model_->get_tooltip()));
862 SetVisible(true); 898 SetVisible(true);
863 } else { 899 } else {
864 SetVisible(false); 900 SetVisible(false);
865 } 901 }
866 } 902 }
867 903
868 void LocationBarViewMac::ContentSettingImageView::SetToolTip(NSString* tooltip) 904 void LocationBarViewMac::ContentSettingImageView::SetToolTip(NSString* tooltip)
869 { 905 {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 ++result; 968 ++result;
933 } 969 }
934 return result; 970 return result;
935 } 971 }
936 972
937 void LocationBarViewMac::PageActionViewList::OnMousePressed(NSRect iconFrame, 973 void LocationBarViewMac::PageActionViewList::OnMousePressed(NSRect iconFrame,
938 size_t index) { 974 size_t index) {
939 ViewAt(index)->OnMousePressed(iconFrame); 975 ViewAt(index)->OnMousePressed(iconFrame);
940 } 976 }
941 977
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/location_bar_view_mac.h ('k') | chrome/browser/cocoa/toolbar_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698