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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <limits> | 10 #include <limits> |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 // Width of the separator between the recently bookmarked button and the | 154 // Width of the separator between the recently bookmarked button and the |
155 // overflow indicator, indexed by MD mode. | 155 // overflow indicator, indexed by MD mode. |
156 static const int kSeparatorWidth[] = {4, 9, 9}; | 156 static const int kSeparatorWidth[] = {4, 9, 9}; |
157 | 157 |
158 // Starting x-coordinate of the separator line within a separator. | 158 // Starting x-coordinate of the separator line within a separator. |
159 static const int kSeparatorStartX = 2; | 159 static const int kSeparatorStartX = 2; |
160 | 160 |
161 // Left-padding for the instructional text. | 161 // Left-padding for the instructional text. |
162 static const int kInstructionsPadding = 6; | 162 static const int kInstructionsPadding = 6; |
163 | 163 |
164 // Tag for the 'Other bookmarks' button. | |
165 static const int kOtherFolderButtonTag = 1; | |
166 | |
167 // Tag for the 'Apps Shortcut' button. | 164 // Tag for the 'Apps Shortcut' button. |
168 static const int kAppsShortcutButtonTag = 2; | 165 static const int kAppsShortcutButtonTag = 2; |
169 | 166 |
170 // Preferred padding between text and edge. | 167 // Preferred padding between text and edge. |
171 static const int kButtonPaddingHorizontal = 6; | 168 static const int kButtonPaddingHorizontal = 6; |
172 static const int kButtonPaddingVertical = 4; | 169 static const int kButtonPaddingVertical = 4; |
173 | 170 |
174 // Tag for the 'Managed bookmarks' button. | |
175 static const int kManagedFolderButtonTag = 3; | |
176 // Tag for the 'Supervised bookmarks' button. | |
177 static const int kSupervisedFolderButtonTag = 4; | |
178 | |
179 static const gfx::ElideBehavior kElideBehavior = gfx::FADE_TAIL; | 171 static const gfx::ElideBehavior kElideBehavior = gfx::FADE_TAIL; |
180 | 172 |
181 namespace { | 173 namespace { |
182 | 174 |
183 // To enable/disable BookmarkBar animations during testing. In production | 175 // To enable/disable BookmarkBar animations during testing. In production |
184 // animations are enabled by default. | 176 // animations are enabled by default. |
185 bool animations_enabled = true; | 177 bool animations_enabled = true; |
186 | 178 |
187 gfx::ImageSkia* GetImageSkiaNamed(int id) { | 179 gfx::ImageSkia* GetImageSkiaNamed(int id) { |
188 return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(id); | 180 return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(id); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 | 287 |
296 // static | 288 // static |
297 const char ShortcutButton::kViewClassName[] = "ShortcutButton"; | 289 const char ShortcutButton::kViewClassName[] = "ShortcutButton"; |
298 | 290 |
299 // BookmarkFolderButton ------------------------------------------------------- | 291 // BookmarkFolderButton ------------------------------------------------------- |
300 | 292 |
301 // Buttons used for folders on the bookmark bar, including the 'other folders' | 293 // Buttons used for folders on the bookmark bar, including the 'other folders' |
302 // button. | 294 // button. |
303 class BookmarkFolderButton : public views::MenuButton { | 295 class BookmarkFolderButton : public views::MenuButton { |
304 public: | 296 public: |
305 BookmarkFolderButton(views::ButtonListener* listener, | 297 BookmarkFolderButton(const base::string16& title, |
306 const base::string16& title, | |
307 views::MenuButtonListener* menu_button_listener, | 298 views::MenuButtonListener* menu_button_listener, |
308 bool show_menu_marker) | 299 bool show_menu_marker) |
309 : MenuButton(listener, title, menu_button_listener, show_menu_marker) { | 300 : MenuButton(title, menu_button_listener, show_menu_marker) { |
310 SetElideBehavior(kElideBehavior); | 301 SetElideBehavior(kElideBehavior); |
311 show_animation_.reset(new gfx::SlideAnimation(this)); | 302 show_animation_.reset(new gfx::SlideAnimation(this)); |
312 if (!animations_enabled) { | 303 if (!animations_enabled) { |
313 // For some reason during testing the events generated by animating | 304 // For some reason during testing the events generated by animating |
314 // throw off the test. So, don't animate while testing. | 305 // throw off the test. So, don't animate while testing. |
315 show_animation_->Reset(1); | 306 show_animation_->Reset(1); |
316 } else { | 307 } else { |
317 show_animation_->Show(); | 308 show_animation_->Show(); |
318 } | 309 } |
319 } | 310 } |
(...skipping 23 matching lines...) Expand all Loading... |
343 scoped_ptr<gfx::SlideAnimation> show_animation_; | 334 scoped_ptr<gfx::SlideAnimation> show_animation_; |
344 | 335 |
345 DISALLOW_COPY_AND_ASSIGN(BookmarkFolderButton); | 336 DISALLOW_COPY_AND_ASSIGN(BookmarkFolderButton); |
346 }; | 337 }; |
347 | 338 |
348 // OverflowButton (chevron) -------------------------------------------------- | 339 // OverflowButton (chevron) -------------------------------------------------- |
349 | 340 |
350 class OverflowButton : public views::MenuButton { | 341 class OverflowButton : public views::MenuButton { |
351 public: | 342 public: |
352 explicit OverflowButton(BookmarkBarView* owner) | 343 explicit OverflowButton(BookmarkBarView* owner) |
353 : MenuButton(NULL, base::string16(), owner, false), owner_(owner) {} | 344 : MenuButton(base::string16(), owner, false), owner_(owner) {} |
354 | 345 |
355 bool OnMousePressed(const ui::MouseEvent& e) override { | 346 bool OnMousePressed(const ui::MouseEvent& e) override { |
356 owner_->StopThrobbing(true); | 347 owner_->StopThrobbing(true); |
357 return views::MenuButton::OnMousePressed(e); | 348 return views::MenuButton::OnMousePressed(e); |
358 } | 349 } |
359 | 350 |
360 private: | 351 private: |
361 BookmarkBarView* owner_; | 352 BookmarkBarView* owner_; |
362 | 353 |
363 DISALLOW_COPY_AND_ASSIGN(OverflowButton); | 354 DISALLOW_COPY_AND_ASSIGN(OverflowButton); |
(...skipping 1090 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1454 OpenURLParams params(GURL(chrome::kChromeUIAppsURL), | 1445 OpenURLParams params(GURL(chrome::kChromeUIAppsURL), |
1455 Referrer(), | 1446 Referrer(), |
1456 disposition_from_event_flags, | 1447 disposition_from_event_flags, |
1457 ui::PAGE_TRANSITION_AUTO_BOOKMARK, | 1448 ui::PAGE_TRANSITION_AUTO_BOOKMARK, |
1458 false); | 1449 false); |
1459 page_navigator_->OpenURL(params); | 1450 page_navigator_->OpenURL(params); |
1460 RecordBookmarkAppsPageOpen(GetBookmarkLaunchLocation()); | 1451 RecordBookmarkAppsPageOpen(GetBookmarkLaunchLocation()); |
1461 return; | 1452 return; |
1462 } | 1453 } |
1463 | 1454 |
1464 const BookmarkNode* node; | 1455 int index = GetIndexOf(sender); |
1465 if (sender->tag() == kOtherFolderButtonTag) { | 1456 DCHECK_NE(-1, index); |
1466 node = model_->other_node(); | 1457 const BookmarkNode* node = model_->bookmark_bar_node()->GetChild(index); |
1467 } else if (sender->tag() == kManagedFolderButtonTag) { | |
1468 node = managed_->managed_node(); | |
1469 } else if (sender->tag() == kSupervisedFolderButtonTag) { | |
1470 node = managed_->supervised_node(); | |
1471 } else { | |
1472 int index = GetIndexOf(sender); | |
1473 DCHECK_NE(-1, index); | |
1474 node = model_->bookmark_bar_node()->GetChild(index); | |
1475 } | |
1476 DCHECK(page_navigator_); | 1458 DCHECK(page_navigator_); |
1477 | 1459 |
1478 if (node->is_url()) { | 1460 if (node->is_url()) { |
1479 RecordAppLaunch(browser_->profile(), node->url()); | 1461 RecordAppLaunch(browser_->profile(), node->url()); |
1480 OpenURLParams params( | 1462 OpenURLParams params( |
1481 node->url(), Referrer(), disposition_from_event_flags, | 1463 node->url(), Referrer(), disposition_from_event_flags, |
1482 ui::PAGE_TRANSITION_AUTO_BOOKMARK, false); | 1464 ui::PAGE_TRANSITION_AUTO_BOOKMARK, false); |
1483 page_navigator_->OpenURL(params); | 1465 page_navigator_->OpenURL(params); |
1484 } else { | 1466 } else { |
1485 chrome::OpenAll(GetWidget()->GetNativeWindow(), page_navigator_, node, | 1467 chrome::OpenAll(GetWidget()->GetNativeWindow(), page_navigator_, node, |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1620 const int bb_count = GetBookmarkButtonCount(); | 1602 const int bb_count = GetBookmarkButtonCount(); |
1621 for (int i = 0; i < bb_count; ++i) { | 1603 for (int i = 0; i < bb_count; ++i) { |
1622 if (!GetBookmarkButton(i)->visible()) | 1604 if (!GetBookmarkButton(i)->visible()) |
1623 return i; | 1605 return i; |
1624 } | 1606 } |
1625 return bb_count; | 1607 return bb_count; |
1626 } | 1608 } |
1627 | 1609 |
1628 MenuButton* BookmarkBarView::CreateOtherBookmarksButton() { | 1610 MenuButton* BookmarkBarView::CreateOtherBookmarksButton() { |
1629 // Title is set in Loaded. | 1611 // Title is set in Loaded. |
1630 MenuButton* button = | 1612 MenuButton* button = new BookmarkFolderButton(base::string16(), this, false); |
1631 new BookmarkFolderButton(this, base::string16(), this, false); | |
1632 button->set_id(VIEW_ID_OTHER_BOOKMARKS); | 1613 button->set_id(VIEW_ID_OTHER_BOOKMARKS); |
1633 button->set_context_menu_controller(this); | 1614 button->set_context_menu_controller(this); |
1634 button->set_tag(kOtherFolderButtonTag); | |
1635 return button; | 1615 return button; |
1636 } | 1616 } |
1637 | 1617 |
1638 MenuButton* BookmarkBarView::CreateManagedBookmarksButton() { | 1618 MenuButton* BookmarkBarView::CreateManagedBookmarksButton() { |
1639 // Title is set in Loaded. | 1619 // Title is set in Loaded. |
1640 MenuButton* button = | 1620 MenuButton* button = new BookmarkFolderButton(base::string16(), this, false); |
1641 new BookmarkFolderButton(this, base::string16(), this, false); | |
1642 button->set_id(VIEW_ID_MANAGED_BOOKMARKS); | 1621 button->set_id(VIEW_ID_MANAGED_BOOKMARKS); |
1643 button->set_context_menu_controller(this); | 1622 button->set_context_menu_controller(this); |
1644 button->set_tag(kManagedFolderButtonTag); | |
1645 return button; | 1623 return button; |
1646 } | 1624 } |
1647 | 1625 |
1648 MenuButton* BookmarkBarView::CreateSupervisedBookmarksButton() { | 1626 MenuButton* BookmarkBarView::CreateSupervisedBookmarksButton() { |
1649 // Title is set in Loaded. | 1627 // Title is set in Loaded. |
1650 MenuButton* button = | 1628 MenuButton* button = new BookmarkFolderButton(base::string16(), this, false); |
1651 new BookmarkFolderButton(this, base::string16(), this, false); | |
1652 button->set_id(VIEW_ID_SUPERVISED_BOOKMARKS); | 1629 button->set_id(VIEW_ID_SUPERVISED_BOOKMARKS); |
1653 button->set_context_menu_controller(this); | 1630 button->set_context_menu_controller(this); |
1654 button->set_tag(kSupervisedFolderButtonTag); | |
1655 return button; | 1631 return button; |
1656 } | 1632 } |
1657 | 1633 |
1658 MenuButton* BookmarkBarView::CreateOverflowButton() { | 1634 MenuButton* BookmarkBarView::CreateOverflowButton() { |
1659 MenuButton* button = new OverflowButton(this); | 1635 MenuButton* button = new OverflowButton(this); |
1660 | 1636 |
1661 // The overflow button's image contains an arrow and therefore it is a | 1637 // The overflow button's image contains an arrow and therefore it is a |
1662 // direction sensitive image and we need to flip it if the UI layout is | 1638 // direction sensitive image and we need to flip it if the UI layout is |
1663 // right-to-left. | 1639 // right-to-left. |
1664 // | 1640 // |
(...skipping 11 matching lines...) Expand all Loading... |
1676 } | 1652 } |
1677 | 1653 |
1678 views::View* BookmarkBarView::CreateBookmarkButton(const BookmarkNode* node) { | 1654 views::View* BookmarkBarView::CreateBookmarkButton(const BookmarkNode* node) { |
1679 if (node->is_url()) { | 1655 if (node->is_url()) { |
1680 BookmarkButton* button = new BookmarkButton( | 1656 BookmarkButton* button = new BookmarkButton( |
1681 this, node->url(), node->GetTitle(), browser_->profile()); | 1657 this, node->url(), node->GetTitle(), browser_->profile()); |
1682 ConfigureButton(node, button); | 1658 ConfigureButton(node, button); |
1683 return button; | 1659 return button; |
1684 } | 1660 } |
1685 views::MenuButton* button = | 1661 views::MenuButton* button = |
1686 new BookmarkFolderButton(this, node->GetTitle(), this, false); | 1662 new BookmarkFolderButton(node->GetTitle(), this, false); |
1687 ConfigureButton(node, button); | 1663 ConfigureButton(node, button); |
1688 return button; | 1664 return button; |
1689 } | 1665 } |
1690 | 1666 |
1691 views::LabelButton* BookmarkBarView::CreateAppsPageShortcutButton() { | 1667 views::LabelButton* BookmarkBarView::CreateAppsPageShortcutButton() { |
1692 views::LabelButton* button = new ShortcutButton( | 1668 views::LabelButton* button = new ShortcutButton( |
1693 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_APPS_SHORTCUT_NAME)); | 1669 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_APPS_SHORTCUT_NAME)); |
1694 button->SetTooltipText(l10n_util::GetStringUTF16( | 1670 button->SetTooltipText(l10n_util::GetStringUTF16( |
1695 IDS_BOOKMARK_BAR_APPS_SHORTCUT_TOOLTIP)); | 1671 IDS_BOOKMARK_BAR_APPS_SHORTCUT_TOOLTIP)); |
1696 button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT); | 1672 button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT); |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2090 return; | 2066 return; |
2091 apps_page_shortcut_->SetVisible(visible); | 2067 apps_page_shortcut_->SetVisible(visible); |
2092 UpdateBookmarksSeparatorVisibility(); | 2068 UpdateBookmarksSeparatorVisibility(); |
2093 LayoutAndPaint(); | 2069 LayoutAndPaint(); |
2094 } | 2070 } |
2095 | 2071 |
2096 void BookmarkBarView::OnShowManagedBookmarksPrefChanged() { | 2072 void BookmarkBarView::OnShowManagedBookmarksPrefChanged() { |
2097 if (UpdateOtherAndManagedButtonsVisibility()) | 2073 if (UpdateOtherAndManagedButtonsVisibility()) |
2098 LayoutAndPaint(); | 2074 LayoutAndPaint(); |
2099 } | 2075 } |
OLD | NEW |