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" | |
47 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" | 48 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" |
48 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | 49 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" |
49 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" | 50 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" |
50 #include "chrome/browser/ui/omnibox/location_bar_util.h" | 51 #include "chrome/browser/ui/omnibox/location_bar_util.h" |
51 #import "chrome/browser/ui/omnibox/omnibox_popup_model.h" | 52 #import "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
52 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 53 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
53 #include "chrome/common/chrome_notification_types.h" | 54 #include "chrome/common/chrome_notification_types.h" |
54 #include "chrome/common/chrome_switches.h" | 55 #include "chrome/common/chrome_switches.h" |
55 #include "chrome/common/extensions/extension.h" | 56 #include "chrome/common/extensions/extension.h" |
56 #include "chrome/common/extensions/extension_action.h" | 57 #include "chrome/common/extensions/extension_action.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 disposition_(CURRENT_TAB), | 94 disposition_(CURRENT_TAB), |
94 location_icon_decoration_(new LocationIconDecoration(this)), | 95 location_icon_decoration_(new LocationIconDecoration(this)), |
95 selected_keyword_decoration_( | 96 selected_keyword_decoration_( |
96 new SelectedKeywordDecoration(OmniboxViewMac::GetFieldFont())), | 97 new SelectedKeywordDecoration(OmniboxViewMac::GetFieldFont())), |
97 ev_bubble_decoration_( | 98 ev_bubble_decoration_( |
98 new EVBubbleDecoration(location_icon_decoration_.get(), | 99 new EVBubbleDecoration(location_icon_decoration_.get(), |
99 OmniboxViewMac::GetFieldFont())), | 100 OmniboxViewMac::GetFieldFont())), |
100 plus_decoration_(NULL), | 101 plus_decoration_(NULL), |
101 star_decoration_(new StarDecoration(command_updater)), | 102 star_decoration_(new StarDecoration(command_updater)), |
102 chrome_to_mobile_decoration_(NULL), | 103 chrome_to_mobile_decoration_(NULL), |
104 zoom_decoration_(new ZoomDecoration(toolbar_model)), | |
103 keyword_hint_decoration_( | 105 keyword_hint_decoration_( |
104 new KeywordHintDecoration(OmniboxViewMac::GetFieldFont())), | 106 new KeywordHintDecoration(OmniboxViewMac::GetFieldFont())), |
105 profile_(profile), | 107 profile_(profile), |
106 browser_(browser), | 108 browser_(browser), |
107 toolbar_model_(toolbar_model), | 109 toolbar_model_(toolbar_model), |
108 transition_(content::PageTransitionFromInt( | 110 transition_(content::PageTransitionFromInt( |
109 content::PAGE_TRANSITION_TYPED | | 111 content::PAGE_TRANSITION_TYPED | |
110 content::PAGE_TRANSITION_FROM_ADDRESS_BAR)), | 112 content::PAGE_TRANSITION_FROM_ADDRESS_BAR)), |
111 weak_ptr_factory_(this) { | 113 weak_ptr_factory_(this) { |
112 // Disable Chrome To Mobile for off-the-record and non-synced profiles, | 114 // Disable Chrome To Mobile for off-the-record and non-synced profiles, |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 // TODO(shess): Why SaveStateToContents vs SaveStateToTab? | 242 // TODO(shess): Why SaveStateToContents vs SaveStateToTab? |
241 omnibox_view_->SaveStateToTab(contents); | 243 omnibox_view_->SaveStateToTab(contents); |
242 } | 244 } |
243 | 245 |
244 void LocationBarViewMac::Update(const WebContents* contents, | 246 void LocationBarViewMac::Update(const WebContents* contents, |
245 bool should_restore_state) { | 247 bool should_restore_state) { |
246 bool star_enabled = IsStarEnabled(); | 248 bool star_enabled = IsStarEnabled(); |
247 command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled); | 249 command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled); |
248 star_decoration_->SetVisible(star_enabled); | 250 star_decoration_->SetVisible(star_enabled); |
249 UpdateChromeToMobileEnabled(); | 251 UpdateChromeToMobileEnabled(); |
252 UpdateZoomDecoration(); | |
250 RefreshPageActionDecorations(); | 253 RefreshPageActionDecorations(); |
251 RefreshContentSettingsDecorations(); | 254 RefreshContentSettingsDecorations(); |
252 // OmniboxView restores state if the tab is non-NULL. | 255 // OmniboxView restores state if the tab is non-NULL. |
253 omnibox_view_->Update(should_restore_state ? contents : NULL); | 256 omnibox_view_->Update(should_restore_state ? contents : NULL); |
254 OnChanged(); | 257 OnChanged(); |
255 } | 258 } |
256 | 259 |
257 void LocationBarViewMac::OnAutocompleteAccept( | 260 void LocationBarViewMac::OnAutocompleteAccept( |
258 const GURL& url, | 261 const GURL& url, |
259 WindowOpenDisposition disposition, | 262 WindowOpenDisposition disposition, |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
452 void LocationBarViewMac::TestPageActionPressed(size_t index) { | 455 void LocationBarViewMac::TestPageActionPressed(size_t index) { |
453 DCHECK_LT(index, page_action_decorations_.size()); | 456 DCHECK_LT(index, page_action_decorations_.size()); |
454 if (index < page_action_decorations_.size()) | 457 if (index < page_action_decorations_.size()) |
455 page_action_decorations_[index]->OnMousePressed(NSZeroRect); | 458 page_action_decorations_[index]->OnMousePressed(NSZeroRect); |
456 } | 459 } |
457 | 460 |
458 void LocationBarViewMac::SetEditable(bool editable) { | 461 void LocationBarViewMac::SetEditable(bool editable) { |
459 [field_ setEditable:editable ? YES : NO]; | 462 [field_ setEditable:editable ? YES : NO]; |
460 star_decoration_->SetVisible(IsStarEnabled()); | 463 star_decoration_->SetVisible(IsStarEnabled()); |
461 UpdateChromeToMobileEnabled(); | 464 UpdateChromeToMobileEnabled(); |
465 UpdateZoomDecoration(); | |
462 UpdatePageActions(); | 466 UpdatePageActions(); |
463 Layout(); | 467 Layout(); |
464 } | 468 } |
465 | 469 |
466 bool LocationBarViewMac::IsEditable() { | 470 bool LocationBarViewMac::IsEditable() { |
467 return [field_ isEditable] ? true : false; | 471 return [field_ isEditable] ? true : false; |
468 } | 472 } |
469 | 473 |
470 void LocationBarViewMac::SetStarred(bool starred) { | 474 void LocationBarViewMac::OnImageDecorationsChanged() { |
Scott Hess - ex-Googler
2012/08/16 04:52:58
Suggest OnDecorationsChanged(), I think the fact t
Dan Beam
2012/08/16 08:55:03
Done.
| |
471 star_decoration_->SetStarred(starred); | |
472 | |
473 // TODO(shess): The field-editor frame and cursor rects should not | 475 // TODO(shess): The field-editor frame and cursor rects should not |
474 // change, here. | 476 // change, here. |
475 [field_ updateCursorAndToolTipRects]; | 477 [field_ updateCursorAndToolTipRects]; |
476 [field_ resetFieldEditorFrameIfNeeded]; | 478 [field_ resetFieldEditorFrameIfNeeded]; |
477 [field_ setNeedsDisplay:YES]; | 479 [field_ setNeedsDisplay:YES]; |
478 } | 480 } |
479 | 481 |
482 void LocationBarViewMac::SetStarred(bool starred) { | |
483 star_decoration_->SetStarred(starred); | |
484 OnImageDecorationsChanged(); | |
485 } | |
486 | |
480 void LocationBarViewMac::SetChromeToMobileDecorationLit(bool lit) { | 487 void LocationBarViewMac::SetChromeToMobileDecorationLit(bool lit) { |
481 chrome_to_mobile_decoration_->SetLit(lit); | 488 chrome_to_mobile_decoration_->SetLit(lit); |
489 OnImageDecorationsChanged(); | |
490 } | |
482 | 491 |
483 // TODO(shess): The field-editor frame and cursor rects should not | 492 void LocationBarViewMac::ZoomChangedForActiveTab(bool can_show_bubble) { |
484 // change, here. | 493 UpdateZoomDecoration(); |
485 [field_ updateCursorAndToolTipRects]; | 494 OnImageDecorationsChanged(); |
486 [field_ resetFieldEditorFrameIfNeeded]; | 495 |
487 [field_ setNeedsDisplay:YES]; | 496 // TODO(dbeam): show a zoom bubble when |can_show_bubble| is true, the zoom |
497 // decoration is showing and the wrench menu isn't showing. | |
488 } | 498 } |
489 | 499 |
490 NSPoint LocationBarViewMac::GetBookmarkBubblePoint() const { | 500 NSPoint LocationBarViewMac::GetBookmarkBubblePoint() const { |
491 AutocompleteTextFieldCell* cell = [field_ cell]; | 501 AutocompleteTextFieldCell* cell = [field_ cell]; |
492 const NSRect frame = [cell frameForDecoration:star_decoration_.get() | 502 const NSRect frame = [cell frameForDecoration:star_decoration_.get() |
493 inFrame:[field_ bounds]]; | 503 inFrame:[field_ bounds]]; |
494 const NSPoint point = star_decoration_->GetBubblePointInFrame(frame); | 504 const NSPoint point = star_decoration_->GetBubblePointInFrame(frame); |
495 return [field_ convertPoint:point toView:nil]; | 505 return [field_ convertPoint:point toView:nil]; |
496 } | 506 } |
497 | 507 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
643 // TODO(shess): Shortly, this code will live somewhere else, like in | 653 // TODO(shess): Shortly, this code will live somewhere else, like in |
644 // the constructor. I am still wrestling with how best to deal with | 654 // the constructor. I am still wrestling with how best to deal with |
645 // right-hand decorations, which are not a static set. | 655 // right-hand decorations, which are not a static set. |
646 [cell clearDecorations]; | 656 [cell clearDecorations]; |
647 [cell addLeftDecoration:location_icon_decoration_.get()]; | 657 [cell addLeftDecoration:location_icon_decoration_.get()]; |
648 [cell addLeftDecoration:selected_keyword_decoration_.get()]; | 658 [cell addLeftDecoration:selected_keyword_decoration_.get()]; |
649 [cell addLeftDecoration:ev_bubble_decoration_.get()]; | 659 [cell addLeftDecoration:ev_bubble_decoration_.get()]; |
650 if (plus_decoration_.get()) | 660 if (plus_decoration_.get()) |
651 [cell addRightDecoration:plus_decoration_.get()]; | 661 [cell addRightDecoration:plus_decoration_.get()]; |
652 [cell addRightDecoration:star_decoration_.get()]; | 662 [cell addRightDecoration:star_decoration_.get()]; |
663 [cell addRightDecoration:zoom_decoration_.get()]; | |
653 if (chrome_to_mobile_decoration_.get()) | 664 if (chrome_to_mobile_decoration_.get()) |
654 [cell addRightDecoration:chrome_to_mobile_decoration_.get()]; | 665 [cell addRightDecoration:chrome_to_mobile_decoration_.get()]; |
655 | 666 |
656 // Note that display order is right to left. | 667 // Note that display order is right to left. |
657 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { | 668 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { |
658 [cell addRightDecoration:page_action_decorations_[i]]; | 669 [cell addRightDecoration:page_action_decorations_[i]]; |
659 } | 670 } |
660 for (size_t i = 0; i < content_setting_decorations_.size(); ++i) { | 671 for (size_t i = 0; i < content_setting_decorations_.size(); ++i) { |
661 [cell addRightDecoration:content_setting_decorations_[i]]; | 672 [cell addRightDecoration:content_setting_decorations_[i]]; |
662 } | 673 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
727 void LocationBarViewMac::UpdateChromeToMobileEnabled() { | 738 void LocationBarViewMac::UpdateChromeToMobileEnabled() { |
728 if (!chrome_to_mobile_decoration_.get()) | 739 if (!chrome_to_mobile_decoration_.get()) |
729 return; | 740 return; |
730 | 741 |
731 DCHECK(ChromeToMobileService::IsChromeToMobileEnabled()); | 742 DCHECK(ChromeToMobileService::IsChromeToMobileEnabled()); |
732 bool enabled = [field_ isEditable] && !toolbar_model_->input_in_progress() && | 743 bool enabled = [field_ isEditable] && !toolbar_model_->input_in_progress() && |
733 ChromeToMobileServiceFactory::GetForProfile(profile_)->HasMobiles(); | 744 ChromeToMobileServiceFactory::GetForProfile(profile_)->HasMobiles(); |
734 chrome_to_mobile_decoration_->SetVisible(enabled); | 745 chrome_to_mobile_decoration_->SetVisible(enabled); |
735 command_updater_->UpdateCommandEnabled(IDC_CHROME_TO_MOBILE_PAGE, enabled); | 746 command_updater_->UpdateCommandEnabled(IDC_CHROME_TO_MOBILE_PAGE, enabled); |
736 } | 747 } |
748 | |
749 void LocationBarViewMac::UpdateZoomDecoration() { | |
750 TabContents* tab_contents = GetTabContents(); | |
751 if (!zoom_decoration_.get() || !tab_contents) | |
Scott Hess - ex-Googler
2012/08/16 04:52:58
zoom_decoration_ can't be NULL, AFAICT.
I'm neutr
Dan Beam
2012/08/16 08:55:03
Done.
Scott Hess - ex-Googler
2012/08/16 20:09:31
Seems reasonable. This class is a mess.
| |
752 return; | |
753 | |
754 zoom_decoration_->Update(tab_contents->zoom_controller()); | |
755 } | |
OLD | NEW |