Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / views / bookmarks / bookmark_bubble_view.h
blob0eea1cfa8293f982df0d79103d0ab4a283f4f4ef
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.
5 #ifndef CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_BUBBLE_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_BUBBLE_VIEW_H_
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"
20 class Profile;
22 namespace bookmarks {
23 class BookmarkBubbleObserver;
26 namespace views {
27 class LabelButton;
28 class Textfield;
31 // BookmarkBubbleView is a view intended to be used as the content of an
32 // Bubble. BookmarkBubbleView provides views for unstarring and editing the
33 // bookmark it is created with. Don't create a BookmarkBubbleView directly,
34 // instead use the static Show method.
35 class BookmarkBubbleView : public views::BubbleDelegateView,
36 public views::ButtonListener,
37 public views::ComboboxListener {
38 public:
39 // If |anchor_view| is null, |anchor_rect| is used to anchor the bubble and
40 // |parent_window| is used to ensure the bubble closes if the parent closes.
41 static void ShowBubble(views::View* anchor_view,
42 const gfx::Rect& anchor_rect,
43 gfx::NativeView parent_window,
44 bookmarks::BookmarkBubbleObserver* observer,
45 scoped_ptr<BookmarkBubbleDelegate> delegate,
46 Profile* profile,
47 const GURL& url,
48 bool already_bookmarked);
50 static void Hide();
52 static BookmarkBubbleView* bookmark_bubble() { return bookmark_bubble_; }
54 ~BookmarkBubbleView() override;
56 // views::WidgetDelegate:
57 void WindowClosing() override;
58 bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
60 protected:
61 // views::BubbleDelegateView method.
62 void Init() override;
64 private:
65 friend class BookmarkBubbleViewTest;
66 FRIEND_TEST_ALL_PREFIXES(BookmarkBubbleViewTest, SyncPromoSignedIn);
67 FRIEND_TEST_ALL_PREFIXES(BookmarkBubbleViewTest, SyncPromoNotSignedIn);
69 // views::BubbleDelegateView:
70 const char* GetClassName() const override;
71 views::View* GetInitiallyFocusedView() override;
73 // Creates a BookmarkBubbleView.
74 BookmarkBubbleView(views::View* anchor_view,
75 bookmarks::BookmarkBubbleObserver* observer,
76 scoped_ptr<BookmarkBubbleDelegate> delegate,
77 Profile* profile,
78 const GURL& url,
79 bool newly_bookmarked);
81 // Returns the title to display.
82 base::string16 GetTitle();
84 // Overridden from views::View:
85 void GetAccessibleState(ui::AXViewState* state) override;
87 // Overridden from views::ButtonListener:
88 // Closes the bubble or opens the edit dialog.
89 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
91 // Overridden from views::ComboboxListener:
92 void OnPerformAction(views::Combobox* combobox) override;
94 // Handle the message when the user presses a button.
95 void HandleButtonPressed(views::Button* sender);
97 // Shows the BookmarkEditor.
98 void ShowEditor();
100 // Sets the title and parent of the node.
101 void ApplyEdits();
103 // The bookmark bubble, if we're showing one.
104 static BookmarkBubbleView* bookmark_bubble_;
106 // Our observer, to notify when the bubble shows or hides.
107 bookmarks::BookmarkBubbleObserver* observer_;
109 // Delegate, to handle clicks on the sign in link.
110 scoped_ptr<BookmarkBubbleDelegate> delegate_;
112 // The profile.
113 Profile* profile_;
115 // The bookmark URL.
116 const GURL url_;
118 // If true, the page was just bookmarked.
119 const bool newly_bookmarked_;
121 RecentlyUsedFoldersComboModel parent_model_;
123 // Button for removing the bookmark.
124 views::LabelButton* remove_button_;
126 // Button to bring up the editor.
127 views::LabelButton* edit_button_;
129 // Button to close the window.
130 views::LabelButton* close_button_;
132 // Textfield showing the title of the bookmark.
133 views::Textfield* title_tf_;
135 // Combobox showing a handful of folders the user can choose from, including
136 // the current parent.
137 views::Combobox* parent_combobox_;
139 // Bookmark sync promo view, if displayed.
140 views::View* sync_promo_view_;
142 // When the destructor is invoked should the bookmark be removed?
143 bool remove_bookmark_;
145 // When the destructor is invoked should edits be applied?
146 bool apply_edits_;
148 DISALLOW_COPY_AND_ASSIGN(BookmarkBubbleView);
151 #endif // CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_BUBBLE_VIEW_H_