| 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 #ifndef CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_BAR_VIEW_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_BAR_VIEW_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_BAR_VIEW_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_BAR_VIEW_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/prefs/public/pref_change_registrar.h" |
| 15 #include "chrome/browser/bookmarks/bookmark_model_observer.h" | 16 #include "chrome/browser/bookmarks/bookmark_model_observer.h" |
| 16 #include "chrome/browser/bookmarks/bookmark_node_data.h" | 17 #include "chrome/browser/bookmarks/bookmark_node_data.h" |
| 17 #include "chrome/browser/bookmarks/bookmark_utils.h" | 18 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 18 #include "chrome/browser/ui/bookmarks/bookmark_bar.h" | 19 #include "chrome/browser/ui/bookmarks/bookmark_bar.h" |
| 19 #include "chrome/browser/ui/bookmarks/bookmark_bar_instructions_delegate.h" | 20 #include "chrome/browser/ui/bookmarks/bookmark_bar_instructions_delegate.h" |
| 20 #include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view_observer.h" | 21 #include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view_observer.h" |
| 21 #include "chrome/browser/ui/views/bookmarks/bookmark_menu_controller_views.h" | 22 #include "chrome/browser/ui/views/bookmarks/bookmark_menu_controller_views.h" |
| 22 #include "chrome/browser/ui/views/detachable_toolbar_view.h" | 23 #include "chrome/browser/ui/views/detachable_toolbar_view.h" |
| 23 #include "ui/base/animation/animation_delegate.h" | 24 #include "ui/base/animation/animation_delegate.h" |
| 24 #include "ui/views/context_menu_controller.h" | 25 #include "ui/views/context_menu_controller.h" |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 virtual void ShowContextMenuForView(views::View* source, | 244 virtual void ShowContextMenuForView(views::View* source, |
| 244 const gfx::Point& point) OVERRIDE; | 245 const gfx::Point& point) OVERRIDE; |
| 245 | 246 |
| 246 private: | 247 private: |
| 247 class ButtonSeparatorView; | 248 class ButtonSeparatorView; |
| 248 struct DropInfo; | 249 struct DropInfo; |
| 249 struct DropLocation; | 250 struct DropLocation; |
| 250 | 251 |
| 251 friend class BookmarkBarViewEventTestBase; | 252 friend class BookmarkBarViewEventTestBase; |
| 252 FRIEND_TEST_ALL_PREFIXES(BookmarkBarViewTest, SwitchProfile); | 253 FRIEND_TEST_ALL_PREFIXES(BookmarkBarViewTest, SwitchProfile); |
| 254 FRIEND_TEST_ALL_PREFIXES(BookmarkBarViewTest, |
| 255 NoAppsShortcutWithoutInstantExtended); |
| 256 FRIEND_TEST_ALL_PREFIXES(BookmarkBarViewInstantExtendedTest, |
| 257 AppsShortcutVisibility); |
| 253 | 258 |
| 254 // Used to identify what the user is dropping onto. | 259 // Used to identify what the user is dropping onto. |
| 255 enum DropButtonType { | 260 enum DropButtonType { |
| 256 DROP_BOOKMARK, | 261 DROP_BOOKMARK, |
| 257 DROP_OTHER_FOLDER, | 262 DROP_OTHER_FOLDER, |
| 258 DROP_OVERFLOW | 263 DROP_OVERFLOW |
| 259 }; | 264 }; |
| 260 | 265 |
| 261 // Creates recent bookmark button and when visible button as well as | 266 // Creates recent bookmark button and when visible button as well as |
| 262 // calculating the preferred height. | 267 // calculating the preferred height. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 286 | 291 |
| 287 // Creates the button showing the other bookmarked items. | 292 // Creates the button showing the other bookmarked items. |
| 288 views::MenuButton* CreateOtherBookmarkedButton(); | 293 views::MenuButton* CreateOtherBookmarkedButton(); |
| 289 | 294 |
| 290 // Creates the button used when not all bookmark buttons fit. | 295 // Creates the button used when not all bookmark buttons fit. |
| 291 views::MenuButton* CreateOverflowButton(); | 296 views::MenuButton* CreateOverflowButton(); |
| 292 | 297 |
| 293 // Creates the button for rendering the specified bookmark node. | 298 // Creates the button for rendering the specified bookmark node. |
| 294 views::View* CreateBookmarkButton(const BookmarkNode* node); | 299 views::View* CreateBookmarkButton(const BookmarkNode* node); |
| 295 | 300 |
| 301 // Creates the button for rendering the apps page shortcut. |
| 302 views::TextButton* CreateAppsPageShortcutButton(); |
| 303 |
| 296 // Configures the button from the specified node. This sets the text, | 304 // Configures the button from the specified node. This sets the text, |
| 297 // and icon. | 305 // and icon. |
| 298 void ConfigureButton(const BookmarkNode* node, views::TextButton* button); | 306 void ConfigureButton(const BookmarkNode* node, views::TextButton* button); |
| 299 | 307 |
| 300 // Implementation for BookmarkNodeAddedImpl. | 308 // Implementation for BookmarkNodeAddedImpl. |
| 301 void BookmarkNodeAddedImpl(BookmarkModel* model, | 309 void BookmarkNodeAddedImpl(BookmarkModel* model, |
| 302 const BookmarkNode* parent, | 310 const BookmarkNode* parent, |
| 303 int index); | 311 int index); |
| 304 | 312 |
| 305 // Implementation for BookmarkNodeRemoved. | 313 // Implementation for BookmarkNodeRemoved. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 // Returns the view to throb when a node is removed. |parent| is the parent of | 346 // Returns the view to throb when a node is removed. |parent| is the parent of |
| 339 // the node that was removed, and |old_index| the index of the node that was | 347 // the node that was removed, and |old_index| the index of the node that was |
| 340 // removed. | 348 // removed. |
| 341 views::CustomButton* DetermineViewToThrobFromRemove( | 349 views::CustomButton* DetermineViewToThrobFromRemove( |
| 342 const BookmarkNode* parent, | 350 const BookmarkNode* parent, |
| 343 int old_index); | 351 int old_index); |
| 344 | 352 |
| 345 // Updates the colors for all the child objects in the bookmarks bar. | 353 // Updates the colors for all the child objects in the bookmarks bar. |
| 346 void UpdateColors(); | 354 void UpdateColors(); |
| 347 | 355 |
| 348 // Updates the visibility of |other_bookmarked_button_| and | 356 // Updates the visibility of |other_bookmarked_button_|. Also shows or hide |
| 349 // |bookmarks_separator_view_|. | 357 // the separator if required. |
| 350 void UpdateOtherBookmarksVisibility(); | 358 void UpdateOtherBookmarksVisibility(); |
| 351 | 359 |
| 360 // Updates the visibility of |bookmarks_separator_view_|. |
| 361 void UpdateBookmarksSeparatorVisibility(); |
| 362 |
| 352 // This method computes the bounds for the bookmark bar items. If | 363 // This method computes the bounds for the bookmark bar items. If |
| 353 // |compute_bounds_only| = TRUE, the bounds for the items are just computed, | 364 // |compute_bounds_only| = TRUE, the bounds for the items are just computed, |
| 354 // but are not set. This mode is used by GetPreferredSize() to obtain the | 365 // but are not set. This mode is used by GetPreferredSize() to obtain the |
| 355 // desired bounds. If |compute_bounds_only| = FALSE, the bounds are set. | 366 // desired bounds. If |compute_bounds_only| = FALSE, the bounds are set. |
| 356 gfx::Size LayoutItems(bool compute_bounds_only); | 367 gfx::Size LayoutItems(bool compute_bounds_only); |
| 357 | 368 |
| 369 // Returns true if we should show the apps shortcut. |
| 370 bool ShouldShowAppsShortcut() const; |
| 371 |
| 372 // Updates the visibility of the apps shortcut based on the pref value. |
| 373 void OnAppsPageShortcutVisibilityChanged(); |
| 374 |
| 375 // Needed to react to kShowAppsShortcutInBookmarkBar changes. |
| 376 PrefChangeRegistrar profile_pref_registrar_; |
| 377 |
| 358 // Used for opening urls. | 378 // Used for opening urls. |
| 359 content::PageNavigator* page_navigator_; | 379 content::PageNavigator* page_navigator_; |
| 360 | 380 |
| 361 // Model providing details as to the starred entries/folders that should be | 381 // Model providing details as to the starred entries/folders that should be |
| 362 // shown. This is owned by the Profile. | 382 // shown. This is owned by the Profile. |
| 363 BookmarkModel* model_; | 383 BookmarkModel* model_; |
| 364 | 384 |
| 365 // Used to manage showing a Menu, either for the most recently bookmarked | 385 // Used to manage showing a Menu, either for the most recently bookmarked |
| 366 // entries, or for the starred folder. | 386 // entries, or for the starred folder. |
| 367 BookmarkMenuController* bookmark_menu_; | 387 BookmarkMenuController* bookmark_menu_; |
| 368 | 388 |
| 369 // Used when showing a menu for drag and drop. That is, if the user drags | 389 // Used when showing a menu for drag and drop. That is, if the user drags |
| 370 // over a folder this becomes non-null and manages the menu showing the | 390 // over a folder this becomes non-null and manages the menu showing the |
| 371 // contents of the node. | 391 // contents of the node. |
| 372 BookmarkMenuController* bookmark_drop_menu_; | 392 BookmarkMenuController* bookmark_drop_menu_; |
| 373 | 393 |
| 374 // If non-NULL we're showing a context menu for one of the items on the | 394 // If non-NULL we're showing a context menu for one of the items on the |
| 375 // bookmark bar. | 395 // bookmark bar. |
| 376 scoped_ptr<BookmarkContextMenu> context_menu_; | 396 scoped_ptr<BookmarkContextMenu> context_menu_; |
| 377 | 397 |
| 378 // Shows the other bookmark entries. | 398 // Shows the other bookmark entries. |
| 379 views::MenuButton* other_bookmarked_button_; | 399 views::MenuButton* other_bookmarked_button_; |
| 380 | 400 |
| 401 // Shows the Apps page shortcut. |
| 402 views::TextButton* apps_page_shortcut_; |
| 403 |
| 381 // Task used to delay showing of the drop menu. | 404 // Task used to delay showing of the drop menu. |
| 382 base::WeakPtrFactory<BookmarkBarView> show_folder_method_factory_; | 405 base::WeakPtrFactory<BookmarkBarView> show_folder_method_factory_; |
| 383 | 406 |
| 384 // Used to track drops on the bookmark bar view. | 407 // Used to track drops on the bookmark bar view. |
| 385 scoped_ptr<DropInfo> drop_info_; | 408 scoped_ptr<DropInfo> drop_info_; |
| 386 | 409 |
| 387 // Visible if not all the bookmark buttons fit. | 410 // Visible if not all the bookmark buttons fit. |
| 388 views::MenuButton* overflow_button_; | 411 views::MenuButton* overflow_button_; |
| 389 | 412 |
| 390 // BookmarkBarInstructionsView that is visible if there are no bookmarks on | 413 // BookmarkBarInstructionsView that is visible if there are no bookmarks on |
| (...skipping 18 matching lines...) Expand all Loading... |
| 409 | 432 |
| 410 BookmarkBar::State bookmark_bar_state_; | 433 BookmarkBar::State bookmark_bar_state_; |
| 411 | 434 |
| 412 // Are we animating to or from the detached state? | 435 // Are we animating to or from the detached state? |
| 413 bool animating_detached_; | 436 bool animating_detached_; |
| 414 | 437 |
| 415 DISALLOW_COPY_AND_ASSIGN(BookmarkBarView); | 438 DISALLOW_COPY_AND_ASSIGN(BookmarkBarView); |
| 416 }; | 439 }; |
| 417 | 440 |
| 418 #endif // CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_BAR_VIEW_H_ | 441 #endif // CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_BAR_VIEW_H_ |
| OLD | NEW |