| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_view.h" | 5 #include "chrome/browser/views/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 "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 | 12 |
| 13 #include "app/gfx/canvas.h" | 13 #include "app/gfx/canvas.h" |
| 14 #include "app/gfx/color_utils.h" | 14 #include "app/gfx/color_utils.h" |
| 15 #include "app/l10n_util.h" | 15 #include "app/l10n_util.h" |
| 16 #include "app/resource_bundle.h" | 16 #include "app/resource_bundle.h" |
| 17 #include "base/file_util.h" | 17 #include "base/file_util.h" |
| 18 #include "base/keyboard_codes.h" | 18 #include "base/keyboard_codes.h" |
| 19 #include "base/path_service.h" | 19 #include "base/path_service.h" |
| 20 #include "base/string_util.h" | 20 #include "base/string_util.h" |
| 21 #include "chrome/app/chrome_dll_resource.h" | 21 #include "chrome/app/chrome_dll_resource.h" |
| 22 #include "chrome/browser/alternate_nav_url_fetcher.h" | 22 #include "chrome/browser/alternate_nav_url_fetcher.h" |
| 23 #include "chrome/browser/browser.h" | 23 #include "chrome/browser/browser.h" |
| 24 #include "chrome/browser/browser_list.h" | 24 #include "chrome/browser/browser_list.h" |
| 25 #include "chrome/browser/bubble_positioner.h" |
| 25 #include "chrome/browser/command_updater.h" | 26 #include "chrome/browser/command_updater.h" |
| 26 #include "chrome/browser/extensions/extension_browser_event_router.h" | 27 #include "chrome/browser/extensions/extension_browser_event_router.h" |
| 27 #include "chrome/browser/extensions/extension_tabs_module.h" | 28 #include "chrome/browser/extensions/extension_tabs_module.h" |
| 28 #include "chrome/browser/extensions/extensions_service.h" | 29 #include "chrome/browser/extensions/extensions_service.h" |
| 29 #include "chrome/browser/page_info_window.h" | 30 #include "chrome/browser/page_info_window.h" |
| 30 #include "chrome/browser/profile.h" | 31 #include "chrome/browser/profile.h" |
| 31 #include "chrome/browser/search_engines/template_url.h" | 32 #include "chrome/browser/search_engines/template_url.h" |
| 32 #include "chrome/browser/search_engines/template_url_model.h" | 33 #include "chrome/browser/search_engines/template_url_model.h" |
| 33 #include "chrome/browser/tab_contents/navigation_entry.h" | 34 #include "chrome/browser/tab_contents/navigation_entry.h" |
| 34 #include "chrome/browser/view_ids.h" | 35 #include "chrome/browser/view_ids.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 const BubblePositioner* bubble_positioner) | 90 const BubblePositioner* bubble_positioner) |
| 90 : profile_(profile), | 91 : profile_(profile), |
| 91 command_updater_(command_updater), | 92 command_updater_(command_updater), |
| 92 model_(model), | 93 model_(model), |
| 93 delegate_(delegate), | 94 delegate_(delegate), |
| 94 disposition_(CURRENT_TAB), | 95 disposition_(CURRENT_TAB), |
| 95 location_entry_view_(NULL), | 96 location_entry_view_(NULL), |
| 96 selected_keyword_view_(profile), | 97 selected_keyword_view_(profile), |
| 97 keyword_hint_view_(profile), | 98 keyword_hint_view_(profile), |
| 98 type_to_search_view_(l10n_util::GetString(IDS_OMNIBOX_EMPTY_TEXT)), | 99 type_to_search_view_(l10n_util::GetString(IDS_OMNIBOX_EMPTY_TEXT)), |
| 99 security_image_view_(profile, model), | 100 security_image_view_(profile, model, bubble_positioner), |
| 100 popup_window_mode_(popup_window_mode), | 101 popup_window_mode_(popup_window_mode), |
| 101 first_run_bubble_(this), | 102 first_run_bubble_(this), |
| 102 bubble_positioner_(bubble_positioner) { | 103 bubble_positioner_(bubble_positioner) { |
| 103 DCHECK(profile_); | 104 DCHECK(profile_); |
| 104 SetID(VIEW_ID_LOCATION_BAR); | 105 SetID(VIEW_ID_LOCATION_BAR); |
| 105 SetFocusable(true); | 106 SetFocusable(true); |
| 106 | 107 |
| 107 if (!kBackground) { | 108 if (!kBackground) { |
| 108 ResourceBundle &rb = ResourceBundle::GetSharedInstance(); | 109 ResourceBundle &rb = ResourceBundle::GetSharedInstance(); |
| 109 kBackground = rb.GetBitmapNamed(IDR_LOCATIONBG); | 110 kBackground = rb.GetBitmapNamed(IDR_LOCATIONBG); |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 page_actions = profile_->GetExtensionsService()->GetPageActions(); | 660 page_actions = profile_->GetExtensionsService()->GetPageActions(); |
| 660 | 661 |
| 661 // On startup we sometimes haven't loaded any extensions. This makes sure | 662 // On startup we sometimes haven't loaded any extensions. This makes sure |
| 662 // we catch up when the extensions (and any page actions) load. | 663 // we catch up when the extensions (and any page actions) load. |
| 663 if (page_actions.size() != page_action_image_views_.size()) { | 664 if (page_actions.size() != page_action_image_views_.size()) { |
| 664 DeletePageActionViews(); // Delete the old views (if any). | 665 DeletePageActionViews(); // Delete the old views (if any). |
| 665 | 666 |
| 666 page_action_image_views_.resize(page_actions.size()); | 667 page_action_image_views_.resize(page_actions.size()); |
| 667 | 668 |
| 668 for (size_t i = 0; i < page_actions.size(); ++i) { | 669 for (size_t i = 0; i < page_actions.size(); ++i) { |
| 669 page_action_image_views_[i] = | 670 page_action_image_views_[i] = new PageActionImageView(this, profile_, |
| 670 new PageActionImageView(this, profile_, page_actions[i]); | 671 page_actions[i], bubble_positioner_); |
| 671 page_action_image_views_[i]->SetVisible(false); | 672 page_action_image_views_[i]->SetVisible(false); |
| 672 page_action_image_views_[i]->SetParentOwned(false); | 673 page_action_image_views_[i]->SetParentOwned(false); |
| 673 AddChildView(page_action_image_views_[i]); | 674 AddChildView(page_action_image_views_[i]); |
| 674 } | 675 } |
| 675 } | 676 } |
| 676 | 677 |
| 677 TabContents* contents = delegate_->GetTabContents(); | 678 TabContents* contents = delegate_->GetTabContents(); |
| 678 if (!page_action_image_views_.empty() && contents) { | 679 if (!page_action_image_views_.empty() && contents) { |
| 679 GURL url = GURL(WideToUTF8(model_->GetText())); | 680 GURL url = GURL(WideToUTF8(model_->GetText())); |
| 680 | 681 |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1053 | 1054 |
| 1054 #if defined(OS_WIN) | 1055 #if defined(OS_WIN) |
| 1055 FirstRunBubble::Show(profile_, GetWindow(), bounds, use_OEM_bubble); | 1056 FirstRunBubble::Show(profile_, GetWindow(), bounds, use_OEM_bubble); |
| 1056 #else | 1057 #else |
| 1057 // First run bubble doesn't make sense for Chrome OS. | 1058 // First run bubble doesn't make sense for Chrome OS. |
| 1058 #endif | 1059 #endif |
| 1059 } | 1060 } |
| 1060 | 1061 |
| 1061 // LocationBarImageView--------------------------------------------------------- | 1062 // LocationBarImageView--------------------------------------------------------- |
| 1062 | 1063 |
| 1063 LocationBarView::LocationBarImageView::LocationBarImageView() | 1064 LocationBarView::LocationBarImageView::LocationBarImageView( |
| 1064 : info_bubble_(NULL), | 1065 const BubblePositioner* bubble_positioner) |
| 1065 show_info_bubble_task_(NULL) { | 1066 : info_bubble_(NULL), |
| 1067 show_info_bubble_task_(NULL), |
| 1068 bubble_positioner_(bubble_positioner) { |
| 1066 } | 1069 } |
| 1067 | 1070 |
| 1068 LocationBarView::LocationBarImageView::~LocationBarImageView() { | 1071 LocationBarView::LocationBarImageView::~LocationBarImageView() { |
| 1069 if (show_info_bubble_task_) | 1072 if (show_info_bubble_task_) |
| 1070 show_info_bubble_task_->Cancel(); | 1073 show_info_bubble_task_->Cancel(); |
| 1071 | 1074 |
| 1072 if (info_bubble_) | 1075 if (info_bubble_) |
| 1073 info_bubble_->Close(); | 1076 info_bubble_->Close(); |
| 1074 } | 1077 } |
| 1075 | 1078 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1101 info_bubble_->Close(); | 1104 info_bubble_->Close(); |
| 1102 } | 1105 } |
| 1103 | 1106 |
| 1104 void LocationBarView::LocationBarImageView::InfoBubbleClosing( | 1107 void LocationBarView::LocationBarImageView::InfoBubbleClosing( |
| 1105 InfoBubble* info_bubble, bool closed_by_escape) { | 1108 InfoBubble* info_bubble, bool closed_by_escape) { |
| 1106 info_bubble_ = NULL; | 1109 info_bubble_ = NULL; |
| 1107 } | 1110 } |
| 1108 | 1111 |
| 1109 void LocationBarView::LocationBarImageView::ShowInfoBubbleImpl( | 1112 void LocationBarView::LocationBarImageView::ShowInfoBubbleImpl( |
| 1110 const std::wstring& text, SkColor text_color) { | 1113 const std::wstring& text, SkColor text_color) { |
| 1114 gfx::Rect bounds(bubble_positioner_->GetLocationStackBounds()); |
| 1111 gfx::Point location; | 1115 gfx::Point location; |
| 1112 views::View::ConvertPointToScreen(this, &location); | 1116 views::View::ConvertPointToScreen(this, &location); |
| 1113 gfx::Rect bounds(location.x(), location.y(), width(), height()); | 1117 bounds.set_x(location.x()); |
| 1118 bounds.set_width(width()); |
| 1114 | 1119 |
| 1115 views::Label* label = new views::Label(text); | 1120 views::Label* label = new views::Label(text); |
| 1116 label->SetMultiLine(true); | 1121 label->SetMultiLine(true); |
| 1117 label->SetColor(text_color); | 1122 label->SetColor(text_color); |
| 1118 label->SetFont(ResourceBundle::GetSharedInstance().GetFont( | 1123 label->SetFont(ResourceBundle::GetSharedInstance().GetFont( |
| 1119 ResourceBundle::BaseFont).DeriveFont(2)); | 1124 ResourceBundle::BaseFont).DeriveFont(2)); |
| 1120 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 1125 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 1121 label->SizeToFit(0); | 1126 label->SizeToFit(0); |
| 1122 DCHECK(info_bubble_ == NULL); | 1127 DCHECK(info_bubble_ == NULL); |
| 1123 info_bubble_ = InfoBubble::Show(GetWindow(), bounds, label, this); | 1128 info_bubble_ = InfoBubble::Show(GetWindow(), bounds, label, this); |
| 1124 show_info_bubble_task_ = NULL; | 1129 show_info_bubble_task_ = NULL; |
| 1125 } | 1130 } |
| 1126 | 1131 |
| 1127 // SecurityImageView------------------------------------------------------------ | 1132 // SecurityImageView------------------------------------------------------------ |
| 1128 | 1133 |
| 1129 // static | 1134 // static |
| 1130 SkBitmap* LocationBarView::SecurityImageView::lock_icon_ = NULL; | 1135 SkBitmap* LocationBarView::SecurityImageView::lock_icon_ = NULL; |
| 1131 SkBitmap* LocationBarView::SecurityImageView::warning_icon_ = NULL; | 1136 SkBitmap* LocationBarView::SecurityImageView::warning_icon_ = NULL; |
| 1132 | 1137 |
| 1133 LocationBarView::SecurityImageView::SecurityImageView(Profile* profile, | 1138 LocationBarView::SecurityImageView::SecurityImageView( |
| 1134 ToolbarModel* model) | 1139 Profile* profile, |
| 1135 : LocationBarImageView(), | 1140 ToolbarModel* model, |
| 1136 profile_(profile), | 1141 const BubblePositioner* bubble_positioner) |
| 1137 model_(model) { | 1142 : LocationBarImageView(bubble_positioner), |
| 1143 profile_(profile), |
| 1144 model_(model) { |
| 1138 if (!lock_icon_) { | 1145 if (!lock_icon_) { |
| 1139 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 1146 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 1140 lock_icon_ = rb.GetBitmapNamed(IDR_LOCK); | 1147 lock_icon_ = rb.GetBitmapNamed(IDR_LOCK); |
| 1141 warning_icon_ = rb.GetBitmapNamed(IDR_WARNING); | 1148 warning_icon_ = rb.GetBitmapNamed(IDR_WARNING); |
| 1142 } | 1149 } |
| 1143 SetImageShown(LOCK); | 1150 SetImageShown(LOCK); |
| 1144 } | 1151 } |
| 1145 | 1152 |
| 1146 LocationBarView::SecurityImageView::~SecurityImageView() { | 1153 LocationBarView::SecurityImageView::~SecurityImageView() { |
| 1147 } | 1154 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1178 ShowInfoBubbleImpl(text, GetColor( | 1185 ShowInfoBubbleImpl(text, GetColor( |
| 1179 model_->GetSecurityLevel() == ToolbarModel::SECURE, | 1186 model_->GetSecurityLevel() == ToolbarModel::SECURE, |
| 1180 SECURITY_INFO_BUBBLE_TEXT)); | 1187 SECURITY_INFO_BUBBLE_TEXT)); |
| 1181 } | 1188 } |
| 1182 | 1189 |
| 1183 // PageActionImageView---------------------------------------------------------- | 1190 // PageActionImageView---------------------------------------------------------- |
| 1184 | 1191 |
| 1185 LocationBarView::PageActionImageView::PageActionImageView( | 1192 LocationBarView::PageActionImageView::PageActionImageView( |
| 1186 LocationBarView* owner, | 1193 LocationBarView* owner, |
| 1187 Profile* profile, | 1194 Profile* profile, |
| 1188 const PageAction* page_action) | 1195 const PageAction* page_action, |
| 1189 : LocationBarImageView(), | 1196 const BubblePositioner* bubble_positioner) |
| 1197 : LocationBarImageView(bubble_positioner), |
| 1190 owner_(owner), | 1198 owner_(owner), |
| 1191 profile_(profile), | 1199 profile_(profile), |
| 1192 page_action_(page_action), | 1200 page_action_(page_action), |
| 1193 current_tab_id_(-1), | 1201 current_tab_id_(-1), |
| 1194 tooltip_(page_action_->name()) { | 1202 tooltip_(page_action_->name()) { |
| 1195 Extension* extension = profile->GetExtensionsService()->GetExtensionById( | 1203 Extension* extension = profile->GetExtensionsService()->GetExtensionById( |
| 1196 page_action->extension_id()); | 1204 page_action->extension_id()); |
| 1197 DCHECK(extension); | 1205 DCHECK(extension); |
| 1198 | 1206 |
| 1199 // Load the images this view needs asynchronously on the file thread. We'll | 1207 // Load the images this view needs asynchronously on the file thread. We'll |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1318 } | 1326 } |
| 1319 | 1327 |
| 1320 int LocationBarView::PageActionVisibleCount() { | 1328 int LocationBarView::PageActionVisibleCount() { |
| 1321 int result = 0; | 1329 int result = 0; |
| 1322 for (size_t i = 0; i < page_action_image_views_.size(); i++) { | 1330 for (size_t i = 0; i < page_action_image_views_.size(); i++) { |
| 1323 if (page_action_image_views_[i]->IsVisible()) | 1331 if (page_action_image_views_[i]->IsVisible()) |
| 1324 ++result; | 1332 ++result; |
| 1325 } | 1333 } |
| 1326 return result; | 1334 return result; |
| 1327 } | 1335 } |
| OLD | NEW |