| 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 11 matching lines...) Expand all Loading... |
| 22 #include "chrome/browser/extensions/extension_tab_helper.h" | 22 #include "chrome/browser/extensions/extension_tab_helper.h" |
| 23 #include "chrome/browser/extensions/location_bar_controller.h" | 23 #include "chrome/browser/extensions/location_bar_controller.h" |
| 24 #include "chrome/browser/favicon/favicon_tab_helper.h" | 24 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 25 #include "chrome/browser/instant/instant_controller.h" | 25 #include "chrome/browser/instant/instant_controller.h" |
| 26 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
| 27 #include "chrome/browser/search_engines/template_url.h" | 27 #include "chrome/browser/search_engines/template_url.h" |
| 28 #include "chrome/browser/search_engines/template_url_service.h" | 28 #include "chrome/browser/search_engines/template_url_service.h" |
| 29 #include "chrome/browser/search_engines/template_url_service_factory.h" | 29 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 30 #include "chrome/browser/ui/browser.h" | 30 #include "chrome/browser/ui/browser.h" |
| 31 #include "chrome/browser/ui/browser_finder.h" | 31 #include "chrome/browser/ui/browser_finder.h" |
| 32 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 32 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 33 #include "chrome/browser/ui/view_ids.h" | 33 #include "chrome/browser/ui/view_ids.h" |
| 34 #include "chrome/browser/ui/views/browser_dialogs.h" | 34 #include "chrome/browser/ui/views/browser_dialogs.h" |
| 35 #include "chrome/browser/ui/views/location_bar/action_box_button_view.h" | 35 #include "chrome/browser/ui/views/location_bar/action_box_button_view.h" |
| 36 #include "chrome/browser/ui/views/location_bar/chrome_to_mobile_view.h" | 36 #include "chrome/browser/ui/views/location_bar/chrome_to_mobile_view.h" |
| 37 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" | 37 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" |
| 38 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" | 38 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" |
| 39 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" | 39 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" |
| 40 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" | 40 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" |
| 41 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" | 41 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" |
| 42 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" | 42 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 73 #if defined(OS_WIN) || defined(USE_AURA) | 73 #if defined(OS_WIN) || defined(USE_AURA) |
| 74 #include "chrome/browser/ui/views/location_bar/suggested_text_view.h" | 74 #include "chrome/browser/ui/views/location_bar/suggested_text_view.h" |
| 75 #endif | 75 #endif |
| 76 | 76 |
| 77 using content::WebContents; | 77 using content::WebContents; |
| 78 using views::View; | 78 using views::View; |
| 79 | 79 |
| 80 namespace { | 80 namespace { |
| 81 | 81 |
| 82 WebContents* GetWebContentsFromDelegate(LocationBarView::Delegate* delegate) { | 82 WebContents* GetWebContentsFromDelegate(LocationBarView::Delegate* delegate) { |
| 83 const TabContentsWrapper* wrapper = delegate->GetTabContentsWrapper(); | 83 const TabContents* tab_contents = delegate->GetTabContents(); |
| 84 return wrapper ? wrapper->web_contents() : NULL; | 84 return tab_contents ? tab_contents->web_contents() : NULL; |
| 85 } | 85 } |
| 86 | 86 |
| 87 // A utility function to cast OmniboxView to OmniboxViewViews. | 87 // A utility function to cast OmniboxView to OmniboxViewViews. |
| 88 OmniboxViewViews* AsViews(OmniboxView* view) { | 88 OmniboxViewViews* AsViews(OmniboxView* view) { |
| 89 return static_cast<OmniboxViewViews*>(view); | 89 return static_cast<OmniboxViewViews*>(view); |
| 90 } | 90 } |
| 91 | 91 |
| 92 // Height of the location bar's round corner region. | 92 // Height of the location bar's round corner region. |
| 93 const int kBorderRoundCornerHeight = 5; | 93 const int kBorderRoundCornerHeight = 5; |
| 94 // Width of location bar's round corner region. | 94 // Width of location bar's round corner region. |
| (...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 945 void LocationBarView::OnSetFocus() { | 945 void LocationBarView::OnSetFocus() { |
| 946 views::FocusManager* focus_manager = GetFocusManager(); | 946 views::FocusManager* focus_manager = GetFocusManager(); |
| 947 if (!focus_manager) { | 947 if (!focus_manager) { |
| 948 NOTREACHED(); | 948 NOTREACHED(); |
| 949 return; | 949 return; |
| 950 } | 950 } |
| 951 focus_manager->SetFocusedView(this); | 951 focus_manager->SetFocusedView(this); |
| 952 } | 952 } |
| 953 | 953 |
| 954 SkBitmap LocationBarView::GetFavicon() const { | 954 SkBitmap LocationBarView::GetFavicon() const { |
| 955 return delegate_->GetTabContentsWrapper()->favicon_tab_helper()->GetFavicon(); | 955 return delegate_->GetTabContents()->favicon_tab_helper()->GetFavicon(); |
| 956 } | 956 } |
| 957 | 957 |
| 958 string16 LocationBarView::GetTitle() const { | 958 string16 LocationBarView::GetTitle() const { |
| 959 return GetWebContentsFromDelegate(delegate_)->GetTitle(); | 959 return GetWebContentsFromDelegate(delegate_)->GetTitle(); |
| 960 } | 960 } |
| 961 | 961 |
| 962 InstantController* LocationBarView::GetInstant() { | 962 InstantController* LocationBarView::GetInstant() { |
| 963 return delegate_->GetInstant(); | 963 return delegate_->GetInstant(); |
| 964 } | 964 } |
| 965 | 965 |
| 966 TabContentsWrapper* LocationBarView::GetTabContentsWrapper() const { | 966 TabContents* LocationBarView::GetTabContents() const { |
| 967 return delegate_->GetTabContentsWrapper(); | 967 return delegate_->GetTabContents(); |
| 968 } | 968 } |
| 969 | 969 |
| 970 int LocationBarView::AvailableWidth(int location_bar_width) { | 970 int LocationBarView::AvailableWidth(int location_bar_width) { |
| 971 return location_bar_width - location_entry_->TextWidth(); | 971 return location_bar_width - location_entry_->TextWidth(); |
| 972 } | 972 } |
| 973 | 973 |
| 974 void LocationBarView::LayoutView(views::View* view, | 974 void LocationBarView::LayoutView(views::View* view, |
| 975 int padding, | 975 int padding, |
| 976 int available_width, | 976 int available_width, |
| 977 bool leading, | 977 bool leading, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1012 // Remember the previous visibility of the page actions so that we can | 1012 // Remember the previous visibility of the page actions so that we can |
| 1013 // notify when this changes. | 1013 // notify when this changes. |
| 1014 std::map<ExtensionAction*, bool> old_visibility; | 1014 std::map<ExtensionAction*, bool> old_visibility; |
| 1015 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 1015 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
| 1016 i != page_action_views_.end(); ++i) { | 1016 i != page_action_views_.end(); ++i) { |
| 1017 old_visibility[(*i)->image_view()->page_action()] = (*i)->visible(); | 1017 old_visibility[(*i)->image_view()->page_action()] = (*i)->visible(); |
| 1018 } | 1018 } |
| 1019 | 1019 |
| 1020 std::vector<ExtensionAction*> page_actions; | 1020 std::vector<ExtensionAction*> page_actions; |
| 1021 | 1021 |
| 1022 TabContentsWrapper* tab_contents = GetTabContentsWrapper(); | 1022 TabContents* tab_contents = GetTabContents(); |
| 1023 if (tab_contents) { | 1023 if (tab_contents) { |
| 1024 extensions::LocationBarController* controller = | 1024 extensions::LocationBarController* controller = |
| 1025 tab_contents->extension_tab_helper()->location_bar_controller(); | 1025 tab_contents->extension_tab_helper()->location_bar_controller(); |
| 1026 page_actions.swap(*controller->GetCurrentActions()); | 1026 page_actions.swap(*controller->GetCurrentActions()); |
| 1027 } | 1027 } |
| 1028 | 1028 |
| 1029 // On startup we sometimes haven't loaded any extensions. This makes sure | 1029 // On startup we sometimes haven't loaded any extensions. This makes sure |
| 1030 // we catch up when the extensions (and any page actions) load. | 1030 // we catch up when the extensions (and any page actions) load. |
| 1031 if (page_actions.size() != page_action_views_.size()) { | 1031 if (page_actions.size() != page_action_views_.size()) { |
| 1032 DeletePageActionViews(); // Delete the old views (if any). | 1032 DeletePageActionViews(); // Delete the old views (if any). |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1046 delegate_->CreatePageActionImageView(this, page_actions[i])); | 1046 delegate_->CreatePageActionImageView(this, page_actions[i])); |
| 1047 page_action_views_[i]->SetVisible(false); | 1047 page_action_views_[i]->SetVisible(false); |
| 1048 AddChildViewAt(page_action_views_[i], GetIndexOf(right_anchor)); | 1048 AddChildViewAt(page_action_views_[i], GetIndexOf(right_anchor)); |
| 1049 } | 1049 } |
| 1050 } | 1050 } |
| 1051 | 1051 |
| 1052 WebContents* contents = GetWebContentsFromDelegate(delegate_); | 1052 WebContents* contents = GetWebContentsFromDelegate(delegate_); |
| 1053 if (!page_action_views_.empty() && contents) { | 1053 if (!page_action_views_.empty() && contents) { |
| 1054 Browser* browser = | 1054 Browser* browser = |
| 1055 browser::FindBrowserForController(&contents->GetController(), NULL); | 1055 browser::FindBrowserForController(&contents->GetController(), NULL); |
| 1056 GURL url = browser->GetSelectedWebContents()->GetURL(); | 1056 GURL url = browser->GetActiveWebContents()->GetURL(); |
| 1057 | 1057 |
| 1058 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 1058 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
| 1059 i != page_action_views_.end(); ++i) { | 1059 i != page_action_views_.end(); ++i) { |
| 1060 (*i)->UpdateVisibility(model_->input_in_progress() ? NULL : contents, | 1060 (*i)->UpdateVisibility(model_->input_in_progress() ? NULL : contents, |
| 1061 url); | 1061 url); |
| 1062 | 1062 |
| 1063 // Check if the visibility of the action changed and notify if it did. | 1063 // Check if the visibility of the action changed and notify if it did. |
| 1064 ExtensionAction* action = (*i)->image_view()->page_action(); | 1064 ExtensionAction* action = (*i)->image_view()->page_action(); |
| 1065 if (old_visibility.find(action) == old_visibility.end() || | 1065 if (old_visibility.find(action) == old_visibility.end() || |
| 1066 old_visibility[action] != (*i)->visible()) { | 1066 old_visibility[action] != (*i)->visible()) { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1163 state->selection_start = entry_start; | 1163 state->selection_start = entry_start; |
| 1164 state->selection_end = entry_end; | 1164 state->selection_end = entry_end; |
| 1165 } | 1165 } |
| 1166 | 1166 |
| 1167 void LocationBarView::WriteDragDataForView(views::View* sender, | 1167 void LocationBarView::WriteDragDataForView(views::View* sender, |
| 1168 const gfx::Point& press_pt, | 1168 const gfx::Point& press_pt, |
| 1169 OSExchangeData* data) { | 1169 OSExchangeData* data) { |
| 1170 DCHECK_NE(GetDragOperationsForView(sender, press_pt), | 1170 DCHECK_NE(GetDragOperationsForView(sender, press_pt), |
| 1171 ui::DragDropTypes::DRAG_NONE); | 1171 ui::DragDropTypes::DRAG_NONE); |
| 1172 | 1172 |
| 1173 TabContentsWrapper* tab_contents = delegate_->GetTabContentsWrapper(); | 1173 TabContents* tab_contents = delegate_->GetTabContents(); |
| 1174 DCHECK(tab_contents); | 1174 DCHECK(tab_contents); |
| 1175 button_drag_utils::SetURLAndDragImage( | 1175 button_drag_utils::SetURLAndDragImage( |
| 1176 tab_contents->web_contents()->GetURL(), | 1176 tab_contents->web_contents()->GetURL(), |
| 1177 tab_contents->web_contents()->GetTitle(), | 1177 tab_contents->web_contents()->GetTitle(), |
| 1178 tab_contents->favicon_tab_helper()->GetFavicon(), | 1178 tab_contents->favicon_tab_helper()->GetFavicon(), |
| 1179 data); | 1179 data); |
| 1180 } | 1180 } |
| 1181 | 1181 |
| 1182 int LocationBarView::GetDragOperationsForView(views::View* sender, | 1182 int LocationBarView::GetDragOperationsForView(views::View* sender, |
| 1183 const gfx::Point& p) { | 1183 const gfx::Point& p) { |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1330 switch (type) { | 1330 switch (type) { |
| 1331 case chrome::NOTIFICATION_PREF_CHANGED: { | 1331 case chrome::NOTIFICATION_PREF_CHANGED: { |
| 1332 std::string* name = content::Details<std::string>(details).ptr(); | 1332 std::string* name = content::Details<std::string>(details).ptr(); |
| 1333 if (*name == prefs::kEditBookmarksEnabled) | 1333 if (*name == prefs::kEditBookmarksEnabled) |
| 1334 Update(NULL); | 1334 Update(NULL); |
| 1335 break; | 1335 break; |
| 1336 } | 1336 } |
| 1337 | 1337 |
| 1338 case chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED: { | 1338 case chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED: { |
| 1339 // Only update if the updated action box was for the active tab contents. | 1339 // Only update if the updated action box was for the active tab contents. |
| 1340 TabContentsWrapper* target_tab = | 1340 TabContents* target_tab = content::Details<TabContents>(details).ptr(); |
| 1341 content::Details<TabContentsWrapper>(details).ptr(); | 1341 if (target_tab == GetTabContents()) |
| 1342 if (target_tab == GetTabContentsWrapper()) | |
| 1343 UpdatePageActions(); | 1342 UpdatePageActions(); |
| 1344 break; | 1343 break; |
| 1345 } | 1344 } |
| 1346 | 1345 |
| 1347 default: | 1346 default: |
| 1348 NOTREACHED() << "Unexpected notification."; | 1347 NOTREACHED() << "Unexpected notification."; |
| 1349 } | 1348 } |
| 1350 } | 1349 } |
| 1351 | 1350 |
| 1352 int LocationBarView::GetInternalHeight(bool use_preferred_size) { | 1351 int LocationBarView::GetInternalHeight(bool use_preferred_size) { |
| 1353 int total_height = | 1352 int total_height = |
| 1354 use_preferred_size ? GetPreferredSize().height() : height(); | 1353 use_preferred_size ? GetPreferredSize().height() : height(); |
| 1355 return std::max(total_height - (kVerticalEdgeThickness * 2), 0); | 1354 return std::max(total_height - (kVerticalEdgeThickness * 2), 0); |
| 1356 } | 1355 } |
| 1357 | 1356 |
| 1358 #if defined(OS_WIN) || defined(USE_AURA) | 1357 #if defined(OS_WIN) || defined(USE_AURA) |
| 1359 bool LocationBarView::HasValidSuggestText() const { | 1358 bool LocationBarView::HasValidSuggestText() const { |
| 1360 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && | 1359 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && |
| 1361 !suggested_text_view_->text().empty(); | 1360 !suggested_text_view_->text().empty(); |
| 1362 } | 1361 } |
| 1363 | 1362 |
| 1364 #if !defined(USE_AURA) | 1363 #if !defined(USE_AURA) |
| 1365 OmniboxViewWin* LocationBarView::GetOmniboxViewWin() { | 1364 OmniboxViewWin* LocationBarView::GetOmniboxViewWin() { |
| 1366 return static_cast<OmniboxViewWin*>(location_entry_.get()); | 1365 return static_cast<OmniboxViewWin*>(location_entry_.get()); |
| 1367 } | 1366 } |
| 1368 #endif | 1367 #endif |
| 1369 #endif | 1368 #endif |
| OLD | NEW |