Chromium Code Reviews| 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 <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 #include "chrome/browser/extensions/extension_service.h" | 23 #include "chrome/browser/extensions/extension_service.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/sync/profile_sync_service.h" | 25 #include "chrome/browser/sync/profile_sync_service.h" |
| 26 #include "chrome/browser/sync/profile_sync_service_factory.h" | 26 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 27 #include "chrome/browser/themes/theme_properties.h" | 27 #include "chrome/browser/themes/theme_properties.h" |
| 28 #include "chrome/browser/ui/bookmarks/bookmark_bar_constants.h" | 28 #include "chrome/browser/ui/bookmarks/bookmark_bar_constants.h" |
| 29 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" | 29 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" |
| 30 #include "chrome/browser/ui/bookmarks/bookmark_utils.h" | 30 #include "chrome/browser/ui/bookmarks/bookmark_utils.h" |
| 31 #include "chrome/browser/ui/browser.h" | 31 #include "chrome/browser/ui/browser.h" |
| 32 #include "chrome/browser/ui/chrome_pages.h" | 32 #include "chrome/browser/ui/chrome_pages.h" |
| 33 #include "chrome/browser/ui/search/search.h" | |
| 33 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 34 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 34 #include "chrome/browser/ui/view_ids.h" | 35 #include "chrome/browser/ui/view_ids.h" |
| 35 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_instructions_view.h" | 36 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_instructions_view.h" |
| 36 #include "chrome/browser/ui/views/bookmarks/bookmark_context_menu.h" | 37 #include "chrome/browser/ui/views/bookmarks/bookmark_context_menu.h" |
| 37 #include "chrome/browser/ui/views/event_utils.h" | 38 #include "chrome/browser/ui/views/event_utils.h" |
| 38 #include "chrome/browser/ui/views/frame/browser_view.h" | 39 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 39 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 40 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 40 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" | 41 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" |
| 41 #include "chrome/common/chrome_notification_types.h" | 42 #include "chrome/common/chrome_notification_types.h" |
| 42 #include "chrome/common/chrome_switches.h" | 43 #include "chrome/common/chrome_switches.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 | 127 |
| 127 // Starting x-coordinate of the separator line within a separator. | 128 // Starting x-coordinate of the separator line within a separator. |
| 128 static const int kSeparatorStartX = 2; | 129 static const int kSeparatorStartX = 2; |
| 129 | 130 |
| 130 // Left-padding for the instructional text. | 131 // Left-padding for the instructional text. |
| 131 static const int kInstructionsPadding = 6; | 132 static const int kInstructionsPadding = 6; |
| 132 | 133 |
| 133 // Tag for the 'Other bookmarks' button. | 134 // Tag for the 'Other bookmarks' button. |
| 134 static const int kOtherFolderButtonTag = 1; | 135 static const int kOtherFolderButtonTag = 1; |
| 135 | 136 |
| 137 // Tag for the 'Apps Shortcut' button. | |
| 138 static const int kAppsShortcutButtonTag = 2; | |
| 139 | |
| 136 namespace { | 140 namespace { |
| 137 | 141 |
| 142 // BookmarkButtonBase --------------------------------------------------------- | |
| 143 | |
| 144 // Base class for text buttons used on the bookmark bar. | |
| 145 | |
| 146 class BookmarkButtonBase : public views::TextButton { | |
| 147 public: | |
| 148 BookmarkButtonBase(views::ButtonListener* listener, | |
| 149 const string16& title) | |
| 150 : TextButton(listener, title) { | |
| 151 show_animation_.reset(new ui::SlideAnimation(this)); | |
| 152 if (bookmark_utils::IsBookmarkBarViewAnimationsDisabled()) { | |
| 153 // For some reason during testing the events generated by animating | |
| 154 // throw off the test. So, don't animate while testing. | |
| 155 show_animation_->Reset(1); | |
| 156 } else { | |
| 157 show_animation_->Show(); | |
| 158 } | |
| 159 } | |
| 160 | |
| 161 virtual bool IsTriggerableEvent(const ui::Event& e) OVERRIDE { | |
| 162 return e.type() == ui::ET_GESTURE_TAP || | |
| 163 e.type() == ui::ET_GESTURE_TAP_DOWN || | |
| 164 event_utils::IsPossibleDispositionEvent(e); | |
| 165 } | |
| 166 | |
| 167 private: | |
| 168 scoped_ptr<ui::SlideAnimation> show_animation_; | |
| 169 | |
| 170 DISALLOW_COPY_AND_ASSIGN(BookmarkButtonBase); | |
| 171 }; | |
| 172 | |
| 138 // BookmarkButton ------------------------------------------------------------- | 173 // BookmarkButton ------------------------------------------------------------- |
| 139 | 174 |
| 140 // Buttons used for the bookmarks on the bookmark bar. | 175 // Buttons used for the bookmarks on the bookmark bar. |
| 141 | 176 |
| 142 class BookmarkButton : public views::TextButton { | 177 class BookmarkButton : public BookmarkButtonBase { |
| 143 public: | 178 public: |
| 144 // The internal view class name. | 179 // The internal view class name. |
| 145 static const char kViewClassName[]; | 180 static const char kViewClassName[]; |
| 146 | 181 |
| 147 BookmarkButton(views::ButtonListener* listener, | 182 BookmarkButton(views::ButtonListener* listener, |
| 148 const GURL& url, | 183 const GURL& url, |
| 149 const string16& title, | 184 const string16& title, |
| 150 Profile* profile) | 185 Profile* profile) |
| 151 : TextButton(listener, title), | 186 : BookmarkButtonBase(listener, title), |
| 152 url_(url), | 187 url_(url), |
| 153 profile_(profile) { | 188 profile_(profile) { |
| 154 show_animation_.reset(new ui::SlideAnimation(this)); | |
| 155 if (bookmark_utils::IsBookmarkBarViewAnimationsDisabled()) { | |
| 156 // For some reason during testing the events generated by animating | |
| 157 // throw off the test. So, don't animate while testing. | |
| 158 show_animation_->Reset(1); | |
| 159 } else { | |
| 160 show_animation_->Show(); | |
| 161 } | |
| 162 } | 189 } |
| 163 | 190 |
| 164 virtual bool GetTooltipText(const gfx::Point& p, | 191 virtual bool GetTooltipText(const gfx::Point& p, |
| 165 string16* tooltip) const OVERRIDE { | 192 string16* tooltip) const OVERRIDE { |
| 166 gfx::Point location(p); | 193 gfx::Point location(p); |
| 167 ConvertPointToScreen(this, &location); | 194 ConvertPointToScreen(this, &location); |
| 168 *tooltip = BookmarkBarView::CreateToolTipForURLAndTitle( | 195 *tooltip = BookmarkBarView::CreateToolTipForURLAndTitle( |
| 169 location, url_, text(), profile_, GetWidget()->GetNativeView()); | 196 location, url_, text(), profile_, GetWidget()->GetNativeView()); |
| 170 return !tooltip->empty(); | 197 return !tooltip->empty(); |
| 171 } | 198 } |
| 172 | 199 |
| 173 virtual bool IsTriggerableEvent(const ui::Event& e) OVERRIDE { | |
| 174 return e.type() == ui::ET_GESTURE_TAP || | |
| 175 e.type() == ui::ET_GESTURE_TAP_DOWN || | |
| 176 event_utils::IsPossibleDispositionEvent(e); | |
| 177 } | |
| 178 | |
| 179 virtual std::string GetClassName() const OVERRIDE { | 200 virtual std::string GetClassName() const OVERRIDE { |
| 180 return kViewClassName; | 201 return kViewClassName; |
| 181 } | 202 } |
| 182 | 203 |
| 183 private: | 204 private: |
| 184 const GURL& url_; | 205 const GURL& url_; |
| 185 Profile* profile_; | 206 Profile* profile_; |
| 186 scoped_ptr<ui::SlideAnimation> show_animation_; | |
| 187 | 207 |
| 188 DISALLOW_COPY_AND_ASSIGN(BookmarkButton); | 208 DISALLOW_COPY_AND_ASSIGN(BookmarkButton); |
| 189 }; | 209 }; |
| 190 | 210 |
| 191 // static for BookmarkButton | 211 // static for BookmarkButton |
| 192 const char BookmarkButton::kViewClassName[] = | 212 const char BookmarkButton::kViewClassName[] = |
| 193 "browser/ui/views/bookmarks/BookmarkButton"; | 213 "browser/ui/views/bookmarks/BookmarkButton"; |
| 194 | 214 |
| 215 // ShortcutButton ------------------------------------------------------------- | |
| 216 | |
| 217 // Buttons used for the shortcuts on the bookmark bar. | |
| 218 | |
| 219 class ShortcutButton : public BookmarkButtonBase { | |
| 220 public: | |
| 221 // The internal view class name. | |
| 222 static const char kViewClassName[]; | |
| 223 | |
| 224 ShortcutButton(views::ButtonListener* listener, | |
| 225 const string16& title) | |
| 226 : BookmarkButtonBase(listener, title) { | |
| 227 } | |
| 228 | |
| 229 virtual std::string GetClassName() const OVERRIDE { | |
| 230 return kViewClassName; | |
| 231 } | |
| 232 | |
| 233 private: | |
| 234 scoped_ptr<ui::SlideAnimation> show_animation_; | |
| 235 | |
| 236 DISALLOW_COPY_AND_ASSIGN(ShortcutButton); | |
| 237 }; | |
| 238 | |
| 239 // static for ShortcutButton | |
| 240 const char ShortcutButton::kViewClassName[] = | |
| 241 "browser/ui/views/bookmarks/ShortcutButton"; | |
| 242 | |
| 195 // BookmarkFolderButton ------------------------------------------------------- | 243 // BookmarkFolderButton ------------------------------------------------------- |
| 196 | 244 |
| 197 // Buttons used for folders on the bookmark bar, including the 'other folders' | 245 // Buttons used for folders on the bookmark bar, including the 'other folders' |
| 198 // button. | 246 // button. |
| 199 class BookmarkFolderButton : public views::MenuButton { | 247 class BookmarkFolderButton : public views::MenuButton { |
| 200 public: | 248 public: |
| 201 BookmarkFolderButton(views::ButtonListener* listener, | 249 BookmarkFolderButton(views::ButtonListener* listener, |
| 202 const string16& title, | 250 const string16& title, |
| 203 views::MenuButtonListener* menu_button_listener, | 251 views::MenuButtonListener* menu_button_listener, |
| 204 bool show_menu_marker) | 252 bool show_menu_marker) |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 375 } | 423 } |
| 376 return *kFolderIcon; | 424 return *kFolderIcon; |
| 377 } | 425 } |
| 378 | 426 |
| 379 BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view) | 427 BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view) |
| 380 : page_navigator_(NULL), | 428 : page_navigator_(NULL), |
| 381 model_(NULL), | 429 model_(NULL), |
| 382 bookmark_menu_(NULL), | 430 bookmark_menu_(NULL), |
| 383 bookmark_drop_menu_(NULL), | 431 bookmark_drop_menu_(NULL), |
| 384 other_bookmarked_button_(NULL), | 432 other_bookmarked_button_(NULL), |
| 433 apps_page_shortcut_(NULL), | |
| 385 ALLOW_THIS_IN_INITIALIZER_LIST(show_folder_method_factory_(this)), | 434 ALLOW_THIS_IN_INITIALIZER_LIST(show_folder_method_factory_(this)), |
| 386 overflow_button_(NULL), | 435 overflow_button_(NULL), |
| 387 instructions_(NULL), | 436 instructions_(NULL), |
| 388 bookmarks_separator_view_(NULL), | 437 bookmarks_separator_view_(NULL), |
| 389 browser_(browser), | 438 browser_(browser), |
| 390 browser_view_(browser_view), | 439 browser_view_(browser_view), |
| 391 infobar_visible_(false), | 440 infobar_visible_(false), |
| 392 throbbing_view_(NULL), | 441 throbbing_view_(NULL), |
| 393 bookmark_bar_state_(BookmarkBar::SHOW), | 442 bookmark_bar_state_(BookmarkBar::SHOW), |
| 394 animating_detached_(false) { | 443 animating_detached_(false) { |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 600 if (bookmark_bar_state_ == BookmarkBar::DETACHED) { | 649 if (bookmark_bar_state_ == BookmarkBar::DETACHED) { |
| 601 double current_state = 1 - size_animation_->GetCurrentValue(); | 650 double current_state = 1 - size_animation_->GetCurrentValue(); |
| 602 width += 2 * static_cast<int>(kNewtabHorizontalPadding * current_state); | 651 width += 2 * static_cast<int>(kNewtabHorizontalPadding * current_state); |
| 603 } | 652 } |
| 604 | 653 |
| 605 gfx::Size other_bookmarked_pref = | 654 gfx::Size other_bookmarked_pref = |
| 606 other_bookmarked_button_->GetPreferredSize(); | 655 other_bookmarked_button_->GetPreferredSize(); |
| 607 gfx::Size overflow_pref = overflow_button_->GetPreferredSize(); | 656 gfx::Size overflow_pref = overflow_button_->GetPreferredSize(); |
| 608 gfx::Size bookmarks_separator_pref = | 657 gfx::Size bookmarks_separator_pref = |
| 609 bookmarks_separator_view_->GetPreferredSize(); | 658 bookmarks_separator_view_->GetPreferredSize(); |
| 659 gfx::Size apps_page_shortcut_pref = | |
| 660 apps_page_shortcut_->GetPreferredSize(); | |
|
sky
2013/02/26 23:56:10
Shouldn't you check visibility here?
MAD
2013/02/27 00:55:43
Then should I also check the visibility of the oth
| |
| 610 | 661 |
| 611 width += other_bookmarked_pref.width() + kButtonPadding + | 662 width += other_bookmarked_pref.width() + kButtonPadding + |
| 663 apps_page_shortcut_pref.width() + kButtonPadding + | |
| 612 overflow_pref.width() + kButtonPadding + | 664 overflow_pref.width() + kButtonPadding + |
| 613 bookmarks_separator_pref.width(); | 665 bookmarks_separator_pref.width(); |
| 614 | 666 |
| 615 return gfx::Size(width, browser_defaults::kBookmarkBarHeight); | 667 return gfx::Size(width, browser_defaults::kBookmarkBarHeight); |
| 616 } | 668 } |
| 617 | 669 |
| 618 void BookmarkBarView::Layout() { | 670 void BookmarkBarView::Layout() { |
| 619 LayoutItems(false); | 671 LayoutItems(false); |
| 620 } | 672 } |
| 621 | 673 |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1022 } | 1074 } |
| 1023 } | 1075 } |
| 1024 return true; | 1076 return true; |
| 1025 } | 1077 } |
| 1026 | 1078 |
| 1027 void BookmarkBarView::OnMenuButtonClicked(views::View* view, | 1079 void BookmarkBarView::OnMenuButtonClicked(views::View* view, |
| 1028 const gfx::Point& point) { | 1080 const gfx::Point& point) { |
| 1029 const BookmarkNode* node; | 1081 const BookmarkNode* node; |
| 1030 | 1082 |
| 1031 int start_index = 0; | 1083 int start_index = 0; |
| 1032 if (view == other_bookmarked_button_) { | 1084 if (view == other_bookmarked_button_ || view == apps_page_shortcut_) { |
|
sky
2013/02/26 23:56:10
Why does the app shortcut button show the contents
MAD
2013/02/27 00:55:43
D'Ho!ne.
| |
| 1085 // We want the same menu for both, so use the other node since the app | |
| 1086 // shortcut doesn't have a node. | |
| 1033 node = model_->other_node(); | 1087 node = model_->other_node(); |
| 1034 } else if (view == overflow_button_) { | 1088 } else if (view == overflow_button_) { |
| 1035 node = model_->bookmark_bar_node(); | 1089 node = model_->bookmark_bar_node(); |
| 1036 start_index = GetFirstHiddenNodeIndex(); | 1090 start_index = GetFirstHiddenNodeIndex(); |
| 1037 } else { | 1091 } else { |
| 1038 int button_index = GetIndexOf(view); | 1092 int button_index = GetIndexOf(view); |
| 1039 DCHECK_NE(-1, button_index); | 1093 DCHECK_NE(-1, button_index); |
| 1040 node = model_->bookmark_bar_node()->GetChild(button_index); | 1094 node = model_->bookmark_bar_node()->GetChild(button_index); |
| 1041 } | 1095 } |
| 1042 | 1096 |
| 1043 bookmark_menu_ = new BookmarkMenuController(browser_, | 1097 bookmark_menu_ = new BookmarkMenuController(browser_, |
| 1044 page_navigator_, GetWidget(), node, start_index); | 1098 page_navigator_, GetWidget(), node, start_index); |
| 1045 bookmark_menu_->set_observer(this); | 1099 bookmark_menu_->set_observer(this); |
| 1046 bookmark_menu_->RunMenuAt(this, false); | 1100 bookmark_menu_->RunMenuAt(this, false); |
| 1047 } | 1101 } |
| 1048 | 1102 |
| 1049 void BookmarkBarView::ButtonPressed(views::Button* sender, | 1103 void BookmarkBarView::ButtonPressed(views::Button* sender, |
| 1050 const ui::Event& event) { | 1104 const ui::Event& event) { |
| 1105 if (sender->tag() == kAppsShortcutButtonTag) { | |
| 1106 chrome::ShowAppLauncherPage(browser_); | |
| 1107 content::RecordAction( | |
| 1108 UserMetricsAction("ClickedBookmarkBarAppsShortcutButton")); | |
| 1109 return; | |
| 1110 } | |
| 1111 | |
| 1051 const BookmarkNode* node; | 1112 const BookmarkNode* node; |
| 1052 if (sender->tag() == kOtherFolderButtonTag) { | 1113 if (sender->tag() == kOtherFolderButtonTag) { |
| 1053 node = model_->other_node(); | 1114 node = model_->other_node(); |
| 1054 } else { | 1115 } else { |
| 1055 int index = GetIndexOf(sender); | 1116 int index = GetIndexOf(sender); |
| 1056 DCHECK_NE(-1, index); | 1117 DCHECK_NE(-1, index); |
| 1057 node = model_->bookmark_bar_node()->GetChild(index); | 1118 node = model_->bookmark_bar_node()->GetChild(index); |
| 1058 } | 1119 } |
| 1059 DCHECK(page_navigator_); | 1120 DCHECK(page_navigator_); |
| 1060 | 1121 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 1083 if (!model_->IsLoaded()) { | 1144 if (!model_->IsLoaded()) { |
| 1084 // Don't do anything if the model isn't loaded. | 1145 // Don't do anything if the model isn't loaded. |
| 1085 return; | 1146 return; |
| 1086 } | 1147 } |
| 1087 | 1148 |
| 1088 const BookmarkNode* parent = NULL; | 1149 const BookmarkNode* parent = NULL; |
| 1089 std::vector<const BookmarkNode*> nodes; | 1150 std::vector<const BookmarkNode*> nodes; |
| 1090 if (source == other_bookmarked_button_) { | 1151 if (source == other_bookmarked_button_) { |
| 1091 parent = model_->other_node(); | 1152 parent = model_->other_node(); |
| 1092 // Do this so the user can open all bookmarks. BookmarkContextMenu makes | 1153 // Do this so the user can open all bookmarks. BookmarkContextMenu makes |
| 1093 // sure the user can edit/delete the node in this case. | 1154 // sure the user can't edit/delete the node in this case. |
| 1094 nodes.push_back(parent); | 1155 nodes.push_back(parent); |
| 1095 } else if (source != this) { | 1156 } else if (source != this && source != apps_page_shortcut_) { |
| 1096 // User clicked on one of the bookmark buttons, find which one they | 1157 // User clicked on one of the bookmark buttons, find which one they |
| 1097 // clicked on. | 1158 // clicked on, except for the apps page shortcut, which must behave as if |
| 1159 // the user clicked on the bookmark bar background. | |
| 1098 int bookmark_button_index = GetIndexOf(source); | 1160 int bookmark_button_index = GetIndexOf(source); |
| 1099 DCHECK(bookmark_button_index != -1 && | 1161 DCHECK(bookmark_button_index != -1 && |
| 1100 bookmark_button_index < GetBookmarkButtonCount()); | 1162 bookmark_button_index < GetBookmarkButtonCount()); |
| 1101 const BookmarkNode* node = | 1163 const BookmarkNode* node = |
| 1102 model_->bookmark_bar_node()->GetChild(bookmark_button_index); | 1164 model_->bookmark_bar_node()->GetChild(bookmark_button_index); |
| 1103 nodes.push_back(node); | 1165 nodes.push_back(node); |
| 1104 parent = node->parent(); | 1166 parent = node->parent(); |
| 1105 } else { | 1167 } else { |
| 1106 parent = model_->bookmark_bar_node(); | 1168 parent = model_->bookmark_bar_node(); |
| 1107 nodes.push_back(parent); | 1169 nodes.push_back(parent); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 1131 // Child views are traversed in the order they are added. Make sure the order | 1193 // Child views are traversed in the order they are added. Make sure the order |
| 1132 // they are added matches the visual order. | 1194 // they are added matches the visual order. |
| 1133 overflow_button_ = CreateOverflowButton(); | 1195 overflow_button_ = CreateOverflowButton(); |
| 1134 AddChildView(overflow_button_); | 1196 AddChildView(overflow_button_); |
| 1135 | 1197 |
| 1136 other_bookmarked_button_ = CreateOtherBookmarkedButton(); | 1198 other_bookmarked_button_ = CreateOtherBookmarkedButton(); |
| 1137 // We'll re-enable when the model is loaded. | 1199 // We'll re-enable when the model is loaded. |
| 1138 other_bookmarked_button_->SetEnabled(false); | 1200 other_bookmarked_button_->SetEnabled(false); |
| 1139 AddChildView(other_bookmarked_button_); | 1201 AddChildView(other_bookmarked_button_); |
| 1140 | 1202 |
| 1203 apps_page_shortcut_ = CreateAppsPageShortcutButton(); | |
| 1204 AddChildView(apps_page_shortcut_); | |
| 1205 profile_pref_registrar_.Init(browser_->profile()->GetPrefs()); | |
| 1206 profile_pref_registrar_.Add( | |
| 1207 prefs::kShowAppsShortcutInBookmarkBar, | |
| 1208 base::Bind(&BookmarkBarView::OnAppsPageShortcutVisibilityChanged, | |
| 1209 base::Unretained(this))); | |
| 1210 apps_page_shortcut_->SetVisible(ShouldShowAppsShortcut()); | |
| 1211 | |
| 1141 bookmarks_separator_view_ = new ButtonSeparatorView(); | 1212 bookmarks_separator_view_ = new ButtonSeparatorView(); |
| 1142 AddChildView(bookmarks_separator_view_); | 1213 AddChildView(bookmarks_separator_view_); |
| 1143 #if defined(USE_ASH) | 1214 #if defined(USE_ASH) |
| 1144 // Ash does not paint the bookmarks separator line because it looks odd on | 1215 // Ash does not paint the bookmarks separator line because it looks odd on |
| 1145 // the flat background. We keep it present for layout, but don't draw it. | 1216 // the flat background. We keep it present for layout, but don't draw it. |
| 1146 bookmarks_separator_view_->SetVisible(false); | 1217 bookmarks_separator_view_->SetVisible(false); |
| 1147 #endif | 1218 #endif |
| 1148 | 1219 |
| 1149 instructions_ = new BookmarkBarInstructionsView(this); | 1220 instructions_ = new BookmarkBarInstructionsView(this); |
| 1150 AddChildView(instructions_); | 1221 AddChildView(instructions_); |
| 1151 | 1222 |
| 1152 set_context_menu_controller(this); | 1223 set_context_menu_controller(this); |
| 1153 | 1224 |
| 1154 size_animation_.reset(new ui::SlideAnimation(this)); | 1225 size_animation_.reset(new ui::SlideAnimation(this)); |
| 1155 | 1226 |
| 1156 model_ = BookmarkModelFactory::GetForProfile(browser_->profile()); | 1227 model_ = BookmarkModelFactory::GetForProfile(browser_->profile()); |
| 1157 if (model_) { | 1228 if (model_) { |
| 1158 model_->AddObserver(this); | 1229 model_->AddObserver(this); |
| 1159 if (model_->IsLoaded()) | 1230 if (model_->IsLoaded()) |
| 1160 Loaded(model_, false); | 1231 Loaded(model_, false); |
| 1161 // else case: we'll receive notification back from the BookmarkModel when | 1232 // else case: we'll receive notification back from the BookmarkModel when |
| 1162 // done loading, then we'll populate the bar. | 1233 // done loading, then we'll populate the bar. |
| 1163 } | 1234 } |
| 1164 } | 1235 } |
| 1165 | 1236 |
| 1166 int BookmarkBarView::GetBookmarkButtonCount() { | 1237 int BookmarkBarView::GetBookmarkButtonCount() { |
| 1167 // We contain four non-bookmark button views: other bookmarks, bookmarks | 1238 // We contain four non-bookmark button views: other bookmarks, bookmarks |
| 1168 // separator, chevrons (for overflow), and the instruction label. | 1239 // separator, chevrons (for overflow), apps page, and the instruction label. |
| 1169 return child_count() - 4; | 1240 return child_count() - 5; |
| 1170 } | 1241 } |
| 1171 | 1242 |
| 1172 views::TextButton* BookmarkBarView::GetBookmarkButton(int index) { | 1243 views::TextButton* BookmarkBarView::GetBookmarkButton(int index) { |
| 1173 DCHECK(index >= 0 && index < GetBookmarkButtonCount()); | 1244 DCHECK(index >= 0 && index < GetBookmarkButtonCount()); |
| 1174 return static_cast<views::TextButton*>(child_at(index)); | 1245 return static_cast<views::TextButton*>(child_at(index)); |
| 1175 } | 1246 } |
| 1176 | 1247 |
| 1177 int BookmarkBarView::GetFirstHiddenNodeIndex() { | 1248 int BookmarkBarView::GetFirstHiddenNodeIndex() { |
| 1178 const int bb_count = GetBookmarkButtonCount(); | 1249 const int bb_count = GetBookmarkButtonCount(); |
| 1179 for (int i = 0; i < bb_count; ++i) { | 1250 for (int i = 0; i < bb_count; ++i) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1223 return button; | 1294 return button; |
| 1224 } else { | 1295 } else { |
| 1225 views::MenuButton* button = new BookmarkFolderButton( | 1296 views::MenuButton* button = new BookmarkFolderButton( |
| 1226 this, node->GetTitle(), this, false); | 1297 this, node->GetTitle(), this, false); |
| 1227 button->SetIcon(GetFolderIcon()); | 1298 button->SetIcon(GetFolderIcon()); |
| 1228 ConfigureButton(node, button); | 1299 ConfigureButton(node, button); |
| 1229 return button; | 1300 return button; |
| 1230 } | 1301 } |
| 1231 } | 1302 } |
| 1232 | 1303 |
| 1304 views::TextButton* BookmarkBarView::CreateAppsPageShortcutButton() { | |
| 1305 views::TextButton* button = new ShortcutButton( | |
| 1306 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_APPS_SHORTCUT_NAME)); | |
| 1307 button->SetTooltipText(l10n_util::GetStringUTF16( | |
| 1308 IDS_BOOKMARK_BAR_APPS_SHORTCUT_TOOLTIP)); | |
| 1309 button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT); | |
| 1310 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 1311 button->SetIcon(*rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_16)); | |
| 1312 button->set_context_menu_controller(this); | |
| 1313 button->set_tag(kAppsShortcutButtonTag); | |
| 1314 button->SetEnabled(true); | |
| 1315 return button; | |
| 1316 } | |
| 1317 | |
| 1233 void BookmarkBarView::ConfigureButton(const BookmarkNode* node, | 1318 void BookmarkBarView::ConfigureButton(const BookmarkNode* node, |
| 1234 views::TextButton* button) { | 1319 views::TextButton* button) { |
| 1235 button->SetText(node->GetTitle()); | 1320 button->SetText(node->GetTitle()); |
| 1236 button->SetAccessibleName(node->GetTitle()); | 1321 button->SetAccessibleName(node->GetTitle()); |
| 1237 button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT); | 1322 button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT); |
| 1238 // We don't always have a theme provider (ui tests, for example). | 1323 // We don't always have a theme provider (ui tests, for example). |
| 1239 if (GetThemeProvider()) { | 1324 if (GetThemeProvider()) { |
| 1240 button->SetEnabledColor(GetThemeProvider()->GetColor( | 1325 button->SetEnabledColor(GetThemeProvider()->GetColor( |
| 1241 ThemeProperties::COLOR_BOOKMARK_TEXT)); | 1326 ThemeProperties::COLOR_BOOKMARK_TEXT)); |
| 1242 } | 1327 } |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1533 if (!theme_provider) | 1618 if (!theme_provider) |
| 1534 return; | 1619 return; |
| 1535 SkColor text_color = | 1620 SkColor text_color = |
| 1536 theme_provider->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT); | 1621 theme_provider->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT); |
| 1537 for (int i = 0; i < GetBookmarkButtonCount(); ++i) | 1622 for (int i = 0; i < GetBookmarkButtonCount(); ++i) |
| 1538 GetBookmarkButton(i)->SetEnabledColor(text_color); | 1623 GetBookmarkButton(i)->SetEnabledColor(text_color); |
| 1539 other_bookmarked_button()->SetEnabledColor(text_color); | 1624 other_bookmarked_button()->SetEnabledColor(text_color); |
| 1540 } | 1625 } |
| 1541 | 1626 |
| 1542 void BookmarkBarView::UpdateOtherBookmarksVisibility() { | 1627 void BookmarkBarView::UpdateOtherBookmarksVisibility() { |
| 1543 bool has_other_children = !model_->other_node()->empty(); | 1628 bool has_other_children = !model_->other_node()->empty(); |
|
sky
2013/02/26 23:56:10
Don't you need to update this too?
MAD
2013/02/27 00:55:43
Why? This is for the visibility of the other bookm
| |
| 1544 if (has_other_children == other_bookmarked_button_->visible()) | 1629 if (has_other_children == other_bookmarked_button_->visible()) |
| 1545 return; | 1630 return; |
| 1546 other_bookmarked_button_->SetVisible(has_other_children); | 1631 other_bookmarked_button_->SetVisible(has_other_children); |
| 1547 #if !defined(USE_ASH) | 1632 #if !defined(USE_ASH) |
| 1548 bookmarks_separator_view_->SetVisible(has_other_children); | 1633 bookmarks_separator_view_->SetVisible(has_other_children); |
| 1549 #endif | 1634 #endif |
| 1550 Layout(); | 1635 Layout(); |
| 1551 SchedulePaint(); | 1636 SchedulePaint(); |
| 1552 } | 1637 } |
| 1553 | 1638 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 1577 // also matches how we layout infobars. | 1662 // also matches how we layout infobars. |
| 1578 y += View::height() - browser_defaults::kBookmarkBarHeight; | 1663 y += View::height() - browser_defaults::kBookmarkBarHeight; |
| 1579 height += browser_defaults::kBookmarkBarHeight; | 1664 height += browser_defaults::kBookmarkBarHeight; |
| 1580 } | 1665 } |
| 1581 | 1666 |
| 1582 gfx::Size other_bookmarked_pref = other_bookmarked_button_->visible() ? | 1667 gfx::Size other_bookmarked_pref = other_bookmarked_button_->visible() ? |
| 1583 other_bookmarked_button_->GetPreferredSize() : gfx::Size(); | 1668 other_bookmarked_button_->GetPreferredSize() : gfx::Size(); |
| 1584 gfx::Size overflow_pref = overflow_button_->GetPreferredSize(); | 1669 gfx::Size overflow_pref = overflow_button_->GetPreferredSize(); |
| 1585 gfx::Size bookmarks_separator_pref = | 1670 gfx::Size bookmarks_separator_pref = |
| 1586 bookmarks_separator_view_->GetPreferredSize(); | 1671 bookmarks_separator_view_->GetPreferredSize(); |
| 1672 gfx::Size apps_page_shortcut_pref = apps_page_shortcut_->visible() ? | |
| 1673 apps_page_shortcut_->GetPreferredSize() : gfx::Size(); | |
| 1587 | 1674 |
| 1588 int max_x = width - overflow_pref.width() - kButtonPadding - | 1675 int max_x = width - overflow_pref.width() - kButtonPadding - |
| 1589 bookmarks_separator_pref.width(); | 1676 bookmarks_separator_pref.width(); |
| 1590 if (other_bookmarked_button_->visible()) | 1677 if (other_bookmarked_button_->visible()) |
| 1591 max_x -= other_bookmarked_pref.width() + kButtonPadding; | 1678 max_x -= other_bookmarked_pref.width() + kButtonPadding; |
| 1679 if (apps_page_shortcut_->visible()) | |
| 1680 max_x -= apps_page_shortcut_pref.width() + kButtonPadding; | |
| 1592 | 1681 |
| 1593 // Next, layout out the buttons. Any buttons that are placed beyond the | 1682 // Next, layout out the buttons. Any buttons that are placed beyond the |
| 1594 // visible region and made invisible. | 1683 // visible region and made invisible. |
| 1595 if (GetBookmarkButtonCount() == 0 && model_ && model_->IsLoaded()) { | 1684 if (GetBookmarkButtonCount() == 0 && model_ && model_->IsLoaded()) { |
| 1596 gfx::Size pref = instructions_->GetPreferredSize(); | 1685 gfx::Size pref = instructions_->GetPreferredSize(); |
| 1597 if (!compute_bounds_only) { | 1686 if (!compute_bounds_only) { |
| 1598 instructions_->SetBounds( | 1687 instructions_->SetBounds( |
| 1599 x + kInstructionsPadding, y, | 1688 x + kInstructionsPadding, y, |
| 1600 std::min(static_cast<int>(pref.width()), | 1689 std::min(static_cast<int>(pref.width()), |
| 1601 max_x - x), | 1690 max_x - x), |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1650 | 1739 |
| 1651 // The other bookmarks button. | 1740 // The other bookmarks button. |
| 1652 if (other_bookmarked_button_->visible()) { | 1741 if (other_bookmarked_button_->visible()) { |
| 1653 if (!compute_bounds_only) { | 1742 if (!compute_bounds_only) { |
| 1654 other_bookmarked_button_->SetBounds(x, y, other_bookmarked_pref.width(), | 1743 other_bookmarked_button_->SetBounds(x, y, other_bookmarked_pref.width(), |
| 1655 height); | 1744 height); |
| 1656 } | 1745 } |
| 1657 x += other_bookmarked_pref.width() + kButtonPadding; | 1746 x += other_bookmarked_pref.width() + kButtonPadding; |
| 1658 } | 1747 } |
| 1659 | 1748 |
| 1749 // The app page shortcut button. | |
| 1750 if (apps_page_shortcut_->visible()) { | |
| 1751 if (!compute_bounds_only) { | |
| 1752 apps_page_shortcut_->SetBounds(x, y, apps_page_shortcut_pref.width(), | |
| 1753 height); | |
| 1754 } | |
| 1755 x += apps_page_shortcut_pref.width() + kButtonPadding; | |
| 1756 } | |
| 1757 | |
| 1660 // Set the preferred size computed so far. | 1758 // Set the preferred size computed so far. |
| 1661 if (compute_bounds_only) { | 1759 if (compute_bounds_only) { |
| 1662 x += kRightMargin; | 1760 x += kRightMargin; |
| 1663 prefsize.set_width(x); | 1761 prefsize.set_width(x); |
| 1664 if (IsDetached()) { | 1762 if (IsDetached()) { |
| 1665 x += static_cast<int>( | 1763 x += static_cast<int>( |
| 1666 kNewtabHorizontalPadding * (1 - size_animation_->GetCurrentValue())); | 1764 kNewtabHorizontalPadding * (1 - size_animation_->GetCurrentValue())); |
| 1667 prefsize.set_height( | 1765 prefsize.set_height( |
| 1668 browser_defaults::kBookmarkBarHeight + | 1766 browser_defaults::kBookmarkBarHeight + |
| 1669 static_cast<int>( | 1767 static_cast<int>( |
| 1670 (chrome::kNTPBookmarkBarHeight - | 1768 (chrome::kNTPBookmarkBarHeight - |
| 1671 browser_defaults::kBookmarkBarHeight) * | 1769 browser_defaults::kBookmarkBarHeight) * |
| 1672 (1 - size_animation_->GetCurrentValue()))); | 1770 (1 - size_animation_->GetCurrentValue()))); |
| 1673 } else { | 1771 } else { |
| 1674 prefsize.set_height( | 1772 prefsize.set_height( |
| 1675 static_cast<int>( | 1773 static_cast<int>( |
| 1676 browser_defaults::kBookmarkBarHeight * | 1774 browser_defaults::kBookmarkBarHeight * |
| 1677 size_animation_->GetCurrentValue())); | 1775 size_animation_->GetCurrentValue())); |
| 1678 } | 1776 } |
| 1679 } | 1777 } |
| 1680 return prefsize; | 1778 return prefsize; |
| 1681 } | 1779 } |
| 1780 | |
| 1781 bool BookmarkBarView::ShouldShowAppsShortcut() const { | |
| 1782 return chrome::search::IsInstantExtendedAPIEnabled(browser_->profile()) && | |
|
sky
2013/02/26 23:56:10
We should also hide this is I don't have any apps,
MAD
2013/02/27 00:55:43
Not sure... Even without apps, we still have the c
| |
| 1783 browser_->profile()->GetPrefs()->GetBoolean( | |
| 1784 prefs::kShowAppsShortcutInBookmarkBar); | |
| 1785 } | |
| 1786 | |
| 1787 void BookmarkBarView::OnAppsPageShortcutVisibilityChanged() { | |
| 1788 DCHECK(apps_page_shortcut_); | |
| 1789 apps_page_shortcut_->SetVisible(ShouldShowAppsShortcut()); | |
| 1790 Layout(); | |
| 1791 } | |
| 1792 | |
| 1793 bool BookmarkBarView::IsAppsShortcutVisibleForTesting() const { | |
| 1794 DCHECK(apps_page_shortcut_); | |
| 1795 return apps_page_shortcut_->visible(); | |
| 1796 } | |
| OLD | NEW |