OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "chrome/browser/search_engines/template_url_service.h" | 27 #include "chrome/browser/search_engines/template_url_service.h" |
28 #include "chrome/browser/search_engines/template_url_service_factory.h" | 28 #include "chrome/browser/search_engines/template_url_service_factory.h" |
29 #include "chrome/browser/ui/browser_instant_controller.h" | 29 #include "chrome/browser/ui/browser_instant_controller.h" |
30 #include "chrome/browser/ui/browser_list.h" | 30 #include "chrome/browser/ui/browser_list.h" |
31 #import "chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.h
" | 31 #import "chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.h
" |
32 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" | 32 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" |
33 #import "chrome/browser/ui/cocoa/first_run_bubble_controller.h" | 33 #import "chrome/browser/ui/cocoa/first_run_bubble_controller.h" |
34 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" | 34 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" |
35 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" | 35 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" |
36 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h" | 36 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h" |
| 37 #import "chrome/browser/ui/cocoa/location_bar/generated_credit_card_decoration.h
" |
37 #import "chrome/browser/ui/cocoa/location_bar/ev_bubble_decoration.h" | 38 #import "chrome/browser/ui/cocoa/location_bar/ev_bubble_decoration.h" |
38 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h" | 39 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h" |
39 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h" | 40 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h" |
40 #import "chrome/browser/ui/cocoa/location_bar/mic_search_decoration.h" | 41 #import "chrome/browser/ui/cocoa/location_bar/mic_search_decoration.h" |
41 #import "chrome/browser/ui/cocoa/location_bar/page_action_decoration.h" | 42 #import "chrome/browser/ui/cocoa/location_bar/page_action_decoration.h" |
42 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h" | 43 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h" |
43 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" | 44 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" |
44 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h" | 45 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h" |
45 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" | 46 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" |
46 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | 47 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 omnibox_view_(new OmniboxViewMac(this, profile, command_updater, field)), | 87 omnibox_view_(new OmniboxViewMac(this, profile, command_updater, field)), |
87 field_(field), | 88 field_(field), |
88 location_icon_decoration_(new LocationIconDecoration(this)), | 89 location_icon_decoration_(new LocationIconDecoration(this)), |
89 selected_keyword_decoration_(new SelectedKeywordDecoration()), | 90 selected_keyword_decoration_(new SelectedKeywordDecoration()), |
90 ev_bubble_decoration_( | 91 ev_bubble_decoration_( |
91 new EVBubbleDecoration(location_icon_decoration_.get())), | 92 new EVBubbleDecoration(location_icon_decoration_.get())), |
92 star_decoration_(new StarDecoration(command_updater)), | 93 star_decoration_(new StarDecoration(command_updater)), |
93 zoom_decoration_(new ZoomDecoration(this)), | 94 zoom_decoration_(new ZoomDecoration(this)), |
94 keyword_hint_decoration_(new KeywordHintDecoration()), | 95 keyword_hint_decoration_(new KeywordHintDecoration()), |
95 mic_search_decoration_(new MicSearchDecoration(command_updater)), | 96 mic_search_decoration_(new MicSearchDecoration(command_updater)), |
| 97 generated_credit_card_decoration_( |
| 98 new GeneratedCreditCardDecoration(this)), |
96 profile_(profile), | 99 profile_(profile), |
97 browser_(browser), | 100 browser_(browser), |
98 weak_ptr_factory_(this) { | 101 weak_ptr_factory_(this) { |
99 | 102 |
100 for (size_t i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { | 103 for (size_t i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { |
101 DCHECK_EQ(i, content_setting_decorations_.size()); | 104 DCHECK_EQ(i, content_setting_decorations_.size()); |
102 ContentSettingsType type = static_cast<ContentSettingsType>(i); | 105 ContentSettingsType type = static_cast<ContentSettingsType>(i); |
103 content_setting_decorations_.push_back( | 106 content_setting_decorations_.push_back( |
104 new ContentSettingDecoration(type, this, profile_)); | 107 new ContentSettingDecoration(type, this, profile_)); |
105 } | 108 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 content::Source<LocationBar>(this), | 195 content::Source<LocationBar>(this), |
193 content::NotificationService::NoDetails()); | 196 content::NotificationService::NoDetails()); |
194 } | 197 } |
195 } | 198 } |
196 | 199 |
197 void LocationBarViewMac::UpdateOpenPDFInReaderPrompt() { | 200 void LocationBarViewMac::UpdateOpenPDFInReaderPrompt() { |
198 // Not implemented on Mac. | 201 // Not implemented on Mac. |
199 } | 202 } |
200 | 203 |
201 void LocationBarViewMac::UpdateGeneratedCreditCardView() { | 204 void LocationBarViewMac::UpdateGeneratedCreditCardView() { |
202 // TODO(dbeam): encourage groby@ to implement via prodding or chocolate. | 205 generated_credit_card_decoration_->Update(); |
203 NOTIMPLEMENTED(); | |
204 } | 206 } |
205 | 207 |
206 void LocationBarViewMac::SaveStateToContents(WebContents* contents) { | 208 void LocationBarViewMac::SaveStateToContents(WebContents* contents) { |
207 // TODO(shess): Why SaveStateToContents vs SaveStateToTab? | 209 // TODO(shess): Why SaveStateToContents vs SaveStateToTab? |
208 omnibox_view_->SaveStateToTab(contents); | 210 omnibox_view_->SaveStateToTab(contents); |
209 } | 211 } |
210 | 212 |
211 void LocationBarViewMac::Revert() { | 213 void LocationBarViewMac::Revert() { |
212 omnibox_view_->RevertAll(); | 214 omnibox_view_->RevertAll(); |
213 } | 215 } |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 } else { | 317 } else { |
316 const NSRect frame = | 318 const NSRect frame = |
317 [cell frameForDecoration:location_icon_decoration_.get() | 319 [cell frameForDecoration:location_icon_decoration_.get() |
318 inFrame:[field_ bounds]]; | 320 inFrame:[field_ bounds]]; |
319 const NSPoint point = | 321 const NSPoint point = |
320 location_icon_decoration_->GetBubblePointInFrame(frame); | 322 location_icon_decoration_->GetBubblePointInFrame(frame); |
321 return [field_ convertPoint:point toView:nil]; | 323 return [field_ convertPoint:point toView:nil]; |
322 } | 324 } |
323 } | 325 } |
324 | 326 |
| 327 NSPoint LocationBarViewMac::GetGeneratedCreditCardBubblePoint() const { |
| 328 AutocompleteTextFieldCell* cell = [field_ cell]; |
| 329 const NSRect frame = |
| 330 [cell frameForDecoration:generated_credit_card_decoration_.get() |
| 331 inFrame:[field_ bounds]]; |
| 332 const NSPoint point = |
| 333 generated_credit_card_decoration_->GetBubblePointInFrame(frame); |
| 334 return [field_ convertPoint:point toView:nil]; |
| 335 } |
| 336 |
325 void LocationBarViewMac::OnDecorationsChanged() { | 337 void LocationBarViewMac::OnDecorationsChanged() { |
326 // TODO(shess): The field-editor frame and cursor rects should not | 338 // TODO(shess): The field-editor frame and cursor rects should not |
327 // change, here. | 339 // change, here. |
328 [field_ updateMouseTracking]; | 340 [field_ updateMouseTracking]; |
329 [field_ resetFieldEditorFrameIfNeeded]; | 341 [field_ resetFieldEditorFrameIfNeeded]; |
330 [field_ setNeedsDisplay:YES]; | 342 [field_ setNeedsDisplay:YES]; |
331 } | 343 } |
332 | 344 |
333 // TODO(shess): This function should over time grow to closely match | 345 // TODO(shess): This function should over time grow to closely match |
334 // the views Layout() function. | 346 // the views Layout() function. |
335 void LocationBarViewMac::Layout() { | 347 void LocationBarViewMac::Layout() { |
336 AutocompleteTextFieldCell* cell = [field_ cell]; | 348 AutocompleteTextFieldCell* cell = [field_ cell]; |
337 | 349 |
338 // Reset the left-hand decorations. | 350 // Reset the left-hand decorations. |
339 // TODO(shess): Shortly, this code will live somewhere else, like in | 351 // TODO(shess): Shortly, this code will live somewhere else, like in |
340 // the constructor. I am still wrestling with how best to deal with | 352 // the constructor. I am still wrestling with how best to deal with |
341 // right-hand decorations, which are not a static set. | 353 // right-hand decorations, which are not a static set. |
342 [cell clearDecorations]; | 354 [cell clearDecorations]; |
343 [cell addLeftDecoration:location_icon_decoration_.get()]; | 355 [cell addLeftDecoration:location_icon_decoration_.get()]; |
344 [cell addLeftDecoration:selected_keyword_decoration_.get()]; | 356 [cell addLeftDecoration:selected_keyword_decoration_.get()]; |
345 [cell addLeftDecoration:ev_bubble_decoration_.get()]; | 357 [cell addLeftDecoration:ev_bubble_decoration_.get()]; |
346 [cell addRightDecoration:star_decoration_.get()]; | 358 [cell addRightDecoration:star_decoration_.get()]; |
347 [cell addRightDecoration:zoom_decoration_.get()]; | 359 [cell addRightDecoration:zoom_decoration_.get()]; |
| 360 [cell addRightDecoration:generated_credit_card_decoration_.get()]; |
348 | 361 |
349 // Note that display order is right to left. | 362 // Note that display order is right to left. |
350 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { | 363 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { |
351 [cell addRightDecoration:page_action_decorations_[i]]; | 364 [cell addRightDecoration:page_action_decorations_[i]]; |
352 } | 365 } |
353 | 366 |
354 for (ScopedVector<ContentSettingDecoration>::iterator i = | 367 for (ScopedVector<ContentSettingDecoration>::iterator i = |
355 content_setting_decorations_.begin(); | 368 content_setting_decorations_.begin(); |
356 i != content_setting_decorations_.end(); ++i) { | 369 i != content_setting_decorations_.end(); ++i) { |
357 [cell addRightDecoration:*i]; | 370 [cell addRightDecoration:*i]; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 | 473 |
461 void LocationBarViewMac::Update(const WebContents* contents) { | 474 void LocationBarViewMac::Update(const WebContents* contents) { |
462 command_updater()->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, IsStarEnabled()); | 475 command_updater()->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, IsStarEnabled()); |
463 command_updater()->UpdateCommandEnabled(IDC_BOOKMARK_PAGE_FROM_STAR, | 476 command_updater()->UpdateCommandEnabled(IDC_BOOKMARK_PAGE_FROM_STAR, |
464 IsStarEnabled()); | 477 IsStarEnabled()); |
465 UpdateStarDecorationVisibility(); | 478 UpdateStarDecorationVisibility(); |
466 UpdateZoomDecoration(); | 479 UpdateZoomDecoration(); |
467 RefreshPageActionDecorations(); | 480 RefreshPageActionDecorations(); |
468 RefreshContentSettingsDecorations(); | 481 RefreshContentSettingsDecorations(); |
469 UpdateMicSearchDecorationVisibility(); | 482 UpdateMicSearchDecorationVisibility(); |
| 483 UpdateGeneratedCreditCardView(); |
470 if (contents) | 484 if (contents) |
471 omnibox_view_->OnTabChanged(contents); | 485 omnibox_view_->OnTabChanged(contents); |
472 else | 486 else |
473 omnibox_view_->Update(); | 487 omnibox_view_->Update(); |
474 OnChanged(); | 488 OnChanged(); |
475 } | 489 } |
476 | 490 |
477 void LocationBarViewMac::OnChanged() { | 491 void LocationBarViewMac::OnChanged() { |
478 // Update the location-bar icon. | 492 // Update the location-bar icon. |
479 const int resource_id = omnibox_view_->GetIcon(); | 493 const int resource_id = omnibox_view_->GetIcon(); |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 } | 696 } |
683 | 697 |
684 bool LocationBarViewMac::UpdateMicSearchDecorationVisibility() { | 698 bool LocationBarViewMac::UpdateMicSearchDecorationVisibility() { |
685 bool is_visible = !GetToolbarModel()->input_in_progress() && | 699 bool is_visible = !GetToolbarModel()->input_in_progress() && |
686 browser_->search_model()->voice_search_supported(); | 700 browser_->search_model()->voice_search_supported(); |
687 if (mic_search_decoration_->IsVisible() == is_visible) | 701 if (mic_search_decoration_->IsVisible() == is_visible) |
688 return false; | 702 return false; |
689 mic_search_decoration_->SetVisible(is_visible); | 703 mic_search_decoration_->SetVisible(is_visible); |
690 return true; | 704 return true; |
691 } | 705 } |
OLD | NEW |