| 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 28 matching lines...) Expand all Loading... |
| 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" | 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" | 41 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h" |
| 42 #import "chrome/browser/ui/cocoa/location_bar/ev_bubble_decoration.h" | 42 #import "chrome/browser/ui/cocoa/location_bar/ev_bubble_decoration.h" |
| 43 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h" | 43 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h" |
| 44 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h" | 44 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h" |
| 45 #import "chrome/browser/ui/cocoa/location_bar/page_action_decoration.h" | 45 #import "chrome/browser/ui/cocoa/location_bar/page_action_decoration.h" |
| 46 #import "chrome/browser/ui/cocoa/location_bar/plus_decoration.h" | 46 #import "chrome/browser/ui/cocoa/location_bar/plus_decoration.h" |
| 47 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h" | 47 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h" |
| 48 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" | 48 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" |
| 49 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h" |
| 49 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" | 50 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" |
| 50 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | 51 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" |
| 51 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" | 52 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" |
| 52 #include "chrome/browser/ui/omnibox/location_bar_util.h" | 53 #include "chrome/browser/ui/omnibox/location_bar_util.h" |
| 53 #import "chrome/browser/ui/omnibox/omnibox_popup_model.h" | 54 #import "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
| 54 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 55 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 55 #include "chrome/common/chrome_notification_types.h" | 56 #include "chrome/common/chrome_notification_types.h" |
| 56 #include "chrome/common/chrome_switches.h" | 57 #include "chrome/common/chrome_switches.h" |
| 57 #include "chrome/common/extensions/extension.h" | 58 #include "chrome/common/extensions/extension.h" |
| 58 #include "chrome/common/extensions/extension_action.h" | 59 #include "chrome/common/extensions/extension_action.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 disposition_(CURRENT_TAB), | 96 disposition_(CURRENT_TAB), |
| 96 location_icon_decoration_(new LocationIconDecoration(this)), | 97 location_icon_decoration_(new LocationIconDecoration(this)), |
| 97 selected_keyword_decoration_( | 98 selected_keyword_decoration_( |
| 98 new SelectedKeywordDecoration(OmniboxViewMac::GetFieldFont())), | 99 new SelectedKeywordDecoration(OmniboxViewMac::GetFieldFont())), |
| 99 ev_bubble_decoration_( | 100 ev_bubble_decoration_( |
| 100 new EVBubbleDecoration(location_icon_decoration_.get(), | 101 new EVBubbleDecoration(location_icon_decoration_.get(), |
| 101 OmniboxViewMac::GetFieldFont())), | 102 OmniboxViewMac::GetFieldFont())), |
| 102 plus_decoration_(NULL), | 103 plus_decoration_(NULL), |
| 103 star_decoration_(new StarDecoration(command_updater)), | 104 star_decoration_(new StarDecoration(command_updater)), |
| 104 chrome_to_mobile_decoration_(NULL), | 105 chrome_to_mobile_decoration_(NULL), |
| 106 zoom_decoration_(new ZoomDecoration(toolbar_model)), |
| 105 keyword_hint_decoration_( | 107 keyword_hint_decoration_( |
| 106 new KeywordHintDecoration(OmniboxViewMac::GetFieldFont())), | 108 new KeywordHintDecoration(OmniboxViewMac::GetFieldFont())), |
| 107 profile_(profile), | 109 profile_(profile), |
| 108 browser_(browser), | 110 browser_(browser), |
| 109 toolbar_model_(toolbar_model), | 111 toolbar_model_(toolbar_model), |
| 110 transition_(content::PageTransitionFromInt( | 112 transition_(content::PageTransitionFromInt( |
| 111 content::PAGE_TRANSITION_TYPED | | 113 content::PAGE_TRANSITION_TYPED | |
| 112 content::PAGE_TRANSITION_FROM_ADDRESS_BAR)), | 114 content::PAGE_TRANSITION_FROM_ADDRESS_BAR)), |
| 113 weak_ptr_factory_(this) { | 115 weak_ptr_factory_(this) { |
| 114 // Disable Chrome To Mobile for off-the-record and non-synced profiles, | 116 // Disable Chrome To Mobile for off-the-record and non-synced profiles, |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 // TODO(shess): Why SaveStateToContents vs SaveStateToTab? | 247 // TODO(shess): Why SaveStateToContents vs SaveStateToTab? |
| 246 omnibox_view_->SaveStateToTab(contents); | 248 omnibox_view_->SaveStateToTab(contents); |
| 247 } | 249 } |
| 248 | 250 |
| 249 void LocationBarViewMac::Update(const WebContents* contents, | 251 void LocationBarViewMac::Update(const WebContents* contents, |
| 250 bool should_restore_state) { | 252 bool should_restore_state) { |
| 251 bool star_enabled = IsStarEnabled(); | 253 bool star_enabled = IsStarEnabled(); |
| 252 command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled); | 254 command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled); |
| 253 star_decoration_->SetVisible(star_enabled); | 255 star_decoration_->SetVisible(star_enabled); |
| 254 UpdateChromeToMobileEnabled(); | 256 UpdateChromeToMobileEnabled(); |
| 257 UpdateZoomDecoration(); |
| 255 RefreshPageActionDecorations(); | 258 RefreshPageActionDecorations(); |
| 256 RefreshContentSettingsDecorations(); | 259 RefreshContentSettingsDecorations(); |
| 257 // OmniboxView restores state if the tab is non-NULL. | 260 // OmniboxView restores state if the tab is non-NULL. |
| 258 omnibox_view_->Update(should_restore_state ? contents : NULL); | 261 omnibox_view_->Update(should_restore_state ? contents : NULL); |
| 259 OnChanged(); | 262 OnChanged(); |
| 260 } | 263 } |
| 261 | 264 |
| 262 void LocationBarViewMac::OnAutocompleteAccept( | 265 void LocationBarViewMac::OnAutocompleteAccept( |
| 263 const GURL& url, | 266 const GURL& url, |
| 264 WindowOpenDisposition disposition, | 267 WindowOpenDisposition disposition, |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 void LocationBarViewMac::TestPageActionPressed(size_t index) { | 473 void LocationBarViewMac::TestPageActionPressed(size_t index) { |
| 471 DCHECK_LT(index, page_action_decorations_.size()); | 474 DCHECK_LT(index, page_action_decorations_.size()); |
| 472 if (index < page_action_decorations_.size()) | 475 if (index < page_action_decorations_.size()) |
| 473 page_action_decorations_[index]->OnMousePressed(NSZeroRect); | 476 page_action_decorations_[index]->OnMousePressed(NSZeroRect); |
| 474 } | 477 } |
| 475 | 478 |
| 476 void LocationBarViewMac::SetEditable(bool editable) { | 479 void LocationBarViewMac::SetEditable(bool editable) { |
| 477 [field_ setEditable:editable ? YES : NO]; | 480 [field_ setEditable:editable ? YES : NO]; |
| 478 star_decoration_->SetVisible(IsStarEnabled()); | 481 star_decoration_->SetVisible(IsStarEnabled()); |
| 479 UpdateChromeToMobileEnabled(); | 482 UpdateChromeToMobileEnabled(); |
| 483 UpdateZoomDecoration(); |
| 480 UpdatePageActions(); | 484 UpdatePageActions(); |
| 481 Layout(); | 485 Layout(); |
| 482 } | 486 } |
| 483 | 487 |
| 484 bool LocationBarViewMac::IsEditable() { | 488 bool LocationBarViewMac::IsEditable() { |
| 485 return [field_ isEditable] ? true : false; | 489 return [field_ isEditable] ? true : false; |
| 486 } | 490 } |
| 487 | 491 |
| 488 void LocationBarViewMac::SetStarred(bool starred) { | 492 void LocationBarViewMac::OnDecorationsChanged() { |
| 489 star_decoration_->SetStarred(starred); | |
| 490 | |
| 491 // TODO(shess): The field-editor frame and cursor rects should not | 493 // TODO(shess): The field-editor frame and cursor rects should not |
| 492 // change, here. | 494 // change, here. |
| 493 [field_ updateCursorAndToolTipRects]; | 495 [field_ updateCursorAndToolTipRects]; |
| 494 [field_ resetFieldEditorFrameIfNeeded]; | 496 [field_ resetFieldEditorFrameIfNeeded]; |
| 495 [field_ setNeedsDisplay:YES]; | 497 [field_ setNeedsDisplay:YES]; |
| 496 } | 498 } |
| 497 | 499 |
| 500 void LocationBarViewMac::SetStarred(bool starred) { |
| 501 star_decoration_->SetStarred(starred); |
| 502 OnDecorationsChanged(); |
| 503 } |
| 504 |
| 498 void LocationBarViewMac::SetChromeToMobileDecorationLit(bool lit) { | 505 void LocationBarViewMac::SetChromeToMobileDecorationLit(bool lit) { |
| 499 chrome_to_mobile_decoration_->SetLit(lit); | 506 chrome_to_mobile_decoration_->SetLit(lit); |
| 507 OnDecorationsChanged(); |
| 508 } |
| 500 | 509 |
| 501 // TODO(shess): The field-editor frame and cursor rects should not | 510 void LocationBarViewMac::ZoomChangedForActiveTab(bool can_show_bubble) { |
| 502 // change, here. | 511 UpdateZoomDecoration(); |
| 503 [field_ updateCursorAndToolTipRects]; | 512 OnDecorationsChanged(); |
| 504 [field_ resetFieldEditorFrameIfNeeded]; | 513 |
| 505 [field_ setNeedsDisplay:YES]; | 514 // 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. |
| 506 } | 516 } |
| 507 | 517 |
| 508 NSPoint LocationBarViewMac::GetBookmarkBubblePoint() const { | 518 NSPoint LocationBarViewMac::GetBookmarkBubblePoint() const { |
| 509 AutocompleteTextFieldCell* cell = [field_ cell]; | 519 AutocompleteTextFieldCell* cell = [field_ cell]; |
| 510 const NSRect frame = [cell frameForDecoration:star_decoration_.get() | 520 const NSRect frame = [cell frameForDecoration:star_decoration_.get() |
| 511 inFrame:[field_ bounds]]; | 521 inFrame:[field_ bounds]]; |
| 512 const NSPoint point = star_decoration_->GetBubblePointInFrame(frame); | 522 const NSPoint point = star_decoration_->GetBubblePointInFrame(frame); |
| 513 return [field_ convertPoint:point toView:nil]; | 523 return [field_ convertPoint:point toView:nil]; |
| 514 } | 524 } |
| 515 | 525 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 // TODO(shess): Shortly, this code will live somewhere else, like in | 670 // TODO(shess): Shortly, this code will live somewhere else, like in |
| 661 // the constructor. I am still wrestling with how best to deal with | 671 // the constructor. I am still wrestling with how best to deal with |
| 662 // right-hand decorations, which are not a static set. | 672 // right-hand decorations, which are not a static set. |
| 663 [cell clearDecorations]; | 673 [cell clearDecorations]; |
| 664 [cell addLeftDecoration:location_icon_decoration_.get()]; | 674 [cell addLeftDecoration:location_icon_decoration_.get()]; |
| 665 [cell addLeftDecoration:selected_keyword_decoration_.get()]; | 675 [cell addLeftDecoration:selected_keyword_decoration_.get()]; |
| 666 [cell addLeftDecoration:ev_bubble_decoration_.get()]; | 676 [cell addLeftDecoration:ev_bubble_decoration_.get()]; |
| 667 if (plus_decoration_.get()) | 677 if (plus_decoration_.get()) |
| 668 [cell addRightDecoration:plus_decoration_.get()]; | 678 [cell addRightDecoration:plus_decoration_.get()]; |
| 669 [cell addRightDecoration:star_decoration_.get()]; | 679 [cell addRightDecoration:star_decoration_.get()]; |
| 680 [cell addRightDecoration:zoom_decoration_.get()]; |
| 670 if (chrome_to_mobile_decoration_.get()) | 681 if (chrome_to_mobile_decoration_.get()) |
| 671 [cell addRightDecoration:chrome_to_mobile_decoration_.get()]; | 682 [cell addRightDecoration:chrome_to_mobile_decoration_.get()]; |
| 672 | 683 |
| 673 // Note that display order is right to left. | 684 // Note that display order is right to left. |
| 674 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { | 685 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { |
| 675 [cell addRightDecoration:page_action_decorations_[i]]; | 686 [cell addRightDecoration:page_action_decorations_[i]]; |
| 676 } | 687 } |
| 677 for (size_t i = 0; i < content_setting_decorations_.size(); ++i) { | 688 for (size_t i = 0; i < content_setting_decorations_.size(); ++i) { |
| 678 [cell addRightDecoration:content_setting_decorations_[i]]; | 689 [cell addRightDecoration:content_setting_decorations_[i]]; |
| 679 } | 690 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 } else if (!keyword.empty() && is_keyword_hint) { | 724 } else if (!keyword.empty() && is_keyword_hint) { |
| 714 keyword_hint_decoration_->SetKeyword(short_name, | 725 keyword_hint_decoration_->SetKeyword(short_name, |
| 715 is_extension_keyword); | 726 is_extension_keyword); |
| 716 keyword_hint_decoration_->SetVisible(true); | 727 keyword_hint_decoration_->SetVisible(true); |
| 717 } | 728 } |
| 718 | 729 |
| 719 // These need to change anytime the layout changes. | 730 // These need to change anytime the layout changes. |
| 720 // TODO(shess): Anytime the field editor might have changed, the | 731 // TODO(shess): Anytime the field editor might have changed, the |
| 721 // cursor rects almost certainly should have changed. The tooltips | 732 // cursor rects almost certainly should have changed. The tooltips |
| 722 // might change even when the rects don't change. | 733 // might change even when the rects don't change. |
| 723 [field_ resetFieldEditorFrameIfNeeded]; | 734 OnDecorationsChanged(); |
| 724 [field_ updateCursorAndToolTipRects]; | |
| 725 | |
| 726 [field_ setNeedsDisplay:YES]; | |
| 727 } | 735 } |
| 728 | 736 |
| 729 void LocationBarViewMac::RedrawDecoration(LocationBarDecoration* decoration) { | 737 void LocationBarViewMac::RedrawDecoration(LocationBarDecoration* decoration) { |
| 730 AutocompleteTextFieldCell* cell = [field_ cell]; | 738 AutocompleteTextFieldCell* cell = [field_ cell]; |
| 731 NSRect frame = [cell frameForDecoration:decoration | 739 NSRect frame = [cell frameForDecoration:decoration |
| 732 inFrame:[field_ bounds]]; | 740 inFrame:[field_ bounds]]; |
| 733 if (!NSIsEmptyRect(frame)) | 741 if (!NSIsEmptyRect(frame)) |
| 734 [field_ setNeedsDisplayInRect:frame]; | 742 [field_ setNeedsDisplayInRect:frame]; |
| 735 } | 743 } |
| 736 | 744 |
| 737 bool LocationBarViewMac::IsStarEnabled() { | 745 bool LocationBarViewMac::IsStarEnabled() { |
| 738 return [field_ isEditable] && | 746 return [field_ isEditable] && |
| 739 browser_defaults::bookmarks_enabled && | 747 browser_defaults::bookmarks_enabled && |
| 740 !toolbar_model_->input_in_progress() && | 748 !toolbar_model_->input_in_progress() && |
| 741 edit_bookmarks_enabled_.GetValue(); | 749 edit_bookmarks_enabled_.GetValue(); |
| 742 } | 750 } |
| 743 | 751 |
| 744 void LocationBarViewMac::UpdateChromeToMobileEnabled() { | 752 void LocationBarViewMac::UpdateChromeToMobileEnabled() { |
| 745 if (!chrome_to_mobile_decoration_.get()) | 753 if (!chrome_to_mobile_decoration_.get()) |
| 746 return; | 754 return; |
| 747 | 755 |
| 748 DCHECK(ChromeToMobileService::IsChromeToMobileEnabled()); | 756 DCHECK(ChromeToMobileService::IsChromeToMobileEnabled()); |
| 749 bool enabled = [field_ isEditable] && !toolbar_model_->input_in_progress() && | 757 bool enabled = [field_ isEditable] && !toolbar_model_->input_in_progress() && |
| 750 ChromeToMobileServiceFactory::GetForProfile(profile_)->HasMobiles(); | 758 ChromeToMobileServiceFactory::GetForProfile(profile_)->HasMobiles(); |
| 751 chrome_to_mobile_decoration_->SetVisible(enabled); | 759 chrome_to_mobile_decoration_->SetVisible(enabled); |
| 752 command_updater_->UpdateCommandEnabled(IDC_CHROME_TO_MOBILE_PAGE, enabled); | 760 command_updater_->UpdateCommandEnabled(IDC_CHROME_TO_MOBILE_PAGE, enabled); |
| 753 } | 761 } |
| 762 |
| 763 void LocationBarViewMac::UpdateZoomDecoration() { |
| 764 TabContents* tab_contents = GetTabContents(); |
| 765 if (!tab_contents) |
| 766 return; |
| 767 |
| 768 zoom_decoration_->Update(tab_contents->zoom_controller()); |
| 769 } |
| OLD | NEW |