diff options
author | initial.commit <initial.commit@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-07-26 23:55:29 +0000 |
---|---|---|
committer | initial.commit <initial.commit@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-07-26 23:55:29 +0000 |
commit | 09911bf300f1a419907a9412154760efd0b7abc3 (patch) | |
tree | f131325fb4e2ad12c6d3504ab75b16dd92facfed /chrome/browser/views/bookmark_bubble_view.h | |
parent | 586acc5fe142f498261f52c66862fa417c3d52d2 (diff) | |
download | chromium_src-09911bf300f1a419907a9412154760efd0b7abc3.zip chromium_src-09911bf300f1a419907a9412154760efd0b7abc3.tar.gz chromium_src-09911bf300f1a419907a9412154760efd0b7abc3.tar.bz2 |
Add chrome to the repository.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/bookmark_bubble_view.h')
-rw-r--r-- | chrome/browser/views/bookmark_bubble_view.h | 187 |
1 files changed, 187 insertions, 0 deletions
diff --git a/chrome/browser/views/bookmark_bubble_view.h b/chrome/browser/views/bookmark_bubble_view.h new file mode 100644 index 0000000..53d95fd --- /dev/null +++ b/chrome/browser/views/bookmark_bubble_view.h @@ -0,0 +1,187 @@ +// Copyright 2008, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef CHROME_BROWSER_VIEWS_BOOKMARK_BUBBLE_VIEW_H__ +#define CHROME_BROWSER_VIEWS_BOOKMARK_BUBBLE_VIEW_H__ + +#include "base/gfx/rect.h" +#include "chrome/browser/views/info_bubble.h" +#include "chrome/views/combo_box.h" +#include "chrome/views/link.h" +#include "chrome/views/native_button.h" +#include "chrome/views/view.h" +#include "googleurl/src/gurl.h" + +class Profile; + +class BookmarkBarModel; +class BookmarkBarNode; + +namespace ChromeViews { +class CheckBox; +class TextField; +} + +// BookmarkBubbleView is a view intended to be used as the content of an +// InfoBubble. BookmarkBubbleView provides views for unstarring and editting +// the bookmark it is created with. Don't create a BookmarkBubbleView directly, +// instead use the static Show method. +class BookmarkBubbleView : public ChromeViews::View, + public ChromeViews::LinkController, + public ChromeViews::NativeButton::Listener, + public ChromeViews::ComboBox::Listener, + public InfoBubbleDelegate { + public: + static void Show(HWND parent, + const gfx::Rect& bounds, + InfoBubbleDelegate* delegate, + Profile* profile, + const GURL& url, + bool newly_bookmarked); + + virtual ~BookmarkBubbleView(); + + // Overriden to force a layout. + virtual void DidChangeBounds(const CRect& previous, const CRect& current); + + // Invoked after the bubble has been shown. + virtual void BubbleShown(); + + // Override to close on return. + virtual bool AcceleratorPressed(const ChromeViews::Accelerator& accelerator); + + private: + // Model for the combobox showing the list of folders to choose from. The + // list always contains the bookmark bar, other node and parent. The list + // also contains an extra item that shows the text 'Choose another folder...'. + class RecentlyUsedFoldersModel : public ChromeViews::ComboBox::Model { + public: + RecentlyUsedFoldersModel(BookmarkBarModel* bb_model, BookmarkBarNode* node); + + // ComboBox::Model methods. Call through to nodes_. + virtual int GetItemCount(ChromeViews::ComboBox* source); + virtual std::wstring GetItemAt(ChromeViews::ComboBox* source, int index); + + // Returns the node at the specified index. + BookmarkBarNode* GetNodeAt(int index); + + // Returns the index of the original parent folder. + int node_parent_index() const { return node_parent_index_; } + + private: + // Removes node from nodes_. Does nothing if node is not in nodes_. + void RemoveNode(BookmarkBarNode* node); + + std::vector<BookmarkBarNode*> nodes_; + int node_parent_index_; + + DISALLOW_EVIL_CONSTRUCTORS(RecentlyUsedFoldersModel); + }; + + // Creates a BookmarkBubbleView. + // |title| is the title of the page. If newly_bookmarked is false, title is + // ignored and the title of the bookmark is fetched from the database. + BookmarkBubbleView(InfoBubbleDelegate* delegate, + Profile* profile, + const GURL& url, + bool newly_bookmarked); + // Creates the child views. + void Init(); + + // Returns the title to display. + std::wstring GetTitle(); + + // LinkController method, either unstars the item or shows the bookmark + // editor (depending upon which link was clicked). + virtual void LinkActivated(ChromeViews::Link* source, int event_flags); + + // ButtonListener method, closes the bubble or opens the edit dialog. + virtual void ButtonPressed(ChromeViews::NativeButton* sender); + + // ComboBox::Listener method. Changes the parent of the bookmark. + virtual void ItemChanged(ChromeViews::ComboBox* combo_box, + int prev_index, + int new_index); + + // InfoBubbleDelegate methods. These forward to the InfoBubbleDelegate + // supplied in the constructor as well as sending out the necessary + // notification. + virtual void InfoBubbleClosing(InfoBubble* info_bubble); + virtual bool CloseOnEscape(); + + // Closes the bubble. + void Close(); + + // Removes the bookmark and closes the view. + void RemoveBookmark(); + + // Shows the BookmarkEditor. + void ShowEditor(); + + // Sets the title of the bookmark from the editor + void SetNodeTitleFromTextField(); + + // Delegate for the bubble, may be null. + InfoBubbleDelegate* delegate_; + + // The profile. + Profile* profile_; + + // The bookmark URL. + const GURL url_; + + // Title of the bookmark. This is initially the title supplied to the + // constructor, which is typically the title of the page. + std::wstring title_; + + // If true, the page was just bookmarked. + const bool newly_bookmarked_; + + RecentlyUsedFoldersModel parent_model_; + + // Link for removing/unstarring the bookmark. + ChromeViews::Link* remove_link_; + + // Button to bring up the editor. + ChromeViews::NativeButton* edit_button_; + + // Button to close the window. + ChromeViews::NativeButton* close_button_; + + // TextField showing the title of the bookmark. + ChromeViews::TextField* title_tf_; + + // ComboBox showing a handful of folders the user can choose from, including + // the current parent. + ChromeViews::ComboBox* parent_combobox_; + + DISALLOW_EVIL_CONSTRUCTORS(BookmarkBubbleView); +}; + +#endif // CHROME_BROWSER_VIEWS_BOOKMARK_BUBBLE_VIEW_H__ |