| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/l10n_util_mac.h" | 7 #include "app/l10n_util_mac.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/sys_string_conversions.h" | 11 #include "base/sys_string_conversions.h" |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 [cell frameForDecoration:location_icon_decoration_.get() | 520 [cell frameForDecoration:location_icon_decoration_.get() |
| 521 inFrame:[field_ bounds]]; | 521 inFrame:[field_ bounds]]; |
| 522 const NSPoint point = | 522 const NSPoint point = |
| 523 location_icon_decoration_->GetBubblePointInFrame(frame); | 523 location_icon_decoration_->GetBubblePointInFrame(frame); |
| 524 return [field_ convertPoint:point toView:nil]; | 524 return [field_ convertPoint:point toView:nil]; |
| 525 } | 525 } |
| 526 } | 526 } |
| 527 | 527 |
| 528 NSImage* LocationBarViewMac::GetKeywordImage(const std::wstring& keyword) { | 528 NSImage* LocationBarViewMac::GetKeywordImage(const std::wstring& keyword) { |
| 529 const TemplateURL* template_url = | 529 const TemplateURL* template_url = |
| 530 profile_->GetTemplateURLModel()->GetTemplateURLForKeyword( | 530 profile_->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword); |
| 531 WideToUTF16Hack(keyword)); | |
| 532 if (template_url && template_url->IsExtensionKeyword()) { | 531 if (template_url && template_url->IsExtensionKeyword()) { |
| 533 const SkBitmap& bitmap = profile_->GetExtensionService()-> | 532 const SkBitmap& bitmap = profile_->GetExtensionService()-> |
| 534 GetOmniboxIcon(template_url->GetExtensionId()); | 533 GetOmniboxIcon(template_url->GetExtensionId()); |
| 535 return gfx::SkBitmapToNSImage(bitmap); | 534 return gfx::SkBitmapToNSImage(bitmap); |
| 536 } | 535 } |
| 537 | 536 |
| 538 return AutocompleteEditViewMac::ImageForResource(IDR_OMNIBOX_SEARCH); | 537 return AutocompleteEditViewMac::ImageForResource(IDR_OMNIBOX_SEARCH); |
| 539 } | 538 } |
| 540 | 539 |
| 541 void LocationBarViewMac::Observe(NotificationType type, | 540 void LocationBarViewMac::Observe(NotificationType type, |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 [cell addRightDecoration:keyword_hint_decoration_.get()]; | 649 [cell addRightDecoration:keyword_hint_decoration_.get()]; |
| 651 | 650 |
| 652 // By default only the location icon is visible. | 651 // By default only the location icon is visible. |
| 653 location_icon_decoration_->SetVisible(true); | 652 location_icon_decoration_->SetVisible(true); |
| 654 selected_keyword_decoration_->SetVisible(false); | 653 selected_keyword_decoration_->SetVisible(false); |
| 655 ev_bubble_decoration_->SetVisible(false); | 654 ev_bubble_decoration_->SetVisible(false); |
| 656 keyword_hint_decoration_->SetVisible(false); | 655 keyword_hint_decoration_->SetVisible(false); |
| 657 | 656 |
| 658 // Get the keyword to use for keyword-search and hinting. | 657 // Get the keyword to use for keyword-search and hinting. |
| 659 const std::wstring keyword(edit_view_->model()->keyword()); | 658 const std::wstring keyword(edit_view_->model()->keyword()); |
| 660 string16 short_name; | 659 std::wstring short_name; |
| 661 bool is_extension_keyword = false; | 660 bool is_extension_keyword = false; |
| 662 if (!keyword.empty()) { | 661 if (!keyword.empty()) { |
| 663 short_name = profile_->GetTemplateURLModel()-> | 662 short_name = profile_->GetTemplateURLModel()-> |
| 664 GetKeywordShortName(WideToUTF16Hack(keyword), &is_extension_keyword); | 663 GetKeywordShortName(keyword, &is_extension_keyword); |
| 665 } | 664 } |
| 666 | 665 |
| 667 const bool is_keyword_hint = edit_view_->model()->is_keyword_hint(); | 666 const bool is_keyword_hint = edit_view_->model()->is_keyword_hint(); |
| 668 | 667 |
| 669 if (!keyword.empty() && !is_keyword_hint) { | 668 if (!keyword.empty() && !is_keyword_hint) { |
| 670 // Switch from location icon to keyword mode. | 669 // Switch from location icon to keyword mode. |
| 671 location_icon_decoration_->SetVisible(false); | 670 location_icon_decoration_->SetVisible(false); |
| 672 selected_keyword_decoration_->SetVisible(true); | 671 selected_keyword_decoration_->SetVisible(true); |
| 673 selected_keyword_decoration_->SetKeyword(UTF16ToWideHack(short_name), | 672 selected_keyword_decoration_->SetKeyword(short_name, is_extension_keyword); |
| 674 is_extension_keyword); | |
| 675 selected_keyword_decoration_->SetImage(GetKeywordImage(keyword)); | 673 selected_keyword_decoration_->SetImage(GetKeywordImage(keyword)); |
| 676 } else if (toolbar_model_->GetSecurityLevel() == ToolbarModel::EV_SECURE) { | 674 } else if (toolbar_model_->GetSecurityLevel() == ToolbarModel::EV_SECURE) { |
| 677 // Switch from location icon to show the EV bubble instead. | 675 // Switch from location icon to show the EV bubble instead. |
| 678 location_icon_decoration_->SetVisible(false); | 676 location_icon_decoration_->SetVisible(false); |
| 679 ev_bubble_decoration_->SetVisible(true); | 677 ev_bubble_decoration_->SetVisible(true); |
| 680 | 678 |
| 681 std::wstring label(toolbar_model_->GetEVCertName()); | 679 std::wstring label(toolbar_model_->GetEVCertName()); |
| 682 ev_bubble_decoration_->SetFullLabel(base::SysWideToNSString(label)); | 680 ev_bubble_decoration_->SetFullLabel(base::SysWideToNSString(label)); |
| 683 } else if (!keyword.empty() && is_keyword_hint) { | 681 } else if (!keyword.empty() && is_keyword_hint) { |
| 684 keyword_hint_decoration_->SetKeyword(short_name, | 682 keyword_hint_decoration_->SetKeyword(WideToUTF16Hack(short_name), |
| 685 is_extension_keyword); | 683 is_extension_keyword); |
| 686 keyword_hint_decoration_->SetVisible(true); | 684 keyword_hint_decoration_->SetVisible(true); |
| 687 } | 685 } |
| 688 | 686 |
| 689 // These need to change anytime the layout changes. | 687 // These need to change anytime the layout changes. |
| 690 // TODO(shess): Anytime the field editor might have changed, the | 688 // TODO(shess): Anytime the field editor might have changed, the |
| 691 // cursor rects almost certainly should have changed. The tooltips | 689 // cursor rects almost certainly should have changed. The tooltips |
| 692 // might change even when the rects don't change. | 690 // might change even when the rects don't change. |
| 693 [field_ resetFieldEditorFrameIfNeeded]; | 691 [field_ resetFieldEditorFrameIfNeeded]; |
| 694 [field_ updateCursorAndToolTipRects]; | 692 [field_ updateCursorAndToolTipRects]; |
| 695 | 693 |
| 696 [field_ setNeedsDisplay:YES]; | 694 [field_ setNeedsDisplay:YES]; |
| 697 } | 695 } |
| OLD | NEW |