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