Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: chrome/browser/ui/views/location_bar/location_bar_view.cc

Issue 60683003: A number of paint optimizations to improve overall paint times. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove SetImageByResourceID and use BackedBySameObjectAs Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 // DropdownBarHostDelegate 487 // DropdownBarHostDelegate
488 void LocationBarView::SetFocusAndSelection(bool select_all) { 488 void LocationBarView::SetFocusAndSelection(bool select_all) {
489 FocusLocation(select_all); 489 FocusLocation(select_all);
490 } 490 }
491 491
492 void LocationBarView::SetAnimationOffset(int offset) { 492 void LocationBarView::SetAnimationOffset(int offset) {
493 animation_offset_ = offset; 493 animation_offset_ = offset;
494 } 494 }
495 495
496 void LocationBarView::UpdateContentSettingsIcons() { 496 void LocationBarView::UpdateContentSettingsIcons() {
497 RefreshContentSettingViews(); 497 if (RefreshContentSettingViews()) {
498 Layout(); 498 Layout();
499 SchedulePaint(); 499 SchedulePaint();
500 }
500 } 501 }
501 502
502 void LocationBarView::UpdateManagePasswordsIconAndBubble() { 503 void LocationBarView::UpdateManagePasswordsIconAndBubble() {
503 RefreshManagePasswordsIconView(); 504 if (RefreshManagePasswordsIconView()) {
504 Layout(); 505 Layout();
505 SchedulePaint(); 506 SchedulePaint();
507 }
506 ShowManagePasswordsBubbleIfNeeded(); 508 ShowManagePasswordsBubbleIfNeeded();
507 } 509 }
508 510
509 void LocationBarView::UpdatePageActions() { 511 void LocationBarView::UpdatePageActions() {
510 size_t count_before = page_action_views_.size(); 512 size_t count_before = page_action_views_.size();
511 RefreshPageActionViews(); 513 bool changed = RefreshPageActionViews();
512 RefreshScriptBubble(); 514 changed |= RefreshScriptBubble();
513 if (page_action_views_.size() != count_before) { 515 if (page_action_views_.size() != count_before) {
514 content::NotificationService::current()->Notify( 516 content::NotificationService::current()->Notify(
515 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED, 517 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED,
516 content::Source<LocationBar>(this), 518 content::Source<LocationBar>(this),
517 content::NotificationService::NoDetails()); 519 content::NotificationService::NoDetails());
518 } 520 }
519 521
520 Layout(); 522 if (changed) {
521 SchedulePaint(); 523 Layout();
524 SchedulePaint();
525 }
522 } 526 }
523 527
524 void LocationBarView::InvalidatePageActions() { 528 void LocationBarView::InvalidatePageActions() {
525 size_t count_before = page_action_views_.size(); 529 size_t count_before = page_action_views_.size();
526 DeletePageActionViews(); 530 DeletePageActionViews();
527 if (page_action_views_.size() != count_before) { 531 if (page_action_views_.size() != count_before) {
528 content::NotificationService::current()->Notify( 532 content::NotificationService::current()->Notify(
529 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED, 533 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED,
530 content::Source<LocationBar>(this), 534 content::Source<LocationBar>(this),
531 content::NotificationService::NoDetails()); 535 content::NotificationService::NoDetails());
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 star_view_->SetToggled(on); 597 star_view_->SetToggled(on);
594 } 598 }
595 599
596 void LocationBarView::ShowBookmarkPrompt() { 600 void LocationBarView::ShowBookmarkPrompt() {
597 if (star_view_ && star_view_->visible()) 601 if (star_view_ && star_view_->visible())
598 BookmarkPromptView::ShowPrompt(star_view_, profile_->GetPrefs()); 602 BookmarkPromptView::ShowPrompt(star_view_, profile_->GetPrefs());
599 } 603 }
600 604
601 void LocationBarView::ZoomChangedForActiveTab(bool can_show_bubble) { 605 void LocationBarView::ZoomChangedForActiveTab(bool can_show_bubble) {
602 DCHECK(zoom_view_); 606 DCHECK(zoom_view_);
603 RefreshZoomView(); 607 if (RefreshZoomView()) {
604 608 Layout();
605 Layout(); 609 SchedulePaint();
606 SchedulePaint(); 610 }
607 611
608 if (can_show_bubble && zoom_view_->visible() && delegate_->GetWebContents()) 612 if (can_show_bubble && zoom_view_->visible() && delegate_->GetWebContents())
609 ZoomBubbleView::ShowBubble(delegate_->GetWebContents(), true); 613 ZoomBubbleView::ShowBubble(delegate_->GetWebContents(), true);
610 } 614 }
611 615
612 gfx::Point LocationBarView::GetLocationEntryOrigin() const { 616 gfx::Point LocationBarView::GetLocationEntryOrigin() const {
613 gfx::Point origin(location_entry_view_->bounds().origin()); 617 gfx::Point origin(location_entry_view_->bounds().origin());
614 // If the UI layout is RTL, the coordinate system is not transformed and 618 // If the UI layout is RTL, the coordinate system is not transformed and
615 // therefore we need to adjust the X coordinate so that bubble appears on the 619 // therefore we need to adjust the X coordinate so that bubble appears on the
616 // right hand side of the location bar. 620 // right hand side of the location bar.
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 return (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) ? 1351 return (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) ?
1348 GetItemPadding() / 2 : 0; 1352 GetItemPadding() / 2 : 0;
1349 } 1353 }
1350 1354
1351 int LocationBarView::GetHorizontalEdgeThickness() const { 1355 int LocationBarView::GetHorizontalEdgeThickness() const {
1352 // In maximized popup mode, there isn't any edge. 1356 // In maximized popup mode, there isn't any edge.
1353 return (is_popup_mode_ && browser_ && browser_->window() && 1357 return (is_popup_mode_ && browser_ && browser_->window() &&
1354 browser_->window()->IsMaximized()) ? 0 : vertical_edge_thickness(); 1358 browser_->window()->IsMaximized()) ? 0 : vertical_edge_thickness();
1355 } 1359 }
1356 1360
1357 void LocationBarView::RefreshContentSettingViews() { 1361 bool LocationBarView::RefreshContentSettingViews() {
1362 bool visibility_changed = false;
1358 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); 1363 for (ContentSettingViews::const_iterator i(content_setting_views_.begin());
1359 i != content_setting_views_.end(); ++i) { 1364 i != content_setting_views_.end(); ++i) {
1365 const bool was_visible = (*i)->visible();
1360 (*i)->Update(GetToolbarModel()->input_in_progress() ? 1366 (*i)->Update(GetToolbarModel()->input_in_progress() ?
1361 NULL : GetWebContents()); 1367 NULL : GetWebContents());
1368 if (was_visible != (*i)->visible())
1369 visibility_changed = true;
1362 } 1370 }
1371 return visibility_changed;
1363 } 1372 }
1364 1373
1365 void LocationBarView::DeletePageActionViews() { 1374 void LocationBarView::DeletePageActionViews() {
1366 for (PageActionViews::const_iterator i(page_action_views_.begin()); 1375 for (PageActionViews::const_iterator i(page_action_views_.begin());
1367 i != page_action_views_.end(); ++i) 1376 i != page_action_views_.end(); ++i)
1368 RemoveChildView(*i); 1377 RemoveChildView(*i);
1369 STLDeleteElements(&page_action_views_); 1378 STLDeleteElements(&page_action_views_);
1370 } 1379 }
1371 1380
1372 void LocationBarView::RefreshPageActionViews() { 1381 bool LocationBarView::RefreshPageActionViews() {
1373 if (is_popup_mode_) 1382 if (is_popup_mode_)
1374 return; 1383 return false;
1384
1385 bool changed = false;
1375 1386
1376 // Remember the previous visibility of the page actions so that we can 1387 // Remember the previous visibility of the page actions so that we can
1377 // notify when this changes. 1388 // notify when this changes.
1378 std::map<ExtensionAction*, bool> old_visibility; 1389 std::map<ExtensionAction*, bool> old_visibility;
1379 for (PageActionViews::const_iterator i(page_action_views_.begin()); 1390 for (PageActionViews::const_iterator i(page_action_views_.begin());
1380 i != page_action_views_.end(); ++i) { 1391 i != page_action_views_.end(); ++i) {
1381 old_visibility[(*i)->image_view()->page_action()] = (*i)->visible(); 1392 old_visibility[(*i)->image_view()->page_action()] = (*i)->visible();
1382 } 1393 }
1383 1394
1384 std::vector<ExtensionAction*> new_page_actions; 1395 std::vector<ExtensionAction*> new_page_actions;
1385 1396
1386 WebContents* contents = delegate_->GetWebContents(); 1397 WebContents* contents = delegate_->GetWebContents();
1387 if (contents) { 1398 if (contents) {
1388 extensions::TabHelper* extensions_tab_helper = 1399 extensions::TabHelper* extensions_tab_helper =
1389 extensions::TabHelper::FromWebContents(contents); 1400 extensions::TabHelper::FromWebContents(contents);
1390 extensions::LocationBarController* controller = 1401 extensions::LocationBarController* controller =
1391 extensions_tab_helper->location_bar_controller(); 1402 extensions_tab_helper->location_bar_controller();
1392 new_page_actions = controller->GetCurrentActions(); 1403 new_page_actions = controller->GetCurrentActions();
1393 } 1404 }
1394 1405
1395 // On startup we sometimes haven't loaded any extensions. This makes sure 1406 // On startup we sometimes haven't loaded any extensions. This makes sure
1396 // we catch up when the extensions (and any page actions) load. 1407 // we catch up when the extensions (and any page actions) load.
1397 if (page_actions_ != new_page_actions) { 1408 if (page_actions_ != new_page_actions) {
1409 changed = true;
1410
1398 page_actions_.swap(new_page_actions); 1411 page_actions_.swap(new_page_actions);
1399 DeletePageActionViews(); // Delete the old views (if any). 1412 DeletePageActionViews(); // Delete the old views (if any).
1400 1413
1401 page_action_views_.resize(page_actions_.size()); 1414 page_action_views_.resize(page_actions_.size());
1402 View* right_anchor = open_pdf_in_reader_view_; 1415 View* right_anchor = open_pdf_in_reader_view_;
1403 if (!right_anchor) 1416 if (!right_anchor)
1404 right_anchor = star_view_; 1417 right_anchor = star_view_;
1405 if (!right_anchor) 1418 if (!right_anchor)
1406 right_anchor = script_bubble_icon_view_; 1419 right_anchor = script_bubble_icon_view_;
1407 DCHECK(right_anchor); 1420 DCHECK(right_anchor);
(...skipping 14 matching lines...) Expand all
1422 1435
1423 for (PageActionViews::const_iterator i(page_action_views_.begin()); 1436 for (PageActionViews::const_iterator i(page_action_views_.begin());
1424 i != page_action_views_.end(); ++i) { 1437 i != page_action_views_.end(); ++i) {
1425 (*i)->UpdateVisibility( 1438 (*i)->UpdateVisibility(
1426 GetToolbarModel()->input_in_progress() ? NULL : contents, url); 1439 GetToolbarModel()->input_in_progress() ? NULL : contents, url);
1427 1440
1428 // Check if the visibility of the action changed and notify if it did. 1441 // Check if the visibility of the action changed and notify if it did.
1429 ExtensionAction* action = (*i)->image_view()->page_action(); 1442 ExtensionAction* action = (*i)->image_view()->page_action();
1430 if (old_visibility.find(action) == old_visibility.end() || 1443 if (old_visibility.find(action) == old_visibility.end() ||
1431 old_visibility[action] != (*i)->visible()) { 1444 old_visibility[action] != (*i)->visible()) {
1445 changed = true;
1432 content::NotificationService::current()->Notify( 1446 content::NotificationService::current()->Notify(
1433 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, 1447 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED,
1434 content::Source<ExtensionAction>(action), 1448 content::Source<ExtensionAction>(action),
1435 content::Details<WebContents>(contents)); 1449 content::Details<WebContents>(contents));
1436 } 1450 }
1437 } 1451 }
1438 } 1452 }
1453 return changed;
1439 } 1454 }
1440 1455
1441 size_t LocationBarView::ScriptBubbleScriptsRunning() { 1456 size_t LocationBarView::ScriptBubbleScriptsRunning() {
1442 WebContents* contents = delegate_->GetWebContents(); 1457 WebContents* contents = delegate_->GetWebContents();
1443 if (!contents) 1458 if (!contents)
1444 return false; 1459 return false;
1445 extensions::TabHelper* extensions_tab_helper = 1460 extensions::TabHelper* extensions_tab_helper =
1446 extensions::TabHelper::FromWebContents(contents); 1461 extensions::TabHelper::FromWebContents(contents);
1447 if (!extensions_tab_helper) 1462 if (!extensions_tab_helper)
1448 return false; 1463 return false;
1449 extensions::ScriptBubbleController* script_bubble_controller = 1464 extensions::ScriptBubbleController* script_bubble_controller =
1450 extensions_tab_helper->script_bubble_controller(); 1465 extensions_tab_helper->script_bubble_controller();
1451 if (!script_bubble_controller) 1466 if (!script_bubble_controller)
1452 return false; 1467 return false;
1453 size_t script_count = 1468 size_t script_count =
1454 script_bubble_controller->extensions_running_scripts().size(); 1469 script_bubble_controller->extensions_running_scripts().size();
1455 return script_count; 1470 return script_count;
1456 } 1471 }
1457 1472
1458 void LocationBarView::RefreshScriptBubble() { 1473 bool LocationBarView::RefreshScriptBubble() {
1459 if (!script_bubble_icon_view_) 1474 if (!script_bubble_icon_view_)
1460 return; 1475 return false;
1461 size_t script_count = ScriptBubbleScriptsRunning(); 1476 size_t script_count = ScriptBubbleScriptsRunning();
1477 const bool was_visible = script_bubble_icon_view_->visible();
1462 script_bubble_icon_view_->SetVisible(script_count > 0); 1478 script_bubble_icon_view_->SetVisible(script_count > 0);
1463 if (script_count > 0) 1479 if (script_count > 0)
1464 script_bubble_icon_view_->SetScriptCount(script_count); 1480 script_bubble_icon_view_->SetScriptCount(script_count);
1481 return was_visible != script_bubble_icon_view_->visible();
1465 } 1482 }
1466 1483
1467 void LocationBarView::RefreshZoomView() { 1484 bool LocationBarView::RefreshZoomView() {
1468 DCHECK(zoom_view_); 1485 DCHECK(zoom_view_);
1469 WebContents* web_contents = GetWebContents(); 1486 WebContents* web_contents = GetWebContents();
1470 if (!web_contents) 1487 if (!web_contents)
1471 return; 1488 return false;
1489 const bool was_visible = zoom_view_->visible();
1472 zoom_view_->Update(ZoomController::FromWebContents(web_contents)); 1490 zoom_view_->Update(ZoomController::FromWebContents(web_contents));
1491 return was_visible != zoom_view_->visible();
1473 } 1492 }
1474 1493
1475 void LocationBarView::RefreshManagePasswordsIconView() { 1494 bool LocationBarView::RefreshManagePasswordsIconView() {
1476 DCHECK(manage_passwords_icon_view_); 1495 DCHECK(manage_passwords_icon_view_);
1477 WebContents* web_contents = GetWebContents(); 1496 WebContents* web_contents = GetWebContents();
1478 if (!web_contents) 1497 if (!web_contents)
1479 return; 1498 return false;
1499 const bool was_visible = manage_passwords_icon_view_->visible();
1480 manage_passwords_icon_view_->Update( 1500 manage_passwords_icon_view_->Update(
1481 ManagePasswordsIconController::FromWebContents(web_contents)); 1501 ManagePasswordsIconController::FromWebContents(web_contents));
1502 return was_visible != manage_passwords_icon_view_->visible();
1482 } 1503 }
1483 1504
1484 void LocationBarView::RefreshTranslateIcon() { 1505 void LocationBarView::RefreshTranslateIcon() {
1485 WebContents* web_contents = GetWebContents(); 1506 WebContents* web_contents = GetWebContents();
1486 if (!web_contents || !CommandLine::ForCurrentProcess()->HasSwitch( 1507 if (!web_contents || !CommandLine::ForCurrentProcess()->HasSwitch(
1487 switches::kEnableTranslateNewUX)) 1508 switches::kEnableTranslateNewUX))
1488 return; 1509 return;
1489 bool enabled = TranslateTabHelper::FromWebContents( 1510 bool enabled = TranslateTabHelper::FromWebContents(
1490 web_contents)->language_state().translate_enabled(); 1511 web_contents)->language_state().translate_enabled();
1491 command_updater()->UpdateCommandEnabled(IDC_TRANSLATE_PAGE, enabled); 1512 command_updater()->UpdateCommandEnabled(IDC_TRANSLATE_PAGE, enabled);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1558 bounds.Inset(-(horizontal_padding + 1) / 2, 0); 1579 bounds.Inset(-(horizontal_padding + 1) / 2, 0);
1559 location_bar_util::PaintExtensionActionBackground( 1580 location_bar_util::PaintExtensionActionBackground(
1560 *(*page_action_view)->image_view()->page_action(), 1581 *(*page_action_view)->image_view()->page_action(),
1561 tab_id, canvas, bounds, text_color, background_color); 1582 tab_id, canvas, bounds, text_color, background_color);
1562 } 1583 }
1563 } 1584 }
1564 1585
1565 void LocationBarView::AccessibilitySetValue(const string16& new_value) { 1586 void LocationBarView::AccessibilitySetValue(const string16& new_value) {
1566 location_entry_->SetUserText(new_value); 1587 location_entry_->SetUserText(new_value);
1567 } 1588 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/location_bar/location_bar_view.h ('k') | chrome/browser/ui/views/status_bubble_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698