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 #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 #if defined(TOOLKIT_USES_GTK) | 7 #if defined(TOOLKIT_USES_GTK) |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 if (!text.empty()) { | 421 if (!text.empty()) { |
422 if (!suggested_text_view_) { | 422 if (!suggested_text_view_) { |
423 suggested_text_view_ = new SuggestedTextView(location_entry_->model()); | 423 suggested_text_view_ = new SuggestedTextView(location_entry_->model()); |
424 suggested_text_view_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 424 suggested_text_view_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
425 suggested_text_view_->SetColor( | 425 suggested_text_view_->SetColor( |
426 GetColor(ToolbarModel::NONE, | 426 GetColor(ToolbarModel::NONE, |
427 LocationBarView::DEEMPHASIZED_TEXT)); | 427 LocationBarView::DEEMPHASIZED_TEXT)); |
428 suggested_text_view_->SetText(UTF16ToWide(text)); | 428 suggested_text_view_->SetText(UTF16ToWide(text)); |
429 if (views::Widget::IsPureViews()) | 429 if (views::Widget::IsPureViews()) |
430 NOTIMPLEMENTED(); | 430 NOTIMPLEMENTED(); |
| 431 #if !defined(USE_AURA) |
431 else | 432 else |
432 suggested_text_view_->SetFont(GetOmniboxViewWin()->GetFont()); | 433 suggested_text_view_->SetFont(GetOmniboxViewWin()->GetFont()); |
| 434 #endif |
433 AddChildView(suggested_text_view_); | 435 AddChildView(suggested_text_view_); |
434 } else if (suggested_text_view_->GetText() != UTF16ToWide(text)) { | 436 } else if (suggested_text_view_->GetText() != UTF16ToWide(text)) { |
435 suggested_text_view_->SetText(UTF16ToWide(text)); | 437 suggested_text_view_->SetText(UTF16ToWide(text)); |
436 } | 438 } |
437 if (animate_to_complete && !location_entry_->IsImeComposing()) | 439 if (animate_to_complete && !location_entry_->IsImeComposing()) |
438 suggested_text_view_->StartAnimation(); | 440 suggested_text_view_->StartAnimation(); |
439 } else if (suggested_text_view_) { | 441 } else if (suggested_text_view_) { |
440 delete suggested_text_view_; | 442 delete suggested_text_view_; |
441 suggested_text_view_ = NULL; | 443 suggested_text_view_ = NULL; |
442 } else { | 444 } else { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 ev_bubble_width = std::min(ev_bubble_width, std::max(kMinElidedBubbleWidth, | 540 ev_bubble_width = std::min(ev_bubble_width, std::max(kMinElidedBubbleWidth, |
539 static_cast<int>((entry_width - total_padding) * kMaxBubbleFraction))); | 541 static_cast<int>((entry_width - total_padding) * kMaxBubbleFraction))); |
540 entry_width -= (total_padding + ev_bubble_width); | 542 entry_width -= (total_padding + ev_bubble_width); |
541 } | 543 } |
542 | 544 |
543 #if defined(OS_WIN) | 545 #if defined(OS_WIN) |
544 int max_edit_width = entry_width; | 546 int max_edit_width = entry_width; |
545 if (views::Widget::IsPureViews()) { | 547 if (views::Widget::IsPureViews()) { |
546 NOTIMPLEMENTED(); | 548 NOTIMPLEMENTED(); |
547 } else { | 549 } else { |
| 550 #if !defined(USE_AURA) |
548 RECT formatting_rect; | 551 RECT formatting_rect; |
549 GetOmniboxViewWin()->GetRect(&formatting_rect); | 552 GetOmniboxViewWin()->GetRect(&formatting_rect); |
550 RECT edit_bounds; | 553 RECT edit_bounds; |
551 GetOmniboxViewWin()->GetClientRect(&edit_bounds); | 554 GetOmniboxViewWin()->GetClientRect(&edit_bounds); |
552 max_edit_width = entry_width - formatting_rect.left - | 555 max_edit_width = entry_width - formatting_rect.left - |
553 (edit_bounds.right - formatting_rect.right); | 556 (edit_bounds.right - formatting_rect.right); |
| 557 #endif |
554 } | 558 } |
555 #else | 559 #else |
556 int max_edit_width = entry_width; | 560 int max_edit_width = entry_width; |
557 #endif | 561 #endif |
558 | 562 |
559 if (max_edit_width < 0) | 563 if (max_edit_width < 0) |
560 return; | 564 return; |
561 const int available_width = AvailableWidth(max_edit_width); | 565 const int available_width = AvailableWidth(max_edit_width); |
562 | 566 |
563 const bool show_keyword_hint = !keyword.empty() && is_keyword_hint; | 567 const bool show_keyword_hint = !keyword.empty() && is_keyword_hint; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 // or the user has scrolled. | 671 // or the user has scrolled. |
668 | 672 |
669 // TODO(sky): We could potentially combine this with the previous step to | 673 // TODO(sky): We could potentially combine this with the previous step to |
670 // force using minimum size if necessary, but currently the chance of showing | 674 // force using minimum size if necessary, but currently the chance of showing |
671 // keyword hints and suggested text is minimal and we're not confident this | 675 // keyword hints and suggested text is minimal and we're not confident this |
672 // is the right approach for suggested text. | 676 // is the right approach for suggested text. |
673 if (suggested_text_view_) { | 677 if (suggested_text_view_) { |
674 if (views::Widget::IsPureViews()) { | 678 if (views::Widget::IsPureViews()) { |
675 NOTIMPLEMENTED(); | 679 NOTIMPLEMENTED(); |
676 } else { | 680 } else { |
| 681 #if !defined(USE_AURA) |
677 // TODO(sky): need to layout when the user changes caret position. | 682 // TODO(sky): need to layout when the user changes caret position. |
678 int suggested_text_width = | 683 int suggested_text_width = |
679 suggested_text_view_->GetPreferredSize().width(); | 684 suggested_text_view_->GetPreferredSize().width(); |
680 int vis_text_width = GetOmniboxViewWin()->WidthOfTextAfterCursor(); | 685 int vis_text_width = GetOmniboxViewWin()->WidthOfTextAfterCursor(); |
681 if (vis_text_width + suggested_text_width > entry_width) { | 686 if (vis_text_width + suggested_text_width > entry_width) { |
682 // Hide the suggested text if the user has scrolled or we can't fit all | 687 // Hide the suggested text if the user has scrolled or we can't fit all |
683 // the suggested text. | 688 // the suggested text. |
684 suggested_text_view_->SetBounds(0, 0, 0, 0); | 689 suggested_text_view_->SetBounds(0, 0, 0, 0); |
685 } else { | 690 } else { |
686 int location_needed_width = location_entry_->TextWidth(); | 691 int location_needed_width = location_entry_->TextWidth(); |
687 location_bounds.set_width(std::min(location_needed_width, | 692 location_bounds.set_width(std::min(location_needed_width, |
688 entry_width - suggested_text_width)); | 693 entry_width - suggested_text_width)); |
689 // TODO(sky): figure out why this needs the -1. | 694 // TODO(sky): figure out why this needs the -1. |
690 suggested_text_view_->SetBounds(location_bounds.right() - 1, | 695 suggested_text_view_->SetBounds(location_bounds.right() - 1, |
691 location_bounds.y(), | 696 location_bounds.y(), |
692 suggested_text_width, | 697 suggested_text_width, |
693 location_bounds.height()); | 698 location_bounds.height()); |
694 } | 699 } |
| 700 #endif |
695 } | 701 } |
696 } | 702 } |
697 #endif | 703 #endif |
698 | 704 |
699 location_entry_view_->SetBoundsRect(location_bounds); | 705 location_entry_view_->SetBoundsRect(location_bounds); |
700 } | 706 } |
701 | 707 |
702 void LocationBarView::OnPaint(gfx::Canvas* canvas) { | 708 void LocationBarView::OnPaint(gfx::Canvas* canvas) { |
703 View::OnPaint(canvas); | 709 View::OnPaint(canvas); |
704 | 710 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
750 | 756 |
751 void LocationBarView::SetShowFocusRect(bool show) { | 757 void LocationBarView::SetShowFocusRect(bool show) { |
752 show_focus_rect_ = show; | 758 show_focus_rect_ = show; |
753 SchedulePaint(); | 759 SchedulePaint(); |
754 } | 760 } |
755 | 761 |
756 void LocationBarView::SelectAll() { | 762 void LocationBarView::SelectAll() { |
757 location_entry_->SelectAll(true); | 763 location_entry_->SelectAll(true); |
758 } | 764 } |
759 | 765 |
760 #if defined(OS_WIN) | 766 #if defined(OS_WIN) && !defined(USE_AURA) |
761 bool LocationBarView::OnMousePressed(const views::MouseEvent& event) { | 767 bool LocationBarView::OnMousePressed(const views::MouseEvent& event) { |
762 UINT msg; | 768 UINT msg; |
763 if (event.IsLeftMouseButton()) { | 769 if (event.IsLeftMouseButton()) { |
764 msg = (event.flags() & ui::EF_IS_DOUBLE_CLICK) ? | 770 msg = (event.flags() & ui::EF_IS_DOUBLE_CLICK) ? |
765 WM_LBUTTONDBLCLK : WM_LBUTTONDOWN; | 771 WM_LBUTTONDBLCLK : WM_LBUTTONDOWN; |
766 } else if (event.IsMiddleMouseButton()) { | 772 } else if (event.IsMiddleMouseButton()) { |
767 msg = (event.flags() & ui::EF_IS_DOUBLE_CLICK) ? | 773 msg = (event.flags() & ui::EF_IS_DOUBLE_CLICK) ? |
768 WM_MBUTTONDBLCLK : WM_MBUTTONDOWN; | 774 WM_MBUTTONDBLCLK : WM_MBUTTONDOWN; |
769 } else if (event.IsRightMouseButton()) { | 775 } else if (event.IsRightMouseButton()) { |
770 msg = (event.flags() & ui::EF_IS_DOUBLE_CLICK) ? | 776 msg = (event.flags() & ui::EF_IS_DOUBLE_CLICK) ? |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
982 old_visibility[action] != (*i)->IsVisible()) { | 988 old_visibility[action] != (*i)->IsVisible()) { |
983 NotificationService::current()->Notify( | 989 NotificationService::current()->Notify( |
984 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, | 990 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, |
985 Source<ExtensionAction>(action), | 991 Source<ExtensionAction>(action), |
986 Details<TabContents>(contents)); | 992 Details<TabContents>(contents)); |
987 } | 993 } |
988 } | 994 } |
989 } | 995 } |
990 } | 996 } |
991 | 997 |
992 #if defined(OS_WIN) | 998 #if defined(OS_WIN) && !defined(USE_AURA) |
993 void LocationBarView::OnMouseEvent(const views::MouseEvent& event, UINT msg) { | 999 void LocationBarView::OnMouseEvent(const views::MouseEvent& event, UINT msg) { |
994 UINT flags = event.GetWindowsFlags(); | 1000 UINT flags = event.GetWindowsFlags(); |
995 gfx::Point screen_point(event.location()); | 1001 gfx::Point screen_point(event.location()); |
996 ConvertPointToScreen(this, &screen_point); | 1002 ConvertPointToScreen(this, &screen_point); |
997 if (views::Widget::IsPureViews()) | 1003 if (views::Widget::IsPureViews()) |
998 NOTIMPLEMENTED(); | 1004 NOTIMPLEMENTED(); |
999 else | 1005 else |
1000 GetOmniboxViewWin()->HandleExternalMsg(msg, flags, screen_point.ToPOINT()); | 1006 GetOmniboxViewWin()->HandleExternalMsg(msg, flags, screen_point.ToPOINT()); |
1001 } | 1007 } |
1002 #endif | 1008 #endif |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1034 if (views::FocusManager::IsTabTraversalKeyEvent(event)) { | 1040 if (views::FocusManager::IsTabTraversalKeyEvent(event)) { |
1035 if (HasValidSuggestText()) { | 1041 if (HasValidSuggestText()) { |
1036 // Return true so that the edit sees the tab and commits the suggestion. | 1042 // Return true so that the edit sees the tab and commits the suggestion. |
1037 return true; | 1043 return true; |
1038 } | 1044 } |
1039 if (keyword_hint_view_->IsVisible() && !event.IsShiftDown()) { | 1045 if (keyword_hint_view_->IsVisible() && !event.IsShiftDown()) { |
1040 // Return true so the edit gets the tab event and enters keyword mode. | 1046 // Return true so the edit gets the tab event and enters keyword mode. |
1041 return true; | 1047 return true; |
1042 } | 1048 } |
1043 | 1049 |
| 1050 #if !defined(USE_AURA) |
1044 // If the caret is not at the end, then tab moves the caret to the end. | 1051 // If the caret is not at the end, then tab moves the caret to the end. |
1045 if (!views_omnibox && !GetOmniboxViewWin()->IsCaretAtEnd()) | 1052 if (!views_omnibox && !GetOmniboxViewWin()->IsCaretAtEnd()) |
1046 return true; | 1053 return true; |
| 1054 #endif |
1047 | 1055 |
1048 // Tab while showing instant commits instant immediately. | 1056 // Tab while showing instant commits instant immediately. |
1049 // Return true so that focus traversal isn't attempted. The edit ends | 1057 // Return true so that focus traversal isn't attempted. The edit ends |
1050 // up doing nothing in this case. | 1058 // up doing nothing in this case. |
1051 if (location_entry_->model()->AcceptCurrentInstantPreview()) | 1059 if (location_entry_->model()->AcceptCurrentInstantPreview()) |
1052 return true; | 1060 return true; |
1053 } | 1061 } |
1054 | 1062 |
| 1063 #if !defined(USE_AURA) |
1055 if (!views_omnibox) | 1064 if (!views_omnibox) |
1056 return GetOmniboxViewWin()->SkipDefaultKeyEventProcessing(event); | 1065 return GetOmniboxViewWin()->SkipDefaultKeyEventProcessing(event); |
| 1066 #endif |
1057 NOTIMPLEMENTED(); | 1067 NOTIMPLEMENTED(); |
1058 return false; | 1068 return false; |
1059 #else | 1069 #else |
1060 // This method is not used for Linux ports. See FocusManager::OnKeyEvent() in | 1070 // This method is not used for Linux ports. See FocusManager::OnKeyEvent() in |
1061 // src/views/focus/focus_manager.cc for details. | 1071 // src/views/focus/focus_manager.cc for details. |
1062 return false; | 1072 return false; |
1063 #endif | 1073 #endif |
1064 } | 1074 } |
1065 | 1075 |
1066 void LocationBarView::GetAccessibleState(ui::AccessibleViewState* state) { | 1076 void LocationBarView::GetAccessibleState(ui::AccessibleViewState* state) { |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1246 Update(NULL); | 1256 Update(NULL); |
1247 } | 1257 } |
1248 } | 1258 } |
1249 | 1259 |
1250 #if defined(OS_WIN) | 1260 #if defined(OS_WIN) |
1251 bool LocationBarView::HasValidSuggestText() const { | 1261 bool LocationBarView::HasValidSuggestText() const { |
1252 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && | 1262 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && |
1253 !suggested_text_view_->GetText().empty(); | 1263 !suggested_text_view_->GetText().empty(); |
1254 } | 1264 } |
1255 | 1265 |
| 1266 #if !defined(USE_AURA) |
1256 OmniboxViewWin* LocationBarView::GetOmniboxViewWin() { | 1267 OmniboxViewWin* LocationBarView::GetOmniboxViewWin() { |
1257 CHECK(!views::Widget::IsPureViews()); | 1268 CHECK(!views::Widget::IsPureViews()); |
1258 return static_cast<OmniboxViewWin*>(location_entry_.get()); | 1269 return static_cast<OmniboxViewWin*>(location_entry_.get()); |
1259 } | 1270 } |
1260 #endif | 1271 #endif |
| 1272 #endif |
OLD | NEW |