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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 keyword_hint_view_(NULL), | 183 keyword_hint_view_(NULL), |
184 mic_search_view_(NULL), | 184 mic_search_view_(NULL), |
185 zoom_view_(NULL), | 185 zoom_view_(NULL), |
186 generated_credit_card_view_(NULL), | 186 generated_credit_card_view_(NULL), |
187 open_pdf_in_reader_view_(NULL), | 187 open_pdf_in_reader_view_(NULL), |
188 script_bubble_icon_view_(NULL), | 188 script_bubble_icon_view_(NULL), |
189 star_view_(NULL), | 189 star_view_(NULL), |
190 is_popup_mode_(is_popup_mode), | 190 is_popup_mode_(is_popup_mode), |
191 show_focus_rect_(false), | 191 show_focus_rect_(false), |
192 template_url_service_(NULL), | 192 template_url_service_(NULL), |
193 animation_offset_(0) { | 193 animation_offset_(0), |
| 194 weak_ptr_factory_(this) { |
194 if (!views::Textfield::IsViewsTextfieldEnabled()) | 195 if (!views::Textfield::IsViewsTextfieldEnabled()) |
195 set_id(VIEW_ID_OMNIBOX); | 196 set_id(VIEW_ID_OMNIBOX); |
196 | 197 |
197 const int kOmniboxBorderImages[] = IMAGE_GRID(IDR_OMNIBOX_BORDER); | 198 const int kOmniboxBorderImages[] = IMAGE_GRID(IDR_OMNIBOX_BORDER); |
198 const int kOmniboxPopupImages[] = IMAGE_GRID(IDR_OMNIBOX_POPUP_BORDER); | 199 const int kOmniboxPopupImages[] = IMAGE_GRID(IDR_OMNIBOX_POPUP_BORDER); |
199 background_border_painter_.reset( | 200 background_border_painter_.reset( |
200 views::Painter::CreateImageGridPainter( | 201 views::Painter::CreateImageGridPainter( |
201 is_popup_mode_ ? kOmniboxPopupImages : kOmniboxBorderImages)); | 202 is_popup_mode_ ? kOmniboxPopupImages : kOmniboxBorderImages)); |
202 #if defined(OS_CHROMEOS) | 203 #if defined(OS_CHROMEOS) |
203 if (!is_popup_mode_) { | 204 if (!is_popup_mode_) { |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 DCHECK(zoom_view_); | 628 DCHECK(zoom_view_); |
628 RefreshZoomView(); | 629 RefreshZoomView(); |
629 | 630 |
630 Layout(); | 631 Layout(); |
631 SchedulePaint(); | 632 SchedulePaint(); |
632 | 633 |
633 if (can_show_bubble && zoom_view_->visible() && delegate_->GetWebContents()) | 634 if (can_show_bubble && zoom_view_->visible() && delegate_->GetWebContents()) |
634 ZoomBubbleView::ShowBubble(delegate_->GetWebContents(), true); | 635 ZoomBubbleView::ShowBubble(delegate_->GetWebContents(), true); |
635 } | 636 } |
636 | 637 |
637 void LocationBarView::RefreshZoomView() { | |
638 DCHECK(zoom_view_); | |
639 WebContents* web_contents = GetWebContents(); | |
640 if (!web_contents) | |
641 return; | |
642 | |
643 ZoomController* zoom_controller = | |
644 ZoomController::FromWebContents(web_contents); | |
645 zoom_view_->Update(zoom_controller); | |
646 } | |
647 | |
648 gfx::Point LocationBarView::GetLocationEntryOrigin() const { | 638 gfx::Point LocationBarView::GetLocationEntryOrigin() const { |
649 gfx::Point origin(location_entry_view_->bounds().origin()); | 639 gfx::Point origin(location_entry_view_->bounds().origin()); |
650 // If the UI layout is RTL, the coordinate system is not transformed and | 640 // If the UI layout is RTL, the coordinate system is not transformed and |
651 // therefore we need to adjust the X coordinate so that bubble appears on the | 641 // therefore we need to adjust the X coordinate so that bubble appears on the |
652 // right hand side of the location bar. | 642 // right hand side of the location bar. |
653 if (base::i18n::IsRTL()) | 643 if (base::i18n::IsRTL()) |
654 origin.set_x(width() - origin.x()); | 644 origin.set_x(width() - origin.x()); |
655 views::View::ConvertPointToScreen(this, &origin); | 645 views::View::ConvertPointToScreen(this, &origin); |
656 return origin; | 646 return origin; |
657 } | 647 } |
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1114 } | 1104 } |
1115 | 1105 |
1116 ToolbarModel* LocationBarView::GetToolbarModel() { | 1106 ToolbarModel* LocationBarView::GetToolbarModel() { |
1117 return delegate_->GetToolbarModel(); | 1107 return delegate_->GetToolbarModel(); |
1118 } | 1108 } |
1119 | 1109 |
1120 const ToolbarModel* LocationBarView::GetToolbarModel() const { | 1110 const ToolbarModel* LocationBarView::GetToolbarModel() const { |
1121 return delegate_->GetToolbarModel(); | 1111 return delegate_->GetToolbarModel(); |
1122 } | 1112 } |
1123 | 1113 |
1124 // static | |
1125 int LocationBarView::GetBuiltInHorizontalPaddingForChildViews() { | |
1126 return (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) ? | |
1127 GetItemPadding() / 2 : 0; | |
1128 } | |
1129 | |
1130 int LocationBarView::GetHorizontalEdgeThickness() const { | |
1131 // In maximized popup mode, there isn't any edge. | |
1132 return (is_popup_mode_ && browser_ && browser_->window() && | |
1133 browser_->window()->IsMaximized()) ? 0 : vertical_edge_thickness(); | |
1134 } | |
1135 | |
1136 void LocationBarView::UpdateContentSettingViewsPreLayout() { | |
1137 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); | |
1138 i != content_setting_views_.end(); ++i) { | |
1139 (*i)->UpdatePreLayout(GetToolbarModel()->input_in_progress() ? | |
1140 NULL : GetWebContents()); | |
1141 } | |
1142 } | |
1143 | |
1144 void LocationBarView::UpdateContentSettingViewsPostLayout() { | |
1145 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); | |
1146 i != content_setting_views_.end(); ++i) { | |
1147 (*i)->UpdatePostLayout(GetToolbarModel()->input_in_progress() ? | |
1148 NULL : GetWebContents()); | |
1149 } | |
1150 } | |
1151 | |
1152 void LocationBarView::DeletePageActionViews() { | |
1153 for (PageActionViews::const_iterator i(page_action_views_.begin()); | |
1154 i != page_action_views_.end(); ++i) | |
1155 RemoveChildView(*i); | |
1156 STLDeleteElements(&page_action_views_); | |
1157 } | |
1158 | |
1159 void LocationBarView::RefreshPageActionViews() { | |
1160 if (is_popup_mode_) | |
1161 return; | |
1162 | |
1163 // Remember the previous visibility of the page actions so that we can | |
1164 // notify when this changes. | |
1165 std::map<ExtensionAction*, bool> old_visibility; | |
1166 for (PageActionViews::const_iterator i(page_action_views_.begin()); | |
1167 i != page_action_views_.end(); ++i) { | |
1168 old_visibility[(*i)->image_view()->page_action()] = (*i)->visible(); | |
1169 } | |
1170 | |
1171 std::vector<ExtensionAction*> new_page_actions; | |
1172 | |
1173 WebContents* contents = delegate_->GetWebContents(); | |
1174 if (contents) { | |
1175 extensions::TabHelper* extensions_tab_helper = | |
1176 extensions::TabHelper::FromWebContents(contents); | |
1177 extensions::LocationBarController* controller = | |
1178 extensions_tab_helper->location_bar_controller(); | |
1179 new_page_actions = controller->GetCurrentActions(); | |
1180 } | |
1181 | |
1182 // On startup we sometimes haven't loaded any extensions. This makes sure | |
1183 // we catch up when the extensions (and any page actions) load. | |
1184 if (page_actions_ != new_page_actions) { | |
1185 page_actions_.swap(new_page_actions); | |
1186 DeletePageActionViews(); // Delete the old views (if any). | |
1187 | |
1188 page_action_views_.resize(page_actions_.size()); | |
1189 View* right_anchor = open_pdf_in_reader_view_; | |
1190 if (!right_anchor) | |
1191 right_anchor = star_view_; | |
1192 if (!right_anchor) | |
1193 right_anchor = script_bubble_icon_view_; | |
1194 DCHECK(right_anchor); | |
1195 | |
1196 // Add the page actions in reverse order, so that the child views are | |
1197 // inserted in left-to-right order for accessibility. | |
1198 for (int i = page_actions_.size() - 1; i >= 0; --i) { | |
1199 page_action_views_[i] = new PageActionWithBadgeView( | |
1200 delegate_->CreatePageActionImageView(this, page_actions_[i])); | |
1201 page_action_views_[i]->SetVisible(false); | |
1202 AddChildViewAt(page_action_views_[i], GetIndexOf(right_anchor)); | |
1203 } | |
1204 } | |
1205 | |
1206 if (!page_action_views_.empty() && contents) { | |
1207 Browser* browser = chrome::FindBrowserWithWebContents(contents); | |
1208 GURL url = browser->tab_strip_model()->GetActiveWebContents()->GetURL(); | |
1209 | |
1210 for (PageActionViews::const_iterator i(page_action_views_.begin()); | |
1211 i != page_action_views_.end(); ++i) { | |
1212 (*i)->UpdateVisibility( | |
1213 GetToolbarModel()->input_in_progress() ? NULL : contents, url); | |
1214 | |
1215 // Check if the visibility of the action changed and notify if it did. | |
1216 ExtensionAction* action = (*i)->image_view()->page_action(); | |
1217 if (old_visibility.find(action) == old_visibility.end() || | |
1218 old_visibility[action] != (*i)->visible()) { | |
1219 content::NotificationService::current()->Notify( | |
1220 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, | |
1221 content::Source<ExtensionAction>(action), | |
1222 content::Details<WebContents>(contents)); | |
1223 } | |
1224 } | |
1225 } | |
1226 } | |
1227 | |
1228 size_t LocationBarView::ScriptBubbleScriptsRunning() { | |
1229 WebContents* contents = delegate_->GetWebContents(); | |
1230 if (!contents) | |
1231 return false; | |
1232 extensions::TabHelper* extensions_tab_helper = | |
1233 extensions::TabHelper::FromWebContents(contents); | |
1234 if (!extensions_tab_helper) | |
1235 return false; | |
1236 extensions::ScriptBubbleController* script_bubble_controller = | |
1237 extensions_tab_helper->script_bubble_controller(); | |
1238 if (!script_bubble_controller) | |
1239 return false; | |
1240 size_t script_count = | |
1241 script_bubble_controller->extensions_running_scripts().size(); | |
1242 return script_count; | |
1243 } | |
1244 | |
1245 void LocationBarView::RefreshScriptBubble() { | |
1246 if (!script_bubble_icon_view_) | |
1247 return; | |
1248 size_t script_count = ScriptBubbleScriptsRunning(); | |
1249 script_bubble_icon_view_->SetVisible(script_count > 0); | |
1250 if (script_count > 0) | |
1251 script_bubble_icon_view_->SetScriptCount(script_count); | |
1252 } | |
1253 | |
1254 #if defined(OS_WIN) && !defined(USE_AURA) | |
1255 void LocationBarView::OnMouseEvent(const ui::MouseEvent& event, UINT msg) { | |
1256 OmniboxViewWin* omnibox_win = GetOmniboxViewWin(location_entry_.get()); | |
1257 if (omnibox_win) { | |
1258 UINT flags = event.native_event().wParam; | |
1259 gfx::Point screen_point(event.location()); | |
1260 ConvertPointToScreen(this, &screen_point); | |
1261 omnibox_win->HandleExternalMsg(msg, flags, screen_point.ToPOINT()); | |
1262 } | |
1263 } | |
1264 #endif | |
1265 | |
1266 void LocationBarView::ShowFirstRunBubbleInternal() { | |
1267 #if !defined(OS_CHROMEOS) | |
1268 // First run bubble doesn't make sense for Chrome OS. | |
1269 Browser* browser = GetBrowserFromDelegate(delegate_); | |
1270 if (!browser) | |
1271 return; // Possible when browser is shutting down. | |
1272 | |
1273 FirstRunBubble::ShowBubble(browser, location_icon_view_); | |
1274 #endif | |
1275 } | |
1276 | |
1277 void LocationBarView::PaintPageActionBackgrounds(gfx::Canvas* canvas) { | |
1278 WebContents* web_contents = GetWebContents(); | |
1279 // web_contents may be NULL while the browser is shutting down. | |
1280 if (!web_contents) | |
1281 return; | |
1282 | |
1283 const int32 tab_id = SessionID::IdForTab(web_contents); | |
1284 const ToolbarModel::SecurityLevel security_level = | |
1285 GetToolbarModel()->GetSecurityLevel(false); | |
1286 const SkColor text_color = GetColor(security_level, TEXT); | |
1287 const SkColor background_color = GetColor(security_level, BACKGROUND); | |
1288 | |
1289 for (PageActionViews::const_iterator | |
1290 page_action_view = page_action_views_.begin(); | |
1291 page_action_view != page_action_views_.end(); | |
1292 ++page_action_view) { | |
1293 gfx::Rect bounds = (*page_action_view)->bounds(); | |
1294 int horizontal_padding = | |
1295 GetItemPadding() - GetBuiltInHorizontalPaddingForChildViews(); | |
1296 // Make the bounding rectangle include the whole vertical range of the | |
1297 // location bar, and the mid-point pixels between adjacent page actions. | |
1298 // | |
1299 // For odd horizontal_paddings, "horizontal_padding + 1" includes the | |
1300 // mid-point between two page actions in the bounding rectangle. For even | |
1301 // paddings, the +1 is dropped, which is right since there is no pixel at | |
1302 // the mid-point. | |
1303 bounds.Inset(-(horizontal_padding + 1) / 2, 0); | |
1304 location_bar_util::PaintExtensionActionBackground( | |
1305 *(*page_action_view)->image_view()->page_action(), | |
1306 tab_id, canvas, bounds, text_color, background_color); | |
1307 } | |
1308 } | |
1309 | |
1310 const char* LocationBarView::GetClassName() const { | 1114 const char* LocationBarView::GetClassName() const { |
1311 return kViewClassName; | 1115 return kViewClassName; |
1312 } | 1116 } |
1313 | 1117 |
1314 bool LocationBarView::SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) { | 1118 bool LocationBarView::SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) { |
1315 #if defined(OS_WIN) | 1119 #if defined(OS_WIN) |
1316 if (views::FocusManager::IsTabTraversalKeyEvent(event)) { | 1120 if (views::FocusManager::IsTabTraversalKeyEvent(event)) { |
1317 if (location_entry_->model()->popup_model()->IsOpen()) { | 1121 if (location_entry_->model()->popup_model()->IsOpen()) { |
1318 // Return true so that the edit sees the tab and moves the selection. | 1122 // Return true so that the edit sees the tab and moves the selection. |
1319 return true; | 1123 return true; |
(...skipping 12 matching lines...) Expand all Loading... |
1332 return omnibox_win->SkipDefaultKeyEventProcessing(event); | 1136 return omnibox_win->SkipDefaultKeyEventProcessing(event); |
1333 #endif // USE_AURA | 1137 #endif // USE_AURA |
1334 #endif // OS_WIN | 1138 #endif // OS_WIN |
1335 | 1139 |
1336 // This method is not used for Linux ports. See FocusManager::OnKeyEvent() in | 1140 // This method is not used for Linux ports. See FocusManager::OnKeyEvent() in |
1337 // src/ui/views/focus/focus_manager.cc for details. | 1141 // src/ui/views/focus/focus_manager.cc for details. |
1338 return false; | 1142 return false; |
1339 } | 1143 } |
1340 | 1144 |
1341 void LocationBarView::GetAccessibleState(ui::AccessibleViewState* state) { | 1145 void LocationBarView::GetAccessibleState(ui::AccessibleViewState* state) { |
| 1146 if (!location_entry_) |
| 1147 return; |
| 1148 |
1342 state->role = ui::AccessibilityTypes::ROLE_LOCATION_BAR; | 1149 state->role = ui::AccessibilityTypes::ROLE_LOCATION_BAR; |
1343 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_LOCATION); | 1150 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_LOCATION); |
1344 state->value = location_entry_->GetText(); | 1151 state->value = location_entry_->GetText(); |
1345 | 1152 |
1346 string16::size_type entry_start; | 1153 string16::size_type entry_start; |
1347 string16::size_type entry_end; | 1154 string16::size_type entry_end; |
1348 location_entry_->GetSelectionBounds(&entry_start, &entry_end); | 1155 location_entry_->GetSelectionBounds(&entry_start, &entry_end); |
1349 state->selection_start = entry_start; | 1156 state->selection_start = entry_start; |
1350 state->selection_end = entry_end; | 1157 state->selection_end = entry_end; |
| 1158 |
| 1159 if (is_popup_mode_) { |
| 1160 state->state |= ui::AccessibilityTypes::STATE_READONLY; |
| 1161 } else { |
| 1162 state->set_value_callback = |
| 1163 base::Bind(&LocationBarView::AccessibilitySetValue, |
| 1164 weak_ptr_factory_.GetWeakPtr()); |
| 1165 } |
1351 } | 1166 } |
1352 | 1167 |
1353 bool LocationBarView::HasFocus() const { | 1168 bool LocationBarView::HasFocus() const { |
1354 return location_entry_->model()->has_focus(); | 1169 return location_entry_->model()->has_focus(); |
1355 } | 1170 } |
1356 | 1171 |
1357 void LocationBarView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 1172 void LocationBarView::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
1358 if (browser_ && browser_->instant_controller() && parent()) | 1173 if (browser_ && browser_->instant_controller() && parent()) |
1359 browser_->instant_controller()->SetOmniboxBounds(bounds()); | 1174 browser_->instant_controller()->SetOmniboxBounds(bounds()); |
1360 OmniboxPopupView* popup = location_entry_->model()->popup_model()->view(); | 1175 OmniboxPopupView* popup = location_entry_->model()->popup_model()->view(); |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1556 Layout(); | 1371 Layout(); |
1557 } | 1372 } |
1558 } | 1373 } |
1559 | 1374 |
1560 int LocationBarView::GetInternalHeight(bool use_preferred_size) { | 1375 int LocationBarView::GetInternalHeight(bool use_preferred_size) { |
1561 int total_height = | 1376 int total_height = |
1562 use_preferred_size ? GetPreferredSize().height() : height(); | 1377 use_preferred_size ? GetPreferredSize().height() : height(); |
1563 return std::max(total_height - (vertical_edge_thickness() * 2), 0); | 1378 return std::max(total_height - (vertical_edge_thickness() * 2), 0); |
1564 } | 1379 } |
1565 | 1380 |
| 1381 //////////////////////////////////////////////////////////////////////////////// |
| 1382 // LocationBarView, private: |
| 1383 |
| 1384 // static |
| 1385 int LocationBarView::GetBuiltInHorizontalPaddingForChildViews() { |
| 1386 return (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) ? |
| 1387 GetItemPadding() / 2 : 0; |
| 1388 } |
| 1389 |
| 1390 int LocationBarView::GetHorizontalEdgeThickness() const { |
| 1391 // In maximized popup mode, there isn't any edge. |
| 1392 return (is_popup_mode_ && browser_ && browser_->window() && |
| 1393 browser_->window()->IsMaximized()) ? 0 : vertical_edge_thickness(); |
| 1394 } |
| 1395 |
| 1396 void LocationBarView::UpdateContentSettingViewsPreLayout() { |
| 1397 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); |
| 1398 i != content_setting_views_.end(); ++i) { |
| 1399 (*i)->UpdatePreLayout(GetToolbarModel()->input_in_progress() ? |
| 1400 NULL : GetWebContents()); |
| 1401 } |
| 1402 } |
| 1403 |
| 1404 void LocationBarView::UpdateContentSettingViewsPostLayout() { |
| 1405 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); |
| 1406 i != content_setting_views_.end(); ++i) { |
| 1407 (*i)->UpdatePostLayout(GetToolbarModel()->input_in_progress() ? |
| 1408 NULL : GetWebContents()); |
| 1409 } |
| 1410 } |
| 1411 |
| 1412 void LocationBarView::DeletePageActionViews() { |
| 1413 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
| 1414 i != page_action_views_.end(); ++i) |
| 1415 RemoveChildView(*i); |
| 1416 STLDeleteElements(&page_action_views_); |
| 1417 } |
| 1418 |
| 1419 void LocationBarView::RefreshPageActionViews() { |
| 1420 if (is_popup_mode_) |
| 1421 return; |
| 1422 |
| 1423 // Remember the previous visibility of the page actions so that we can |
| 1424 // notify when this changes. |
| 1425 std::map<ExtensionAction*, bool> old_visibility; |
| 1426 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
| 1427 i != page_action_views_.end(); ++i) { |
| 1428 old_visibility[(*i)->image_view()->page_action()] = (*i)->visible(); |
| 1429 } |
| 1430 |
| 1431 std::vector<ExtensionAction*> new_page_actions; |
| 1432 |
| 1433 WebContents* contents = delegate_->GetWebContents(); |
| 1434 if (contents) { |
| 1435 extensions::TabHelper* extensions_tab_helper = |
| 1436 extensions::TabHelper::FromWebContents(contents); |
| 1437 extensions::LocationBarController* controller = |
| 1438 extensions_tab_helper->location_bar_controller(); |
| 1439 new_page_actions = controller->GetCurrentActions(); |
| 1440 } |
| 1441 |
| 1442 // On startup we sometimes haven't loaded any extensions. This makes sure |
| 1443 // we catch up when the extensions (and any page actions) load. |
| 1444 if (page_actions_ != new_page_actions) { |
| 1445 page_actions_.swap(new_page_actions); |
| 1446 DeletePageActionViews(); // Delete the old views (if any). |
| 1447 |
| 1448 page_action_views_.resize(page_actions_.size()); |
| 1449 View* right_anchor = open_pdf_in_reader_view_; |
| 1450 if (!right_anchor) |
| 1451 right_anchor = star_view_; |
| 1452 if (!right_anchor) |
| 1453 right_anchor = script_bubble_icon_view_; |
| 1454 DCHECK(right_anchor); |
| 1455 |
| 1456 // Add the page actions in reverse order, so that the child views are |
| 1457 // inserted in left-to-right order for accessibility. |
| 1458 for (int i = page_actions_.size() - 1; i >= 0; --i) { |
| 1459 page_action_views_[i] = new PageActionWithBadgeView( |
| 1460 delegate_->CreatePageActionImageView(this, page_actions_[i])); |
| 1461 page_action_views_[i]->SetVisible(false); |
| 1462 AddChildViewAt(page_action_views_[i], GetIndexOf(right_anchor)); |
| 1463 } |
| 1464 } |
| 1465 |
| 1466 if (!page_action_views_.empty() && contents) { |
| 1467 Browser* browser = chrome::FindBrowserWithWebContents(contents); |
| 1468 GURL url = browser->tab_strip_model()->GetActiveWebContents()->GetURL(); |
| 1469 |
| 1470 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
| 1471 i != page_action_views_.end(); ++i) { |
| 1472 (*i)->UpdateVisibility( |
| 1473 GetToolbarModel()->input_in_progress() ? NULL : contents, url); |
| 1474 |
| 1475 // Check if the visibility of the action changed and notify if it did. |
| 1476 ExtensionAction* action = (*i)->image_view()->page_action(); |
| 1477 if (old_visibility.find(action) == old_visibility.end() || |
| 1478 old_visibility[action] != (*i)->visible()) { |
| 1479 content::NotificationService::current()->Notify( |
| 1480 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, |
| 1481 content::Source<ExtensionAction>(action), |
| 1482 content::Details<WebContents>(contents)); |
| 1483 } |
| 1484 } |
| 1485 } |
| 1486 } |
| 1487 |
| 1488 size_t LocationBarView::ScriptBubbleScriptsRunning() { |
| 1489 WebContents* contents = delegate_->GetWebContents(); |
| 1490 if (!contents) |
| 1491 return false; |
| 1492 extensions::TabHelper* extensions_tab_helper = |
| 1493 extensions::TabHelper::FromWebContents(contents); |
| 1494 if (!extensions_tab_helper) |
| 1495 return false; |
| 1496 extensions::ScriptBubbleController* script_bubble_controller = |
| 1497 extensions_tab_helper->script_bubble_controller(); |
| 1498 if (!script_bubble_controller) |
| 1499 return false; |
| 1500 size_t script_count = |
| 1501 script_bubble_controller->extensions_running_scripts().size(); |
| 1502 return script_count; |
| 1503 } |
| 1504 |
| 1505 void LocationBarView::RefreshScriptBubble() { |
| 1506 if (!script_bubble_icon_view_) |
| 1507 return; |
| 1508 size_t script_count = ScriptBubbleScriptsRunning(); |
| 1509 script_bubble_icon_view_->SetVisible(script_count > 0); |
| 1510 if (script_count > 0) |
| 1511 script_bubble_icon_view_->SetScriptCount(script_count); |
| 1512 } |
| 1513 |
| 1514 void LocationBarView::RefreshZoomView() { |
| 1515 DCHECK(zoom_view_); |
| 1516 WebContents* web_contents = GetWebContents(); |
| 1517 if (!web_contents) |
| 1518 return; |
| 1519 |
| 1520 ZoomController* zoom_controller = |
| 1521 ZoomController::FromWebContents(web_contents); |
| 1522 zoom_view_->Update(zoom_controller); |
| 1523 } |
| 1524 |
| 1525 #if defined(OS_WIN) && !defined(USE_AURA) |
| 1526 void LocationBarView::OnMouseEvent(const ui::MouseEvent& event, UINT msg) { |
| 1527 OmniboxViewWin* omnibox_win = GetOmniboxViewWin(location_entry_.get()); |
| 1528 if (omnibox_win) { |
| 1529 UINT flags = event.native_event().wParam; |
| 1530 gfx::Point screen_point(event.location()); |
| 1531 ConvertPointToScreen(this, &screen_point); |
| 1532 omnibox_win->HandleExternalMsg(msg, flags, screen_point.ToPOINT()); |
| 1533 } |
| 1534 } |
| 1535 #endif |
| 1536 |
1566 bool LocationBarView::HasValidSuggestText() const { | 1537 bool LocationBarView::HasValidSuggestText() const { |
1567 return suggested_text_view_->visible() && | 1538 return suggested_text_view_->visible() && |
1568 !suggested_text_view_->size().IsEmpty(); | 1539 !suggested_text_view_->size().IsEmpty(); |
1569 } | 1540 } |
| 1541 |
| 1542 void LocationBarView::ShowFirstRunBubbleInternal() { |
| 1543 #if !defined(OS_CHROMEOS) |
| 1544 // First run bubble doesn't make sense for Chrome OS. |
| 1545 Browser* browser = GetBrowserFromDelegate(delegate_); |
| 1546 if (!browser) |
| 1547 return; // Possible when browser is shutting down. |
| 1548 |
| 1549 FirstRunBubble::ShowBubble(browser, location_icon_view_); |
| 1550 #endif |
| 1551 } |
| 1552 |
| 1553 void LocationBarView::PaintPageActionBackgrounds(gfx::Canvas* canvas) { |
| 1554 WebContents* web_contents = GetWebContents(); |
| 1555 // web_contents may be NULL while the browser is shutting down. |
| 1556 if (!web_contents) |
| 1557 return; |
| 1558 |
| 1559 const int32 tab_id = SessionID::IdForTab(web_contents); |
| 1560 const ToolbarModel::SecurityLevel security_level = |
| 1561 GetToolbarModel()->GetSecurityLevel(false); |
| 1562 const SkColor text_color = GetColor(security_level, TEXT); |
| 1563 const SkColor background_color = GetColor(security_level, BACKGROUND); |
| 1564 |
| 1565 for (PageActionViews::const_iterator |
| 1566 page_action_view = page_action_views_.begin(); |
| 1567 page_action_view != page_action_views_.end(); |
| 1568 ++page_action_view) { |
| 1569 gfx::Rect bounds = (*page_action_view)->bounds(); |
| 1570 int horizontal_padding = |
| 1571 GetItemPadding() - GetBuiltInHorizontalPaddingForChildViews(); |
| 1572 // Make the bounding rectangle include the whole vertical range of the |
| 1573 // location bar, and the mid-point pixels between adjacent page actions. |
| 1574 // |
| 1575 // For odd horizontal_paddings, "horizontal_padding + 1" includes the |
| 1576 // mid-point between two page actions in the bounding rectangle. For even |
| 1577 // paddings, the +1 is dropped, which is right since there is no pixel at |
| 1578 // the mid-point. |
| 1579 bounds.Inset(-(horizontal_padding + 1) / 2, 0); |
| 1580 location_bar_util::PaintExtensionActionBackground( |
| 1581 *(*page_action_view)->image_view()->page_action(), |
| 1582 tab_id, canvas, bounds, text_color, background_color); |
| 1583 } |
| 1584 } |
| 1585 |
| 1586 void LocationBarView::AccessibilitySetValue(const string16& new_value) { |
| 1587 location_entry_->SetUserText(new_value); |
| 1588 } |
OLD | NEW |