bookmark_bubble_view.h revision 868fa2fe829687343ffae624259930155e16dbd8
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/strings/string16.h"
11#include "chrome/browser/ui/bookmarks/recently_used_folders_combo_model.h"
12#include "googleurl/src/gurl.h"
13#include "ui/views/bubble/bubble_delegate.h"
14#include "ui/views/controls/button/button.h"
15#include "ui/views/controls/combobox/combobox_listener.h"
16#include "ui/views/controls/link_listener.h"
17
18class BookmarkBubbleViewObserver;
19class Profile;
20
21namespace views {
22class LabelButton;
23class Textfield;
24}
25
26// BookmarkBubbleView is a view intended to be used as the content of an
27// Bubble. BookmarkBubbleView provides views for unstarring and editing the
28// bookmark it is created with. Don't create a BookmarkBubbleView directly,
29// instead use the static Show method.
30class BookmarkBubbleView : public views::BubbleDelegateView,
31                           public views::LinkListener,
32                           public views::ButtonListener,
33                           public views::ComboboxListener {
34 public:
35  static void ShowBubble(views::View* anchor_view,
36                         BookmarkBubbleViewObserver* observer,
37                         Profile* profile,
38                         const GURL& url,
39                         bool newly_bookmarked);
40
41  static bool IsShowing();
42
43  static void Hide();
44
45  virtual ~BookmarkBubbleView();
46
47  // views::BubbleDelegateView method.
48  virtual views::View* GetInitiallyFocusedView() OVERRIDE;
49
50  // views::WidgetDelegate method.
51  virtual void WindowClosing() OVERRIDE;
52
53  // views::View method.
54  virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
55
56 protected:
57  // views::BubbleDelegateView method.
58  virtual void Init() OVERRIDE;
59
60 private:
61  // Creates a BookmarkBubbleView.
62  BookmarkBubbleView(views::View* anchor_view,
63                     BookmarkBubbleViewObserver* observer,
64                     Profile* profile,
65                     const GURL& url,
66                     bool newly_bookmarked);
67
68  // Returns the title to display.
69  string16 GetTitle();
70
71  // Overridden from views::LinkListener:
72  // Either unstars the item or shows the bookmark editor (depending upon which
73  // link was clicked).
74  virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
75
76  // Overridden from views::ButtonListener:
77  // Closes the bubble or opens the edit dialog.
78  virtual void ButtonPressed(views::Button* sender,
79                             const ui::Event& event) OVERRIDE;
80
81  // Overridden from views::ComboboxListener:
82  virtual void OnSelectedIndexChanged(views::Combobox* combobox) OVERRIDE;
83
84  // Handle the message when the user presses a button.
85  void HandleButtonPressed(views::Button* sender);
86
87  // Shows the BookmarkEditor.
88  void ShowEditor();
89
90  // Sets the title and parent of the node.
91  void ApplyEdits();
92
93  // The bookmark bubble, if we're showing one.
94  static BookmarkBubbleView* bookmark_bubble_;
95
96  // Our observer, to notify when the bubble shows or hides.
97  BookmarkBubbleViewObserver* observer_;
98
99  // The profile.
100  Profile* profile_;
101
102  // The bookmark URL.
103  const GURL url_;
104
105  // If true, the page was just bookmarked.
106  const bool newly_bookmarked_;
107
108  RecentlyUsedFoldersComboModel parent_model_;
109
110  // Link for removing/unstarring the bookmark.
111  views::Link* remove_link_;
112
113  // Button to bring up the editor.
114  views::LabelButton* edit_button_;
115
116  // Button to close the window.
117  views::LabelButton* close_button_;
118
119  // Textfield showing the title of the bookmark.
120  views::Textfield* title_tf_;
121
122  // Combobox showing a handful of folders the user can choose from, including
123  // the current parent.
124  views::Combobox* parent_combobox_;
125
126  // When the destructor is invoked should the bookmark be removed?
127  bool remove_bookmark_;
128
129  // When the destructor is invoked should edits be applied?
130  bool apply_edits_;
131
132  DISALLOW_COPY_AND_ASSIGN(BookmarkBubbleView);
133};
134
135#endif  // CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_BUBBLE_VIEW_H_
136