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