1 // Copyright (c) 2011 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 #pragma once 8 9 #include "base/string16.h" 10 #include "chrome/browser/bookmarks/recently_used_folders_combo_model.h" 11 #include "chrome/browser/ui/views/bubble/bubble.h" 12 #include "googleurl/src/gurl.h" 13 #include "ui/gfx/rect.h" 14 #include "views/controls/button/button.h" 15 #include "views/controls/combobox/combobox.h" 16 #include "views/controls/link.h" 17 #include "views/view.h" 18 19 class Profile; 20 21 class BookmarkModel; 22 class BookmarkNode; 23 24 namespace views { 25 class NativeButton; 26 class Textfield; 27 } 28 29 // BookmarkBubbleView is a view intended to be used as the content of an 30 // Bubble. BookmarkBubbleView provides views for unstarring and editing the 31 // bookmark it is created with. Don't create a BookmarkBubbleView directly, 32 // instead use the static Show method. 33 class BookmarkBubbleView : public views::View, 34 public views::LinkController, 35 public views::ButtonListener, 36 public views::Combobox::Listener, 37 public BubbleDelegate { 38 public: 39 static void Show(views::Window* window, 40 const gfx::Rect& bounds, 41 BubbleDelegate* delegate, 42 Profile* profile, 43 const GURL& url, 44 bool newly_bookmarked); 45 46 static bool IsShowing(); 47 48 static void Hide(); 49 50 virtual ~BookmarkBubbleView(); 51 52 void set_bubble(Bubble* bubble) { bubble_ = bubble; } 53 54 // Invoked after the bubble has been shown. 55 virtual void BubbleShown(); 56 57 // Override to close on return. 58 virtual bool AcceleratorPressed(const views::Accelerator& accelerator); 59 60 virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child); 61 62 private: 63 // Creates a BookmarkBubbleView. 64 // |title| is the title of the page. If newly_bookmarked is false, title is 65 // ignored and the title of the bookmark is fetched from the database. 66 BookmarkBubbleView(BubbleDelegate* delegate, 67 Profile* profile, 68 const GURL& url, 69 bool newly_bookmarked); 70 // Creates the child views. 71 void Init(); 72 73 // Returns the title to display. 74 string16 GetTitle(); 75 76 // LinkController method, either unstars the item or shows the bookmark 77 // editor (depending upon which link was clicked). 78 virtual void LinkActivated(views::Link* source, int event_flags); 79 80 // ButtonListener method, closes the bubble or opens the edit dialog. 81 virtual void ButtonPressed(views::Button* sender, const views::Event& event); 82 83 // Combobox::Listener method. Changes the parent of the bookmark. 84 virtual void ItemChanged(views::Combobox* combobox, 85 int prev_index, 86 int new_index); 87 88 // BubbleDelegate methods. These forward to the BubbleDelegate supplied in the 89 // constructor as well as sending out the necessary notification. 90 virtual void BubbleClosing(Bubble* bubble, bool closed_by_escape); 91 virtual bool CloseOnEscape(); 92 virtual bool FadeInOnShow(); 93 virtual std::wstring accessible_name(); 94 95 // Closes the bubble. 96 void Close(); 97 98 // Handle the message when the user presses a button. 99 void HandleButtonPressed(views::Button* sender); 100 101 // Shows the BookmarkEditor. 102 void ShowEditor(); 103 104 // Sets the title and parent of the node. 105 void ApplyEdits(); 106 107 // The bookmark bubble, if we're showing one. 108 static BookmarkBubbleView* bookmark_bubble_; 109 110 // The Bubble showing us. 111 Bubble* bubble_; 112 113 // Delegate for the bubble, may be null. 114 BubbleDelegate* delegate_; 115 116 // The profile. 117 Profile* profile_; 118 119 // The bookmark URL. 120 const GURL url_; 121 122 // Title of the bookmark. This is initially the title supplied to the 123 // constructor, which is typically the title of the page. 124 std::wstring title_; 125 126 // If true, the page was just bookmarked. 127 const bool newly_bookmarked_; 128 129 RecentlyUsedFoldersComboModel parent_model_; 130 131 // Link for removing/unstarring the bookmark. 132 views::Link* remove_link_; 133 134 // Button to bring up the editor. 135 views::NativeButton* edit_button_; 136 137 // Button to close the window. 138 views::NativeButton* close_button_; 139 140 // Textfield showing the title of the bookmark. 141 views::Textfield* title_tf_; 142 143 // Combobox showing a handful of folders the user can choose from, including 144 // the current parent. 145 views::Combobox* parent_combobox_; 146 147 // When the destructor is invoked should the bookmark be removed? 148 bool remove_bookmark_; 149 150 // When the destructor is invoked should edits be applied? 151 bool apply_edits_; 152 153 DISALLOW_COPY_AND_ASSIGN(BookmarkBubbleView); 154 }; 155 156 #endif // CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_BUBBLE_VIEW_H_ 157