summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/bookmark_bubble_view.h
blob: 53d95fd23bb75111885d733ecf28bb62a58beb52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
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__