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