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

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

Issue 11418043: Remove TabContents from OmniboxEditController and friends. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cros Created 8 years, 1 month 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 | Annotate | Revision Log
OLDNEW
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/location_bar/location_bar_view_mac.h" 5 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 10 matching lines...) Expand all
21 #include "chrome/browser/extensions/extension_service.h" 21 #include "chrome/browser/extensions/extension_service.h"
22 #include "chrome/browser/extensions/location_bar_controller.h" 22 #include "chrome/browser/extensions/location_bar_controller.h"
23 #include "chrome/browser/extensions/tab_helper.h" 23 #include "chrome/browser/extensions/tab_helper.h"
24 #include "chrome/browser/prefs/pref_service.h" 24 #include "chrome/browser/prefs/pref_service.h"
25 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/browser/search_engines/template_url.h" 26 #include "chrome/browser/search_engines/template_url.h"
27 #include "chrome/browser/search_engines/template_url_service.h" 27 #include "chrome/browser/search_engines/template_url_service.h"
28 #include "chrome/browser/search_engines/template_url_service_factory.h" 28 #include "chrome/browser/search_engines/template_url_service_factory.h"
29 #include "chrome/browser/ui/browser_instant_controller.h" 29 #include "chrome/browser/ui/browser_instant_controller.h"
30 #include "chrome/browser/ui/browser_list.h" 30 #include "chrome/browser/ui/browser_list.h"
31 #include "chrome/browser/ui/browser_tabstrip.h"
32 #import "chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.h " 31 #import "chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.h "
33 #include "chrome/browser/ui/cocoa/event_utils.h" 32 #include "chrome/browser/ui/cocoa/event_utils.h"
34 #import "chrome/browser/ui/cocoa/extensions/extension_action_context_menu.h" 33 #import "chrome/browser/ui/cocoa/extensions/extension_action_context_menu.h"
35 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" 34 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h"
36 #import "chrome/browser/ui/cocoa/first_run_bubble_controller.h" 35 #import "chrome/browser/ui/cocoa/first_run_bubble_controller.h"
37 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" 36 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h"
38 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" 37 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h"
39 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h" 38 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h"
40 #import "chrome/browser/ui/cocoa/location_bar/ev_bubble_decoration.h" 39 #import "chrome/browser/ui/cocoa/location_bar/ev_bubble_decoration.h"
41 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h" 40 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h"
42 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h" 41 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h"
43 #import "chrome/browser/ui/cocoa/location_bar/page_action_decoration.h" 42 #import "chrome/browser/ui/cocoa/location_bar/page_action_decoration.h"
44 #import "chrome/browser/ui/cocoa/location_bar/plus_decoration.h" 43 #import "chrome/browser/ui/cocoa/location_bar/plus_decoration.h"
45 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h" 44 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h"
46 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" 45 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h"
47 #import "chrome/browser/ui/cocoa/location_bar/web_intents_button_decoration.h" 46 #import "chrome/browser/ui/cocoa/location_bar/web_intents_button_decoration.h"
48 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h" 47 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h"
49 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" 48 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h"
50 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" 49 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
51 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" 50 #include "chrome/browser/ui/content_settings/content_setting_image_model.h"
52 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" 51 #include "chrome/browser/ui/intents/web_intent_picker_controller.h"
53 #include "chrome/browser/ui/omnibox/location_bar_util.h" 52 #include "chrome/browser/ui/omnibox/location_bar_util.h"
54 #import "chrome/browser/ui/omnibox/omnibox_popup_model.h" 53 #import "chrome/browser/ui/omnibox/omnibox_popup_model.h"
55 #include "chrome/browser/ui/tab_contents/tab_contents.h" 54 #include "chrome/browser/ui/tab_contents/tab_contents.h"
55 #include "chrome/browser/ui/tabs/tab_strip_model.h"
56 #include "chrome/browser/ui/zoom/zoom_controller.h" 56 #include "chrome/browser/ui/zoom/zoom_controller.h"
57 #include "chrome/common/chrome_notification_types.h" 57 #include "chrome/common/chrome_notification_types.h"
58 #include "chrome/common/chrome_switches.h" 58 #include "chrome/common/chrome_switches.h"
59 #include "chrome/common/extensions/extension.h" 59 #include "chrome/common/extensions/extension.h"
60 #include "chrome/common/extensions/extension_resource.h" 60 #include "chrome/common/extensions/extension_resource.h"
61 #include "chrome/common/extensions/feature_switch.h" 61 #include "chrome/common/extensions/feature_switch.h"
62 #include "chrome/common/pref_names.h" 62 #include "chrome/common/pref_names.h"
63 #include "content/public/browser/notification_service.h" 63 #include "content/public/browser/notification_service.h"
64 #include "content/public/browser/web_contents.h" 64 #include "content/public/browser/web_contents.h"
65 #include "grit/generated_resources.h" 65 #include "grit/generated_resources.h"
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 } 331 }
332 332
333 string16 LocationBarViewMac::GetTitle() const { 333 string16 LocationBarViewMac::GetTitle() const {
334 return browser_->GetWindowTitleForCurrentTab(); 334 return browser_->GetWindowTitleForCurrentTab();
335 } 335 }
336 336
337 InstantController* LocationBarViewMac::GetInstant() { 337 InstantController* LocationBarViewMac::GetInstant() {
338 return browser_->instant_controller()->instant(); 338 return browser_->instant_controller()->instant();
339 } 339 }
340 340
341 TabContents* LocationBarViewMac::GetTabContents() const {
342 return chrome::GetActiveTabContents(browser_);
343 }
344
345 void LocationBarViewMac::Revert() { 341 void LocationBarViewMac::Revert() {
346 omnibox_view_->RevertAll(); 342 omnibox_view_->RevertAll();
347 } 343 }
348 344
349 const OmniboxView* LocationBarViewMac::GetLocationEntry() const { 345 const OmniboxView* LocationBarViewMac::GetLocationEntry() const {
350 return omnibox_view_.get(); 346 return omnibox_view_.get();
351 } 347 }
352 348
353 OmniboxView* LocationBarViewMac::GetLocationEntry() { 349 OmniboxView* LocationBarViewMac::GetLocationEntry() {
354 return omnibox_view_.get(); 350 return omnibox_view_.get();
(...skipping 11 matching lines...) Expand all
366 int LocationBarViewMac::PageActionVisibleCount() { 362 int LocationBarViewMac::PageActionVisibleCount() {
367 int result = 0; 363 int result = 0;
368 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { 364 for (size_t i = 0; i < page_action_decorations_.size(); ++i) {
369 if (page_action_decorations_[i]->IsVisible()) 365 if (page_action_decorations_[i]->IsVisible())
370 ++result; 366 ++result;
371 } 367 }
372 return result; 368 return result;
373 } 369 }
374 370
375 WebContents* LocationBarViewMac::GetWebContents() const { 371 WebContents* LocationBarViewMac::GetWebContents() const {
376 return chrome::GetActiveWebContents(browser_); 372 return browser_->tab_strip_model()->GetActiveWebContents();
377 } 373 }
378 374
379 PageActionDecoration* LocationBarViewMac::GetPageActionDecoration( 375 PageActionDecoration* LocationBarViewMac::GetPageActionDecoration(
380 ExtensionAction* page_action) { 376 ExtensionAction* page_action) {
381 DCHECK(page_action); 377 DCHECK(page_action);
382 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { 378 for (size_t i = 0; i < page_action_decorations_.size(); ++i) {
383 if (page_action_decorations_[i]->page_action() == page_action) 379 if (page_action_decorations_[i]->page_action() == page_action)
384 return page_action_decorations_[i]; 380 return page_action_decorations_[i];
385 } 381 }
386 // If |page_action| is the browser action of an extension, no element in 382 // If |page_action| is the browser action of an extension, no element in
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 return; 577 return;
582 578
583 [field_ updateMouseTracking]; 579 [field_ updateMouseTracking];
584 [field_ setNeedsDisplay:YES]; 580 [field_ setNeedsDisplay:YES];
585 break; 581 break;
586 } 582 }
587 583
588 case chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED: { 584 case chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED: {
589 // Only update if the updated action box was for the active tab contents. 585 // Only update if the updated action box was for the active tab contents.
590 WebContents* target_tab = content::Details<WebContents>(details).ptr(); 586 WebContents* target_tab = content::Details<WebContents>(details).ptr();
591 if (target_tab == GetTabContents()->web_contents()) 587 if (target_tab == GetWebContents())
592 UpdatePageActions(); 588 UpdatePageActions();
593 break; 589 break;
594 } 590 }
595 591
596 default: 592 default:
597 NOTREACHED() << "Unexpected notification"; 593 NOTREACHED() << "Unexpected notification";
598 break; 594 break;
599 } 595 }
600 } 596 }
601 597
602 void LocationBarViewMac::OnPreferenceChanged(PrefServiceBase* service, 598 void LocationBarViewMac::OnPreferenceChanged(PrefServiceBase* service,
603 const std::string& pref_name) { 599 const std::string& pref_name) {
604 UpdateStarDecorationVisibility(); 600 UpdateStarDecorationVisibility();
605 OnChanged(); 601 OnChanged();
606 } 602 }
607 603
608 void LocationBarViewMac::PostNotification(NSString* notification) { 604 void LocationBarViewMac::PostNotification(NSString* notification) {
609 [[NSNotificationCenter defaultCenter] postNotificationName:notification 605 [[NSNotificationCenter defaultCenter] postNotificationName:notification
610 object:[NSValue valueWithPointer:this]]; 606 object:[NSValue valueWithPointer:this]];
611 } 607 }
612 608
613 bool LocationBarViewMac::RefreshContentSettingsDecorations() { 609 bool LocationBarViewMac::RefreshContentSettingsDecorations() {
614 const bool input_in_progress = toolbar_model_->GetInputInProgress(); 610 const bool input_in_progress = toolbar_model_->GetInputInProgress();
615 WebContents* web_contents = 611 WebContents* web_contents = input_in_progress ?
616 input_in_progress ? NULL : chrome::GetActiveWebContents(browser_); 612 NULL : browser_->tab_strip_model()->GetActiveWebContents();
617 bool icons_updated = false; 613 bool icons_updated = false;
618 for (size_t i = 0; i < content_setting_decorations_.size(); ++i) { 614 for (size_t i = 0; i < content_setting_decorations_.size(); ++i) {
619 icons_updated |= 615 icons_updated |=
620 content_setting_decorations_[i]->UpdateFromWebContents(web_contents); 616 content_setting_decorations_[i]->UpdateFromWebContents(web_contents);
621 } 617 }
622 return icons_updated; 618 return icons_updated;
623 } 619 }
624 620
625 void LocationBarViewMac::DeletePageActionDecorations() { 621 void LocationBarViewMac::DeletePageActionDecorations() {
626 // TODO(shess): Deleting these decorations could result in the cell 622 // TODO(shess): Deleting these decorations could result in the cell
627 // refering to them before things are laid out again. Meanwhile, at 623 // refering to them before things are laid out again. Meanwhile, at
628 // least fail safe. 624 // least fail safe.
629 [[field_ cell] clearDecorations]; 625 [[field_ cell] clearDecorations];
630 626
631 page_action_decorations_.clear(); 627 page_action_decorations_.clear();
632 } 628 }
633 629
634 void LocationBarViewMac::RefreshPageActionDecorations() { 630 void LocationBarViewMac::RefreshPageActionDecorations() {
635 if (!IsEditable()) { 631 if (!IsEditable()) {
636 DeletePageActionDecorations(); 632 DeletePageActionDecorations();
637 return; 633 return;
638 } 634 }
639 635
640 TabContents* tab_contents = GetTabContents(); 636 WebContents* web_contents = GetWebContents();
641 if (!tab_contents) { 637 if (!web_contents) {
642 DeletePageActionDecorations(); // Necessary? 638 DeletePageActionDecorations(); // Necessary?
643 return; 639 return;
644 } 640 }
645 641
646 std::vector<ExtensionAction*> new_page_actions = 642 std::vector<ExtensionAction*> new_page_actions =
647 extensions::TabHelper::FromWebContents(tab_contents->web_contents())-> 643 extensions::TabHelper::FromWebContents(web_contents)->
648 location_bar_controller()->GetCurrentActions(); 644 location_bar_controller()->GetCurrentActions();
649 645
650 if (new_page_actions != page_actions_) { 646 if (new_page_actions != page_actions_) {
651 page_actions_.swap(new_page_actions); 647 page_actions_.swap(new_page_actions);
652 DeletePageActionDecorations(); 648 DeletePageActionDecorations();
653 for (size_t i = 0; i < page_actions_.size(); ++i) { 649 for (size_t i = 0; i < page_actions_.size(); ++i) {
654 page_action_decorations_.push_back( 650 page_action_decorations_.push_back(
655 new PageActionDecoration(this, browser_, page_actions_[i])); 651 new PageActionDecoration(this, browser_, page_actions_[i]));
656 } 652 }
657 } 653 }
658 654
659 GURL url = toolbar_model_->GetURL(); 655 GURL url = toolbar_model_->GetURL();
660 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { 656 for (size_t i = 0; i < page_action_decorations_.size(); ++i) {
661 page_action_decorations_[i]->UpdateVisibility( 657 page_action_decorations_[i]->UpdateVisibility(
662 toolbar_model_->GetInputInProgress() ? 658 toolbar_model_->GetInputInProgress() ? NULL : web_contents,
663 NULL : tab_contents->web_contents(),
664 url); 659 url);
665 } 660 }
666 } 661 }
667 662
668 void LocationBarViewMac::RefreshWebIntentsButtonDecoration() { 663 void LocationBarViewMac::RefreshWebIntentsButtonDecoration() {
669 TabContents* tab_contents = GetTabContents(); 664 WebContents* web_contents = GetWebContents();
670 if (!tab_contents) { 665 if (!web_contents) {
671 web_intents_button_decoration_->SetVisible(false); 666 web_intents_button_decoration_->SetVisible(false);
672 return; 667 return;
673 } 668 }
674 669
675 web_intents_button_decoration_->Update(tab_contents); 670 web_intents_button_decoration_->Update(web_contents);
676 } 671 }
677 672
678 // TODO(shess): This function should over time grow to closely match 673 // TODO(shess): This function should over time grow to closely match
679 // the views Layout() function. 674 // the views Layout() function.
680 void LocationBarViewMac::Layout() { 675 void LocationBarViewMac::Layout() {
681 AutocompleteTextFieldCell* cell = [field_ cell]; 676 AutocompleteTextFieldCell* cell = [field_ cell];
682 677
683 // Reset the left-hand decorations. 678 // Reset the left-hand decorations.
684 // TODO(shess): Shortly, this code will live somewhere else, like in 679 // TODO(shess): Shortly, this code will live somewhere else, like in
685 // the constructor. I am still wrestling with how best to deal with 680 // the constructor. I am still wrestling with how best to deal with
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 } 753 }
759 754
760 bool LocationBarViewMac::IsStarEnabled() { 755 bool LocationBarViewMac::IsStarEnabled() {
761 return [field_ isEditable] && 756 return [field_ isEditable] &&
762 browser_defaults::bookmarks_enabled && 757 browser_defaults::bookmarks_enabled &&
763 !toolbar_model_->GetInputInProgress() && 758 !toolbar_model_->GetInputInProgress() &&
764 edit_bookmarks_enabled_.GetValue(); 759 edit_bookmarks_enabled_.GetValue();
765 } 760 }
766 761
767 void LocationBarViewMac::UpdateZoomDecoration() { 762 void LocationBarViewMac::UpdateZoomDecoration() {
768 TabContents* tab_contents = GetTabContents(); 763 WebContents* web_contents = GetWebContents();
769 if (!tab_contents) 764 if (!web_contents)
770 return; 765 return;
771 766
772 ZoomController* zoom_controller = 767 zoom_decoration_->Update(ZoomController::FromWebContents(web_contents));
773 ZoomController::FromWebContents(tab_contents->web_contents());
774 zoom_decoration_->Update(zoom_controller);
775 } 768 }
776 769
777 void LocationBarViewMac::UpdateStarDecorationVisibility() { 770 void LocationBarViewMac::UpdateStarDecorationVisibility() {
778 // If the action box is enabled, only show the star if it's lit. 771 // If the action box is enabled, only show the star if it's lit.
779 bool visible = IsStarEnabled(); 772 bool visible = IsStarEnabled();
780 if (!star_decoration_->starred() && 773 if (!star_decoration_->starred() &&
781 extensions::FeatureSwitch::action_box()->IsEnabled()) 774 extensions::FeatureSwitch::action_box()->IsEnabled())
782 visible = false; 775 visible = false;
783 star_decoration_->SetVisible(visible); 776 star_decoration_->SetVisible(visible);
784 } 777 }
785 778
786 void LocationBarViewMac::UpdatePlusDecorationVisibility() { 779 void LocationBarViewMac::UpdatePlusDecorationVisibility() {
787 if (extensions::FeatureSwitch::action_box()->IsEnabled()) { 780 if (extensions::FeatureSwitch::action_box()->IsEnabled()) {
788 // If the action box is enabled, hide it when input is in progress. 781 // If the action box is enabled, hide it when input is in progress.
789 plus_decoration_->SetVisible(!toolbar_model_->GetInputInProgress()); 782 plus_decoration_->SetVisible(!toolbar_model_->GetInputInProgress());
790 } 783 }
791 } 784 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698