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 24 matching lines...) Expand all Loading... |
35 #import "chrome/browser/ui/cocoa/first_run_bubble_controller.h" | 35 #import "chrome/browser/ui/cocoa/first_run_bubble_controller.h" |
36 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" | 36 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" |
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/content_setting_decoration.h" | 38 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h" |
39 #import "chrome/browser/ui/cocoa/location_bar/ev_bubble_decoration.h" | 39 #import "chrome/browser/ui/cocoa/location_bar/ev_bubble_decoration.h" |
40 #import "chrome/browser/ui/cocoa/location_bar/generated_credit_card_decoration.h
" | 40 #import "chrome/browser/ui/cocoa/location_bar/generated_credit_card_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/manage_passwords_decoration.h" | 43 #import "chrome/browser/ui/cocoa/location_bar/manage_passwords_decoration.h" |
44 #import "chrome/browser/ui/cocoa/location_bar/mic_search_decoration.h" | 44 #import "chrome/browser/ui/cocoa/location_bar/mic_search_decoration.h" |
45 #import "chrome/browser/ui/cocoa/location_bar/origin_chip_decoration.h" | |
46 #import "chrome/browser/ui/cocoa/location_bar/page_action_decoration.h" | 45 #import "chrome/browser/ui/cocoa/location_bar/page_action_decoration.h" |
47 #import "chrome/browser/ui/cocoa/location_bar/search_button_decoration.h" | 46 #import "chrome/browser/ui/cocoa/location_bar/search_button_decoration.h" |
48 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h" | 47 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h" |
49 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" | 48 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" |
50 #import "chrome/browser/ui/cocoa/location_bar/translate_decoration.h" | 49 #import "chrome/browser/ui/cocoa/location_bar/translate_decoration.h" |
51 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h" | 50 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h" |
52 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" | 51 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" |
53 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | 52 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" |
54 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" | 53 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" |
55 #import "chrome/browser/ui/omnibox/omnibox_popup_model.h" | 54 #import "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 edit_bookmarks_enabled_.Init( | 127 edit_bookmarks_enabled_.Init( |
129 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(), | 128 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(), |
130 base::Bind(&LocationBarViewMac::OnEditBookmarksEnabledChanged, | 129 base::Bind(&LocationBarViewMac::OnEditBookmarksEnabledChanged, |
131 base::Unretained(this))); | 130 base::Unretained(this))); |
132 | 131 |
133 browser_->search_model()->AddObserver(this); | 132 browser_->search_model()->AddObserver(this); |
134 | 133 |
135 [[field_ cell] setIsPopupMode: | 134 [[field_ cell] setIsPopupMode: |
136 !browser->SupportsWindowFeature(Browser::FEATURE_TABSTRIP)]; | 135 !browser->SupportsWindowFeature(Browser::FEATURE_TABSTRIP)]; |
137 | 136 |
138 if (chrome::ShouldDisplayOriginChip()) | |
139 origin_chip_decoration_.reset(new OriginChipDecoration( | |
140 this, location_icon_decoration_.get())); | |
141 | |
142 // Sets images for the decorations, and performs a layout. This call ensures | 137 // Sets images for the decorations, and performs a layout. This call ensures |
143 // that this class is in a consistent state after initialization. | 138 // that this class is in a consistent state after initialization. |
144 OnChanged(); | 139 OnChanged(); |
145 } | 140 } |
146 | 141 |
147 LocationBarViewMac::~LocationBarViewMac() { | 142 LocationBarViewMac::~LocationBarViewMac() { |
148 // Disconnect from cell in case it outlives us. | 143 // Disconnect from cell in case it outlives us. |
149 [[field_ cell] clearDecorations]; | 144 [[field_ cell] clearDecorations]; |
150 | 145 |
151 browser_->search_model()->RemoveObserver(this); | 146 browser_->search_model()->RemoveObserver(this); |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 | 351 |
357 NSPoint LocationBarViewMac::GetTranslateBubblePoint() const { | 352 NSPoint LocationBarViewMac::GetTranslateBubblePoint() const { |
358 return [field_ bubblePointForDecoration:translate_decoration_.get()]; | 353 return [field_ bubblePointForDecoration:translate_decoration_.get()]; |
359 } | 354 } |
360 | 355 |
361 NSPoint LocationBarViewMac::GetManagePasswordsBubblePoint() const { | 356 NSPoint LocationBarViewMac::GetManagePasswordsBubblePoint() const { |
362 return [field_ bubblePointForDecoration:manage_passwords_decoration_.get()]; | 357 return [field_ bubblePointForDecoration:manage_passwords_decoration_.get()]; |
363 } | 358 } |
364 | 359 |
365 NSPoint LocationBarViewMac::GetPageInfoBubblePoint() const { | 360 NSPoint LocationBarViewMac::GetPageInfoBubblePoint() const { |
366 if (origin_chip_decoration_ && origin_chip_decoration_->IsVisible()) { | 361 if (ev_bubble_decoration_->IsVisible()) { |
367 return [field_ bubblePointForDecoration:origin_chip_decoration_.get()]; | |
368 } else if (ev_bubble_decoration_->IsVisible()) { | |
369 return [field_ bubblePointForDecoration:ev_bubble_decoration_.get()]; | 362 return [field_ bubblePointForDecoration:ev_bubble_decoration_.get()]; |
370 } else { | 363 } else { |
371 return [field_ bubblePointForDecoration:location_icon_decoration_.get()]; | 364 return [field_ bubblePointForDecoration:location_icon_decoration_.get()]; |
372 } | 365 } |
373 } | 366 } |
374 | 367 |
375 NSPoint LocationBarViewMac::GetGeneratedCreditCardBubblePoint() const { | 368 NSPoint LocationBarViewMac::GetGeneratedCreditCardBubblePoint() const { |
376 return | 369 return |
377 [field_ bubblePointForDecoration:generated_credit_card_decoration_.get()]; | 370 [field_ bubblePointForDecoration:generated_credit_card_decoration_.get()]; |
378 } | 371 } |
379 | 372 |
380 void LocationBarViewMac::OnDecorationsChanged() { | 373 void LocationBarViewMac::OnDecorationsChanged() { |
381 // TODO(shess): The field-editor frame and cursor rects should not | 374 // TODO(shess): The field-editor frame and cursor rects should not |
382 // change, here. | 375 // change, here. |
383 [field_ updateMouseTracking]; | 376 [field_ updateMouseTracking]; |
384 [field_ resetFieldEditorFrameIfNeeded]; | 377 [field_ resetFieldEditorFrameIfNeeded]; |
385 [field_ setNeedsDisplay:YES]; | 378 [field_ setNeedsDisplay:YES]; |
386 } | 379 } |
387 | 380 |
388 // TODO(shess): This function should over time grow to closely match | 381 // TODO(shess): This function should over time grow to closely match |
389 // the views Layout() function. | 382 // the views Layout() function. |
390 void LocationBarViewMac::Layout() { | 383 void LocationBarViewMac::Layout() { |
391 AutocompleteTextFieldCell* cell = [field_ cell]; | 384 AutocompleteTextFieldCell* cell = [field_ cell]; |
392 | 385 |
393 // Reset the left-hand decorations. | 386 // Reset the left-hand decorations. |
394 // TODO(shess): Shortly, this code will live somewhere else, like in | 387 // TODO(shess): Shortly, this code will live somewhere else, like in |
395 // the constructor. I am still wrestling with how best to deal with | 388 // the constructor. I am still wrestling with how best to deal with |
396 // right-hand decorations, which are not a static set. | 389 // right-hand decorations, which are not a static set. |
397 [cell clearDecorations]; | 390 [cell clearDecorations]; |
398 if (origin_chip_decoration_.get()) | |
399 [cell addLeftDecoration:origin_chip_decoration_.get()]; | |
400 [cell addLeftDecoration:location_icon_decoration_.get()]; | 391 [cell addLeftDecoration:location_icon_decoration_.get()]; |
401 [cell addLeftDecoration:selected_keyword_decoration_.get()]; | 392 [cell addLeftDecoration:selected_keyword_decoration_.get()]; |
402 if (!origin_chip_decoration_.get()) | 393 [cell addLeftDecoration:ev_bubble_decoration_.get()]; |
403 [cell addLeftDecoration:ev_bubble_decoration_.get()]; | |
404 [cell addRightDecoration:search_button_decoration_.get()]; | 394 [cell addRightDecoration:search_button_decoration_.get()]; |
405 [cell addRightDecoration:star_decoration_.get()]; | 395 [cell addRightDecoration:star_decoration_.get()]; |
406 [cell addRightDecoration:translate_decoration_.get()]; | 396 [cell addRightDecoration:translate_decoration_.get()]; |
407 [cell addRightDecoration:zoom_decoration_.get()]; | 397 [cell addRightDecoration:zoom_decoration_.get()]; |
408 [cell addRightDecoration:generated_credit_card_decoration_.get()]; | 398 [cell addRightDecoration:generated_credit_card_decoration_.get()]; |
409 [cell addRightDecoration:manage_passwords_decoration_.get()]; | 399 [cell addRightDecoration:manage_passwords_decoration_.get()]; |
410 | 400 |
411 // Note that display order is right to left. | 401 // Note that display order is right to left. |
412 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { | 402 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { |
413 [cell addRightDecoration:page_action_decorations_[i]]; | 403 [cell addRightDecoration:page_action_decorations_[i]]; |
414 } | 404 } |
415 | 405 |
416 for (ScopedVector<ContentSettingDecoration>::iterator i = | 406 for (ScopedVector<ContentSettingDecoration>::iterator i = |
417 content_setting_decorations_.begin(); | 407 content_setting_decorations_.begin(); |
418 i != content_setting_decorations_.end(); ++i) { | 408 i != content_setting_decorations_.end(); ++i) { |
419 [cell addRightDecoration:*i]; | 409 [cell addRightDecoration:*i]; |
420 } | 410 } |
421 | 411 |
422 [cell addRightDecoration:keyword_hint_decoration_.get()]; | 412 [cell addRightDecoration:keyword_hint_decoration_.get()]; |
423 [cell addRightDecoration:mic_search_decoration_.get()]; | 413 [cell addRightDecoration:mic_search_decoration_.get()]; |
424 | 414 |
425 // By default only the location icon is visible. | 415 // By default only the location icon is visible. |
426 location_icon_decoration_->SetVisible(!origin_chip_decoration_.get() || | 416 location_icon_decoration_->SetVisible(true); |
427 !origin_chip_decoration_->IsVisible()); | |
428 selected_keyword_decoration_->SetVisible(false); | 417 selected_keyword_decoration_->SetVisible(false); |
429 ev_bubble_decoration_->SetVisible(false); | 418 ev_bubble_decoration_->SetVisible(false); |
430 keyword_hint_decoration_->SetVisible(false); | 419 keyword_hint_decoration_->SetVisible(false); |
431 | 420 |
432 // Get the keyword to use for keyword-search and hinting. | 421 // Get the keyword to use for keyword-search and hinting. |
433 const base::string16 keyword = omnibox_view_->model()->keyword(); | 422 const base::string16 keyword = omnibox_view_->model()->keyword(); |
434 base::string16 short_name; | 423 base::string16 short_name; |
435 bool is_extension_keyword = false; | 424 bool is_extension_keyword = false; |
436 if (!keyword.empty()) { | 425 if (!keyword.empty()) { |
437 short_name = TemplateURLServiceFactory::GetForProfile(profile())-> | 426 short_name = TemplateURLServiceFactory::GetForProfile(profile())-> |
438 GetKeywordShortName(keyword, &is_extension_keyword); | 427 GetKeywordShortName(keyword, &is_extension_keyword); |
439 } | 428 } |
440 | 429 |
441 const bool is_keyword_hint = omnibox_view_->model()->is_keyword_hint(); | 430 const bool is_keyword_hint = omnibox_view_->model()->is_keyword_hint(); |
442 if (!keyword.empty() && !is_keyword_hint) { | 431 if (!keyword.empty() && !is_keyword_hint) { |
443 // Switch from location icon to keyword mode. | 432 // Switch from location icon to keyword mode. |
444 location_icon_decoration_->SetVisible(false); | 433 location_icon_decoration_->SetVisible(false); |
445 selected_keyword_decoration_->SetVisible(true); | 434 selected_keyword_decoration_->SetVisible(true); |
446 selected_keyword_decoration_->SetKeyword(short_name, is_extension_keyword); | 435 selected_keyword_decoration_->SetKeyword(short_name, is_extension_keyword); |
447 selected_keyword_decoration_->SetImage(GetKeywordImage(keyword)); | 436 selected_keyword_decoration_->SetImage(GetKeywordImage(keyword)); |
448 } else if ((GetToolbarModel()->GetSecurityLevel(false) == | 437 } else if ((GetToolbarModel()->GetSecurityLevel(false) == |
449 ToolbarModel::EV_SECURE) && !origin_chip_decoration_.get()) { | 438 ToolbarModel::EV_SECURE)) { |
450 // Switch from location icon to show the EV bubble instead. | 439 // Switch from location icon to show the EV bubble instead. |
451 location_icon_decoration_->SetVisible(false); | 440 location_icon_decoration_->SetVisible(false); |
452 ev_bubble_decoration_->SetVisible(true); | 441 ev_bubble_decoration_->SetVisible(true); |
453 | 442 |
454 base::string16 label(GetToolbarModel()->GetEVCertName()); | 443 base::string16 label(GetToolbarModel()->GetEVCertName()); |
455 ev_bubble_decoration_->SetFullLabel(base::SysUTF16ToNSString(label)); | 444 ev_bubble_decoration_->SetFullLabel(base::SysUTF16ToNSString(label)); |
456 } else if (!keyword.empty() && is_keyword_hint) { | 445 } else if (!keyword.empty() && is_keyword_hint) { |
457 keyword_hint_decoration_->SetKeyword(short_name, | 446 keyword_hint_decoration_->SetKeyword(short_name, |
458 is_extension_keyword); | 447 is_extension_keyword); |
459 keyword_hint_decoration_->SetVisible(true); | 448 keyword_hint_decoration_->SetVisible(true); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 OnChanged(); | 530 OnChanged(); |
542 } | 531 } |
543 | 532 |
544 void LocationBarViewMac::OnChanged() { | 533 void LocationBarViewMac::OnChanged() { |
545 // Update the location-bar icon. | 534 // Update the location-bar icon. |
546 const int resource_id = omnibox_view_->GetIcon(); | 535 const int resource_id = omnibox_view_->GetIcon(); |
547 NSImage* image = OmniboxViewMac::ImageForResource(resource_id); | 536 NSImage* image = OmniboxViewMac::ImageForResource(resource_id); |
548 location_icon_decoration_->SetImage(image); | 537 location_icon_decoration_->SetImage(image); |
549 ev_bubble_decoration_->SetImage(image); | 538 ev_bubble_decoration_->SetImage(image); |
550 | 539 |
551 if (origin_chip_decoration_.get()) | |
552 origin_chip_decoration_->Update(); | |
553 | |
554 ToolbarModel* toolbar_model = GetToolbarModel(); | 540 ToolbarModel* toolbar_model = GetToolbarModel(); |
555 const chrome::DisplaySearchButtonConditions conditions = | 541 const chrome::DisplaySearchButtonConditions conditions = |
556 chrome::GetDisplaySearchButtonConditions(); | 542 chrome::GetDisplaySearchButtonConditions(); |
557 const bool meets_conditions = | 543 const bool meets_conditions = |
558 (conditions == chrome::DISPLAY_SEARCH_BUTTON_ALWAYS) || | 544 (conditions == chrome::DISPLAY_SEARCH_BUTTON_ALWAYS) || |
559 ((conditions != chrome::DISPLAY_SEARCH_BUTTON_NEVER) && | 545 ((conditions != chrome::DISPLAY_SEARCH_BUTTON_NEVER) && |
560 (toolbar_model->WouldPerformSearchTermReplacement(true) || | 546 (toolbar_model->WouldPerformSearchTermReplacement(true) || |
561 ((conditions == chrome::DISPLAY_SEARCH_BUTTON_FOR_STR_OR_IIP) && | 547 ((conditions == chrome::DISPLAY_SEARCH_BUTTON_FOR_STR_OR_IIP) && |
562 toolbar_model->input_in_progress()))); | 548 toolbar_model->input_in_progress()))); |
563 search_button_decoration_->SetVisible( | 549 search_button_decoration_->SetVisible( |
(...skipping 14 matching lines...) Expand all Loading... |
578 | 564 |
579 void LocationBarViewMac::OnSetFocus() { | 565 void LocationBarViewMac::OnSetFocus() { |
580 // Update the keyword and search hint states. | 566 // Update the keyword and search hint states. |
581 OnChanged(); | 567 OnChanged(); |
582 } | 568 } |
583 | 569 |
584 void LocationBarViewMac::ShowURL() { | 570 void LocationBarViewMac::ShowURL() { |
585 omnibox_view_->ShowURL(); | 571 omnibox_view_->ShowURL(); |
586 } | 572 } |
587 | 573 |
588 void LocationBarViewMac::HideURL() { | |
589 omnibox_view_->HideURL(); | |
590 } | |
591 | |
592 void LocationBarViewMac::EndOriginChipAnimations(bool cancel_fade) { | |
593 } | |
594 | |
595 InstantController* LocationBarViewMac::GetInstant() { | 574 InstantController* LocationBarViewMac::GetInstant() { |
596 return browser_->instant_controller() ? | 575 return browser_->instant_controller() ? |
597 browser_->instant_controller()->instant() : NULL; | 576 browser_->instant_controller()->instant() : NULL; |
598 } | 577 } |
599 | 578 |
600 WebContents* LocationBarViewMac::GetWebContents() { | 579 WebContents* LocationBarViewMac::GetWebContents() { |
601 return browser_->tab_strip_model()->GetActiveWebContents(); | 580 return browser_->tab_strip_model()->GetActiveWebContents(); |
602 } | 581 } |
603 | 582 |
604 ToolbarModel* LocationBarViewMac::GetToolbarModel() { | 583 ToolbarModel* LocationBarViewMac::GetToolbarModel() { |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 } | 744 } |
766 | 745 |
767 bool LocationBarViewMac::UpdateMicSearchDecorationVisibility() { | 746 bool LocationBarViewMac::UpdateMicSearchDecorationVisibility() { |
768 bool is_visible = !GetToolbarModel()->input_in_progress() && | 747 bool is_visible = !GetToolbarModel()->input_in_progress() && |
769 browser_->search_model()->voice_search_supported(); | 748 browser_->search_model()->voice_search_supported(); |
770 if (mic_search_decoration_->IsVisible() == is_visible) | 749 if (mic_search_decoration_->IsVisible() == is_visible) |
771 return false; | 750 return false; |
772 mic_search_decoration_->SetVisible(is_visible); | 751 mic_search_decoration_->SetVisible(is_visible); |
773 return true; | 752 return true; |
774 } | 753 } |
OLD | NEW |