| 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/bookmarks/bookmark_bar_view.h" | 5 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
| 14 #include "base/location.h" | 14 #include "base/location.h" |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
| 17 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/thread_task_runner_handle.h" | 20 #include "base/thread_task_runner_handle.h" |
| 21 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 21 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 22 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" | |
| 23 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h" | |
| 24 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
| 25 #include "chrome/browser/chrome_notification_types.h" | 23 #include "chrome/browser/chrome_notification_types.h" |
| 26 #include "chrome/browser/defaults.h" | 24 #include "chrome/browser/defaults.h" |
| 27 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
| 28 #include "chrome/browser/search/search.h" | 26 #include "chrome/browser/search/search.h" |
| 29 #include "chrome/browser/sync/profile_sync_service.h" | 27 #include "chrome/browser/sync/profile_sync_service.h" |
| 30 #include "chrome/browser/sync/profile_sync_service_factory.h" | 28 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 31 #include "chrome/browser/themes/theme_properties.h" | 29 #include "chrome/browser/themes/theme_properties.h" |
| 32 #include "chrome/browser/ui/bookmarks/bookmark_bar_constants.h" | 30 #include "chrome/browser/ui/bookmarks/bookmark_bar_constants.h" |
| 33 #include "chrome/browser/ui/bookmarks/bookmark_drag_drop.h" | 31 #include "chrome/browser/ui/bookmarks/bookmark_drag_drop.h" |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 DISALLOW_COPY_AND_ASSIGN(ButtonSeparatorView); | 494 DISALLOW_COPY_AND_ASSIGN(ButtonSeparatorView); |
| 497 }; | 495 }; |
| 498 | 496 |
| 499 // BookmarkBarView ------------------------------------------------------------ | 497 // BookmarkBarView ------------------------------------------------------------ |
| 500 | 498 |
| 501 // static | 499 // static |
| 502 const char BookmarkBarView::kViewClassName[] = "BookmarkBarView"; | 500 const char BookmarkBarView::kViewClassName[] = "BookmarkBarView"; |
| 503 | 501 |
| 504 BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view) | 502 BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view) |
| 505 : page_navigator_(NULL), | 503 : page_navigator_(NULL), |
| 506 client_(NULL), | |
| 507 bookmark_menu_(NULL), | 504 bookmark_menu_(NULL), |
| 508 bookmark_drop_menu_(NULL), | 505 bookmark_drop_menu_(NULL), |
| 509 other_bookmarks_button_(NULL), | 506 other_bookmarks_button_(NULL), |
| 510 managed_bookmarks_button_(NULL), | 507 managed_bookmarks_button_(NULL), |
| 511 supervised_bookmarks_button_(NULL), | 508 supervised_bookmarks_button_(NULL), |
| 512 apps_page_shortcut_(NULL), | 509 apps_page_shortcut_(NULL), |
| 513 overflow_button_(NULL), | 510 overflow_button_(NULL), |
| 514 instructions_(NULL), | 511 instructions_(NULL), |
| 515 bookmarks_separator_view_(NULL), | 512 bookmarks_separator_view_(NULL), |
| 516 browser_(browser), | 513 browser_(browser), |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 *model_start_index = 0; | 597 *model_start_index = 0; |
| 601 | 598 |
| 602 if (loc.x() < 0 || loc.x() >= width() || loc.y() < 0 || loc.y() >= height()) | 599 if (loc.x() < 0 || loc.x() >= width() || loc.y() < 0 || loc.y() >= height()) |
| 603 return NULL; | 600 return NULL; |
| 604 | 601 |
| 605 gfx::Point adjusted_loc(GetMirroredXInView(loc.x()), loc.y()); | 602 gfx::Point adjusted_loc(GetMirroredXInView(loc.x()), loc.y()); |
| 606 | 603 |
| 607 // Check the managed button first. | 604 // Check the managed button first. |
| 608 if (managed_bookmarks_button_->visible() && | 605 if (managed_bookmarks_button_->visible() && |
| 609 managed_bookmarks_button_->bounds().Contains(adjusted_loc)) { | 606 managed_bookmarks_button_->bounds().Contains(adjusted_loc)) { |
| 610 return client_->managed_node(); | 607 return model_->managed_node(); |
| 611 } | 608 } |
| 612 | 609 |
| 613 // Then check the supervised button. | 610 // Then check the supervised button. |
| 614 if (supervised_bookmarks_button_->visible() && | 611 if (supervised_bookmarks_button_->visible() && |
| 615 supervised_bookmarks_button_->bounds().Contains(adjusted_loc)) { | 612 supervised_bookmarks_button_->bounds().Contains(adjusted_loc)) { |
| 616 return client_->supervised_node(); | 613 return model_->supervised_node(); |
| 617 } | 614 } |
| 618 | 615 |
| 619 // Then check the bookmark buttons. | 616 // Then check the bookmark buttons. |
| 620 for (int i = 0; i < GetBookmarkButtonCount(); ++i) { | 617 for (int i = 0; i < GetBookmarkButtonCount(); ++i) { |
| 621 views::View* child = child_at(i); | 618 views::View* child = child_at(i); |
| 622 if (!child->visible()) | 619 if (!child->visible()) |
| 623 break; | 620 break; |
| 624 if (child->bounds().Contains(adjusted_loc)) | 621 if (child->bounds().Contains(adjusted_loc)) |
| 625 return model_->bookmark_bar_node()->GetChild(i); | 622 return model_->bookmark_bar_node()->GetChild(i); |
| 626 } | 623 } |
| 627 | 624 |
| 628 // Then the overflow button. | 625 // Then the overflow button. |
| 629 if (overflow_button_->visible() && | 626 if (overflow_button_->visible() && |
| 630 overflow_button_->bounds().Contains(adjusted_loc)) { | 627 overflow_button_->bounds().Contains(adjusted_loc)) { |
| 631 *model_start_index = GetFirstHiddenNodeIndex(); | 628 *model_start_index = GetFirstHiddenNodeIndex(); |
| 632 return model_->bookmark_bar_node(); | 629 return model_->bookmark_bar_node(); |
| 633 } | 630 } |
| 634 | 631 |
| 635 // And finally the other folder. | 632 // And finally the other folder. |
| 636 if (other_bookmarks_button_->visible() && | 633 if (other_bookmarks_button_->visible() && |
| 637 other_bookmarks_button_->bounds().Contains(adjusted_loc)) { | 634 other_bookmarks_button_->bounds().Contains(adjusted_loc)) { |
| 638 return model_->other_node(); | 635 return model_->other_node(); |
| 639 } | 636 } |
| 640 | 637 |
| 641 return NULL; | 638 return NULL; |
| 642 } | 639 } |
| 643 | 640 |
| 644 views::MenuButton* BookmarkBarView::GetMenuButtonForNode( | 641 views::MenuButton* BookmarkBarView::GetMenuButtonForNode( |
| 645 const BookmarkNode* node) { | 642 const BookmarkNode* node) { |
| 646 if (node == client_->managed_node()) | 643 if (node == model_->managed_node()) |
| 647 return managed_bookmarks_button_; | 644 return managed_bookmarks_button_; |
| 648 if (node == client_->supervised_node()) | 645 if (node == model_->supervised_node()) |
| 649 return supervised_bookmarks_button_; | 646 return supervised_bookmarks_button_; |
| 650 if (node == model_->other_node()) | 647 if (node == model_->other_node()) |
| 651 return other_bookmarks_button_; | 648 return other_bookmarks_button_; |
| 652 if (node == model_->bookmark_bar_node()) | 649 if (node == model_->bookmark_bar_node()) |
| 653 return overflow_button_; | 650 return overflow_button_; |
| 654 int index = model_->bookmark_bar_node()->GetIndexOf(node); | 651 int index = model_->bookmark_bar_node()->GetIndexOf(node); |
| 655 if (index == -1 || !node->is_folder()) | 652 if (index == -1 || !node->is_folder()) |
| 656 return NULL; | 653 return NULL; |
| 657 return static_cast<views::MenuButton*>(child_at(index)); | 654 return static_cast<views::MenuButton*>(child_at(index)); |
| 658 } | 655 } |
| (...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1227 void BookmarkBarView::BookmarkModelLoaded(BookmarkModel* model, | 1224 void BookmarkBarView::BookmarkModelLoaded(BookmarkModel* model, |
| 1228 bool ids_reassigned) { | 1225 bool ids_reassigned) { |
| 1229 // There should be no buttons. If non-zero it means Load was invoked more than | 1226 // There should be no buttons. If non-zero it means Load was invoked more than |
| 1230 // once, or we didn't properly clear things. Either of which shouldn't happen. | 1227 // once, or we didn't properly clear things. Either of which shouldn't happen. |
| 1231 // The actual bookmark buttons are added from Layout(). | 1228 // The actual bookmark buttons are added from Layout(). |
| 1232 DCHECK_EQ(0, GetBookmarkButtonCount()); | 1229 DCHECK_EQ(0, GetBookmarkButtonCount()); |
| 1233 DCHECK(model->other_node()); | 1230 DCHECK(model->other_node()); |
| 1234 other_bookmarks_button_->SetAccessibleName(model->other_node()->GetTitle()); | 1231 other_bookmarks_button_->SetAccessibleName(model->other_node()->GetTitle()); |
| 1235 other_bookmarks_button_->SetText(model->other_node()->GetTitle()); | 1232 other_bookmarks_button_->SetText(model->other_node()->GetTitle()); |
| 1236 managed_bookmarks_button_->SetAccessibleName( | 1233 managed_bookmarks_button_->SetAccessibleName( |
| 1237 client_->managed_node()->GetTitle()); | 1234 model_->managed_node()->GetTitle()); |
| 1238 managed_bookmarks_button_->SetText(client_->managed_node()->GetTitle()); | 1235 managed_bookmarks_button_->SetText(model_->managed_node()->GetTitle()); |
| 1239 supervised_bookmarks_button_->SetAccessibleName( | 1236 supervised_bookmarks_button_->SetAccessibleName( |
| 1240 client_->supervised_node()->GetTitle()); | 1237 model_->supervised_node()->GetTitle()); |
| 1241 supervised_bookmarks_button_->SetText(client_->supervised_node()->GetTitle()); | 1238 supervised_bookmarks_button_->SetText(model_->supervised_node()->GetTitle()); |
| 1242 UpdateColors(); | 1239 UpdateColors(); |
| 1243 UpdateOtherAndManagedButtonsVisibility(); | 1240 UpdateOtherAndManagedButtonsVisibility(); |
| 1244 other_bookmarks_button_->SetEnabled(true); | 1241 other_bookmarks_button_->SetEnabled(true); |
| 1245 managed_bookmarks_button_->SetEnabled(true); | 1242 managed_bookmarks_button_->SetEnabled(true); |
| 1246 supervised_bookmarks_button_->SetEnabled(true); | 1243 supervised_bookmarks_button_->SetEnabled(true); |
| 1247 LayoutAndPaint(); | 1244 LayoutAndPaint(); |
| 1248 } | 1245 } |
| 1249 | 1246 |
| 1250 void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkModel* model) { | 1247 void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkModel* model) { |
| 1251 NOTREACHED(); | 1248 NOTREACHED(); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1410 } | 1407 } |
| 1411 | 1408 |
| 1412 void BookmarkBarView::OnMenuButtonClicked(views::View* view, | 1409 void BookmarkBarView::OnMenuButtonClicked(views::View* view, |
| 1413 const gfx::Point& point) { | 1410 const gfx::Point& point) { |
| 1414 const BookmarkNode* node; | 1411 const BookmarkNode* node; |
| 1415 | 1412 |
| 1416 int start_index = 0; | 1413 int start_index = 0; |
| 1417 if (view == other_bookmarks_button_) { | 1414 if (view == other_bookmarks_button_) { |
| 1418 node = model_->other_node(); | 1415 node = model_->other_node(); |
| 1419 } else if (view == managed_bookmarks_button_) { | 1416 } else if (view == managed_bookmarks_button_) { |
| 1420 node = client_->managed_node(); | 1417 node = model_->managed_node(); |
| 1421 } else if (view == supervised_bookmarks_button_) { | 1418 } else if (view == supervised_bookmarks_button_) { |
| 1422 node = client_->supervised_node(); | 1419 node = model_->supervised_node(); |
| 1423 } else if (view == overflow_button_) { | 1420 } else if (view == overflow_button_) { |
| 1424 node = model_->bookmark_bar_node(); | 1421 node = model_->bookmark_bar_node(); |
| 1425 start_index = GetFirstHiddenNodeIndex(); | 1422 start_index = GetFirstHiddenNodeIndex(); |
| 1426 } else { | 1423 } else { |
| 1427 int button_index = GetIndexOf(view); | 1424 int button_index = GetIndexOf(view); |
| 1428 DCHECK_NE(-1, button_index); | 1425 DCHECK_NE(-1, button_index); |
| 1429 node = model_->bookmark_bar_node()->GetChild(button_index); | 1426 node = model_->bookmark_bar_node()->GetChild(button_index); |
| 1430 } | 1427 } |
| 1431 | 1428 |
| 1432 RecordBookmarkFolderOpen(GetBookmarkLaunchLocation()); | 1429 RecordBookmarkFolderOpen(GetBookmarkLaunchLocation()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1449 false); | 1446 false); |
| 1450 page_navigator_->OpenURL(params); | 1447 page_navigator_->OpenURL(params); |
| 1451 RecordBookmarkAppsPageOpen(GetBookmarkLaunchLocation()); | 1448 RecordBookmarkAppsPageOpen(GetBookmarkLaunchLocation()); |
| 1452 return; | 1449 return; |
| 1453 } | 1450 } |
| 1454 | 1451 |
| 1455 const BookmarkNode* node; | 1452 const BookmarkNode* node; |
| 1456 if (sender->tag() == kOtherFolderButtonTag) { | 1453 if (sender->tag() == kOtherFolderButtonTag) { |
| 1457 node = model_->other_node(); | 1454 node = model_->other_node(); |
| 1458 } else if (sender->tag() == kManagedFolderButtonTag) { | 1455 } else if (sender->tag() == kManagedFolderButtonTag) { |
| 1459 node = client_->managed_node(); | 1456 node = model_->managed_node(); |
| 1460 } else if (sender->tag() == kSupervisedFolderButtonTag) { | 1457 } else if (sender->tag() == kSupervisedFolderButtonTag) { |
| 1461 node = client_->supervised_node(); | 1458 node = model_->supervised_node(); |
| 1462 } else { | 1459 } else { |
| 1463 int index = GetIndexOf(sender); | 1460 int index = GetIndexOf(sender); |
| 1464 DCHECK_NE(-1, index); | 1461 DCHECK_NE(-1, index); |
| 1465 node = model_->bookmark_bar_node()->GetChild(index); | 1462 node = model_->bookmark_bar_node()->GetChild(index); |
| 1466 } | 1463 } |
| 1467 DCHECK(page_navigator_); | 1464 DCHECK(page_navigator_); |
| 1468 | 1465 |
| 1469 if (node->is_url()) { | 1466 if (node->is_url()) { |
| 1470 RecordAppLaunch(browser_->profile(), node->url()); | 1467 RecordAppLaunch(browser_->profile(), node->url()); |
| 1471 OpenURLParams params( | 1468 OpenURLParams params( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1489 } | 1486 } |
| 1490 | 1487 |
| 1491 const BookmarkNode* parent = NULL; | 1488 const BookmarkNode* parent = NULL; |
| 1492 std::vector<const BookmarkNode*> nodes; | 1489 std::vector<const BookmarkNode*> nodes; |
| 1493 if (source == other_bookmarks_button_) { | 1490 if (source == other_bookmarks_button_) { |
| 1494 parent = model_->other_node(); | 1491 parent = model_->other_node(); |
| 1495 // Do this so the user can open all bookmarks. BookmarkContextMenu makes | 1492 // Do this so the user can open all bookmarks. BookmarkContextMenu makes |
| 1496 // sure the user can't edit/delete the node in this case. | 1493 // sure the user can't edit/delete the node in this case. |
| 1497 nodes.push_back(parent); | 1494 nodes.push_back(parent); |
| 1498 } else if (source == managed_bookmarks_button_) { | 1495 } else if (source == managed_bookmarks_button_) { |
| 1499 parent = client_->managed_node(); | 1496 parent = model_->managed_node(); |
| 1500 nodes.push_back(parent); | 1497 nodes.push_back(parent); |
| 1501 } else if (source == supervised_bookmarks_button_) { | 1498 } else if (source == supervised_bookmarks_button_) { |
| 1502 parent = client_->supervised_node(); | 1499 parent = model_->supervised_node(); |
| 1503 nodes.push_back(parent); | 1500 nodes.push_back(parent); |
| 1504 } else if (source != this && source != apps_page_shortcut_) { | 1501 } else if (source != this && source != apps_page_shortcut_) { |
| 1505 // User clicked on one of the bookmark buttons, find which one they | 1502 // User clicked on one of the bookmark buttons, find which one they |
| 1506 // clicked on, except for the apps page shortcut, which must behave as if | 1503 // clicked on, except for the apps page shortcut, which must behave as if |
| 1507 // the user clicked on the bookmark bar background. | 1504 // the user clicked on the bookmark bar background. |
| 1508 int bookmark_button_index = GetIndexOf(source); | 1505 int bookmark_button_index = GetIndexOf(source); |
| 1509 DCHECK(bookmark_button_index != -1 && | 1506 DCHECK(bookmark_button_index != -1 && |
| 1510 bookmark_button_index < GetBookmarkButtonCount()); | 1507 bookmark_button_index < GetBookmarkButtonCount()); |
| 1511 const BookmarkNode* node = | 1508 const BookmarkNode* node = |
| 1512 model_->bookmark_bar_node()->GetChild(bookmark_button_index); | 1509 model_->bookmark_bar_node()->GetChild(bookmark_button_index); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1572 UpdateBookmarksSeparatorVisibility(); | 1569 UpdateBookmarksSeparatorVisibility(); |
| 1573 | 1570 |
| 1574 instructions_ = new BookmarkBarInstructionsView(this); | 1571 instructions_ = new BookmarkBarInstructionsView(this); |
| 1575 AddChildView(instructions_); | 1572 AddChildView(instructions_); |
| 1576 | 1573 |
| 1577 set_context_menu_controller(this); | 1574 set_context_menu_controller(this); |
| 1578 | 1575 |
| 1579 size_animation_.reset(new gfx::SlideAnimation(this)); | 1576 size_animation_.reset(new gfx::SlideAnimation(this)); |
| 1580 | 1577 |
| 1581 model_ = BookmarkModelFactory::GetForProfile(browser_->profile()); | 1578 model_ = BookmarkModelFactory::GetForProfile(browser_->profile()); |
| 1582 client_ = ChromeBookmarkClientFactory::GetForProfile(browser_->profile()); | |
| 1583 if (model_) { | 1579 if (model_) { |
| 1584 model_->AddObserver(this); | 1580 model_->AddObserver(this); |
| 1585 if (model_->loaded()) | 1581 if (model_->loaded()) |
| 1586 BookmarkModelLoaded(model_, false); | 1582 BookmarkModelLoaded(model_, false); |
| 1587 // else case: we'll receive notification back from the BookmarkModel when | 1583 // else case: we'll receive notification back from the BookmarkModel when |
| 1588 // done loading, then we'll populate the bar. | 1584 // done loading, then we'll populate the bar. |
| 1589 } | 1585 } |
| 1590 } | 1586 } |
| 1591 | 1587 |
| 1592 int BookmarkBarView::GetBookmarkButtonCount() const { | 1588 int BookmarkBarView::GetBookmarkButtonCount() const { |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1758 } | 1754 } |
| 1759 if (index >= GetBookmarkButtonCount()) | 1755 if (index >= GetBookmarkButtonCount()) |
| 1760 return needs_layout; | 1756 return needs_layout; |
| 1761 | 1757 |
| 1762 delete child_at(index); | 1758 delete child_at(index); |
| 1763 return true; | 1759 return true; |
| 1764 } | 1760 } |
| 1765 | 1761 |
| 1766 void BookmarkBarView::BookmarkNodeChangedImpl(BookmarkModel* model, | 1762 void BookmarkBarView::BookmarkNodeChangedImpl(BookmarkModel* model, |
| 1767 const BookmarkNode* node) { | 1763 const BookmarkNode* node) { |
| 1768 if (node == client_->managed_node()) { | 1764 if (node == model_->managed_node()) { |
| 1769 // The managed node may have its title updated. | 1765 // The managed node may have its title updated. |
| 1770 managed_bookmarks_button_->SetAccessibleName( | 1766 managed_bookmarks_button_->SetAccessibleName( |
| 1771 client_->managed_node()->GetTitle()); | 1767 model_->managed_node()->GetTitle()); |
| 1772 managed_bookmarks_button_->SetText(client_->managed_node()->GetTitle()); | 1768 managed_bookmarks_button_->SetText(model_->managed_node()->GetTitle()); |
| 1773 return; | 1769 return; |
| 1774 } | 1770 } |
| 1775 if (node == client_->supervised_node()) { | 1771 if (node == model_->supervised_node()) { |
| 1776 // The supervised node may have its title updated. | 1772 // The supervised node may have its title updated. |
| 1777 supervised_bookmarks_button_->SetAccessibleName( | 1773 supervised_bookmarks_button_->SetAccessibleName( |
| 1778 client_->supervised_node()->GetTitle()); | 1774 model_->supervised_node()->GetTitle()); |
| 1779 supervised_bookmarks_button_->SetText( | 1775 supervised_bookmarks_button_->SetText( |
| 1780 client_->supervised_node()->GetTitle()); | 1776 model_->supervised_node()->GetTitle()); |
| 1781 return; | 1777 return; |
| 1782 } | 1778 } |
| 1783 | 1779 |
| 1784 if (node->parent() != model->bookmark_bar_node()) { | 1780 if (node->parent() != model->bookmark_bar_node()) { |
| 1785 // We only care about nodes on the bookmark bar. | 1781 // We only care about nodes on the bookmark bar. |
| 1786 return; | 1782 return; |
| 1787 } | 1783 } |
| 1788 int index = model->bookmark_bar_node()->GetIndexOf(node); | 1784 int index = model->bookmark_bar_node()->GetIndexOf(node); |
| 1789 DCHECK_NE(-1, index); | 1785 DCHECK_NE(-1, index); |
| 1790 if (index >= GetBookmarkButtonCount()) | 1786 if (index >= GetBookmarkButtonCount()) |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1860 if (other_bookmarks_button_->visible() && other_delta_x >= 0 && | 1856 if (other_bookmarks_button_->visible() && other_delta_x >= 0 && |
| 1861 other_delta_x < other_bookmarks_button_->width()) { | 1857 other_delta_x < other_bookmarks_button_->width()) { |
| 1862 // Mouse is over 'other' folder. | 1858 // Mouse is over 'other' folder. |
| 1863 location->button_type = DROP_OTHER_FOLDER; | 1859 location->button_type = DROP_OTHER_FOLDER; |
| 1864 location->on = true; | 1860 location->on = true; |
| 1865 found = true; | 1861 found = true; |
| 1866 } else if (!GetBookmarkButtonCount()) { | 1862 } else if (!GetBookmarkButtonCount()) { |
| 1867 // No bookmarks, accept the drop. | 1863 // No bookmarks, accept the drop. |
| 1868 location->index = 0; | 1864 location->index = 0; |
| 1869 const BookmarkNode* node = data.GetFirstNode(model_, profile->GetPath()); | 1865 const BookmarkNode* node = data.GetFirstNode(model_, profile->GetPath()); |
| 1870 int ops = node && client_->CanBeEditedByUser(node) ? | 1866 int ops = node && model_->CanBeEditedByUser(node) ? |
| 1871 ui::DragDropTypes::DRAG_MOVE : | 1867 ui::DragDropTypes::DRAG_MOVE : |
| 1872 ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK; | 1868 ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK; |
| 1873 location->operation = chrome::GetPreferredBookmarkDropOperation( | 1869 location->operation = chrome::GetPreferredBookmarkDropOperation( |
| 1874 event.source_operations(), ops); | 1870 event.source_operations(), ops); |
| 1875 return; | 1871 return; |
| 1876 } | 1872 } |
| 1877 | 1873 |
| 1878 for (int i = 0; i < GetBookmarkButtonCount() && | 1874 for (int i = 0; i < GetBookmarkButtonCount() && |
| 1879 GetBookmarkButton(i)->visible() && !found; i++) { | 1875 GetBookmarkButton(i)->visible() && !found; i++) { |
| 1880 views::LabelButton* button = GetBookmarkButton(i); | 1876 views::LabelButton* button = GetBookmarkButton(i); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1966 parent_on_bb = parent; | 1962 parent_on_bb = parent; |
| 1967 } | 1963 } |
| 1968 if (parent_on_bb) { | 1964 if (parent_on_bb) { |
| 1969 int index = bbn->GetIndexOf(parent_on_bb); | 1965 int index = bbn->GetIndexOf(parent_on_bb); |
| 1970 if (index >= GetFirstHiddenNodeIndex()) { | 1966 if (index >= GetFirstHiddenNodeIndex()) { |
| 1971 // Node is hidden, animate the overflow button. | 1967 // Node is hidden, animate the overflow button. |
| 1972 throbbing_view_ = overflow_button_; | 1968 throbbing_view_ = overflow_button_; |
| 1973 } else if (!overflow_only) { | 1969 } else if (!overflow_only) { |
| 1974 throbbing_view_ = static_cast<CustomButton*>(child_at(index)); | 1970 throbbing_view_ = static_cast<CustomButton*>(child_at(index)); |
| 1975 } | 1971 } |
| 1976 } else if (bookmarks::IsDescendantOf(node, client_->managed_node())) { | 1972 } else if (bookmarks::IsDescendantOf(node, model_->managed_node())) { |
| 1977 throbbing_view_ = managed_bookmarks_button_; | 1973 throbbing_view_ = managed_bookmarks_button_; |
| 1978 } else if (bookmarks::IsDescendantOf(node, client_->supervised_node())) { | 1974 } else if (bookmarks::IsDescendantOf(node, model_->supervised_node())) { |
| 1979 throbbing_view_ = supervised_bookmarks_button_; | 1975 throbbing_view_ = supervised_bookmarks_button_; |
| 1980 } else if (!overflow_only) { | 1976 } else if (!overflow_only) { |
| 1981 throbbing_view_ = other_bookmarks_button_; | 1977 throbbing_view_ = other_bookmarks_button_; |
| 1982 } | 1978 } |
| 1983 | 1979 |
| 1984 // Use a large number so that the button continues to throb. | 1980 // Use a large number so that the button continues to throb. |
| 1985 if (throbbing_view_) | 1981 if (throbbing_view_) |
| 1986 throbbing_view_->StartThrobbing(std::numeric_limits<int>::max()); | 1982 throbbing_view_->StartThrobbing(std::numeric_limits<int>::max()); |
| 1987 } | 1983 } |
| 1988 | 1984 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2000 } | 1996 } |
| 2001 old_node = parent; | 1997 old_node = parent; |
| 2002 } | 1998 } |
| 2003 if (old_node) { | 1999 if (old_node) { |
| 2004 if (old_index_on_bb >= GetFirstHiddenNodeIndex()) { | 2000 if (old_index_on_bb >= GetFirstHiddenNodeIndex()) { |
| 2005 // Node is hidden, animate the overflow button. | 2001 // Node is hidden, animate the overflow button. |
| 2006 return overflow_button_; | 2002 return overflow_button_; |
| 2007 } | 2003 } |
| 2008 return static_cast<CustomButton*>(child_at(old_index_on_bb)); | 2004 return static_cast<CustomButton*>(child_at(old_index_on_bb)); |
| 2009 } | 2005 } |
| 2010 if (bookmarks::IsDescendantOf(parent, client_->managed_node())) | 2006 if (bookmarks::IsDescendantOf(parent, model_->managed_node())) |
| 2011 return managed_bookmarks_button_; | 2007 return managed_bookmarks_button_; |
| 2012 if (bookmarks::IsDescendantOf(parent, client_->supervised_node())) | 2008 if (bookmarks::IsDescendantOf(parent, model_->supervised_node())) |
| 2013 return supervised_bookmarks_button_; | 2009 return supervised_bookmarks_button_; |
| 2014 // Node wasn't on the bookmark bar, use the "Other Bookmarks" button. | 2010 // Node wasn't on the bookmark bar, use the "Other Bookmarks" button. |
| 2015 return other_bookmarks_button_; | 2011 return other_bookmarks_button_; |
| 2016 } | 2012 } |
| 2017 | 2013 |
| 2018 void BookmarkBarView::UpdateColors() { | 2014 void BookmarkBarView::UpdateColors() { |
| 2019 // We don't always have a theme provider (ui tests, for example). | 2015 // We don't always have a theme provider (ui tests, for example). |
| 2020 const ui::ThemeProvider* theme_provider = GetThemeProvider(); | 2016 const ui::ThemeProvider* theme_provider = GetThemeProvider(); |
| 2021 if (!theme_provider) | 2017 if (!theme_provider) |
| 2022 return; | 2018 return; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2033 } | 2029 } |
| 2034 | 2030 |
| 2035 bool BookmarkBarView::UpdateOtherAndManagedButtonsVisibility() { | 2031 bool BookmarkBarView::UpdateOtherAndManagedButtonsVisibility() { |
| 2036 bool has_other_children = !model_->other_node()->empty(); | 2032 bool has_other_children = !model_->other_node()->empty(); |
| 2037 bool update_other = has_other_children != other_bookmarks_button_->visible(); | 2033 bool update_other = has_other_children != other_bookmarks_button_->visible(); |
| 2038 if (update_other) { | 2034 if (update_other) { |
| 2039 other_bookmarks_button_->SetVisible(has_other_children); | 2035 other_bookmarks_button_->SetVisible(has_other_children); |
| 2040 UpdateBookmarksSeparatorVisibility(); | 2036 UpdateBookmarksSeparatorVisibility(); |
| 2041 } | 2037 } |
| 2042 | 2038 |
| 2043 bool show_managed = !client_->managed_node()->empty() && | 2039 bool show_managed = !model_->managed_node()->empty() && |
| 2044 browser_->profile()->GetPrefs()->GetBoolean( | 2040 browser_->profile()->GetPrefs()->GetBoolean( |
| 2045 bookmarks::prefs::kShowManagedBookmarksInBookmarkBar); | 2041 bookmarks::prefs::kShowManagedBookmarksInBookmarkBar); |
| 2046 bool update_managed = show_managed != managed_bookmarks_button_->visible(); | 2042 bool update_managed = show_managed != managed_bookmarks_button_->visible(); |
| 2047 if (update_managed) | 2043 if (update_managed) |
| 2048 managed_bookmarks_button_->SetVisible(show_managed); | 2044 managed_bookmarks_button_->SetVisible(show_managed); |
| 2049 | 2045 |
| 2050 bool show_supervised = !client_->supervised_node()->empty(); | 2046 bool show_supervised = !model_->supervised_node()->empty(); |
| 2051 bool update_supervised = | 2047 bool update_supervised = |
| 2052 show_supervised != supervised_bookmarks_button_->visible(); | 2048 show_supervised != supervised_bookmarks_button_->visible(); |
| 2053 if (update_supervised) | 2049 if (update_supervised) |
| 2054 supervised_bookmarks_button_->SetVisible(show_supervised); | 2050 supervised_bookmarks_button_->SetVisible(show_supervised); |
| 2055 | 2051 |
| 2056 return update_other || update_managed || update_supervised; | 2052 return update_other || update_managed || update_supervised; |
| 2057 } | 2053 } |
| 2058 | 2054 |
| 2059 void BookmarkBarView::UpdateBookmarksSeparatorVisibility() { | 2055 void BookmarkBarView::UpdateBookmarksSeparatorVisibility() { |
| 2060 // Ash does not paint the bookmarks separator line because it looks odd on | 2056 // Ash does not paint the bookmarks separator line because it looks odd on |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2073 return; | 2069 return; |
| 2074 apps_page_shortcut_->SetVisible(visible); | 2070 apps_page_shortcut_->SetVisible(visible); |
| 2075 UpdateBookmarksSeparatorVisibility(); | 2071 UpdateBookmarksSeparatorVisibility(); |
| 2076 LayoutAndPaint(); | 2072 LayoutAndPaint(); |
| 2077 } | 2073 } |
| 2078 | 2074 |
| 2079 void BookmarkBarView::OnShowManagedBookmarksPrefChanged() { | 2075 void BookmarkBarView::OnShowManagedBookmarksPrefChanged() { |
| 2080 if (UpdateOtherAndManagedButtonsVisibility()) | 2076 if (UpdateOtherAndManagedButtonsVisibility()) |
| 2081 LayoutAndPaint(); | 2077 LayoutAndPaint(); |
| 2082 } | 2078 } |
| OLD | NEW |