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