| OLD | NEW |
| 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 19 matching lines...) Expand all Loading... |
| 30 #include "chrome/browser/ui/browser_instant_controller.h" | 30 #include "chrome/browser/ui/browser_instant_controller.h" |
| 31 #include "chrome/browser/ui/browser_list.h" | 31 #include "chrome/browser/ui/browser_list.h" |
| 32 #include "chrome/browser/ui/browser_tabstrip.h" | 32 #include "chrome/browser/ui/browser_tabstrip.h" |
| 33 #import "chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.h
" | 33 #import "chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.h
" |
| 34 #include "chrome/browser/ui/cocoa/event_utils.h" | 34 #include "chrome/browser/ui/cocoa/event_utils.h" |
| 35 #import "chrome/browser/ui/cocoa/extensions/extension_action_context_menu.h" | 35 #import "chrome/browser/ui/cocoa/extensions/extension_action_context_menu.h" |
| 36 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" | 36 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" |
| 37 #import "chrome/browser/ui/cocoa/first_run_bubble_controller.h" | 37 #import "chrome/browser/ui/cocoa/first_run_bubble_controller.h" |
| 38 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" | 38 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" |
| 39 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" | 39 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" |
| 40 #import "chrome/browser/ui/cocoa/location_bar/chrome_to_mobile_decoration.h" | |
| 41 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h" | 40 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h" |
| 42 #import "chrome/browser/ui/cocoa/location_bar/ev_bubble_decoration.h" | 41 #import "chrome/browser/ui/cocoa/location_bar/ev_bubble_decoration.h" |
| 43 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h" | 42 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h" |
| 44 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h" | 43 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h" |
| 45 #import "chrome/browser/ui/cocoa/location_bar/page_action_decoration.h" | 44 #import "chrome/browser/ui/cocoa/location_bar/page_action_decoration.h" |
| 46 #import "chrome/browser/ui/cocoa/location_bar/plus_decoration.h" | 45 #import "chrome/browser/ui/cocoa/location_bar/plus_decoration.h" |
| 47 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h" | 46 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h" |
| 48 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" | 47 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" |
| 49 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h" | 48 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h" |
| 50 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" | 49 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 field_(field), | 94 field_(field), |
| 96 disposition_(CURRENT_TAB), | 95 disposition_(CURRENT_TAB), |
| 97 location_icon_decoration_(new LocationIconDecoration(this)), | 96 location_icon_decoration_(new LocationIconDecoration(this)), |
| 98 selected_keyword_decoration_( | 97 selected_keyword_decoration_( |
| 99 new SelectedKeywordDecoration(OmniboxViewMac::GetFieldFont())), | 98 new SelectedKeywordDecoration(OmniboxViewMac::GetFieldFont())), |
| 100 ev_bubble_decoration_( | 99 ev_bubble_decoration_( |
| 101 new EVBubbleDecoration(location_icon_decoration_.get(), | 100 new EVBubbleDecoration(location_icon_decoration_.get(), |
| 102 OmniboxViewMac::GetFieldFont())), | 101 OmniboxViewMac::GetFieldFont())), |
| 103 plus_decoration_(NULL), | 102 plus_decoration_(NULL), |
| 104 star_decoration_(new StarDecoration(command_updater)), | 103 star_decoration_(new StarDecoration(command_updater)), |
| 105 chrome_to_mobile_decoration_(NULL), | |
| 106 zoom_decoration_(new ZoomDecoration(toolbar_model)), | 104 zoom_decoration_(new ZoomDecoration(toolbar_model)), |
| 107 keyword_hint_decoration_( | 105 keyword_hint_decoration_( |
| 108 new KeywordHintDecoration(OmniboxViewMac::GetFieldFont())), | 106 new KeywordHintDecoration(OmniboxViewMac::GetFieldFont())), |
| 109 profile_(profile), | 107 profile_(profile), |
| 110 browser_(browser), | 108 browser_(browser), |
| 111 toolbar_model_(toolbar_model), | 109 toolbar_model_(toolbar_model), |
| 112 transition_(content::PageTransitionFromInt( | 110 transition_(content::PageTransitionFromInt( |
| 113 content::PAGE_TRANSITION_TYPED | | 111 content::PAGE_TRANSITION_TYPED | |
| 114 content::PAGE_TRANSITION_FROM_ADDRESS_BAR)), | 112 content::PAGE_TRANSITION_FROM_ADDRESS_BAR)), |
| 115 weak_ptr_factory_(this) { | 113 weak_ptr_factory_(this) { |
| 116 // Disable Chrome To Mobile for off-the-record and non-synced profiles, | |
| 117 // or if the feature is disabled by a command line flag or chrome://flags. | |
| 118 if (!profile_->IsOffTheRecord() && profile_->IsSyncAccessible() && | |
| 119 ChromeToMobileService::IsChromeToMobileEnabled()) { | |
| 120 command_updater_->AddCommandObserver(IDC_CHROME_TO_MOBILE_PAGE, this); | |
| 121 chrome_to_mobile_decoration_.reset( | |
| 122 new ChromeToMobileDecoration(profile, command_updater)); | |
| 123 UpdateChromeToMobileEnabled(); | |
| 124 } | |
| 125 | |
| 126 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableActionBox)) { | 114 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableActionBox)) { |
| 127 plus_decoration_.reset(new PlusDecoration(this, command_updater, browser_)); | 115 plus_decoration_.reset(new PlusDecoration(this, command_updater, browser_)); |
| 128 } | 116 } |
| 129 | 117 |
| 130 for (size_t i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { | 118 for (size_t i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { |
| 131 DCHECK_EQ(i, content_setting_decorations_.size()); | 119 DCHECK_EQ(i, content_setting_decorations_.size()); |
| 132 ContentSettingsType type = static_cast<ContentSettingsType>(i); | 120 ContentSettingsType type = static_cast<ContentSettingsType>(i); |
| 133 content_setting_decorations_.push_back( | 121 content_setting_decorations_.push_back( |
| 134 new ContentSettingDecoration(type, this, profile_)); | 122 new ContentSettingDecoration(type, this, profile_)); |
| 135 } | 123 } |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 [field_ resetFieldEditorFrameIfNeeded]; | 483 [field_ resetFieldEditorFrameIfNeeded]; |
| 496 [field_ setNeedsDisplay:YES]; | 484 [field_ setNeedsDisplay:YES]; |
| 497 } | 485 } |
| 498 | 486 |
| 499 void LocationBarViewMac::SetStarred(bool starred) { | 487 void LocationBarViewMac::SetStarred(bool starred) { |
| 500 star_decoration_->SetStarred(starred); | 488 star_decoration_->SetStarred(starred); |
| 501 UpdateStarDecorationVisibility(); | 489 UpdateStarDecorationVisibility(); |
| 502 OnDecorationsChanged(); | 490 OnDecorationsChanged(); |
| 503 } | 491 } |
| 504 | 492 |
| 505 void LocationBarViewMac::SetChromeToMobileDecorationLit(bool lit) { | 493 void LocationBarViewMac::SetActionBoxIcon(int image_id) { |
| 506 chrome_to_mobile_decoration_->SetLit(lit); | 494 plus_decoration_->SetImage(OmniboxViewMac::ImageForResource(image_id)); |
| 507 OnDecorationsChanged(); | 495 OnDecorationsChanged(); |
| 508 } | 496 } |
| 509 | 497 |
| 510 void LocationBarViewMac::ZoomChangedForActiveTab(bool can_show_bubble) { | 498 void LocationBarViewMac::ZoomChangedForActiveTab(bool can_show_bubble) { |
| 511 UpdateZoomDecoration(); | 499 UpdateZoomDecoration(); |
| 512 OnDecorationsChanged(); | 500 OnDecorationsChanged(); |
| 513 | 501 |
| 514 // TODO(dbeam): show a zoom bubble when |can_show_bubble| is true, the zoom | 502 // TODO(dbeam): show a zoom bubble when |can_show_bubble| is true, the zoom |
| 515 // decoration is showing, and the wrench menu isn't showing. | 503 // decoration is showing, and the wrench menu isn't showing. |
| 516 } | 504 } |
| 517 | 505 |
| 518 NSPoint LocationBarViewMac::GetActionBoxAnchorPoint() const { | 506 NSPoint LocationBarViewMac::GetActionBoxAnchorPoint() const { |
| 519 NSPoint point = plus_decoration_->GetActionBoxAnchorPoint(); | 507 NSPoint point = plus_decoration_->GetActionBoxAnchorPoint(); |
| 520 return [field_ convertPoint:point toView:nil]; | 508 return [field_ convertPoint:point toView:nil]; |
| 521 } | 509 } |
| 522 | 510 |
| 523 NSPoint LocationBarViewMac::GetBookmarkBubblePoint() const { | 511 NSPoint LocationBarViewMac::GetBookmarkBubblePoint() const { |
| 524 AutocompleteTextFieldCell* cell = [field_ cell]; | 512 AutocompleteTextFieldCell* cell = [field_ cell]; |
| 525 const NSRect frame = [cell frameForDecoration:star_decoration_.get() | 513 const NSRect frame = [cell frameForDecoration:star_decoration_.get() |
| 526 inFrame:[field_ bounds]]; | 514 inFrame:[field_ bounds]]; |
| 527 const NSPoint point = star_decoration_->GetBubblePointInFrame(frame); | 515 const NSPoint point = star_decoration_->GetBubblePointInFrame(frame); |
| 528 return [field_ convertPoint:point toView:nil]; | 516 return [field_ convertPoint:point toView:nil]; |
| 529 } | 517 } |
| 530 | 518 |
| 531 NSPoint LocationBarViewMac::GetChromeToMobileBubblePoint() const { | |
| 532 AutocompleteTextFieldCell* cell = [field_ cell]; | |
| 533 const NSRect frame = | |
| 534 [cell frameForDecoration:chrome_to_mobile_decoration_.get() | |
| 535 inFrame:[field_ bounds]]; | |
| 536 const NSPoint point = | |
| 537 chrome_to_mobile_decoration_->GetBubblePointInFrame(frame); | |
| 538 return [field_ convertPoint:point toView:nil]; | |
| 539 } | |
| 540 | |
| 541 NSPoint LocationBarViewMac::GetPageInfoBubblePoint() const { | 519 NSPoint LocationBarViewMac::GetPageInfoBubblePoint() const { |
| 542 AutocompleteTextFieldCell* cell = [field_ cell]; | 520 AutocompleteTextFieldCell* cell = [field_ cell]; |
| 543 if (ev_bubble_decoration_->IsVisible()) { | 521 if (ev_bubble_decoration_->IsVisible()) { |
| 544 const NSRect frame = [cell frameForDecoration:ev_bubble_decoration_.get() | 522 const NSRect frame = [cell frameForDecoration:ev_bubble_decoration_.get() |
| 545 inFrame:[field_ bounds]]; | 523 inFrame:[field_ bounds]]; |
| 546 const NSPoint point = ev_bubble_decoration_->GetBubblePointInFrame(frame); | 524 const NSPoint point = ev_bubble_decoration_->GetBubblePointInFrame(frame); |
| 547 return [field_ convertPoint:point toView:nil]; | 525 return [field_ convertPoint:point toView:nil]; |
| 548 } else { | 526 } else { |
| 549 const NSRect frame = | 527 const NSRect frame = |
| 550 [cell frameForDecoration:location_icon_decoration_.get() | 528 [cell frameForDecoration:location_icon_decoration_.get() |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 UpdateChromeToMobileEnabled(); | 571 UpdateChromeToMobileEnabled(); |
| 594 OnChanged(); | 572 OnChanged(); |
| 595 break; | 573 break; |
| 596 | 574 |
| 597 default: | 575 default: |
| 598 NOTREACHED() << "Unexpected notification"; | 576 NOTREACHED() << "Unexpected notification"; |
| 599 break; | 577 break; |
| 600 } | 578 } |
| 601 } | 579 } |
| 602 | 580 |
| 603 void LocationBarViewMac::EnabledStateChangedForCommand(int id, bool enabled) { | |
| 604 DCHECK_EQ(id, IDC_CHROME_TO_MOBILE_PAGE); | |
| 605 UpdateChromeToMobileEnabled(); | |
| 606 OnChanged(); | |
| 607 } | |
| 608 | |
| 609 void LocationBarViewMac::PostNotification(NSString* notification) { | 581 void LocationBarViewMac::PostNotification(NSString* notification) { |
| 610 [[NSNotificationCenter defaultCenter] postNotificationName:notification | 582 [[NSNotificationCenter defaultCenter] postNotificationName:notification |
| 611 object:[NSValue valueWithPointer:this]]; | 583 object:[NSValue valueWithPointer:this]]; |
| 612 } | 584 } |
| 613 | 585 |
| 614 bool LocationBarViewMac::RefreshContentSettingsDecorations() { | 586 bool LocationBarViewMac::RefreshContentSettingsDecorations() { |
| 615 const bool input_in_progress = toolbar_model_->input_in_progress(); | 587 const bool input_in_progress = toolbar_model_->input_in_progress(); |
| 616 WebContents* web_contents = | 588 WebContents* web_contents = |
| 617 input_in_progress ? NULL : chrome::GetActiveWebContents(browser_); | 589 input_in_progress ? NULL : chrome::GetActiveWebContents(browser_); |
| 618 bool icons_updated = false; | 590 bool icons_updated = false; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 // the constructor. I am still wrestling with how best to deal with | 648 // the constructor. I am still wrestling with how best to deal with |
| 677 // right-hand decorations, which are not a static set. | 649 // right-hand decorations, which are not a static set. |
| 678 [cell clearDecorations]; | 650 [cell clearDecorations]; |
| 679 [cell addLeftDecoration:location_icon_decoration_.get()]; | 651 [cell addLeftDecoration:location_icon_decoration_.get()]; |
| 680 [cell addLeftDecoration:selected_keyword_decoration_.get()]; | 652 [cell addLeftDecoration:selected_keyword_decoration_.get()]; |
| 681 [cell addLeftDecoration:ev_bubble_decoration_.get()]; | 653 [cell addLeftDecoration:ev_bubble_decoration_.get()]; |
| 682 if (plus_decoration_.get()) | 654 if (plus_decoration_.get()) |
| 683 [cell addRightDecoration:plus_decoration_.get()]; | 655 [cell addRightDecoration:plus_decoration_.get()]; |
| 684 [cell addRightDecoration:star_decoration_.get()]; | 656 [cell addRightDecoration:star_decoration_.get()]; |
| 685 [cell addRightDecoration:zoom_decoration_.get()]; | 657 [cell addRightDecoration:zoom_decoration_.get()]; |
| 686 if (chrome_to_mobile_decoration_.get()) | |
| 687 [cell addRightDecoration:chrome_to_mobile_decoration_.get()]; | |
| 688 | 658 |
| 689 // Note that display order is right to left. | 659 // Note that display order is right to left. |
| 690 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { | 660 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { |
| 691 [cell addRightDecoration:page_action_decorations_[i]]; | 661 [cell addRightDecoration:page_action_decorations_[i]]; |
| 692 } | 662 } |
| 693 for (size_t i = 0; i < content_setting_decorations_.size(); ++i) { | 663 for (size_t i = 0; i < content_setting_decorations_.size(); ++i) { |
| 694 [cell addRightDecoration:content_setting_decorations_[i]]; | 664 [cell addRightDecoration:content_setting_decorations_[i]]; |
| 695 } | 665 } |
| 696 | 666 |
| 697 [cell addRightDecoration:keyword_hint_decoration_.get()]; | 667 [cell addRightDecoration:keyword_hint_decoration_.get()]; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 } | 718 } |
| 749 | 719 |
| 750 bool LocationBarViewMac::IsStarEnabled() { | 720 bool LocationBarViewMac::IsStarEnabled() { |
| 751 return [field_ isEditable] && | 721 return [field_ isEditable] && |
| 752 browser_defaults::bookmarks_enabled && | 722 browser_defaults::bookmarks_enabled && |
| 753 !toolbar_model_->input_in_progress() && | 723 !toolbar_model_->input_in_progress() && |
| 754 edit_bookmarks_enabled_.GetValue(); | 724 edit_bookmarks_enabled_.GetValue(); |
| 755 } | 725 } |
| 756 | 726 |
| 757 void LocationBarViewMac::UpdateChromeToMobileEnabled() { | 727 void LocationBarViewMac::UpdateChromeToMobileEnabled() { |
| 758 if (!chrome_to_mobile_decoration_.get()) | 728 bool enabled = ChromeToMobileService::IsChromeToMobileEnabled() && |
| 759 return; | 729 [field_ isEditable] && !toolbar_model_->input_in_progress() && |
| 760 | |
| 761 DCHECK(ChromeToMobileService::IsChromeToMobileEnabled()); | |
| 762 bool enabled = [field_ isEditable] && !toolbar_model_->input_in_progress() && | |
| 763 ChromeToMobileServiceFactory::GetForProfile(profile_)->HasMobiles(); | 730 ChromeToMobileServiceFactory::GetForProfile(profile_)->HasMobiles(); |
| 764 chrome_to_mobile_decoration_->SetVisible(enabled); | |
| 765 command_updater_->UpdateCommandEnabled(IDC_CHROME_TO_MOBILE_PAGE, enabled); | 731 command_updater_->UpdateCommandEnabled(IDC_CHROME_TO_MOBILE_PAGE, enabled); |
| 766 } | 732 } |
| 767 | 733 |
| 768 void LocationBarViewMac::UpdateZoomDecoration() { | 734 void LocationBarViewMac::UpdateZoomDecoration() { |
| 769 TabContents* tab_contents = GetTabContents(); | 735 TabContents* tab_contents = GetTabContents(); |
| 770 if (!tab_contents) | 736 if (!tab_contents) |
| 771 return; | 737 return; |
| 772 | 738 |
| 773 zoom_decoration_->Update(tab_contents->zoom_controller()); | 739 zoom_decoration_->Update(tab_contents->zoom_controller()); |
| 774 } | 740 } |
| 775 | 741 |
| 776 void LocationBarViewMac::UpdateStarDecorationVisibility() { | 742 void LocationBarViewMac::UpdateStarDecorationVisibility() { |
| 777 bool action_box_enabled = | 743 bool action_box_enabled = |
| 778 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableActionBox); | 744 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableActionBox); |
| 779 // If the action box is enabled, only show the star if it's lit. | 745 // If the action box is enabled, only show the star if it's lit. |
| 780 bool visible = IsStarEnabled(); | 746 bool visible = IsStarEnabled(); |
| 781 if (!star_decoration_->starred() && action_box_enabled) | 747 if (!star_decoration_->starred() && action_box_enabled) |
| 782 visible = false; | 748 visible = false; |
| 783 star_decoration_->SetVisible(visible); | 749 star_decoration_->SetVisible(visible); |
| 784 } | 750 } |
| OLD | NEW |