diff options
Diffstat (limited to 'chrome/browser/views/bookmark_bar_view.cc')
-rw-r--r-- | chrome/browser/views/bookmark_bar_view.cc | 65 |
1 files changed, 48 insertions, 17 deletions
diff --git a/chrome/browser/views/bookmark_bar_view.cc b/chrome/browser/views/bookmark_bar_view.cc index e9dbb11..6579a0f 100644 --- a/chrome/browser/views/bookmark_bar_view.cc +++ b/chrome/browser/views/bookmark_bar_view.cc @@ -235,7 +235,13 @@ class BookmarkButton : public ChromeViews::TextButton { url_(url), profile_(profile) { show_animation_.reset(new SlideAnimation(this)); - show_animation_->Show(); + if (BookmarkBarView::testing_) { + // For some reason during testing the events generated by animating + // throw off the test. So, don't animate while testing. + show_animation_->Reset(1); + } else { + show_animation_->Show(); + } } bool GetTooltipText(int x, int y, std::wstring* tooltip) { @@ -507,6 +513,8 @@ class BookmarkNodeMenuController : public ChromeViews::MenuDelegate, menu_.Cancel(); } + MenuItemView* menu() { return &menu_; } + private: // Menu::Delegate method. Does the appropriate operation based on chosen // menu item. @@ -750,6 +758,12 @@ class MenuRunner : public ChromeViews::MenuDelegate, menu_.Cancel(); } + MenuItemView* menu() { return &menu_; } + + MenuItemView* context_menu() { + return context_menu_.get() ? context_menu_->menu() : NULL; + } + private: // Creates an entry in menu for each child node of parent starting at // start_child_index, recursively invoking this for any star groups. @@ -980,6 +994,9 @@ class ButtonSeparatorView : public ChromeViews::View { // static const int BookmarkBarView::kMaxButtonWidth = 150; +// static +bool BookmarkBarView::testing_ = false; + // Returns the bitmap to use for starred groups. static const SkBitmap& GetGroupIcon() { if (!kFolderIcon) { @@ -1444,24 +1461,38 @@ bool BookmarkBarView::IsAlwaysShown() { } bool BookmarkBarView::IsNewTabPage() { - DCHECK(browser_); - - if (browser_->GetSelectedTabContents()) { - return browser_->GetSelectedTabContents()->IsBookmarkBarAlwaysVisible(); - } - - return false; + return (browser_ && browser_->GetSelectedTabContents() && + browser_->GetSelectedTabContents()->IsBookmarkBarAlwaysVisible()); } void BookmarkBarView::AnimationProgressed(const Animation* animation) { - browser_->ToolbarSizeChanged(NULL, true); + if (browser_) + browser_->ToolbarSizeChanged(NULL, true); } void BookmarkBarView::AnimationEnded(const Animation* animation) { - browser_->ToolbarSizeChanged(NULL, false); + if (browser_) + browser_->ToolbarSizeChanged(NULL, false); SchedulePaint(); } +ChromeViews::TextButton* BookmarkBarView::GetBookmarkButton(int index) { + DCHECK(index >= 0 && index < GetBookmarkButtonCount()); + return static_cast<ChromeViews::TextButton*>(GetChildViewAt(index)); +} + +ChromeViews::MenuItemView* BookmarkBarView::GetMenu() { + return menu_runner_.get() ? menu_runner_->menu() : NULL; +} + +ChromeViews::MenuItemView* BookmarkBarView::GetContextMenu() { + return menu_runner_.get() ? menu_runner_->context_menu() : NULL; +} + +ChromeViews::MenuItemView* BookmarkBarView::GetDropMenu() { + return drop_menu_runner_.get() ? drop_menu_runner_->menu() : NULL; +} + void BookmarkBarView::Init() { ResourceBundle& rb = ResourceBundle::GetSharedInstance(); @@ -1525,11 +1556,6 @@ int BookmarkBarView::GetBookmarkButtonCount() { return GetChildViewCount() - 4; } -ChromeViews::TextButton* BookmarkBarView::GetBookmarkButton(int index) { - DCHECK(index >= 0 && index < GetBookmarkButtonCount()); - return static_cast<ChromeViews::TextButton*>(GetChildViewAt(index)); -} - void BookmarkBarView::Loaded(BookmarkBarModel* model) { BookmarkBarNode* node = model_->GetBookmarkBarNode(); DCHECK(node && model_->other_node()); @@ -1722,8 +1748,7 @@ void BookmarkBarView::RunMenu(ChromeViews::View* view, CPoint screen_loc(x, 0); View::ConvertPointToScreen(this, &screen_loc); menu_runner_.reset(new MenuRunner(this, node, start_index)); - HWND parent_hwnd = reinterpret_cast<HWND>( - browser_->window()->GetPlatformID()); + HWND parent_hwnd = GetViewContainer()->GetHWND(); menu_runner_->RunMenuAt(parent_hwnd, gfx::Rect(screen_loc.x, screen_loc.y, view->GetWidth(), height), @@ -1914,6 +1939,12 @@ void BookmarkBarView::StopShowFolderDropMenuTimer() { } void BookmarkBarView::StartShowFolderDropMenuTimer(BookmarkBarNode* node) { + if (testing_) { + // So that tests can run as fast as possible disable the delay during + // testing. + ShowDropFolderForNode(node); + return; + } DCHECK(!show_folder_drop_menu_task_); show_folder_drop_menu_task_ = new ShowFolderDropMenuTask(this, node); static DWORD delay = 0; |