OLD | NEW |
1 // Copyright (c) 2011 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 "base/stl_util-inl.h" | 7 #include "base/stl_util-inl.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 instant->SetCommitOnMouseUp(); | 241 instant->SetCommitOnMouseUp(); |
242 } else { | 242 } else { |
243 instant->CommitCurrentPreview(INSTANT_COMMIT_FOCUS_LOST); | 243 instant->CommitCurrentPreview(INSTANT_COMMIT_FOCUS_LOST); |
244 } | 244 } |
245 } | 245 } |
246 | 246 |
247 void LocationBarViewMac::OnAutocompleteWillAccept() { | 247 void LocationBarViewMac::OnAutocompleteWillAccept() { |
248 update_instant_ = false; | 248 update_instant_ = false; |
249 } | 249 } |
250 | 250 |
251 bool LocationBarViewMac::OnCommitSuggestedText(const std::wstring& typed_text) { | 251 bool LocationBarViewMac::OnCommitSuggestedText(const string16& typed_text) { |
252 return edit_view_->CommitSuggestText(); | 252 return edit_view_->CommitSuggestText(); |
253 } | 253 } |
254 | 254 |
255 bool LocationBarViewMac::AcceptCurrentInstantPreview() { | 255 bool LocationBarViewMac::AcceptCurrentInstantPreview() { |
256 return InstantController::CommitIfCurrent(browser_->instant()); | 256 return InstantController::CommitIfCurrent(browser_->instant()); |
257 } | 257 } |
258 | 258 |
259 void LocationBarViewMac::OnPopupBoundsChanged(const gfx::Rect& bounds) { | 259 void LocationBarViewMac::OnPopupBoundsChanged(const gfx::Rect& bounds) { |
260 InstantController* instant = browser_->instant(); | 260 InstantController* instant = browser_->instant(); |
261 if (instant) | 261 if (instant) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 Layout(); | 310 Layout(); |
311 | 311 |
312 InstantController* instant = browser_->instant(); | 312 InstantController* instant = browser_->instant(); |
313 string16 suggested_text; | 313 string16 suggested_text; |
314 if (update_instant_ && instant && GetTabContents()) { | 314 if (update_instant_ && instant && GetTabContents()) { |
315 if (edit_view_->model()->user_input_in_progress() && | 315 if (edit_view_->model()->user_input_in_progress() && |
316 edit_view_->model()->popup_model()->IsOpen()) { | 316 edit_view_->model()->popup_model()->IsOpen()) { |
317 instant->Update | 317 instant->Update |
318 (browser_->GetSelectedTabContentsWrapper(), | 318 (browser_->GetSelectedTabContentsWrapper(), |
319 edit_view_->model()->CurrentMatch(), | 319 edit_view_->model()->CurrentMatch(), |
320 WideToUTF16(edit_view_->GetText()), | 320 edit_view_->GetText(), |
321 edit_view_->model()->UseVerbatimInstant(), | 321 edit_view_->model()->UseVerbatimInstant(), |
322 &suggested_text); | 322 &suggested_text); |
323 if (!instant->MightSupportInstant()) { | 323 if (!instant->MightSupportInstant()) { |
324 edit_view_->model()->FinalizeInstantQuery(std::wstring(), | 324 edit_view_->model()->FinalizeInstantQuery(string16(), |
325 std::wstring()); | 325 string16()); |
326 } | 326 } |
327 } else { | 327 } else { |
328 instant->DestroyPreviewContents(); | 328 instant->DestroyPreviewContents(); |
329 edit_view_->model()->FinalizeInstantQuery(std::wstring(), | 329 edit_view_->model()->FinalizeInstantQuery(string16(), |
330 std::wstring()); | 330 string16()); |
331 } | 331 } |
332 } | 332 } |
333 | 333 |
334 SetSuggestedText(suggested_text); | 334 SetSuggestedText(suggested_text); |
335 } | 335 } |
336 | 336 |
337 void LocationBarViewMac::OnSelectionBoundsChanged() { | 337 void LocationBarViewMac::OnSelectionBoundsChanged() { |
338 NOTIMPLEMENTED(); | 338 NOTIMPLEMENTED(); |
339 } | 339 } |
340 | 340 |
341 void LocationBarViewMac::OnInputInProgress(bool in_progress) { | 341 void LocationBarViewMac::OnInputInProgress(bool in_progress) { |
342 toolbar_model_->set_input_in_progress(in_progress); | 342 toolbar_model_->set_input_in_progress(in_progress); |
343 Update(NULL, false); | 343 Update(NULL, false); |
344 } | 344 } |
345 | 345 |
346 void LocationBarViewMac::OnSetFocus() { | 346 void LocationBarViewMac::OnSetFocus() { |
347 // Update the keyword and search hint states. | 347 // Update the keyword and search hint states. |
348 OnChanged(); | 348 OnChanged(); |
349 } | 349 } |
350 | 350 |
351 void LocationBarViewMac::OnKillFocus() { | 351 void LocationBarViewMac::OnKillFocus() { |
352 // Do nothing. | 352 // Do nothing. |
353 } | 353 } |
354 | 354 |
355 SkBitmap LocationBarViewMac::GetFavIcon() const { | 355 SkBitmap LocationBarViewMac::GetFavIcon() const { |
356 NOTIMPLEMENTED(); | 356 NOTIMPLEMENTED(); |
357 return SkBitmap(); | 357 return SkBitmap(); |
358 } | 358 } |
359 | 359 |
360 std::wstring LocationBarViewMac::GetTitle() const { | 360 string16 LocationBarViewMac::GetTitle() const { |
361 NOTIMPLEMENTED(); | 361 NOTIMPLEMENTED(); |
362 return std::wstring(); | 362 return string16(); |
363 } | 363 } |
364 | 364 |
365 void LocationBarViewMac::Revert() { | 365 void LocationBarViewMac::Revert() { |
366 edit_view_->RevertAll(); | 366 edit_view_->RevertAll(); |
367 } | 367 } |
368 | 368 |
369 // TODO(pamg): Change all these, here and for other platforms, to size_t. | 369 // TODO(pamg): Change all these, here and for other platforms, to size_t. |
370 int LocationBarViewMac::PageActionCount() { | 370 int LocationBarViewMac::PageActionCount() { |
371 return static_cast<int>(page_action_decorations_.size()); | 371 return static_cast<int>(page_action_decorations_.size()); |
372 } | 372 } |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 } else { | 513 } else { |
514 const NSRect frame = | 514 const NSRect frame = |
515 [cell frameForDecoration:location_icon_decoration_.get() | 515 [cell frameForDecoration:location_icon_decoration_.get() |
516 inFrame:[field_ bounds]]; | 516 inFrame:[field_ bounds]]; |
517 const NSPoint point = | 517 const NSPoint point = |
518 location_icon_decoration_->GetBubblePointInFrame(frame); | 518 location_icon_decoration_->GetBubblePointInFrame(frame); |
519 return [field_ convertPoint:point toView:nil]; | 519 return [field_ convertPoint:point toView:nil]; |
520 } | 520 } |
521 } | 521 } |
522 | 522 |
523 NSImage* LocationBarViewMac::GetKeywordImage(const std::wstring& keyword) { | 523 NSImage* LocationBarViewMac::GetKeywordImage(const string16& keyword) { |
524 const TemplateURL* template_url = | 524 const TemplateURL* template_url = |
525 profile_->GetTemplateURLModel()->GetTemplateURLForKeyword( | 525 profile_->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword); |
526 WideToUTF16Hack(keyword)); | |
527 if (template_url && template_url->IsExtensionKeyword()) { | 526 if (template_url && template_url->IsExtensionKeyword()) { |
528 const SkBitmap& bitmap = profile_->GetExtensionService()-> | 527 const SkBitmap& bitmap = profile_->GetExtensionService()-> |
529 GetOmniboxIcon(template_url->GetExtensionId()); | 528 GetOmniboxIcon(template_url->GetExtensionId()); |
530 return gfx::SkBitmapToNSImage(bitmap); | 529 return gfx::SkBitmapToNSImage(bitmap); |
531 } | 530 } |
532 | 531 |
533 return AutocompleteEditViewMac::ImageForResource(IDR_OMNIBOX_SEARCH); | 532 return AutocompleteEditViewMac::ImageForResource(IDR_OMNIBOX_SEARCH); |
534 } | 533 } |
535 | 534 |
536 void LocationBarViewMac::Observe(NotificationType type, | 535 void LocationBarViewMac::Observe(NotificationType type, |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 | 643 |
645 [cell addRightDecoration:keyword_hint_decoration_.get()]; | 644 [cell addRightDecoration:keyword_hint_decoration_.get()]; |
646 | 645 |
647 // By default only the location icon is visible. | 646 // By default only the location icon is visible. |
648 location_icon_decoration_->SetVisible(true); | 647 location_icon_decoration_->SetVisible(true); |
649 selected_keyword_decoration_->SetVisible(false); | 648 selected_keyword_decoration_->SetVisible(false); |
650 ev_bubble_decoration_->SetVisible(false); | 649 ev_bubble_decoration_->SetVisible(false); |
651 keyword_hint_decoration_->SetVisible(false); | 650 keyword_hint_decoration_->SetVisible(false); |
652 | 651 |
653 // Get the keyword to use for keyword-search and hinting. | 652 // Get the keyword to use for keyword-search and hinting. |
654 const std::wstring keyword(edit_view_->model()->keyword()); | 653 const string16 keyword = edit_view_->model()->keyword(); |
655 string16 short_name; | 654 string16 short_name; |
656 bool is_extension_keyword = false; | 655 bool is_extension_keyword = false; |
657 if (!keyword.empty()) { | 656 if (!keyword.empty()) { |
658 short_name = profile_->GetTemplateURLModel()-> | 657 short_name = profile_->GetTemplateURLModel()-> |
659 GetKeywordShortName(WideToUTF16Hack(keyword), &is_extension_keyword); | 658 GetKeywordShortName(keyword, &is_extension_keyword); |
660 } | 659 } |
661 | 660 |
662 const bool is_keyword_hint = edit_view_->model()->is_keyword_hint(); | 661 const bool is_keyword_hint = edit_view_->model()->is_keyword_hint(); |
663 | 662 |
664 if (!keyword.empty() && !is_keyword_hint) { | 663 if (!keyword.empty() && !is_keyword_hint) { |
665 // Switch from location icon to keyword mode. | 664 // Switch from location icon to keyword mode. |
666 location_icon_decoration_->SetVisible(false); | 665 location_icon_decoration_->SetVisible(false); |
667 selected_keyword_decoration_->SetVisible(true); | 666 selected_keyword_decoration_->SetVisible(true); |
668 selected_keyword_decoration_->SetKeyword(UTF16ToWideHack(short_name), | 667 selected_keyword_decoration_->SetKeyword(short_name, is_extension_keyword); |
669 is_extension_keyword); | |
670 selected_keyword_decoration_->SetImage(GetKeywordImage(keyword)); | 668 selected_keyword_decoration_->SetImage(GetKeywordImage(keyword)); |
671 } else if (toolbar_model_->GetSecurityLevel() == ToolbarModel::EV_SECURE) { | 669 } else if (toolbar_model_->GetSecurityLevel() == ToolbarModel::EV_SECURE) { |
672 // Switch from location icon to show the EV bubble instead. | 670 // Switch from location icon to show the EV bubble instead. |
673 location_icon_decoration_->SetVisible(false); | 671 location_icon_decoration_->SetVisible(false); |
674 ev_bubble_decoration_->SetVisible(true); | 672 ev_bubble_decoration_->SetVisible(true); |
675 | 673 |
676 std::wstring label(toolbar_model_->GetEVCertName()); | 674 std::wstring label(toolbar_model_->GetEVCertName()); |
677 ev_bubble_decoration_->SetFullLabel(base::SysWideToNSString(label)); | 675 ev_bubble_decoration_->SetFullLabel(base::SysWideToNSString(label)); |
678 } else if (!keyword.empty() && is_keyword_hint) { | 676 } else if (!keyword.empty() && is_keyword_hint) { |
679 keyword_hint_decoration_->SetKeyword(short_name, | 677 keyword_hint_decoration_->SetKeyword(short_name, |
680 is_extension_keyword); | 678 is_extension_keyword); |
681 keyword_hint_decoration_->SetVisible(true); | 679 keyword_hint_decoration_->SetVisible(true); |
682 } | 680 } |
683 | 681 |
684 // These need to change anytime the layout changes. | 682 // These need to change anytime the layout changes. |
685 // TODO(shess): Anytime the field editor might have changed, the | 683 // TODO(shess): Anytime the field editor might have changed, the |
686 // cursor rects almost certainly should have changed. The tooltips | 684 // cursor rects almost certainly should have changed. The tooltips |
687 // might change even when the rects don't change. | 685 // might change even when the rects don't change. |
688 [field_ resetFieldEditorFrameIfNeeded]; | 686 [field_ resetFieldEditorFrameIfNeeded]; |
689 [field_ updateCursorAndToolTipRects]; | 687 [field_ updateCursorAndToolTipRects]; |
690 | 688 |
691 [field_ setNeedsDisplay:YES]; | 689 [field_ setNeedsDisplay:YES]; |
692 } | 690 } |
OLD | NEW |