| 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_view_mac.h" | 5 #import "chrome/browser/cocoa/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" |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 delete fetcher; | 248 delete fetcher; |
| 249 } else { | 249 } else { |
| 250 // The navigation controller will delete the fetcher. | 250 // The navigation controller will delete the fetcher. |
| 251 } | 251 } |
| 252 } | 252 } |
| 253 | 253 |
| 254 void LocationBarViewMac::OnChangedImpl(AutocompleteTextField* field, | 254 void LocationBarViewMac::OnChangedImpl(AutocompleteTextField* field, |
| 255 const std::wstring& keyword, | 255 const std::wstring& keyword, |
| 256 const std::wstring& short_name, | 256 const std::wstring& short_name, |
| 257 const bool is_keyword_hint, | 257 const bool is_keyword_hint, |
| 258 const bool is_extension_keyword, |
| 258 NSImage* image) { | 259 NSImage* image) { |
| 259 AutocompleteTextFieldCell* cell = [field autocompleteTextFieldCell]; | 260 AutocompleteTextFieldCell* cell = [field autocompleteTextFieldCell]; |
| 260 const CGFloat availableWidth([field availableDecorationWidth]); | 261 const CGFloat availableWidth([field availableDecorationWidth]); |
| 261 | 262 |
| 262 if (!keyword.empty() && !is_keyword_hint) { | 263 if (!keyword.empty() && !is_keyword_hint) { |
| 263 // Keyword search mode. The text will be like "Search Engine:". | 264 // Keyword search mode. The text will be like "Search Engine:". |
| 264 // "Engine" is a parameter to be replaced by text based on the | 265 // "Engine" is a parameter to be replaced by text based on the |
| 265 // keyword. | 266 // keyword. |
| 266 | 267 |
| 267 const std::wstring min_name(CalculateMinString(short_name)); | 268 const std::wstring min_name(CalculateMinString(short_name)); |
| 268 NSString* partial_string = nil; | 269 NSString* partial_string = nil; |
| 270 int message_id = is_extension_keyword ? |
| 271 IDS_OMNIBOX_EXTENSION_KEYWORD_TEXT : IDS_OMNIBOX_KEYWORD_TEXT; |
| 269 if (!min_name.empty()) { | 272 if (!min_name.empty()) { |
| 270 partial_string = | 273 partial_string = |
| 271 l10n_util::GetNSStringF(IDS_OMNIBOX_KEYWORD_TEXT, | 274 l10n_util::GetNSStringF(message_id, WideToUTF16(min_name)); |
| 272 WideToUTF16(min_name)); | |
| 273 } | 275 } |
| 274 | 276 |
| 275 NSString* keyword_string = | 277 NSString* keyword_string = |
| 276 l10n_util::GetNSStringF(IDS_OMNIBOX_KEYWORD_TEXT, | 278 l10n_util::GetNSStringF(message_id, WideToUTF16(short_name)); |
| 277 WideToUTF16(short_name)); | |
| 278 [cell setKeywordString:keyword_string | 279 [cell setKeywordString:keyword_string |
| 279 partialString:partial_string | 280 partialString:partial_string |
| 280 availableWidth:availableWidth]; | 281 availableWidth:availableWidth]; |
| 281 } else if (!keyword.empty() && is_keyword_hint) { | 282 } else if (!keyword.empty() && is_keyword_hint) { |
| 282 // Keyword is a hint, like "Press [Tab] to search Engine". [Tab] | 283 // Keyword is a hint, like "Press [Tab] to search Engine". [Tab] |
| 283 // is a parameter to be replaced by an image. "Engine" is a | 284 // is a parameter to be replaced by an image. "Engine" is a |
| 284 // parameter to be replaced by text based on the keyword. | 285 // parameter to be replaced by text based on the keyword. |
| 285 std::vector<size_t> content_param_offsets; | 286 std::vector<size_t> content_param_offsets; |
| 287 int message_id = is_extension_keyword ? |
| 288 IDS_OMNIBOX_EXTENSION_KEYWORD_HINT : IDS_OMNIBOX_KEYWORD_HINT; |
| 286 const std::wstring keyword_hint( | 289 const std::wstring keyword_hint( |
| 287 l10n_util::GetStringF(IDS_OMNIBOX_KEYWORD_HINT, | 290 l10n_util::GetStringF(message_id, |
| 288 std::wstring(), short_name, | 291 std::wstring(), short_name, |
| 289 &content_param_offsets)); | 292 &content_param_offsets)); |
| 290 | 293 |
| 291 // Should always be 2 offsets, see the comment in | 294 // Should always be 2 offsets, see the comment in |
| 292 // location_bar_view.cc after IDS_OMNIBOX_KEYWORD_HINT fetch. | 295 // location_bar_view.cc after IDS_OMNIBOX_KEYWORD_HINT fetch. |
| 293 DCHECK_EQ(content_param_offsets.size(), 2U); | 296 DCHECK_EQ(content_param_offsets.size(), 2U); |
| 294 | 297 |
| 295 // Where to put the [TAB] image. | 298 // Where to put the [TAB] image. |
| 296 const size_t split(content_param_offsets.front()); | 299 const size_t split(content_param_offsets.front()); |
| 297 | 300 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 311 | 314 |
| 312 void LocationBarViewMac::OnChanged() { | 315 void LocationBarViewMac::OnChanged() { |
| 313 // Update the location-bar icon. | 316 // Update the location-bar icon. |
| 314 SetIcon(edit_view_->GetIcon()); | 317 SetIcon(edit_view_->GetIcon()); |
| 315 | 318 |
| 316 // Unfortunately, the unit-test Profile doesn't have the right stuff | 319 // Unfortunately, the unit-test Profile doesn't have the right stuff |
| 317 // setup to do what GetKeywordName() needs to do. So do that out | 320 // setup to do what GetKeywordName() needs to do. So do that out |
| 318 // here where we have a Profile and pass it into OnChangedImpl(). | 321 // here where we have a Profile and pass it into OnChangedImpl(). |
| 319 const std::wstring keyword(edit_view_->model()->keyword()); | 322 const std::wstring keyword(edit_view_->model()->keyword()); |
| 320 std::wstring short_name; | 323 std::wstring short_name; |
| 324 bool is_extension_keyword = false; |
| 321 if (!keyword.empty()) { | 325 if (!keyword.empty()) { |
| 322 short_name = GetKeywordName(profile_, keyword); | 326 short_name = profile_->GetTemplateURLModel()-> |
| 327 GetKeywordShortName(keyword, &is_extension_keyword); |
| 323 } | 328 } |
| 324 | 329 |
| 325 // TODO(shess): Implementation exported to a static so that it can | 330 // TODO(shess): Implementation exported to a static so that it can |
| 326 // be unit tested without having to setup the entire object. This | 331 // be unit tested without having to setup the entire object. This |
| 327 // makes me sad. I should fix that. | 332 // makes me sad. I should fix that. |
| 328 OnChangedImpl(field_, | 333 OnChangedImpl(field_, |
| 329 keyword, | 334 keyword, |
| 330 short_name, | 335 short_name, |
| 331 edit_view_->model()->is_keyword_hint(), | 336 edit_view_->model()->is_keyword_hint(), |
| 337 is_extension_keyword, |
| 332 GetTabButtonImage()); | 338 GetTabButtonImage()); |
| 333 } | 339 } |
| 334 | 340 |
| 335 void LocationBarViewMac::OnInputInProgress(bool in_progress) { | 341 void LocationBarViewMac::OnInputInProgress(bool in_progress) { |
| 336 toolbar_model_->set_input_in_progress(in_progress); | 342 toolbar_model_->set_input_in_progress(in_progress); |
| 337 Update(NULL, false); | 343 Update(NULL, false); |
| 338 } | 344 } |
| 339 | 345 |
| 340 void LocationBarViewMac::OnSetFocus() { | 346 void LocationBarViewMac::OnSetFocus() { |
| 341 // Update the keyword and search hint states. | 347 // Update the keyword and search hint states. |
| (...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 995 ++result; | 1001 ++result; |
| 996 } | 1002 } |
| 997 return result; | 1003 return result; |
| 998 } | 1004 } |
| 999 | 1005 |
| 1000 void LocationBarViewMac::PageActionViewList::OnMousePressed(NSRect iconFrame, | 1006 void LocationBarViewMac::PageActionViewList::OnMousePressed(NSRect iconFrame, |
| 1001 size_t index) { | 1007 size_t index) { |
| 1002 ViewAt(index)->OnMousePressed(iconFrame); | 1008 ViewAt(index)->OnMousePressed(iconFrame); |
| 1003 } | 1009 } |
| 1004 | 1010 |
| OLD | NEW |