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.h" | 37 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" |
38 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" | 38 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" |
39 #import "chrome/browser/ui/cocoa/location_bar/chrome_to_mobile_decoration.h" | 39 #import "chrome/browser/ui/cocoa/location_bar/chrome_to_mobile_decoration.h" |
40 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h" | 40 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h" |
41 #import "chrome/browser/ui/cocoa/location_bar/ev_bubble_decoration.h" | 41 #import "chrome/browser/ui/cocoa/location_bar/ev_bubble_decoration.h" |
42 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h" | 42 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h" |
43 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h" | 43 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h" |
44 #import "chrome/browser/ui/cocoa/location_bar/page_action_decoration.h" | 44 #import "chrome/browser/ui/cocoa/location_bar/page_action_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/extensions/extension.h" | 55 #include "chrome/common/extensions/extension.h" |
55 #include "chrome/common/extensions/extension_action.h" | 56 #include "chrome/common/extensions/extension_action.h" |
56 #include "chrome/common/extensions/extension_resource.h" | 57 #include "chrome/common/extensions/extension_resource.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 field_(field), | 91 field_(field), |
91 disposition_(CURRENT_TAB), | 92 disposition_(CURRENT_TAB), |
92 location_icon_decoration_(new LocationIconDecoration(this)), | 93 location_icon_decoration_(new LocationIconDecoration(this)), |
93 selected_keyword_decoration_( | 94 selected_keyword_decoration_( |
94 new SelectedKeywordDecoration(OmniboxViewMac::GetFieldFont())), | 95 new SelectedKeywordDecoration(OmniboxViewMac::GetFieldFont())), |
95 ev_bubble_decoration_( | 96 ev_bubble_decoration_( |
96 new EVBubbleDecoration(location_icon_decoration_.get(), | 97 new EVBubbleDecoration(location_icon_decoration_.get(), |
97 OmniboxViewMac::GetFieldFont())), | 98 OmniboxViewMac::GetFieldFont())), |
98 star_decoration_(new StarDecoration(command_updater)), | 99 star_decoration_(new StarDecoration(command_updater)), |
99 chrome_to_mobile_decoration_(nil), | 100 chrome_to_mobile_decoration_(nil), |
| 101 zoom_decoration_(new ZoomDecoration(toolbar_model)), |
100 keyword_hint_decoration_( | 102 keyword_hint_decoration_( |
101 new KeywordHintDecoration(OmniboxViewMac::GetFieldFont())), | 103 new KeywordHintDecoration(OmniboxViewMac::GetFieldFont())), |
102 profile_(profile), | 104 profile_(profile), |
103 browser_(browser), | 105 browser_(browser), |
104 toolbar_model_(toolbar_model), | 106 toolbar_model_(toolbar_model), |
105 transition_(content::PageTransitionFromInt( | 107 transition_(content::PageTransitionFromInt( |
106 content::PAGE_TRANSITION_TYPED | | 108 content::PAGE_TRANSITION_TYPED | |
107 content::PAGE_TRANSITION_FROM_ADDRESS_BAR)), | 109 content::PAGE_TRANSITION_FROM_ADDRESS_BAR)), |
108 weak_ptr_factory_(this) { | 110 weak_ptr_factory_(this) { |
109 // Disable Chrome To Mobile for off-the-record and non-synced profiles, | 111 // Disable Chrome To Mobile for off-the-record and non-synced profiles, |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 // TODO(shess): Why SaveStateToContents vs SaveStateToTab? | 235 // TODO(shess): Why SaveStateToContents vs SaveStateToTab? |
234 omnibox_view_->SaveStateToTab(contents); | 236 omnibox_view_->SaveStateToTab(contents); |
235 } | 237 } |
236 | 238 |
237 void LocationBarViewMac::Update(const WebContents* contents, | 239 void LocationBarViewMac::Update(const WebContents* contents, |
238 bool should_restore_state) { | 240 bool should_restore_state) { |
239 bool star_enabled = IsStarEnabled(); | 241 bool star_enabled = IsStarEnabled(); |
240 command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled); | 242 command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled); |
241 star_decoration_->SetVisible(star_enabled); | 243 star_decoration_->SetVisible(star_enabled); |
242 UpdateChromeToMobileEnabled(); | 244 UpdateChromeToMobileEnabled(); |
| 245 const TabContents* tc = TabContents::FromWebContents(contents); |
| 246 zoom_decoration_->Update(tc->zoom_controller()); |
243 RefreshPageActionDecorations(); | 247 RefreshPageActionDecorations(); |
244 RefreshContentSettingsDecorations(); | 248 RefreshContentSettingsDecorations(); |
245 // OmniboxView restores state if the tab is non-NULL. | 249 // OmniboxView restores state if the tab is non-NULL. |
246 omnibox_view_->Update(should_restore_state ? contents : NULL); | 250 omnibox_view_->Update(should_restore_state ? contents : NULL); |
247 OnChanged(); | 251 OnChanged(); |
248 } | 252 } |
249 | 253 |
250 void LocationBarViewMac::OnAutocompleteAccept( | 254 void LocationBarViewMac::OnAutocompleteAccept( |
251 const GURL& url, | 255 const GURL& url, |
252 WindowOpenDisposition disposition, | 256 WindowOpenDisposition disposition, |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 void LocationBarViewMac::TestPageActionPressed(size_t index) { | 449 void LocationBarViewMac::TestPageActionPressed(size_t index) { |
446 DCHECK_LT(index, page_action_decorations_.size()); | 450 DCHECK_LT(index, page_action_decorations_.size()); |
447 if (index < page_action_decorations_.size()) | 451 if (index < page_action_decorations_.size()) |
448 page_action_decorations_[index]->OnMousePressed(NSZeroRect); | 452 page_action_decorations_[index]->OnMousePressed(NSZeroRect); |
449 } | 453 } |
450 | 454 |
451 void LocationBarViewMac::SetEditable(bool editable) { | 455 void LocationBarViewMac::SetEditable(bool editable) { |
452 [field_ setEditable:editable ? YES : NO]; | 456 [field_ setEditable:editable ? YES : NO]; |
453 star_decoration_->SetVisible(IsStarEnabled()); | 457 star_decoration_->SetVisible(IsStarEnabled()); |
454 UpdateChromeToMobileEnabled(); | 458 UpdateChromeToMobileEnabled(); |
| 459 zoom_decoration_->Update(GetTabContents()->zoom_controller()); |
455 UpdatePageActions(); | 460 UpdatePageActions(); |
456 Layout(); | 461 Layout(); |
457 } | 462 } |
458 | 463 |
459 bool LocationBarViewMac::IsEditable() { | 464 bool LocationBarViewMac::IsEditable() { |
460 return [field_ isEditable] ? true : false; | 465 return [field_ isEditable] ? true : false; |
461 } | 466 } |
462 | 467 |
463 void LocationBarViewMac::SetStarred(bool starred) { | 468 void LocationBarViewMac::OnImageDecorationsChanged() { |
464 star_decoration_->SetStarred(starred); | |
465 | |
466 // TODO(shess): The field-editor frame and cursor rects should not | 469 // TODO(shess): The field-editor frame and cursor rects should not |
467 // change, here. | 470 // change, here. |
468 [field_ updateCursorAndToolTipRects]; | 471 [field_ updateCursorAndToolTipRects]; |
469 [field_ resetFieldEditorFrameIfNeeded]; | 472 [field_ resetFieldEditorFrameIfNeeded]; |
470 [field_ setNeedsDisplay:YES]; | 473 [field_ setNeedsDisplay:YES]; |
471 } | 474 } |
472 | 475 |
| 476 void LocationBarViewMac::SetStarred(bool starred) { |
| 477 star_decoration_->SetStarred(starred); |
| 478 OnImageDecorationsChanged(); |
| 479 } |
| 480 |
473 void LocationBarViewMac::SetChromeToMobileDecorationLit(bool lit) { | 481 void LocationBarViewMac::SetChromeToMobileDecorationLit(bool lit) { |
474 chrome_to_mobile_decoration_->SetLit(lit); | 482 chrome_to_mobile_decoration_->SetLit(lit); |
| 483 OnImageDecorationsChanged(); |
| 484 } |
475 | 485 |
476 // TODO(shess): The field-editor frame and cursor rects should not | 486 void LocationBarViewMac::ZoomChangedForActiveTab(bool can_show_bubble) { |
477 // change, here. | 487 zoom_decoration_->Update(GetTabContents()->zoom_controller()); |
478 [field_ updateCursorAndToolTipRects]; | 488 OnImageDecorationsChanged(); |
479 [field_ resetFieldEditorFrameIfNeeded]; | 489 |
480 [field_ setNeedsDisplay:YES]; | 490 //if (can_show_bubble) |
| 491 // [controller_ showZoomBubble]; |
481 } | 492 } |
482 | 493 |
483 NSPoint LocationBarViewMac::GetBookmarkBubblePoint() const { | 494 NSPoint LocationBarViewMac::GetBookmarkBubblePoint() const { |
484 AutocompleteTextFieldCell* cell = [field_ cell]; | 495 AutocompleteTextFieldCell* cell = [field_ cell]; |
485 const NSRect frame = [cell frameForDecoration:star_decoration_.get() | 496 const NSRect frame = [cell frameForDecoration:star_decoration_.get() |
486 inFrame:[field_ bounds]]; | 497 inFrame:[field_ bounds]]; |
487 const NSPoint point = star_decoration_->GetBubblePointInFrame(frame); | 498 const NSPoint point = star_decoration_->GetBubblePointInFrame(frame); |
488 return [field_ convertPoint:point toView:nil]; | 499 return [field_ convertPoint:point toView:nil]; |
489 } | 500 } |
490 | 501 |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 | 645 |
635 // Reset the left-hand decorations. | 646 // Reset the left-hand decorations. |
636 // TODO(shess): Shortly, this code will live somewhere else, like in | 647 // TODO(shess): Shortly, this code will live somewhere else, like in |
637 // 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 |
638 // right-hand decorations, which are not a static set. | 649 // right-hand decorations, which are not a static set. |
639 [cell clearDecorations]; | 650 [cell clearDecorations]; |
640 [cell addLeftDecoration:location_icon_decoration_.get()]; | 651 [cell addLeftDecoration:location_icon_decoration_.get()]; |
641 [cell addLeftDecoration:selected_keyword_decoration_.get()]; | 652 [cell addLeftDecoration:selected_keyword_decoration_.get()]; |
642 [cell addLeftDecoration:ev_bubble_decoration_.get()]; | 653 [cell addLeftDecoration:ev_bubble_decoration_.get()]; |
643 [cell addRightDecoration:star_decoration_.get()]; | 654 [cell addRightDecoration:star_decoration_.get()]; |
| 655 [cell addRightDecoration:zoom_decoration_.get()]; |
644 if (chrome_to_mobile_decoration_.get()) | 656 if (chrome_to_mobile_decoration_.get()) |
645 [cell addRightDecoration:chrome_to_mobile_decoration_.get()]; | 657 [cell addRightDecoration:chrome_to_mobile_decoration_.get()]; |
646 | 658 |
647 // Note that display order is right to left. | 659 // Note that display order is right to left. |
648 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { | 660 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { |
649 [cell addRightDecoration:page_action_decorations_[i]]; | 661 [cell addRightDecoration:page_action_decorations_[i]]; |
650 } | 662 } |
651 for (size_t i = 0; i < content_setting_decorations_.size(); ++i) { | 663 for (size_t i = 0; i < content_setting_decorations_.size(); ++i) { |
652 [cell addRightDecoration:content_setting_decorations_[i]]; | 664 [cell addRightDecoration:content_setting_decorations_[i]]; |
653 } | 665 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 void LocationBarViewMac::UpdateChromeToMobileEnabled() { | 730 void LocationBarViewMac::UpdateChromeToMobileEnabled() { |
719 if (!chrome_to_mobile_decoration_.get()) | 731 if (!chrome_to_mobile_decoration_.get()) |
720 return; | 732 return; |
721 | 733 |
722 DCHECK(ChromeToMobileService::IsChromeToMobileEnabled()); | 734 DCHECK(ChromeToMobileService::IsChromeToMobileEnabled()); |
723 bool enabled = [field_ isEditable] && !toolbar_model_->input_in_progress() && | 735 bool enabled = [field_ isEditable] && !toolbar_model_->input_in_progress() && |
724 ChromeToMobileServiceFactory::GetForProfile(profile_)->HasDevices(); | 736 ChromeToMobileServiceFactory::GetForProfile(profile_)->HasDevices(); |
725 chrome_to_mobile_decoration_->SetVisible(enabled); | 737 chrome_to_mobile_decoration_->SetVisible(enabled); |
726 command_updater_->UpdateCommandEnabled(IDC_CHROME_TO_MOBILE_PAGE, enabled); | 738 command_updater_->UpdateCommandEnabled(IDC_CHROME_TO_MOBILE_PAGE, enabled); |
727 } | 739 } |
OLD | NEW |