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