OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 5 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 72 |
73 namespace { | 73 namespace { |
74 | 74 |
75 WebContents* GetWebContentsFromDelegate(LocationBarView::Delegate* delegate) { | 75 WebContents* GetWebContentsFromDelegate(LocationBarView::Delegate* delegate) { |
76 const TabContentsWrapper* wrapper = delegate->GetTabContentsWrapper(); | 76 const TabContentsWrapper* wrapper = delegate->GetTabContentsWrapper(); |
77 return wrapper ? wrapper->web_contents() : NULL; | 77 return wrapper ? wrapper->web_contents() : NULL; |
78 } | 78 } |
79 | 79 |
80 // A utility function to cast OmniboxView to OmniboxViewViews. | 80 // A utility function to cast OmniboxView to OmniboxViewViews. |
81 OmniboxViewViews* AsViews(OmniboxView* view) { | 81 OmniboxViewViews* AsViews(OmniboxView* view) { |
82 DCHECK(views::Widget::IsPureViews()); | |
83 return static_cast<OmniboxViewViews*>(view); | 82 return static_cast<OmniboxViewViews*>(view); |
84 } | 83 } |
85 | 84 |
86 // Height of the location bar's round corner region. | 85 // Height of the location bar's round corner region. |
87 // TODO(jamescook): Update all Chrome platforms to use the new art and metrics | 86 // TODO(jamescook): Update all Chrome platforms to use the new art and metrics |
88 // from Ash, crbug.com/118228 | 87 // from Ash, crbug.com/118228 |
89 #if defined(USE_ASH) | 88 #if defined(USE_ASH) |
90 const int kBorderRoundCornerHeight = 5; | 89 const int kBorderRoundCornerHeight = 5; |
91 #else | 90 #else |
92 const int kBorderRoundCornerHeight = 6; | 91 const int kBorderRoundCornerHeight = 6; |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 } | 454 } |
456 | 455 |
457 #if defined(OS_WIN) || defined(USE_AURA) | 456 #if defined(OS_WIN) || defined(USE_AURA) |
458 void LocationBarView::SetInstantSuggestion(const string16& text, | 457 void LocationBarView::SetInstantSuggestion(const string16& text, |
459 bool animate_to_complete) { | 458 bool animate_to_complete) { |
460 // Don't show the suggested text if inline autocomplete is prevented. | 459 // Don't show the suggested text if inline autocomplete is prevented. |
461 if (!text.empty()) { | 460 if (!text.empty()) { |
462 if (!suggested_text_view_) { | 461 if (!suggested_text_view_) { |
463 suggested_text_view_ = new SuggestedTextView(location_entry_->model()); | 462 suggested_text_view_ = new SuggestedTextView(location_entry_->model()); |
464 suggested_text_view_->SetText(text); | 463 suggested_text_view_->SetText(text); |
465 if (views::Widget::IsPureViews()) | 464 #if defined(USE_AURA) |
466 NOTIMPLEMENTED(); | 465 NOTIMPLEMENTED(); |
467 #if !defined(USE_AURA) | 466 #else |
468 else | 467 suggested_text_view_->SetFont(GetOmniboxViewWin()->GetFont()); |
469 suggested_text_view_->SetFont(GetOmniboxViewWin()->GetFont()); | |
470 #endif | 468 #endif |
471 AddChildView(suggested_text_view_); | 469 AddChildView(suggested_text_view_); |
472 } else if (suggested_text_view_->text() != text) { | 470 } else if (suggested_text_view_->text() != text) { |
473 suggested_text_view_->SetText(text); | 471 suggested_text_view_->SetText(text); |
474 } | 472 } |
475 if (animate_to_complete && !location_entry_->IsImeComposing()) | 473 if (animate_to_complete && !location_entry_->IsImeComposing()) |
476 suggested_text_view_->StartAnimation(); | 474 suggested_text_view_->StartAnimation(); |
477 } else if (suggested_text_view_) { | 475 } else if (suggested_text_view_) { |
478 delete suggested_text_view_; | 476 delete suggested_text_view_; |
479 suggested_text_view_ = NULL; | 477 suggested_text_view_ = NULL; |
480 } else { | 478 } else { |
481 return; | 479 return; |
482 } | 480 } |
483 | 481 |
484 Layout(); | 482 Layout(); |
485 SchedulePaint(); | 483 SchedulePaint(); |
486 } | 484 } |
487 | 485 |
488 string16 LocationBarView::GetInstantSuggestion() const { | 486 string16 LocationBarView::GetInstantSuggestion() const { |
489 return HasValidSuggestText() ? suggested_text_view_->text() : string16(); | 487 return HasValidSuggestText() ? suggested_text_view_->text() : string16(); |
490 } | 488 } |
491 #endif | 489 #endif |
492 | 490 |
493 void LocationBarView::SetLocationEntryFocusable(bool focusable) { | 491 void LocationBarView::SetLocationEntryFocusable(bool focusable) { |
494 if (views::Widget::IsPureViews()) | 492 #if defined(USE_AURA) |
495 AsViews(location_entry_.get())->SetLocationEntryFocusable(focusable); | 493 AsViews(location_entry_.get())->SetLocationEntryFocusable(focusable); |
496 else | 494 #else |
497 set_focusable(focusable); | 495 set_focusable(focusable); |
| 496 #endif |
498 } | 497 } |
499 | 498 |
500 bool LocationBarView::IsLocationEntryFocusableInRootView() const { | 499 bool LocationBarView::IsLocationEntryFocusableInRootView() const { |
501 return views::Widget::IsPureViews() ? | 500 #if defined(USE_AURA) |
502 AsViews(location_entry_.get())->IsLocationEntryFocusableInRootView() : | 501 return AsViews(location_entry_.get())->IsLocationEntryFocusableInRootView(); |
503 views::View::IsFocusable(); | 502 #else |
| 503 return views::View::IsFocusable(); |
| 504 #endif |
504 } | 505 } |
505 | 506 |
506 gfx::Size LocationBarView::GetPreferredSize() { | 507 gfx::Size LocationBarView::GetPreferredSize() { |
507 return gfx::Size(0, GetThemeProvider()->GetBitmapNamed(mode_ == POPUP ? | 508 return gfx::Size(0, GetThemeProvider()->GetBitmapNamed(mode_ == POPUP ? |
508 IDR_LOCATIONBG_POPUPMODE_CENTER : IDR_LOCATIONBG_C)->height()); | 509 IDR_LOCATIONBG_POPUPMODE_CENTER : IDR_LOCATIONBG_C)->height()); |
509 } | 510 } |
510 | 511 |
511 void LocationBarView::Layout() { | 512 void LocationBarView::Layout() { |
512 if (!location_entry_.get()) | 513 if (!location_entry_.get()) |
513 return; | 514 return; |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 // entry. Only show the suggested text if we can fit the text from one | 716 // entry. Only show the suggested text if we can fit the text from one |
716 // character before the end of the selection to the end of the text and the | 717 // character before the end of the selection to the end of the text and the |
717 // suggested text. If we can't it means either the suggested text is too big, | 718 // suggested text. If we can't it means either the suggested text is too big, |
718 // or the user has scrolled. | 719 // or the user has scrolled. |
719 | 720 |
720 // TODO(sky): We could potentially combine this with the previous step to | 721 // TODO(sky): We could potentially combine this with the previous step to |
721 // force using minimum size if necessary, but currently the chance of showing | 722 // force using minimum size if necessary, but currently the chance of showing |
722 // keyword hints and suggested text is minimal and we're not confident this | 723 // keyword hints and suggested text is minimal and we're not confident this |
723 // is the right approach for suggested text. | 724 // is the right approach for suggested text. |
724 if (suggested_text_view_) { | 725 if (suggested_text_view_) { |
725 if (views::Widget::IsPureViews()) { | 726 #if defined(USE_AURA) |
726 NOTIMPLEMENTED(); | 727 NOTIMPLEMENTED(); |
| 728 #else |
| 729 // TODO(sky): need to layout when the user changes caret position. |
| 730 int suggested_text_width = |
| 731 suggested_text_view_->GetPreferredSize().width(); |
| 732 int vis_text_width = GetOmniboxViewWin()->WidthOfTextAfterCursor(); |
| 733 if (vis_text_width + suggested_text_width > entry_width) { |
| 734 // Hide the suggested text if the user has scrolled or we can't fit all |
| 735 // the suggested text. |
| 736 suggested_text_view_->SetBounds(0, 0, 0, 0); |
727 } else { | 737 } else { |
728 #if !defined(USE_AURA) | 738 int location_needed_width = location_entry_->TextWidth(); |
729 // TODO(sky): need to layout when the user changes caret position. | 739 location_bounds.set_width(std::min(location_needed_width, |
730 int suggested_text_width = | 740 entry_width - suggested_text_width)); |
731 suggested_text_view_->GetPreferredSize().width(); | 741 // TODO(sky): figure out why this needs the -1. |
732 int vis_text_width = GetOmniboxViewWin()->WidthOfTextAfterCursor(); | 742 suggested_text_view_->SetBounds(location_bounds.right() - 1, |
733 if (vis_text_width + suggested_text_width > entry_width) { | 743 location_bounds.y(), |
734 // Hide the suggested text if the user has scrolled or we can't fit all | 744 suggested_text_width, |
735 // the suggested text. | 745 location_bounds.height()); |
736 suggested_text_view_->SetBounds(0, 0, 0, 0); | 746 } |
737 } else { | |
738 int location_needed_width = location_entry_->TextWidth(); | |
739 location_bounds.set_width(std::min(location_needed_width, | |
740 entry_width - suggested_text_width)); | |
741 // TODO(sky): figure out why this needs the -1. | |
742 suggested_text_view_->SetBounds(location_bounds.right() - 1, | |
743 location_bounds.y(), | |
744 suggested_text_width, | |
745 location_bounds.height()); | |
746 } | |
747 #endif | 747 #endif |
748 } | |
749 } | 748 } |
750 #endif | 749 #endif |
751 | 750 |
752 location_entry_view_->SetBoundsRect(location_bounds); | 751 location_entry_view_->SetBoundsRect(location_bounds); |
753 } | 752 } |
754 | 753 |
755 void LocationBarView::OnPaint(gfx::Canvas* canvas) { | 754 void LocationBarView::OnPaint(gfx::Canvas* canvas) { |
756 View::OnPaint(canvas); | 755 View::OnPaint(canvas); |
757 | 756 |
758 if (painter_.get()) { | 757 if (painter_.get()) { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 } else if (event.IsRightMouseButton()) { | 848 } else if (event.IsRightMouseButton()) { |
850 msg = WM_RBUTTONUP; | 849 msg = WM_RBUTTONUP; |
851 } else { | 850 } else { |
852 NOTREACHED(); | 851 NOTREACHED(); |
853 return; | 852 return; |
854 } | 853 } |
855 OnMouseEvent(event, msg); | 854 OnMouseEvent(event, msg); |
856 } | 855 } |
857 | 856 |
858 void LocationBarView::OnMouseCaptureLost() { | 857 void LocationBarView::OnMouseCaptureLost() { |
859 if (views::Widget::IsPureViews()) | 858 GetOmniboxViewWin()->HandleExternalMsg(WM_CAPTURECHANGED, 0, CPoint()); |
860 NOTIMPLEMENTED(); | |
861 else | |
862 GetOmniboxViewWin()->HandleExternalMsg(WM_CAPTURECHANGED, 0, CPoint()); | |
863 } | 859 } |
864 #endif | 860 #endif |
865 | 861 |
866 void LocationBarView::OnAutocompleteAccept( | 862 void LocationBarView::OnAutocompleteAccept( |
867 const GURL& url, | 863 const GURL& url, |
868 WindowOpenDisposition disposition, | 864 WindowOpenDisposition disposition, |
869 content::PageTransition transition, | 865 content::PageTransition transition, |
870 const GURL& alternate_nav_url) { | 866 const GURL& alternate_nav_url) { |
871 // WARNING: don't add an early return here. The calls after the if must | 867 // WARNING: don't add an early return here. The calls after the if must |
872 // happen. | 868 // happen. |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1051 } | 1047 } |
1052 } | 1048 } |
1053 } | 1049 } |
1054 } | 1050 } |
1055 | 1051 |
1056 #if defined(OS_WIN) && !defined(USE_AURA) | 1052 #if defined(OS_WIN) && !defined(USE_AURA) |
1057 void LocationBarView::OnMouseEvent(const views::MouseEvent& event, UINT msg) { | 1053 void LocationBarView::OnMouseEvent(const views::MouseEvent& event, UINT msg) { |
1058 UINT flags = event.native_event().wParam; | 1054 UINT flags = event.native_event().wParam; |
1059 gfx::Point screen_point(event.location()); | 1055 gfx::Point screen_point(event.location()); |
1060 ConvertPointToScreen(this, &screen_point); | 1056 ConvertPointToScreen(this, &screen_point); |
1061 if (views::Widget::IsPureViews()) | 1057 GetOmniboxViewWin()->HandleExternalMsg(msg, flags, screen_point.ToPOINT()); |
1062 NOTIMPLEMENTED(); | |
1063 else | |
1064 GetOmniboxViewWin()->HandleExternalMsg(msg, flags, screen_point.ToPOINT()); | |
1065 } | 1058 } |
1066 #endif | 1059 #endif |
1067 | 1060 |
1068 void LocationBarView::ShowFirstRunBubbleInternal() { | 1061 void LocationBarView::ShowFirstRunBubbleInternal() { |
1069 #if !defined(OS_CHROMEOS) | 1062 #if !defined(OS_CHROMEOS) |
1070 // First run bubble doesn't make sense for Chrome OS. | 1063 // First run bubble doesn't make sense for Chrome OS. |
1071 FirstRunBubble::ShowBubble(profile_, location_icon_view_); | 1064 FirstRunBubble::ShowBubble(profile_, location_icon_view_); |
1072 #endif | 1065 #endif |
1073 } | 1066 } |
1074 | 1067 |
(...skipping 14 matching lines...) Expand all Loading... |
1089 return true; | 1082 return true; |
1090 } | 1083 } |
1091 | 1084 |
1092 // Tab while showing instant commits instant immediately. | 1085 // Tab while showing instant commits instant immediately. |
1093 // Return true so that focus traversal isn't attempted. The edit ends | 1086 // Return true so that focus traversal isn't attempted. The edit ends |
1094 // up doing nothing in this case. | 1087 // up doing nothing in this case. |
1095 if (location_entry_->model()->AcceptCurrentInstantPreview()) | 1088 if (location_entry_->model()->AcceptCurrentInstantPreview()) |
1096 return true; | 1089 return true; |
1097 } | 1090 } |
1098 | 1091 |
1099 #if !defined(USE_AURA) | 1092 #if defined(USE_AURA) |
1100 if (!views::Widget::IsPureViews()) | |
1101 return GetOmniboxViewWin()->SkipDefaultKeyEventProcessing(event); | |
1102 #endif | |
1103 NOTIMPLEMENTED(); | 1093 NOTIMPLEMENTED(); |
1104 return false; | 1094 return false; |
1105 #else | 1095 #else |
| 1096 return GetOmniboxViewWin()->SkipDefaultKeyEventProcessing(event); |
| 1097 #endif |
| 1098 |
| 1099 #else |
1106 // This method is not used for Linux ports. See FocusManager::OnKeyEvent() in | 1100 // This method is not used for Linux ports. See FocusManager::OnKeyEvent() in |
1107 // src/ui/views/focus/focus_manager.cc for details. | 1101 // src/ui/views/focus/focus_manager.cc for details. |
1108 return false; | 1102 return false; |
1109 #endif | 1103 #endif |
1110 } | 1104 } |
1111 | 1105 |
1112 void LocationBarView::GetAccessibleState(ui::AccessibleViewState* state) { | 1106 void LocationBarView::GetAccessibleState(ui::AccessibleViewState* state) { |
1113 state->role = ui::AccessibilityTypes::ROLE_LOCATION_BAR; | 1107 state->role = ui::AccessibilityTypes::ROLE_LOCATION_BAR; |
1114 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_LOCATION); | 1108 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_LOCATION); |
1115 state->value = location_entry_->GetText(); | 1109 state->value = location_entry_->GetText(); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1293 } | 1287 } |
1294 | 1288 |
1295 #if defined(OS_WIN) || defined(USE_AURA) | 1289 #if defined(OS_WIN) || defined(USE_AURA) |
1296 bool LocationBarView::HasValidSuggestText() const { | 1290 bool LocationBarView::HasValidSuggestText() const { |
1297 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && | 1291 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && |
1298 !suggested_text_view_->text().empty(); | 1292 !suggested_text_view_->text().empty(); |
1299 } | 1293 } |
1300 | 1294 |
1301 #if !defined(USE_AURA) | 1295 #if !defined(USE_AURA) |
1302 OmniboxViewWin* LocationBarView::GetOmniboxViewWin() { | 1296 OmniboxViewWin* LocationBarView::GetOmniboxViewWin() { |
1303 CHECK(!views::Widget::IsPureViews()); | |
1304 return static_cast<OmniboxViewWin*>(location_entry_.get()); | 1297 return static_cast<OmniboxViewWin*>(location_entry_.get()); |
1305 } | 1298 } |
1306 #endif | 1299 #endif |
1307 #endif | 1300 #endif |
OLD | NEW |