| OLD | NEW |
| 1 // Copyright (c) 2010 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/cocoa/location_bar/location_bar_view_mac.h" | 5 #import "chrome/browser/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/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/nsimage_cache_mac.h" | 10 #include "base/nsimage_cache_mac.h" |
| 11 #include "base/stl_util-inl.h" | 11 #include "base/stl_util-inl.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/sys_string_conversions.h" | 13 #include "base/sys_string_conversions.h" |
| 14 #include "chrome/app/chrome_dll_resource.h" | 14 #include "chrome/app/chrome_dll_resource.h" |
| 15 #include "chrome/browser/alternate_nav_url_fetcher.h" | 15 #include "chrome/browser/alternate_nav_url_fetcher.h" |
| 16 #import "chrome/browser/app_controller_mac.h" | 16 #import "chrome/browser/app_controller_mac.h" |
| 17 #import "chrome/browser/autocomplete/autocomplete_edit_view_mac.h" | 17 #import "chrome/browser/autocomplete/autocomplete_edit_view_mac.h" |
| 18 #include "chrome/browser/browser_list.h" | 18 #include "chrome/browser/browser_list.h" |
| 19 #import "chrome/browser/cocoa/content_blocked_bubble_controller.h" | 19 #import "chrome/browser/cocoa/content_blocked_bubble_controller.h" |
| 20 #include "chrome/browser/cocoa/event_utils.h" | 20 #include "chrome/browser/cocoa/event_utils.h" |
| 21 #import "chrome/browser/cocoa/extensions/extension_action_context_menu.h" | 21 #import "chrome/browser/cocoa/extensions/extension_action_context_menu.h" |
| 22 #import "chrome/browser/cocoa/extensions/extension_popup_controller.h" | 22 #import "chrome/browser/cocoa/extensions/extension_popup_controller.h" |
| 23 #import "chrome/browser/cocoa/first_run_bubble_controller.h" | 23 #import "chrome/browser/cocoa/first_run_bubble_controller.h" |
| 24 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field.h" | 24 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field.h" |
| 25 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.h" | 25 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.h" |
| 26 #import "chrome/browser/cocoa/location_bar/content_setting_decoration.h" | 26 #import "chrome/browser/cocoa/location_bar/content_setting_decoration.h" |
| 27 #import "chrome/browser/cocoa/location_bar/ev_bubble_decoration.h" | 27 #import "chrome/browser/cocoa/location_bar/ev_bubble_decoration.h" |
| 28 #import "chrome/browser/cocoa/location_bar/keyword_hint_decoration.h" |
| 28 #import "chrome/browser/cocoa/location_bar/location_icon_decoration.h" | 29 #import "chrome/browser/cocoa/location_bar/location_icon_decoration.h" |
| 29 #import "chrome/browser/cocoa/location_bar/page_action_decoration.h" | 30 #import "chrome/browser/cocoa/location_bar/page_action_decoration.h" |
| 30 #import "chrome/browser/cocoa/location_bar/selected_keyword_decoration.h" | 31 #import "chrome/browser/cocoa/location_bar/selected_keyword_decoration.h" |
| 31 #import "chrome/browser/cocoa/location_bar/star_decoration.h" | 32 #import "chrome/browser/cocoa/location_bar/star_decoration.h" |
| 32 #include "chrome/browser/command_updater.h" | 33 #include "chrome/browser/command_updater.h" |
| 33 #include "chrome/browser/content_setting_image_model.h" | 34 #include "chrome/browser/content_setting_image_model.h" |
| 34 #include "chrome/browser/content_setting_bubble_model.h" | 35 #include "chrome/browser/content_setting_bubble_model.h" |
| 35 #include "chrome/browser/extensions/extension_browser_event_router.h" | 36 #include "chrome/browser/extensions/extension_browser_event_router.h" |
| 36 #include "chrome/browser/extensions/extensions_service.h" | 37 #include "chrome/browser/extensions/extensions_service.h" |
| 37 #include "chrome/browser/extensions/extension_tabs_module.h" | 38 #include "chrome/browser/extensions/extension_tabs_module.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 66 command_updater_(command_updater), | 67 command_updater_(command_updater), |
| 67 field_(field), | 68 field_(field), |
| 68 disposition_(CURRENT_TAB), | 69 disposition_(CURRENT_TAB), |
| 69 location_icon_decoration_(new LocationIconDecoration(this)), | 70 location_icon_decoration_(new LocationIconDecoration(this)), |
| 70 selected_keyword_decoration_( | 71 selected_keyword_decoration_( |
| 71 new SelectedKeywordDecoration([field_ font])), | 72 new SelectedKeywordDecoration([field_ font])), |
| 72 ev_bubble_decoration_( | 73 ev_bubble_decoration_( |
| 73 new EVBubbleDecoration(location_icon_decoration_.get(), | 74 new EVBubbleDecoration(location_icon_decoration_.get(), |
| 74 [field_ font])), | 75 [field_ font])), |
| 75 star_decoration_(new StarDecoration(command_updater)), | 76 star_decoration_(new StarDecoration(command_updater)), |
| 77 keyword_hint_decoration_(new KeywordHintDecoration([field_ font])), |
| 76 profile_(profile), | 78 profile_(profile), |
| 77 browser_(browser), | 79 browser_(browser), |
| 78 toolbar_model_(toolbar_model), | 80 toolbar_model_(toolbar_model), |
| 79 transition_(PageTransition::TYPED), | 81 transition_(PageTransition::TYPED), |
| 80 first_run_bubble_(this) { | 82 first_run_bubble_(this) { |
| 81 for (size_t i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { | 83 for (size_t i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { |
| 82 DCHECK_EQ(i, content_setting_decorations_.size()); | 84 DCHECK_EQ(i, content_setting_decorations_.size()); |
| 83 ContentSettingsType type = static_cast<ContentSettingsType>(i); | 85 ContentSettingsType type = static_cast<ContentSettingsType>(i); |
| 84 content_setting_decorations_.push_back( | 86 content_setting_decorations_.push_back( |
| 85 new ContentSettingDecoration(type, this, profile_)); | 87 new ContentSettingDecoration(type, this, profile_)); |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 } | 372 } |
| 371 | 373 |
| 372 NSPoint LocationBarViewMac::GetBookmarkBubblePoint() const { | 374 NSPoint LocationBarViewMac::GetBookmarkBubblePoint() const { |
| 373 AutocompleteTextFieldCell* cell = [field_ cell]; | 375 AutocompleteTextFieldCell* cell = [field_ cell]; |
| 374 const NSRect frame = [cell frameForDecoration:star_decoration_.get() | 376 const NSRect frame = [cell frameForDecoration:star_decoration_.get() |
| 375 inFrame:[field_ bounds]]; | 377 inFrame:[field_ bounds]]; |
| 376 const NSPoint point = star_decoration_->GetBubblePointInFrame(frame); | 378 const NSPoint point = star_decoration_->GetBubblePointInFrame(frame); |
| 377 return [field_ convertPoint:point toView:nil]; | 379 return [field_ convertPoint:point toView:nil]; |
| 378 } | 380 } |
| 379 | 381 |
| 380 NSImage* LocationBarViewMac::GetTabButtonImage() { | |
| 381 if (!tab_button_image_) { | |
| 382 SkBitmap* skiaBitmap = ResourceBundle::GetSharedInstance(). | |
| 383 GetBitmapNamed(IDR_LOCATION_BAR_KEYWORD_HINT_TAB); | |
| 384 if (skiaBitmap) { | |
| 385 tab_button_image_.reset([gfx::SkBitmapToNSImage(*skiaBitmap) retain]); | |
| 386 } | |
| 387 } | |
| 388 return tab_button_image_; | |
| 389 } | |
| 390 | |
| 391 NSImage* LocationBarViewMac::GetKeywordImage(const std::wstring& keyword) { | 382 NSImage* LocationBarViewMac::GetKeywordImage(const std::wstring& keyword) { |
| 392 const TemplateURL* template_url = | 383 const TemplateURL* template_url = |
| 393 profile_->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword); | 384 profile_->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword); |
| 394 if (template_url && template_url->IsExtensionKeyword()) { | 385 if (template_url && template_url->IsExtensionKeyword()) { |
| 395 const SkBitmap& bitmap = profile_->GetExtensionsService()-> | 386 const SkBitmap& bitmap = profile_->GetExtensionsService()-> |
| 396 GetOmniboxIcon(template_url->GetExtensionId()); | 387 GetOmniboxIcon(template_url->GetExtensionId()); |
| 397 return gfx::SkBitmapToNSImage(bitmap); | 388 return gfx::SkBitmapToNSImage(bitmap); |
| 398 } | 389 } |
| 399 | 390 |
| 400 return AutocompleteEditViewMac::ImageForResource(IDR_OMNIBOX_SEARCH); | 391 return AutocompleteEditViewMac::ImageForResource(IDR_OMNIBOX_SEARCH); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 [cell addRightDecoration:star_decoration_.get()]; | 488 [cell addRightDecoration:star_decoration_.get()]; |
| 498 | 489 |
| 499 // Note that display order is right to left. | 490 // Note that display order is right to left. |
| 500 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { | 491 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { |
| 501 [cell addRightDecoration:page_action_decorations_[i]]; | 492 [cell addRightDecoration:page_action_decorations_[i]]; |
| 502 } | 493 } |
| 503 for (size_t i = 0; i < content_setting_decorations_.size(); ++i) { | 494 for (size_t i = 0; i < content_setting_decorations_.size(); ++i) { |
| 504 [cell addRightDecoration:content_setting_decorations_[i]]; | 495 [cell addRightDecoration:content_setting_decorations_[i]]; |
| 505 } | 496 } |
| 506 | 497 |
| 498 [cell addRightDecoration:keyword_hint_decoration_.get()]; |
| 499 |
| 507 // By default only the location icon is visible. | 500 // By default only the location icon is visible. |
| 508 location_icon_decoration_->SetVisible(true); | 501 location_icon_decoration_->SetVisible(true); |
| 509 selected_keyword_decoration_->SetVisible(false); | 502 selected_keyword_decoration_->SetVisible(false); |
| 510 ev_bubble_decoration_->SetVisible(false); | 503 ev_bubble_decoration_->SetVisible(false); |
| 504 keyword_hint_decoration_->SetVisible(false); |
| 511 | 505 |
| 512 // Get the keyword to use for keyword-search and hinting. | 506 // Get the keyword to use for keyword-search and hinting. |
| 513 const std::wstring keyword(edit_view_->model()->keyword()); | 507 const std::wstring keyword(edit_view_->model()->keyword()); |
| 514 std::wstring short_name; | 508 std::wstring short_name; |
| 515 bool is_extension_keyword = false; | 509 bool is_extension_keyword = false; |
| 516 if (!keyword.empty()) { | 510 if (!keyword.empty()) { |
| 517 short_name = profile_->GetTemplateURLModel()-> | 511 short_name = profile_->GetTemplateURLModel()-> |
| 518 GetKeywordShortName(keyword, &is_extension_keyword); | 512 GetKeywordShortName(keyword, &is_extension_keyword); |
| 519 } | 513 } |
| 520 | 514 |
| 521 const bool is_keyword_hint = edit_view_->model()->is_keyword_hint(); | 515 const bool is_keyword_hint = edit_view_->model()->is_keyword_hint(); |
| 522 | 516 |
| 523 if (!keyword.empty() && !is_keyword_hint) { | 517 if (!keyword.empty() && !is_keyword_hint) { |
| 524 // Switch from location icon to keyword mode. | 518 // Switch from location icon to keyword mode. |
| 525 location_icon_decoration_->SetVisible(false); | 519 location_icon_decoration_->SetVisible(false); |
| 526 selected_keyword_decoration_->SetVisible(true); | 520 selected_keyword_decoration_->SetVisible(true); |
| 527 selected_keyword_decoration_->SetKeyword(short_name, is_extension_keyword); | 521 selected_keyword_decoration_->SetKeyword(short_name, is_extension_keyword); |
| 528 selected_keyword_decoration_->SetImage(GetKeywordImage(keyword)); | 522 selected_keyword_decoration_->SetImage(GetKeywordImage(keyword)); |
| 529 | |
| 530 // TODO(shess): This goes away once the hints are decorations. | |
| 531 [cell clearHint]; | |
| 532 } else if (toolbar_model_->GetSecurityLevel() == ToolbarModel::EV_SECURE) { | 523 } else if (toolbar_model_->GetSecurityLevel() == ToolbarModel::EV_SECURE) { |
| 533 // Switch from location icon to show the EV bubble instead. | 524 // Switch from location icon to show the EV bubble instead. |
| 534 location_icon_decoration_->SetVisible(false); | 525 location_icon_decoration_->SetVisible(false); |
| 535 ev_bubble_decoration_->SetVisible(true); | 526 ev_bubble_decoration_->SetVisible(true); |
| 536 | 527 |
| 537 std::wstring label(toolbar_model_->GetEVCertName()); | 528 std::wstring label(toolbar_model_->GetEVCertName()); |
| 538 ev_bubble_decoration_->SetLabel(base::SysWideToNSString(label)); | 529 ev_bubble_decoration_->SetLabel(base::SysWideToNSString(label)); |
| 539 | |
| 540 // TODO(shess): This goes away once the hints are decorations. | |
| 541 [cell clearHint]; | |
| 542 } else if (!keyword.empty() && is_keyword_hint) { | 530 } else if (!keyword.empty() && is_keyword_hint) { |
| 543 // Keyword is a hint, like "Press [Tab] to search Engine". [Tab] | 531 keyword_hint_decoration_->SetKeyword(short_name, is_extension_keyword); |
| 544 // is a parameter to be replaced by an image. "Engine" is a | 532 keyword_hint_decoration_->SetVisible(true); |
| 545 // parameter to be replaced by text based on the keyword. | |
| 546 std::vector<size_t> content_param_offsets; | |
| 547 int message_id = is_extension_keyword ? | |
| 548 IDS_OMNIBOX_EXTENSION_KEYWORD_HINT : IDS_OMNIBOX_KEYWORD_HINT; | |
| 549 const std::wstring keyword_hint( | |
| 550 l10n_util::GetStringF(message_id, | |
| 551 std::wstring(), short_name, | |
| 552 &content_param_offsets)); | |
| 553 | |
| 554 // Should always be 2 offsets, see the comment in | |
| 555 // location_bar_view.cc after IDS_OMNIBOX_KEYWORD_HINT fetch. | |
| 556 DCHECK_EQ(content_param_offsets.size(), 2U); | |
| 557 | |
| 558 // Where to put the [TAB] image. | |
| 559 const size_t split(content_param_offsets.front()); | |
| 560 | |
| 561 NSString* prefix = base::SysWideToNSString(keyword_hint.substr(0, split)); | |
| 562 NSString* suffix = base::SysWideToNSString(keyword_hint.substr(split)); | |
| 563 | |
| 564 NSImage* image = GetTabButtonImage(); | |
| 565 const CGFloat availableWidth([field_ availableDecorationWidth]); | |
| 566 [cell setKeywordHintPrefix:prefix image:image suffix:suffix | |
| 567 availableWidth:availableWidth]; | |
| 568 } else { | |
| 569 // Nothing interesting to show, plain old text field. | |
| 570 [cell clearHint]; | |
| 571 } | 533 } |
| 572 | 534 |
| 573 // These need to change anytime the layout changes. | 535 // These need to change anytime the layout changes. |
| 574 // TODO(shess): Anytime the field editor might have changed, the | 536 // TODO(shess): Anytime the field editor might have changed, the |
| 575 // cursor rects almost certainly should have changed. The tooltips | 537 // cursor rects almost certainly should have changed. The tooltips |
| 576 // might change even when the rects don't change. | 538 // might change even when the rects don't change. |
| 577 [field_ resetFieldEditorFrameIfNeeded]; | 539 [field_ resetFieldEditorFrameIfNeeded]; |
| 578 [field_ updateCursorAndToolTipRects]; | 540 [field_ updateCursorAndToolTipRects]; |
| 579 | 541 |
| 580 [field_ setNeedsDisplay:YES]; | 542 [field_ setNeedsDisplay:YES]; |
| 581 } | 543 } |
| OLD | NEW |