bookmark_bubble_view.h revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_BUBBLE_VIEW_H_ 6#define CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_BUBBLE_VIEW_H_ 7 8#include "base/basictypes.h" 9#include "base/compiler_specific.h" 10#include "base/gtest_prod_util.h" 11#include "base/memory/scoped_ptr.h" 12#include "base/strings/string16.h" 13#include "chrome/browser/ui/bookmarks/bookmark_bubble_delegate.h" 14#include "chrome/browser/ui/bookmarks/recently_used_folders_combo_model.h" 15#include "ui/views/bubble/bubble_delegate.h" 16#include "ui/views/controls/button/button.h" 17#include "ui/views/controls/combobox/combobox_listener.h" 18#include "url/gurl.h" 19 20class BookmarkBubbleViewObserver; 21class Profile; 22 23namespace views { 24class LabelButton; 25class Textfield; 26} 27 28// BookmarkBubbleView is a view intended to be used as the content of an 29// Bubble. BookmarkBubbleView provides views for unstarring and editing the 30// bookmark it is created with. Don't create a BookmarkBubbleView directly, 31// instead use the static Show method. 32class BookmarkBubbleView : public views::BubbleDelegateView, 33 public views::ButtonListener, 34 public views::ComboboxListener { 35 public: 36 static void ShowBubble(views::View* anchor_view, 37 BookmarkBubbleViewObserver* observer, 38 scoped_ptr<BookmarkBubbleDelegate> delegate, 39 Profile* profile, 40 const GURL& url, 41 bool newly_bookmarked); 42 43 static bool IsShowing(); 44 45 static void Hide(); 46 47 virtual ~BookmarkBubbleView(); 48 49 // views::BubbleDelegateView method. 50 virtual views::View* GetInitiallyFocusedView() OVERRIDE; 51 52 // views::WidgetDelegate method. 53 virtual void WindowClosing() OVERRIDE; 54 55 // views::View method. 56 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; 57 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE; 58 59 protected: 60 // views::BubbleDelegateView method. 61 virtual void Init() OVERRIDE; 62 63 private: 64 friend class BookmarkBubbleViewTest; 65 FRIEND_TEST_ALL_PREFIXES(BookmarkBubbleViewTest, SyncPromoSignedIn); 66 FRIEND_TEST_ALL_PREFIXES(BookmarkBubbleViewTest, SyncPromoNotSignedIn); 67 68 // Creates a BookmarkBubbleView. 69 BookmarkBubbleView(views::View* anchor_view, 70 BookmarkBubbleViewObserver* observer, 71 scoped_ptr<BookmarkBubbleDelegate> delegate, 72 Profile* profile, 73 const GURL& url, 74 bool newly_bookmarked); 75 76 // Returns the title to display. 77 base::string16 GetTitle(); 78 79 // Overridden from views::View: 80 virtual gfx::Size GetMinimumSize() OVERRIDE; 81 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE; 82 83 // Overridden from views::ButtonListener: 84 // Closes the bubble or opens the edit dialog. 85 virtual void ButtonPressed(views::Button* sender, 86 const ui::Event& event) OVERRIDE; 87 88 // Overridden from views::ComboboxListener: 89 virtual void OnPerformAction(views::Combobox* combobox) OVERRIDE; 90 91 // Handle the message when the user presses a button. 92 void HandleButtonPressed(views::Button* sender); 93 94 // Shows the BookmarkEditor. 95 void ShowEditor(); 96 97 // Sets the title and parent of the node. 98 void ApplyEdits(); 99 100 // The bookmark bubble, if we're showing one. 101 static BookmarkBubbleView* bookmark_bubble_; 102 103 // Our observer, to notify when the bubble shows or hides. 104 BookmarkBubbleViewObserver* observer_; 105 106 // Delegate, to handle clicks on the sign in link. 107 scoped_ptr<BookmarkBubbleDelegate> delegate_; 108 109 // The profile. 110 Profile* profile_; 111 112 // The bookmark URL. 113 const GURL url_; 114 115 // If true, the page was just bookmarked. 116 const bool newly_bookmarked_; 117 118 RecentlyUsedFoldersComboModel parent_model_; 119 120 // Button for removing the bookmark. 121 views::LabelButton* remove_button_; 122 123 // Button to bring up the editor. 124 views::LabelButton* edit_button_; 125 126 // Button to close the window. 127 views::LabelButton* close_button_; 128 129 // Textfield showing the title of the bookmark. 130 views::Textfield* title_tf_; 131 132 // Combobox showing a handful of folders the user can choose from, including 133 // the current parent. 134 views::Combobox* parent_combobox_; 135 136 // Bookmark sync promo view, if displayed. 137 views::View* sync_promo_view_; 138 139 // When the destructor is invoked should the bookmark be removed? 140 bool remove_bookmark_; 141 142 // When the destructor is invoked should edits be applied? 143 bool apply_edits_; 144 145 DISALLOW_COPY_AND_ASSIGN(BookmarkBubbleView); 146}; 147 148#endif // CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_BUBBLE_VIEW_H_ 149