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 #include "chrome/browser/views/location_bar/location_bar_view.h" | 5 #include "chrome/browser/views/location_bar/location_bar_view.h" |
6 | 6 |
7 #if defined(OS_LINUX) | 7 #if defined(OS_LINUX) |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 #endif | 9 #endif |
10 | 10 |
11 #include "app/drag_drop_types.h" | 11 #include "app/drag_drop_types.h" |
12 #include "app/l10n_util.h" | 12 #include "app/l10n_util.h" |
13 #include "app/resource_bundle.h" | 13 #include "app/resource_bundle.h" |
14 #include "app/theme_provider.h" | 14 #include "app/theme_provider.h" |
15 #include "base/stl_util-inl.h" | 15 #include "base/stl_util-inl.h" |
16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
17 #include "chrome/app/chrome_command_ids.h" | 17 #include "chrome/app/chrome_command_ids.h" |
18 #include "chrome/browser/alternate_nav_url_fetcher.h" | 18 #include "chrome/browser/alternate_nav_url_fetcher.h" |
19 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 19 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
20 #include "chrome/browser/defaults.h" | 20 #include "chrome/browser/defaults.h" |
21 #include "chrome/browser/extensions/extension_browser_event_router.h" | 21 #include "chrome/browser/extensions/extension_browser_event_router.h" |
22 #include "chrome/browser/extensions/extensions_service.h" | 22 #include "chrome/browser/extensions/extensions_service.h" |
23 #include "chrome/browser/instant/instant_controller.h" | 23 #include "chrome/browser/instant/instant_controller.h" |
24 #include "chrome/browser/profile.h" | 24 #include "chrome/browser/profile.h" |
25 #include "chrome/browser/renderer_host/render_widget_host_view.h" | 25 #include "chrome/browser/renderer_host/render_widget_host_view.h" |
26 #include "chrome/browser/search_engines/template_url.h" | 26 #include "chrome/browser/search_engines/template_url.h" |
27 #include "chrome/browser/search_engines/template_url_model.h" | 27 #include "chrome/browser/search_engines/template_url_model.h" |
| 28 #include "chrome/browser/tab_contents_wrapper.h" |
28 #include "chrome/browser/ui/views/location_bar/suggested_text_view.h" | 29 #include "chrome/browser/ui/views/location_bar/suggested_text_view.h" |
29 #include "chrome/browser/view_ids.h" | 30 #include "chrome/browser/view_ids.h" |
30 #include "chrome/browser/views/browser_dialogs.h" | 31 #include "chrome/browser/views/browser_dialogs.h" |
31 #include "chrome/browser/views/location_bar/content_setting_image_view.h" | 32 #include "chrome/browser/views/location_bar/content_setting_image_view.h" |
32 #include "chrome/browser/views/location_bar/ev_bubble_view.h" | 33 #include "chrome/browser/views/location_bar/ev_bubble_view.h" |
33 #include "chrome/browser/views/location_bar/keyword_hint_view.h" | 34 #include "chrome/browser/views/location_bar/keyword_hint_view.h" |
34 #include "chrome/browser/views/location_bar/location_icon_view.h" | 35 #include "chrome/browser/views/location_bar/location_icon_view.h" |
35 #include "chrome/browser/views/location_bar/page_action_image_view.h" | 36 #include "chrome/browser/views/location_bar/page_action_image_view.h" |
36 #include "chrome/browser/views/location_bar/page_action_with_badge_view.h" | 37 #include "chrome/browser/views/location_bar/page_action_with_badge_view.h" |
37 #include "chrome/browser/views/location_bar/selected_keyword_view.h" | 38 #include "chrome/browser/views/location_bar/selected_keyword_view.h" |
38 #include "chrome/browser/views/location_bar/star_view.h" | 39 #include "chrome/browser/views/location_bar/star_view.h" |
39 #include "gfx/canvas_skia.h" | 40 #include "gfx/canvas_skia.h" |
40 #include "gfx/color_utils.h" | 41 #include "gfx/color_utils.h" |
41 #include "gfx/skia_util.h" | 42 #include "gfx/skia_util.h" |
42 #include "grit/generated_resources.h" | 43 #include "grit/generated_resources.h" |
43 #include "grit/theme_resources.h" | 44 #include "grit/theme_resources.h" |
44 #include "views/controls/label.h" | 45 #include "views/controls/label.h" |
45 #include "views/drag_utils.h" | 46 #include "views/drag_utils.h" |
46 | 47 |
47 #if defined(OS_WIN) | 48 #if defined(OS_WIN) |
48 #include "chrome/browser/views/first_run_bubble.h" | 49 #include "chrome/browser/views/first_run_bubble.h" |
49 #endif | 50 #endif |
50 | 51 |
51 using views::View; | 52 using views::View; |
52 | 53 |
| 54 namespace { |
| 55 TabContents* GetTabContentsFromDelegate(LocationBarView::Delegate* delegate) { |
| 56 const TabContentsWrapper* wrapper = delegate->GetTabContentsWrapper(); |
| 57 return wrapper ? wrapper->tab_contents() : NULL; |
| 58 } |
| 59 } // namespace |
| 60 |
53 // static | 61 // static |
54 const int LocationBarView::kNormalHorizontalEdgeThickness = 1; | 62 const int LocationBarView::kNormalHorizontalEdgeThickness = 1; |
55 const int LocationBarView::kVerticalEdgeThickness = 2; | 63 const int LocationBarView::kVerticalEdgeThickness = 2; |
56 const int LocationBarView::kItemPadding = 3; | 64 const int LocationBarView::kItemPadding = 3; |
57 const int LocationBarView::kExtensionItemPadding = 5; | 65 const int LocationBarView::kExtensionItemPadding = 5; |
58 const int LocationBarView::kEdgeItemPadding = kItemPadding; | 66 const int LocationBarView::kEdgeItemPadding = kItemPadding; |
59 const int LocationBarView::kBubblePadding = 1; | 67 const int LocationBarView::kBubblePadding = 1; |
60 const char LocationBarView::kViewClassName[] = | 68 const char LocationBarView::kViewClassName[] = |
61 "browser/views/location_bar/LocationBarView"; | 69 "browser/views/location_bar/LocationBarView"; |
62 | 70 |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 profile_ = profile; | 336 profile_ = profile; |
329 location_entry_->model()->SetProfile(profile); | 337 location_entry_->model()->SetProfile(profile); |
330 selected_keyword_view_->set_profile(profile); | 338 selected_keyword_view_->set_profile(profile); |
331 keyword_hint_view_->set_profile(profile); | 339 keyword_hint_view_->set_profile(profile); |
332 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); | 340 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); |
333 i != content_setting_views_.end(); ++i) | 341 i != content_setting_views_.end(); ++i) |
334 (*i)->set_profile(profile); | 342 (*i)->set_profile(profile); |
335 } | 343 } |
336 } | 344 } |
337 | 345 |
338 TabContents* LocationBarView::GetTabContents() const { | 346 TabContentsWrapper* LocationBarView::GetTabContentsWrapper() const { |
339 return delegate_->GetTabContents(); | 347 return delegate_->GetTabContentsWrapper(); |
340 } | 348 } |
341 | 349 |
342 void LocationBarView::SetPreviewEnabledPageAction(ExtensionAction* page_action, | 350 void LocationBarView::SetPreviewEnabledPageAction(ExtensionAction* page_action, |
343 bool preview_enabled) { | 351 bool preview_enabled) { |
344 if (mode_ != NORMAL) | 352 if (mode_ != NORMAL) |
345 return; | 353 return; |
346 | 354 |
347 DCHECK(page_action); | 355 DCHECK(page_action); |
348 TabContents* contents = delegate_->GetTabContents(); | 356 TabContents* contents = GetTabContentsFromDelegate(delegate_); |
349 | 357 |
350 RefreshPageActionViews(); | 358 RefreshPageActionViews(); |
351 PageActionWithBadgeView* page_action_view = | 359 PageActionWithBadgeView* page_action_view = |
352 static_cast<PageActionWithBadgeView*>(GetPageActionView(page_action)); | 360 static_cast<PageActionWithBadgeView*>(GetPageActionView(page_action)); |
353 DCHECK(page_action_view); | 361 DCHECK(page_action_view); |
354 if (!page_action_view) | 362 if (!page_action_view) |
355 return; | 363 return; |
356 | 364 |
357 page_action_view->image_view()->set_preview_enabled(preview_enabled); | 365 page_action_view->image_view()->set_preview_enabled(preview_enabled); |
358 page_action_view->UpdateVisibility(contents, | 366 page_action_view->UpdateVisibility(contents, |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 | 840 |
833 void LocationBarView::OnChanged() { | 841 void LocationBarView::OnChanged() { |
834 location_icon_view_->SetImage( | 842 location_icon_view_->SetImage( |
835 ResourceBundle::GetSharedInstance().GetBitmapNamed( | 843 ResourceBundle::GetSharedInstance().GetBitmapNamed( |
836 location_entry_->GetIcon())); | 844 location_entry_->GetIcon())); |
837 Layout(); | 845 Layout(); |
838 SchedulePaint(); | 846 SchedulePaint(); |
839 | 847 |
840 InstantController* instant = delegate_->GetInstant(); | 848 InstantController* instant = delegate_->GetInstant(); |
841 string16 suggested_text; | 849 string16 suggested_text; |
842 if (update_instant_ && instant && GetTabContents()) { | 850 if (update_instant_ && instant && GetTabContentsWrapper()) { |
843 if (location_entry_->model()->user_input_in_progress() && | 851 if (location_entry_->model()->user_input_in_progress() && |
844 location_entry_->model()->popup_model()->IsOpen()) { | 852 location_entry_->model()->popup_model()->IsOpen()) { |
845 instant->Update(GetTabContents(), | 853 instant->Update(GetTabContentsWrapper(), |
846 location_entry_->model()->CurrentMatch(), | 854 location_entry_->model()->CurrentMatch(), |
847 WideToUTF16(location_entry_->GetText()), | 855 WideToUTF16(location_entry_->GetText()), |
848 &suggested_text); | 856 &suggested_text); |
849 } else { | 857 } else { |
850 instant->DestroyPreviewContents(); | 858 instant->DestroyPreviewContents(); |
851 } | 859 } |
852 } | 860 } |
853 | 861 |
854 SetSuggestedText(suggested_text); | 862 SetSuggestedText(suggested_text); |
855 } | 863 } |
(...skipping 13 matching lines...) Expand all Loading... |
869 void LocationBarView::OnSetFocus() { | 877 void LocationBarView::OnSetFocus() { |
870 views::FocusManager* focus_manager = GetFocusManager(); | 878 views::FocusManager* focus_manager = GetFocusManager(); |
871 if (!focus_manager) { | 879 if (!focus_manager) { |
872 NOTREACHED(); | 880 NOTREACHED(); |
873 return; | 881 return; |
874 } | 882 } |
875 focus_manager->SetFocusedView(this); | 883 focus_manager->SetFocusedView(this); |
876 } | 884 } |
877 | 885 |
878 SkBitmap LocationBarView::GetFavIcon() const { | 886 SkBitmap LocationBarView::GetFavIcon() const { |
879 DCHECK(delegate_); | 887 return GetTabContentsFromDelegate(delegate_)->GetFavIcon(); |
880 DCHECK(delegate_->GetTabContents()); | |
881 return delegate_->GetTabContents()->GetFavIcon(); | |
882 } | 888 } |
883 | 889 |
884 std::wstring LocationBarView::GetTitle() const { | 890 std::wstring LocationBarView::GetTitle() const { |
885 DCHECK(delegate_); | 891 return UTF16ToWideHack(GetTabContentsFromDelegate(delegate_)->GetTitle()); |
886 DCHECK(delegate_->GetTabContents()); | |
887 return UTF16ToWideHack(delegate_->GetTabContents()->GetTitle()); | |
888 } | 892 } |
889 | 893 |
890 int LocationBarView::AvailableWidth(int location_bar_width) { | 894 int LocationBarView::AvailableWidth(int location_bar_width) { |
891 return location_bar_width - location_entry_->TextWidth(); | 895 return location_bar_width - location_entry_->TextWidth(); |
892 } | 896 } |
893 | 897 |
894 void LocationBarView::LayoutView(views::View* view, | 898 void LocationBarView::LayoutView(views::View* view, |
895 int padding, | 899 int padding, |
896 int available_width, | 900 int available_width, |
897 bool leading, | 901 bool leading, |
898 gfx::Rect* bounds) { | 902 gfx::Rect* bounds) { |
899 DCHECK(view && bounds); | 903 DCHECK(view && bounds); |
900 gfx::Size view_size = view->GetPreferredSize(); | 904 gfx::Size view_size = view->GetPreferredSize(); |
901 if ((view_size.width() + padding) > available_width) | 905 if ((view_size.width() + padding) > available_width) |
902 view_size = view->GetMinimumSize(); | 906 view_size = view->GetMinimumSize(); |
903 int desired_width = view_size.width() + padding; | 907 int desired_width = view_size.width() + padding; |
904 view->SetVisible(desired_width < bounds->width()); | 908 view->SetVisible(desired_width < bounds->width()); |
905 if (view->IsVisible()) { | 909 if (view->IsVisible()) { |
906 view->SetBounds( | 910 view->SetBounds( |
907 leading ? bounds->x() : (bounds->right() - view_size.width()), | 911 leading ? bounds->x() : (bounds->right() - view_size.width()), |
908 view->y(), view_size.width(), view->height()); | 912 view->y(), view_size.width(), view->height()); |
909 bounds->set_width(bounds->width() - desired_width); | 913 bounds->set_width(bounds->width() - desired_width); |
910 } | 914 } |
911 } | 915 } |
912 | 916 |
913 void LocationBarView::RefreshContentSettingViews() { | 917 void LocationBarView::RefreshContentSettingViews() { |
914 const TabContents* tab_contents = delegate_->GetTabContents(); | |
915 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); | 918 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); |
916 i != content_setting_views_.end(); ++i) { | 919 i != content_setting_views_.end(); ++i) { |
917 (*i)->UpdateFromTabContents( | 920 (*i)->UpdateFromTabContents( |
918 model_->input_in_progress() ? NULL : tab_contents); | 921 model_->input_in_progress() ? NULL : GetTabContentsFromDelegate(delegate
_)); |
919 } | 922 } |
920 } | 923 } |
921 | 924 |
922 void LocationBarView::DeletePageActionViews() { | 925 void LocationBarView::DeletePageActionViews() { |
923 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 926 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
924 i != page_action_views_.end(); ++i) | 927 i != page_action_views_.end(); ++i) |
925 RemoveChildView(*i); | 928 RemoveChildView(*i); |
926 STLDeleteElements(&page_action_views_); | 929 STLDeleteElements(&page_action_views_); |
927 } | 930 } |
928 | 931 |
(...skipping 28 matching lines...) Expand all Loading... |
957 // Add the page actions in reverse order, so that the child views are | 960 // Add the page actions in reverse order, so that the child views are |
958 // inserted in left-to-right order for accessibility. | 961 // inserted in left-to-right order for accessibility. |
959 for (int i = page_actions.size() - 1; i >= 0; --i) { | 962 for (int i = page_actions.size() - 1; i >= 0; --i) { |
960 page_action_views_[i] = new PageActionWithBadgeView( | 963 page_action_views_[i] = new PageActionWithBadgeView( |
961 new PageActionImageView(this, profile_, page_actions[i])); | 964 new PageActionImageView(this, profile_, page_actions[i])); |
962 page_action_views_[i]->SetVisible(false); | 965 page_action_views_[i]->SetVisible(false); |
963 AddChildView(GetChildIndex(star_view_), page_action_views_[i]); | 966 AddChildView(GetChildIndex(star_view_), page_action_views_[i]); |
964 } | 967 } |
965 } | 968 } |
966 | 969 |
967 TabContents* contents = delegate_->GetTabContents(); | 970 TabContents* contents = GetTabContentsFromDelegate(delegate_); |
968 if (!page_action_views_.empty() && contents) { | 971 if (!page_action_views_.empty() && contents) { |
969 GURL url = GURL(WideToUTF8(model_->GetText())); | 972 GURL url = GURL(WideToUTF8(model_->GetText())); |
970 | 973 |
971 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 974 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
972 i != page_action_views_.end(); ++i) { | 975 i != page_action_views_.end(); ++i) { |
973 (*i)->UpdateVisibility(model_->input_in_progress() ? NULL : contents, | 976 (*i)->UpdateVisibility(model_->input_in_progress() ? NULL : contents, |
974 url); | 977 url); |
975 | 978 |
976 // Check if the visibility of the action changed and notify if it did. | 979 // Check if the visibility of the action changed and notify if it did. |
977 ExtensionAction* action = (*i)->image_view()->page_action(); | 980 ExtensionAction* action = (*i)->image_view()->page_action(); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1060 | 1063 |
1061 AccessibilityTypes::Role LocationBarView::GetAccessibleRole() { | 1064 AccessibilityTypes::Role LocationBarView::GetAccessibleRole() { |
1062 return AccessibilityTypes::ROLE_GROUPING; | 1065 return AccessibilityTypes::ROLE_GROUPING; |
1063 } | 1066 } |
1064 | 1067 |
1065 void LocationBarView::WriteDragData(views::View* sender, | 1068 void LocationBarView::WriteDragData(views::View* sender, |
1066 const gfx::Point& press_pt, | 1069 const gfx::Point& press_pt, |
1067 OSExchangeData* data) { | 1070 OSExchangeData* data) { |
1068 DCHECK(GetDragOperations(sender, press_pt) != DragDropTypes::DRAG_NONE); | 1071 DCHECK(GetDragOperations(sender, press_pt) != DragDropTypes::DRAG_NONE); |
1069 | 1072 |
1070 TabContents* tab_contents = delegate_->GetTabContents(); | 1073 TabContents* tab_contents = GetTabContentsFromDelegate(delegate_); |
1071 DCHECK(tab_contents); | 1074 DCHECK(tab_contents); |
1072 drag_utils::SetURLAndDragImage(tab_contents->GetURL(), | 1075 drag_utils::SetURLAndDragImage(tab_contents->GetURL(), |
1073 UTF16ToWideHack(tab_contents->GetTitle()), | 1076 UTF16ToWideHack(tab_contents->GetTitle()), |
1074 tab_contents->GetFavIcon(), data); | 1077 tab_contents->GetFavIcon(), data); |
1075 } | 1078 } |
1076 | 1079 |
1077 int LocationBarView::GetDragOperations(views::View* sender, | 1080 int LocationBarView::GetDragOperations(views::View* sender, |
1078 const gfx::Point& p) { | 1081 const gfx::Point& p) { |
1079 DCHECK((sender == location_icon_view_) || (sender == ev_bubble_view_)); | 1082 DCHECK((sender == location_icon_view_) || (sender == ev_bubble_view_)); |
1080 TabContents* tab_contents = delegate_->GetTabContents(); | 1083 TabContents* tab_contents = GetTabContentsFromDelegate(delegate_); |
1081 return (tab_contents && tab_contents->GetURL().is_valid() && | 1084 return (tab_contents && tab_contents->GetURL().is_valid() && |
1082 !location_entry()->IsEditingOrEmpty()) ? | 1085 !location_entry()->IsEditingOrEmpty()) ? |
1083 (DragDropTypes::DRAG_COPY | DragDropTypes::DRAG_LINK) : | 1086 (DragDropTypes::DRAG_COPY | DragDropTypes::DRAG_LINK) : |
1084 DragDropTypes::DRAG_NONE; | 1087 DragDropTypes::DRAG_NONE; |
1085 } | 1088 } |
1086 | 1089 |
1087 bool LocationBarView::CanStartDrag(View* sender, | 1090 bool LocationBarView::CanStartDrag(View* sender, |
1088 const gfx::Point& press_pt, | 1091 const gfx::Point& press_pt, |
1089 const gfx::Point& p) { | 1092 const gfx::Point& p) { |
1090 return true; | 1093 return true; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1223 } | 1226 } |
1224 | 1227 |
1225 NOTREACHED(); | 1228 NOTREACHED(); |
1226 } | 1229 } |
1227 | 1230 |
1228 void LocationBarView::OnTemplateURLModelChanged() { | 1231 void LocationBarView::OnTemplateURLModelChanged() { |
1229 template_url_model_->RemoveObserver(this); | 1232 template_url_model_->RemoveObserver(this); |
1230 template_url_model_ = NULL; | 1233 template_url_model_ = NULL; |
1231 ShowFirstRunBubble(bubble_type_); | 1234 ShowFirstRunBubble(bubble_type_); |
1232 } | 1235 } |
OLD | NEW |